insertTimeForm.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. $this->addField($account);
  87. }
  88. }
  89. }
  90. else
  91. {
  92. $this->setAdminAction(0);
  93. }
  94. }
  95. public function accounts($ids = null)
  96. {
  97. $user = new userModel();
  98. $id = $user->getId();
  99. $authLevel = $user->getAuthLevel();
  100. $accounts = new userModel();
  101. $users = $accounts->listAll();
  102. $data = array();
  103. if($ids == null)
  104. {
  105. foreach($users as $user)
  106. {
  107. if($user['supervisorId'] == $id)
  108. {
  109. $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
  110. }
  111. elseif($authLevel >= 900)
  112. {
  113. $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
  114. }
  115. }
  116. }
  117. else
  118. {
  119. foreach($users as $user)
  120. {
  121. $data[] = $user['id'];
  122. }
  123. }
  124. return $data;
  125. }
  126. }
  127. ?>