/www/admin/users/edit.php

https://github.com/alcf/chms · PHP · 160 lines · 129 code · 25 blank · 6 comment · 14 complexity · 1bef69cab0fe0bd5f477db960cdb3820 MD5 · raw file

  1. <?php
  2. require(dirname(__FILE__) . '/../../../includes/prepend.inc.php');
  3. QApplication::Authenticate(array(RoleType::ChMSAdministrator));
  4. class AdminUsersForm extends ChmsForm {
  5. protected $strPageTitle = 'Administration - Manage Users - ';
  6. protected $intNavSectionId = ChmsForm::NavSectionAdministration;
  7. protected $objLogin;
  8. protected $lblUsername;
  9. protected $lblEmail;
  10. protected $lblMinistries;
  11. protected $lstRoleType;
  12. protected $lblDomainActive;
  13. protected $rblLoginActive;
  14. protected $lblDateLastLogin;
  15. protected $rblPermissionArray = array();
  16. protected $rblMinistryArray = array();
  17. protected $txtNewPassword;
  18. protected $txtConfirmPassword;
  19. protected $btnSave;
  20. protected $btnCancel;
  21. protected function Form_Create() {
  22. // Load and validate the Staff Person we're trying to view
  23. $this->objLogin = Login::Load(QApplication::PathInfo(0));
  24. if (!$this->objLogin) QApplication::Redirect('/admin/users');
  25. $this->strPageTitle .= $this->objLogin->Name;
  26. // Display: Username
  27. $this->lblUsername = new QLabel($this);
  28. $this->lblUsername->Name = 'Username';
  29. $this->lblUsername->Text = $this->objLogin->Username;
  30. // Display: Email
  31. $this->lblEmail = new QLabel($this);
  32. $this->lblEmail->Name = 'Email';
  33. if ($this->objLogin->Email)
  34. $this->lblEmail->Text = $this->objLogin->Email;
  35. else {
  36. $this->lblEmail->Text = 'none';
  37. $this->lblEmail->CssClass = 'na';
  38. }
  39. // Display Ministry Involvement Information
  40. $this->lblMinistries = new QLabel($this);
  41. $this->lblMinistries->Name = 'Ministry Involvement';
  42. $strArray = array();
  43. foreach ($this->objLogin->GetMinistryArray() as $objMinistry) $strArray[] = QApplication::HtmlEntities($objMinistry->Name);
  44. $this->lblMinistries->Text = implode(' &nbsp;&bull;&nbsp; ', $strArray);
  45. if (!$this->lblMinistries->Text) {
  46. $this->lblMinistries->CssClass = 'na';
  47. $this->lblMinistries->Text = 'n/a';
  48. }
  49. $this->lblMinistries->HtmlEntities = false;
  50. foreach (Ministry::LoadAll(QQ::OrderBy(QQN::Ministry()->Name)) as $objMinistry) {
  51. $rblMinistry = new QRadioButtonList($this);
  52. $rblMinistry->Name = $objMinistry->Name;
  53. if (in_array($objMinistry->Name,$strArray)) {
  54. $rblMinistry->AddItem('Yes',$objMinistry->Id,true);
  55. $rblMinistry->AddItem('No', 0, false);
  56. } else {
  57. $rblMinistry->AddItem('Yes', $objMinistry->Id, false);
  58. $rblMinistry->AddItem('No', 0, true);
  59. }
  60. $rblMinistry->RepeatColumns = 2;
  61. $this->rblMinistryArray[] = $rblMinistry;
  62. }
  63. $this->lstRoleType = new QListBox($this);
  64. $this->lstRoleType->Name = 'Role';
  65. foreach (RoleType::$NameArray as $intKey=>$strName)
  66. $this->lstRoleType->AddItem($strName, $intKey, $this->objLogin->RoleTypeId == $intKey);
  67. $this->lblDomainActive = new QLabel($this);
  68. $this->lblDomainActive->Name = 'Domain Account Active';
  69. $this->lblDomainActive->Text = ($this->objLogin->DomainActiveFlag) ? 'Yes' : 'No';
  70. $this->rblLoginActive = new QRadioButtonList($this);
  71. $this->rblLoginActive->Name = 'ChMS Login Enabled';
  72. $this->rblLoginActive->AddItem('Yes', true, ($this->objLogin->LoginActiveFlag));
  73. $this->rblLoginActive->AddItem('No', false, (!$this->objLogin->LoginActiveFlag));
  74. $this->rblLoginActive->RepeatColumns = 2;
  75. foreach (PermissionType::$NameArray as $intId => $strName) {
  76. $rblPermission = new QRadioButtonList($this);
  77. $rblPermission->Name = 'Can ' . $strName;
  78. $rblPermission->AddItem('Yes', $intId, ($this->objLogin->IsPermissionAllowed($intId)));
  79. $rblPermission->AddItem('No', 0, (!$this->objLogin->IsPermissionAllowed($intId)));
  80. $rblPermission->RepeatColumns = 2;
  81. $this->rblPermissionArray[] = $rblPermission;
  82. }
  83. $this->lblDateLastLogin = new QLabel($this);
  84. $this->lblDateLastLogin->Name = 'Date of Last ChMS Access';
  85. if ($this->objLogin->DateLastLogin) {
  86. $this->lblDateLastLogin->Text = $this->objLogin->DateLastLogin->ToString('MMMM D YYYY') . ' at ' . $this->objLogin->DateLastLogin->ToString('h:mmz');
  87. } else {
  88. $this->lblDateLastLogin->Text = 'None';
  89. $this->lblDateLastLogin->CssClass = 'na';
  90. }
  91. $this->txtNewPassword = new QTextBox($this);
  92. $this->txtNewPassword->Name = 'Reset Password to: ';
  93. $this->txtNewPassword->TextMode = QTextMode::Password;
  94. $this->txtConfirmPassword = new QTextBox($this);
  95. $this->txtConfirmPassword->Name = "Confirm Password";
  96. $this->txtConfirmPassword->TextMode = QTextMode::Password;
  97. // Add controls and stuff for Editable pages
  98. $this->btnSave = new QButton($this);
  99. $this->btnSave->Text = 'Update';
  100. $this->btnSave->AddAction(new QClickEvent(), new QAjaxAction('btnSave_Click'));
  101. $this->btnSave->CssClass = 'primary';
  102. $this->btnCancel = new QLinkButton($this);
  103. $this->btnCancel->Text = 'Cancel';
  104. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxAction('btnCancel_Click'));
  105. $this->btnCancel->AddAction(new QClickEvent(), new QTerminateAction());
  106. $this->btnCancel->CssClass = 'cancel';
  107. }
  108. public function btnSave_Click() {
  109. $this->objLogin->LoginActiveFlag = $this->rblLoginActive->SelectedValue;
  110. $this->objLogin->RoleTypeId = $this->lstRoleType->SelectedValue;
  111. $intBitmap = 0;
  112. foreach ($this->rblPermissionArray as $rblPermission) {
  113. $intBitmap = $intBitmap | $rblPermission->SelectedValue;
  114. }
  115. // Update ministries associated
  116. $this->objLogin->UnassociateAllMinistries();
  117. foreach ($this->rblMinistryArray as $rblMinistry) {
  118. $objMinistry = Ministry::LoadById($rblMinistry->SelectedValue);
  119. if ($objMinistry) $objMinistry->AssociateLogin($this->objLogin);
  120. }
  121. $this->objLogin->PermissionBitmap = $intBitmap;
  122. if ($this->txtNewPassword->Text == $this->txtConfirmPassword->Text) {
  123. if (strlen(trim($this->txtNewPassword->Text)) != 0) {
  124. $this->objLogin->SetPasswordCache($this->txtNewPassword->Text);
  125. }
  126. }
  127. $this->objLogin->Save();
  128. QApplication::Redirect('/admin/users/');
  129. }
  130. public function btnCancel_Click() {
  131. QApplication::Redirect('/admin/users/');
  132. }
  133. }
  134. AdminUsersForm::Run('AdminUsersForm');
  135. ?>