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.

176 lines
7.0 KiB

  1. <?php
  2. /** @brief A panel for editing Account information
  3. *
  4. * This panel presents the information associated with an account
  5. * in the CMS.
  6. *
  7. * @package Quinta
  8. * @subpackage AdminUI
  9. */
  10. class AccountEditPanel extends QPanel {
  11. protected $mctAccount;
  12. protected $objAccount;
  13. protected $pnlListPanel;
  14. //Controls for listing orders associated with this account
  15. public $dtgOrders;
  16. public $objPaginator;
  17. public $pxyViewOrder;
  18. // Controls for Account's Data Fields
  19. public $lblId;
  20. public $lblRegistrationDate;
  21. public $txtUsername;
  22. public $txtPassword;
  23. public $txtNotes;
  24. public $lblLastLogin;
  25. public $txtLoginCount;
  26. public $chkOnline;
  27. public $chkOnetimePassword;
  28. public $chkValidPassword;
  29. public $lstType;
  30. public $lstStatus;
  31. public $lblPerson;
  32. // Action controls
  33. public $btnSave;
  34. public $btnDelete;
  35. public $btnCancel;
  36. protected $strClosePanelMethod;
  37. public function __construct($objParentObject, $strClosePanelMethod, $intId = null, $strControlId = null){
  38. $this->pnlListPanel =& $objParentObject;
  39. try {
  40. parent::__construct($objParentObject, $strControlId);
  41. } catch (QCallerException $objExc) {
  42. $objExc->IncrementOffset();
  43. throw $objExc;
  44. }
  45. $this->strTemplate = 'AccountEditPanel.tpl.php';
  46. $this->strClosePanelMethod = $strClosePanelMethod;
  47. $this->mctAccount = AccountMetaControl::Create($this, $intId);
  48. $this->objAccount =& $this->mctAccount->Account;
  49. $this->lblId = $this->mctAccount->lblId_Create();
  50. $this->lblRegistrationDate = $this->mctAccount->lblRegistrationDate_Create();
  51. $this->txtUsername = $this->mctAccount->txtUsername_Create();
  52. $this->txtPassword = $this->mctAccount->txtPassword_Create();
  53. $this->txtPassword->Required = false;
  54. $this->txtNotes = $this->mctAccount->txtNotes_Create();
  55. $this->lblLastLogin = $this->mctAccount->lblLastLogin_Create();
  56. $this->txtLoginCount = $this->mctAccount->txtLoginCount_Create();
  57. $this->chkOnline = $this->mctAccount->chkOnline_Create();
  58. $this->chkOnetimePassword = $this->mctAccount->chkOnetimePassword_Create();
  59. $this->chkValidPassword = $this->mctAccount->chkValidPassword_Create();
  60. $this->lstType = $this->mctAccount->lstType_Create();
  61. $this->lstStatus = $this->mctAccount->lstStatus_Create();
  62. $this->lblPerson = $this->mctAccount->lblPersonId_Create();
  63. // Create a Meta DataGrid to list the Orders for the Account
  64. $this->dtgOrders = new OrderDataGrid($this);
  65. $this->dtgOrders->SetDataBinder('AccountOrderDataBinder', $this);
  66. $this->dtgOrders->CssClass = 'datagrid';
  67. $this->dtgOrders->AlternateRowStyle->CssClass = 'alternate';
  68. $this->objPaginator = new QPaginator($this->dtgOrders);
  69. $this->dtgOrders->Paginator = $this->objPaginator;
  70. $this->dtgOrders->ItemsPerPage = 25;
  71. $this->pxyViewOrder = new QControlProxy($this);
  72. $this->pxyViewOrder->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyViewOrder_Click'));
  73. $this->dtgOrders->MetaAddProxyColumn($this->pxyViewOrder, 'Id');
  74. $this->dtgOrders->MetaAddColumn('CreationDate');
  75. $this->dtgOrders->MetaAddColumn('LastModification');
  76. $this->dtgOrders->MetaAddColumn('CompletionDate');
  77. $this->dtgOrders->MetaAddColumn(QQN::Order()->ShippingMethod);
  78. $this->dtgOrders->MetaAddColumn(QQN::Order()->PaymentMethod);
  79. $this->dtgOrders->MetaAddTypeColumn('StatusId', 'OrderStatusType');
  80. $strOrderTotalParam = '<?= money_format("%n", $_ITEM->ProductTotalCharged '
  81. . ' + $_ITEM->ShippingCharged '
  82. . ' + $_ITEM->HandlingCharged '
  83. . ' + $_ITEM->Tax ) ?>';
  84. $objOrderTotalColumn = new QDataGridColumn('Order Total', $strOrderTotalParam );
  85. $this->dtgOrders->AddColumn($objOrderTotalColumn);
  86. $this->btnSave = new QButton($this);
  87. $this->btnSave->Text = QApplication::Translate('Save');
  88. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  89. $this->btnSave->CausesValidation = $this;
  90. $this->btnCancel = new QButton($this);
  91. $this->btnCancel->Text = QApplication::Translate('Cancel');
  92. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  93. $this->btnDelete = new QButton($this);
  94. $this->btnDelete->Text = QApplication::Translate('Delete');
  95. $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('Account') . '?'));
  96. $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
  97. $this->btnDelete->Visible = $this->mctAccount->EditMode;
  98. }
  99. /**
  100. * This binds the Datagrid data retrieval to this Account, the orders listed in the Datagrid will be those
  101. * associated with this account in the database.
  102. *
  103. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  104. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  105. */
  106. public function AccountOrderDataBinder(){
  107. if ($this->objPaginator)
  108. $this->dtgOrders->TotalItemCount = Order::CountByAccountId($this->objAccount->Id);
  109. $objClauses = array();
  110. // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
  111. // the OrderByClause to the $objClauses array - this is in the datagrid if the user clicks on column title
  112. if ($objClause = $this->dtgOrders->OrderByClause)
  113. array_push($objClauses, $objClause);
  114. // Add the LimitClause information, as well
  115. if ($objClause = $this->dtgOrders->LimitClause)
  116. array_push($objClauses, $objClause);
  117. array_push($objClauses, QQ::OrderBy(QQN::Order()->CreationDate, false) );
  118. $this->dtgOrders->DataSource = Order::LoadArrayByAccountId(
  119. $this->objAccount->Id, $objClauses
  120. );
  121. }
  122. /**
  123. * @brief Callback to view an order in the list
  124. *
  125. *@todo - fix this ..
  126. *
  127. * @param strFormId ...
  128. * @param strControlId ...
  129. * @param strParameter ...
  130. * @return void
  131. **/
  132. public function pxyViewOrder_Click($strFormId, $strControlId, $strParameter){
  133. $strParameterArray = explode(',', $strParameter);
  134. // $objEditPanel = new OrderEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0]);
  135. // $objEditPanel = new OrderEditPanel($this, 'CloseEditPane', $strParameterArray[0]);
  136. $objEditPanel = new OrderEditPanel($this->pnlListPanel , 'CloseEditPane', $strParameter);
  137. // $strMethodName = $this->strSetEditPanelMethod;
  138. // $this->objForm->$strMethodName($objEditPanel);
  139. $this->objForm->SetEditPane($objEditPanel);
  140. }
  141. public function btnSave_Click($strFormId, $strControlId, $strParameter) {
  142. $this->mctAccount->SaveAccount();
  143. $this->CloseSelf(true);
  144. }
  145. public function btnDelete_Click($strFormId, $strControlId, $strParameter) {
  146. $this->mctAccount->DeleteAccount();
  147. $this->CloseSelf(true);
  148. }
  149. public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
  150. $this->CloseSelf(false);
  151. }
  152. protected function CloseSelf($blnChangesMade) {
  153. $strMethod = $this->strClosePanelMethod;
  154. $this->objForm->$strMethod($blnChangesMade);
  155. }
  156. }
  157. ?>