Beispiel #1
0
/**
 * Toolbar bar for admin panel
 * @category admin
 *
 * @author PrestaShop <*****@*****.**>
 * @copyright PrestaShop
 * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
 * @version 1.2
 *
 */
function recursiveTab($id_tab)
{
    global $cookie, $tabs;
    $adminTab = Tab::getTab(intval($cookie->id_lang), $id_tab);
    $tabs[] = $adminTab;
    if ($adminTab['id_parent'] > 0) {
        recursiveTab($adminTab['id_parent']);
    }
}
Beispiel #2
0
    /**
     * Options lists
     */
    public function displayOptionsList()
    {
        global $currentIndex, $cookie, $tab;
        if (!isset($this->_fieldsOptions) or !sizeof($this->_fieldsOptions)) {
            return false;
        }
        $defaultLanguage = (int) Configuration::get('PS_LANG_DEFAULT');
        $this->_languages = Language::getLanguages(false);
        $tab = Tab::getTab((int) $cookie->id_lang, Tab::getIdFromClassName($tab));
        echo '<br /><br />';
        echo isset($this->optionTitle) ? '<h2>' . $this->optionTitle . '</h2>' : '';
        echo '
		<script type="text/javascript">
			id_language = Number(' . $defaultLanguage . ');
		</script>
		<form action="' . $currentIndex . '" id="' . $tab['name'] . '" name="' . $tab['name'] . '" method="post">
			<fieldset>';
        echo isset($this->optionTitle) ? '<legend>
					<img src="' . (!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" />' . $this->optionTitle . '</legend>' : '';
        foreach ($this->_fieldsOptions as $key => $field) {
            $val = Tools::getValue($key, Configuration::get($key));
            if ($field['type'] != 'textLang') {
                if (!Validate::isCleanHtml($val)) {
                    $val = Configuration::get($key);
                }
            }
            echo '<label>' . $field['title'] . ' </label>
			<div class="margin-form">';
            switch ($field['type']) {
                case 'select':
                    echo '<select name="' . $key . '">';
                    foreach ($field['list'] as $value) {
                        echo '<option
							value="' . (isset($field['cast']) ? $field['cast']($value[$field['identifier']]) : $value[$field['identifier']]) . '"' . ($val == $value[$field['identifier']] ? ' selected="selected"' : '') . '>' . $value['name'] . '</option>';
                    }
                    echo '</select>';
                    break;
                case 'bool':
                    echo '<label class="t" for="' . $key . '_on"><img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /></label>
					<input type="radio" name="' . $key . '" id="' . $key . '_on" value="1"' . ($val ? ' checked="checked"' : '') . ' />
					<label class="t" for="' . $key . '_on"> ' . $this->l('Yes') . '</label>
					<label class="t" for="' . $key . '_off"><img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /></label>
					<input type="radio" name="' . $key . '" id="' . $key . '_off" value="0" ' . (!$val ? 'checked="checked"' : '') . '/>
					<label class="t" for="' . $key . '_off"> ' . $this->l('No') . '</label>';
                    break;
                case 'textLang':
                    foreach ($this->_languages as $language) {
                        $val = Tools::getValue($key . '_' . $language['id_lang'], Configuration::get($key, $language['id_lang']));
                        if (!Validate::isCleanHtml($val)) {
                            $val = Configuration::get($key);
                        }
                        echo '
						<div id="' . $key . '_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
							<input size="' . $field['size'] . '" type="text" name="' . $key . '_' . $language['id_lang'] . '" value="' . $val . '" />
						</div>';
                    }
                    $this->displayFlags($this->_languages, $defaultLanguage, $key, $key);
                    echo '<br style="clear:both">';
                    break;
                case 'textareaLang':
                    foreach ($this->_languages as $language) {
                        $val = Configuration::get($key, $language['id_lang']);
                        echo '
						<div id="' . $key . '_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
							<textarea rows="' . (int) $field['rows'] . '" cols="' . (int) $field['cols'] . '"  name="' . $key . '_' . $language['id_lang'] . '">' . str_replace('\\r\\n', "\n", $val) . '</textarea>
						</div>';
                    }
                    $this->displayFlags($this->_languages, $defaultLanguage, $key, $key);
                    echo '<br style="clear:both">';
                    break;
                case 'text':
                default:
                    echo '<input type="text" name="' . $key . '" value="' . $val . '" size="' . $field['size'] . '" />' . (isset($field['suffix']) ? $field['suffix'] : '');
            }
            if (isset($field['required']) and $field['required']) {
                echo ' <sup>*</sup>';
            }
            echo isset($field['desc']) ? '<p>' . $field['desc'] . '</p>' : '';
            echo '</div>';
        }
        echo '<div class="margin-form">
					<input type="submit" value="' . $this->l('   Save   ') . '" name="submitOptions' . $this->table . '" class="button" />
				</div>
			</fieldset>
			<input type="hidden" name="token" value="' . $this->token . '" />
		</form>';
    }
