// Update the way to skip actions for rows in list mode + code refactoring

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9420 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-10-18 13:15:46 +00:00
parent 9f92e7941c
commit 7b2c4b0f06
2 changed files with 302 additions and 186 deletions
+279 -164
View File
@@ -79,8 +79,6 @@ class AdminControllerCore extends Controller
/** @var array list of option forms to be generated */ /** @var array list of option forms to be generated */
protected $options; protected $options;
protected $_listSkipDelete = array();
protected $shopLink; protected $shopLink;
/** @var array Cache for query results */ /** @var array Cache for query results */
@@ -104,12 +102,15 @@ class AdminControllerCore extends Controller
/** @var string Order way (ASC, DESC) determined by arrows in list header */ /** @var string Order way (ASC, DESC) determined by arrows in list header */
protected $_orderWay; protected $_orderWay;
/** @var array list of available actions for each list row */ /** @var array list of available actions for each list row - default actions are view, edit, delete, duplicate */
protected $actions_available = array('view', 'edit', 'delete', 'duplicate'); protected $actions_available = array('view', 'edit', 'delete', 'duplicate');
/** @var array list of required actions for each list row */ /** @var array list of required actions for each list row */
protected $actions = array(); protected $actions = array();
/** @var array list of row ids associated with a given action for witch this action have to not be available */
protected $list_skip_actions = array();
/** @var array $cache_lang cache for traduction */ /** @var array $cache_lang cache for traduction */
public static $cache_lang = array(); public static $cache_lang = array();
@@ -159,10 +160,6 @@ class AdminControllerCore extends Controller
'id_attribute' => 'id_attribute' 'id_attribute' => 'id_attribute'
); );
protected $view;
protected $edit;
protected $delete;
protected $duplicate;
protected $deleted; protected $deleted;
/** /**
* @var bool is a list filter set * @var bool is a list filter set
@@ -299,7 +296,10 @@ class AdminControllerCore extends Controller
case 'delete_image': case 'delete_image':
if (Validate::isLoadedObject($object = $this->loadObject())) if (Validate::isLoadedObject($object = $this->loadObject()))
if (($object->deleteImage())) if (($object->deleteImage()))
Tools::redirectAdmin(self::$currentIndex.'&add'.$this->table.'&'.$this->identifier.'='.Tools::getValue($this->identifier).'&conf=7&token='.$token); {
$redirect = self::$currentIndex.'&add'.$this->table.'&'.$this->identifier.'='.Tools::getValue($this->identifier).'&conf=7&token='.$token;
Tools::redirectAdmin($redirect);
}
$this->_errors[] = Tools::displayError('An error occurred during image deletion (cannot load object).'); $this->_errors[] = Tools::displayError('An error occurred during image deletion (cannot load object).');
break; break;
/* Delete object */ /* Delete object */
@@ -308,7 +308,11 @@ class AdminControllerCore extends Controller
{ {
// check if request at least one object with noZeroObject // check if request at least one object with noZeroObject
if (isset($object->noZeroObject) && count(call_user_func(array($this->className, $object->noZeroObject))) <= 1) if (isset($object->noZeroObject) && count(call_user_func(array($this->className, $object->noZeroObject))) <= 1)
$this->_errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.'); {
$this->_errors[] = Tools::displayError('You need at least one object.').
' <b>'.$this->table.'</b><br />'.
Tools::displayError('You cannot delete all of the items.');
}
else else
{ {
if ($this->deleted) if ($this->deleted)
@@ -328,7 +332,11 @@ class AdminControllerCore extends Controller
} }
} }
else else
$this->_errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); {
$this->_errors[] = Tools::displayError('An error occurred while deleting object.').
' <b>'.$this->table.'</b> '.
Tools::displayError('(cannot load object)');
}
break; break;
/* Change object statuts (active, inactive) */ /* Change object statuts (active, inactive) */
@@ -336,23 +344,34 @@ class AdminControllerCore extends Controller
if (Validate::isLoadedObject($object = $this->loadObject())) if (Validate::isLoadedObject($object = $this->loadObject()))
{ {
if ($object->toggleStatus()) if ($object->toggleStatus())
Tools::redirectAdmin(self::$currentIndex.'&conf=5'.((($id_category = (int)(Tools::getValue('id_category'))) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$token); {
$id_category = (($id_category = (int)Tools::getValue('id_category')) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '';
Tools::redirectAdmin(self::$currentIndex.'&conf=5'.$id_category.'&token='.$token);
}
else else
$this->_errors[] = Tools::displayError('An error occurred while updating status.'); $this->_errors[] = Tools::displayError('An error occurred while updating status.');
} }
else else
$this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').
' <b>'.$this->table.'</b> '.
Tools::displayError('(cannot load object)');
break; break;
/* Move an object */ /* Move an object */
case 'position': case 'position':
if (!Validate::isLoadedObject($object = $this->loadObject())) if (!Validate::isLoadedObject($object = $this->loadObject()))
$this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); {
else if (!$object->updatePosition((int)(Tools::getValue('way')), (int)(Tools::getValue('position')))) $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').
' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
}
else if (!$object->updatePosition((int)Tools::getValue('way'), (int)Tools::getValue('position')))
$this->_errors[] = Tools::displayError('Failed to update the position.'); $this->_errors[] = Tools::displayError('Failed to update the position.');
else else
Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.$token); {
Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.((($id_category = (int)(Tools::getValue('id_category'))) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$token); $id_identifier_str = ($id_identifier = (int)Tools::getValue($this->identifier)) ? '&'.$this->identifier.'='.$id_identifier : '';
$redirect = self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.$id_identifier_str.'&token='.$token;
Tools::redirectAdmin($redirect);
}
break; break;
/* Delete multiple objects */ /* Delete multiple objects */
@@ -360,10 +379,14 @@ class AdminControllerCore extends Controller
if (isset($_POST[$this->table.'Box'])) if (isset($_POST[$this->table.'Box']))
{ {
$object = new $this->className(); $object = new $this->className();
if (isset($object->noZeroObject) &&
// Check if all object will be deleted // Check if all object will be deleted
(count(call_user_func(array($this->className, $object->noZeroObject))) <= 1 || count($_POST[$this->table.'Box']) == count(call_user_func(array($this->className, $object->noZeroObject))))) $count = count(call_user_func(array($this->className, $object->noZeroObject)));
$this->_errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.');
if (isset($object->noZeroObject) && $count <= 1 || count($_POST[$this->table.'Box']) == $count)
$this->_errors[] = Tools::displayError('You need at least one object.').
' <b>'.$this->table.'</b><br />'.
Tools::displayError('You cannot delete all of the items.');
else else
{ {
$result = true; $result = true;
@@ -394,12 +417,16 @@ class AdminControllerCore extends Controller
$this->validateRules(); $this->validateRules();
if (!count($this->_errors)) if (!count($this->_errors))
{ {
$id = (int)(Tools::getValue($this->identifier)); $id = (int)Tools::getValue($this->identifier);
/* Object update */ /* Object update */
if (isset($id) && !empty($id)) if (isset($id) && !empty($id))
{ {
if ($this->tabAccess['edit'] === '1' || ($this->table == 'employee' && $this->context->employee->id == Tools::getValue('id_employee') && Tools::isSubmit('updateemployee'))) if ($this->tabAccess['edit'] === '1' || (
$this->table == 'employee' &&
$this->context->employee->id == Tools::getValue('id_employee') &&
Tools::isSubmit('updateemployee')
))
{ {
$object = new $this->className($id); $object = new $this->className($id);
if (Validate::isLoadedObject($object)) if (Validate::isLoadedObject($object))
@@ -408,20 +435,20 @@ class AdminControllerCore extends Controller
if ($this->deleted && $this->beforeDelete($object)) if ($this->deleted && $this->beforeDelete($object))
{ {
// Create new one with old objet values // Create new one with old objet values
$objectNew = new $this->className($object->id); $object_new = new $this->className($object->id);
$objectNew->id = null; $object_new->id = null;
$objectNew->date_add = ''; $object_new->date_add = '';
$objectNew->date_upd = ''; $object_new->date_upd = '';
// Update old object to deleted // Update old object to deleted
$object->deleted = 1; $object->deleted = 1;
$object->update(); $object->update();
// Update new object with post values // Update new object with post values
$this->copyFromPost($objectNew, $this->table); $this->copyFromPost($object_new, $this->table);
$result = $objectNew->add(); $result = $object_new->add();
if (Validate::isLoadedObject($objectNew)) if (Validate::isLoadedObject($object_new))
$this->afterDelete($objectNew, $object->id); $this->afterDelete($object_new, $object->id);
} }
else else
{ {
@@ -434,10 +461,13 @@ class AdminControllerCore extends Controller
$this->updateAssoShop($object->id); $this->updateAssoShop($object->id);
if (!$result) if (!$result)
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b> ('.Db::getInstance()->getMsgError().')'; {
$this->_errors[] = Tools::displayError('An error occurred while updating object.').
' <b>'.$this->table.'</b> ('.Db::getInstance()->getMsgError().')';
}
else if ($this->postImage($object->id) && !count($this->_errors)) else if ($this->postImage($object->id) && !count($this->_errors))
{ {
$parent_id = (int)(Tools::getValue('id_parent', 1)); $parent_id = (int)Tools::getValue('id_parent', 1);
// Specific back redirect // Specific back redirect
if ($back = Tools::getValue('back')) if ($back = Tools::getValue('back'))
Tools::redirectAdmin(urldecode($back).'&conf=4'); Tools::redirectAdmin(urldecode($back).'&conf=4');
@@ -455,7 +485,8 @@ class AdminControllerCore extends Controller
} }
} }
else else
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); $this->_errors[] = Tools::displayError('An error occurred while updating object.').
' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
} }
else else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.'); $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
@@ -469,10 +500,14 @@ class AdminControllerCore extends Controller
$object = new $this->className(); $object = new $this->className();
$this->copyFromPost($object, $this->table); $this->copyFromPost($object, $this->table);
if (!$object->add()) if (!$object->add())
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
else if (($_POST[$this->identifier] = $object->id /* voluntary */) && $this->postImage($object->id) && !count($this->_errors) && $this->_redirect)
{ {
$parent_id = (int)(Tools::getValue('id_parent', 1)); $this->_errors[] = Tools::displayError('An error occurred while creating object.').
' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
}
/* voluntary do affectation here */
else if (($_POST[$this->identifier] = $object->id) && $this->postImage($object->id) && !count($this->_errors) && $this->_redirect)
{
$parent_id = (int)Tools::getValue('id_parent', 1);
$this->afterAdd($object); $this->afterAdd($object);
$this->updateAssoShop($object->id); $this->updateAssoShop($object->id);
// Save and stay on same form // Save and stay on same form
@@ -495,22 +530,27 @@ class AdminControllerCore extends Controller
/* Cancel all filters for this tab */ /* Cancel all filters for this tab */
case 'reset_filters': case 'reset_filters':
$filters = $this->context->cookie->getFamily($this->table.'Filter_'); $filters = $this->context->cookie->getFamily($this->table.'Filter_');
foreach ($filters as $cookieKey => $filter)
if (strncmp($cookieKey, $this->table.'Filter_', 7 + Tools::strlen($this->table)) == 0) foreach ($filters as $cookie_key => $filter)
{ if (strncmp($cookie_key, $this->table.'Filter_', 7 + Tools::strlen($this->table)) == 0)
$key = substr($cookieKey, 7 + Tools::strlen($this->table)); {
/* Table alias could be specified using a ! eg. alias!field */ $key = substr($cookie_key, 7 + Tools::strlen($this->table));
$tmpTab = explode('!', $key); /* Table alias could be specified using a ! eg. alias!field */
$key = (count($tmpTab) > 1 ? $tmpTab[1] : $tmpTab[0]); $tmp_tab = explode('!', $key);
if (array_key_exists($key, $this->fieldsDisplay)) $key = (count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0]);
unset($this->context->cookie->$cookieKey); if (array_key_exists($key, $this->fieldsDisplay))
} unset($this->context->cookie->$cookie_key);
}
if (isset($this->context->cookie->{'submitFilter'.$this->table})) if (isset($this->context->cookie->{'submitFilter'.$this->table}))
unset($this->context->cookie->{'submitFilter'.$this->table}); unset($this->context->cookie->{'submitFilter'.$this->table});
if (isset($this->context->cookie->{$this->table.'Orderby'})) if (isset($this->context->cookie->{$this->table.'Orderby'}))
unset($this->context->cookie->{$this->table.'Orderby'}); unset($this->context->cookie->{$this->table.'Orderby'});
if (isset($this->context->cookie->{$this->table.'Orderway'})) if (isset($this->context->cookie->{$this->table.'Orderway'}))
unset($this->context->cookie->{$this->table.'Orderway'}); unset($this->context->cookie->{$this->table.'Orderway'});
unset($_POST); unset($_POST);
$this->filter = false; $this->filter = false;
break; break;
@@ -546,20 +586,20 @@ class AdminControllerCore extends Controller
{ {
$key = Tools::substr($key, 7 + Tools::strlen($this->table)); $key = Tools::substr($key, 7 + Tools::strlen($this->table));
/* Table alias could be specified using a ! eg. alias!field */ /* Table alias could be specified using a ! eg. alias!field */
$tmpTab = explode('!', $key); $tmp_tab = explode('!', $key);
$filter = count($tmpTab) > 1 ? $tmpTab[1] : $tmpTab[0]; $filter = count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0];
if ($field = $this->filterToField($key, $filter)) if ($field = $this->filterToField($key, $filter))
{ {
$type = (array_key_exists('filter_type', $field) ? $field['filter_type'] : (array_key_exists('type', $field) ? $field['type'] : false)); $type = (array_key_exists('filter_type', $field) ? $field['filter_type'] : (array_key_exists('type', $field) ? $field['type'] : false));
if (($type == 'date' || $type == 'datetime') && is_string($value)) if (($type == 'date' || $type == 'datetime') && is_string($value))
$value = unserialize($value); $value = unserialize($value);
$key = isset($tmpTab[1]) ? $tmpTab[0].'.`'.$tmpTab[1].'`' : '`'.$tmpTab[0].'`'; $key = isset($tmp_tab[1]) ? $tmp_tab[0].'.`'.$tmp_tab[1].'`' : '`'.$tmp_tab[0].'`';
if (array_key_exists('tmpTableFilter', $field)) if (array_key_exists('tmpTableFilter', $field))
$sqlFilter = & $this->_tmpTableFilter; $sql_filter = & $this->_tmpTableFilter;
else if (array_key_exists('havingFilter', $field)) else if (array_key_exists('havingFilter', $field))
$sqlFilter = & $this->_filterHaving; $sql_filter = & $this->_filterHaving;
else else
$sqlFilter = & $this->_filter; $sql_filter = & $this->_filter;
/* Only for date filtering (from, to) */ /* Only for date filtering (from, to) */
if (is_array($value)) if (is_array($value))
@@ -569,7 +609,7 @@ class AdminControllerCore extends Controller
if (!Validate::isDate($value[0])) if (!Validate::isDate($value[0]))
$this->_errors[] = Tools::displayError('\'from:\' date format is invalid (YYYY-MM-DD)'); $this->_errors[] = Tools::displayError('\'from:\' date format is invalid (YYYY-MM-DD)');
else else
$sqlFilter .= ' AND `'.bqSQL($key).'` >= \''.pSQL(Tools::dateFrom($value[0])).'\''; $sql_filter .= ' AND `'.bqSQL($key).'` >= \''.pSQL(Tools::dateFrom($value[0])).'\'';
} }
if (isset($value[1]) && !empty($value[1])) if (isset($value[1]) && !empty($value[1]))
@@ -577,20 +617,22 @@ class AdminControllerCore extends Controller
if (!Validate::isDate($value[1])) if (!Validate::isDate($value[1]))
$this->_errors[] = Tools::displayError('\'to:\' date format is invalid (YYYY-MM-DD)'); $this->_errors[] = Tools::displayError('\'to:\' date format is invalid (YYYY-MM-DD)');
else else
$sqlFilter .= ' AND `'.bqSQL($key).'` <= \''.pSQL(Tools::dateTo($value[1])).'\''; $sql_filter .= ' AND `'.bqSQL($key).'` <= \''.pSQL(Tools::dateTo($value[1])).'\'';
} }
} }
else else
{ {
$sqlFilter .= ' AND '; $sql_filter .= ' AND ';
$check_key = ($key == $this->identifier || $key == '`'.$this->identifier.'`');
if ($type == 'int' || $type == 'bool') if ($type == 'int' || $type == 'bool')
$sqlFilter .= (($key == $this->identifier || $key == '`'.$this->identifier.'`' || $key == '`active`') ? 'a.' : '').pSQL($key).' = '.(int)($value).' '; $sql_filter .= (($check_key || $key == '`active`') ? 'a.' : '').pSQL($key).' = '.(int)$value.' ';
else if ($type == 'decimal') else if ($type == 'decimal')
$sqlFilter .= (($key == $this->identifier || $key == '`'.$this->identifier.'`') ? 'a.' : '').pSQL($key).' = '.(float)($value).' '; $sql_filter .= ($check_key ? 'a.' : '').pSQL($key).' = '.(float)$value.' ';
else if ($type == 'select') else if ($type == 'select')
$sqlFilter .= (($key == $this->identifier || $key == '`'.$this->identifier.'`') ? 'a.' : '').pSQL($key).' = \''.pSQL($value).'\' '; $sql_filter .= ($check_key ? 'a.' : '').pSQL($key).' = \''.pSQL($value).'\' ';
else else
$sqlFilter .= (($key == $this->identifier || $key == '`'.$this->identifier.'`') ? 'a.' : '').pSQL($key).' LIKE \'%'.pSQL($value).'%\' '; $sql_filter .= ($check_key ? 'a.' : '').pSQL($key).' LIKE \'%'.pSQL($value).'%\' ';
} }
} }
} }
@@ -605,24 +647,28 @@ class AdminControllerCore extends Controller
public function displayForm($firstCall = true) public function displayForm($firstCall = true)
{ {
$content = ''; $content = '';
$allowEmployeeFormLang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
if ($allowEmployeeFormLang && !$this->context->cookie->employee_form_lang)
$this->context->cookie->employee_form_lang = (int)(Configuration::get('PS_LANG_DEFAULT')); if ($allow_employee_form_lang && !$this->context->cookie->employee_form_lang)
$useLangFromCookie = false; $this->context->cookie->employee_form_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$use_lang_from_cookie = false;
$this->_languages = Language::getLanguages(false); $this->_languages = Language::getLanguages(false);
if ($allowEmployeeFormLang)
if ($allow_employee_form_lang)
foreach ($this->_languages as $lang) foreach ($this->_languages as $lang)
if ($this->context->cookie->employee_form_lang == $lang['id_lang']) if ($this->context->cookie->employee_form_lang == $lang['id_lang'])
$useLangFromCookie = true; $use_lang_from_cookie = true;
if (!$useLangFromCookie)
$this->_defaultFormLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); if (!$use_lang_from_cookie)
$this->_defaultFormLanguage = (int)Configuration::get('PS_LANG_DEFAULT');
else else
$this->_defaultFormLanguage = (int)($this->context->cookie->employee_form_lang); $this->_defaultFormLanguage = (int)$this->context->cookie->employee_form_lang;
// Only if it is the first call to displayForm, otherwise it has already been defined // Only if it is the first call to displayForm, otherwise it has already been defined
if ($firstCall) if ($firstCall)
{ {
$content .=' $content .= '
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
id_language = '.$this->_defaultFormLanguage.'; id_language = '.$this->_defaultFormLanguage.';
@@ -635,7 +681,7 @@ class AdminControllerCore extends Controller
name: \''.htmlentities($language['name'], ENT_COMPAT, 'UTF-8').'\' name: \''.htmlentities($language['name'], ENT_COMPAT, 'UTF-8').'\'
};'; };';
$content .= ' $content .= '
displayFlags(languages, id_language, '.$allowEmployeeFormLang.'); displayFlags(languages, id_language, '.$allow_employee_form_lang.');
}); });
</script>'; </script>';
} }
@@ -651,7 +697,7 @@ class AdminControllerCore extends Controller
*/ */
protected function loadObject($opt = false) protected function loadObject($opt = false)
{ {
if ($id = (int)(Tools::getValue($this->identifier)) AND Validate::isUnsignedId($id)) if ($id = (int)Tools::getValue($this->identifier) && Validate::isUnsignedId($id))
{ {
if (!$this->_object) if (!$this->_object)
$this->_object = new $this->className($id); $this->_object = new $this->className($id);
@@ -740,7 +786,7 @@ class AdminControllerCore extends Controller
else else
{ {
if ($conf = Tools::getValue('conf')) if ($conf = Tools::getValue('conf'))
$this->context->smarty->assign('conf', $this->_conf[(int)($conf)]); $this->context->smarty->assign('conf', $this->_conf[(int)$conf]);
$this->context->smarty->assign('errors', $this->_errors); $this->context->smarty->assign('errors', $this->_errors);
$this->context->smarty->assign('warnings', $this->warnings); $this->context->smarty->assign('warnings', $this->warnings);
@@ -799,7 +845,11 @@ class AdminControllerCore extends Controller
'shop_name' => $shop_name, 'shop_name' => $shop_name,
'shop_context' => $shop_context, 'shop_context' => $shop_context,
)); ));
$youEditFieldFor = sprintf($this->l('A modification of this field will be applied for the shop %s'), '<b>'.Context::getContext()->shop->name.'</b>');
$you_edit_field_for = sprintf(
$this->l('A modification of this field will be applied for the shop %s'),
'<b>'.Context::getContext()->shop->name.'</b>'
);
} }
// Multishop // Multishop
@@ -817,18 +867,18 @@ class AdminControllerCore extends Controller
$shop_name = $this->context->shop->name; $shop_name = $this->context->shop->name;
}*/ }*/
// Quick access // Quick access
$quick_access = QuickAccess::getQuickAccesses($this->context->language->id); $quick_access = QuickAccess::getQuickAccesses($this->context->language->id);
foreach ($quick_access as $index => $quick) foreach ($quick_access as $index => $quick)
{ {
preg_match('/tab=(.+)(&.+)?$/', $quick['link'], $adminTab); preg_match('/tab=(.+)(&.+)?$/', $quick['link'], $admin_tab);
if (isset($adminTab[1])) if (isset($admin_tab[1]))
{ {
if (strpos($adminTab[1], '&')) if (strpos($admin_tab[1], '&'))
$adminTab[1] = substr($adminTab[1], 0, strpos($adminTab[1], '&')); $admin_tab[1] = substr($admin_tab[1], 0, strpos($admin_tab[1], '&'));
$quick_access[$index]['link'] .= '&token='.Tools::getAdminToken($adminTab[1].(int)(Tab::getIdFromClassName($adminTab[1])).(int)($this->context->employee->id));
$token = Tools::getAdminToken($admin_tab[1].(int)Tab::getIdFromClassName($admin_tab[1]).(int)$this->context->employee->id);
$quick_access[$index]['link'] .= '&token='.$token;
} }
} }
@@ -870,11 +920,14 @@ class AdminControllerCore extends Controller
$tabs_breadcrumb = array_reverse($tabs_breadcrumb); $tabs_breadcrumb = array_reverse($tabs_breadcrumb);
foreach ($tabs_breadcrumb as $key => $item) foreach ($tabs_breadcrumb as $key => $item)
for ($i = 0; $i < (count($tabs_breadcrumb) - 1); $i++) {
$tabs_count = count($tabs_breadcrumb) - 1;
for ($i = 0; $i < $tabs_count; $i++)
$tabs_breadcrumb[$key]['token'] = Tools::getAdminToken($item['class_name'].intval($item['id_tab']).(int)$this->context->employee->id); $tabs_breadcrumb[$key]['token'] = Tools::getAdminToken($item['class_name'].intval($item['id_tab']).(int)$this->context->employee->id);
}
/* Hooks are volontary out the initialize array (need those variables already assigned) */ /* Hooks are volontary out the initialize array (need those variables already assigned) */
$bo_color = empty($this->context->employee->bo_color) ? '#FFFFFF' : $this->context->employee->bo_color;
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'img_dir' => _PS_IMG_, 'img_dir' => _PS_IMG_,
'iso' => $this->context->language->iso_code, 'iso' => $this->context->language->iso_code,
@@ -884,8 +937,8 @@ class AdminControllerCore extends Controller
'version' => _PS_VERSION_, 'version' => _PS_VERSION_,
'help_box' => Configuration::get('PS_HELPBOX'), 'help_box' => Configuration::get('PS_HELPBOX'),
'round_mode' => Configuration::get('PS_PRICE_ROUND_MODE'), 'round_mode' => Configuration::get('PS_PRICE_ROUND_MODE'),
'brightness' => Tools::getBrightness(empty($this->context->employee->bo_color) ? '#FFFFFF' : $this->context->employee->bo_color) < 128 ? 'white' : '#383838', 'brightness' => Tools::getBrightness($bo_color) < 128 ? 'white' : '#383838',
'edit_field' => isset($youEditFieldFor) ? $youEditFieldFor : '\'\'', 'edit_field' => isset($you_edit_field_for) ? $you_edit_field_for : '\'\'',
'lang_iso' => $this->context->language->iso_code, 'lang_iso' => $this->context->language->iso_code,
'link' => $this->context->link, 'link' => $this->context->link,
'bo_color' => isset($this->context->employee->bo_color) ? Tools::htmlentitiesUTF8($this->context->employee->bo_color) : null, 'bo_color' => isset($this->context->employee->bo_color) ? Tools::htmlentitiesUTF8($this->context->employee->bo_color) : null,
@@ -927,9 +980,24 @@ class AdminControllerCore extends Controller
*/ */
public function addRowAction($action) public function addRowAction($action)
{ {
$action = strtolower($action);
$this->actions[] = $action; $this->actions[] = $action;
} }
/**
* Add an action to use for each row in the list
*/
public function addRowActionSkipList($action, $list)
{
$action = strtolower($action);
$list = (array)$list;
if (array_key_exists($action, $this->list_skip_actions))
$this->list_skip_actions[$action] = array_merge($this->list_skip_actions[$action], $list);
else
$this->list_skip_actions[$action] = $list;
}
/** /**
* Assign smarty variables for the page main content * Assign smarty variables for the page main content
*/ */
@@ -1008,13 +1076,7 @@ class AdminControllerCore extends Controller
$helper->colorOnBackground = $this->colorOnBackground; $helper->colorOnBackground = $this->colorOnBackground;
// For each action, try to add the corresponding skip elements list // For each action, try to add the corresponding skip elements list
foreach ($this->actions as $action) $helper->list_skip_actions = $this->list_skip_actions;
{
$skip_attribute = '_listSkip'.ucfirst($action);
if (isset($this->$skip_attribute))
$helper->$skip_attribute = $this->$skip_attribute;
}
$this->content .= $helper->generateList($this->_list, $this->fieldsDisplay); $this->content .= $helper->generateList($this->_list, $this->fieldsDisplay);
} }
else if ($this->display == 'options') else if ($this->display == 'options')
@@ -1122,11 +1184,11 @@ class AdminControllerCore extends Controller
Tools::redirectAdmin('login.php?redirect='.$_SERVER['REQUEST_URI']); Tools::redirectAdmin('login.php?redirect='.$_SERVER['REQUEST_URI']);
// Set current index // Set current index
$currentIndex = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller : ''); $current_index = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller : '');
if ($back = Tools::getValue('back')) if ($back = Tools::getValue('back'))
$currentIndex .= '&back='.urlencode($back); $current_index .= '&back='.urlencode($back);
self::$currentIndex = $currentIndex; self::$currentIndex = $current_index;
$iso = $this->context->language->iso_code; $iso = $this->context->language->iso_code;
include(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php'); include(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
include(_PS_TRANSLATIONS_DIR_.$iso.'/fields.php'); include(_PS_TRANSLATIONS_DIR_.$iso.'/fields.php');
@@ -1148,9 +1210,9 @@ class AdminControllerCore extends Controller
$this->context->cookie->shopContext = Tools::getValue('setShopContext'); $this->context->cookie->shopContext = Tools::getValue('setShopContext');
$url = parse_url($_SERVER['REQUEST_URI']); $url = parse_url($_SERVER['REQUEST_URI']);
$query = (isset($url['query'])) ? $url['query'] : ''; $query = (isset($url['query'])) ? $url['query'] : '';
parse_str($query, $parseQuery); parse_str($query, $parse_query);
unset($parseQuery['setShopContext']); unset($parse_query['setShopContext']);
Tools::redirectAdmin($url['path'].'?'.http_build_query($parseQuery)); Tools::redirectAdmin($url['path'].'?'.http_build_query($parse_query));
} }
$shop_id = ''; $shop_id = '';
@@ -1309,7 +1371,10 @@ class AdminControllerCore extends Controller
{ {
/* Manage default params values */ /* Manage default params values */
if (empty($limit)) if (empty($limit))
$limit = ((!isset($this->context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[1] : $limit = $this->context->cookie->{$this->table.'_pagination'}); if (!isset($this->context->cookie->{$this->table.'_pagination'}))
$limit = $this->_pagination[1];
else
$limit = $this->context->cookie->{$this->table.'_pagination'};
if (!Validate::isTableOrIdentifier($this->table)) if (!Validate::isTableOrIdentifier($this->table))
die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"'); die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"');
@@ -1319,10 +1384,9 @@ class AdminControllerCore extends Controller
if (empty($orderWay)) if (empty($orderWay))
$orderWay = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC'; $orderWay = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
$limit = (int)(Tools::getValue('pagination', $limit)); $limit = (int)Tools::getValue('pagination', $limit);
$this->context->cookie->{$this->table.'_pagination'} = $limit; $this->context->cookie->{$this->table.'_pagination'} = $limit;
/* Check params validity */ /* Check params validity */
if (!Validate::isOrderBy($orderBy) || !Validate::isOrderWay($orderWay) if (!Validate::isOrderBy($orderBy) || !Validate::isOrderWay($orderWay)
|| !is_numeric($start) || !is_numeric($limit) || !is_numeric($start) || !is_numeric($limit)
@@ -1335,68 +1399,94 @@ class AdminControllerCore extends Controller
isset($_POST['submitFilter'.$this->table.'_y'])) && isset($_POST['submitFilter'.$this->table.'_y'])) &&
!empty($_POST['submitFilter'.$this->table]) && !empty($_POST['submitFilter'.$this->table]) &&
is_numeric($_POST['submitFilter'.$this->table])) is_numeric($_POST['submitFilter'.$this->table]))
$start = (int)($_POST['submitFilter'.$this->table] - 1) * $limit; $start = ((int)$_POST['submitFilter'.$this->table] - 1) * $limit;
/* Cache */ /* Cache */
$this->_lang = (int)($id_lang); $this->_lang = (int)$id_lang;
$this->_orderBy = $orderBy; $this->_orderBy = $orderBy;
$this->_orderWay = Tools::strtoupper($orderWay); $this->_orderWay = Tools::strtoupper($orderWay);
/* SQL table : orders, but class name is Order */ /* SQL table : orders, but class name is Order */
$sqlTable = $this->table == 'order' ? 'orders' : $this->table; $sql_table = $this->table == 'order' ? 'orders' : $this->table;
// Add SQL shop restriction // Add SQL shop restriction
$selectShop = $joinShop = $whereShop = ''; $select_shop = $join_shop = $where_shop = '';
if ($this->shopLinkType) if ($this->shopLinkType)
{ {
$selectShop = ', shop.name as shop_name '; $select_shop = ', shop.name as shop_name ';
$joinShop = ' LEFT JOIN '._DB_PREFIX_.$this->shopLinkType.' shop $join_shop = ' LEFT JOIN '._DB_PREFIX_.$this->shopLinkType.' shop
ON a.id_'.$this->shopLinkType.' = shop.id_'.$this->shopLinkType; ON a.id_'.$this->shopLinkType.' = shop.id_'.$this->shopLinkType;
$whereShop = $this->context->shop->sqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType); $where_shop = $this->context->shop->sqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
} }
$assos = Shop::getAssoTables(); $assos = Shop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop') if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
{ {
$filterKey = $assos[$this->table]['type']; $filter_key = $assos[$this->table]['type'];
$idenfierShop = $this->context->shop->getListOfID(); $idenfier_shop = $this->context->shop->getListOfID();
} }
else if (Context::shop() == Shop::CONTEXT_GROUP) else if (Context::shop() == Shop::CONTEXT_GROUP)
{ {
$assos = GroupShop::getAssoTables(); $assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop') if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop')
{ {
$filterKey = $assos[$this->table]['type']; $filter_key = $assos[$this->table]['type'];
$idenfierShop = array($this->context->shop->getGroupID()); $idenfier_shop = array($this->context->shop->getGroupID());
} }
} }
$filterShop = ''; $filter_shop = '';
if (isset($filterKey)) if (isset($filter_key))
{ {
if (!$this->_group) if (!$this->_group)
$this->_group = 'GROUP BY a.'.pSQL($this->identifier); $this->_group = ' GROUP BY a.'.pSQL($this->identifier);
else if (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group)) else if (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group))
$this->_group .= ', a.'.pSQL($this->identifier); $this->_group .= ', a.'.pSQL($this->identifier);
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_'.$filterKey).'`? *sa#', $this->_join)) $test_join = !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_'.$filter_key).'`? *sa#', $this->_join);
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))'; if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && $test_join)
{
$filter_shop = ' JOIN `'._DB_PREFIX_.$this->table.'_'.$filter_key.'` sa ';
$filter_shop .= 'ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filter_key.' IN ('.implode(', ', $idenfier_shop).'))';
}
} }
/* Query in order to get results with all fields */ /* Query in order to get results with all fields */
$lang_join = '';
if ($this->lang)
{
$lang_join = 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'`';
$lang_join .= ' AND b.`id_lang` = '.(int)$id_lang;
if ($id_lang_shop)
$lang_join .= ' AND b.`id_shop`='.(int)$id_lang_shop;
$lang_join .= ')';
}
$having_clause = '';
if (isset($this->_filterHaving) || isset($this->_having))
{
$having_clause = ' HAVING ';
if (isset($this->_filterHaving))
$having_clause .= ltrim($this->_filterHaving, ' AND ');
if (isset($this->_having))
$having_clause .= $this->_having.' ';
}
$sql = 'SELECT SQL_CALC_FOUND_ROWS $sql = 'SELECT SQL_CALC_FOUND_ROWS
'.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').' '.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
'.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').$selectShop.' '.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').$select_shop.'
FROM `'._DB_PREFIX_.$sqlTable.'` a FROM `'._DB_PREFIX_.$sql_table.'` a
'.$filterShop.' '.$filter_shop.'
'.($this->lang ? 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)$id_lang.($id_lang_shop ? ' AND b.`id_shop`='.(int)$id_lang_shop : '').')' : '').' '.$lang_join.'
'.(isset($this->_join) ? $this->_join.' ' : '').' '.(isset($this->_join) ? $this->_join.' ' : '').'
'.$joinShop.' '.$join_shop.'
WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').(isset($this->_filter) ? $this->_filter : '').$whereShop.' WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').
(isset($this->_filter) ? $this->_filter : '').$where_shop.'
'.(isset($this->_group) ? $this->_group.' ' : '').' '.(isset($this->_group) ? $this->_group.' ' : '').'
'.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').(isset($this->_having) ? $this->_having.' ' : '').' '.$having_clause.'
ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay). ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').' ($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').'
LIMIT '.(int)$start.','.(int)$limit; LIMIT '.(int)$start.','.(int)$limit;
$this->_list = Db::getInstance()->executeS($sql); $this->_list = Db::getInstance()->executeS($sql);
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`'); $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
} }
@@ -1458,18 +1548,18 @@ class AdminControllerCore extends Controller
* *
* @param string $className Allow to validate a different class than the current one * @param string $className Allow to validate a different class than the current one
*/ */
public function validateRules($className = false) public function validateRules($class_name = false)
{ {
if (!$className) if (!$class_name)
$className = $this->className; $class_name = $this->className;
/* Class specific validation rules */ /* Class specific validation rules */
$rules = call_user_func(array($className, 'getValidationRules'), $className); $rules = call_user_func(array($class_name, 'getValidationRules'), $class_name);
if ((count($rules['requiredLang']) || count($rules['sizeLang']) || count($rules['validateLang']))) if ((count($rules['requiredLang']) || count($rules['sizeLang']) || count($rules['validateLang'])))
{ {
/* Language() instance determined by default language */ /* Language() instance determined by default language */
$default_language = new Language((int)(Configuration::get('PS_LANG_DEFAULT'))); $default_language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
/* All availables languages */ /* All availables languages */
$languages = Language::getLanguages(false); $languages = Language::getLanguages(false);
@@ -1479,24 +1569,34 @@ class AdminControllerCore extends Controller
foreach ($rules['required'] as $field) foreach ($rules['required'] as $field)
if (($value = Tools::getValue($field)) == false && (string)$value != '0') if (($value = Tools::getValue($field)) == false && (string)$value != '0')
if (!Tools::getValue($this->identifier) || ($field != 'passwd' && $field != 'no-picture')) if (!Tools::getValue($this->identifier) || ($field != 'passwd' && $field != 'no-picture'))
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is required'); $this->_errors[] = $this->l('the field').
' <b>'.call_user_func(array($class_name, 'displayFieldName'), $field, $class_name).'</b> '.
$this->l('is required');
/* Checking for multilingual required fields */ /* Checking for multilingual required fields */
foreach ($rules['requiredLang'] as $fieldLang) foreach ($rules['requiredLang'] as $field_lang)
if (($empty = Tools::getValue($fieldLang.'_'.$default_language->id)) === false || $empty !== '0' && empty($empty)) if (($empty = Tools::getValue($field_lang.'_'.$default_language->id)) === false || $empty !== '0' && empty($empty))
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).'</b> '.$this->l('is required at least in').' '.$default_language->name; $this->_errors[] = $this->l('the field').
' <b>'.call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name).'</b> '.
$this->l('is required at least in').' '.$default_language->name;
/* Checking for maximum fields sizes */ /* Checking for maximum fields sizes */
foreach ($rules['size'] as $field => $maxLength) foreach ($rules['size'] as $field => $max_length)
if (Tools::getValue($field) !== false && Tools::strlen(Tools::getValue($field)) > $maxLength) if (Tools::getValue($field) !== false && Tools::strlen(Tools::getValue($field)) > $max_length)
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is too long').' ('.$maxLength.' '.$this->l('chars max').')'; $this->_errors[] = $this->l('the field').
' <b>'.call_user_func(array($class_name, 'displayFieldName'), $field, $class_name).'</b> '.
$this->l('is too long').' ('.$max_length.' '.$this->l('chars max').')';
/* Checking for maximum multilingual fields size */ /* Checking for maximum multilingual fields size */
foreach ($rules['sizeLang'] as $fieldLang => $maxLength) foreach ($rules['sizeLang'] as $field_lang => $max_length)
foreach ($languages as $language) foreach ($languages as $language)
if (Tools::getValue($fieldLang.'_'.$language['id_lang']) !== false && Tools::strlen(Tools::getValue($fieldLang.'_'.$language['id_lang'])) > $maxLength) {
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).' ('.$language['name'].')</b> '.$this->l('is too long').' ('.$maxLength.' '.$this->l('chars max, html chars including').')'; $field_lang = Tools::getValue($field_lang.'_'.$language['id_lang']);
if ($field_lang !== false && Tools::strlen($field_lang) > $max_length)
$this->_errors[] = $this->l('the field').
' <b>'.call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name).' ('.$language['name'].')</b> '.
$this->l('is too long').' ('.$max_length.' '.$this->l('chars max, html chars including').')';
}
/* Overload this method for custom checking */ /* Overload this method for custom checking */
$this->_childValidation(); $this->_childValidation();
@@ -1504,23 +1604,31 @@ class AdminControllerCore extends Controller
foreach ($rules['validate'] as $field => $function) foreach ($rules['validate'] as $field => $function)
if (($value = Tools::getValue($field)) !== false && ($field != 'passwd')) if (($value = Tools::getValue($field)) !== false && ($field != 'passwd'))
if (!Validate::$function($value)) if (!Validate::$function($value))
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is invalid'); $this->_errors[] = $this->l('the field').
' <b>'.call_user_func(array($class_name, 'displayFieldName'), $field, $class_name).'</b> '.
$this->l('is invalid');
/* Checking for passwd_old validity */ /* Checking for passwd_old validity */
if (($value = Tools::getValue('passwd')) != false) if (($value = Tools::getValue('passwd')) != false)
{ {
if ($className == 'Employee' && !Validate::isPasswdAdmin($value)) if ($class_name == 'Employee' && !Validate::isPasswdAdmin($value))
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), 'passwd', $className).'</b> '.$this->l('is invalid'); $this->_errors[] = $this->l('the field').
else if ($className == 'Customer' && !Validate::isPasswd($value)) ' <b>'.call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name).'</b> '.
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), 'passwd', $className).'</b> '.$this->l('is invalid'); $this->l('is invalid');
else if ($class_name == 'Customer' && !Validate::isPasswd($value))
$this->_errors[] = $this->l('the field').
' <b>'.call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name).
'</b> '.$this->l('is invalid');
} }
/* Checking for multilingual fields validity */ /* Checking for multilingual fields validity */
foreach ($rules['validateLang'] as $fieldLang => $function) foreach ($rules['validateLang'] as $field_lang => $function)
foreach ($languages as $language) foreach ($languages as $language)
if (($value = Tools::getValue($fieldLang.'_'.$language['id_lang'])) !== false && !empty($value)) if (($value = Tools::getValue($field_lang.'_'.$language['id_lang'])) !== false && !empty($value))
if (!Validate::$function($value)) if (!Validate::$function($value))
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).' ('.$language['name'].')</b> '.$this->l('is invalid'); $this->_errors[] = $this->l('the field').
' <b>'.call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name).' ('.$language['name'].')</b> '.
$this->l('is invalid');
} }
/** /**
@@ -1605,7 +1713,7 @@ class AdminControllerCore extends Controller
foreach ($languages as $language) foreach ($languages as $language)
foreach (array_keys($rules['validateLang']) as $field) foreach (array_keys($rules['validateLang']) as $field)
if (isset($_POST[$field.'_'.(int)$language['id_lang']])) if (isset($_POST[$field.'_'.(int)$language['id_lang']]))
$object->{$field}[(int)$language['id_lang']] = $_POST[$field.'_'.(int)($language['id_lang'])]; $object->{$field}[(int)$language['id_lang']] = $_POST[$field.'_'.(int)$language['id_lang']];
} }
} }
@@ -1642,7 +1750,8 @@ class AdminControllerCore extends Controller
{ {
if (isset($field['validation'])) if (isset($field['validation']))
{ {
if ((!isset($field['empty']) || !$field['empty'] || (isset($field['empty']) && $field['empty'] && $value)) && method_exists('Validate', $field['validation'])) $valid_method_exists = method_exists('Validate', $field['validation']);
if ((!isset($field['empty']) || !$field['empty'] || (isset($field['empty']) && $field['empty'] && $value)) && $valid_method_exists)
{ {
if (!Validate::$field['validation']($value)) if (!Validate::$field['validation']($value))
{ {
@@ -1677,9 +1786,9 @@ class AdminControllerCore extends Controller
foreach ($this->options as $option_list) foreach ($this->options as $option_list)
{ {
foreach ($option_list as $category => $categoryData) foreach ($option_list as $category => $category_data)
{ {
$fields = $categoryData['fields']; $fields = $category_data['fields'];
/* Check required fields */ /* Check required fields */
foreach ($fields as $field => $values) foreach ($fields as $field => $values)
@@ -1690,7 +1799,7 @@ class AdminControllerCore extends Controller
if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false && (string)$value != '0') if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false && (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.'); $this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
} }
elseif (($value = Tools::getValue($field)) == false && (string)$value != '0') else if (($value = Tools::getValue($field)) == false && (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.'); $this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
/* Check fields validity */ /* Check fields validity */
@@ -1702,7 +1811,7 @@ class AdminControllerCore extends Controller
if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang']))) if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang'])))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.'); $this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
} }
elseif (Tools::getValue($field) && isset($values['validation'])) else if (Tools::getValue($field) && isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field))) if (!Validate::$values['validation'](Tools::getValue($field)))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.'); $this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
@@ -1711,7 +1820,7 @@ class AdminControllerCore extends Controller
if (!Tools::getValue($field) && isset($values['default'])) if (!Tools::getValue($field) && isset($values['default']))
$_POST[$field] = $values['default']; $_POST[$field] = $values['default'];
if (1||!count($this->_errors)) if (1 || !count($this->_errors))
{ {
foreach ($fields as $key => $options) foreach ($fields as $key => $options)
{ {
@@ -1733,7 +1842,8 @@ class AdminControllerCore extends Controller
$list = array(); $list = array();
foreach ($languages as $language) foreach ($languages as $language)
{ {
$val = (isset($options['cast']) ? $options['cast'](Tools::getValue($key.'_'.$language['id_lang'])) : Tools::getValue($key.'_'.$language['id_lang'])); $key_lang = Tools::getValue($key.'_'.$language['id_lang']);
$val = (isset($options['cast']) ? $options['cast']($key_lang) : $key_lang);
if ($this->validateField($val, $options)) if ($this->validateField($val, $options))
{ {
if (Validate::isCleanHtml($val)) if (Validate::isCleanHtml($val))
@@ -1784,7 +1894,7 @@ class AdminControllerCore extends Controller
return !count($this->_errors) ? true : false; return !count($this->_errors) ? true : false;
} }
protected function uploadImage($id, $name, $dir, $ext = false, $width = NULL, $height = NULL) protected function uploadImage($id, $name, $dir, $ext = false, $width = null, $height = null)
{ {
if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name'])) if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name']))
{ {
@@ -1794,24 +1904,23 @@ class AdminControllerCore extends Controller
else else
return false; return false;
// Check image validity // Check image validity
$max_size = isset($this->maxImageSize) ? $this->maxImageSize : 0; $max_size = isset($this->maxImageSize) ? $this->maxImageSize : 0;
if ($error = checkImage($_FILES[$name], Tools::getMaxUploadSize($max_size))) if ($error = checkImage($_FILES[$name], Tools::getMaxUploadSize($max_size)))
$this->_errors[] = $error; $this->_errors[] = $error;
elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') || !move_uploaded_file($_FILES[$name]['tmp_name'], $tmpName)) else if (!$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS') || !move_uploaded_file($_FILES[$name]['tmp_name'], $tmp_name))
return false; return false;
else else
{ {
$tmpName = $_FILES[$name]['tmp_name']; $tmp_name = $_FILES[$name]['tmp_name'];
// Copy new image // Copy new image
if (!imageResize($tmpName, _PS_IMG_DIR_.$dir.$id.'.'.$this->imageType, (int)$width, (int)$height, ($ext ? $ext : $this->imageType))) if (!imageResize($tmp_name, _PS_IMG_DIR_.$dir.$id.'.'.$this->imageType, (int)$width, (int)$height, ($ext ? $ext : $this->imageType)))
$this->_errors[] = Tools::displayError('An error occurred while uploading image.'); $this->_errors[] = Tools::displayError('An error occurred while uploading image.');
if (count($this->_errors)) if (count($this->_errors))
return false; return false;
if ($this->afterImageUpload()) if ($this->afterImageUpload())
{ {
unlink($tmpName); unlink($tmp_name);
return true; return true;
} }
return false; return false;
@@ -1830,10 +1939,16 @@ class AdminControllerCore extends Controller
if (is_array($boxes) && !empty($boxes)) if (is_array($boxes) && !empty($boxes))
{ {
$object = new $this->className(); $object = new $this->className();
if (isset($object->noZeroObject) && if (isset($object->noZeroObject))
{
$objects_count = count(call_user_func(array($this->className, $object->noZeroObject)));
// Check if all object will be deleted // Check if all object will be deleted
(count(call_user_func(array($this->className, $object->noZeroObject))) <= 1 || count($boxes) == count(call_user_func(array($this->className, $object->noZeroObject))))) if ($objects_count <= 1 || count($boxes) == $objects_count)
$this->_errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.'); $this->_errors[] = Tools::displayError('You need at least one object.').
' <b>'.$this->table.'</b><br />'.
Tools::displayError('You cannot delete all of the items.');
}
else else
{ {
$result = true; $result = true;
+23 -22
View File
@@ -79,7 +79,13 @@ class HelperListCore extends Helper
public $header_tpl = 'list_header.tpl'; public $header_tpl = 'list_header.tpl';
public $content_tpl = 'list_content.tpl'; public $content_tpl = 'list_content.tpl';
public $footer_tpl = 'list_footer.tpl'; public $footer_tpl = 'list_footer.tpl';
/** @var array list of required actions for each list row */
public $actions = array(); public $actions = array();
/** @var array list of row ids associated with a given action for witch this action have to not be available */
public $list_skip_actions = array();
public $bulk_actions = false; public $bulk_actions = false;
public $specificConfirmDelete; public $specificConfirmDelete;
public $colorOnBackground; public $colorOnBackground;
@@ -138,7 +144,7 @@ class HelperListCore extends Helper
* @param unknown_type $id_category * @param unknown_type $id_category
* @param unknown_type $id_product * @param unknown_type $id_product
*/ */
protected function _displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null) protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{ {
return '<a href="'.$this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table. return '<a href="'.$this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token).'"> ((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token).'">
@@ -177,18 +183,15 @@ class HelperListCore extends Helper
// Check all available actions to add to the current list row // Check all available actions to add to the current list row
foreach ($this->actions as $action) foreach ($this->actions as $action)
{ {
$skip = '_listSkip'.ucfirst($action); //Check if the action is available for the current row
$method_name = 'display'.ucfirst($action).'Link'; if (!array_key_exists($action, $this->list_skip_actions) || !in_array($id, $this->list_skip_actions[$action]))
if (!isset($this->$skip) || !in_array($id, $this->$skip))
{ {
$method_name = 'display'.ucfirst($action).'Link';
if (method_exists($this->context->controller, $method_name)) if (method_exists($this->context->controller, $method_name))
$this->_list[$index][$action] = $this->context->controller->$method_name($token, $id); $this->_list[$index][$action] = $this->context->controller->$method_name($token, $id);
else if (method_exists($this, $method_name))
else if (method_exists($this, '_'.$method_name))
{
$method_name = '_'.$method_name;
$this->_list[$index][$action] = $this->$method_name($token, $id); $this->_list[$index][$action] = $this->$method_name($token, $id);
}
} }
} }
@@ -198,7 +201,7 @@ class HelperListCore extends Helper
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0]; $key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
if (isset($params['active'])) if (isset($params['active']))
$this->_list[$index][$key] = $this->_displayEnableLink( $this->_list[$index][$key] = $this->displayEnableLink(
$this->token, $this->token,
$id, $id,
$tr[$key], $tr[$key],
@@ -214,10 +217,10 @@ class HelperListCore extends Helper
'position' => $tr[$key], 'position' => $tr[$key],
'position_url_down' => $this->currentIndex. 'position_url_down' => $this->currentIndex.
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id. '&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
'&way=1&position='.(int)($tr['position'] + 1).'&token='.$this->token, '&way=1&position='.((int)$tr['position'] + 1).'&token='.$this->token,
'position_url_up' => $this->currentIndex. 'position_url_up' => $this->currentIndex.
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id. '&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
'&way=0&position='.(int)($tr['position'] - 1).'&token='.$this->token '&way=0&position='.((int)$tr['position'] - 1).'&token='.$this->token
); );
} }
else if (isset($params['image'])) else if (isset($params['image']))
@@ -269,9 +272,6 @@ class HelperListCore extends Helper
} }
} }
if (isset($this->_listSkipDelete))
$this->context->smarty->assign('listSkipDelete', $this->_listSkipDelete);
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'is_dnd_identifier' => $this->is_dnd_identifier, 'is_dnd_identifier' => $this->is_dnd_identifier,
'color_on_bg' => $this->colorOnBackground, 'color_on_bg' => $this->colorOnBackground,
@@ -288,6 +288,7 @@ class HelperListCore extends Helper
'view' => in_array('view', $this->actions), 'view' => in_array('view', $this->actions),
'edit' => in_array('edit', $this->actions), 'edit' => in_array('edit', $this->actions),
'has_actions' => (bool)count($this->actions), 'has_actions' => (bool)count($this->actions),
'list_skip_actions' => $this->list_skip_actions,
)); ));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_content.tpl'); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_content.tpl');
} }
@@ -295,7 +296,7 @@ class HelperListCore extends Helper
/** /**
* Display duplicate action link * Display duplicate action link
*/ */
protected function _displayDuplicateLink($token = null, $id) protected function displayDuplicateLink($token = null, $id)
{ {
if (!array_key_exists('Duplicate', self::$cache_lang)) if (!array_key_exists('Duplicate', self::$cache_lang))
self::$cache_lang['Duplicate'] = $this->l('Duplicate'); self::$cache_lang['Duplicate'] = $this->l('Duplicate');
@@ -315,7 +316,7 @@ class HelperListCore extends Helper
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_duplicate.tpl'); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_duplicate.tpl');
} }
/** /**
* Display action show details of a table row * Display action show details of a table row
@@ -336,7 +337,7 @@ class HelperListCore extends Helper
* fields_display: // attribute $fieldsDisplay of the admin controller * fields_display: // attribute $fieldsDisplay of the admin controller
* } * }
*/ */
protected function _displayDetailsLink($token = null, $id) protected function displayDetailsLink($token = null, $id)
{ {
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'id' => $id, 'id' => $id,
@@ -349,7 +350,7 @@ class HelperListCore extends Helper
/** /**
* Display view action link * Display view action link
*/ */
protected function _displayViewLink($token = null, $id) protected function displayViewLink($token = null, $id)
{ {
if (!array_key_exists('View', self::$cache_lang)) if (!array_key_exists('View', self::$cache_lang))
self::$cache_lang['View'] = $this->l('View'); self::$cache_lang['View'] = $this->l('View');
@@ -366,7 +367,7 @@ class HelperListCore extends Helper
/** /**
* Display edit action link * Display edit action link
*/ */
protected function _displayEditLink($token = null, $id) protected function displayEditLink($token = null, $id)
{ {
if (!array_key_exists('Edit', self::$cache_lang)) if (!array_key_exists('Edit', self::$cache_lang))
self::$cache_lang['Edit'] = $this->l('Edit'); self::$cache_lang['Edit'] = $this->l('Edit');
@@ -383,7 +384,7 @@ class HelperListCore extends Helper
/** /**
* Display delete action link * Display delete action link
*/ */
protected function _displayDeleteLink($token = null, $id) protected function displayDeleteLink($token = null, $id)
{ {
if (!array_key_exists('Delete', self::$cache_lang)) if (!array_key_exists('Delete', self::$cache_lang))
self::$cache_lang['Delete'] = $this->l('Delete'); self::$cache_lang['Delete'] = $this->l('Delete');
@@ -404,7 +405,7 @@ class HelperListCore extends Helper
/** /**
* Display list header (filtering, pagination and column names) * Display list header (filtering, pagination and column names)
*/ */
public function displayListHeader($token = NULL) public function displayListHeader($token = null)
{ {
$id_cat = Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category'); $id_cat = Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category');