PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/ace/prestashop/admin7/tabs/AdminGroups.php

https://github.com/sealence/local
PHP | 181 lines | 155 code | 16 blank | 10 comment | 10 complexity | 0221f04dac2da776b2477c2efbeb4757 MD5 | raw file
  1. <?php
  2. /**
  3. * Customers tab for admin panel, AdminContacts.php
  4. * @category admin
  5. *
  6. * @author PrestaShop <support@prestashop.com>
  7. * @copyright PrestaShop
  8. * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
  9. * @version 1.2
  10. *
  11. */
  12. include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
  13. class AdminGroups extends AdminTab
  14. {
  15. public function __construct()
  16. {
  17. $this->table = 'group';
  18. $this->className = 'Group';
  19. $this->lang = true;
  20. $this->edit = true;
  21. $this->view = true;
  22. $this->delete = true;
  23. $this->_select = 'count(cg.id_customer) as nb';
  24. $this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer_group cg on (cg.id_group = a.id_group)';
  25. $this->_group = 'GROUP BY a.id_group';
  26. $this->_listSkipDelete = array(1);
  27. $this->fieldsDisplay = array(
  28. 'id_group' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
  29. 'name' => array('title' => $this->l('Name'), 'width' => 80, 'filter_key' => 'b!name'),
  30. 'reduction' => array('title' => $this->l('Reduction'), 'width' => 50, 'align' => 'right'),
  31. 'nb' => array('title' => $this->l('Members'), 'width' => 25, 'align' => 'center'),
  32. 'date_add' => array('title' => $this->l('Creation date'), 'width' => 60, 'type' => 'date'));
  33. parent::__construct();
  34. }
  35. public function displayForm()
  36. {
  37. global $currentIndex;
  38. $obj = $this->loadObject(true);
  39. $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
  40. $languages = Language::getLanguages();
  41. echo '
  42. <script type="text/javascript">
  43. id_language = Number('.$defaultLanguage.');
  44. </script>
  45. <form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" class="width3">
  46. '.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
  47. <fieldset><legend><img src="../img/admin/tab-groups.gif" />'.$this->l('Group').'</legend>
  48. <label>'.$this->l('Name:').' </label>
  49. <div class="margin-form">';
  50. foreach ($languages as $language)
  51. echo '
  52. <div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">
  53. <input size="33" type="text" name="name_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'name', intval($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
  54. <span class="hint" name="help_box">'.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer">&nbsp;</span></span>
  55. </div>';
  56. $this->displayFlags($languages, $defaultLanguage, 'name', 'name');
  57. $reduction = htmlentities($this->getFieldValue($obj, 'reduction'), ENT_COMPAT, 'UTF-8');
  58. echo '
  59. </div>
  60. <div class="clear">&nbsp;</div>
  61. <label>'.$this->l('Reduction:').' </label>
  62. <div class="margin-form">
  63. <input type="text" size="5" name="reduction" value="'.($reduction ? $reduction : '0').'" /> '.$this->l('%').'
  64. <p>'.$this->l('Will automatically apply this value as a reduction on ALL shop\'s products for this group\'s members').'</p>
  65. </div>
  66. <div class="clear">&nbsp;</div>
  67. <div class="margin-form">
  68. <input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
  69. </div>
  70. <div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
  71. </fieldset>
  72. </form>';
  73. }
  74. public function viewgroup()
  75. {
  76. global $cookie;
  77. $currentIndex = 'index.php?tab=AdminGroups';
  78. $obj = $this->loadObject(true);
  79. $group = new Group(intval($obj->id));
  80. $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
  81. echo '
  82. <fieldset style="width: 400px">
  83. <div style="float: right"><a href="'.$currentIndex.'&updategroup&id_group='.$obj->id.'&token='.$this->token.'"><img src="../img/admin/edit.gif" /></a></div>
  84. <span style="font-weight: bold; font-size: 14px;">'.strval($obj->name[intval($cookie->id_lang)]).'</span>
  85. <div class="clear">&nbsp;</div>
  86. '.$this->l('Reduction:').' '.floatval($obj->reduction).$this->l('%').'
  87. </fieldset>
  88. <div class="clear">&nbsp;</div>';
  89. $customers = $obj->getCustomers();
  90. $this->fieldsDisplay = (array(
  91. 'ID' => array('title' => $this->l('ID')),
  92. 'sex' => array('title' => $this->l('Sex')),
  93. 'name' => array('title' => $this->l('Name')),
  94. 'e-mail' => array('title' => $this->l('e-mail')),
  95. 'birthdate' => array('title' => $this->l('Birth date')),
  96. 'register_date' => array('title' => $this->l('Register date')),
  97. 'orders' => array('title' => $this->l('Orders')),
  98. 'status' => array('title' => $this->l('Status')),
  99. 'actions' => array('title' => $this->l('Actions'))
  100. ));
  101. if (isset($customers) AND !empty($customers) AND $nbCustomers = sizeof($customers))
  102. {
  103. echo '<h2>'.$this->l('Customers member of this group').' ('.$nbCustomers.')</h2>
  104. <table cellspacing="0" cellpadding="0" class="table widthfull">
  105. <tr>';
  106. foreach ($this->fieldsDisplay AS $field)
  107. echo '<th'.(isset($field['width']) ? 'style="width: '.$field['width'].'"' : '').'>'.$field['title'].'</th>';
  108. echo '
  109. </tr>';
  110. $irow = 0;
  111. foreach ($customers AS $k => $customer)
  112. {
  113. $imgGender = $customer['id_gender'] == 1 ? '<img src="../img/admin/male.gif" alt="'.$this->l('Male').'" />' : ($customer['id_gender'] == 2 ? '<img src="../img/admin/female.gif" alt="'.$this->l('Female').'" />' : '');
  114. echo '
  115. <tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
  116. <td>'.$customer['id_customer'].'</td>
  117. <td class="center">'.$imgGender.'</td>
  118. <td>'.stripslashes($customer['lastname']).' '.stripslashes($customer['firstname']).'</td>
  119. <td>'.stripslashes($customer['email']).'<a href="mailto:'.stripslashes($customer['email']).'"> <img src="../img/admin/email_edit.gif" alt="'.$this->l('Write to this customer').'" /></a></td>
  120. <td>'.Tools::displayDate($customer['birthday'], intval($cookie->id_lang)).'</td>
  121. <td>'.Tools::displayDate($customer['date_add'], intval($cookie->id_lang)).'</td>
  122. <td>'.Order::getCustomerNbOrders($customer['id_customer']).'</td>
  123. <td class="center"><img src="../img/admin/'.($customer['active'] ? 'enabled.gif' : 'forbbiden.gif').'" alt="" /></td>
  124. <td class="center" width="60px">
  125. <a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.intval(Tab::getIdFromClassName('AdminCustomers')).intval($cookie->id_employee)).'">
  126. <img src="../img/admin/details.gif" alt="'.$this->l('View orders').'" /></a>
  127. <a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&addcustomer&token='.Tools::getAdminToken('AdminCustomers'.intval(Tab::getIdFromClassName('AdminCustomers')).intval($cookie->id_employee)).'">
  128. <img src="../img/admin/edit.gif" alt="'.$this->l('Modify this customer').'" /></a>
  129. <a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&deletecustomer&token='.Tools::getAdminToken('AdminCustomers'.intval(Tab::getIdFromClassName('AdminCustomers')).intval($cookie->id_employee)).'" onclick="return confirm(\''.$this->l('Are you sure?', __CLASS__, true, false).'\');">
  130. <img src="../img/admin/delete.gif" alt="'.$this->l('Delete this customer').'" /></a>
  131. </td>
  132. </tr>';
  133. }
  134. echo '</table>';
  135. }
  136. }
  137. public function postProcess()
  138. {
  139. global $currentIndex;
  140. $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
  141. if (isset($_GET['delete'.$this->table]))
  142. {
  143. if ($this->tabAccess['delete'] === '1')
  144. {
  145. if (Validate::isLoadedObject($object = $this->loadObject()))
  146. {
  147. if ($object->id == 1)
  148. $this->_errors[] = Tools::displayError('You cannot delete default group');
  149. else
  150. {
  151. if ($object->delete())
  152. Tools::redirectAdmin($currentIndex.'&conf=1&token='.$token);
  153. $this->_errors[] = Tools::displayError('an error occurred during deletion');
  154. }
  155. }
  156. else
  157. $this->_errors[] = Tools::displayError('an error occurred while deleting object').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
  158. }
  159. else
  160. $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
  161. }
  162. else
  163. parent::postProcess();
  164. }
  165. }