<?
/* index.php: $pubmodule, $pubtask, $pubitemid */
?>

<script type="text/javascript">

// ................................................................................
// user-interaction handlers..
// ................................................................................

function user_button_add() {
  document.location='index.php?module=user&task=add';
}

function user_button_edit(userpkey) {
  document.location='index.php?module=user&task=edit&itemid='+userpkey;
}

function user_button_view(userpkey) {
  document.location='index.php?module=user&task=view&itemid='+userpkey;
}

function user_button_delete(userpkey) {
  document.location='index.php?module=user&task=delete&itemid='+userpkey;
}

function user_button_resetpassword(userpkey, staffname, username) {
  if (staffname=="") staffname=username;
  if (confirm("Are you sure to Reset the Password for "+staffname+"?\n(This will set the password to '"+username+"')")) {
    document.userform.job.value="user_resetpwd";
    document.userform.submit();
  }
}

function user_button_changepwd() {
  if (validateForm()==true) {
    if (confirm("Are you sure to change your Password?")) {
      document.userform.job.value="user_changepwd";
      document.userform.submit();
    }
  }
}

function user_button_addgroup() {
  document.location='index.php?module=user&task=groupadd';
}

function user_button_editgroup(grouppkey) {
  document.location='index.php?module=user&task=groupedit&itemid='+grouppkey;
}

function user_button_viewgroup(grouppkey) {
  document.location='index.php?module=user&task=groupview&itemid='+grouppkey;
}

function user_button_deletegroup(grouppkey) {
  document.location='index.php?module=user&task=groupdelete&itemid='+grouppkey;
}

function user_button_addstaff() {
  document.location='index.php?module=user&task=staffadd';
}

function user_button_editstaff(staffpkey) {
  document.location='index.php?module=user&task=staffedit&itemid='+staffpkey;
}

function user_button_viewstaff(staffpkey) {
  document.location='index.php?module=user&task=staffview&itemid='+staffpkey;
}

function user_button_deletestaff(staffpkey) {
  document.location='index.php?module=user&task=staffdelete&itemid='+staffpkey;
}

function user_button_adddept() {
  document.location='index.php?module=user&task=deptadd';
}

function user_button_editdept(deptpkey) {
  document.location='index.php?module=user&task=deptedit&itemid='+deptpkey;
}

function user_button_viewdept(deptpkey) {
  document.location='index.php?module=user&task=deptview&itemid='+deptpkey;
}

function user_button_deletedept(deptpkey) {
  document.location='index.php?module=user&task=deptdelete&itemid='+deptpkey;
}

function user_button_adddiv() {
  document.location='index.php?module=user&task=divadd';
}

function user_button_editdiv(divpkey) {
  document.location='index.php?module=user&task=divedit&itemid='+divpkey;
}

function user_button_viewdiv(divpkey) {
  document.location='index.php?module=user&task=divview&itemid='+divpkey;
}

function user_button_deletediv(divpkey) {
  document.location='index.php?module=user&task=divdelete&itemid='+divpkey;
}

function user_button_save() {
  if (validateForm()==true) {
    document.userform.job.value='user_add'; document.userform.submit();
  }
}

function user_button_update() {
  if (validateForm()==true) {
    document.userform.job.value='user_edit'; document.userform.submit();
  }
}

function user_button_purge() {
  document.userform.job.value='user_remove'; document.userform.submit();
}

function user_button_savegroup() {
  if (validateForm()==true) {
    document.userform.job.value='user_groupadd'; document.userform.submit();
  }
}

function user_button_updategroup() {
  if (validateForm()==true) {
    document.userform.job.value='user_groupedit'; document.userform.submit();
  }
}

function user_button_purgegroup() {
  document.userform.job.value='user_groupremove'; document.userform.submit();
}

function user_button_savestaff() {
  if (validateForm()==true) {
    document.userform.job.value='user_staffadd'; document.userform.submit();
  }
}

function user_button_updatestaff() {
  if (validateForm()==true) {
    document.userform.job.value='user_staffedit'; document.userform.submit();
  }
}

function user_button_purgestaff() {
  document.userform.job.value='user_staffremove'; document.userform.submit();
}

function user_button_savedept() {
  if (validateForm()==true) {
    document.userform.job.value='user_deptadd'; document.userform.submit();
  }
}

function user_button_updatedept() {
  if (validateForm()==true) {
    document.userform.job.value='user_deptedit'; document.userform.submit();
  }
}

function user_button_purgedept() {
  document.userform.job.value='user_deptremove'; document.userform.submit();
}

