reportsController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. class reportsController extends Staple_Controller
  3. {
  4. private $authLevel;
  5. public function _start()
  6. {
  7. $auth = Staple_Auth::get();
  8. $this->authLevel = $auth->getAuthLevel();
  9. if ($this->authLevel < 500) {
  10. header("location:" . $this->_link(array('index', 'index')) . "");
  11. }
  12. }
  13. public function index($year = null, $month = null)
  14. {
  15. if ($year == null) {
  16. $year = date('Y');
  17. }
  18. if ($month == null) {
  19. $month = date('m');
  20. }
  21. $report = new reportModel($year, $month);
  22. $this->view->report = $report->getTimesheets();
  23. }
  24. public function weekly()
  25. {
  26. //Weekly report form
  27. $form = new weeklyReportForm();
  28. if ($form->wasSubmitted()) {
  29. $form->addData($_POST);
  30. if ($form->validate()) {
  31. $data = $form->exportFormData();
  32. $report = new weeklyReportModel();
  33. $this->view->report = $report->timeWorked($data['account'], $data['year']);
  34. $account = new userModel();
  35. $this->view->account = $account->userInfo($data['account']);
  36. $this->view->year = $data['year'];
  37. } else {
  38. $this->view->form = $form;
  39. }
  40. } else {
  41. $this->view->form = $form;
  42. }
  43. }
  44. public function unlock()
  45. {
  46. $auth = Staple_Auth::get();
  47. $this->authLevel = $auth->getAuthLevel();
  48. if ($this->authLevel < 900)
  49. {
  50. header("location:" . $this->_link(array('index', 'index')) . "");
  51. }
  52. else
  53. {
  54. $rangeForm = new rangeUnlockForm();
  55. if ($rangeForm->wasSubmitted()) {
  56. $rangeForm->addData($_POST);
  57. if ($rangeForm->validate()) {
  58. $data = $rangeForm->exportFormData();
  59. $unlock = new unlockModel();
  60. $unlock->setStartTime($data['startDate']);
  61. $unlock->setEndTime($data['endDate']);
  62. $unlock->setUserId($data['account']);
  63. $unlock->save();
  64. $this->view->rangeForm = new rangeUnlockForm();
  65. } else {
  66. $this->view->rangeForm = $rangeForm;
  67. }
  68. } else {
  69. $this->view->rangeForm = $rangeForm;
  70. }
  71. $singleForm = new singleUnlockForm();
  72. if ($singleForm->wasSubmitted()) {
  73. $singleForm->addData($_POST);
  74. if ($singleForm->validate()) {
  75. $data = $singleForm->exportFormData();
  76. } else {
  77. $this->view->singleForm = $singleForm;
  78. }
  79. } else {
  80. $this->view->singleForm = $singleForm;
  81. }
  82. $year = date('Y');
  83. $month = date('m');
  84. $timesheets = new reportModel($year, $month);
  85. $this->view->accounts = $timesheets;
  86. }
  87. }
  88. public function unlockid($id)
  89. {
  90. $auth = Staple_Auth::get();
  91. $this->authLevel = $auth->getAuthLevel();
  92. if ($this->authLevel < 900)
  93. {
  94. header("location:" . $this->_link(array('index', 'index')) . "");
  95. }
  96. else
  97. {
  98. $unlock = new unlockModel();
  99. if ($unlock->unlock($id)) {
  100. $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
  101. } else {
  102. $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
  103. }
  104. }
  105. }
  106. }