reportsController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $date = new DateTime();
  35. $date->setDate($year, $month, 1);
  36. $this->view->month = $date->format('F');
  37. }
  38. public function changeyear()
  39. {
  40. $form = new changeYearForm();
  41. if($form->wasSubmitted())
  42. {
  43. $form->addData($_POST);
  44. if($form->validate())
  45. {
  46. $data = $form->exportFormData();
  47. header("location: ".$this->_link(array('reports',$data['year']))."");
  48. }
  49. else
  50. {
  51. header("location: ".$this->_link(array('reports'))."");
  52. }
  53. }
  54. else
  55. {
  56. header("location: ".$this->_link(array('reports'))."");
  57. }
  58. }
  59. public function weekly()
  60. {
  61. //Weekly report form
  62. $form = new weeklyReportForm();
  63. if ($form->wasSubmitted()) {
  64. $form->addData($_POST);
  65. if ($form->validate()) {
  66. $data = $form->exportFormData();
  67. $report = new weeklyReportModel();
  68. $this->view->report = $report->timeWorked($data['account'], $data['year']);
  69. $account = new userModel();
  70. $this->view->account = $account->userInfo($data['account']);
  71. $this->view->year = $data['year'];
  72. } else {
  73. $this->view->form = $form;
  74. }
  75. } else {
  76. $this->view->form = $form;
  77. }
  78. }
  79. public function unlock()
  80. {
  81. $auth = Staple_Auth::get();
  82. $this->authLevel = $auth->getAuthLevel();
  83. if ($this->authLevel < 900)
  84. {
  85. header("location:" . $this->_link(array('index', 'index')) . "");
  86. }
  87. else
  88. {
  89. $year = date('Y');
  90. $month = date('m');
  91. $timesheets = new reportModel($year, $month);
  92. $this->view->accounts = $timesheets;
  93. }
  94. }
  95. public function unlockid($id)
  96. {
  97. $auth = Staple_Auth::get();
  98. $this->authLevel = $auth->getAuthLevel();
  99. if ($this->authLevel < 900)
  100. {
  101. header("location:" . $this->_link(array('index', 'index')) . "");
  102. }
  103. else
  104. {
  105. $unlock = new unlockModel();
  106. if ($unlock->unlock($id))
  107. {
  108. $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
  109. }
  110. else
  111. {
  112. $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
  113. }
  114. }
  115. }
  116. }