function user_button_savediv() {
  if (validateForm()==true) {
    document.userform.job.value='user_divadd'; document.userform.submit();
  }
}

function user_button_updatediv() {
  if (validateForm()==true) {
    document.userform.job.value='user_divedit'; document.userform.submit();
  }
}

function user_button_purgediv() {
  document.userform.job.value='user_divremove'; document.userform.submit();
}

function user_button_updateaccess() {
  if (submitForm()==true) {
    document.userform.job.value='user_projectaccess'; document.userform.submit();
  }
}

function user_button_back() {
  history.go(-1);
}

</script>

<?

// ................................................................................
// model..
// ................................................................................

include_once('models/userModel.php');
$myuserModel=new userModel;

?>

<?

// ................................................................................
// data retrieval functions..
// ................................................................................


// ................................................................................
// data modifications functions..
// ................................................................................


// ................................................................................
// default to list view if none specified..
// ................................................................................
if ($pubtask=="") $pubtask="main";

// ................................................................................
// display page header..
// ................................................................................

$pagetitle="Users";
if ($pubtask=="submenu") {
  $subtitle="User Administration Menu";
} else if (($pubtask=="main")||($pubtask=="list")) {
  $subtitle="List of Users";
} else if ($pubtask=="add") {
  $subtitle="Add User";
} else if ($pubtask=="edit") {
  $subtitle="Edit User";
} else if ($pubtask=="view") {
  $subtitle="User Information";
} else if ($pubtask=="delete") {
  $subtitle="Delete User";
} else if ($pubtask=="chgpwd") {
  $subtitle="Change Password";
} else if ($pubtask=="groups") {
  $subtitle="User Groups";
} else if ($pubtask=="groupadd") {
  $subtitle="Add User Group";
} else if ($pubtask=="groupedit") {
  $subtitle="Edit User Group";
} else if ($pubtask=="groupview") {
  $subtitle="User Group Information";
} else if ($pubtask=="groupdelete") {
  $subtitle="Delete User Group";
} else if ($pubtask=="project") {
  $subtitle="Project Access";

} else if ($pubtask=="menu") {
  $subtitle="Manage Staff Profiles";
} else if ($pubtask=="staff") {
  $subtitle="Staff Profiles";
} else if ($pubtask=="staffadd") {
  $subtitle="Add Staff Profile";
} else if ($pubtask=="staffedit") {
  $subtitle="Edit Staff Profile";
} else if ($pubtask=="selfedit") {
  $subtitle="Update Particulars";
} else if ($pubtask=="staffview") {
  $subtitle="Staff Profile";
} else if ($pubtask=="staffdelete") {
  $subtitle="Delete Staff Profile";
} else if ($pubtask=="depts") {
  $subtitle="Departments";
} else if ($pubtask=="deptadd") {
  $subtitle="Add Department";
} else if ($pubtask=="deptedit") {
  $subtitle="Edit Department";
} else if ($pubtask=="deptview") {
  $subtitle="Department Information";
} else if ($pubtask=="deptdelete") {
  $subtitle="Delete Department";
} else if ($pubtask=="divs") {
  $subtitle="Divisions";
} else if ($pubtask=="divadd") {
  $subtitle="Add Division";
} else if ($pubtask=="divedit") {
  $subtitle="Edit Division";
} else if ($pubtask=="divview") {
  $subtitle="Division Information";
} else if ($pubtask=="divdelete") {
  $subtitle="Delete Division";
} else {
  $subtitle="Error: Invalid Option";
}

$headercaption=$pagetitle." --&raquo; ".$subtitle;
include_once('header.php');

include_once('views/general-header.tpl');


// TODO: Later to show list of available variables here if in DEBUG mode!!

// ................................................................................
// display main area..
// ................................................................................

