// Move helper classes in subdirectory
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10968 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
Executable
+407
@@ -0,0 +1,407 @@
|
||||
<?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$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO : move HTML code in template files
|
||||
* TODO : phpDoc on two last methods: includeDatepicker() & bindDatepicker()
|
||||
*/
|
||||
|
||||
class HelperCore
|
||||
{
|
||||
public $currentIndex;
|
||||
public $table;
|
||||
public $identifier;
|
||||
public $token;
|
||||
public $toolbar_btn;
|
||||
public $ps_help_context;
|
||||
public $title;
|
||||
public $show_toolbar = true;
|
||||
public $context;
|
||||
public $toolbar_fix = false;
|
||||
|
||||
/** @var string Helper tpl folder */
|
||||
public $base_folder;
|
||||
|
||||
/** @var string Controller tpl folder */
|
||||
public $override_folder;
|
||||
|
||||
/**
|
||||
* @var smartyTemplate base template object
|
||||
*/
|
||||
protected $tpl;
|
||||
|
||||
/**
|
||||
* @var string base template name
|
||||
*/
|
||||
public $base_tpl = 'content.tpl';
|
||||
|
||||
public $tpl_vars = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
}
|
||||
|
||||
public function setTpl($tpl)
|
||||
{
|
||||
$this->tpl = $this->createTemplate($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a template from the override file, else from the base file.
|
||||
*
|
||||
* @param string $tpl_name filename
|
||||
* @return Template
|
||||
*/
|
||||
public function createTemplate($tpl_name)
|
||||
{
|
||||
// Overrides exists?
|
||||
if ($this->override_folder && file_exists($this->context->smarty->template_dir[0].$this->override_folder.$tpl_name))
|
||||
return $this->context->smarty->createTemplate($this->override_folder.$tpl_name);
|
||||
|
||||
return $this->context->smarty->createTemplate($this->base_folder.$tpl_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* default behaviour for helper is to return a tpl fetched
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$this->tpl->assign($this->tpl_vars);
|
||||
return $this->tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $trads values of translations keys
|
||||
* For the moment, translation are not automatic
|
||||
* @param type $selected_cat array of selected categories
|
||||
* Format
|
||||
* Array
|
||||
* (
|
||||
* [0] => 1
|
||||
* [1] => 2
|
||||
* )
|
||||
* OR
|
||||
* Array
|
||||
* (
|
||||
* [1] => Array
|
||||
* (
|
||||
* [id_category] => 1
|
||||
* [name] => Home page
|
||||
* [link_rewrite] => home
|
||||
* )
|
||||
* )
|
||||
* @param type $input_name name of input
|
||||
* @return string
|
||||
*/
|
||||
public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array())
|
||||
{
|
||||
if (!$use_radio)
|
||||
$input_name = $input_name.'[]';
|
||||
|
||||
$context = Context::getContext();
|
||||
|
||||
$context->controller->addCSS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.css');
|
||||
|
||||
|
||||
$context->controller->addJs(array(
|
||||
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.js',
|
||||
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js',
|
||||
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.edit.js',
|
||||
_PS_JS_DIR_.'admin-categories-tree.js'));
|
||||
if ($use_search)
|
||||
$context->controller->addJs(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
|
||||
|
||||
|
||||
$html = '
|
||||
<script type="text/javascript">
|
||||
var inputName = "'.$input_name.'";
|
||||
var use_radio = '.($use_radio ? '1' : '0').';
|
||||
';
|
||||
if (sizeof($selected_cat) > 0)
|
||||
{
|
||||
if (isset($selected_cat[0]))
|
||||
$html .= 'var selectedCat = "'.implode(',', $selected_cat).'";';
|
||||
else
|
||||
$html .= 'var selectedCat = "'.implode(',', array_keys($selected_cat)).'";';
|
||||
}
|
||||
else
|
||||
$html .= 'var selectedCat = "";';
|
||||
$html .= '
|
||||
var selectedLabel = \''.$trads['selected'].'\';
|
||||
var home = \''.$trads['Home'].'\';
|
||||
var use_radio = '.(int)$use_radio.';
|
||||
</script>';
|
||||
|
||||
$html .= '
|
||||
<div style="background-color:#F4E6C9; width:99%;padding:5px 0 5px 5px;">
|
||||
<a href="#" id="collapse_all" >'.$trads['Collapse All'].'</a>
|
||||
- <a href="#" id="expand_all" >'.$trads['Expand All'].'</a>
|
||||
'.(!$use_radio ? '
|
||||
- <a href="#" id="check_all" >'.$trads['Check All'].'</a>
|
||||
- <a href="#" id="uncheck_all" >'.$trads['Uncheck All'].'</a>
|
||||
' : '').($use_search ? '<span style="margin-left:20px">'.$trads['search'].' : <form method="post" id="filternameForm"><input type="text" name="search_cat" id="search_cat"></form></span>' : '').'
|
||||
</div>
|
||||
';
|
||||
|
||||
$home_is_selected = false;
|
||||
foreach($selected_cat AS $cat)
|
||||
{
|
||||
if (is_array($cat))
|
||||
{
|
||||
$disabled = in_array($cat['id_category'], $disabled_categories);
|
||||
if ($cat['id_category'] != 1)
|
||||
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat['id_category'].'" >';
|
||||
else
|
||||
$home_is_selected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$disabled = in_array($cat, $disabled_categories);
|
||||
if ($cat != 1)
|
||||
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat.'" >';
|
||||
else
|
||||
$home_is_selected = true;
|
||||
}
|
||||
}
|
||||
$html .= '
|
||||
<ul id="categories-treeview" class="filetree">
|
||||
<li id="1" class="hasChildren">
|
||||
<span class="folder"> <input type="'.(!$use_radio ? 'checkbox' : 'radio').'" name="'.$input_name.'" value="1" '.($home_is_selected ? 'checked' : '').' onclick="clickOnCategoryBox($(this));" /> '.$trads['Home'].'</span>
|
||||
<ul>
|
||||
<li><span class="placeholder"> </span></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a select input field
|
||||
*
|
||||
* @param array $values
|
||||
* @param array $html_options any key => value options
|
||||
* @param array $select_options
|
||||
* - key: the array value that will be used as a key in my select (optional)
|
||||
* - value: the array value that will be used as a label in my select (optional)
|
||||
* - empty: the label displayed as an empty value (optional)
|
||||
* - selected: the key corresponding to the selected value (optional)
|
||||
*
|
||||
* @return string html content
|
||||
*/
|
||||
public static function selectInput(array $values, array $html_options = array(), array $select_options = array())
|
||||
{
|
||||
// options management
|
||||
$options = self::buildHtmlOptions($html_options);
|
||||
$select_html = '<select '.$options.'>';
|
||||
|
||||
if (isset($select_options['key']))
|
||||
$use_key = $select_options['key'];
|
||||
|
||||
if (isset($select_options['value']))
|
||||
$use_value = $select_options['value'];
|
||||
|
||||
if (isset($select_options['empty']))
|
||||
$select_html .= '<option value="">'.$select_options['empty'].'</option>';
|
||||
|
||||
if (isset($select_options['selected']) && !is_array($select_options['selected']))
|
||||
$select_options['selected'] = array($select_options['selected']);
|
||||
// render options fields
|
||||
foreach ($values as $key => $value)
|
||||
{
|
||||
$current_key = isset($use_key) ? $value[$use_key] : $key;
|
||||
$current_value = isset($use_value) ? $value[$use_value] : $value;
|
||||
|
||||
if (isset($select_options['selected']) && in_array($current_key, $select_options['selected']))
|
||||
$selected = 'selected="selected"';
|
||||
else
|
||||
$selected = '';
|
||||
|
||||
$select_html .= '<option value="'.Tools::htmlentitiesUTF8($current_key).'" '.$selected.'>'.Tools::htmlentitiesUTF8($current_value).'</option>';
|
||||
}
|
||||
|
||||
$select_html .= '</select>';
|
||||
return $select_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create html a string containing html options
|
||||
* eg: buildHtmlOptions(array('name' => 'myInputName', 'id' => 'myInputId'));
|
||||
* return => 'name="myInputName" id="myInputId"'
|
||||
*
|
||||
* @param array $html_options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function buildHtmlOptions(array $html_options)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
foreach ($html_options as $html_option => $value)
|
||||
$html .= Tools::htmlentitiesUTF8($html_option).'="'.Tools::htmlentitiesUTF8($value).'" ';
|
||||
|
||||
return rtrim($html, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* use translations files to replace english expression.
|
||||
*
|
||||
* @param mixed $string term or expression in english
|
||||
* @param string $class
|
||||
* @param boolan $addslashes if set to true, the return value will pass through addslashes(). Otherwise, stripslashes().
|
||||
* @param boolean $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8')
|
||||
* @return string the translation if available, or the english default text.
|
||||
*/
|
||||
protected function l($string, $class = 'AdminTab', $addslashes = FALSE, $htmlentities = TRUE)
|
||||
{
|
||||
// if the class is extended by a module, use modules/[module_name]/xx.php lang file
|
||||
$currentClass = get_class($this);
|
||||
if(Module::getModuleNameFromClass($currentClass))
|
||||
{
|
||||
$string = str_replace('\'', '\\\'', $string);
|
||||
return Module::findTranslation(Module::$classInModule[$currentClass], $string, $currentClass);
|
||||
}
|
||||
global $_LANGADM;
|
||||
|
||||
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);
|
||||
$str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str;
|
||||
return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str)));
|
||||
}
|
||||
|
||||
protected function displayAssoShop($type = 'shop')
|
||||
{
|
||||
if (!Shop::isFeatureActive() || (!$this->id && $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 = <<<EOF
|
||||
<script type="text/javascript">
|
||||
$().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);
|
||||
}
|
||||
</script>
|
||||
EOF;
|
||||
|
||||
$html .= '<div class="assoShop">';
|
||||
$html .= '<table class="table" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr><th>'.$this->l('Shop').'</th></tr>';
|
||||
$html .= '<tr'.(($type == 'group_shop') ? ' class="alt_row"' : '').'><td><label class="t"><input class="input_all_shop" type="checkbox" /> '.$this->l('All shops').'</label></td></tr>';
|
||||
foreach (Shop::getTree() as $groupID => $groupData)
|
||||
{
|
||||
$groupChecked = ($type == 'group_shop' && ((isset($assos[$groupID]) && in_array($this->id, $assos[$groupID])) || !$this->id));
|
||||
$html .= '<tr'.(($type == 'shop') ? ' class="alt_row"' : '').'>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" /><label class="t"><input class="input_group_shop" type="checkbox" name="checkBoxGroupShopAsso_'.$this->table.'_'.$this->id.'_'.$groupID.'" value="'.$groupID.'" '.($groupChecked ? 'checked="checked"' : '').' /> '.$groupData['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
|
||||
if ($type == 'shop')
|
||||
{
|
||||
$total = count($groupData['shops']);
|
||||
$j = 0;
|
||||
foreach ($groupData['shops'] as $shopID => $shopData)
|
||||
{
|
||||
$checked = ((isset($assos[$shopID]) && in_array($this->id, $assos[$shopID])) || !$this->id);
|
||||
$html .= '<tr>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv3_'.(($j < $total - 1) ? 'b' : 'f').'.png" /><label class="child">';
|
||||
$html .= '<input class="input_shop" type="checkbox" value="'.$groupID.'" name="checkBoxShopAsso_'.$this->table.'_'.$this->id.'_'.$shopID.'" id="checkedBox_'.$shopID.'" '.($checked ? 'checked="checked"' : '').' /> ';
|
||||
$html .= $shopData['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= '</table></div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
<?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: 9194 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class HelperFormCore extends Helper
|
||||
{
|
||||
public $id;
|
||||
public $first_call = true;
|
||||
|
||||
/** @var array of forms fields */
|
||||
protected $fields_form = array();
|
||||
|
||||
/** @var array values of form fields */
|
||||
public $fields_value = array();
|
||||
|
||||
public $table;
|
||||
|
||||
/** @var string if not null, a title will be added on that list */
|
||||
public $title = null;
|
||||
|
||||
/** @var string Used to override default 'submitAdd' parameter in form action attribute */
|
||||
public $submit_action = '';
|
||||
|
||||
public $token;
|
||||
public $languages = null;
|
||||
public $default_form_language = null;
|
||||
public $allow_employee_form_lang = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->base_folder = 'helper/form/';
|
||||
$this->base_tpl = 'form.tpl';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function generateForm($fields_form)
|
||||
{
|
||||
$this->fields_form = $fields_form;
|
||||
return $this->generate();
|
||||
}
|
||||
|
||||
public function generate()
|
||||
{
|
||||
$this->tpl = $this->createTemplate($this->base_tpl);
|
||||
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');
|
||||
else if ($this->fields_form[0]['form']['asso_shop'] == 'shop')
|
||||
$asso_shop = $this->displayAssoShop();
|
||||
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'form.js');
|
||||
|
||||
$categories = true;
|
||||
$color = true;
|
||||
$date = true;
|
||||
$tinymce = true;
|
||||
foreach ($this->fields_form as $fieldset)
|
||||
if (isset($fieldset['form']['input']))
|
||||
foreach ($fieldset['form']['input'] as $key => $params)
|
||||
{
|
||||
switch ($params['type'])
|
||||
{
|
||||
case 'categories':
|
||||
if ($categories)
|
||||
{
|
||||
// Added Jquery plugin treeview (css and js files)
|
||||
$this->context->controller->addJqueryPlugin('treeview');
|
||||
|
||||
// Added JS files
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js');
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.edit.js');
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'admin-categories-tree.js');
|
||||
|
||||
if (isset($params['use_search']) && $params['use_search'])
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
|
||||
$categories = false;
|
||||
}
|
||||
break;
|
||||
case 'color':
|
||||
if ($color)
|
||||
{
|
||||
// Added JS file
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/jquery.colorpicker.js');
|
||||
$color = false;
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
if ($date)
|
||||
{
|
||||
$this->context->controller->addJqueryUI('ui.datepicker');
|
||||
$date = false;
|
||||
}
|
||||
break;
|
||||
case 'textarea':
|
||||
if ($tinymce)
|
||||
{
|
||||
$iso = $this->context->language->iso_code;
|
||||
$this->tpl_vars['iso'] = file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en';
|
||||
$this->tpl_vars['path_css'] = _THEME_CSS_DIR_;
|
||||
$this->tpl_vars['ad'] = dirname($_SERVER['PHP_SELF']);
|
||||
$this->tpl_vars['tinymce'] = true;
|
||||
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'tinymce.inc.js');
|
||||
$tinymce = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->tpl->assign(array(
|
||||
'title' => $this->title,
|
||||
'toolbar_btn' => $this->toolbar_btn,
|
||||
|
||||
'ps_help_context' => $this->ps_help_context,
|
||||
'class_name' => get_class($this->context->controller),
|
||||
'iso_user' => $this->context->language->id,
|
||||
'country_iso_code' => $this->context->country->iso_code,
|
||||
'version' => _PS_VERSION_,
|
||||
|
||||
'show_toolbar' => $this->show_toolbar,
|
||||
'toolbar_fix' => $this->toolbar_fix,
|
||||
'submit_action' => $this->submit_action,
|
||||
'firstCall' => $this->first_call,
|
||||
'current' => $this->currentIndex,
|
||||
'token' => $this->token,
|
||||
'table' => $this->table,
|
||||
'languages' => $this->languages,
|
||||
'defaultFormLanguage' => $this->default_form_language,
|
||||
'allowEmployeeFormLang' => $this->allow_employee_form_lang,
|
||||
'form_id' => $this->id,
|
||||
'fields' => $this->fields_form,
|
||||
'fields_value' => $this->fields_value,
|
||||
'required_fields' => $this->getFieldsRequired(),
|
||||
'vat_number' => file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php'),
|
||||
'module_dir' => _MODULE_DIR_,
|
||||
'contains_states' => (isset($this->fields_value['id_country']) && isset($this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null,
|
||||
'asso_shop' => isset($asso_shop) ? $asso_shop : null
|
||||
));
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there are required fields
|
||||
*/
|
||||
public function getFieldsRequired()
|
||||
{
|
||||
foreach ($this->fields_form as $fieldset)
|
||||
if (isset($fieldset['form']['input']))
|
||||
foreach ($fieldset['form']['input'] as $input)
|
||||
if (array_key_exists('required', $input) && $input['required'])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,641 @@
|
||||
<?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$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class HelperListCore extends Helper
|
||||
{
|
||||
/** @var array Cache for query results */
|
||||
protected $_list = array();
|
||||
|
||||
/** @var integer Number of results in list */
|
||||
public $listTotal = 0;
|
||||
|
||||
/** @var array WHERE clause determined by filter fields */
|
||||
protected $_filter;
|
||||
|
||||
/** @var array Temporary SQL table WHERE clause determinated by filter fields */
|
||||
protected $_tmpTableFilter = '';
|
||||
|
||||
/** @var array Number of results in list per page (used in select field) */
|
||||
protected $_pagination = array(20, 50, 100, 300);
|
||||
|
||||
/** @var string ORDER BY clause determined by field/arrows in list header */
|
||||
public $orderBy;
|
||||
|
||||
/** @var string Default ORDER BY clause when $orderBy is not defined */
|
||||
public $_defaultOrderBy = false;
|
||||
|
||||
/** @var array : list of vars for button delete*/
|
||||
public $tpl_delete_link_vars = array();
|
||||
|
||||
/** @var string Order way (ASC, DESC) determined by arrows in list header */
|
||||
public $orderWay;
|
||||
|
||||
public $identifier;
|
||||
|
||||
protected $deleted = 0;
|
||||
|
||||
/** @var array $cache_lang use to cache texts in current language */
|
||||
public static $cache_lang = array();
|
||||
|
||||
protected $is_cms = false;
|
||||
|
||||
protected $is_dnd_identifier = false;
|
||||
|
||||
/* Customize list display
|
||||
*
|
||||
* align : determine value alignment
|
||||
* prefix : displayed before value
|
||||
* suffix : displayed after value
|
||||
* image : object image
|
||||
* icon : icon determined by values
|
||||
* active : allow to toggle status
|
||||
*/
|
||||
protected $fieldsDisplay;
|
||||
|
||||
/** @var boolean Content line is clickable if true */
|
||||
public $no_link = false;
|
||||
|
||||
protected $header_tpl = 'list_header.tpl';
|
||||
protected $content_tpl = 'list_content.tpl';
|
||||
protected $footer_tpl = 'list_footer.tpl';
|
||||
|
||||
/** @var array list of required actions for each list row */
|
||||
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 $specificConfirmDelete;
|
||||
public $colorOnBackground;
|
||||
|
||||
protected $identifiersDnd = array(
|
||||
'id_product' => 'id_product',
|
||||
'id_category' => 'id_category_to_move',
|
||||
'id_cms_category' => 'id_cms_category_to_move',
|
||||
'id_cms' => 'id_cms',
|
||||
'id_attribute' => 'id_attribute',
|
||||
'id_attribute_group' => 'id_attribute_group',
|
||||
'id_carrier' => 'id_carrier',
|
||||
'id_tab' => 'id_tab',
|
||||
'id_feature' => 'id_feature'
|
||||
);
|
||||
|
||||
/** @var if not null, a title will be added on that list */
|
||||
public $title = null;
|
||||
|
||||
/** @var boolean ask for simple header : no filters, no paginations and no sorting */
|
||||
public $simple_header = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* Usage : Set the value to false if you want to simply display the back button
|
||||
*/
|
||||
public $no_back = true;
|
||||
|
||||
public $ajax_params = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->base_folder = 'helper/list/';
|
||||
$this->base_tpl = 'list.tpl';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an html list given the data to fill it up
|
||||
*
|
||||
* @param array $list entries to display (rows)
|
||||
* @param array $fieldsDisplay fields (cols)
|
||||
* @return string html
|
||||
*/
|
||||
public function generateList($list, $fields_display)
|
||||
{
|
||||
/*if ($this->edit AND (!isset($this->noAdd) OR !$this->noAdd))
|
||||
$this->displayAddButton();*/
|
||||
|
||||
/* Append when we get a syntax error in SQL query */
|
||||
if ($list === false)
|
||||
{
|
||||
$this->displayWarning($this->l('Bad SQL query'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->tpl = $this->createTemplate($this->base_tpl);
|
||||
$this->header_tpl = $this->createTemplate($this->header_tpl);
|
||||
$this->content_tpl = $this->createTemplate($this->content_tpl);
|
||||
$this->footer_tpl = $this->createTemplate($this->footer_tpl);
|
||||
|
||||
$this->_list = $list;
|
||||
$this->fieldsDisplay = $fields_display;
|
||||
/* Display list header (filtering, pagination and column names) */
|
||||
$tpl_vars['header'] = $this->displayListHeader();
|
||||
/* Show the content of the table */
|
||||
$tpl_vars['content'] = $this->displayListContent();
|
||||
/* Close list table and submit button */
|
||||
$tpl_vars['footer'] = $this->displayListFooter();
|
||||
|
||||
|
||||
$this->tpl->assign($tpl_vars);
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the template for action enable
|
||||
*
|
||||
* @param string $token
|
||||
* @param int $id
|
||||
* @param int $value state enabled or not
|
||||
* @param string $active status
|
||||
* @param int $id_category
|
||||
* @param int $id_product
|
||||
*/
|
||||
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
|
||||
{
|
||||
$tpl_enable = $this->createTemplate('list_action_enable.tpl');
|
||||
$tpl_enable->assign(array(
|
||||
'enabled' => (bool)$value,
|
||||
'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
|
||||
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token)
|
||||
));
|
||||
return $tpl_enable->fetch();
|
||||
}
|
||||
|
||||
public function displayListContent($token = null)
|
||||
{
|
||||
if ($this->is_dnd_identifier)
|
||||
$id_category = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category', '1');
|
||||
else
|
||||
$id_category = 1; // default categ
|
||||
|
||||
if (isset($this->fieldsDisplay['position']))
|
||||
{
|
||||
$positions = array_map(create_function('$elem', 'return (int)($elem[\'position\']);'), $this->_list);
|
||||
sort($positions);
|
||||
}
|
||||
|
||||
$identifier = in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : '';
|
||||
$key_to_get = 'id_'.($this->is_cms ? 'cms_' : '').'category'.$identifier;
|
||||
|
||||
$fields = array();
|
||||
|
||||
foreach ($this->_list as $index => $tr)
|
||||
{
|
||||
$id = $tr[$this->identifier];
|
||||
|
||||
if ($this->shopLinkType)
|
||||
$this->_list[$index]['short_shop_name'] = Tools::strlen($tr['shop_name']) > 15 ? Tools::substr($tr['shop_name'], 0, 15).'...' : $tr['shop_name'];
|
||||
|
||||
// Check all available actions to add to the current list row
|
||||
foreach ($this->actions as $action)
|
||||
{
|
||||
//Check if the action is available for the current row
|
||||
if (!array_key_exists($action, $this->list_skip_actions) || !in_array($id, $this->list_skip_actions[$action]))
|
||||
{
|
||||
$method_name = 'display'.ucfirst($action).'Link';
|
||||
|
||||
if (method_exists($this->context->controller, $method_name))
|
||||
$this->_list[$index][$action] = $this->context->controller->$method_name($token, $id);
|
||||
else if (method_exists($this, $method_name))
|
||||
$this->_list[$index][$action] = $this->$method_name($token, $id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// @todo skip action for bulk actions
|
||||
// $this->_list[$index]['has_bulk_actions'] = true;
|
||||
foreach ($this->fieldsDisplay as $key => $params)
|
||||
{
|
||||
$tmp = explode('!', $key);
|
||||
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
|
||||
|
||||
if (isset($params['active']))
|
||||
{
|
||||
// If method is defined in calling controller, use it instead of the Helper method
|
||||
if (method_exists($this->context->controller, 'displayEnableLink'))
|
||||
$calling_obj = $this->context->controller;
|
||||
else
|
||||
$calling_obj = $this;
|
||||
$this->_list[$index][$key] = $calling_obj->displayEnableLink(
|
||||
$this->token,
|
||||
$id,
|
||||
$tr[$key],
|
||||
$params['active'],
|
||||
Tools::getValue('id_category'),
|
||||
Tools::getValue('id_product')
|
||||
);
|
||||
}
|
||||
else if (isset($params['activeVisu']))
|
||||
$this->_list[$index][$key] = (bool)$tr[$key];
|
||||
else if (isset($params['position']))
|
||||
{
|
||||
$this->_list[$index][$key] = array(
|
||||
'position' => $tr[$key],
|
||||
'position_url_down' => $this->currentIndex.
|
||||
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
|
||||
'&way=1&position='.((int)$tr['position'] + 1).'&token='.$this->token,
|
||||
'position_url_up' => $this->currentIndex.
|
||||
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
|
||||
'&way=0&position='.((int)$tr['position'] - 1).'&token='.$this->token
|
||||
);
|
||||
}
|
||||
else if (isset($params['image']))
|
||||
{
|
||||
// item_id is the product id in a product image context, else it is the image id.
|
||||
$item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id;
|
||||
// If it's a product image
|
||||
if (isset($tr['id_image']))
|
||||
{
|
||||
$image = new Image((int)$tr['id_image']);
|
||||
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$image->getExistingImgPath().'.'.$this->imageType;
|
||||
}else
|
||||
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$item_id.(isset($tr['id_image']) ? '-'.(int)$tr['id_image'] : '').'.'.$this->imageType;
|
||||
|
||||
$this->_list[$index][$key] = cacheImage($path_to_image, $this->table.'_mini_'.$item_id.'.'.$this->imageType, 45, $this->imageType);
|
||||
}
|
||||
else if (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default'])))
|
||||
$this->_list[$index][$key] = isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'];
|
||||
else if (isset($params['float']))
|
||||
$this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.');
|
||||
else if (isset($params['type']) && $params['type'] == 'price')
|
||||
{
|
||||
$currency = isset($params['currency']) ? Currency::getCurrencyInstance($tr['id_currency']) : $this->context->currency;
|
||||
$this->_list[$index][$key] = Tools::displayPrice($tr[$key], $currency, false);
|
||||
}
|
||||
else if (isset($params['type']) && $params['type'] == 'date')
|
||||
$this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id);
|
||||
else if (isset($params['type']) && $params['type'] == 'datetime')
|
||||
$this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id, true);
|
||||
else if (isset($tr[$key]))
|
||||
{
|
||||
if ($key == 'price')
|
||||
$echo = round($tr[$key], 2);
|
||||
else if (isset($params['maxlength']) && Tools::strlen($tr[$key]) > $params['maxlength'])
|
||||
$echo = '<span title="'.$tr[$key].'">'.Tools::substr($tr[$key], 0, $params['maxlength']).'...</span>';
|
||||
else
|
||||
$echo = $tr[$key];
|
||||
|
||||
$this->_list[$index][$key] = isset($params['callback'])
|
||||
?
|
||||
call_user_func_array(array((isset($params['callback_object']))
|
||||
?
|
||||
$params['callback_object']
|
||||
:
|
||||
$this->context->controller, $params['callback']), array($echo, $tr))
|
||||
:
|
||||
$echo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->content_tpl->assign(array_merge($this->tpl_vars, array(
|
||||
'shop_link_type' => $this->shopLinkType,
|
||||
'name' => isset($name) ? $name : null,
|
||||
'is_dnd_identifier' => $this->is_dnd_identifier,
|
||||
'identifier' => $this->identifier,
|
||||
'table' => $this->table,
|
||||
'token' => $this->token,
|
||||
'color_on_bg' => $this->colorOnBackground,
|
||||
'id_category' => $id_category,
|
||||
'bulk_actions' => $this->bulk_actions,
|
||||
'key_to_get' => $key_to_get,
|
||||
'positions' => isset($positions) ? $positions : null,
|
||||
'order_by' => $this->orderBy,
|
||||
'order_way' => $this->orderWay,
|
||||
'is_cms' => $this->is_cms,
|
||||
'fields_display' => $this->fieldsDisplay,
|
||||
'list' => $this->_list,
|
||||
'actions' => $this->actions,
|
||||
'no_link' => $this->no_link,
|
||||
'current_index' => $this->currentIndex,
|
||||
'view' => in_array('view', $this->actions),
|
||||
'edit' => in_array('edit', $this->actions),
|
||||
'has_actions' => !empty($this->actions),
|
||||
'has_bulk_actions' => !empty($this->bulk_actions),
|
||||
'list_skip_actions' => $this->list_skip_actions,
|
||||
)));
|
||||
return $this->content_tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display duplicate action link
|
||||
*/
|
||||
protected function displayDuplicateLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->createTemplate('list_action_duplicate.tpl');
|
||||
if (!array_key_exists('Duplicate', self::$cache_lang))
|
||||
self::$cache_lang['Duplicate'] = $this->l('Duplicate');
|
||||
|
||||
if (!array_key_exists('Copy images too?', self::$cache_lang))
|
||||
self::$cache_lang['Copy images too?'] = $this->l('Copy images too?', __CLASS__, true, false);
|
||||
|
||||
$duplicate = $this->currentIndex.'&'.$this->identifier.'='.$id.'&duplicate'.$this->table;
|
||||
|
||||
$tpl->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&view'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['Duplicate'],
|
||||
'confirm' => self::$cache_lang['Copy images too?'],
|
||||
'location_ok' => $duplicate.'&token='.($token != null ? $token : $this->token),
|
||||
'location_ko' => $duplicate.'&noimage=1&token='.($token ? $token : $this->token),
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display action show details of a table row
|
||||
* This action need an ajax request with a return like this:
|
||||
* {
|
||||
* use_parent_structure: true // If false, data need to be an html
|
||||
* data:
|
||||
* [
|
||||
* {field_name: 'value'}
|
||||
* ],
|
||||
* fields_display: // attribute $fieldsDisplay of the admin controller
|
||||
* }
|
||||
* or somethins like this:
|
||||
* {
|
||||
* use_parent_structure: false // If false, data need to be an html
|
||||
* data:
|
||||
* '<p>My html content</p>',
|
||||
* fields_display: // attribute $fieldsDisplay of the admin controller
|
||||
* }
|
||||
*/
|
||||
protected function displayDetailsLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->createTemplate('list_action_details.tpl');
|
||||
if (!array_key_exists('Details', self::$cache_lang))
|
||||
self::$cache_lang['Details'] = $this->l('Details');
|
||||
$tpl->assign(array(
|
||||
'id' => $id,
|
||||
'controller' => str_replace('Controller', '', get_class($this->context->controller)),
|
||||
'token' => $token != null ? $token : $this->token,
|
||||
'action' => self::$cache_lang['Details'],
|
||||
'params' => $this->ajax_params
|
||||
));
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display view action link
|
||||
*/
|
||||
protected function displayViewLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->createTemplate('list_action_view.tpl');
|
||||
if (!array_key_exists('View', self::$cache_lang))
|
||||
self::$cache_lang['View'] = $this->l('View');
|
||||
|
||||
$tpl->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&view'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['View'],
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display edit action link
|
||||
*/
|
||||
protected function displayEditLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->createTemplate('list_action_edit.tpl');
|
||||
if (!array_key_exists('Edit', self::$cache_lang))
|
||||
self::$cache_lang['Edit'] = $this->l('Edit');
|
||||
|
||||
$tpl->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['Edit'],
|
||||
'id' => $id
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display delete action link
|
||||
*/
|
||||
protected function displayDeleteLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->createTemplate('list_action_delete.tpl');
|
||||
if (!array_key_exists('Delete', self::$cache_lang))
|
||||
self::$cache_lang['Delete'] = $this->l('Delete');
|
||||
|
||||
if (!array_key_exists('DeleteItem', self::$cache_lang))
|
||||
self::$cache_lang['DeleteItem'] = $this->l('Delete item #', __CLASS__, true, false);
|
||||
|
||||
$tpl->assign(array_merge($this->tpl_delete_link_vars, array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'confirm' => (!is_null($this->specificConfirmDelete) ? '\r'.$this->specificConfirmDelete : self::$cache_lang['DeleteItem'].$id.' ? '),
|
||||
'action' => self::$cache_lang['Delete'],
|
||||
'id' => $id,
|
||||
)));
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display delete action link
|
||||
*/
|
||||
protected function displayDefaultLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->createTemplate('list_action_default.tpl');
|
||||
if (!array_key_exists('Default', self::$cache_lang))
|
||||
self::$cache_lang['Default'] = $this->l('Default');
|
||||
|
||||
$tpl->assign(array_merge($this->tpl_delete_link_vars, array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['Default'],
|
||||
'id' => $id,
|
||||
)));
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display list header (filtering, pagination and column names)
|
||||
*/
|
||||
public function displayListHeader($token = null)
|
||||
{
|
||||
$id_cat = Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category');
|
||||
|
||||
if (!isset($token) || empty($token))
|
||||
$token = $this->token;
|
||||
|
||||
/* Determine total page number */
|
||||
if (isset($this->context->cookie->{$this->table.'_pagination'}) && $this->context->cookie->{$this->table.'_pagination'})
|
||||
$default_pagination = $this->context->cookie->{$this->table.'_pagination'};
|
||||
else
|
||||
$default_pagination = $this->_pagination[0];
|
||||
|
||||
$total_pages = ceil($this->listTotal / Tools::getValue('pagination', ($default_pagination)));
|
||||
|
||||
if (!$total_pages) $total_pages = 1;
|
||||
|
||||
$identifier = Tools::getIsset($this->identifier) ? '&'.$this->identifier.'='.(int)Tools::getValue($this->identifier) : '';
|
||||
$order = '';
|
||||
if (Tools::getIsset($this->table.'Orderby'))
|
||||
$order = '&'.$this->table.'Orderby='.urlencode($this->orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->orderWay));
|
||||
|
||||
$action = $this->currentIndex.$identifier.'&token='.$token.$order.'#'.$this->table;
|
||||
|
||||
/* Determine current page number */
|
||||
$page = (int)Tools::getValue('submitFilter'.$this->table);
|
||||
if (!$page) $page = 1;
|
||||
|
||||
/* Choose number of results per page */
|
||||
$selected_pagination = Tools::getValue(
|
||||
'pagination',
|
||||
isset($this->context->cookie->{$this->table.'_pagination'}) ? $this->context->cookie->{$this->table.'_pagination'} : null
|
||||
);
|
||||
|
||||
$this->is_dnd_identifier = array_key_exists($this->identifier, $this->identifiersDnd);
|
||||
/*
|
||||
if ($is_dnd_identifier)
|
||||
{
|
||||
' id="'.
|
||||
if(((int)(Tools::getValue($this->identifiersDnd[$this->identifier], 1)))
|
||||
substr($this->identifier,3,strlen($this->identifier)))
|
||||
}
|
||||
.' class="table'.(
|
||||
if ($is_dnd_identifier AND ($this->orderBy != 'position 'AND $this->orderWay != 'DESC'))
|
||||
' tableDnD'
|
||||
.'" cellpadding="0" cellspacing="0">*/
|
||||
|
||||
// Cleaning links
|
||||
if (Tools::getValue($this->table.'Orderby') && Tools::getValue($this->table.'Orderway'))
|
||||
$this->currentIndex = preg_replace('/&'.$this->table.'Orderby=([a-z _]*)&'.$this->table.'Orderway=([a-z]*)/i', '', $this->currentIndex);
|
||||
|
||||
if (array_key_exists($this->identifier, $this->identifiersDnd) && (int)Tools::getValue($this->identifiersDnd[$this->identifier], 1))
|
||||
$table_id = substr($this->identifier, 3, strlen($this->identifier));
|
||||
|
||||
if (array_key_exists($this->identifier, $this->identifiersDnd) && ($this->orderBy == 'position' && $this->orderWay != 'DESC'))
|
||||
$table_dnd = true;
|
||||
|
||||
foreach ($this->fieldsDisplay as $key => $params)
|
||||
{
|
||||
if (!isset($params['type']))
|
||||
$params['type'] = 'text';
|
||||
|
||||
$value = Tools::getValue($this->table.'Filter_'.(array_key_exists('filter_key', $params) ? $params['filter_key'] : $key));
|
||||
|
||||
switch ($params['type'])
|
||||
{
|
||||
case 'bool':
|
||||
break;
|
||||
case 'date':
|
||||
case 'datetime':
|
||||
if (is_string($value))
|
||||
$value = unserialize($value);
|
||||
if (!Validate::isCleanHtml($value[0]) || !Validate::isCleanHtml($value[1]))
|
||||
$value = '';
|
||||
$name = $this->table.'Filter_'.(isset($params['filter_key']) ? $params['filter_key'] : $key);
|
||||
$name_id = str_replace('!', '__', $name);
|
||||
$this->context->controller->addJqueryUI('ui.datepicker');
|
||||
break;
|
||||
case 'select':
|
||||
foreach ($params['list'] as $option_value => $option_display)
|
||||
{
|
||||
if (isset($_POST[$this->table.'Filter_'.$params['filter_key']])
|
||||
&& Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $option_value
|
||||
&& Tools::getValue($this->table.'Filter_'.$params['filter_key']) != '')
|
||||
$this->fieldsDisplay[$key]['select'][$option_value]['selected'] = 'selected';
|
||||
}
|
||||
break;
|
||||
case 'text':
|
||||
if (!Validate::isCleanHtml($value))
|
||||
$value = '';
|
||||
}
|
||||
$params['value'] = $value;
|
||||
$this->fieldsDisplay[$key] = $params;
|
||||
}
|
||||
|
||||
$this->header_tpl->assign(array_merge($this->tpl_vars, array(
|
||||
'title' => $this->title,
|
||||
'show_toolbar' => $this->show_toolbar,
|
||||
'toolbar_fix' => $this->toolbar_fix,
|
||||
'toolbar_btn' => $this->toolbar_btn,
|
||||
|
||||
'ps_help_context' => $this->ps_help_context,
|
||||
'class_name' => get_class($this->context->controller),
|
||||
'iso_user' => $this->context->language->id,
|
||||
'country_iso_code' => $this->context->country->iso_code,
|
||||
'version' => _PS_VERSION_,
|
||||
|
||||
'table' => $this->table,
|
||||
'currentIndex' => $this->currentIndex,
|
||||
'action' => $action,
|
||||
'page' => $page,
|
||||
'simple_header' => $this->simple_header,
|
||||
'total_pages' => $total_pages,
|
||||
'selected_pagination' => $selected_pagination,
|
||||
'pagination' => $this->_pagination,
|
||||
'list_total' => $this->listTotal,
|
||||
'is_order_position' => array_key_exists($this->identifier, $this->identifiersDnd) && $this->orderBy == 'position',
|
||||
'order_way' => $this->orderWay,
|
||||
'order_by' => $this->orderBy,
|
||||
'token' => $this->token,
|
||||
'fields_display' => $this->fieldsDisplay,
|
||||
'delete' => in_array('delete', $this->actions),
|
||||
'identifier' => $this->identifier,
|
||||
'id_cat' => $id_cat,
|
||||
'shop_link_type' => $this->shopLinkType,
|
||||
'has_actions' => !empty($this->actions),
|
||||
'has_bulk_actions' => !empty($this->bulk_actions),
|
||||
'bulk_actions' => $this->bulk_actions,
|
||||
'table_id' => isset($table_id) ? $table_id : null,
|
||||
'table_dnd' => isset($table_dnd) ? $table_dnd : null,
|
||||
'name' => isset($name) ? $name : null,
|
||||
'name_id' => isset($name_id) ? $name_id : null,
|
||||
/*'back' => Tools::getValue('back'),
|
||||
'no_back' => $this->no_back,*/
|
||||
)));
|
||||
|
||||
return $this->header_tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close list table and submit button
|
||||
*/
|
||||
public function displayListFooter($token = null)
|
||||
{
|
||||
$this->footer_tpl->assign(array_merge($this->tpl_vars, array(
|
||||
'token' => $this->token,
|
||||
'table' => $this->table,
|
||||
'current' => $this->currentIndex,
|
||||
'simple_header' => $this->simple_header,
|
||||
'bulk_actions' => $this->bulk_actions,
|
||||
'back' => Tools::getValue('back'),
|
||||
'no_back' => $this->no_back,
|
||||
)));
|
||||
return $this->footer_tpl->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
<?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$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Use this helper to generate preferences forms, with values stored in the configuration table
|
||||
*/
|
||||
class HelperOptionsCore extends Helper
|
||||
{
|
||||
public $required = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->base_folder = 'helper/options/';
|
||||
$this->base_tpl = 'options.tpl';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a form for options
|
||||
* @param array options
|
||||
* @return string html
|
||||
*/
|
||||
public function generateOptions($option_list)
|
||||
{
|
||||
$this->tpl = $this->createTemplate($this->base_tpl);
|
||||
$tab = Tab::getTab($this->context->language->id, $this->id);
|
||||
if (!isset($languages))
|
||||
$languages = Language::getLanguages(false);
|
||||
|
||||
foreach ($option_list as $category => $category_data)
|
||||
{
|
||||
if(!is_array($category_data))
|
||||
continue;
|
||||
|
||||
if (!isset($category_data['image']))
|
||||
$category_data['image'] = (!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif';
|
||||
|
||||
if (!isset($category_data['fields']))
|
||||
$category_data['fields'] = array();
|
||||
|
||||
foreach ($category_data['fields'] as $key => $field)
|
||||
{
|
||||
// Set field value
|
||||
$field['value'] = $this->getOptionValue($key, $field);
|
||||
|
||||
// Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop)
|
||||
$isDisabled = $isInvisible = false;
|
||||
if (Shop::isFeatureActive())
|
||||
{
|
||||
if (isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType())
|
||||
{
|
||||
$isDisabled = true;
|
||||
$isInvisible = true;
|
||||
}
|
||||
else if (Context::shop() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key))
|
||||
$isDisabled = true;
|
||||
}
|
||||
$field['is_disabled'] = $isDisabled;
|
||||
$field['is_invisible'] = $isInvisible;
|
||||
|
||||
$field['required'] = isset($field['required']) ? $field['required'] : $this->required;
|
||||
|
||||
// Cast options values if specified
|
||||
if ($field['type'] == 'select' && isset($field['cast']))
|
||||
foreach ($field['list'] as $option_key => $option)
|
||||
$field['list'][$option_key][$field['identifier']] = $field['cast']($option[$field['identifier']]);
|
||||
|
||||
// Fill values for all languages for all lang fields
|
||||
if (substr($field['type'], -4) == 'Lang')
|
||||
{
|
||||
|
||||
foreach ($languages as $language)
|
||||
{
|
||||
if ($field['type'] == 'textLang')
|
||||
$value = Tools::safeOutput(Tools::getValue($key.'_'.$language['id_lang'], Configuration::get($key, $language['id_lang'])));
|
||||
elseif ($field['type'] == 'textareaLang')
|
||||
$value = Configuration::get($key, $language['id_lang']);
|
||||
elseif ($field['type'] == 'selectLang')
|
||||
$value = Configuration::get($key, $language['id_lang']);
|
||||
$field['languages'][$language['id_lang']] = $value;
|
||||
$field['value'][$language['id_lang']] = $this->getOptionValue($key.'_'.strtoupper($language['iso_code']), $field);
|
||||
}
|
||||
}
|
||||
|
||||
// pre-assign vars to the tpl
|
||||
if ($field['type'] == 'maintenance_ip')
|
||||
{
|
||||
$field['script_ip'] = '
|
||||
<script type="text/javascript">
|
||||
function addRemoteAddr()
|
||||
{
|
||||
var length = $(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\').length;
|
||||
if (length > 0)
|
||||
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\') +\','.Tools::getRemoteAddr().'\');
|
||||
else
|
||||
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',\''.Tools::getRemoteAddr().'\');
|
||||
}
|
||||
</script>';
|
||||
$field['link_remove_ip'] = '  <a href="#" class="button" onclick="addRemoteAddr(); return false;">'.$this->l('Add my IP').'</a>';
|
||||
if (!isset($category_data['bottom']))
|
||||
$category_data['bottom'] = '<script type="text/javascript">changeCMSActivationAuthorization();</script>';
|
||||
}
|
||||
|
||||
// Multishop default value
|
||||
$field['multishop_default'] = (Shop::isFeatureActive() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible);
|
||||
|
||||
// Assign the modifications back to parent array
|
||||
$category_data['fields'][$key] = $field;
|
||||
|
||||
// Is at least one required field present?
|
||||
if (isset($field['required']) && $field['required'])
|
||||
$required_fields = true;
|
||||
|
||||
}
|
||||
// Assign the modifications back to parent array
|
||||
$option_list[$category] = $category_data;
|
||||
}
|
||||
|
||||
$this->tpl->assign(array(
|
||||
'title' => $this->title,
|
||||
'toolbar_btn' => $this->toolbar_btn,
|
||||
'show_toolbar' => $this->show_toolbar,
|
||||
'toolbar_fix' => $this->toolbar_fix,
|
||||
'current' => $this->currentIndex,
|
||||
'table' => $this->table,
|
||||
'token' => $this->token,
|
||||
'option_list' => $option_list,
|
||||
'current_id_lang' => $this->context->language->id,
|
||||
'required_fields' => isset($required_fields) ? $required_fields : false,
|
||||
'languages' => isset($languages) ? $languages : null,
|
||||
'currency_left_sign' => $this->context->currency->getSign('left'),
|
||||
'currency_right_sign' => $this->context->currency->getSign('right'),
|
||||
));
|
||||
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type = image
|
||||
* @ TODO
|
||||
*/
|
||||
public function displayOptionTypeImage($key, $field, $value)
|
||||
{
|
||||
echo '<table cellspacing="0" cellpadding="0">';
|
||||
echo '<tr>';
|
||||
|
||||
$i = 0;
|
||||
foreach ($field['list'] as $theme)
|
||||
{
|
||||
echo '<td class="center" style="width: 180px; padding:0px 20px 20px 0px;">';
|
||||
echo '<input type="radio" name="'.$key.'" id="'.$key.'_'.$theme['name'].'_on" style="vertical-align: text-bottom;" value="'.$theme['name'].'"'.(_THEME_NAME_ == $theme['name'] ? 'checked="checked"' : '').' />';
|
||||
echo '<label class="t" for="'.$key.'_'.$theme['name'].'_on"> '.Tools::strtolower($theme['name']).'</label>';
|
||||
echo '<br />';
|
||||
echo '<label class="t" for="'.$key.'_'.$theme['name'].'_on">';
|
||||
echo '<img src="../themes/'.$theme['name'].'/preview.jpg" alt="'.Tools::strtolower($theme['name']).'">';
|
||||
echo '</label>';
|
||||
echo '</td>';
|
||||
if (isset($field['max']) && ($i +1 ) % $field['max'] == 0)
|
||||
echo '</tr><tr>';
|
||||
$i++;
|
||||
}
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Type = price
|
||||
* @ TODO
|
||||
*/
|
||||
public function displayOptionTypePrice($key, $field, $value)
|
||||
{
|
||||
echo $this->context->currency->getSign('left');
|
||||
$this->displayOptionTypeText($key, $field, $value);
|
||||
echo $this->context->currency->getSign('right').' '.$this->l('(tax excl.)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Type = disabled
|
||||
*
|
||||
* @ TODO
|
||||
*/
|
||||
public function displayOptionTypeDisabled($key, $field, $value)
|
||||
{
|
||||
echo $field['disabled'];
|
||||
}
|
||||
|
||||
public function getOptionValue($key, $field)
|
||||
{
|
||||
$value = Tools::getValue($key, Configuration::get($key));
|
||||
if (!Validate::isCleanHtml($value))
|
||||
$value = Configuration::get($key);
|
||||
|
||||
if (isset($field['defaultValue']) && !$value)
|
||||
$value = $field['defaultValue'];
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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: 9194 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class HelperViewCore extends Helper
|
||||
{
|
||||
public $id;
|
||||
public $toolbar = true;
|
||||
public $table;
|
||||
public $token;
|
||||
|
||||
/** @var if not null, a title will be added on that list */
|
||||
public $title = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->base_folder = 'helper/view/';
|
||||
$this->base_tpl = 'view.tpl';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function generateView()
|
||||
{
|
||||
$this->tpl = $this->createTemplate($this->base_tpl);
|
||||
|
||||
$this->tpl->assign(array(
|
||||
'title' => $this->title,
|
||||
'current' => $this->currentIndex,
|
||||
'title' => $this->title,
|
||||
'token' => $this->token,
|
||||
'table' => $this->table,
|
||||
'show_toolbar' => $this->show_toolbar,
|
||||
'toolbar_fix' => $this->toolbar_fix,
|
||||
'toolbar_btn' => $this->toolbar_btn,
|
||||
'link' => $this->context->link
|
||||
));
|
||||
|
||||
return parent::generate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user