Beispiel #3
0
 public static function recursiveTab($id_tab, $tabs)
 {
     $admin_tab = Tab::getTab((int) Context::getContext()->language->id, $id_tab);
     $tabs[] = $admin_tab;
     if ($admin_tab['id_parent'] > 0) {
         $tabs = Tab::recursiveTab($admin_tab['id_parent'], $tabs);
     }
     return $tabs;
 }
Beispiel #4
0
    /**
     * Options lists
     */
    public function displayOptionsList()
    {
        $tab = Tab::getTab($this->context->language->id, $this->id);
        // Retrocompatibility < 1.5.0
        if (!$this->optionsList && $this->_fieldsOptions) {
            $this->optionsList = array('options' => array('title' => $this->optionTitle ? $this->optionTitle : $this->l('Options'), 'fields' => $this->_fieldsOptions));
        }
        if (!$this->optionsList) {
            return;
        }
        echo '<br />';
        echo '<script type="text/javascript">
			id_language = Number(' . $this->context->language->id . ');
		</script>';
        $action = Tools::safeOutput(self::$currentIndex . '&submitOptions' . $this->table . '=1&token=' . $this->token);
        echo '<form action="' . $action . '" method="post" enctype="multipart/form-data">';
        foreach ($this->optionsList as $category => $categoryData) {
            $required = false;
            $this->displayTopOptionCategory($category, $categoryData);
            echo '<fieldset>';
            // Options category title
            $legend = '<img src="' . (!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" /> ';
            $legend .= isset($categoryData['title']) ? $categoryData['title'] : $this->l('Options');
            echo '<legend>' . $legend . '</legend>';
            // Category fields
            if (!isset($categoryData['fields'])) {
                continue;
            }
            // Category description
            if (isset($categoryData['description']) && $categoryData['description']) {
                echo '<p class="optionsDescription">' . $categoryData['description'] . '</p>';
            }
            foreach ($categoryData['fields'] as $key => $field) {
                // Field value
                $value = Tools::getValue($key, Configuration::get($key));
                if (!Validate::isCleanHtml($value)) {
                    $value = Configuration::get($key);
                }
                if (isset($field['defaultValue']) && !$value) {
                    $value = $field['defaultValue'];
                }
                // 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'] > Shop::getContext()) {
                        $isDisabled = true;
                        $isInvisible = true;
                    } elseif (Shop::getContext() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key)) {
                        $isDisabled = true;
                    }
                }
                // Display title
                echo '<div style="clear: both; padding-top:15px;" id="conf_id_' . $key . '" ' . ($isInvisible ? 'class="isInvisible"' : '') . '>';
                if ($field['title']) {
                    echo '<label class="conf_title">';
                    // Is this field required ?
                    if (isset($field['required']) && $field['required']) {
                        $required = true;
                        echo '<sup>*</sup> ';
                    }
                    echo $field['title'] . '</label>';
                }
                echo '<div class="margin-form" style="padding-top:5px;">';
                // Display option inputs
                $method = 'displayOptionType' . Tools::toCamelCase($field['type'], true);
                if (!method_exists($this, $method)) {
                    $this->displayOptionTypeText($key, $field, $value);
                } else {
                    $this->{$method}($key, $field, $value);
                }
                // Multishop default value
                if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && !$isInvisible) {
                    echo '<div class="preference_default_multishop">
							<label>
								<input type="checkbox" name="multishopOverrideOption[' . $key . ']" value="1" ' . ($isDisabled ? 'checked="checked"' : '') . ' onclick="checkMultishopDefaultValue(this, \'' . $key . '\')" /> ' . $this->l('Use default value') . '
							</label>
						</div>';
                }
                // Field description
                //echo (isset($field['desc']) ? '<p class="preference_description">'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" style="float:left;" />' : '' ).$field['desc'].'</p>' : '');
                echo isset($field['desc']) ? '<p class="preference_description">' . $field['desc'] . '</p>' : '';
                // Is this field invisible in current shop context ?
                echo $isInvisible ? '<p class="multishop_warning">' . $this->l('You cannot change the value of this configuration field in this shop context') . '</p>' : '';
                echo '</div></div>';
            }
            echo '<div align="center" style="margin-top: 20px;">';
            echo '<input type="submit" value="' . $this->l('   Save   ') . '" name="submit' . ucfirst($category) . $this->table . '" class="button" />';
            echo '</div>';
            if ($required) {
                echo '<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div>';
            }
            echo '</fieldset><br />';
            $this->displayBottomOptionCategory($category, $categoryData);
        }
        echo '</form>';
    }
