PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/category_list.php

http://tracmor.googlecode.com/
PHP | 241 lines | 130 code | 42 blank | 69 comment | 8 complexity | bb83dba93964d984e230fb439678dab3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * Copyright (c) 2009, Tracmor, LLC
  4. *
  5. * This file is part of Tracmor.
  6. *
  7. * Tracmor is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tracmor is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tracmor; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. // Include prepend.inc to load Qcodo
  22. require('../includes/prepend.inc.php'); /* if you DO NOT have "includes/" in your include_path */
  23. // require('prepend.inc'); /* if you DO have "includes/" in your include_path */
  24. QApplication::Authenticate();
  25. // Include the classfile for CategoryListFormBase
  26. require(__FORMBASE_CLASSES__ . '/CategoryListFormBase.class.php');
  27. /**
  28. * This is a quick-and-dirty draft form object to do the List All functionality
  29. * of the Category class. It extends from the code-generated
  30. * abstract CategoryListFormBase class.
  31. *
  32. * Any display custimizations and presentation-tier logic can be implemented
  33. * here by overriding existing or implementing new methods, properties and variables.
  34. *
  35. * Additional qform control objects can also be defined and used here, as well.
  36. *
  37. * @package Application
  38. * @subpackage FormDraftObjects
  39. *
  40. */
  41. class CategoryListForm extends CategoryListFormBase {
  42. // Header Menu
  43. protected $ctlHeaderMenu;
  44. protected $btnNew;
  45. protected $btnImport;
  46. protected $lblTest;
  47. protected $txtQuickAdd;
  48. protected $btnQuickAdd;
  49. protected function Form_Create() {
  50. // Create the Header Menu
  51. $this->ctlHeaderMenu_Create();
  52. $this->btnNew_Create();
  53. $this->btnImport_Create();
  54. $this->txtQuickAdd_Create();
  55. $this->btnQuickAdd_Create();
  56. $this->dtgCategory_Create();
  57. }
  58. //protected function Form_PreRender() {
  59. // Enable Profiling
  60. //QApplication::$Database[1]->EnableProfiling();
  61. //}
  62. // Create and Setup the Header Composite Control
  63. protected function ctlHeaderMenu_Create() {
  64. $this->ctlHeaderMenu = new QHeaderMenu($this);
  65. }
  66. // Create/Setup the new button
  67. protected function btnNew_Create() {
  68. $this->btnNew = new QButton($this);
  69. $this->btnNew->Text = 'New Category';
  70. $this->btnNew->AddAction(new QClickEvent(), new QServerAction('btnNew_Click'));
  71. }
  72. // Create/Setup the Import button
  73. protected function btnImport_Create() {
  74. $this->btnImport = new QButton($this);
  75. $this->btnImport->Text = 'Import Categories';
  76. $this->btnImport->AddAction(new QClickEvent(), new QServerAction('btnImport_Click'));
  77. }
  78. protected function txtQuickAdd_Create() {
  79. $this->txtQuickAdd = new QTextBox($this);
  80. $this->txtQuickAdd->Focus();
  81. $this->txtQuickAdd->Width = '160';
  82. $this->txtQuickAdd->CssClass = 'textbox';
  83. $this->txtQuickAdd->SetCustomStyle('vertical-align', 'baseline');
  84. $this->txtQuickAdd->AddAction(new QEnterKeyEvent(), new QAjaxAction('btnQuickAdd_Click'));
  85. $this->txtQuickAdd->AddAction(new QEnterKeyEvent(), new QTerminateAction());
  86. }
  87. protected function btnQuickAdd_Create() {
  88. $this->btnQuickAdd = new QButton($this);
  89. $this->btnQuickAdd->Text = 'Quick Add';
  90. $this->btnQuickAdd->SetCustomStyle('vertical-align', 'baseline');
  91. $this->btnQuickAdd->AddAction(new QClickEvent(), new QAjaxAction('btnQuickAdd_Click'));
  92. }
  93. protected function btnQuickAdd_Click($strFormId, $strControlId, $strParameter) {
  94. $blnError = false;
  95. $this->btnQuickAdd->Warning = '';
  96. if (strlen(trim($this->txtQuickAdd->Text)) == 0) {
  97. $blnError = true;
  98. $this->btnQuickAdd->Warning = 'You must enter a Category name';
  99. }
  100. // Check for dupes
  101. $objCategoryDuplicate = Category::QuerySingle(QQ::Equal(QQN::Category()->ShortDescription, $this->txtQuickAdd->Text));
  102. if ($objCategoryDuplicate) {
  103. $blnError = true;
  104. $this->btnQuickAdd->Warning = 'This Category Name is already in use. Please try another.';
  105. }
  106. if (!$blnError) {
  107. $objCategory = new Category();
  108. $objCategory->ShortDescription = $this->txtQuickAdd->Text;
  109. $objCategory->AssetFlag = '1';
  110. $objCategory->InventoryFlag = '1';
  111. $objCategory->CreatedBy = QApplication::$objUserAccount->UserAccountId;
  112. $objCategory->CreationDate = QDateTime::Now();
  113. $objCategory->Save();
  114. $this->dtgCategory->Refresh();
  115. $this->txtQuickAdd->Text = '';
  116. }
  117. $this->txtQuickAdd->Focus();
  118. $this->txtQuickAdd->Select();
  119. }
  120. // Create/Setup the category datagrid
  121. protected function dtgCategory_Create() {
  122. $this->dtgCategory = new QDataGrid($this);
  123. $this->dtgCategory->Name = 'category_list';
  124. $this->dtgCategory->CellPadding = 5;
  125. $this->dtgCategory->CellSpacing = 0;
  126. $this->dtgCategory->CssClass = "datagrid";
  127. $this->dtgCategory->SortColumnIndex = 0;
  128. // Enable AJAX - this won't work while using the DB profiler
  129. $this->dtgCategory->UseAjax = true;
  130. // Allow for column toggling
  131. $this->dtgCategory->ShowColumnToggle = true;
  132. // Enable Pagination, and set to 20 items per page
  133. $objPaginator = new QPaginator($this->dtgCategory);
  134. $this->dtgCategory->Paginator = $objPaginator;
  135. $this->dtgCategory->ItemsPerPage = 20;
  136. $this->dtgCategory->ShowExportCsv = true;
  137. $this->dtgCategory->AddColumn(new QDataGridColumnExt('ID', '<?= $_ITEM->CategoryId ?>', array('OrderByClause' => QQ::OrderBy(QQN::Category()->CategoryId), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Category()->CategoryId, false), 'CssClass' => "dtg_column", 'HtmlEntities' => false)));
  138. $this->dtgCategory->AddColumn(new QDataGridColumnExt('Category', '<?= $_ITEM->__toStringWithLink("bluelink") ?>', array('OrderByClause' => QQ::OrderBy(QQN::Category()->ShortDescription), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Category()->ShortDescription, false), 'CssClass' => "dtg_column", 'HtmlEntities' => false)));
  139. $this->dtgCategory->AddColumn(new QDataGridColumnExt('Description', '<?= $_ITEM->LongDescription ?>', array('Width' => "200", 'OrderByClause' => QQ::OrderBy(QQN::Category()->LongDescription), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Category()->LongDescription, false), 'CssClass' => "dtg_column")));
  140. /* $this->dtgCategory->AddColumn(new QDataGridColumnExt('Created By', '<?= $_ITEM->CreatedByObject->__toStringFullName() ?>', array('OrderByClause' => QQ::OrderBy(QQN::Category()->CreatedByObject->LastName, false, QQN::Category()->CreatedByObject->FirstName, false), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Category()->CreatedByObject->LastName, QQN::Category()->CreatedByObject->FirstName), 'CssClass' => "dtg_column")));*/
  141. $this->dtgCategory->AddColumn(new QDataGridColumnExt('Created By', '<?= $_ITEM->CreatedByObject->__toStringFullName() ?>', array('SortByCommand' => 'category__created_by__last_name DESC, category__created_by__first_name DESC', 'ReverseSortByCommand' => 'category__created_by__last_name ASC, category__created_by__first_name ASC', 'CssClass' => "dtg_column")));
  142. // Add the custom field columns with Display set to false. These can be shown by using the column toggle menu.
  143. $objCustomFieldArray = CustomField::LoadObjCustomFieldArray(6, false);
  144. if ($objCustomFieldArray) {
  145. foreach ($objCustomFieldArray as $objCustomField) {
  146. $this->dtgCategory->AddColumn(new QDataGridColumnExt($objCustomField->ShortDescription, '<?= $_ITEM->GetVirtualAttribute(\''.$objCustomField->CustomFieldId.'\') ?>', 'SortByCommand="__'.$objCustomField->CustomFieldId.' ASC"', 'ReverseSortByCommand="__'.$objCustomField->CustomFieldId.' DESC"','HtmlEntities="false"', 'CssClass="dtg_column"', 'Display="false"'));
  147. }
  148. }
  149. $this->dtgCategory->SortColumnIndex = 1;
  150. $this->dtgCategory->SortDirection = 0;
  151. $objStyle = $this->dtgCategory->RowStyle;
  152. $objStyle->ForeColor = '#000000';
  153. $objStyle->BackColor = '#FFFFFF';
  154. $objStyle->FontSize = 12;
  155. $objStyle = $this->dtgCategory->AlternateRowStyle;
  156. $objStyle->BackColor = '#EFEFEF';
  157. $objStyle = $this->dtgCategory->HeaderRowStyle;
  158. $objStyle->ForeColor = '#000000';
  159. $objStyle->BackColor = '#EFEFEF';
  160. $objStyle->CssClass = 'dtg_header';
  161. $this->dtgCategory->SetDataBinder('dtgCategory_Bind');
  162. }
  163. protected function dtgCategory_Bind() {
  164. $objExpansionMap[Category::ExpandCreatedByObject] = true;
  165. // Get Total Count b/c of Pagination
  166. $this->dtgCategory->TotalItemCount = Category::CountAll();
  167. if ($this->dtgCategory->TotalItemCount == 0) {
  168. $this->dtgCategory->ShowHeader = false;
  169. }
  170. else {
  171. /* $objClauses = array();
  172. if ($objClause = $this->dtgCategory->OrderByClause)
  173. array_push($objClauses, $objClause);
  174. if ($objClause = $this->dtgCategory->LimitClause)
  175. array_push($objClauses, $objClause);
  176. if ($objClause = QQ::Expand(QQN::Category()->CreatedByObject))
  177. array_push($objClauses, $objClause);
  178. $this->dtgCategory->DataSource = Category::LoadAll($objClauses);
  179. $this->dtgCategory->ShowHeader = true;*/
  180. $this->dtgCategory->DataSource = Category::LoadAllWithCustomFieldsHelper($this->dtgCategory->SortInfo, $this->dtgCategory->LimitInfo, $objExpansionMap);
  181. $this->dtgCategory->ShowHeader = true;
  182. }
  183. }
  184. //protected function Form_Exit() {
  185. // Output database profiling - it shows you the queries made to create this page
  186. // This will not work on pages with the AJAX Pagination
  187. //QApplication::$Database[1]->OutputProfiling();
  188. //}
  189. protected function btnNew_Click() {
  190. QApplication::Redirect('category_edit.php');
  191. }
  192. protected function btnImport_Click() {
  193. QApplication::Redirect('category_import.php');
  194. }
  195. }
  196. // Go ahead and run this form object to generate the page and event handlers, using
  197. // generated/category_edit.php.inc as the included HTML template file
  198. CategoryListForm::Run('CategoryListForm', __DOCROOT__ . __SUBDIRECTORY__ . '/admin/category_list.tpl.php');
  199. ?>