[*] BO #PSFV-94 : Added AdminAccessController
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9896 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+88
-7
@@ -949,22 +949,22 @@ if (Tools::isSubmit('searchCategory'))
|
||||
'SELECT c.`id_category`, cl.`name`
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.$context->shop->addSqlRestrictionOnLang('cl').')
|
||||
WHERE cl.`id_lang` = '.(int)($context->language->id).' AND c.`level_depth` <> 0
|
||||
WHERE cl.`id_lang` = '.(int)$context->language->id.' AND c.`level_depth` <> 0
|
||||
AND cl.`name` LIKE \'%'.pSQL($q).'%\'
|
||||
GROUP BY c.id_category
|
||||
ORDER BY c.`position`
|
||||
LIMIT '.(int)$limit);
|
||||
if ($results)
|
||||
foreach ($results AS $result)
|
||||
echo trim($result['name']).'|'.(int)($result['id_category'])."\n";
|
||||
foreach ($results as $result)
|
||||
echo trim($result['name']).'|'.(int)$result['id_category']."\n";
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('getParentCategoriesId') AND $id_category = Tools::getValue('id_category'))
|
||||
if (Tools::isSubmit('getParentCategoriesId') && $id_category = Tools::getValue('id_category'))
|
||||
{
|
||||
$category = new Category((int)$id_category);
|
||||
$results = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category` c WHERE c.`nleft` < '.(int)$category->nleft.' AND c.`nright` > '.(int)$category->nright.'');
|
||||
$output = array();
|
||||
foreach($results as $result)
|
||||
foreach ($results as $result)
|
||||
$output[] = $result;
|
||||
|
||||
die(Tools::jsonEncode($output));
|
||||
@@ -976,9 +976,90 @@ if (Tools::isSubmit('ajaxUpdateTaxRule'))
|
||||
$id_tax_rule = Tools::getValue('id_tax_rule');
|
||||
$tax_rules = new TaxRule((int)$id_tax_rule);
|
||||
$output = array();
|
||||
foreach($tax_rules as $key => $result)
|
||||
foreach ($tax_rules as $key => $result)
|
||||
$output[$key] = $result;
|
||||
die(Tools::jsonEncode($output));
|
||||
|
||||
}
|
||||
|
||||
/* Update Access Tabs */
|
||||
if (Tools::isSubmit('submitAddAccess'))
|
||||
{
|
||||
$perm = Tools::getValue('perm');
|
||||
if (!in_array($perm, array('view', 'add', 'edit', 'delete', 'all')))
|
||||
throw new PrestashopException('permission not exists');
|
||||
|
||||
$enabled = (int)Tools::getValue('enabled');
|
||||
$id_tab = (int)Tools::getValue('id_tab');
|
||||
$id_profile = (int)Tools::getValue('id_profile');
|
||||
$res = true;
|
||||
|
||||
if ($id_tab == -1 && $perm == 'all' && $enabled == 0)
|
||||
$res &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.'
|
||||
WHERE `id_profile` = '.(int)$id_profile.' AND `id_tab` != 31
|
||||
');
|
||||
else if ($id_tab == -1 && $perm == 'all')
|
||||
$res &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.'
|
||||
WHERE `id_profile` = '.(int)$id_profile
|
||||
);
|
||||
else if ($id_tab == -1)
|
||||
$res &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
SET `'.pSQL($perm).'` = '.$enabled.'
|
||||
WHERE `id_profile` = '.(int)$id_profile
|
||||
);
|
||||
else if ($perm == 'all')
|
||||
$res &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.'
|
||||
WHERE `id_tab` = '.(int)$id_tab.'
|
||||
AND `id_profile` = '.(int)$id_profile
|
||||
);
|
||||
else
|
||||
$res &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
SET `'.pSQL($perm).'` = '.$enabled.'
|
||||
WHERE `id_tab` = '.(int)$id_tab.'
|
||||
AND `id_profile` = '.(int)$id_profile
|
||||
);
|
||||
$res = $res?'ok':'error';
|
||||
die(Tools::jsonEncode($res));
|
||||
}
|
||||
|
||||
/* Update Access Modules */
|
||||
if (Tools::isSubmit('changeModuleAccess'))
|
||||
{
|
||||
$perm = Tools::getValue('perm');
|
||||
$enabled = (int)Tools::getValue('enabled');
|
||||
$id_module = (int)Tools::getValue('id_module');
|
||||
$id_profile = (int)Tools::getValue('id_profile');
|
||||
$res = true;
|
||||
|
||||
if (!in_array($perm, array('view', 'configure')))
|
||||
throw new PrestashopException('permission not exists');
|
||||
|
||||
if ($id_module == -1)
|
||||
{
|
||||
$res &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'module_access`
|
||||
SET `'.pSQL($perm).'` = '.(int)$enabled.'
|
||||
WHERE `id_profile` = '.(int)$id_profile
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'module_access`
|
||||
SET `'.pSQL($perm).'` = '.(int)$enabled.'
|
||||
WHERE `id_module` = '.(int)$id_module.'
|
||||
AND `id_profile` = '.(int)$id_profile
|
||||
);
|
||||
}
|
||||
|
||||
$res = $res?'ok':'error';
|
||||
die(Tools::jsonEncode($res));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,365 +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: 6844 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
include_once(_PS_ADMIN_DIR_.'/../classes/AdminTab.php');
|
||||
|
||||
class AdminAccess extends AdminTab
|
||||
{
|
||||
private $return_status;
|
||||
private $return_message;
|
||||
|
||||
public function processSubmitAddAccess()
|
||||
{
|
||||
$perm = Tools::getValue('perm') ;
|
||||
if (!in_array($perm, array('view', 'add', 'edit', 'delete', 'all')))
|
||||
throw new PrestashopException('permission not exists');
|
||||
|
||||
$enabled = (int)Tools::getValue('enabled');
|
||||
$id_tab = (int)(Tools::getValue('id_tab'));
|
||||
$id_profile = (int)(Tools::getValue('id_profile'));
|
||||
$res = true;
|
||||
|
||||
if ($id_tab == -1 AND $perm == 'all' AND $enabled == 0)
|
||||
$res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'access` SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.' WHERE `id_profile` = '.(int)($id_profile).' AND `id_tab` != 31');
|
||||
else if ($id_tab == -1 AND $perm == 'all')
|
||||
$res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'access` SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.' WHERE `id_profile` = '.(int)($id_profile));
|
||||
else if ($id_tab == -1)
|
||||
$res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'access` SET `'.pSQL($perm).'` = '.$enabled.' WHERE `id_profile` = '.(int)($id_profile));
|
||||
else if ($perm == 'all')
|
||||
$res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'access` SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.' WHERE `id_tab` = '.(int)($id_tab).' AND `id_profile` = '.(int)($id_profile));
|
||||
else
|
||||
$res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'access` SET `'.pSQL($perm).'` = '.$enabled.' WHERE `id_tab` = '.(int)($id_tab).' AND `id_profile` = '.(int)($id_profile));
|
||||
|
||||
$this->return_status = $res?'ok':'error';
|
||||
if ($res)
|
||||
$this->return_message = $this->l('Access successfully updated');
|
||||
else
|
||||
$this->return_message = $this->l('An error when updating access');
|
||||
}
|
||||
|
||||
public function processChangeModuleAccess()
|
||||
{
|
||||
$perm = Tools::getValue('perm');
|
||||
$enabled = (int)Tools::getValue('enabled');
|
||||
$id_module = (int)Tools::getValue('id_module');
|
||||
$id_profile = (int)Tools::getValue('id_profile');
|
||||
$res = true;
|
||||
|
||||
if (!in_array($perm, array('view', 'configure')))
|
||||
throw new PrestashopException('permission not exists');
|
||||
|
||||
if ($id_module == -1)
|
||||
$res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'module_access` SET `'.pSQL($perm).'` = '.(int)$enabled.' WHERE `id_profile` = '.(int)$id_profile);
|
||||
else
|
||||
$res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'module_access` SET `'.pSQL($perm).'` = '.(int)$enabled.' WHERE `id_module` = '.(int)$id_module.' AND `id_profile` = '.(int)$id_profile);
|
||||
|
||||
$this->return_status = $res?'ok':'error';
|
||||
if ($res)
|
||||
$this->return_message = $this->l('Access successfully updated.');
|
||||
else
|
||||
$this->return_message = $this->l('An error when updating access.');
|
||||
}
|
||||
|
||||
|
||||
public function displayAjax()
|
||||
{
|
||||
$return = array('result'=>$this->return_status,'msg'=>$this->return_message);
|
||||
|
||||
echo Tools::jsonEncode($return);
|
||||
}
|
||||
public function display()
|
||||
{
|
||||
$this->displayForm();
|
||||
echo '<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$(".ajaxPower").change(function(){
|
||||
var tout = $(this).attr("rel").split("||");
|
||||
var id_tab = tout[0];
|
||||
var id_profile = tout[1];
|
||||
var perm = tout[2];
|
||||
var enabled = $(this).is(":checked")? 1 : 0;
|
||||
var tabsize = tout[3];
|
||||
var tabnumber = tout[4];
|
||||
|
||||
perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber);
|
||||
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url : "ajax-tab.php",
|
||||
async: true,
|
||||
data : {
|
||||
id_tab:id_tab,
|
||||
id_profile:id_profile,
|
||||
perm:perm,
|
||||
enabled:enabled,
|
||||
submitAddaccess:"1",
|
||||
ajaxMode : "1",
|
||||
token : "'.$this->token.'",
|
||||
controller:"AdminAccess"
|
||||
},
|
||||
success : function(res,textStatus,jqXHR)
|
||||
{
|
||||
try
|
||||
{
|
||||
res = $.parseJSON(res);
|
||||
if (res.result == "ok")
|
||||
showSuccessMessage(res.msg);
|
||||
else
|
||||
showErrorMessage(res.msg);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert("oups");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});</script>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current profile id
|
||||
*
|
||||
* @return the $_GET['profile'] if valid, else 1 (the first profile id)
|
||||
*/
|
||||
function getCurrentProfileId()
|
||||
{
|
||||
return (isset($_GET['profile']) AND !empty($_GET['profile']) AND is_numeric($_GET['profile'])) ? (int)($_GET['profile']) : 1;
|
||||
}
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
parent::displayForm();
|
||||
$currentProfile = (int)($this->getCurrentProfileId());
|
||||
$tabs = Tab::getTabs($this->context->language->id);
|
||||
$profiles = Profile::getProfiles($this->context->language->id);
|
||||
$accesses = Profile::getProfileAccesses($currentProfile);
|
||||
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
setLang(Array(\''.$this->l('Profile updated').'\', \''.$this->l('Request failed!').'\', \''.$this->l('Update in progress. Please wait.').'\', \''.$this->l('Server connection failed!').'\'));
|
||||
</script>
|
||||
<table class="table float" cellspacing="0">
|
||||
<tr>
|
||||
<th '.($currentProfile == (int)_PS_ADMIN_PROFILE_ ? 'colspan="6"' : '').'>
|
||||
<select name="profile" onchange="redirect(\''.Tools::getHttpHost(true, true).self::$currentIndex.'&token='.$this->token.'&profile=\'+this.options[this.selectedIndex].value)">';
|
||||
if ($profiles)
|
||||
foreach ($profiles AS $profile)
|
||||
echo '<option value="'.(int)$profile['id_profile'].'" '.((int)$profile['id_profile'] == $currentProfile ? 'selected="selected"' : '').'>'.$profile['name'].'</option>';
|
||||
|
||||
$tabsize = sizeof($tabs);
|
||||
foreach ($tabs AS $tab)
|
||||
if ($tab['id_tab'] > $tabsize)
|
||||
$tabsize = $tab['id_tab'];
|
||||
echo ' </select>
|
||||
</th>';
|
||||
|
||||
if ($currentProfile != (int)(_PS_ADMIN_PROFILE_))
|
||||
echo '
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="viewall"
|
||||
'.($this->tabAccess['edit'] == 1 ? ' rel="-1||'.$currentProfile.'||view||'.$tabsize.'||'.sizeof($tabs).'" class="ajaxPower"' : 'disabled="disabled"').' />
|
||||
'.$this->l('View').'
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="addall"
|
||||
'.($this->tabAccess['edit'] == 1 ? ' rel="-1||'.$currentProfile.'||add||'.$tabsize.'||'.sizeof($tabs).'" class="ajaxPower"' : 'disabled="disabled"').' />
|
||||
'.$this->l('Add').'
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="editall"
|
||||
'.($this->tabAccess['edit'] == 1 ? ' rel="-1||'.$currentProfile.'||edit||'.$tabsize.'||'.sizeof($tabs).'" class="ajaxPower"' : 'disabled="disabled"').' />
|
||||
'.$this->l('Edit').'
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="deleteall"
|
||||
'.($this->tabAccess['edit'] == 1 ? ' rel="-1||'.$currentProfile.'||delete||'.$tabsize.'||'.sizeof($tabs).'" class="ajaxPower"' : 'disabled="disabled"').' />
|
||||
'.$this->l('Delete').'
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="allall"
|
||||
'.($this->tabAccess['edit'] == 1 ? ' rel="-1||'.$currentProfile.'||all||'.$tabsize.'||'.sizeof($tabs).'" class="ajaxPower"' : 'disabled="disabled"').' />
|
||||
'.$this->l('All').'
|
||||
</th>
|
||||
</tr>';
|
||||
|
||||
if (!sizeof($tabs))
|
||||
echo '<tr><td colspan="5">'.$this->l('No tab').'</td></tr>';
|
||||
elseif ($currentProfile == (int)(_PS_ADMIN_PROFILE_))
|
||||
echo '<tr><td colspan="5">'.$this->l('Administrator permissions can\'t be modified.').'</td></tr>';
|
||||
else
|
||||
foreach ($tabs AS $tab)
|
||||
if (!$tab['id_parent'] OR (int)($tab['id_parent']) == -1)
|
||||
{
|
||||
$this->printTabAccess((int)($currentProfile), $tab, $accesses[$tab['id_tab']], false, $tabsize, sizeof($tabs));
|
||||
foreach ($tabs AS $child)
|
||||
if ($child['id_parent'] === $tab['id_tab'])
|
||||
if (isset($accesses[$child['id_tab']]))
|
||||
{
|
||||
|
||||
$this->printTabAccess($currentProfile, $child, $accesses[$child['id_tab']], true, $tabsize, sizeof($tabs));
|
||||
}
|
||||
}
|
||||
echo '</table>';
|
||||
|
||||
if ($currentProfile != (int)(_PS_ADMIN_PROFILE_))
|
||||
$this->displayModuleAccesses($currentProfile);
|
||||
echo '<div class="clear"> </div>';
|
||||
}
|
||||
|
||||
private function printTabAccess($currentProfile, $tab, $access, $is_child, $tabsize, $tabnumber)
|
||||
{
|
||||
$result_accesses = 0;
|
||||
$perms = array('view', 'add', 'edit', 'delete');
|
||||
echo '<tr><td'.($is_child ? '' : ' class="bold"').'>'.($is_child ? ' » ' : '').$tab['name'].'</td>';
|
||||
foreach ($perms as $perm)
|
||||
{
|
||||
if ($this->tabAccess['edit'] == 1)
|
||||
echo '<td><input type="checkbox" name="1" id="'.$perm.(int)($access['id_tab']).'" rel="'.(int)($access['id_tab']).'||'.(int)($currentProfile).'||'.$perm.'||'.$tabsize.'||'.$tabnumber.'" class="ajaxPower '.$perm.' '.(int)($access['id_tab']).'" '.((int)($access[$perm]) == 1 ? 'checked="checked"' : '').'/></td>';
|
||||
else
|
||||
echo '<td><input type="checkbox" name="1" disabled="disabled" '.((int)($access[$perm]) == 1 ? 'checked="checked"' : '').' /></td>';
|
||||
$result_accesses += $access[$perm];
|
||||
}
|
||||
echo '<td>
|
||||
<input type="checkbox" name="1" id=\'all'.(int)($access['id_tab']).'\'
|
||||
'.($this->tabAccess['edit'] == 1 ? ' rel="'.(int)($access['id_tab']).'||'.(int)($currentProfile).'||all||'.$tabsize.'||'.$tabnumber.'" class="ajaxPower all '.(int)($access['id_tab']).'"' : ' class="all '.(int)($access['id_tab']).'" disabled="disabled"').'
|
||||
'.($result_accesses == 4 ? 'checked="checked"' : '').'
|
||||
/>
|
||||
</td></tr>';
|
||||
}
|
||||
|
||||
public function ajaxProcess()
|
||||
{
|
||||
/* PrestaShop demo mode */
|
||||
if (_PS_MODE_DEMO_)
|
||||
{
|
||||
$this->_errors[] = Tools::displayError('This functionnality has been disabled.');
|
||||
return;
|
||||
}
|
||||
/* PrestaShop demo mode*/
|
||||
|
||||
if ($this->tabAccess['edit'] == 1)
|
||||
{
|
||||
if (Tools::isSubmit('submitAddaccess'))
|
||||
$this->processSubmitAddAccess();
|
||||
if (Tools::isSubmit('changeModuleAccess'))
|
||||
$this->processChangeModuleAccess();
|
||||
}
|
||||
}
|
||||
|
||||
private function displayModuleAccesses($currentProfile)
|
||||
{
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$(".changeModuleAccess").change(function(){
|
||||
var tout = $(this).attr("rel").split("||");
|
||||
var id_module = tout[0];
|
||||
var perm = tout[1];
|
||||
var enabled = $(this).is(":checked")? 1 : 0;
|
||||
|
||||
if (id_module == -1)
|
||||
$(\'.ajax-ma-\'+perm).each(function(key, value) {
|
||||
$(this).attr("checked", enabled);
|
||||
});
|
||||
else if (!enabled)
|
||||
$(\'#ajax-ma-\'+perm+\'-master\').each(function(key, value) {
|
||||
$(this).attr("checked", enabled);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url : "ajax-tab.php",
|
||||
async: true,
|
||||
data : {
|
||||
ajaxMode : "1",
|
||||
id_module:id_module,
|
||||
perm:perm,
|
||||
enabled:enabled,
|
||||
id_profile:'.(int)$currentProfile.',
|
||||
changeModuleAccess:"1",
|
||||
token : "'.$this->token.'",
|
||||
controller:"AdminAccess"
|
||||
},
|
||||
success : function(res,textStatus,jqXHR)
|
||||
{
|
||||
try
|
||||
{
|
||||
res = $.parseJSON(res);
|
||||
if (res.result == "ok")
|
||||
showSuccessMessage(res.msg);
|
||||
else
|
||||
showErrorMessage(res.msg);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert("oups");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<table class="table float" cellspacing="0" style="margin-left:20px">
|
||||
<tr>
|
||||
<th>'.$this->l('Modules').'</th>
|
||||
<th class="center"><input type="checkbox" id="ajax-ma-view-master" '.($this->tabAccess['edit'] == 1 ? 'class="changeModuleAccess" rel="-1||view"' : 'disabled="disabled"').' /> '.$this->l('View').'</th>
|
||||
<th class="center"><input type="checkbox" id="ajax-ma-configure-master" '.($this->tabAccess['edit'] == 1 ? 'class="changeModuleAccess" rel="-1||configure"' : 'disabled="disabled"').' /> '.$this->l('Configure').'</th>
|
||||
</tr>';
|
||||
|
||||
$modules = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT ma.id_module, m.name, ma.`view`, ma.`configure`
|
||||
FROM '._DB_PREFIX_.'module_access ma
|
||||
LEFT JOIN '._DB_PREFIX_.'module m ON ma.id_module = m.id_module
|
||||
WHERE id_profile = '.(int)$currentProfile.'
|
||||
ORDER BY m.name');
|
||||
if (!sizeof($modules))
|
||||
echo '<tr><td colspan="2">'.$this->l('No modules installed').'</td></tr>';
|
||||
else
|
||||
foreach ($modules AS $module)
|
||||
echo '<tr>
|
||||
<td>» '.$module['name'].'</td>
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
'.((int)$module['view'] == 1 ? 'checked="checked"' : '').'
|
||||
'.($this->tabAccess['edit'] == 1 ? 'class="ajax-ma-view changeModuleAccess" rel="'.(int)$module['id_module'].'||view"' : ' class="ajax-ma-view" disabled="disabled"').'
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
'.((int)$module['configure'] == 1 ? 'checked="checked"' : '').'
|
||||
'.($this->tabAccess['edit'] == 1 ? ' class="ajax-ma-configure changeModuleAccess" rel="'.(int)$module['id_module'].'||configure"' : ' class="ajax-ma-configure" disabled="disabled"').'
|
||||
/>
|
||||
</td>
|
||||
</tr>';
|
||||
|
||||
echo '</table>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,14 +154,14 @@ a.module_toggle_all{color: #268CCD;}
|
||||
#productBox { position:relative; width:100%; float:left;}
|
||||
|
||||
/*tab-pane*/
|
||||
form#product{ background-color:#ebedf4; border:1px solid #ccced7; min-height:300px; padding: 5px 10px 10px; margin-left:140px;}
|
||||
form#product, form#access_form{ background-color:#ebedf4; border:1px solid #ccced7; min-height:300px; padding: 5px 10px 10px; margin-left:140px;}
|
||||
form.defaultForm{ background-color:#ebedf4; border:1px solid #ccced7; min-height:300px; padding: 5px 10px 10px;}
|
||||
.tab-row {}
|
||||
.tab-row .tab {background:#EFEFEF;width:100px;}
|
||||
.tab-row .tab-page.selected {}
|
||||
.tab-row .tab-page {}
|
||||
.productTabs{ background-color:#fafafa; border:1px solid #ccced7; border-right:none; float:left; width:140px;}
|
||||
.productTabs ul{padding:0;}
|
||||
.productTabs ul{padding:0;margin:0;}
|
||||
.productTabs ul li.tab-row { border:none; }
|
||||
.productTabs ul li.tab-row:first-child a {border-top:none;}
|
||||
.productTabs ul li.tab-row a { display:block; font-weight:normal; color:#666;padding: 7px 10px; border-top:1px solid #CCCED7; border-right:1px solid #CCCED7;}
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
{*
|
||||
* 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
|
||||
*}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
|
||||
$('div.productTabs').find('a').each(function() {
|
||||
$(this).attr('href', '#');
|
||||
});
|
||||
|
||||
$('div.productTabs a').click(function() {
|
||||
var id = $(this).attr('id');
|
||||
$('.nav-profile').removeClass('selected');
|
||||
$(this).addClass('selected');
|
||||
$('.tab-profile').hide()
|
||||
$('.'+id).show();
|
||||
});
|
||||
|
||||
$('.ajaxPower').change(function(){
|
||||
var tout = $(this).attr('rel').split('||');
|
||||
var id_tab = tout[0];
|
||||
var id_profile = tout[1];
|
||||
var perm = tout[2];
|
||||
var enabled = $(this).is(':checked')? 1 : 0;
|
||||
var tabsize = tout[3];
|
||||
var tabnumber = tout[4];
|
||||
var table = 'table#table_'+id_profile;
|
||||
|
||||
perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table);
|
||||
|
||||
$.ajax({
|
||||
url: "ajax.php",
|
||||
cache: false,
|
||||
data : {
|
||||
ajaxMode : '1',
|
||||
id_tab: id_tab,
|
||||
id_profile: id_profile,
|
||||
perm: perm,
|
||||
enabled: enabled,
|
||||
submitAddAccess: '1'
|
||||
},
|
||||
success : function(res,textStatus,jqXHR)
|
||||
{
|
||||
try
|
||||
{
|
||||
res = $.parseJSON(res);
|
||||
if (res.result == 'ok')
|
||||
showSuccessMessage(res.msg);
|
||||
else
|
||||
showErrorMessage(res.msg);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert('oups');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".changeModuleAccess").change(function(){
|
||||
var tout = $(this).attr('rel').split('||');
|
||||
var id_module = tout[0];
|
||||
var perm = tout[1];
|
||||
var id_profile = tout[2];
|
||||
var enabled = $(this).is(':checked')? 1 : 0;
|
||||
var table = 'table#table_module_'+id_profile;
|
||||
|
||||
if (id_module == -1)
|
||||
$(table+' .ajax-ma-'+perm).each(function(key, value) {
|
||||
$(this).attr("checked", enabled);
|
||||
});
|
||||
else if (!enabled)
|
||||
$(table+' #ajax-ma-'+perm+'-master').each(function(key, value) {
|
||||
$(this).attr("checked", enabled);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: "ajax.php",
|
||||
cache: false,
|
||||
data : {
|
||||
ajaxMode: '1',
|
||||
id_module: id_module,
|
||||
perm: perm,
|
||||
enabled: enabled,
|
||||
id_profile: id_profile,
|
||||
changeModuleAccess: '1',
|
||||
},
|
||||
success : function(res,textStatus,jqXHR)
|
||||
{
|
||||
try
|
||||
{
|
||||
res = $.parseJSON(res);
|
||||
if (res.result == "ok")
|
||||
showSuccessMessage(res.msg);
|
||||
else
|
||||
showErrorMessage(res.msg);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert("oups");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<div class="toolbarBox">
|
||||
{if $show_toolbar}
|
||||
{include file="toolbar.tpl" toolbar_btn=$toolbar_btn}
|
||||
<div class="pageTitle">
|
||||
<h3>{block name=pageTitle}
|
||||
<span id="current_obj" style="font-weight: normal;">{$title|default:' '}</span>
|
||||
{/block}</h3>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="leadin">{block name="leadin"}{/block}</div>
|
||||
</div>
|
||||
|
||||
<div class="productTabs">
|
||||
<ul class="tab">
|
||||
{foreach $profiles as $profile}
|
||||
<li class="tab-row">
|
||||
<a class="nav-profile {if $profile.id_profile == $current_profile}selected{/if}" id="profile-{$profile.id_profile}" href="{$current}&token={$token}&id_profile={$profile.id_profile}">{$profile.name}</a>
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<form id="{$table}_form" class="defaultForm" action="{$current}&{$submit_action}=1&token={$token}" method="post" enctype="multipart/form-data">
|
||||
{if $form_id}
|
||||
<input type="hidden" name="id_{$table}" id="id_{$table}" value="{$form_id}" />
|
||||
{/if}
|
||||
|
||||
{assign var=tabsize value=count($tabs)}
|
||||
{foreach $tabs AS $tab}
|
||||
{if $tab.id_tab > $tabsize}
|
||||
{assign var=tabsize value=$tab.id_tab}
|
||||
{/if}
|
||||
{/foreach}
|
||||
|
||||
{foreach $profiles as $profile}
|
||||
|
||||
<div class="profile-{$profile.id_profile} tab-profile" style="display:{if $profile.id_profile == $current_profile}block{else}none{/if}">
|
||||
|
||||
{if $profile.id_profile != $admin_profile}
|
||||
<table class="table float" cellspacing="0" style="margin-right:50px" id="table_{$profile.id_profile}">
|
||||
<tr>
|
||||
<th class="center">
|
||||
{l s='Tabs'}
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="viewall"
|
||||
{if $access_edit == 1}
|
||||
rel="-1||{$profile.id_profile}||view||{$tabsize}||{count($tabs)}" class="ajaxPower"
|
||||
{else}
|
||||
disabled="disabled"
|
||||
{/if} />
|
||||
{l s='View'}
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="addall"
|
||||
{if $access_edit == 1}
|
||||
rel="-1||{$profile.id_profile}||add||{$tabsize}||{count($tabs)}" class="ajaxPower"
|
||||
{else}
|
||||
disabled="disabled"
|
||||
{/if} />
|
||||
{l s='Add'}
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="editall"
|
||||
{if $access_edit == 1}
|
||||
rel="-1||{$profile.id_profile}||edit||{$tabsize}||{count($tabs)}" class="ajaxPower"
|
||||
{else}
|
||||
disabled="disabled"
|
||||
{/if} />
|
||||
{l s='Edit'}
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="deleteall"
|
||||
{if $access_edit == 1}
|
||||
rel="-1||{$profile.id_profile}||delete||{$tabsize}||{count($tabs)}" class="ajaxPower"
|
||||
{else}
|
||||
disabled="disabled"
|
||||
{/if} />
|
||||
{l s='Delete'}
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox" name="1" id="allall"
|
||||
{if $access_edit == 1}
|
||||
rel="-1||{$profile.id_profile}||all||{$tabsize}||{count($tabs)}" class="ajaxPower"
|
||||
{else}
|
||||
disabled="disabled"
|
||||
{/if} />
|
||||
{l s='All'}
|
||||
</th>
|
||||
</tr>
|
||||
{if !count($tabs)}
|
||||
<tr>
|
||||
<td colspan="6">{l s='No tab'}</td>
|
||||
</tr>
|
||||
{else}
|
||||
{foreach $tabs AS $tab}
|
||||
|
||||
{assign var=access value=$accesses[$profile.id_profile]}
|
||||
|
||||
{if !$tab.id_parent OR $tab.id_parent == -1}
|
||||
{assign var=is_child value=false}
|
||||
{assign var=result_accesses value=0}
|
||||
<tr>
|
||||
<td{if !$is_child} class="bold"{/if}>{if $is_child} » {/if}<strong>{$tab.name}</strong></td>
|
||||
{foreach $perms as $perm}
|
||||
{if $access_edit == 1}
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
id="{$perm}{$access[$tab.id_tab]['id_tab']}"
|
||||
rel="{$access[$tab.id_tab]['id_tab']}||{$profile.id_profile}||{$perm}||{$tabsize}||{count($tabs)}"
|
||||
class="ajaxPower {$perm} {$access[$tab.id_tab]['id_tab']}"
|
||||
{if $access[$tab.id_tab][$perm] == 1}checked="checked"{/if}/>
|
||||
</td>
|
||||
{else}
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
disabled="disabled"
|
||||
{if $access[$tab.id_tab][$perm] == 1}checked="checked"{/if}/>
|
||||
</td>
|
||||
{/if}
|
||||
{assign var=result_accesses value=$result_accesses + $access[$tab.id_tab][$perm]}
|
||||
{/foreach}
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
id='all{$access[$tab.id_tab]['id_tab']}'
|
||||
{if $access_edit == 1}
|
||||
rel="{$access[$tab.id_tab]['id_tab']}||{$profile.id_profile}||all||{$tabsize}||{count($tabs)}"
|
||||
class="ajaxPower all {$access[$tab.id_tab]['id_tab']}"
|
||||
{else}
|
||||
class="all {$access[$tab.id_tab]['id_tab']}"
|
||||
disabled="disabled"
|
||||
{/if}
|
||||
{if $result_accesses == 4}checked="checked"{/if}/>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{foreach $tabs AS $child}
|
||||
{if $child.id_parent === $tab.id_tab}
|
||||
{if isset($access[$child.id_tab])}
|
||||
{assign var=is_child value=true}
|
||||
{assign var=result_accesses value=0}
|
||||
<tr>
|
||||
<td{if !$is_child} class="bold"{/if}>{if $is_child} » {/if}<strong>{$child.name}</strong></td>
|
||||
{foreach $perms as $perm}
|
||||
{if $access_edit == 1}
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
id="{$perm}{$access[$child.id_tab]['id_tab']}"
|
||||
rel="{$access[$child.id_tab]['id_tab']}||{$profile.id_profile}||{$perm}||{$tabsize}||{count($tabs)}"
|
||||
class="ajaxPower {$perm} {$access[$child.id_tab]['id_tab']}"
|
||||
{if $access[$child.id_tab][$perm] == 1}checked="checked"{/if}/>
|
||||
</td>
|
||||
{else}
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
disabled="disabled"
|
||||
{if $access[$child.id_tab][$perm] == 1}checked="checked"{/if}/>
|
||||
</td>
|
||||
{/if}
|
||||
{assign var=result_accesses value=$result_accesses + $access[$child.id_tab][$perm]}
|
||||
{/foreach}
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
id='all{$access[$child.id_tab]['id_tab']}'
|
||||
{if $access_edit == 1}
|
||||
rel="{$access[$child.id_tab]['id_tab']}||{$profile.id_profile}||all||{$tabsize}||{count($tabs)}"
|
||||
class="ajaxPower all {$access[$child.id_tab]['id_tab']}"
|
||||
{else}
|
||||
class="all {$access[$child.id_tab]['id_tab']}"
|
||||
disabled="disabled"
|
||||
{/if}
|
||||
{if $result_accesses == 4}checked="checked"{/if}/>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/if}
|
||||
{/foreach}
|
||||
|
||||
{/if}
|
||||
|
||||
{/foreach}
|
||||
{/if}
|
||||
</table>
|
||||
|
||||
<table class="table" cellspacing="0" style="margin-left:20px" id="table_module_{$profile.id_profile}">
|
||||
<tr>
|
||||
<th>{l s='Modules'}</th>
|
||||
<th class="center">
|
||||
<input type="checkbox"
|
||||
id="ajax-ma-view-master"
|
||||
{if $access_edit == 1}
|
||||
class="changeModuleAccess" rel="-1||view||{$profile.id_profile}"
|
||||
{else}
|
||||
disabled="disabled"
|
||||
{/if} /> {l s='View'}
|
||||
</th>
|
||||
<th class="center">
|
||||
<input type="checkbox"
|
||||
id="ajax-ma-configure-master"
|
||||
{if $access_edit == 1}
|
||||
class="changeModuleAccess" rel="-1||configure||{$profile.id_profile}"
|
||||
{else}
|
||||
disabled="disabled"
|
||||
{/if} /> {l s='Configure'}</th>
|
||||
</tr>
|
||||
|
||||
{if !count($modules)}
|
||||
<tr>
|
||||
<td colspan="3">{l s='No modules installed'}</td>
|
||||
</tr>
|
||||
{else}
|
||||
{foreach $modules[$profile.id_profile] AS $module}
|
||||
<tr>
|
||||
<td>» {$module.name}</td>
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
value="1"
|
||||
{if $module.view == true}checked="checked"{/if}
|
||||
{if $access_edit == 1}
|
||||
class="ajax-ma-view changeModuleAccess"
|
||||
rel="{$module.id_module}||view||{$profile.id_profile}"
|
||||
{else}
|
||||
class="ajax-ma-view"
|
||||
disabled="disabled"
|
||||
{/if}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
value="1"
|
||||
{if $module.configure == true}checked="checked"{/if}
|
||||
{if $access_edit == 1}
|
||||
class="ajax-ma-configure changeModuleAccess"
|
||||
rel="{$module.id_module}||configure||{$profile.id_profile}"
|
||||
{else}
|
||||
class="ajax-ma-configure"
|
||||
disabled="disabled"
|
||||
{/if}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</table>
|
||||
|
||||
<div class="clear"> </div>
|
||||
|
||||
{else}
|
||||
{l s="Administrator permissions can't be modified."}
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
|
||||
{/foreach}
|
||||
</form>
|
||||
Reference in New Issue
Block a user