if (($pubtask=="submenu")&&((($pubuseraccess['access_system_managestaff']==1)||($pubuseraccess['access_system_manageusers']==1)||($pubuseraccess['access_system_manageaccess']==1))||($pubuserrole>=2))) {

  include_once('views/user-submenu.tpl');

} else if ((($pubtask=="main")||($pubtask=="list"))&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  $user_list = $myuserModel->getlist_users();
  include_once('views/user-list.tpl');

} else if ((($pubtask=="add")||($pubtask=="edit"))&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  $staff_data = $myuserModel->getdata_staff($pubitemid);
  $user_data = $myuserModel->getdata_user($pubitemid);
  include_once('views/user-edit.tpl');

} else if ((($pubtask=="view")||($pubtask=="delete"))&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  $staff_data = $myuserModel->getdata_staff($pubitemid);
  $user_data = $myuserModel->getdata_user($pubitemid);
  include_once('views/user-view.tpl');

} else if ($pubtask=="chgpwd") {

  include_once('views/user-chgpwd.tpl');

} else if (($pubtask=="groups")&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  $usergroup_list = $myuserModel->getlist_usergroups();
  include_once('views/usergroup-list.tpl');

} else if ((($pubtask=="groupadd")||($pubtask=="groupedit"))&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  $usergroup_data = $myuserModel->getdata_usergroupaccess($pubitemid);
  if ($pubitemid=="") {
    $usergroup_data['access_mbl_view']="1";
    $usergroup_data['access_mro_view']="1";
    $usergroup_data['access_itq_view']="1";
    $usergroup_data['access_po_view']="1";
    $usergroup_data['access_do_view']="1";
    $usergroup_data['access_invoice_view']="1";
    $usergroup_data['access_reports_all']="1";
    $usergroup_data['access_reports_mbl']="1";
    $usergroup_data['access_reports_qv']="1";
    $usergroup_data['access_reports_po']="1";
    $usergroup_data['access_reports_sp']="1";
    $usergroup_data['access_reports_bm']="1";
    $usergroup_data['access_reports_pmc']="1";
    $usergroup_data['access_reports_scm']="1";
    $usergroup_data['access_reports_iqa']="1";
    $usergroup_data['access_supplier_view']="1";
    $usergroup_data['access_client_view']="1";
    $usergroup_data['access_subcon_view']="1";
  }
  include_once('views/usergroup-edit.tpl');

} else if ((($pubtask=="groupview")||($pubtask=="groupdelete"))&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  $usergroup_data = $myuserModel->getdata_usergroupaccess($pubitemid);
  include_once('views/usergroup-view.tpl');

} else if ($pubtask=="project") {

  include_once('models/projectModel.php');
  $myprojectModelPMS=new projectModelPMS;

  $staff_data = $myuserModel->getdata_staff($pubitemid);
  $user_data = $myuserModel->getdata_user($pubitemid);
  $project_list = $myprojectModelPMS->getlist_projects();
  $access_list = $myprojectModelPMS->getlist_useraccess($pubitemid);

  include_once('views/user-project.tpl');

} else if (($pubtask=="menu")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  include_once('views/user-menu.tpl');

} else if (($pubtask=="staff")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $staff_list = $myuserModel->getlist_staff();
  include_once('views/staff-list.tpl');

} else if ((($pubtask=="staffadd")||($pubtask=="staffedit"))&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $staff_data = $myuserModel->getdata_staff($pubitemid);
  $user_data = $myuserModel->getdata_user($staff_data['staff_userpkey']);
  include_once('views/staff-edit.tpl');

} else if ($pubtask=="update") {

  //if ($_SESSION['Xstaffpkey']==$pubitemid) {

    $staff_data = $myuserModel->getdata_staff($_SESSION['Xuserpkey']);
    $user_data = $myuserModel->getdata_user($_SESSION['Xuserpkey']);
    include_once('views/user-edit.tpl');

  //}

} else if ((($pubtask=="staffview")||($pubtask=="staffdelete"))&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $staff_data = $myuserModel->getdata_staff($pubitemid);
  include_once('views/staff-view.tpl');

} else if (($pubtask=="depts")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $dept_list = $myuserModel->getlist_departments();
  include_once('views/department-list.tpl');

} else if ((($pubtask=="deptadd")||($pubtask=="deptedit"))&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $dept_data = $myuserModel->getdata_department($pubitemid);
  include_once('views/department-edit.tpl');

} else if ((($pubtask=="deptview")||($pubtask=="deptdelete"))&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $dept_data = $myuserModel->getdata_department($pubitemid);
  include_once('views/department-view.tpl');

} else if (($pubtask=="divs")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $div_list = $myuserModel->getlist_divisions();
  include_once('views/division-list.tpl');

} else if ((($pubtask=="divadd")||($pubtask=="divedit"))&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $div_data = $myuserModel->getdata_division($pubitemid);
  include_once('views/division-edit.tpl');

} else if ((($pubtask=="divview")||($pubtask=="divdelete"))&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  $div_data = $myuserModel->getdata_division($pubitemid);
  include_once('views/division-view.tpl');

} else {
  include_once('views/general-invalidtask.php');
}

// ...............................................................................
// display button options area..
// ...............................................................................

$prevurl = explode('/',$_SESSION['Xpreviousurl']);
$prevfile = $prevurl[count($prevurl)-1];
if ($prevfile=='inputController.php') $backstatus="style='display: none;'";

