accountsController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class accountsController extends Staple_Controller
  3. {
  4. private $authLevel;
  5. public function _start()
  6. {
  7. $auth = Staple_Auth::get();
  8. $this->authLevel = $auth->getAuthLevel();
  9. if($this->authLevel < 900)
  10. {
  11. header("location:".$this->_link(array('index','index'))."");
  12. }
  13. }
  14. public function index()
  15. {
  16. $accounts = new userModel();
  17. $this->view->accounts = $accounts->listActive();
  18. $this->view->allAccounts = $accounts->listAll();
  19. $form = new newAccountForm();
  20. if($form->wasSubmitted())
  21. {
  22. $form->addData($_POST);
  23. if($form->validate())
  24. {
  25. $data = $form->exportFormData();
  26. if($data['pinNum'] == $data['pinNum2'])
  27. {
  28. $user = new accountModel();
  29. $user->setFirstName(ucfirst($data['firstName']));
  30. $user->setLastName(ucfirst($data['lastName']));
  31. $user->setSupervisorId($data['supervisor']);
  32. $user->setType($data['type']);
  33. $user->setAuthLevel($data['level']);
  34. $user->setPin($data['pinNum']);
  35. if($user->save())
  36. {
  37. $this->view->newUser = true;
  38. $this->view->firstName = $user->getFirstName();
  39. $this->view->lastName = $user->getLastName();
  40. $this->view->tempPin = $user->getTempPin();
  41. $form = new newAccountForm();
  42. $this->view->form = $form;
  43. }
  44. else
  45. {
  46. $form->errorMessage = array("ERROR: Could not create account");
  47. $this->view->form = $form;
  48. $this->layout->addScriptBlock('$(document).ready(function() { $("#new").foundation("reveal", "open"); }); ');
  49. }
  50. }
  51. else
  52. {
  53. $form->errorMessage = array("PINs do not match");
  54. $this->view->form = $form;
  55. $this->layout->addScriptBlock('$(document).ready(function() { $("#new").foundation("reveal", "open"); }); ');
  56. }
  57. }
  58. else
  59. {
  60. $this->view->form = $form;
  61. $this->layout->addScriptBlock('$(document).ready(function() { $("#new").foundation("reveal", "open"); }); ');
  62. }
  63. }
  64. else
  65. {
  66. $this->view->form = $form;
  67. }
  68. }
  69. public function inactive()
  70. {
  71. $accounts = new userModel();
  72. $this->view->accounts = $accounts->listInactive();
  73. $this->view->allAccounts = $accounts->listAll();
  74. }
  75. }
  76. ?>