Beispiel #5
0
    /**
     * Options lists
     */
    public function displayOptionsList()
    {
        global $currentIndex, $cookie, $tab;
        if (!isset($this->_fieldsOptions) or !sizeof($this->_fieldsOptions)) {
            return;
        }
        $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
        $languages = Language::getLanguages();
        $tab = Tab::getTab(intval($cookie->id_lang), Tab::getIdFromClassName($tab));
        echo '<br /><br />';
        echo isset($this->optionTitle) ? '<h2>' . $this->optionTitle . '</h2>' : '';
        echo '
		<script type="text/javascript">
			id_language = Number(' . $defaultLanguage . ');
		</script>
		<form action="' . $currentIndex . '" id="' . $tab['name'] . '" name="' . $tab['name'] . '" method="post" class="width3">
			<fieldset>';
        echo isset($this->optionTitle) ? '<legend><img src="../img/t/' . $tab['class_name'] . '.gif" />' . $this->optionTitle . '</legend>' : '';
        foreach ($this->_fieldsOptions as $key => $field) {
            $val = Tools::getValue($key, Configuration::get($key));
            echo '
				<label>' . $field['title'] . ' </label>
				<div class="margin-form">';
            switch ($field['type']) {
                case 'select':
                    echo '<select name="' . $key . '">';
                    foreach ($field['list'] as $value) {
                        echo '<option
							value="' . (isset($field['cast']) ? $field['cast']($value[$field['identifier']]) : $value[$field['identifier']]) . '"' . ($val == $value[$field['identifier']] ? ' selected="selected"' : '') . '>' . $value['name'] . '</option>';
                    }
                    echo '</select>';
                    break;
                case 'bool':
                    echo '<label class="t" for="' . $key . '_on"><img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /></label>
					<input type="radio" name="' . $key . '" id="' . $key . '_on" value="1"' . ($val ? ' checked="checked"' : '') . ' />
					<label class="t" for="' . $key . '_on"> ' . $this->l('Yes') . '</label>
					<label class="t" for="' . $key . '_off"><img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /></label>
					<input type="radio" name="' . $key . '" id="' . $key . '_off" value="0" ' . (!$val ? 'checked="checked"' : '') . '/>
					<label class="t" for="' . $key . '_off"> ' . $this->l('No') . '</label>';
                    break;
                case 'textLang':
                    foreach ($languages as $language) {
                        $val = Tools::getValue($key . '_' . $language['id_lang'], Configuration::get($key, $language['id_lang']));
                        echo '
						<div id="' . $key . '_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
							<input size="' . $field['size'] . '" type="text" name="' . $key . '_' . $language['id_lang'] . '" value="' . $val . '" />
						</div>';
                    }
                    $this->displayFlags($languages, $defaultLanguage, $key, $key);
                    echo '<br style="clear:both">';
                    break;
                case 'text':
                default:
                    echo '<input type="text" name="' . $key . '" value="' . $val . '" size="' . $field['size'] . '" />' . (isset($field['suffix']) ? $field['suffix'] : '');
            }
            echo isset($field['desc']) ? '<p>' . $field['desc'] . '</p>' : '';
            echo '</div>';
        }
        echo '<div class="margin-form">
					<input type="submit" value="' . $this->l('   Save   ') . '" name="submitOptions' . $this->table . '" class="button" />
				</div>
			</fieldset>
			<input type="hidden" name="token" value="' . $this->token . '" />
		</form>';
    }
