reportsController.php 4.8 KB

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