[+] BO : adminTab Groups is now a convert to a AdminController
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10192 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1,558 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7332 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class AdminGroups extends AdminTab
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'group';
|
||||
$this->className = 'Group';
|
||||
$this->lang = true;
|
||||
$this->edit = true;
|
||||
$this->view = true;
|
||||
$this->delete = true;
|
||||
|
||||
$this->_select = '
|
||||
(SELECT COUNT(jcg.`id_customer`)
|
||||
FROM `'._DB_PREFIX_.'customer_group` jcg
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` jc ON (jc.`id_customer` = jcg.`id_customer`)
|
||||
WHERE jc.`deleted` != 1
|
||||
AND jcg.`id_group` = a.`id_group`) AS nb
|
||||
';
|
||||
$this->_listSkipDelete = array(1);
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_group' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 80, 'filter_key' => 'b!name'),
|
||||
'reduction' => array('title' => $this->l('Discount'), 'width' => 50, 'align' => 'right'),
|
||||
'nb' => array('title' => $this->l('Members'), 'width' => 25, 'align' => 'center'),
|
||||
'date_add' => array('title' => $this->l('Creation date'), 'width' => 60, 'type' => 'date', 'align' => 'right'));
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
parent::displayForm();
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
$groupReductions = $obj->id ? GroupReduction::getGroupReductions($obj->id, $this->context->language->id) : array();
|
||||
$categories = Category::getSimpleCategories($this->context->language->id);
|
||||
|
||||
echo '
|
||||
<form id="group" action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post">
|
||||
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
|
||||
<fieldset class="width3"><legend><img src="../img/admin/tab-groups.gif" alt="" />'.$this->l('Customer group').'</legend>
|
||||
<label>'.$this->l('Name:').' </label>
|
||||
<div class="margin-form">';
|
||||
foreach ($this->_languages as $language)
|
||||
echo '
|
||||
<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||||
<input size="33" type="text" name="name_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'name', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
|
||||
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>
|
||||
</div>';
|
||||
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'name', 'name');
|
||||
$reduction = htmlentities($this->getFieldValue($obj, 'reduction'), ENT_COMPAT, 'UTF-8');
|
||||
echo '
|
||||
</div>
|
||||
<div class="clear"> </div>
|
||||
<label>'.$this->l('Discount:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="text" size="5" name="reduction" value="'.($reduction ? $reduction : '0').'" /> '.$this->l('%').'
|
||||
<p>'.$this->l('Will automatically apply this value as a discount on ALL shop\'s products for this group\'s members.').'</p>
|
||||
</div>';
|
||||
if ($obj->id)
|
||||
{
|
||||
echo '
|
||||
<label>'.$this->l('Current category discount:').'</label>
|
||||
<div class="margin-form">';
|
||||
if ($groupReductions)
|
||||
{
|
||||
|
||||
echo '
|
||||
<table>
|
||||
<tr>
|
||||
<th>'.$this->l('Category').'</th>
|
||||
<th>'.$this->l('Value').'</th>
|
||||
<th>'.$this->l('Action').'</th>
|
||||
</tr>';
|
||||
foreach ($groupReductions as $groupReduction)
|
||||
echo '
|
||||
<tr>
|
||||
<td>'.Tools::htmlentitiesUTF8($groupReduction['category_name']).'</td>
|
||||
<td><input type="hidden" name="gr_id_group_reduction[]" value="'.(int)($groupReduction['id_group_reduction']).'" /><input type="text" name="gr_reduction[]" value="'.($groupReduction['reduction'] * 100).'" /></td>
|
||||
<td><a href="'.self::$currentIndex.'&deleteGroupReduction&id_group_reduction='.(int)($groupReduction['id_group_reduction']).'&id_group='.(int)($obj->id).'&token='.$this->token.'"><img src="" alt="'.$this->l('Delete').'" /></a></td>
|
||||
</tr>';
|
||||
echo '</table>';
|
||||
}
|
||||
else
|
||||
echo $this->l('No discount');
|
||||
echo ' </div>';
|
||||
}
|
||||
echo '
|
||||
<label>'.$this->l('Price display method:').' </label>
|
||||
<div class="margin-form">
|
||||
<select name="price_display_method">
|
||||
<option value="'.PS_TAX_EXC.'"'.((int)($this->getFieldValue($obj, 'price_display_method')) == PS_TAX_EXC ? ' selected="selected"' : '').'>'.$this->l('Tax excluded').'</option>
|
||||
<option value="'.PS_TAX_INC.'"'.((int)($this->getFieldValue($obj, 'price_display_method')) == PS_TAX_INC ? ' selected="selected"' : '').'>'.$this->l('Tax included').'</option>
|
||||
</select>
|
||||
<p>'.$this->l('How the prices are displayed on order summary for this customer group (tax included or excluded).').'</p>
|
||||
</div>
|
||||
<div class="clear"> </div>';
|
||||
if (Shop::isFeatureActive())
|
||||
{
|
||||
echo '<label>'.$this->l('GroupShop association:').'</label><div class="margin-form">';
|
||||
$this->displayAssoShop('group_shop');
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<div class="margin-form">
|
||||
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
|
||||
</div>
|
||||
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
|
||||
</fieldset>';
|
||||
$this->displayFormRestrictions($obj->id);
|
||||
echo '
|
||||
</form><br />';
|
||||
|
||||
if ($obj->id)
|
||||
{
|
||||
echo '
|
||||
<form action="'.self::$currentIndex.'&update'.$this->table.'&id_group='.$obj->id.'&token='.$this->token.'" method="post" class="width3">
|
||||
<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />
|
||||
<fieldset><legend><img src="../img/admin/tab-groups.gif" />'.$this->l('New group discount').'</legend>
|
||||
<div class="hintGroup">'.$this->l('Beware the reduction applied to a category does not stack with the overall reduction but replaces it. The group is automatically added to the category.').'</div>
|
||||
<label>'.$this->l('Category:').' </label>
|
||||
<div class="margin-form">
|
||||
<select name="id_category">';
|
||||
foreach ($categories as $category)
|
||||
echo ' <option value="'.(int)($category['id_category']).'">'.Tools::htmlentitiesUTF8($category['name']).'</option>';
|
||||
echo ' </select><sup>*</sup>
|
||||
<p>'.$this->l('Only products that have this category as default category will be affected').'.</p>
|
||||
</div>
|
||||
<label>'.$this->l('Discount (in %):').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="reductionByCategory" value="" /><sup>*</sup>
|
||||
</div>
|
||||
<div class="clear"> </div>
|
||||
<div class="margin-form">
|
||||
<input type="submit" value="'.$this->l(' Add ').'" name="submitAddGroupReduction" class="button" />
|
||||
</div>
|
||||
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
|
||||
</fieldset>
|
||||
</form>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display form client groups restrictions
|
||||
*/
|
||||
protected function displayFormRestrictions($id = false)
|
||||
{
|
||||
$modules = Module::getModulesInstalled();
|
||||
$authorized_modules = '';
|
||||
$auth_modules = array();
|
||||
$unauth_modules = array();
|
||||
|
||||
if ($id)
|
||||
$authorized_modules = Module::getAuthorizedModules($id);
|
||||
else
|
||||
$id = '';
|
||||
|
||||
if (is_array($authorized_modules))
|
||||
{
|
||||
foreach ($modules as $module)
|
||||
{
|
||||
$authorized = false;
|
||||
foreach ($authorized_modules as $auth_module)
|
||||
if ($module['name'] == $auth_module['name'])
|
||||
$authorized = true;
|
||||
|
||||
if ($authorized)
|
||||
$auth_modules[] = $module;
|
||||
else
|
||||
$unauth_modules[] = $module;
|
||||
}
|
||||
}
|
||||
else
|
||||
$auth_modules = $modules;
|
||||
|
||||
echo '
|
||||
<br />
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(document).ready(function(){
|
||||
$(\'#addRestrictions\').click(function() {
|
||||
return !$(\'#selectRestrictions1 option:selected\').remove().appendTo(\'#selectRestrictions2\');
|
||||
});
|
||||
$(\'#removeRestrictions\').click(function() {
|
||||
return !$(\'#selectRestrictions2 option:selected\').remove().appendTo(\'#selectRestrictions1\');
|
||||
});
|
||||
$(\'#group\').submit(function() {
|
||||
$(\'#selectRestrictions1 option\').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
$(\'#selectRestrictions2 option\').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
});
|
||||
$(\'#restriction\').submit(function() {
|
||||
$(\'#selectRestrictions1 option\').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
$(\'#selectRestrictions2 option\').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
});
|
||||
select1 = true;
|
||||
select2 = true;
|
||||
$(\'#selectAll1\').click(function() {
|
||||
if (select1)
|
||||
{
|
||||
select2 = false;
|
||||
$(\'#selectRestrictions1 option\').attr(\'selected\', \'selected\');
|
||||
$(this).text(\''.$this->l('Unselect All', get_class($this), false, false).'\');
|
||||
}
|
||||
else
|
||||
{
|
||||
select2 = true;
|
||||
$(\'#selectRestrictions1 option\').removeAttr(\'selected\');
|
||||
$(this).text(\''.$this->l('Select All', get_class($this), false, false).'\');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$(\'#selectAll2\').click(function() {
|
||||
if (select2)
|
||||
{
|
||||
select2 = false;
|
||||
$(\'#selectRestrictions2 option\').attr(\'selected\', \'selected\');
|
||||
$(this).text(\''.$this->l('Unselect All', get_class($this), false, false).'\');
|
||||
}
|
||||
else
|
||||
{
|
||||
select2 = true;
|
||||
$(\'#selectRestrictions2 option\').removeAttr(\'selected\');
|
||||
$(this).text(\''.$this->l('Select All', get_class($this), false, false).'\');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<fieldset><legend><img src="../img/admin/access.png" />'.$this->l('Modules restrictions').'</legend>
|
||||
<table class="margin-form">
|
||||
<tr>
|
||||
<td>
|
||||
<p>'.$this->l('Unauthorized modules:').'</p>
|
||||
<select multiple id="selectRestrictions1" name="unauthorized_modules[]" style="width:300px;height:160px;">';
|
||||
foreach ($unauth_modules as $module)
|
||||
{
|
||||
$module = Module::getInstanceById($module['id_module']);
|
||||
echo ' <option value="'.$module->name.'">'.Tools::htmlentitiesUTF8($module->displayName).'</option>';
|
||||
}
|
||||
echo ' </select><br /><br />
|
||||
<a href="#" id="selectAll1" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
|
||||
'.$this->l('Select All').'
|
||||
</a>
|
||||
<a href="#" id="addRestrictions" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
|
||||
'.$this->l('Authorize').' >>
|
||||
</a>
|
||||
</td>
|
||||
<td style="padding-left:20px;">
|
||||
<p>'.$this->l('Authorized modules:').'</p>
|
||||
<select multiple id="selectRestrictions2" name="authorized_modules[]" style="width:300px;height:160px;">';
|
||||
foreach ($auth_modules as $module)
|
||||
{
|
||||
$module = Module::getInstanceById($module['id_module']);
|
||||
echo ' <option value="'.$module->name.'">'.Tools::htmlentitiesUTF8($module->displayName).'</option>';
|
||||
}
|
||||
echo ' </select><br /><br />
|
||||
<a href="#" id="selectAll2" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
|
||||
'.$this->l('Select All').'
|
||||
</a>
|
||||
<a href="#" id="removeRestrictions" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
|
||||
<< '.$this->l('Unauthorize').'
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="clear"> </div>
|
||||
<div class="margin-form">
|
||||
<input type="submit" name="submitRestrictions" id="submitRestrictions" value="'.$this->l('Update restrictions').'" class="button" />
|
||||
</div>
|
||||
</fieldset>';
|
||||
}
|
||||
|
||||
public function viewgroup()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
self::$currentIndex = 'index.php?tab=AdminGroups';
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
echo '
|
||||
<fieldset style="width: 400px">
|
||||
<div style="float: right"><a href="'.self::$currentIndex.'&updategroup&id_group='.$obj->id.'&token='.$this->token.'"><img src="../img/admin/edit.gif" /></a></div>
|
||||
<span style="font-weight: bold; font-size: 14px;">'.strval($obj->name[(int)$this->context->language->id]).'</span>
|
||||
<div class="clear"> </div>
|
||||
'.$this->l('Discount:').' '.(float)($obj->reduction).$this->l('%').'
|
||||
</fieldset>
|
||||
<div class="clear"> </div>';
|
||||
|
||||
$this->fieldsDisplay = (array(
|
||||
'ID' => array('title' => $this->l('ID')),
|
||||
'sex' => array('title' => $this->l('Sex')),
|
||||
'name' => array('title' => $this->l('Name')),
|
||||
'e-mail' => array('title' => $this->l('e-mail')),
|
||||
'birthdate' => array('title' => $this->l('Birth date')),
|
||||
'register_date' => array('title' => $this->l('Registration date')),
|
||||
'orders' => array('title' => $this->l('Orders')),
|
||||
'status' => array('title' => $this->l('Status')),
|
||||
'actions' => array('title' => $this->l('Actions'))
|
||||
));
|
||||
|
||||
if ($nbCustomers = $obj->getCustomers(true))
|
||||
{
|
||||
echo '<h2>'.$this->l('Customer members of this group').' ('.$nbCustomers.')</h2>';
|
||||
|
||||
// Pagination Begin
|
||||
$customersPerPage = (Tools::getValue('customerPerPage') ? (int)Tools::getValue('customerPerPage') : 50);
|
||||
$totalPages = ceil($nbCustomers / $customersPerPage);
|
||||
$perPageOptions = array(20, 50, 100, 300);
|
||||
|
||||
$customerPageIndex = (Tools::getValue('customerPageIndex') && Tools::getValue('customerPageIndex') <= $totalPages ? (int)Tools::getValue('customerPageIndex') : 1);
|
||||
$from = (Tools::getValue('customerPageIndex') ? ((int)$customerPageIndex - 1) * ((int)$customersPerPage) : 0);
|
||||
|
||||
$customers = $obj->getCustomers(false, $from, $customersPerPage);
|
||||
|
||||
echo '<table><tr>
|
||||
<form method="post" action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'">
|
||||
<td style="vertical-align: bottom;"><span style="float: left; height:30px">';
|
||||
|
||||
if ($customerPageIndex > 1)
|
||||
{
|
||||
echo ' <input type="image" onclick="document.getElementById(\'customerPageIndex\').value=1" src="../img/admin/list-prev2.gif"> ';
|
||||
echo ' <input type="image" onclick="document.getElementById(\'customerPageIndex\').value='.($customerPageIndex - 1).'" src="../img/admin/list-prev.gif"> ';
|
||||
}
|
||||
|
||||
echo 'Page <b><select onChange="submit()" name="customerPageIndex" id="customerPageIndex">';
|
||||
for ($i = 1; $i <= $totalPages; $i++)
|
||||
echo '<option value="'.$i.'"'.((int)$customerPageIndex === $i ? 'selected="selected"' : '').'>'.$i.'</option>';
|
||||
echo '</select></b> / '.$totalPages;
|
||||
|
||||
if ($customerPageIndex < $totalPages)
|
||||
{
|
||||
echo ' <input type="image" onclick="document.getElementById(\'customerPageIndex\').value='.((int)$customerPageIndex + 1).'" src="../img/admin/list-next.gif">';
|
||||
echo ' <input type="image" onclick="document.getElementById(\'customerPageIndex\').value='.$totalPages.'" src="../img/admin/list-next2.gif">';
|
||||
}
|
||||
|
||||
echo ' | Display
|
||||
<select onchange="document.getElementById(\'customerPageIndex\').value=1; submit();" name="customerPerPage">';
|
||||
foreach ($perPageOptions as $option)
|
||||
echo '<option value="'.$option.'"'.((int)$customersPerPage == $option ? 'selected="selected"' : '').'>'.$option.'</option>';
|
||||
echo ' </select> / '.$nbCustomers.' result(s)
|
||||
</span><span class="clear"></span></td>
|
||||
</form>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="clear"></div>';
|
||||
// Pagination End
|
||||
|
||||
echo '<table cellspacing="0" cellpadding="0" class="table widthfull">
|
||||
<tr>';
|
||||
foreach ($this->fieldsDisplay as $field)
|
||||
echo '<th'.(isset($field['width']) ? 'style="width: '.$field['width'].'"' : '').'>'.$field['title'].'</th>';
|
||||
echo '
|
||||
</tr>';
|
||||
$irow = 0;
|
||||
|
||||
foreach ($customers as $k => $customer)
|
||||
{
|
||||
echo '
|
||||
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
||||
<td>'.$customer['id_customer'].'</td>
|
||||
<td class="center"><img src="'.Gender::getStaticImage($customer['id_gender']).'" /></td>
|
||||
<td>'.stripslashes($customer['lastname']).' '.stripslashes($customer['firstname']).'</td>
|
||||
<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>
|
||||
<td>'.Tools::displayDate($customer['birthday'], $this->context->language->id).'</td>
|
||||
<td>'.Tools::displayDate($customer['date_add'], $this->context->language->id).'</td>
|
||||
<td>'.Order::getCustomerNbOrders($customer['id_customer']).'</td>
|
||||
<td class="center"><img src="../img/admin/'.($customer['active'] ? 'enabled.gif' : 'forbbiden.gif').'" alt="" /></td>
|
||||
<td class="center" width="60px">
|
||||
<a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'">
|
||||
<img src="../img/admin/details.gif" alt="'.$this->l('View orders').'" /></a>
|
||||
<a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&addcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'">
|
||||
<img src="../img/admin/edit.gif" alt="'.$this->l('Modify this customer').'" /></a>
|
||||
<a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&deletecustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'" onclick="return confirm(\''.$this->l('Are you sure?', __CLASS__, true, false).'\');">
|
||||
<img src="../img/admin/delete.gif" alt="'.$this->l('Delete this customer').'" /></a>
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
else
|
||||
echo '<p><img src="../img/admin/information.png" style="float:left;margin-right:5px;" alt="" /> '.$this->l('No user in this group.').'</p>';
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
|
||||
|
||||
if (Tools::isSubmit('deleteGroupReduction'))
|
||||
{
|
||||
if ($this->tabAccess['delete'] === '1')
|
||||
{
|
||||
if (!$id_group_reduction = Tools::getValue('id_group_reduction'))
|
||||
$this->_errors[] = Tools::displayError('Invalid group reduction ID');
|
||||
else
|
||||
{
|
||||
$groupReduction = new GroupReduction((int)($id_group_reduction));
|
||||
if (!$groupReduction->delete())
|
||||
$this->_errors[] = Tools::displayError('An error occurred while deleting the group reduction');
|
||||
else
|
||||
Tools::redirectAdmin(self::$currentIndex.'&update'.$this->table.'&id_group='.(int)(Tools::getValue('id_group')).'&conf=1&token='.$token);
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
|
||||
}
|
||||
if (Tools::isSubmit('submitAddGroupReduction'))
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
{
|
||||
if (!($obj = $this->loadObject()))
|
||||
return;
|
||||
$groupReduction = new GroupReduction();
|
||||
if (!$id_category = Tools::getValue('id_category') || !Validate::isUnsignedId($id_category))
|
||||
$this->_errors[] = Tools::displayError('Wrong category ID');
|
||||
else if (!$reduction = Tools::getValue('reductionByCategory') || !Validate::isPrice($reduction))
|
||||
$this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)');
|
||||
else if (Tools::getValue('reductionByCategory') > 100 || Tools::getValue('reductionByCategory') < 0)
|
||||
$this->_errors[] = Tools::displayError('Reduction value is incorrect');
|
||||
else if (GroupReduction::doesExist((int)$obj->id, $id_category))
|
||||
$this->_errors[] = Tools::displayError('A reduction already exists for this category.');
|
||||
else
|
||||
{
|
||||
$reduction = Tools::getValue('reductionByCategory');
|
||||
$id_category = Tools::getValue('id_category');
|
||||
|
||||
$category = new Category((int)($id_category));
|
||||
$category->addGroupsIfNoExist(Tools::getValue('id_group'));
|
||||
|
||||
$groupReduction->id_category = (int)($id_category);
|
||||
$groupReduction->id_group = (int)($obj->id);
|
||||
$groupReduction->reduction = (float)($reduction) / 100;
|
||||
if (!$groupReduction->add())
|
||||
$this->_errors[] = Tools::displayError('An error occurred while adding a category group reduction.');
|
||||
else
|
||||
Tools::redirectAdmin(self::$currentIndex.'&update'.$this->table.'&id_group='.(int)(Tools::getValue('id_group')).'&conf=3&token='.$this->token);
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitRestrictions'))
|
||||
{
|
||||
$this->updateRestrictions();
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitAddgroup'))
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
{
|
||||
if (Tools::getValue('reduction') > 100 || Tools::getValue('reduction') < 0)
|
||||
$this->_errors[] = Tools::displayError('Reduction value is incorrect');
|
||||
else
|
||||
{
|
||||
$id_group_reductions = Tools::getValue('gr_id_group_reduction');
|
||||
$reductions = Tools::getValue('gr_reduction');
|
||||
if ($id_group_reductions)
|
||||
{
|
||||
foreach ($id_group_reductions as $key => $id_group_reduction)
|
||||
if (!Validate::isUnsignedId($id_group_reductions[$key]) || !Validate::isPrice($reductions[$key]))
|
||||
$this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)');
|
||||
else if ($reductions[$key] > 100 || $reductions[$key] < 0)
|
||||
$this->_errors[] = Tools::displayError('Reduction value is incorrect');
|
||||
else
|
||||
{
|
||||
$groupReduction = new GroupReduction((int)($id_group_reductions[$key]));
|
||||
$groupReduction->reduction = $reductions[$key] / 100;
|
||||
if (!$groupReduction->update())
|
||||
$this->_errors[] = Tools::displayError('Cannot update group reductions');
|
||||
}
|
||||
}
|
||||
if (!count($this->_errors))
|
||||
{
|
||||
parent::postProcess();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||
}
|
||||
else if (isset($_GET['delete'.$this->table]))
|
||||
{
|
||||
if ($this->tabAccess['delete'] === '1')
|
||||
{
|
||||
if (Validate::isLoadedObject($object = $this->loadObject()))
|
||||
{
|
||||
if ($object->id == 1)
|
||||
$this->_errors[] = Tools::displayError('You cannot delete default group.');
|
||||
else
|
||||
{
|
||||
if ($object->delete())
|
||||
Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.$token);
|
||||
$this->_errors[] = Tools::displayError('An error occurred during deletion.');
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
|
||||
}
|
||||
else
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update (or create) restrictions for modules by group
|
||||
*/
|
||||
protected function updateRestrictions()
|
||||
{
|
||||
$id_group = Tools::getValue('id_group');
|
||||
$unauth_modules = Tools::getValue('unauthorized_modules');
|
||||
$auth_modules = Tools::getValue('authorized_modules');
|
||||
Group::truncateModulesRestrictions($id_group);
|
||||
if (is_array($auth_modules))
|
||||
Group::addModulesRestrictions($id_group, $auth_modules, 1);
|
||||
if (is_array($unauth_modules))
|
||||
Group::addModulesRestrictions($id_group, $unauth_modules, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 8971 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
{extends file="helper/form/form.tpl"}
|
||||
|
||||
{block name="label"}
|
||||
{if $input['type'] == 'modules'}
|
||||
<div style="{if !$form_id}display:none{/if}">
|
||||
<div class="separation"></div>
|
||||
<label>{l s='Modules restrictions: '}</label>
|
||||
</div>
|
||||
{elseif $input['type'] == 'group_discount_category'}
|
||||
<div style="{if !$form_id}display:none{/if}">
|
||||
<div class="separation"></div>
|
||||
<label>{$input.label} </label>
|
||||
</div>
|
||||
{else}
|
||||
<label>{$input.label} </label>
|
||||
{/if}
|
||||
{/block}
|
||||
|
||||
|
||||
{block name="start_field_block"}
|
||||
{if $input['type'] == 'group_discount_category'}
|
||||
<div style="{if !$form_id}display:none{/if}">
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#group_discount_category").fancybox({
|
||||
onStart: function () {
|
||||
$('#group_discount_category_fancybox').show();
|
||||
initFancyBox();
|
||||
},
|
||||
onClosed: function () {
|
||||
$('#group_discount_category_fancybox').hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function deleteCategoryReduction(id_category)
|
||||
{
|
||||
$('#group_discount_category_table tr#'+id_category).fadeOut('slow', function () {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
}
|
||||
function toogleCheck(elt)
|
||||
{
|
||||
if ($(elt).hasClass('select_all'))
|
||||
{
|
||||
$(elt).addClass('unselect_all').removeClass('select_all');
|
||||
$('ul#sortable_module_'+$(elt).attr('id')).find('input[type="checkbox"]').removeAttr('checked');
|
||||
$(elt).html('{l s="Select all"}');
|
||||
}
|
||||
else
|
||||
{
|
||||
$(elt).addClass('select_all').removeClass('unselect_all');
|
||||
$('ul#sortable_module_'+$(elt).attr('id')).find('input[type="checkbox"]').attr('checked', 'checked');
|
||||
$(elt).html('{l s="Unselect all"}');
|
||||
}
|
||||
}
|
||||
|
||||
function unauthorizeChecked()
|
||||
{
|
||||
$('ul#sortable_module_unauthorize_list').find('input[type="checkbox"]:checked').each( function () {
|
||||
$('ul#sortable_module_authorize_list').prepend($(this).parent());
|
||||
$(this).removeAttr('checked');
|
||||
$(this).parent().children('input["type=hidden"]').attr('name', 'modulesBoxAuth[]');
|
||||
});
|
||||
}
|
||||
|
||||
function authorizeChecked()
|
||||
{
|
||||
$('ul#sortable_module_authorize_list').find('input[type="checkbox"]:checked').each( function () {
|
||||
$('ul#sortable_module_unauthorize_list').prepend($(this).parent());
|
||||
$(this).removeAttr('checked');
|
||||
$(this).parent().children('input["type=hidden"]').attr('name', 'modulesBoxUnauth[]');
|
||||
});
|
||||
}
|
||||
|
||||
function addCategoryReduction()
|
||||
{
|
||||
exist = false;
|
||||
$('.category_reduction').each( function () {
|
||||
if ($(this).attr('name') == 'category_reduction['+$('[name="id_category"]:checked').val()+']')
|
||||
{
|
||||
exist = true;
|
||||
alert('{l s='This category already exist for this group'}');
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (exist)
|
||||
return;
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url: "ajax-tab.php",
|
||||
async: true,
|
||||
dataType: "json",
|
||||
data : {
|
||||
ajax: "1",
|
||||
token: "{getAdminToken tab='AdminGroups'}",
|
||||
controller: "AdminGroups",
|
||||
action: "addCategoryReduction",
|
||||
category_reduction: $('#category_reduction_fancybox').val() ,
|
||||
id_category: $('[name="id_category"]:checked').val()
|
||||
},
|
||||
success : function(jsonData)
|
||||
{
|
||||
if (jsonData.hasError)
|
||||
{
|
||||
var errors = '';
|
||||
for(error in jsonData.errors)
|
||||
//IE6 bug fix
|
||||
if(error != 'indexOf')
|
||||
errors += jsonData.errors[error] + "\n";
|
||||
alert(errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#group_discount_category_table').append('<tr class="alt_row" id="'+jsonData.id_category+'"><td>'+jsonData.catPath+'</td><td>{l s='Discount:'}'+jsonData.discount+'{l s='%'}</td><td><a href="#" onclick="deleteCategoryReduction('+jsonData.id_category+');"><img src="../img/admin/delete.gif"></a></td></tr>');
|
||||
|
||||
var input_hidden = document.createElement("input");
|
||||
input_hidden.setAttribute('type', 'hidden');
|
||||
input_hidden.setAttribute('value', jsonData.discount);
|
||||
input_hidden.setAttribute('name', 'category_reduction['+jsonData.id_category+']');
|
||||
input_hidden.setAttribute('class', 'category_reduction');
|
||||
|
||||
$('#group_discount_category_table tr#'+jsonData.id_category+' > td:last').append(input_hidden);
|
||||
$.fancybox.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function initFancyBox()
|
||||
{
|
||||
$('[name="id_category"]:checked').removeAttr('checked');
|
||||
collapseAllCategories();
|
||||
$('#category_reduction_fancybox').val('0.00');
|
||||
}
|
||||
</script>
|
||||
<div class="margin-form">
|
||||
<a class="button" href="#group_discount_category_fancybox" id="group_discount_category">{l s='Add a category discount'}</a>
|
||||
<table cellspacing="0" cellpadding="0" class="table" style="margin-top:10px" id="group_discount_category_table">
|
||||
{foreach $input['values'] key=key item=category }
|
||||
<tr class="alt_row" id="{$category.id_category}">
|
||||
<td>{$category.path}</td>
|
||||
<td>{l s='Discount:'} {$category.reduction}{l s='%'}</td>
|
||||
<td>
|
||||
<a href="#" onclick="deleteCategoryReduction({$category.id_category});"><img src="../img/admin/delete.gif"></a>
|
||||
<input type="hidden" class="category_reduction" name="category_reduction[{$category.id_category}]" value="{$category.reduction}">
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
|
||||
<div style="display:none" id="group_discount_category_fancybox">
|
||||
<fieldset style="text-align:left"><legend><img src="../img/admin/tab-groups.gif" />{l s='New group category discount'}</legend>
|
||||
<div class="hintGroup" style="font-size: 13px;">
|
||||
{l s='Beware the reduction applied to a category does not stack with the overall reduction but replaces it. The group is automatically added to the category.'}
|
||||
</div>
|
||||
{$categoryTreeView}
|
||||
<div class="warn">{l s='Only products that have this category as the default category will be affected'}</div>
|
||||
<div class="clear"> </div>
|
||||
<label>{l s='Discount (in %):'}</label>
|
||||
<input type="text" name="category_reduction_fancybox" id="category_reduction_fancybox" value="0.00" size="33">
|
||||
<div class="clear"> </div>
|
||||
<button onclick="addCategoryReduction();" class="button">{l s='add'}</button>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
{elseif $input['type'] == 'modules'}
|
||||
<div style="{if !$form_id}display:none{/if}">
|
||||
<div class="margin-form">
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$( "#sortable_module_authorize_list, #sortable_module_unauthorize_list" ).sortable({
|
||||
connectWith: ".connectedSortable",
|
||||
stop: function(event, ui)
|
||||
{
|
||||
console.log($(event.toElement).parent('ul').attr('id'));
|
||||
if ($(event.toElement).parent('ul').attr('id') == 'sortable_module_authorize_list')
|
||||
$(event.toElement).children('input["type=hidden"]').attr('name', 'modulesBoxAuth[]');
|
||||
else
|
||||
$(event.toElement).children('input["type=hidden"]').attr('name', 'modulesBoxUnauth[]');
|
||||
}
|
||||
}).disableSelection();
|
||||
});
|
||||
</script>
|
||||
<table cellspacing="0" cellpadding="0" class="table" style="width:600px">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="padding-left:10px;">
|
||||
{$input['label']['auth_modules']}
|
||||
</th>
|
||||
<th style="padding-left:10px;">
|
||||
{$input['label']['unauth_modules']}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width:300px">
|
||||
<ul id="sortable_module_authorize_list" class="connectedSortable" style="height:300px;overflow:auto">
|
||||
<li></li>
|
||||
{foreach $input['values']['auth_modules'] key=key item=module }
|
||||
<li class="module_list" id="module_{$module->id}">
|
||||
<input type="checkbox" style="margin-right:5px">
|
||||
<img src="../modules/{$module->name}/logo.gif">
|
||||
{$module->displayName}
|
||||
<input type="hidden" name="modulesBoxAuth[]" value="{$module->id}">
|
||||
</li>
|
||||
|
||||
{/foreach}
|
||||
</ul>
|
||||
</td>
|
||||
<td style="width:300px">
|
||||
<ul id="sortable_module_unauthorize_list" class="connectedSortable" style="height:300px;overflow:auto">
|
||||
<li></li>
|
||||
{foreach $input['values']['unauth_modules'] key=key item=module }
|
||||
<li class="module_list" id="module_{$module->id}">
|
||||
<input type="checkbox" style="margin-right:5px">
|
||||
<img src="../modules/{$module->name}/logo.gif">
|
||||
{$module->displayName}
|
||||
<input type="hidden" name="modulesBoxUnauth[]" value="{$module->id}">
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td style="text-align:center">
|
||||
<button style="width:100%;margin-top:5px" id="authorize_list" onclick="toogleCheck(this);return false;" class="button">{l s="Select all"}</button>
|
||||
<button style="width:100%;margin-top:5px;margin-bottom:5px" onclick="authorizeChecked();return false;" class="button">{l s="<< Unauthorize"}</button>
|
||||
</td>
|
||||
<td style="text-align:center">
|
||||
<button style="width:100%;margin-top:5px"id="unauthorize_list" onclick="toogleCheck(this);return false;" class="button">{l s="Select all"}</button>
|
||||
<button style="width:100%;margin-top:5px;margin-bottom:5px" onclick="unauthorizeChecked();return false;" class="button">{l s="<< Authorize"}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
{else}
|
||||
<div class="margin-form">
|
||||
{/if}
|
||||
{/block}
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9596 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
<fieldset style="width: 400px">
|
||||
<span style="font-weight: bold; font-size: 14px;">{l s='Name:'}</span>
|
||||
<div class="clear"> </div>
|
||||
<span style="font-weight: bold; font-size: 14px;">{l s='Discount:'}</span> {$group->reduction} {l s='%'}
|
||||
<div class="clear"> </div>
|
||||
<span style="font-weight: bold; font-size: 14px;">{l s='Current category discount:'}</span>
|
||||
{if !$categorieReductions}
|
||||
{l s='None'}
|
||||
{else}
|
||||
<table cellspacing="0" cellpadding="0" class="table" style="margin-top:10px">
|
||||
{foreach $categorieReductions key=key item=category }
|
||||
<tr class="alt_row">
|
||||
<td>{$category.path}</td>
|
||||
<td>{l s='Discount:'} {$category.reduction}{l s='%'}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{/if}
|
||||
<div class="clear"> </div>
|
||||
<span style="font-weight: bold; font-size: 14px;">{l s='Price display method:'}</span>
|
||||
{if $group->price_display_method}
|
||||
{l s='Tax excluded'}
|
||||
{else}
|
||||
{l s='Tax included'}
|
||||
{/if}
|
||||
<div class="clear"> </div>
|
||||
</fieldset>
|
||||
<h2>{l s='Customer members of this group'}</h2>
|
||||
{$customerList}
|
||||
Reference in New Issue
Block a user