A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
8.5 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  3. if (!defined("CREATEACCOUNTMODULE.CLASS.PHP")){
  4. define("CREATEACCOUNTMODULE.CLASS.PHP",1);
  5. /**
  6. * Class CreateAccountModule - a registration page module
  7. *@author Erik Winn <sidewalksoftware@gmail.com>
  8. *
  9. * This module provides a center page block with a registration page.
  10. * On success the user is redirected to his/her UserPage.
  11. * On failure, the entry fields are redrawn and an error message
  12. * is displayed next to any fields that are incorrect or required.
  13. *
  14. * The module stores the Account, Person, Address in the respective tables
  15. * - all of which are associated with the Person. An Account can have _one_
  16. * and only one Person, a Person may have many Persons and Addresses
  17. * which will be associated with the original Person for the Account.
  18. *
  19. *@version 0.3
  20. *
  21. *@package Quinta
  22. * @subpackage Modules
  23. */
  24. class CreateAccountModule extends QPanel{
  25. protected $objParentObject;
  26. /** ******************************
  27. * Section: Local object instances
  28. ******************************** */
  29. protected $objAccount;
  30. protected $objPerson;
  31. protected $objAddress;
  32. /** ******************************
  33. * Section: Object MetaControls
  34. ******************************** */
  35. protected $mctAccount;
  36. protected $mctPerson;
  37. protected $mctAddress;
  38. /** ******************************
  39. * Section: Control fields
  40. ******************************** */
  41. // Controls for Account's Data Fields
  42. public $txtUsername;
  43. public $txtPassword;
  44. public $txtPassword2;
  45. // Controls for Person's Data Fields
  46. public $txtFirstName;
  47. public $txtMiddleName;
  48. public $txtLastName;
  49. public $txtNamePrefix;
  50. public $txtNameSuffix;
  51. public $txtCompanyName;
  52. // Controls for Address's Data Fields
  53. public $txtTitle;
  54. public $txtStreet1;
  55. public $txtStreet2;
  56. public $txtSuburb;
  57. public $txtCity;
  58. public $txtCounty;
  59. public $lstZone;
  60. public $lstCountry;
  61. public $txtPostalCode;
  62. public $lstAddressType;
  63. // public $txtEmailAddress;
  64. // public $txtPhoneNumber;
  65. // Action Button Controls
  66. public $btnSave;
  67. public $btnReset;
  68. public $btnCancel;
  69. /**
  70. * Module constructor
  71. * NOTE: This module ignores the required extra parameters ..
  72. *@param ContentBlockController - parent controller object.
  73. *@param mixed - extra parameters, ignored
  74. */
  75. public function __construct( ContentBlockController $objParentObject, $mixParameters=null){
  76. //Parent should always be a ContentBlockController
  77. $this->objParentObject =& $objParentObject;
  78. try {
  79. parent::__construct($this->objParentObject/*, $this->strCssId*/);
  80. } catch (QCallerException $objExc) {
  81. $objExc->IncrementOffset();
  82. throw $objExc;
  83. }
  84. // We'll let the MetaControls create the new objects - this gives us a nice connection
  85. // to relevant fields and saving methods immediately.
  86. $this->mctAccount = AccountMetaControl::Create($this);
  87. $this->mctPerson = PersonMetaControl::Create($this);
  88. $this->mctAddress = AddressMetaControl::Create($this);
  89. // Use Account MetaControl's methods to create qcontrols based on Account's data fields
  90. $this->txtUsername = $this->mctAccount->txtUsername_Create('username', true);
  91. $this->txtUsername->Required = true;
  92. $this->txtUsername->Name = Quinta::Translate('Login Name');
  93. $this->txtPassword = $this->mctAccount->txtPassword_Create('password');
  94. $this->txtPassword->TextMode = QTextMode::Password;
  95. $this->txtPassword->Required = true;
  96. $this->txtPassword2 = new QTextBox($this, 'password2');
  97. $this->txtPassword2->TextMode = QTextMode::Password;
  98. $this->txtPassword2->Name = Quinta::Translate('Confirm Password');
  99. $this->txtPassword2->Required = true;
  100. //Person MetaControl methods
  101. $this->txtNamePrefix = $this->mctPerson->txtNamePrefix_Create();
  102. $this->txtNamePrefix->Name = Quinta::Translate('Mr., Ms., Dr., etc. ');
  103. $this->txtFirstName = $this->mctPerson->txtFirstName_Create();
  104. $this->txtFirstName->Required = true;
  105. $this->txtMiddleName = $this->mctPerson->txtMiddleName_Create();
  106. $this->txtLastName = $this->mctPerson->txtLastName_Create();
  107. $this->txtLastName->Required = true;
  108. $this->txtNameSuffix = $this->mctPerson->txtNameSuffix_Create();
  109. $this->txtNameSuffix->Name = Quinta::Translate('Jr., Sr., PhD, etc. ');
  110. $this->txtCompanyName = $this->mctPerson->txtCompanyName_Create();
  111. // $this->txtEmailAddress = $this->mctPerson->txtEmailAddress_Create();
  112. // $this->txtEmailAddress->Required = true;
  113. // $this->txtEmailAddress->Name =Quinta::Translate('Email Address');
  114. // $this->txtPhoneNumber = $this->mctPerson->txtPhoneNumber_Create();
  115. // $this->txtPhoneNumber->Name =Quinta::Translate('Phone Number');
  116. // Address MetaControl methods
  117. $this->txtTitle = $this->mctAddress->txtTitle_Create();
  118. $this->txtTitle->Name = 'Address Title: ';
  119. $this->txtStreet1 = $this->mctAddress->txtStreet1_Create();
  120. $this->txtStreet1->Name = 'Street :';
  121. $this->txtStreet1->Required = true;
  122. $this->txtStreet2 = $this->mctAddress->txtStreet2_Create();
  123. $this->txtStreet2->Name = 'Street 2 or Apt.#:';
  124. $this->txtSuburb = $this->mctAddress->txtSuburb_Create();
  125. $this->txtSuburb->Name = 'Suburb :';
  126. $this->txtCity = $this->mctAddress->txtCity_Create();
  127. $this->txtCity->Name = 'City :';
  128. $this->txtCity->Required = true;
  129. $this->txtCounty = $this->mctAddress->txtCounty_Create();
  130. $this->txtCounty->Name = 'County/District :';
  131. $this->lstZone = $this->mctAddress->lstZone_Create();
  132. $this->lstZone->Name = 'State/Province :';
  133. $this->lstCountry = $this->mctAddress->lstCountry_Create();
  134. $this->lstCountry->Name = 'Country :';
  135. $this->lstCountry->Required = true;
  136. $this->txtPostalCode = $this->mctAddress->txtPostalCode_Create();
  137. $this->txtPostalCode->Name = 'Zip/Postal Code :';
  138. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/CreateAccountModule.tpl.php';
  139. // Create Buttons and Actions on this Form
  140. $this->btnSave = new QButton($this,'createAccountSaveButton');
  141. $this->btnSave->Text = Quinta::Translate('Register');
  142. if(IndexPage::$blnAjaxOk)
  143. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  144. else
  145. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click'));
  146. $this->btnSave->CausesValidation = true;
  147. $this->btnCancel = new QButton($this,'createAccountCancelButton');
  148. $this->btnCancel->Text = Quinta::Translate('Cancel');
  149. if(IndexPage::$blnAjaxOk)
  150. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  151. else
  152. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click'));
  153. $this->btnReset = new QButton($this,'createAccountResetButton');
  154. $this->btnReset->Text = Quinta::Translate('Reset');
  155. if(IndexPage::$blnAjaxOk)
  156. $this->btnReset->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnReset_Click'));
  157. else
  158. $this->btnReset->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnReset_Click'));
  159. }
  160. public function Validate(){
  161. $blnToReturn = true;
  162. if($this->txtPassword->Text !== $this->txtPassword2->Text ){
  163. $this->txtPassword->Warning = 'Passwords do not match!';
  164. $blnToReturn = false;
  165. }
  166. return $blnToReturn;
  167. }
  168. public function btnSave_Click($strFormId, $strControlId, $strParameter){
  169. $this->objAccount = $this->mctAccount->Account;
  170. $this->objPerson = $this->mctPerson->Person;
  171. $this->objAddress = $this->mctAddress->Address;
  172. //Account Metacontrol will encrypt password ..
  173. $this->objAccount->Password = $this->txtPassword->Text;
  174. //This will give us an Id number for the person, which the Account needs for creation.
  175. $this->mctPerson->SavePerson();
  176. //Make the appropriate types and foriegn keys ..
  177. $this->objAccount->PersonId = $this->objPerson->Id;
  178. $this->objAddress->PersonId = $this->objPerson->Id;
  179. $this->objAddress->TypeId = AddressType::Primary;
  180. // go ..
  181. $this->mctAccount->SaveAccount();
  182. $this->mctAddress->SaveAddress();
  183. $this->mctPerson->SavePerson();
  184. $this->objAccount->Online = true;
  185. $this->objAccount->LastLogin = date("Y-m-d H:i:s");
  186. $this->objAccount->UpdateLoginState();
  187. $_SESSION["AccountLogin"] = serialize($this->objAccount);
  188. Quinta::Redirect(__QUINTA_SUBDIRECTORY__ . LOGIN_REDIRECT );
  189. }
  190. public function btnReset_Click($strFormId, $strControlId, $strParameter){
  191. $this->mctAccount->Refresh();
  192. $this->mctPerson->Refresh();
  193. $this->mctAddress->Refresh();
  194. }
  195. public function btnCancel_Click($strFormId, $strControlId, $strParameter){
  196. Quinta::Redirect( __QUINTA_SUBDIRECTORY__ . '/index.php/Home' );
  197. }
  198. }//end class
  199. }//end define
  200. ?>