A Qcodo based CMS/ecommerce framework
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.

267 lines
11 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("CREATEACCOUNTMODULE.CLASS.PHP")){
  4. define("CREATEACCOUNTMODULE.CLASS.PHP",1);
  5. /**
  6. * Class CreateAccountModule - a registration page module
  7. *@author Erik Winn <erikwinnmail@yahoo.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. * $Id: CreateAccountModule.class.php 524 2009-05-12 16:23:30Z bbearnes $
  20. *@version 0.1
  21. *
  22. *@copyright (C) 2008 by Erik Winn
  23. *@license GPL v.2
  24. This program is free software; you can redistribute it and/or modify
  25. it under the terms of the GNU General Public License as published by
  26. the Free Software Foundation; either version 2 of the License, or
  27. (at your option) any later version.
  28. This program is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. GNU General Public License for more details.
  32. You should have received a copy of the GNU General Public License
  33. along with this program; if not, write to the Free Software
  34. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  35. *
  36. *@package Quasi
  37. * @subpackage Modules
  38. */
  39. class CreateAccountModule extends QPanel
  40. {
  41. protected $objParentObject;
  42. /** ******************************
  43. * Section: Local object instances
  44. ******************************** */
  45. protected $objAccount;
  46. protected $objPerson;
  47. protected $objAddress;
  48. /** ******************************
  49. * Section: Object MetaControls
  50. ******************************** */
  51. protected $mctAccount;
  52. protected $mctPerson;
  53. protected $mctAddress;
  54. /** ******************************
  55. * Section: Control fields
  56. ******************************** */
  57. // Controls for Account's Data Fields
  58. public $txtUsername;
  59. public $txtPassword;
  60. public $txtPassword2;
  61. // Controls for Person's Data Fields
  62. public $txtFirstName;
  63. public $txtMiddleName;
  64. public $txtLastName;
  65. public $txtNamePrefix;
  66. public $txtNameSuffix;
  67. public $txtCompanyName;
  68. // Controls for Address's Data Fields
  69. public $txtTitle;
  70. public $txtStreet1;
  71. public $txtStreet2;
  72. public $txtSuburb;
  73. public $txtCity;
  74. public $txtCounty;
  75. public $lstZone;
  76. public $lstCountry;
  77. public $txtPostalCode;
  78. public $lstAddressType;
  79. public $txtEmailAddress;
  80. public $txtPhoneNumber;
  81. // Action Button Controls
  82. public $btnSave;
  83. public $btnReset;
  84. public $btnCancel;
  85. /**
  86. * Module constructor
  87. * NOTE: This module ignores the required extra parameters ..
  88. *@param ContentBlockView - parent controller object.
  89. *@param mixed - extra parameters, ignored
  90. */
  91. public function __construct( ContentBlockView $objParentObject, $mixParameters=null)
  92. {
  93. //Parent should always be a ContentBlockView
  94. $this->objParentObject =& $objParentObject;
  95. //make sure momma can do this ..
  96. try {
  97. parent::__construct($this->objParentObject/*, $this->strCssId*/);
  98. } catch (QCallerException $objExc) {
  99. $objExc->IncrementOffset();
  100. throw $objExc;
  101. }
  102. // We'll let the MetaControls create the new objects - this gives us a nice connection
  103. // to relevant fields and saving methods immediately.
  104. $this->mctAccount = AccountMetaControl::Create($this);
  105. $this->mctPerson = PersonMetaControl::Create($this);
  106. $this->mctAddress = AddressMetaControl::Create($this);
  107. // Use Account MetaControl's methods to create qcontrols based on Account's data fields
  108. $this->txtUsername = $this->mctAccount->txtUsername_Create('username', true);
  109. $this->txtUsername->Required = true;
  110. $this->txtUsername->Name = Quasi::Translate('Login Name');
  111. $this->txtPassword = $this->mctAccount->txtPassword_Create('password');
  112. $this->txtPassword->TextMode = QTextMode::Password;
  113. $this->txtPassword->Required = true;
  114. $this->txtPassword2 = new QTextBox($this, 'password2');
  115. $this->txtPassword2->TextMode = QTextMode::Password;
  116. $this->txtPassword2->Name = Quasi::Translate('Confirm Password');
  117. $this->txtPassword2->Required = true;
  118. //Person MetaControl methods
  119. $this->txtNamePrefix = $this->mctPerson->txtNamePrefix_Create();
  120. $this->txtNamePrefix->Name = Quasi::Translate('Mr., Ms., Dr., etc. ');
  121. $this->txtFirstName = $this->mctPerson->txtFirstName_Create();
  122. $this->txtFirstName->Required = true;
  123. $this->txtMiddleName = $this->mctPerson->txtMiddleName_Create();
  124. $this->txtLastName = $this->mctPerson->txtLastName_Create();
  125. $this->txtLastName->Required = true;
  126. $this->txtNameSuffix = $this->mctPerson->txtNameSuffix_Create();
  127. $this->txtNameSuffix->Name = Quasi::Translate('Jr., Sr., PhD, etc. ');
  128. $this->txtCompanyName = $this->mctPerson->txtCompanyName_Create();
  129. $this->txtEmailAddress = $this->mctPerson->txtEmailAddress_Create();
  130. $this->txtEmailAddress->Required = true;
  131. $this->txtEmailAddress->Name =Quasi::Translate('Email Address');
  132. $this->txtPhoneNumber = $this->mctPerson->txtPhoneNumber_Create();
  133. $this->txtPhoneNumber->Name =Quasi::Translate('Phone Number');
  134. // Address MetaControl methods
  135. $this->txtTitle = $this->mctAddress->txtTitle_Create();
  136. $this->txtTitle->Name = 'Address Title: ';
  137. $this->txtStreet1 = $this->mctAddress->txtStreet1_Create();
  138. $this->txtStreet1->Name = 'Street :';
  139. $this->txtStreet1->Required = true;
  140. $this->txtStreet2 = $this->mctAddress->txtStreet2_Create();
  141. $this->txtStreet2->Name = 'Street 2 or Apt.#:';
  142. $this->txtSuburb = $this->mctAddress->txtSuburb_Create();
  143. $this->txtSuburb->Name = 'Suburb :';
  144. $this->txtCity = $this->mctAddress->txtCity_Create();
  145. $this->txtCity->Name = 'City :';
  146. $this->txtCity->Required = true;
  147. $this->txtCounty = $this->mctAddress->txtCounty_Create();
  148. $this->txtCounty->Name = 'County/District :';
  149. $this->lstZone = $this->mctAddress->lstZone_Create();
  150. $this->lstZone->Name = 'State/Province :';
  151. $this->lstCountry = $this->mctAddress->lstCountry_Create();
  152. $this->lstCountry->Name = 'Country :';
  153. $this->lstCountry->Required = true;
  154. $this->txtPostalCode = $this->mctAddress->txtPostalCode_Create();
  155. $this->txtPostalCode->Name = 'Zip/Postal Code :';
  156. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/CreateAccountModule.tpl.php';
  157. // Create Buttons and Actions on this Form
  158. $this->btnSave = new QButton($this,'createAccountSaveButton');
  159. $this->btnSave->Text = Quasi::Translate('Register');
  160. if(IndexPage::$blnAjaxOk)
  161. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  162. else
  163. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click'));
  164. $this->btnSave->CausesValidation = true;
  165. $this->btnCancel = new QButton($this,'createAccountCancelButton');
  166. $this->btnCancel->Text = Quasi::Translate('Cancel');
  167. if(IndexPage::$blnAjaxOk)
  168. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  169. else
  170. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click'));
  171. $this->btnReset = new QButton($this,'createAccountResetButton');
  172. $this->btnReset->Text = Quasi::Translate('Reset');
  173. if(IndexPage::$blnAjaxOk)
  174. $this->btnReset->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnReset_Click'));
  175. else
  176. $this->btnReset->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnReset_Click'));
  177. }
  178. public function Validate()
  179. {
  180. $blnToReturn = true;
  181. if($this->txtPassword->Text !== $this->txtPassword2->Text )
  182. {
  183. $this->txtPassword->Warning = 'Passwords do not match!';
  184. $blnToReturn = false;
  185. }
  186. return $blnToReturn;
  187. }
  188. public function btnSave_Click($strFormId, $strControlId, $strParameter)
  189. {
  190. $this->objAccount = $this->mctAccount->Account;
  191. $this->objPerson = $this->mctPerson->Person;
  192. $this->objAddress = $this->mctAddress->Address;
  193. //Account Metacontrol will encrypt password ..
  194. $this->objAccount->Password = $this->txtPassword->Text;
  195. //This will give us an Id number for the person, which the Account needs for creation.
  196. $this->mctPerson->SavePerson();
  197. //Make the appropriate types and foriegn keys ..
  198. $this->objAccount->PersonId = $this->objPerson->Id;
  199. $this->objAddress->PersonId = $this->objPerson->Id;
  200. $this->objAddress->TypeId = AddressType::Primary;
  201. // go ..
  202. $this->mctAccount->SaveAccount();
  203. $this->mctAddress->SaveAddress();
  204. $this->mctPerson->SavePerson();
  205. $this->objAccount->Online = true;
  206. $this->objAccount->LastLogin = date("Y-m-d H:i:s");
  207. $this->objAccount->UpdateLoginState();
  208. $_SESSION["AccountLogin"] = serialize($this->objAccount);
  209. if(Quasi::IsBrowser( QBrowserType::Opera ))
  210. {
  211. ob_clean();
  212. header('Location: http://www.batchpcb.com/index.php/AccountHome/PcbDesign');
  213. exit;
  214. }
  215. Quasi::Redirect(__QUASI_SUBDIRECTORY__ . LOGIN_REDIRECT );
  216. }
  217. public function btnReset_Click($strFormId, $strControlId, $strParameter)
  218. {
  219. $this->mctAccount->Refresh();
  220. $this->mctPerson->Refresh();
  221. $this->mctAddress->Refresh();
  222. }
  223. public function btnCancel_Click($strFormId, $strControlId, $strParameter)
  224. {
  225. Quasi::Redirect( __QUASI_SUBDIRECTORY__ . '/index.php/Home' );
  226. }
  227. }//end class
  228. }//end define
  229. ?>