reportsController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. $this->layout->addScriptBlock("
  46. window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
  47. ");
  48. $this->view->printTimeSheetForm = $printTimeSheetForm;
  49. }
  50. else
  51. {
  52. $this->view->printTimeSheetForm = $printTimeSheetForm;
  53. }
  54. }
  55. else
  56. {
  57. $this->view->printTimeSheetForm = $printTimeSheetForm;
  58. }
  59. }
  60. public function changeyear()
  61. {
  62. $form = new changeYearForm();
  63. if($form->wasSubmitted())
  64. {
  65. $form->addData($_POST);
  66. if($form->validate())
  67. {
  68. $data = $form->exportFormData();
  69. header("location: ".$this->_link(array('reports',$data['year']))."");
  70. }
  71. else
  72. {
  73. header("location: ".$this->_link(array('reports'))."");
  74. }
  75. }
  76. else
  77. {
  78. header("location: ".$this->_link(array('reports'))."");
  79. }
  80. }
  81. public function weekly()
  82. {
  83. //Weekly report form
  84. $form = new weeklyReportForm();
  85. if ($form->wasSubmitted()) {
  86. $form->addData($_POST);
  87. if ($form->validate()) {
  88. $data = $form->exportFormData();
  89. $report = new weeklyReportModel();
  90. $this->view->report = $report->timeWorked($data['account'], $data['year']);
  91. $account = new userModel();
  92. $this->view->account = $account->userInfo($data['account']);
  93. $this->view->year = $data['year'];
  94. } else {
  95. $this->view->form = $form;
  96. }
  97. } else {
  98. $this->view->form = $form;
  99. }
  100. }
  101. public function unlock()
  102. {
  103. $auth = Staple_Auth::get();
  104. $this->authLevel = $auth->getAuthLevel();
  105. if ($this->authLevel < 900)
  106. {
  107. header("location:" . $this->_link(array('index', 'index')) . "");
  108. }
  109. else
  110. {
  111. $year = date('Y');
  112. $month = date('m');
  113. $timesheets = new reportModel($year, $month);
  114. $this->view->accounts = $timesheets;
  115. }
  116. }
  117. public function unlockid($id)
  118. {
  119. $auth = Staple_Auth::get();
  120. $this->authLevel = $auth->getAuthLevel();
  121. if ($this->authLevel < 900)
  122. {
  123. header("location:" . $this->_link(array('index', 'index')) . "");
  124. }
  125. else
  126. {
  127. $unlock = new unlockModel();
  128. if ($unlock->unlock($id))
  129. {
  130. $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
  131. }
  132. else
  133. {
  134. $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
  135. }
  136. }
  137. }
  138. public function printpreview($year,$month,$uid)
  139. {
  140. $this->_setLayout('print');
  141. $user = new userModel();
  142. $account = $user->userInfo($uid);
  143. $this->view->firstName = $account['firstName'];
  144. $this->view->lastName = $account['lastName'];
  145. $this->view->batchId = $account['batchId'];
  146. $this->view->year = $year;
  147. $this->view->month = date('F',$month);
  148. $timesheet = new timesheetModel($year, $month,$uid);
  149. $this->view->timesheet = $timesheet;
  150. }
  151. }