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.

203 lines
8.8 KiB

12 years ago
  1. <?php
  2. /**
  3. * This is a quick-and-dirty draft QPanel object to do Create, Edit, and Delete functionality
  4. * of the Account class. It uses the code-generated
  5. * AccountMetaControl class, which has meta-methods to help with
  6. * easily creating/defining controls to modify the fields of a Account columns.
  7. *
  8. * Any display customizations and presentation-tier logic can be implemented
  9. * here by overriding existing or implementing new methods, properties and variables.
  10. *
  11. * NOTE: This file is overwritten on any code regenerations. If you want to make
  12. * permanent changes, it is STRONGLY RECOMMENDED to move both account_edit.php AND
  13. * account_edit.tpl.php out of this Form Drafts directory.
  14. *
  15. * @package Quasi
  16. * @subpackage Drafts
  17. */
  18. class AccountEditPanel extends QPanel {
  19. // Local instance of the AccountMetaControl
  20. protected $mctAccount;
  21. protected $objAccount;
  22. protected $pnlListPanel;
  23. public $dtgOrders;
  24. public $objPaginator;
  25. public $pxyViewOrder;
  26. // Controls for Account's Data Fields
  27. public $lblId;
  28. public $lblRegistrationDate;
  29. public $txtUsername;
  30. public $txtPassword;
  31. public $txtNotes;
  32. public $lblLastLogin;
  33. public $txtLoginCount;
  34. public $chkOnline;
  35. public $chkOnetimePassword;
  36. public $chkValidPassword;
  37. public $lstType;
  38. public $lstStatus;
  39. public $lblPerson;
  40. // Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
  41. // Other Controls
  42. public $btnSave;
  43. public $btnDelete;
  44. public $btnCancel;
  45. // Callback
  46. protected $strClosePanelMethod;
  47. public function __construct($objParentObject, $strClosePanelMethod, $intId = null, $strControlId = null)
  48. {
  49. $this->pnlListPanel =& $objParentObject;
  50. // Call the Parent
  51. try {
  52. parent::__construct($objParentObject, $strControlId);
  53. } catch (QCallerException $objExc) {
  54. $objExc->IncrementOffset();
  55. throw $objExc;
  56. }
  57. // Setup Callback and Template
  58. $this->strTemplate = 'AccountEditPanel.tpl.php';
  59. $this->strClosePanelMethod = $strClosePanelMethod;
  60. // Construct the AccountMetaControl
  61. // MAKE SURE we specify "$this" as the MetaControl's (and thus all subsequent controls') parent
  62. $this->mctAccount = AccountMetaControl::Create($this, $intId);
  63. $this->objAccount =& $this->mctAccount->Account;
  64. // Call MetaControl's methods to create qcontrols based on Account's data fields
  65. $this->lblId = $this->mctAccount->lblId_Create();
  66. $this->lblRegistrationDate = $this->mctAccount->lblRegistrationDate_Create();
  67. $this->txtUsername = $this->mctAccount->txtUsername_Create();
  68. $this->txtPassword = $this->mctAccount->txtPassword_Create();
  69. $this->txtPassword->Required = false;
  70. $this->txtNotes = $this->mctAccount->txtNotes_Create();
  71. $this->lblLastLogin = $this->mctAccount->lblLastLogin_Create();
  72. $this->txtLoginCount = $this->mctAccount->txtLoginCount_Create();
  73. $this->chkOnline = $this->mctAccount->chkOnline_Create();
  74. $this->chkOnetimePassword = $this->mctAccount->chkOnetimePassword_Create();
  75. $this->chkValidPassword = $this->mctAccount->chkValidPassword_Create();
  76. $this->lstType = $this->mctAccount->lstType_Create();
  77. $this->lstStatus = $this->mctAccount->lstStatus_Create();
  78. $this->lblPerson = $this->mctAccount->lblPersonId_Create();
  79. // Create a Meta DataGrid to list the Orders for the Account
  80. $this->dtgOrders = new OrderDataGrid($this);
  81. $this->dtgOrders->SetDataBinder('AccountOrderDataBinder', $this);
  82. $this->dtgOrders->CssClass = 'datagrid';
  83. $this->dtgOrders->AlternateRowStyle->CssClass = 'alternate';
  84. $this->objPaginator = new QPaginator($this->dtgOrders);
  85. $this->dtgOrders->Paginator = $this->objPaginator;
  86. $this->dtgOrders->ItemsPerPage = 25;
  87. $this->pxyViewOrder = new QControlProxy($this);
  88. $this->pxyViewOrder->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyViewOrder_Click'));
  89. $this->dtgOrders->MetaAddProxyColumn($this->pxyViewOrder, 'Id');
  90. $this->dtgOrders->MetaAddColumn('CreationDate');
  91. $this->dtgOrders->MetaAddColumn('LastModificationDate');
  92. $this->dtgOrders->MetaAddColumn('CompletionDate');
  93. $this->dtgOrders->MetaAddColumn(QQN::Order()->ShippingMethod);
  94. $this->dtgOrders->MetaAddColumn(QQN::Order()->PaymentMethod);
  95. $this->dtgOrders->MetaAddTypeColumn('StatusId', 'OrderStatusType');
  96. $strOrderTotalParam = '<?= money_format("%n", $_ITEM->ProductTotalCharged '
  97. . ' + $_ITEM->ShippingCharged '
  98. . ' + $_ITEM->HandlingCharged '
  99. . ' + $_ITEM->Tax ) ?>';
  100. $objOrderTotalColumn = new QDataGridColumn('Order Total', $strOrderTotalParam );
  101. $this->dtgOrders->AddColumn($objOrderTotalColumn);
  102. // Create Buttons
  103. $this->btnSave = new QButton($this);
  104. $this->btnSave->Text = QApplication::Translate('Save');
  105. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  106. $this->btnSave->CausesValidation = $this;
  107. $this->btnCancel = new QButton($this);
  108. $this->btnCancel->Text = QApplication::Translate('Cancel');
  109. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  110. $this->btnDelete = new QButton($this);
  111. $this->btnDelete->Text = QApplication::Translate('Delete');
  112. $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('Account') . '?'));
  113. $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
  114. $this->btnDelete->Visible = $this->mctAccount->EditMode;
  115. }
  116. /**
  117. * This binds the Datagrid data retrieval to this Account, the orders listed in the Datagrid will be those
  118. * associated with this account in the database.
  119. *
  120. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  121. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  122. */
  123. public function AccountOrderDataBinder()
  124. {
  125. if ($this->objPaginator)
  126. $this->dtgOrders->TotalItemCount = Order::CountByAccountId($this->objAccount->Id) ;
  127. $objClauses = array();
  128. // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
  129. // the OrderByClause to the $objClauses array - this is in the datagrid if the user clicks on column title
  130. if ($objClause = $this->dtgOrders->OrderByClause)
  131. array_push($objClauses, $objClause);
  132. // Add the LimitClause information, as well
  133. if ($objClause = $this->dtgOrders->LimitClause)
  134. array_push($objClauses, $objClause);
  135. array_push($objClauses, QQ::OrderBy(QQN::Order()->CreationDate, false) );
  136. $this->dtgOrders->DataSource = Order::LoadArrayByAccountId(
  137. $this->objAccount->Id, $objClauses
  138. );
  139. }
  140. public function pxyViewOrder_Click($strFormId, $strControlId, $strParameter)
  141. {
  142. //die($strParameter);
  143. $strParameterArray = explode(',', $strParameter);
  144. // $objEditPanel = new OrderEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0]);
  145. // $objEditPanel = new OrderEditPanel($this, 'CloseEditPane', $strParameterArray[0]);
  146. $objEditPanel = new OrderEditPanel($this->pnlListPanel , 'CloseEditPane', $strParameter);
  147. // $strMethodName = $this->strSetEditPanelMethod;
  148. // $this->objForm->$strMethodName($objEditPanel);
  149. $this->objForm->SetEditPane($objEditPanel);
  150. }
  151. // Control AjaxAction Event Handlers
  152. public function btnSave_Click($strFormId, $strControlId, $strParameter) {
  153. // Delegate "Save" processing to the AccountMetaControl
  154. $this->mctAccount->SaveAccount();
  155. $this->CloseSelf(true);
  156. }
  157. public function btnDelete_Click($strFormId, $strControlId, $strParameter) {
  158. // Delegate "Delete" processing to the AccountMetaControl
  159. $this->mctAccount->DeleteAccount();
  160. $this->CloseSelf(true);
  161. }
  162. public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
  163. $this->CloseSelf(false);
  164. }
  165. // Close Myself and Call ClosePanelMethod Callback
  166. protected function CloseSelf($blnChangesMade) {
  167. $strMethod = $this->strClosePanelMethod;
  168. $this->objForm->$strMethod($blnChangesMade);
  169. }
  170. }
  171. ?>