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.

222 lines
8.5 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  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 <sidewalksoftware@gmail.com>
  13. *
  14. *@version 0.3
  15. *
  16. * @package Quinta
  17. * @subpackage Modules
  18. */
  19. class AddressSelectionModule extends QPanel{
  20. // Local instance of the AddressMetaControl
  21. protected $mctAddress;
  22. protected $objAddress;
  23. protected $objControlBlock;
  24. protected $objAccount;
  25. protected $blnModifiable;
  26. protected $intCurrentAddressId;
  27. protected $strRefreshAddressCallback;
  28. public $lstMyAddresses;
  29. // Controls that allow the viewing of Address's individual data fields
  30. public $lblTitle;
  31. public $lblPersonId;
  32. public $lblStreet1;
  33. public $lblStreet2;
  34. public $lblSuburb;
  35. public $lblCity;
  36. public $lblCounty;
  37. public $lblZoneId;
  38. public $lblCountryId;
  39. public $lblPostalCode;
  40. public $lblIsCurrent;
  41. public $lblTypeId;
  42. // Controls that allow the editing of Address's individual data fields
  43. public $txtTitle;
  44. public $lstMyPeople;
  45. public $txtStreet1;
  46. public $txtStreet2;
  47. public $txtSuburb;
  48. public $txtCity;
  49. public $txtCounty;
  50. public $lstZone;
  51. public $lstCountry;
  52. public $txtPostalCode;
  53. public $lstType;
  54. public $btnSave;
  55. public $btnCancel;
  56. public $objWaitIcon;
  57. public function __construct($objControlBlock,
  58. $strRefreshAddressCallback,
  59. $intAddressId = null,
  60. $blnModifiable = false,
  61. $strControlId = null)
  62. {
  63. try {
  64. parent::__construct($objControlBlock, $strControlId);
  65. } catch (QCallerException $objExc) {
  66. $objExc->IncrementOffset();
  67. throw $objExc;
  68. }
  69. $this->objAccount =& IndexPage::$objAccount;
  70. $this->objControlBlock =& $objControlBlock;
  71. $this->intCurrentAddressId = $intAddressId;
  72. $this->blnModifiable = $blnModifiable;
  73. $this->strRefreshAddressCallback = $strRefreshAddressCallback;
  74. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/AddressSelectionModule.tpl.php';
  75. $this->mctAddress = AddressMetaControl::Create($this, $intAddressId);
  76. $this->objAddress =& $this->mctAddress->Address;
  77. $this->objWaitIcon = new QWaitIcon($this);
  78. $this->init($intAddressId, $blnModifiable);
  79. }
  80. public function init( $intAddressId, $blnModifiable){
  81. if( $blnModifiable || ! $intAddressId){
  82. $this->txtTitle = $this->mctAddress->txtTitle_Create();
  83. $this->lstMyPeople = $this->mctAddress->lstMyPeople_Create($this->objAccount->PersonId);
  84. $this->lstMyPeople->Name = Quinta::Translate('Address for') . ' :';
  85. $this->txtStreet1 = $this->mctAddress->txtStreet1_Create();
  86. $this->txtStreet1->Name = Quinta::Translate('Street') . ' :';
  87. $this->txtStreet2 = $this->mctAddress->txtStreet2_Create();
  88. $this->txtStreet2->Name = Quinta::Translate('Street 2 or Apt') . '.# :';
  89. $this->txtSuburb = $this->mctAddress->txtSuburb_Create();
  90. $this->txtSuburb->Name = Quinta::Translate('Suburb') . ' :';
  91. $this->txtCity = $this->mctAddress->txtCity_Create();
  92. $this->txtCity->Name = Quinta::Translate('City') . ' :';
  93. $this->txtCounty = $this->mctAddress->txtCounty_Create();
  94. $this->txtCounty->Name = Quinta::Translate('County/District') . ' :';
  95. $this->lstZone = $this->mctAddress->lstZone_Create();
  96. $this->lstZone->Name = Quinta::Translate('State/Province') . ' :';
  97. $this->lstCountry = $this->mctAddress->lstCountry_Create();
  98. $this->lstCountry->Name = Quinta::Translate('Country') . ' :';
  99. $this->txtPostalCode = $this->mctAddress->txtPostalCode_Create();
  100. $this->txtPostalCode->Name = Quinta::Translate('Zip/Postal Code') . ' :';
  101. $this->lstType = $this->mctAddress->lstType_Create();
  102. $this->lstType->Name = Quinta::Translate('Type of Address') . ' :';
  103. //create buttons to save modifications ..
  104. $this->btnSave = new QButton($this);
  105. $this->btnSave->Text = QApplication::Translate('Save');
  106. if(IndexPage::$blnAjaxOk)
  107. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click', $this->objWaitIcon));
  108. else
  109. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click', $this->objWaitIcon));
  110. $this->btnSave->CausesValidation = $this;
  111. $this->btnCancel = new QButton($this);
  112. $this->btnCancel->Text = QApplication::Translate('Cancel');
  113. if(IndexPage::$blnAjaxOk)
  114. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click', $this->objWaitIcon));
  115. else
  116. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click', $this->objWaitIcon));
  117. }else{
  118. $this->lstMyAddresses = $this->mctAddress->lstMyAddresses_Create($this->objAccount);
  119. $this->lstMyAddresses->AddItem('Edit','Edit');
  120. $this->lstMyAddresses->AddItem('New','New');
  121. if(IndexPage::$blnAjaxOk)
  122. $this->lstMyAddresses->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMyAddresses_Selected', $this->objWaitIcon) );
  123. else
  124. $this->lstMyAddresses->AddAction(new QChangeEvent(), new QServerControlAction($this, 'lstMyAddresses_Selected', $this->objWaitIcon) );
  125. $this->lstMyAddresses->ActionParameter = $intAddressId;
  126. $this->lblPersonId = $this->mctAddress->lblPersonId_Create();
  127. $this->lblPersonId->Name = Quinta::Translate('Address for') . ' :';
  128. $this->lblStreet1 = $this->mctAddress->lblStreet1_Create();
  129. $this->lblStreet1->Name = Quinta::Translate('Street') . ' :';
  130. $this->lblStreet2 = $this->mctAddress->lblStreet2_Create();
  131. $this->lblStreet2->Name = Quinta::Translate('Street 2 or Apt') . '.# :';
  132. $this->lblSuburb = $this->mctAddress->lblSuburb_Create();
  133. $this->lblSuburb->Name = Quinta::Translate('Suburb') . ' :';
  134. $this->lblCity = $this->mctAddress->lblCity_Create();
  135. $this->lblCity->Name = Quinta::Translate('City') . ' :';
  136. $this->lblCounty = $this->mctAddress->lblCounty_Create();
  137. $this->lblCounty->Name = Quinta::Translate('County/District') . ' :';
  138. $this->lblZoneId = $this->mctAddress->lblZoneId_Create();
  139. $this->lblZoneId->Name = Quinta::Translate('State/Province') . ' :';
  140. $this->lblCountryId = $this->mctAddress->lblCountryId_Create();
  141. $this->lblCountryId->Name = Quinta::Translate('Country') . ' :';
  142. $this->lblPostalCode = $this->mctAddress->lblPostalCode_Create();
  143. $this->lblPostalCode->Name = Quinta::Translate('Zip/Postal Code') . ' :';
  144. $this->lblTypeId = $this->mctAddress->lblTypeId_Create();
  145. $this->lblTypeId->Name = Quinta::Translate('Type of Address') . ' :';
  146. }
  147. }
  148. /**
  149. * This function is called when the user selects an Item from the address list. The parameter that
  150. * passed is the id of the origianally displayed address. The selected address is obtained directly
  151. * from the listbox and objAddress is set to be this address before issueing the callback.
  152. */
  153. public function lstMyAddresses_Selected($strFormId, $strControlId, $intAddressId){
  154. $strCallback = $this->strRefreshAddressCallback;
  155. $strAction = $this->lstMyAddresses->SelectedValue;
  156. if(! is_numeric($strAction) )
  157. $this->objControlBlock->$strCallback($this->intCurrentAddressId, $strAction);
  158. else{
  159. $objAddress = Address::Load($strAction);
  160. if($objAddress instanceof Address)
  161. $this->objAddress = $objAddress;
  162. $this->objControlBlock->$strCallback($strAction);
  163. }
  164. }
  165. public function btnSave_Click($strFormId, $strControlId, $strParameter){
  166. $strCallback = $this->strRefreshAddressCallback;
  167. $this->mctAddress->SaveAddress();
  168. $this->objAddress = $this->mctAddress->Address;
  169. $this->objControlBlock->$strCallback($this->mctAddress->Address->Id, 'Save');
  170. }
  171. public function btnCancel_Click($strFormId, $strControlId, $intAddressId){
  172. $strCallback = $this->strRefreshAddressCallback;
  173. $this->objControlBlock->$strCallback($this->intCurrentAddressId);
  174. }
  175. public function __get($strName){
  176. switch ($strName){
  177. case 'Modifiable':
  178. return $this->blnModifiable;
  179. case 'Address':
  180. return $this->objAddress;
  181. default:
  182. try {
  183. return parent::__get($strName);
  184. } catch (QCallerException $objExc) {
  185. $objExc->IncrementOffset();
  186. throw $objExc;
  187. }
  188. }
  189. }
  190. }//end class
  191. }//end define
  192. ?>