Beispiel #6
0
    /**
     * Generate a form for options
     * @param array $option_list
     * @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);
        }
        $use_multishop = false;
        $hide_multishop_checkbox = Shop::getTotalShops(false, null) < 2 ? true : 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();
            }
            $category_data['hide_multishop_checkbox'] = true;
            if (isset($category_data['tabs'])) {
                $tabs[$category] = $category_data['tabs'];
                $tabs[$category]['misc'] = $this->l('Miscellaneous');
            }
            foreach ($category_data['fields'] as $key => $field) {
                if (empty($field['no_multishop_checkbox']) && !$hide_multishop_checkbox) {
                    $category_data['hide_multishop_checkbox'] = false;
                }
                // Set field value unless explicitly denied
                if (!isset($field['auto_value']) || $field['auto_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)
                $is_disabled = $is_invisible = false;
                if (Shop::isFeatureActive()) {
                    if (isset($field['visibility']) && $field['visibility'] > Shop::getContext()) {
                        $is_disabled = true;
                        $is_invisible = true;
                    } elseif (Shop::getContext() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key)) {
                        $is_disabled = true;
                    }
                }
                $field['is_disabled'] = $is_disabled;
                $field['is_invisible'] = $is_invisible;
                $field['required'] = isset($field['required']) ? $field['required'] : $this->required;
                if ($field['type'] == 'color') {
                    $this->context->controller->addJqueryPlugin('colorpicker');
                }
                if ($field['type'] == 'texarea' || $field['type'] == 'textareaLang') {
                    $this->context->controller->addJqueryPlugin('autosize');
                }
                if ($field['type'] == 'file') {
                    $uploader = new HelperUploader();
                    $uploader->setId(isset($field['id']) ? $field['id'] : null);
                    $uploader->setName($field['name']);
                    $uploader->setUrl(isset($field['url']) ? $field['url'] : null);
                    $uploader->setMultiple(isset($field['multiple']) ? $field['multiple'] : false);
                    $uploader->setUseAjax(isset($field['ajax']) ? $field['ajax'] : false);
                    $uploader->setMaxFiles(isset($field['max_files']) ? $field['max_files'] : null);
                    if (isset($field['files']) && $field['files']) {
                        $uploader->setFiles($field['files']);
                    } elseif (isset($field['image']) && $field['image']) {
                        // Use for retrocompatibility
                        $uploader->setFiles(array(0 => array('type' => HelperUploader::TYPE_IMAGE, 'image' => isset($field['image']) ? $field['image'] : null, 'size' => isset($field['size']) ? $field['size'] : null, 'delete_url' => isset($field['delete_url']) ? $field['delete_url'] : null)));
                    }
                    if (isset($field['file']) && $field['file']) {
                        // Use for retrocompatibility
                        $uploader->setFiles(array(0 => array('type' => HelperUploader::TYPE_FILE, 'size' => isset($field['size']) ? $field['size'] : null, 'delete_url' => isset($field['delete_url']) ? $field['delete_url'] : null, 'download_url' => isset($field['file']) ? $field['file'] : null)));
                    }
                    if (isset($field['thumb']) && $field['thumb']) {
                        // Use for retrocompatibility
                        $uploader->setFiles(array(0 => array('type' => HelperUploader::TYPE_IMAGE, 'image' => isset($field['thumb']) ? '<img src="' . $field['thumb'] . '" alt="' . $field['title'] . '" title="' . $field['title'] . '" />' : null)));
                    }
                    $uploader->setTitle(isset($field['title']) ? $field['title'] : null);
                    $field['file'] = $uploader->render();
                }
                // 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::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
                // @todo move this
                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'] = '<button type="button" class="btn btn-default" onclick="addRemoteAddr();"><i class="icon-plus"></i> ' . $this->l('Add my IP', 'Helper') . '</button>';
                }
                // Multishop default value
                $field['multishop_default'] = false;
                if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && !$is_invisible) {
                    $field['multishop_default'] = true;
                    $use_multishop = true;
                }
                // 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']) {
                    $category_data['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_scroll' => $this->toolbar_scroll, 'current' => $this->currentIndex, 'table' => $this->table, 'token' => $this->token, 'tabs' => isset($tabs) ? $tabs : null, 'option_list' => $option_list, 'current_id_lang' => $this->context->language->id, 'languages' => isset($languages) ? $languages : null, 'currency_left_sign' => $this->context->currency->getSign('left'), 'currency_right_sign' => $this->context->currency->getSign('right'), 'use_multishop' => $use_multishop));
        return parent::generate();
    }