// Context

This commit is contained in:
rMalie
2011-07-12 13:50:15 +00:00
parent 89920e17fd
commit 286a374353
20 changed files with 319 additions and 264 deletions
+6 -12
View File
@@ -50,7 +50,7 @@ class AdminCatalog extends AdminTab
{
/* Get current category */
$id_category = abs(Tools::getValue('id_category'));
$shop = new Shop(Shop::getCurrentShop(true));
$shop = Context::getContext()->shop;
if (!$id_category)
$id_category = $shop->id_category;
else if ($id_category != $shop->id_category)
@@ -58,18 +58,18 @@ class AdminCatalog extends AdminTab
// Check if current category is "inside" shop default category
$sql = 'SELECT nleft, nright FROM '._DB_PREFIX_.'category
WHERE id_category = '.$shop->id_category;
if ($result = Db::getInstance()->getRow($sql))
if ($interval = Category::getInterval($shop->id_category))
{
$sql = 'SELECT id_category FROM '._DB_PREFIX_.'category
WHERE id_category = '.(int)$id_category.'
AND nleft >= '.$result['nleft'].'
AND nright <= '.$result['nright'];
AND nleft >= '.$interval['nleft'].'
AND nright <= '.$interval['nright'];
if (!Db::getInstance()->getValue($sql))
$id_category = $shop->id_category;
}
}
self::$_category = new Category($id_category, NULL, Shop::getCurrentShop(true));
self::$_category = new Category($id_category);
if (!Validate::isLoadedObject(self::$_category))
die('Category cannot be loaded');
@@ -176,13 +176,7 @@ class AdminCatalog extends AdminTab
if (!$id_category)
{
$home = true;
if (Shop::getContextType() == Shop::CONTEXT_SHOP)
{
$shop = new Shop((int)Shop::getCurrentShop());
$id_category = $shop->id_category;
}
else
$id_category = 1;
$id_category = Context::getContext()->shop->id_category1;
}
$catalog_tabs = array('category', 'product');
// Cleaning links
+15 -19
View File
@@ -34,8 +34,6 @@ class AdminCategories extends AdminTab
public function __construct()
{
global $cookie;
$this->table = 'category';
$this->className = 'Category';
$this->lang = true;
@@ -61,8 +59,6 @@ class AdminCategories extends AdminTab
public function displayList($token = NULL)
{
global $currentIndex;
/* Display list header (filtering, pagination and column names) */
$this->displayListHeader($token);
if (!sizeof($this->_list))
@@ -77,8 +73,9 @@ class AdminCategories extends AdminTab
public function display($token = NULL)
{
global $currentIndex, $cookie;
$this->getList((int)($cookie->id_lang), !$cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, (int)Shop::getCurrentShop(true));
$context = Context::getContext();
$this->getList((int)($context->language->id), !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $context->shop->getID());
echo '<h3>'.(!$this->_listTotal ? ($this->l('There are no subcategories')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('subcategories') : $this->l('subcategory')))).' '.$this->l('in category').' "'.stripslashes($this->_category->getName()).'"</h3>';
if ($this->tabAccess['add'] === '1')
echo '<a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminCatalog&add'.$this->table.'&id_parent='.$this->_category->id.'&token='.($token!=NULL ? $token : $this->token).'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new subcategory').'</a>';
@@ -89,9 +86,8 @@ class AdminCategories extends AdminTab
public function postProcess($token = NULL)
{
global $cookie, $currentIndex;
$this->tabAccess = Profile::getProfileAccess($cookie->profile, $this->id);
$context = Context::getContext();
$this->tabAccess = Profile::getProfileAccess($context->employee->id_profile, $this->id);
if (Tools::isSubmit('submitAdd'.$this->table))
{
@@ -123,7 +119,7 @@ class AdminCategories extends AdminTab
$target = '&id_category='.(int)($matches[1]);
}
Module::hookExec('categoryUpdate');
Tools::redirectAdmin($currentIndex.'&conf=5'.$target.'&token='.Tools::getValue('token'));
Tools::redirectAdmin($this->currentIndex.'&conf=5'.$target.'&token='.Tools::getValue('token'));
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating status.');
@@ -151,10 +147,10 @@ class AdminCategories extends AdminTab
$object->deleteImage();
$object->deleted = 1;
if ($object->update())
Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent));
Tools::redirectAdmin($this->currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent));
}
elseif ($object->delete())
Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent));
Tools::redirectAdmin($this->currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent));
$this->_errors[] = Tools::displayError('An error occurred during deletion.');
}
}
@@ -173,7 +169,7 @@ class AdminCategories extends AdminTab
if (!$object->updatePosition((int)(Tools::getValue('way')), (int)(Tools::getValue('position'))))
$this->_errors[] = Tools::displayError('Failed to update the position.');
else
Tools::redirectAdmin($currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier, Tools::getValue('id_category_parent', 1)))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.Tools::getAdminTokenLite('AdminCatalog'));
Tools::redirectAdmin($this->currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier, Tools::getValue('id_category_parent', 1)))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.Tools::getAdminTokenLite('AdminCatalog'));
}
/* Delete multiple objects */
elseif (Tools::getValue('submitDel'.$this->table))
@@ -188,7 +184,7 @@ class AdminCategories extends AdminTab
if ($result)
{
$category->cleanPositions((int)(Tools::getValue('id_category')));
Tools::redirectAdmin($currentIndex.'&conf=2&token='.Tools::getAdminTokenLite('AdminCatalog').'&id_category='.(int)(Tools::getValue('id_category')));
Tools::redirectAdmin($this->currentIndex.'&conf=2&token='.Tools::getAdminTokenLite('AdminCatalog').'&id_category='.(int)(Tools::getValue('id_category')));
}
$this->_errors[] = Tools::displayError('An error occurred while deleting selection.');
@@ -217,9 +213,9 @@ class AdminCategories extends AdminTab
public function displayForm($token = NULL)
{
global $currentIndex, $cookie;
parent::displayForm();
$context = Context::getContext();
if (!($obj = $this->loadObject(true)))
return;
$active = $this->getFieldValue($obj, 'active');
@@ -233,7 +229,7 @@ class AdminCategories extends AdminTab
$id_category = (int)Tools::getValue('id_parent');
echo '
<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.($token!=NULL ? $token : $this->token).'" method="post" enctype="multipart/form-data">
<form action="'.$this->currentIndex.'&submitAdd'.$this->table.'=1&token='.($token!=NULL ? $token : $this->token).'" method="post" enctype="multipart/form-data">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/admin/tab-categories.gif" />'.$this->l('Category').'</legend>
<label>'.$this->l('Name:').' </label>
@@ -256,7 +252,7 @@ class AdminCategories extends AdminTab
<label>'.$this->l('Parent category:').' </label>
<div class="margin-form">
<select name="id_parent">';
$categories = Category::getCategories((int)$cookie->id_lang, false);
$categories = Category::getCategories((int)$context->language->id, false);
Category::recurseCategory($categories, $categories[0][1], 1, ($obj->id ? $this->getFieldValue($obj, 'id_parent') : $id_category));
echo '
</select>
@@ -272,7 +268,7 @@ class AdminCategories extends AdminTab
</div>
<label>'.$this->l('Image:').' </label>
<div class="margin-form">';
echo $this->displayImage($obj->id, _PS_IMG_DIR_.'c/'.$obj->id.'.jpg', 350, NULL, Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)), true);
echo $this->displayImage($obj->id, _PS_IMG_DIR_.'c/'.$obj->id.'.jpg', 350, NULL, Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).$context->employee->id), true);
echo ' <br /><input type="file" name="image" />
<p>'.$this->l('Upload category logo from your computer').'</p>
</div>
@@ -317,7 +313,7 @@ class AdminCategories extends AdminTab
</div>
<label>'.$this->l('Groups access:').' </label>
<div class="margin-form">';
$groups = Group::getGroups((int)($cookie->id_lang));
$groups = Group::getGroups((int)($context->language->id));
if (sizeof($groups))
{
echo '
+1 -1
View File
@@ -188,7 +188,7 @@ class AdminMeta extends AdminTab
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false)
{
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Shop::getCurrentShop(true));
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID());
}
}
+1 -1
View File
@@ -262,7 +262,7 @@ class AdminModulesPositions extends AdminTab
else
echo '<p>'.$this->l('By clicking here you will be redirected to the front office of your shop to move and delete modules directly.').'</p>
<br>
<a href="'.$link->getPageLink('index').'&live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_).((Tools::isMultiShopActivated()) ? '&id_shop='.Shop::getCurrentShop() : '').'" target="_blank" class="button">'.$this->l('Run LiveEdit').'</a>';
<a href="'.$link->getPageLink('index').'&live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_).((Tools::isMultiShopActivated()) ? '&id_shop='.Context::getContext()->shop->getID() : '').'" target="_blank" class="button">'.$this->l('Run LiveEdit').'</a>';
echo '</fieldset>';
// Print hook list
+9 -8
View File
@@ -31,9 +31,9 @@ class AdminPayment extends AdminTab
public function __construct()
{
global $cookie;
/* Get all modules then select only payment ones*/
$shopID = Context::getContext()->shop->getID();
/* Get all modules then select only payment ones*/
$modules = Module::getModulesOnDisk();
foreach ($modules AS $module)
@@ -43,19 +43,19 @@ class AdminPayment extends AdminTab
{
if(!get_class($module) == 'SimpleXMLElement')
$module->country = array();
$countries = DB::getInstance()->ExecuteS('SELECT id_country FROM '._DB_PREFIX_.'module_country WHERE id_module = '.(int)$module->id.' AND `id_shop`='.Shop::getCurrentShop(true));
$countries = DB::getInstance()->ExecuteS('SELECT id_country FROM '._DB_PREFIX_.'module_country WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
foreach ($countries as $country)
$module->country[] = $country['id_country'];
if(!get_class($module) == 'SimpleXMLElement')
$module->currency = array();
$currencies = DB::getInstance()->ExecuteS('SELECT id_currency FROM '._DB_PREFIX_.'module_currency WHERE id_module = '.(int)$module->id.' AND `id_shop`='.Shop::getCurrentShop(true));
$currencies = DB::getInstance()->ExecuteS('SELECT id_currency FROM '._DB_PREFIX_.'module_currency WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
foreach ($currencies as $currency)
$module->currency[] = $currency['id_currency'];
if(!get_class($module) == 'SimpleXMLElement')
$module->group = array();
$groups = DB::getInstance()->ExecuteS('SELECT id_group FROM '._DB_PREFIX_.'module_group WHERE id_module = '.(int)$module->id.' AND `id_shop`='.Shop::getCurrentShop(true));
$groups = DB::getInstance()->ExecuteS('SELECT id_group FROM '._DB_PREFIX_.'module_group WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
foreach ($groups as $group)
$module->group[] = $group['id_group'];
}
@@ -84,12 +84,13 @@ class AdminPayment extends AdminTab
private function saveRestrictions($type)
{
global $currentIndex, $cookie;
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'module_'.$type.' WHERE id_shop='.Shop::getCurrentShop(true));
global $currentIndex;
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'module_'.$type.' WHERE id_shop='.Context::getContext()->shop->getID());
foreach ($this->paymentModules as $module)
if ($module->active AND isset($_POST[$module->name.'_'.$type.'']))
foreach ($_POST[$module->name.'_'.$type.''] as $selected)
$values[] = '('.(int)$module->id.', '.Shop::getCurrentShop(true).', '.(int)$selected.')';
$values[] = '('.(int)$module->id.', '.Context::getContext()->shop->getID().', '.(int)$selected.')';
if (sizeof($values))
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'module_'.$type.' (`id_module`, `id_shop`, `id_'.$type.'`) VALUES '.implode(',', $values));
Tools::redirectAdmin($currentIndex.'&conf=4'.'&token='.$this->token);
+2 -2
View File
@@ -222,7 +222,7 @@ class AdminPreferences extends AdminTab
{
if (Tools::isSubmit('submitAppearanceconfiguration'))
{
$id_shop = Shop::getCurrentShop(true);
$id_shop = Context::getContext()->shop->getID();
if (isset($_FILES['PS_LOGO']['tmp_name']) AND $_FILES['PS_LOGO']['tmp_name'])
{
if ($error = checkImage($_FILES['PS_LOGO'], 300000))
@@ -242,7 +242,7 @@ class AdminPreferences extends AdminTab
$this->_errors[] = $error;
if (!$tmpName == tempnam(_PS_TMP_IMG_DIR_, 'PS_MAIL') OR !move_uploaded_file($_FILES['PS_LOGO_MAIL']['tmp_name'], $tmpName))
return false;
if ($id_shop = Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail.jpg'))
if ($id_shop == Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail.jpg'))
$this->_errors[] = 'an error occurred during logo copy';
if (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg'))
$this->_errors[] = 'an error occurred during logo copy';
+1 -1
View File
@@ -95,7 +95,7 @@ class AdminThemes extends AdminPreferences
{
$this->className = 'Configuration';
$this->table = 'configuration';
$id_shop = (int)Shop::getCurrentShop(true);
$id_shop = Context::getContext()->shop->getID();
$this->_fieldsAppearance = array(
'PS_LOGO' => array('title' => $this->l('Header logo:'), 'desc' => $this->l('Will appear on main page'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time(), 'pos' => 'before')),
'PS_LOGO_MAIL' => array('title' => $this->l('Mail logo:'), 'desc' => $this->l('Will appear on e-mail headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => array('file' => ((file_exists(_PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg')) ? _PS_IMG_.'logo_mail-'.(int)$id_shop.'.jpg?date='.time() : _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time()), 'pos' => 'before')),