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.

229 lines
9.7 KiB

13 years ago
  1. <?php
  2. /**
  3. * AccountAddressEditPanel - provides a panel for user viewing and modification of an address
  4. *
  5. *@author Erik Winn <erikwinnmail@yahoo.com>
  6. *
  7. *
  8. * $Id: AccountAddressEditPanel.class.php 322 2008-10-24 20:30:55Z erikwinn $
  9. *@version 0.1
  10. *
  11. *@copyright (C) 2008 by Erik Winn
  12. *@license GPL v.2
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  24. *
  25. * @package Quasi
  26. * @subpackage Classes
  27. */
  28. class AccountAddressEditPanel extends QPanel
  29. {
  30. // Local instance of the AddressMetaControl
  31. public $mctAddress;
  32. protected $objControlBlock;
  33. protected $objParentBlock;
  34. // Controls for Address's Data Fields
  35. public $txtTitle;
  36. public $lstMyPeople;
  37. public $txtStreet1;
  38. public $txtStreet2;
  39. public $txtSuburb;
  40. public $txtCity;
  41. public $txtCounty;
  42. public $lstZone;
  43. public $lstCountry;
  44. public $txtPostalCode;
  45. public $lstType;
  46. // Other Controls
  47. public $btnSave;
  48. public $btnDelete;
  49. public $btnCancel;
  50. public $btnAddPerson;
  51. // Callback
  52. protected $strClosePanelMethod;
  53. public function __construct($objParentObject,
  54. $objControlBlock,
  55. $strClosePanelMethod,
  56. $intId = null,
  57. $strControlId = null)
  58. {
  59. try {
  60. parent::__construct($objParentObject, $strControlId);
  61. } catch (QCallerException $objExc) {
  62. $objExc->IncrementOffset();
  63. throw $objExc;
  64. }
  65. $this->objControlBlock =& $objControlBlock;
  66. $this->objParentBlock =& $objParentObject;
  67. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/AccountAddressEditPanel.tpl.php';
  68. $this->strClosePanelMethod = $strClosePanelMethod;
  69. $this->mctAddress = AddressMetaControl::Create($this, $intId);
  70. // Call MetaControl's methods to create qcontrols based on Address's data fields
  71. $this->txtTitle = $this->mctAddress->txtTitle_Create();
  72. $this->txtTitle->Name = 'Address Title: ';
  73. $this->lstMyPeople = $this->mctAddress->lstMyPeople_Create($this->objControlBlock->Account->PersonId);
  74. $this->lstMyPeople->Name = 'Address for : ';
  75. $this->txtStreet1 = $this->mctAddress->txtStreet1_Create();
  76. $this->txtStreet1->Name = 'Street :';
  77. $this->txtStreet2 = $this->mctAddress->txtStreet2_Create();
  78. $this->txtStreet2->Name = 'Street 2 or Apt.#:';
  79. $this->txtSuburb = $this->mctAddress->txtSuburb_Create();
  80. $this->txtSuburb->Name = 'Suburb :';
  81. $this->txtCity = $this->mctAddress->txtCity_Create();
  82. $this->txtCity->Name = 'City :';
  83. $this->txtCounty = $this->mctAddress->txtCounty_Create();
  84. $this->txtCounty->Name = 'County/District :';
  85. $this->lstZone = $this->mctAddress->lstZone_Create();
  86. $this->lstZone->Name = 'State/Province :';
  87. $this->lstCountry = $this->mctAddress->lstCountry_Create();
  88. $this->lstCountry->Name = 'Country :';
  89. $this->txtPostalCode = $this->mctAddress->txtPostalCode_Create();
  90. $this->txtPostalCode->Name = 'Zip/Postal Code :';
  91. $this->lstType = $this->mctAddress->lstType_Create();
  92. $this->lstType->Name = 'Type of Address :';
  93. // Create Buttons and Actions
  94. $this->btnAddPerson = new QButton($this);
  95. $this->btnAddPerson->Text = QApplication::Translate('Add a Person');
  96. if(IndexPage::$blnAjaxOk)
  97. $this->btnAddPerson->AddAction(new QClickEvent(), new QAjaxControlAction($this->objParentBlock, 'btnAddPerson_Click'));
  98. else
  99. $this->btnAddPerson->AddAction(new QClickEvent(), new QServerControlAction($this->objParentBlock, 'btnAddPerson_Click'));
  100. $this->btnSave = new QButton($this);
  101. $this->btnSave->Text = QApplication::Translate('Save');
  102. if(IndexPage::$blnAjaxOk)
  103. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  104. else
  105. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click'));
  106. $this->btnSave->CausesValidation = $this;
  107. $this->btnCancel = new QButton($this);
  108. $this->btnCancel->Text = QApplication::Translate('Cancel');
  109. if(IndexPage::$blnAjaxOk)
  110. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  111. else
  112. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click'));
  113. $this->btnDelete = new QButton($this);
  114. $this->btnDelete->Text = QApplication::Translate('Delete');
  115. $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('Address') . '?'));
  116. if(IndexPage::$blnAjaxOk)
  117. $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
  118. else
  119. $this->btnDelete->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnDelete_Click'));
  120. $this->btnDelete->Visible = $this->mctAddress->EditMode;
  121. }
  122. public function btnSave_Click($strFormId, $strControlId, $strParameter)
  123. {
  124. if( '' == $this->txtTitle->Text)
  125. {
  126. if( AddressType::Primary == $this->lstType->SelectedValue )
  127. $this->txtTitle->Text = 'Primary Address';
  128. else
  129. {
  130. $aryPersons = Person::QueryArray(
  131. QQ::OrCondition(
  132. QQ::Equal( QQN::Person()->Id, $this->objControlBlock->Account->PersonId),
  133. QQ::Equal( QQN::Person()->OwnerPersonId, $this->objControlBlock->Account->PersonId)
  134. ));
  135. foreach( $aryPersons as $objPerson )
  136. $aryPersonIds[] = $objPerson->Id;
  137. if(AddressType::Shipping == $this->lstType->SelectedValue)
  138. {
  139. $this->txtTitle->Text = 'Shipping Address';
  140. $intCount = Address::QueryCount(
  141. QQ::AndCondition(
  142. QQ::In( QQN::Address()->PersonId, $aryPersonIds),
  143. QQ::Equal( QQN::Address()->TypeId, AddressType::Shipping)
  144. ));
  145. }
  146. elseif(AddressType::Billing == $this->lstType->SelectedValue)
  147. {
  148. $this->txtTitle->Text = 'Billing Address';
  149. $intCount = Address::QueryCount(
  150. QQ::AndCondition(
  151. QQ::In( QQN::Address()->PersonId, $aryPersonIds),
  152. QQ::Equal( QQN::Address()->TypeId, AddressType::Billing)
  153. ));
  154. }
  155. else
  156. {
  157. $this->txtTitle->Text = 'Extra Address';
  158. $intCount = Address::QueryCount(
  159. QQ::AndCondition(
  160. QQ::In( QQN::Address()->PersonId, $aryPersonIds),
  161. QQ::NotEqual( QQN::Address()->TypeId, AddressType::Billing),
  162. QQ::NotEqual( QQN::Address()->TypeId, AddressType::Shipping)
  163. ));
  164. }
  165. $this->txtTitle->Text .= ' ' . $intCount;
  166. }
  167. }
  168. $this->mctAddress->SaveAddress();
  169. $this->CloseSelf(true);
  170. }
  171. public function btnDelete_Click($strFormId, $strControlId, $strParameter)
  172. {
  173. if( Address::CountByPersonId($this->objControlBlock->Account->PersonId) > 1 )
  174. $this->mctAddress->DeleteAddress();
  175. $this->CloseSelf(true);
  176. }
  177. public function btnCancel_Click($strFormId, $strControlId, $strParameter)
  178. {
  179. $this->CloseSelf(false);
  180. }
  181. // Close Myself and Call ClosePanelMethod Callback
  182. protected function CloseSelf($blnChangesMade)
  183. {
  184. $strMethod = $this->strClosePanelMethod;
  185. $this->objControlBlock->$strMethod($blnChangesMade);
  186. }
  187. public function __get($strName)
  188. {
  189. switch ($strName)
  190. {
  191. case 'Account':
  192. return $this->objControlBlock->Account ;
  193. default:
  194. try {
  195. return parent::__get($strName);
  196. } catch (QCallerException $objExc) {
  197. $objExc->IncrementOffset();
  198. throw $objExc;
  199. }
  200. }
  201. }
  202. }
  203. ?>