* @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 $token; public $context; public function __construct() { $this->context = Context::getContext(); } /** * * @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) { if (!$use_radio) $input_name = $input_name.'[]'; $html = ' '. ($use_search ? '' : '' ).' '; $html .= '
'.$trads['Collapse All'].' - '.$trads['Expand All'].' '.(!$use_radio ? ' - '.$trads['Check All'].' - '.$trads['Uncheck All'].' ' : '').($use_search ? ''.$trads['search'].' :
' : '').'
'; $home_is_selected = false; foreach($selected_cat AS $cat) { if (is_array($cat)) { if ($cat['id_category'] != 1) $html .= ''; else $home_is_selected = true; } else { if ($cat != 1) $html .= ''; else $home_is_selected = true; } } $html .= ' '; 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 = ''; 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))); } /** * Display flags in forms for translations * * @param array $languages All languages available * @param integer $default_language Default language id * @param string $ids Multilingual div ids in form * @param string $id Current div id] * @param boolean $return define the return way : false for a display, true for a return * @param boolean $use_vars_instead_of_ids use an js vars instead of ids seperate by "ยค" */ public function displayFlags($languages, $default_language, $ids, $id, $return = false, $use_vars_instead_of_ids = false) { if (count($languages) == 1) return false; $output = '
'.$this->l('Choose language:').'

'; foreach ($languages as $language) if($use_vars_instead_of_ids) $output .= ''.$language['name'].' '; else $output .= ''.$language['name'].' '; $output .= '
'; if ($return) return $output; echo $output; } }