PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/leave/leaverecommendation/recommend_exec.php

https://bitbucket.org/lecturer34/hrmis
PHP | 83 lines | 77 code | 4 blank | 2 comment | 9 complexity | 4b0241e4a510ee42ce445725dc9d029b MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. session_start();
  3. require_once('../../lib/database.php');
  4. require_once('../../lib/globals.php');
  5. openConnection();
  6. function adminLogLeaveScheduleOperations($logoperation, $leavescheduleid, $employeeid) {
  7. $currentdate = Date('Y-m-d');
  8. $sql = "INSERT INTO tblleavescheduleadminlogs
  9. VALUES ('',
  10. '$currentdate',
  11. NOW(),
  12. '$logoperation',
  13. '$leavescheduleid',
  14. '$employeeid')";
  15. $result = mysql_query($sql) or die(mysql_error());
  16. }
  17. function adminEmailAlert($sendermail, $empid, $sub, $msg) {
  18. $sql = "SELECT * FROM tblemployee JOIN tblemployeeemail ON tblemployee.employeeid = tblemployeeemail.employeeid WHERE tblemployee.employeeid = '$empid'";
  19. $result = mysql_query($sql);
  20. while ($row = mysql_fetch_array($result)) {
  21. $receivermail = $row['email'];
  22. }
  23. $subject = "HRMIS - $sub";
  24. $message = $msg;
  25. mail($receivermail, $subject, $message, "From:" . $sendermail);
  26. }
  27. $employeeid = sanitizeInput($_SESSION['SESS_EMPLOYEE_ID']);
  28. $leavescheduleid = sanitizeInput($_POST['leavescheduleid']);
  29. $leavetype = sanitizeInput($_POST['leavetype']); // Needs to be worked upon
  30. $fiscalyear = sanitizeInput($_POST['fiscalyear']);
  31. $startdate = sanitizeInput($_POST['startdate']);
  32. $enddate = sanitizeInput($_POST['enddate']);
  33. $location = sanitizeInput($_POST['location']);
  34. $remark = sanitizeInput($_POST['remark']);
  35. $recommendstatus = sanitizeInput($_POST['recommendstatus']);
  36. $daystaken = daydiff($enddate, $startdate);
  37. if ($recommendstatus == 'recommend') {
  38. $sql = "UPDATE tblleaveschedule SET
  39. planid = '$leavetype',
  40. fiscalyear = '$fiscalyear',
  41. startdate = '$startdate',
  42. enddate = '$enddate',
  43. daystaken = '$daystaken',
  44. location = '$location',
  45. remark = '$remark',
  46. status = 'Recommended'
  47. WHERE leavescheduleid = '$leavescheduleid'";
  48. $result = mysql_query($sql) or die(mysql_error());
  49. if ($result) {
  50. adminLogLeaveScheduleOperations("Recommend Leave", $leavescheduleid, $employeeid);
  51. //adminEmailAlert("hrmis@gmail.com", $employeeid, "Leave Recommended", "Leave Recommendation");
  52. }
  53. } elseif ($recommendstatus == 'reject') {
  54. $sql = "UPDATE tblleaveschedule SET
  55. planid = '$leavetype',
  56. fiscalyear = '$fiscalyear',
  57. startdate = '$startdate',
  58. enddate = '$enddate',
  59. daystaken = '$daystaken',
  60. location = '$location',
  61. remark = '$remark',
  62. status = 'Not Recommended'
  63. WHERE leavescheduleid = '$leavescheduleid'";
  64. $result = mysql_query($sql) or die(mysql_error());
  65. if ($result) {
  66. adminLogLeaveScheduleOperations("Change leave status to not recommended", $leavescheduleid, $employeeid);
  67. }
  68. } elseif ($recommendstatus == 'revert') {
  69. $sql = "UPDATE tblleaveschedule SET status = 'Pending' WHERE leavescheduleid = '$leavescheduleid'";
  70. $result = mysql_query($sql) or die(mysql_error());
  71. if ($result) {
  72. adminLogLeaveScheduleOperations("Change leave status to pending", $leavescheduleid, $employeeid);
  73. //adminEmailAlert("hrmis@gmail.com", $employeeid, "Leave Not Recommended", "Leave Not Recommended");
  74. }
  75. }
  76. if ($result) {
  77. echo "Submitted";
  78. }
  79. ?>