echo "<br>";

if ((($pubtask=="main")||($pubtask=="list"))&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"add\" id=\"add\" onClick=\"user_button_add();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add New User</button>&nbsp;";
  // edit 17-08-2010
  //echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="add")&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"user_button_save();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save User</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="edit")&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"user_button_update();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update User</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<button name=\"resetpwd\" id=\"resetpwd\" onClick=\"user_button_resetpassword('".$user_data['user_pkey']."','".$user_data['staff_name']."','".$user_data['user_name']."');\"><img src='gfx/options/b_resetpwd.png' class='actionbutton'>&nbsp;&nbsp;Reset Password</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="view")&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"edit\" id=\"edit\" onClick=\"javascript:user_button_edit('".$user_data['user_pkey']."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"javascript:user_button_delete('".$user_data['user_pkey']."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"javascript:user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="delete")&&(($pubuseraccess['access_system_manageusers']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS USER?<br>(NOTE: USER WILL NOT BE DELETED IF THERE ARE ANY RECORDS LINKED TO IT)</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"user_button_purge();\">&nbsp;Yes, Delete User&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";

} else if ($pubtask=="chgpwd") {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"user_button_changepwd();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Change Password</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="groups")&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"add\" id=\"add\" onClick=\"user_button_addgroup();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add New User Group</button>&nbsp;";
  //echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="groupadd")&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"user_button_savegroup();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save User Group</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="groupedit")&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"user_button_updategroup();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update User Group</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="groupview")&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"edit\" id=\"edit\" onClick=\"javascript:user_button_editgroup('".$usergroup_data['group_pkey']."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"javascript:user_button_deletegroup('".$usergroup_data['group_pkey']."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"javascript:user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="groupdelete")&&(($pubuseraccess['access_system_manageaccess']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS USER GROUP?</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"user_button_purgegroup();\">&nbsp;Yes, Delete User Group&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";

} else if ($pubtask=="project") {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"user_button_updateaccess();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update User Access</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="menu")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="staff")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"add\" id=\"add\" onClick=\"user_button_addstaff();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add New Staff Profile</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="staffadd")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"user_button_savestaff();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save Staff Profile</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="staffedit")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"user_button_updatestaff();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update Staff Profile</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if ($pubtask=="update") {

  //if ($_SESSION['Xstaffpkey']==$pubitemid) {

    echo "<br><hr size=1>";
    echo "<button name=\"update\" id=\"update\" onClick=\"user_button_update();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update Staff Profile</button>&nbsp;";
    echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
    echo "<br><hr size=1><br>";

  //} else {

  //  echo "<br><hr size=1>";
  //  echo "<font color='#ff0000'><b>YOU ARE NOT LOGGED IN AS THIS STAFF!</b></font><br><br>";
  //  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  //  echo "<brp><hr size=1><br>";

  //}

} else if (($pubtask=="staffview")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"edit\" id=\"edit\" onClick=\"javascript:user_button_editstaff('".$staff_data['staff_pkey']."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"javascript:user_button_deletestaff('".$staff_data['staff_pkey']."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"javascript:user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="staffdelete")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS USER STAFF PROFILE?</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"user_button_purgestaff();\">&nbsp;Yes, Delete Staff Profile&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";

} else if (($pubtask=="depts")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"add\" id=\"add\" onClick=\"user_button_adddept();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add New Department</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="deptadd")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"user_button_savedept();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save Department</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="deptedit")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"user_button_updatedept();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update Department</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="deptview")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"edit\" id=\"edit\" onClick=\"javascript:user_button_editdept('".$dept_data['dept_pkey']."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"javascript:user_button_deletedept('".$dept_data['dept_pkey']."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"javascript:user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="deptdelete")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS DEPARTMENT?</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"user_button_purgedept();\">&nbsp;Yes, Delete Department&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";

} else if (($pubtask=="divs")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"add\" id=\"add\" onClick=\"user_button_adddiv();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add New Division</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="divadd")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"user_button_savediv();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save Division</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="divedit")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"user_button_updatediv();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update Division</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="divview")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"edit\" id=\"edit\" onClick=\"javascript:user_button_editdiv('".$div_data['div_pkey']."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"javascript:user_button_deletediv('".$div_data['div_pkey']."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"javascript:user_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if (($pubtask=="divdelete")&&(($pubuseraccess['access_system_managestaff']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS DIVISION?</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"user_button_purgediv();\">&nbsp;Yes, Delete Division&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"user_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";

}

// ................................................................................
// display page footer..
// ................................................................................

include_once('views/general-footer.tpl');

?>