reportsController.php 3.6 KB

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