insertTimeForm.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. class insertTimeForm extends Staple_Form
  3. {
  4. private $accountLevel;
  5. private $adminAction;
  6. /**
  7. * @return mixed
  8. */
  9. public function getAdminAction()
  10. {
  11. return $this->adminAction;
  12. }
  13. /**
  14. * @param mixed $adminAction
  15. */
  16. public function setAdminAction($adminAction)
  17. {
  18. $this->adminAction = $adminAction;
  19. }
  20. /**
  21. * @return mixed
  22. */
  23. public function getAccountLevel()
  24. {
  25. return $this->accountLevel;
  26. }
  27. /**
  28. * @param mixed $accountLevel
  29. */
  30. public function setAccountLevel($accountLevel)
  31. {
  32. $this->accountLevel = $accountLevel;
  33. }
  34. public function _start()
  35. {
  36. $auth = Staple_Auth::get();
  37. $user = new userModel();
  38. $user->userInfo($auth->getAuthId());
  39. $this->accountLevel = $user->getAuthLevel();
  40. $this->setLayout('insertFormLayout');
  41. $this->setName('insertTimeForm')
  42. ->setAction($this->link(array('timesheet')));
  43. $date = new Staple_Form_FoundationTextElement('date','Date');
  44. $date->setRequired()
  45. ->addValidator(new Staple_Form_Validate_Date())
  46. ->addAttrib('placeholder','mm/dd/yyyy');
  47. $inTime = new Staple_Form_FoundationTextElement('inTime','Time In');
  48. $inTime->setRequired()
  49. ->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/','Invalid time format. Expected format: h:mm am/pm.'))
  50. ->addAttrib('placeholder','h:mm am/pm');
  51. $outTime = new Staple_Form_FoundationTextElement('outTime','Time Out');
  52. $outTime->setRequired()
  53. ->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/','Invalid time format. Expected format: h:mm am/pm.'))
  54. ->addAttrib('placeholder','h:mm am/pm');;
  55. $lessTime = new Staple_Form_FoundationSelectElement('lessTime','Less Time');
  56. $lessTime->setRequired()
  57. ->addOptionsArray(array("0"=>"None","60"=>"1 Hour","30"=>"30 Minutes","15"=>"15 Minutes"))
  58. ->addValidator(new Staple_Form_Validate_InArray(array('0','60','30','15')));
  59. $timeCodes = new codeModel();
  60. $code = new Staple_Form_FoundationSelectElement('code','Code');
  61. $code->setRequired()
  62. ->addOption("x","Select an option")
  63. ->addOptionsArray($timeCodes->allCodes())
  64. ->addValidator(new Staple_Form_Validate_InArray(array_keys($timeCodes->allCodes())));
  65. $code->setValue($timeCodes->getIdFor('Normal')['id']);
  66. $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
  67. $submit->addClass('button expand radius');
  68. $this->addField($date, $inTime, $outTime, $lessTime, $code, $submit);
  69. }
  70. public function admin($key)
  71. {
  72. if($key == 1)
  73. {
  74. $this->setAdminAction(1);
  75. if($this->accountLevel >= 900)
  76. {
  77. if($this->adminAction == 1)
  78. {
  79. $this->setAction($this->link(array('timesheet','admininsert')));
  80. $this->setLayout('adminInsertFormLayout');
  81. $account = new Staple_Form_FoundationSelectElement('account','Account');
  82. $account->setRequired()
  83. ->addOption('','Select an account')
  84. ->addOptionsArray($this->accounts())
  85. ->addValidator(new Staple_Form_Validate_InArray($this->accounts(1)));
  86. $note = new Staple_Form_FoundationTextElement('note','Note');
  87. $note->setRequired()
  88. ->addValidator(new Staple_Form_Validate_Length(1,5000))
  89. ->addFilter(new Staple_Form_Filter_Trim());
  90. $this->addField($account, $note);
  91. }
  92. }
  93. }
  94. else
  95. {
  96. $this->setAdminAction(0);
  97. }
  98. }
  99. public function accounts($ids = null)
  100. {
  101. $user = new userModel();
  102. $id = $user->getId();
  103. $authLevel = $user->getAuthLevel();
  104. $accounts = new userModel();
  105. $users = $accounts->listAll();
  106. $data = array();
  107. if($ids == null)
  108. {
  109. foreach($users as $user)
  110. {
  111. if($user['supervisorId'] == $id)
  112. {
  113. $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
  114. }
  115. elseif($authLevel >= 900)
  116. {
  117. $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
  118. }
  119. }
  120. }
  121. else
  122. {
  123. foreach($users as $user)
  124. {
  125. $data[] = $user['id'];
  126. }
  127. }
  128. return $data;
  129. }
  130. }
  131. ?>