<?

function profile_adddesignation($staffdesignationtitle, $staffdesignationdescription, $staffdesignationsuperiorpkey, $staffdesignationdivisionpkey, $staffdesignationdepartmentpkey)
{
  // convert params..
  $staffdesignationpkey=md5(microtime());
  $creationdate=gettimestamp();
  // update staff designation..
  $sa = add_data("Profil [Tambah Jawatan]", "staff_designations", "staffdesignationpkey, staffdesignationtitle, staffdesignationdescription, staffdesignationsuperiorpkey, staffdesignationdivisionpkey, staffdesignationdepartmentpkey, staffdesignationcreationdate, staffdesignationcreatedby, staffdesignationupdatedby",
                 "'".$staffdesignationpkey."','".$staffdesignationtitle.
                 "','".$staffdesignationdescription."','".$staffdesignationsuperiorpkey.
                 "','".$staffdesignationdivisionpkey."','".$staffdesignationdepartmentpkey.
                 "','".$creationdate.
                 "','".$_SESSION['Xuserpkey']."','".$_SESSION['Xuserpkey']."'");
  // return result..
  if ($sa==1) {
    $m=msg_n_goto("index.php?module=admin&task=designations","Jawatan Staf Berjaya Ditambah!");
    echo $m;
  } else {
    $e=error_n_goto("index.php?module=admin&task=designations","Ralat: Jawatan Staf Gagal Ditambah!");
    echo $e;
  }
}

function profile_editdesignation($staffdesignationpkey, $staffdesignationtitle, $staffdesignationdescription, $staffdesignationsuperiorpkey, $staffdesignationdivisionpkey, $staffdesignationdepartmentpkey)
{
  // convert params..
  // update staff designation..
  $sa = update_data("Profil [Pinda Jawatan]", "staff_designations", "staffdesignationtitle = '".$staffdesignationtitle.
                      "', staffdesignationdescription = '".$staffdesignationdescription.
                      "', staffdesignationsuperiorpkey = '".$staffdesignationsuperiorpkey.
                      "', staffdesignationdivisionpkey = '".$staffdesignationdivisionpkey.
                      "', staffdesignationdepartmentpkey = '".$staffdesignationdepartmentpkey.
                      "', staffdesignationupdatedby = '".$_SESSION['Xuserpkey']."'",
                      "where staffdesignationpkey = '".$staffdesignationpkey."'");
  // return result..
  if ($sa==1) {
    $m=msg_n_goto("index.php?module=admin&task=designations","Jawatan Staf Berjaya Dipinda!");
    echo $m;
  } else {
    $e=error_n_goto("index.php?module=admin&task=designations","Ralat: Jawatan Staf Gagal Dipinda!");
    echo $e;
  }
}

function profile_addunit($staffunitname, $staffunitdescription, $staffunitsuperiorpkey, $staffunitdivisionpkey)
{
  // convert params..
  $staffunitpkey=md5(microtime());
  $creationdate=gettimestamp();
  // update staff unit..
  $sa = add_data("Profil [Tambah Unit]", "staff_units", "staffunitpkey, staffunitname, staffunitdescription, staffunitsuperiorpkey, staffunitdivisionpkey, staffunitcreationdate, staffunitcreatedby, staffunitupdatedby",
                 "'".$staffunitpkey."','".$staffunitname.
                 "','".$staffunitdescription."','".$staffunitsuperiorpkey.
                 "','".$staffunitdivisionpkey.
                 "','".$creationdate.
                 "','".$_SESSION['Xuserpkey']."','".$_SESSION['Xuserpkey']."'");
  // return result..
  if ($sa==1) {
    $m=msg_n_goto("index.php?module=admin&task=units","Unit Staf Berjaya Ditambah!");
    echo $m;
  } else {
    $e=error_n_goto("index.php?module=admin&task=units","Ralat: Unit Staf Gagal Ditambah!");
    echo $e;
  }
}

function profile_editunit($staffunitpkey, $staffunitname, $staffunitdescription, $staffunitsuperiorpkey, $staffunitdivisionpkey)
{
  // convert params..
  // update staff unit..
  $sa = update_data("Profil [Pinda Unit]", "staff_units", "staffunitname = '".$staffunitname.
                      "', staffunitdescription = '".$staffunitdescription.
                      "', staffunitsuperiorpkey = '".$staffunitsuperiorpkey.
                      "', staffunitdivisionpkey = '".$staffunitdivisionpkey.
                      "', staffunitupdatedby = '".$_SESSION['Xuserpkey']."'",
                      "where staffunitpkey = '".$staffunitpkey."'");
  // return result..
  if ($sa==1) {
    $m=msg_n_goto("index.php?module=admin&task=units","Unit Staf Berjaya Dipinda!");
    echo $m;
  } else {
    $e=error_n_goto("index.php?module=admin&task=units","Ralat: Unit Staf Gagal Dipinda!");
    echo $e;
  }
}

function profile_getstaffname($myuserpkey) {
  global $db;
  $myquery="Select staffname from staff_profiles where staffuserpkey='".$myuserpkey."'"; 
  $myresult =& $db->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return $myrow['staffname'];
    }
  } else {
    return "NA";
  }
}

function profile_getfullstaffname($myuserpkey) {
  global $db;
  // salutation
  $myquery="Select staffrank, staffname from staff_profiles where staffuserpkey='".$myuserpkey."'"; 
  $myresult =& $db->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return $myrow['staffrank']." ".$myrow['staffname'];
    }
  } else {
    return "NA";
  }
}

function profile_getdivisioncode($mydivisionpkey) {
  global $db;
  $myquery="Select staffdivisioncode from staff_divisions where staffdivisionpkey='".$mydivisionpkey."'"; 
  $myresult =& $db->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return $myrow['staffdivisioncode'];
    }
  } else {
    return "Umum";
  }
}

function profile_getdepartmentcode($mydepartmentpkey) {
  global $db;
  $myquery="Select staffdepartmentcode from staff_departments where staffdepartmentpkey='".$mydepartmentpkey."'"; 
  $myresult =& $db->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return $myrow['staffdepartmentcode'];
    }
  } else {
    return "NA";
  }
}

/*
function profile_getdepartmentname($mydepartmentpkey) {
  global $db;
  $myquery="Select staffdepartmentname from staff_departments where staffdepartmentpkey='".$mydepartmentpkey."'"; 
  $myresult =& $db->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return $myrow['staffdepartmentname'];
    }
  } else {
    return "TIADA";
  }
}
*/

function profile_getdepartmentfullname($mydepartmentpkey) {
  global $db;
  $myquery="Select staffdepartmentcode, staffdepartmentname from staff_departments where staffdepartmentpkey='".$mydepartmentpkey."'"; 
  $myresult =& $db->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return $myrow['staffdepartmentcode']." - ".$myrow['staffdepartmentname'];
    }
  } else {
    return "NA - UMUM";
  }
}

function profile_getdivisionname($divno) {
  if ($divno==1) {
    echo "Emerg. Srv.";
  } else if ($divno==2) {
    echo "Res. & Policy";
  } else if ($divno==3) {
    echo "CEO/COO/CTO";
  } else {
    echo "NA";
  }
}

function profile_getdepartmentname($deptno) {
  if ($deptno==1) {
    echo "C. Media Res.";
  } else if ($deptno==2) {
    echo "Strat. P & R";
  } else if ($deptno==3) {
    echo "COO's Office";
  } else if ($deptno==4) {
    echo "IT Department";
  } else {
    echo "NA";
  }
}

?>