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.

255 lines
11 KiB

13 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("ADDRESSSELECTIONMODULE.CLASS.PHP")){
  4. define("ADDRESSSELECTIONMODULE.CLASS.PHP",1);
  5. /**
  6. * AddressSelectionModule - provides a panel for selecting an address
  7. * This panel also offers options in the selection to add or edit an address. When the "Add" option
  8. * is selected in the dropdown list, the fields are converted to text boxes and the save button
  9. * appears. If the "Edit" option is selected the text boxes will contain the currently displayed
  10. * values for modification.
  11. *
  12. *@author Erik Winn <erikwinnmail@yahoo.com>
  13. *
  14. *
  15. * $Id: AddressSelectionModule.class.php 307 2008-10-21 18:34:09Z erikwinn $
  16. *@version 0.1
  17. *
  18. *@copyright (C) 2008 by Erik Winn
  19. *@license GPL v.2
  20. This program is free software; you can redistribute it and/or modify
  21. it under the terms of the GNU General Public License as published by
  22. the Free Software Foundation; either version 2 of the License, or
  23. (at your option) any later version.
  24. This program is distributed in the hope that it will be useful,
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. GNU General Public License for more details.
  28. You should have received a copy of the GNU General Public License
  29. along with this program; if not, write to the Free Software
  30. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  31. *
  32. * @package Quasi
  33. * @subpackage Views
  34. */
  35. class AddressSelectionModule extends QPanel
  36. {
  37. // Local instance of the AddressMetaControl
  38. protected $mctAddress;
  39. protected $objAddress;
  40. protected $objControlBlock;
  41. protected $objAccount;
  42. protected $blnModifiable;
  43. protected $intCurrentAddressId;
  44. protected $strRefreshAddressCallback;
  45. public $lstMyAddresses;
  46. // Controls that allow the viewing of Address's individual data fields
  47. public $lblTitle;
  48. public $lblPersonId;
  49. public $lblStreet1;
  50. public $lblStreet2;
  51. public $lblSuburb;
  52. public $lblCity;
  53. public $lblCounty;
  54. public $lblZoneId;
  55. public $lblCountryId;
  56. public $lblPostalCode;
  57. public $lblIsCurrent;
  58. public $lblTypeId;
  59. // Controls that allow the editing of Address's individual data fields
  60. public $txtTitle;
  61. public $lstMyPeople;
  62. public $txtStreet1;
  63. public $txtStreet2;
  64. public $txtSuburb;
  65. public $txtCity;
  66. public $txtCounty;
  67. public $lstZone;
  68. public $lstCountry;
  69. public $txtPostalCode;
  70. public $lstType;
  71. public $btnSave;
  72. public $btnCancel;
  73. public $objWaitIcon;
  74. public function __construct($objControlBlock,
  75. $strRefreshAddressCallback,
  76. $intAddressId = null,
  77. $blnModifiable = false,
  78. $strControlId = null)
  79. {
  80. try {
  81. parent::__construct($objControlBlock, $strControlId);
  82. } catch (QCallerException $objExc) {
  83. $objExc->IncrementOffset();
  84. throw $objExc;
  85. }
  86. $this->objAccount =& IndexPage::$objAccount;
  87. $this->objControlBlock =& $objControlBlock;
  88. $this->intCurrentAddressId = $intAddressId;
  89. $this->blnModifiable = $blnModifiable;
  90. $this->strRefreshAddressCallback = $strRefreshAddressCallback;
  91. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/AddressSelectionModule.tpl.php';
  92. $this->mctAddress = AddressMetaControl::Create($this, $intAddressId);
  93. $this->objAddress =& $this->mctAddress->Address;
  94. $this->objWaitIcon = new QWaitIcon($this);
  95. $this->init($intAddressId, $blnModifiable);
  96. }
  97. public function init( $intAddressId, $blnModifiable)
  98. {
  99. if( $blnModifiable || ! $intAddressId)
  100. {
  101. $this->txtTitle = $this->mctAddress->txtTitle_Create();
  102. $this->lstMyPeople = $this->mctAddress->lstMyPeople_Create($this->objAccount->PersonId);
  103. $this->lstMyPeople->Name = Quasi::Translate('Address for') . ' :';
  104. $this->txtStreet1 = $this->mctAddress->txtStreet1_Create();
  105. $this->txtStreet1->Name = Quasi::Translate('Street') . ' :';
  106. $this->txtStreet2 = $this->mctAddress->txtStreet2_Create();
  107. $this->txtStreet2->Name = Quasi::Translate('Street 2 or Apt') . '.# :';
  108. $this->txtSuburb = $this->mctAddress->txtSuburb_Create();
  109. $this->txtSuburb->Name = Quasi::Translate('Suburb') . ' :';
  110. $this->txtCity = $this->mctAddress->txtCity_Create();
  111. $this->txtCity->Name = Quasi::Translate('City') . ' :';
  112. $this->txtCounty = $this->mctAddress->txtCounty_Create();
  113. $this->txtCounty->Name = Quasi::Translate('County/District') . ' :';
  114. $this->lstZone = $this->mctAddress->lstZone_Create();
  115. $this->lstZone->Name = Quasi::Translate('State/Province') . ' :';
  116. $this->lstCountry = $this->mctAddress->lstCountry_Create();
  117. $this->lstCountry->Name = Quasi::Translate('Country') . ' :';
  118. $this->txtPostalCode = $this->mctAddress->txtPostalCode_Create();
  119. $this->txtPostalCode->Name = Quasi::Translate('Zip/Postal Code') . ' :';
  120. $this->lstType = $this->mctAddress->lstType_Create();
  121. $this->lstType->Name = Quasi::Translate('Type of Address') . ' :';
  122. //create buttons to save modifications ..
  123. $this->btnSave = new QButton($this);
  124. $this->btnSave->Text = QApplication::Translate('Save');
  125. if(IndexPage::$blnAjaxOk)
  126. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click', $this->objWaitIcon));
  127. else
  128. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click', $this->objWaitIcon));
  129. $this->btnSave->CausesValidation = $this;
  130. $this->btnCancel = new QButton($this);
  131. $this->btnCancel->Text = QApplication::Translate('Cancel');
  132. if(IndexPage::$blnAjaxOk)
  133. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click', $this->objWaitIcon));
  134. else
  135. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click', $this->objWaitIcon));
  136. }
  137. else
  138. {
  139. $this->lstMyAddresses = $this->mctAddress->lstMyAddresses_Create($this->objAccount);
  140. $this->lstMyAddresses->AddItem('Edit','Edit');
  141. $this->lstMyAddresses->AddItem('New','New');
  142. if(IndexPage::$blnAjaxOk)
  143. $this->lstMyAddresses->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMyAddresses_Selected', $this->objWaitIcon) );
  144. else
  145. $this->lstMyAddresses->AddAction(new QChangeEvent(), new QServerControlAction($this, 'lstMyAddresses_Selected', $this->objWaitIcon) );
  146. $this->lstMyAddresses->ActionParameter = $intAddressId;
  147. $this->lblPersonId = $this->mctAddress->lblPersonId_Create();
  148. $this->lblPersonId->Name = Quasi::Translate('Address for') . ' :';
  149. $this->lblStreet1 = $this->mctAddress->lblStreet1_Create();
  150. $this->lblStreet1->Name = Quasi::Translate('Street') . ' :';
  151. $this->lblStreet2 = $this->mctAddress->lblStreet2_Create();
  152. $this->lblStreet2->Name = Quasi::Translate('Street 2 or Apt') . '.# :';
  153. $this->lblSuburb = $this->mctAddress->lblSuburb_Create();
  154. $this->lblSuburb->Name = Quasi::Translate('Suburb') . ' :';
  155. $this->lblCity = $this->mctAddress->lblCity_Create();
  156. $this->lblCity->Name = Quasi::Translate('City') . ' :';
  157. $this->lblCounty = $this->mctAddress->lblCounty_Create();
  158. $this->lblCounty->Name = Quasi::Translate('County/District') . ' :';
  159. $this->lblZoneId = $this->mctAddress->lblZoneId_Create();
  160. $this->lblZoneId->Name = Quasi::Translate('State/Province') . ' :';
  161. $this->lblCountryId = $this->mctAddress->lblCountryId_Create();
  162. $this->lblCountryId->Name = Quasi::Translate('Country') . ' :';
  163. $this->lblPostalCode = $this->mctAddress->lblPostalCode_Create();
  164. $this->lblPostalCode->Name = Quasi::Translate('Zip/Postal Code') . ' :';
  165. $this->lblTypeId = $this->mctAddress->lblTypeId_Create();
  166. $this->lblTypeId->Name = Quasi::Translate('Type of Address') . ' :';
  167. }
  168. }
  169. /**
  170. * This function is called when the user selects an Item from the address list. The parameter that
  171. * passed is the id of the origianally displayed address. The selected address is obtained directly
  172. * from the listbox and objAddress is set to be this address before issueing the callback.
  173. */
  174. public function lstMyAddresses_Selected($strFormId, $strControlId, $intAddressId)
  175. {
  176. $strCallback = $this->strRefreshAddressCallback;
  177. $strAction = $this->lstMyAddresses->SelectedValue;
  178. if(! is_numeric($strAction) )
  179. $this->objControlBlock->$strCallback($this->intCurrentAddressId, $strAction);
  180. else
  181. {
  182. $objAddress = Address::Load($strAction);
  183. if($objAddress instanceof Address)
  184. $this->objAddress = $objAddress;
  185. $this->objControlBlock->$strCallback($strAction);
  186. }
  187. }
  188. public function btnSave_Click($strFormId, $strControlId, $strParameter)
  189. {
  190. $strCallback = $this->strRefreshAddressCallback;
  191. $this->mctAddress->SaveAddress();
  192. $this->objAddress = $this->mctAddress->Address;
  193. $this->objControlBlock->$strCallback($this->mctAddress->Address->Id, 'Save');
  194. }
  195. public function btnCancel_Click($strFormId, $strControlId, $intAddressId)
  196. {
  197. $strCallback = $this->strRefreshAddressCallback;
  198. $this->objControlBlock->$strCallback($this->intCurrentAddressId);
  199. }
  200. public function __get($strName)
  201. {
  202. switch ($strName)
  203. {
  204. case 'Modifiable':
  205. return $this->blnModifiable;
  206. case 'Address':
  207. return $this->objAddress;
  208. default:
  209. try {
  210. return parent::__get($strName);
  211. } catch (QCallerException $objExc) {
  212. $objExc->IncrementOffset();
  213. throw $objExc;
  214. }
  215. }
  216. }
  217. }//end class
  218. }//end define
  219. ?>