diff --git a/admin-dev/themes/template/helper/assoshop.tpl b/admin-dev/themes/template/helper/assoshop.tpl new file mode 100644 index 000000000..cf0ad9eb7 --- /dev/null +++ b/admin-dev/themes/template/helper/assoshop.tpl @@ -0,0 +1,131 @@ +{* +* 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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + + +
+ + + + + + + + {foreach $input.values as $groupID => $groupData} + {if ($input.type == 'group_shop' && (isset($fields_value.shop[$groupID]) || !$form_id))} + {assign var=groupChecked value=true} + {else} + {assign var=groupChecked value=false} + {/if} + + + + + {if $input.type == 'shop'} + {assign var=j value=0} + {foreach $groupData['shops'] as $shopID => $shopData} + {if (isset($fields_value.shop[$shopID]) || !$form_id)} + {assign var=checked value=true} + {else} + {assign var=checked value=false} + {/if} + + + + {assign var=j value=$j+1} + {/foreach} + {/if} + {/foreach} +
{if $input.type == 'group_shop'}{l s='Group shop'}{else}{l s='Shop'}{/if}
+ +
+ + +
+ + +
+
\ No newline at end of file diff --git a/classes/AdminController.php b/classes/AdminController.php index 365ccd481..3149558b7 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -2253,12 +2253,12 @@ class AdminControllerCore extends Controller return; $assos = array(); - foreach ($_POST as $k => $row) + foreach ($_POST['checkBox'.Tools::toCamelCase($type, true).'Asso_'.$table] as $id_asso_object => $row) { - if (!preg_match('/^checkBox'.Tools::toCamelCase($type, true).'Asso_'.$table.'_([0-9]+)?_([0-9]+)$/Ui', $k, $res)) - continue; - $id_asso_object = (!empty($res[1]) ? $res[1] : $id_object); - $assos[] = array('id_object' => (int)$id_asso_object, 'id_'.$type => (int)$res[2]); + if (!(int)$id_asso_object) + $id_asso_object = $id_object; + foreach ($row as $id_shop => $value) + $assos[] = array('id_object' => (int)$id_asso_object, 'id_'.$type => (int)$id_shop); } return array($assos, $type); } @@ -2276,21 +2276,9 @@ class AdminControllerCore extends Controller $shop_asso = Shop::getAssoTables(); $group_shop_asso = GroupShop::getAssoTables(); - if (isset($shop_asso[$this->table]) && $shop_asso[$this->table]['type'] == 'shop') - $type = 'shop'; - else if (isset($group_shop_asso[$this->table]) && $group_shop_asso[$this->table]['type'] == 'group_shop') - $type = 'group_shop'; - else - return; - - $assos = array(); - foreach ($_POST as $k => $row) - { - if (!preg_match('/^checkBox'.Tools::toCamelCase($type, true).'Asso_'.$this->table.'_([0-9]+)?_([0-9]+)$/Ui', $k, $res)) - continue; - $id_asso_object = (!empty($res[1]) ? $res[1] : $id_object); - $assos[] = array('id_object' => (int)$id_asso_object, 'id_'.$type => (int)$res[2]); - } + $assos_data = $this->getAssoShop($this->table, $id_object); + $assos = $assos_data[0]; + $type = $assos_data[1]; Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.($id_object ? ' WHERE `'.$this->identifier.'`='.(int)$id_object : '')); @@ -2324,137 +2312,6 @@ class AdminControllerCore extends Controller { } - /** - * displayAssoShop - * @todo : create assoshop.tpl and use smarty var asso_shop in pages - * - * @param string $type - * @return void - */ - protected function displayAssoShop($type = 'shop') - { - if (!Shop::isFeatureActive() || (!$this->object && $this->context->shop->getContextType() != Shop::CONTEXT_ALL)) - return; - - if ($type != 'shop' && $type != 'group_shop') - $type = 'shop'; - - $assos = array(); - $sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'` - FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`'; - foreach (Db::getInstance()->executeS($sql) as $row) - $assos[$row['id_'.$type]][] = $row[$this->identifier]; - - $html = << - $().ready(function() - { - // Click on "all shop" - $('.input_all_shop').click(function() - { - var checked = $(this).attr('checked'); - $('.input_group_shop').attr('checked', checked); - $('.input_shop').attr('checked', checked); - }); - - // Click on a group shop - $('.input_group_shop').click(function() - { - $('.input_shop[value='+$(this).val()+']').attr('checked', $(this).attr('checked')); - check_all_shop(); - }); - - // Click on a shop - $('.input_shop').click(function() - { - check_group_shop_status($(this).val()); - check_all_shop(); - }); - - // Initialize checkbox - $('.input_shop').each(function(k, v) - { - check_group_shop_status($(v).val()); - check_all_shop(); - }); - }); - - function check_group_shop_status(id_group) - { - var groupChecked = true; - $('.input_shop[value='+id_group+']').each(function(k, v) - { - if (!$(v).attr('checked')) - groupChecked = false; - }); - $('.input_group_shop[value='+id_group+']').attr('checked', groupChecked); - } - - function check_all_shop() - { - var allChecked = true; - $('.input_group_shop').each(function(k, v) - { - if (!$(v).attr('checked')) - allChecked = false; - }); - $('.input_all_shop').attr('checked', allChecked); - } - -EOF; - - $html .= '
'; - $html .= ' - '; - $html .= ' - - '; - foreach (Shop::getTree() as $group_id => $group_data) - { - $group_checked = ($type == 'group_shop' && ((isset($assos[$group_id]) && in_array($this->object->id, $assos[$group_id])) || !$this->object->id)); - $html .= ''; - $html .= ''; - $html .= ''; - - if ($type == 'shop') - { - $total = count($group_data['shops']); - $j = 0; - foreach ($group_data['shops'] as $shop_id => $shop_data) - { - $checked = ((isset($assos[$shop_id]) && in_array($this->object->id, $assos[$shop_id])) || !$this->object->id); - $html .= ''; - $html .= ''; - $html .= ''; - $j++; - } - } - } - $html .= '
'.$this->l('Shop').'
- -
- - -
- -
'; - $this->context->smarty->assign('asso_shop', $html); - return $html; - } - - - /** * Overload this method for custom checking * diff --git a/classes/Configuration.php b/classes/Configuration.php index 8ad8f4aa4..057e55031 100644 --- a/classes/Configuration.php +++ b/classes/Configuration.php @@ -364,7 +364,7 @@ class ConfigurationCore extends ObjectModel return false; $sql = 'DELETE FROM `'._DB_PREFIX_.'configuration_lang` - WHERE `id_configuration` = ( + WHERE `id_configuration` IN ( SELECT `id_configuration` FROM `'._DB_PREFIX_.'configuration` WHERE `name` = \''.pSQL($key).'\' diff --git a/classes/helper/Helper.php b/classes/helper/Helper.php index 798ea935c..a6b42954f 100755 --- a/classes/helper/Helper.php +++ b/classes/helper/Helper.php @@ -293,8 +293,8 @@ class HelperCore } global $_LANGADM; - if ($class == __CLASS__) - $class = 'AdminTab'; + if ($class == __CLASS__) + $class = 'AdminTab'; $key = md5(str_replace('\'', '\\\'', $string)); $str = (key_exists(get_class($this).$key, $_LANGADM)) ? $_LANGADM[get_class($this).$key] : ((key_exists($class.$key, $_LANGADM)) ? $_LANGADM[$class.$key] : $string); @@ -302,7 +302,14 @@ class HelperCore return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str))); } - protected function displayAssoShop($type = 'shop') + /** + * Render an area to determinate shop association + * + * @param string $type 'shop' or 'group_shop' + * + * @return string + */ + public function renderAssoShop($type = 'shop') { if (!Shop::isFeatureActive() || (!$this->id && $this->context->shop->getContextType() != Shop::CONTEXT_ALL)) return; @@ -311,12 +318,33 @@ class HelperCore $type = 'shop'; $assos = array(); - $sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'` - FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`'; - - foreach (Db::getInstance()->executeS($sql) as $row) - $assos[$row['id_'.$type]][] = $row[$this->identifier]; + + if ((int)$this->id) + { + $sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'` + FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'` + WHERE `'.pSQL($this->identifier).'` = '.(int)$this->id; + + foreach (Db::getInstance()->executeS($sql) as $row) + $assos[$row['id_'.$type]] = $row['id_'.$type]; + } + + $tpl = $this->createTemplate('helper/assoshop.tpl'); + $tpl->assign(array( + 'input' => array( + 'type' => $type, + 'values' => Shop::getTree(), + ), + 'fields_value' => array( + 'shop' => $assos + ), + 'form_id' => $this->id, + 'table' => $this->table + )); + return $tpl->fetch(); + /* + //$page = $this->context->smarty->fetch($tpl); $html = << $().ready(function() @@ -404,6 +432,7 @@ EOF; } $html .= ''; return $html; + */ } } diff --git a/classes/helper/HelperForm.php b/classes/helper/HelperForm.php index 3465aaffb..dacf93b50 100644 --- a/classes/helper/HelperForm.php +++ b/classes/helper/HelperForm.php @@ -68,12 +68,11 @@ class HelperFormCore extends Helper if ($this->submit_action == '') $this->submit_action = 'submitAdd'.$this->table; - /* TODO : replace call method displayAssoShop() by form_shop.tpl */ if (isset($this->fields_form[0]['form']['asso_shop']) && Shop::isFeatureActive()) if ($this->fields_form[0]['asso_shop'] == 'group') - $asso_shop = $this->displayAssoShop('group_shop'); + $asso_shop = $this->renderAssoShop('group_shop'); else if ($this->fields_form[0]['form']['asso_shop'] == 'shop') - $asso_shop = $this->displayAssoShop(); + $asso_shop = $this->renderAssoShop(); $this->context->controller->addJS(_PS_JS_DIR_.'form.js'); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 4ae87b4a6..a7fa9623e 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2742,8 +2742,16 @@ class AdminProductsControllerCore extends AdminController $cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute'); $data->assign('feature_shop_active', Shop::isFeatureActive()); - // @todo : uses the helperform - $data->assign('displayAssoShop', $this->displayAssoShop()); + + $helper = new Helper(); + if ($this->object && $this->object->id) + $helper->id = $this->object->id; + else + $helper->id = null; + $helper->table = $this->table; + $helper->identifier = $this->identifier; + + $data->assign('displayAssoShop', $helper->renderAssoShop()); $product_props = array(); // global informations