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.

184 lines
6.7 KiB

  1. <?php
  2. /**
  3. * AccountAddressEditPanel - provides a panel for user viewing and modification of an address
  4. *
  5. * @author Erik Winn <sidewalksoftware@gmail.com>
  6. *
  7. * @version 0.3
  8. * @package Quinta
  9. * @subpackage Classes
  10. */
  11. class AccountAddressEditPanel extends QPanel {
  12. // Local instance of the AddressMetaControl
  13. public $mctAddress;
  14. protected $objControlBlock;
  15. protected $objParentBlock;
  16. // Controls for Address's Data Fields
  17. public $txtTitle;
  18. public $lstMyPeople;
  19. public $txtStreet1;
  20. public $txtStreet2;
  21. public $txtSuburb;
  22. public $txtCity;
  23. public $txtCounty;
  24. public $lstZone;
  25. public $lstCountry;
  26. public $txtPostalCode;
  27. public $lstType;
  28. // Other Controls
  29. public $btnSave;
  30. public $btnDelete;
  31. public $btnCancel;
  32. public $btnAddPerson;
  33. // Callback
  34. protected $strClosePanelMethod;
  35. public function __construct($objParentObject, $objControlBlock, $strClosePanelMethod, $intId = null, $strControlId = null) {
  36. try {
  37. parent::__construct($objParentObject, $strControlId);
  38. } catch (QCallerException $objExc) {
  39. $objExc->IncrementOffset();
  40. throw $objExc;
  41. }
  42. $this->objControlBlock = $objControlBlock;
  43. ///@todo not sure we need this, could use objParentControl ..?
  44. $this->objParentBlock = $objParentObject;
  45. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/AccountAddressEditPanel.tpl.php';
  46. $this->strClosePanelMethod = $strClosePanelMethod;
  47. $this->mctAddress = AddressMetaControl::Create($this, $intId);
  48. // Call MetaControl's methods to create qcontrols based on Address's data fields
  49. $this->txtTitle = $this->mctAddress->txtTitle_Create();
  50. $this->txtTitle->Name = 'Address Title: ';
  51. $this->lstMyPeople = $this->mctAddress->lstMyPeople_Create($this->objControlBlock->Account->PersonId);
  52. $this->lstMyPeople->Name = 'Address for : ';
  53. $this->txtStreet1 = $this->mctAddress->txtStreet1_Create();
  54. $this->txtStreet1->Name = 'Street :';
  55. $this->txtStreet2 = $this->mctAddress->txtStreet2_Create();
  56. $this->txtStreet2->Name = 'Street 2 or Apt.#:';
  57. $this->txtSuburb = $this->mctAddress->txtSuburb_Create();
  58. $this->txtSuburb->Name = 'Suburb :';
  59. $this->txtCity = $this->mctAddress->txtCity_Create();
  60. $this->txtCity->Name = 'City :';
  61. $this->txtCounty = $this->mctAddress->txtCounty_Create();
  62. $this->txtCounty->Name = 'County/District :';
  63. $this->lstZone = $this->mctAddress->lstZone_Create();
  64. $this->lstZone->Name = 'State/Province :';
  65. $this->lstCountry = $this->mctAddress->lstCountry_Create();
  66. $this->lstCountry->Name = 'Country :';
  67. $this->txtPostalCode = $this->mctAddress->txtPostalCode_Create();
  68. $this->txtPostalCode->Name = 'Zip/Postal Code :';
  69. $this->lstType = $this->mctAddress->lstType_Create();
  70. $this->lstType->Name = 'Type of Address :';
  71. // Create Buttons and Actions
  72. $this->btnAddPerson = new QButton($this);
  73. $this->btnAddPerson->Text = QApplication::Translate('Add a Person');
  74. if (IndexPage::$blnAjaxOk)
  75. $this->btnAddPerson->AddAction(new QClickEvent(), new QAjaxControlAction($this->objParentBlock, 'btnAddPerson_Click'));
  76. else
  77. $this->btnAddPerson->AddAction(new QClickEvent(), new QServerControlAction($this->objParentBlock, 'btnAddPerson_Click'));
  78. $this->btnSave = new QButton($this);
  79. $this->btnSave->Text = QApplication::Translate('Save');
  80. if (IndexPage::$blnAjaxOk)
  81. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  82. else
  83. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click'));
  84. $this->btnSave->CausesValidation = $this;
  85. $this->btnCancel = new QButton($this);
  86. $this->btnCancel->Text = QApplication::Translate('Cancel');
  87. if (IndexPage::$blnAjaxOk)
  88. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  89. else
  90. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click'));
  91. $this->btnDelete = new QButton($this);
  92. $this->btnDelete->Text = QApplication::Translate('Delete');
  93. $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('Address') . '?'));
  94. if (IndexPage::$blnAjaxOk)
  95. $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
  96. else
  97. $this->btnDelete->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnDelete_Click'));
  98. $this->btnDelete->Visible = $this->mctAddress->EditMode;
  99. }
  100. public function btnSave_Click($strFormId, $strControlId, $strParameter) {
  101. if ('' == $this->txtTitle->Text) {
  102. if (AddressType::Primary == $this->lstType->SelectedValue) {
  103. $this->txtTitle->Text = 'Primary Address';
  104. } else {
  105. $aryPersons = Person::QueryArray(
  106. QQ::OrCondition(
  107. QQ::Equal(QQN::Person()->Id, $this->objControlBlock->Account->PersonId), QQ::Equal(QQN::Person()->OwnerPersonId, $this->objControlBlock->Account->PersonId)
  108. ));
  109. foreach ($aryPersons as $objPerson)
  110. $aryPersonIds[] = $objPerson->Id;
  111. if (AddressType::Shipping == $this->lstType->SelectedValue) {
  112. $this->txtTitle->Text = 'Shipping Address';
  113. $intCount = Address::QueryCount(
  114. QQ::AndCondition(
  115. QQ::In(QQN::Address()->PersonId, $aryPersonIds), QQ::Equal(QQN::Address()->TypeId, AddressType::Shipping)
  116. ));
  117. } elseif (AddressType::Billing == $this->lstType->SelectedValue) {
  118. $this->txtTitle->Text = 'Billing Address';
  119. $intCount = Address::QueryCount(
  120. QQ::AndCondition(
  121. QQ::In(QQN::Address()->PersonId, $aryPersonIds), QQ::Equal(QQN::Address()->TypeId, AddressType::Billing)
  122. ));
  123. } else {
  124. $this->txtTitle->Text = 'Extra Address';
  125. $intCount = Address::QueryCount(
  126. QQ::AndCondition(
  127. QQ::In(QQN::Address()->PersonId, $aryPersonIds), QQ::NotEqual(QQN::Address()->TypeId, AddressType::Billing), QQ::NotEqual(QQN::Address()->TypeId, AddressType::Shipping)
  128. ));
  129. }
  130. $this->txtTitle->Text .= ' ' . $intCount;
  131. }
  132. }
  133. $this->mctAddress->SaveAddress();
  134. $this->CloseSelf(true);
  135. }
  136. public function btnDelete_Click($strFormId, $strControlId, $strParameter) {
  137. if (Address::CountByPersonId($this->objControlBlock->Account->PersonId) > 1)
  138. $this->mctAddress->DeleteAddress();
  139. $this->CloseSelf(true);
  140. }
  141. public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
  142. $this->CloseSelf(false);
  143. }
  144. // Close Myself and Call ClosePanelMethod Callback
  145. protected function CloseSelf($blnChangesMade) {
  146. $strMethod = $this->strClosePanelMethod;
  147. $this->objControlBlock->$strMethod($blnChangesMade);
  148. }
  149. public function __get($strName) {
  150. switch ($strName) {
  151. case 'Account':
  152. return $this->objControlBlock->Account;
  153. default:
  154. try {
  155. return parent::__get($strName);
  156. } catch (QCallerException $objExc) {
  157. $objExc->IncrementOffset();
  158. throw $objExc;
  159. }
  160. }
  161. }
  162. }
  163. ?>