public function ajaxProcessaddSliderImage()
 {
     if (isset($_FILES['file'])) {
         $image_uploader = new HelperUploader('file');
         if (!is_dir($this->img_path)) {
             if (!is_dir(_PS_ALL_THEMES_DIR_ . $this->themeName . '/img')) {
                 mkdir(_PS_ALL_THEMES_DIR_ . $this->themeName . '/img', 0755);
             }
             if (!is_dir(_PS_ALL_THEMES_DIR_ . $this->themeName . '/img/modules')) {
                 mkdir(_PS_ALL_THEMES_DIR_ . $this->themeName . '/img/modules', 0755);
             }
             mkdir(_PS_ALL_THEMES_DIR_ . $this->themeName . '/img/modules/leosliderlayer', 0755);
         }
         $image_uploader->setSavePath($this->img_path);
         $image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size);
         $files = $image_uploader->process();
         $total_errors = array();
         //			foreach ($files as $key => &$file)
         foreach ($files as &$file) {
             $errors = array();
             // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
             if (!ImageManager::checkImageMemoryLimit($file['save_path'])) {
                 $errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
             }
             if (count($errors)) {
                 $total_errors = array_merge($total_errors, $errors);
             }
             //unlink($file['save_path']);
             //Necesary to prevent hacking
             unset($file['save_path']);
             //Add image preview and delete url
         }
         if (count($total_errors)) {
             $this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors);
         }
         $images = $this->getImageList('date');
         $tpl = $this->createTemplate('imagemanager.tpl');
         $tpl->assign(array('images' => $images, 'reloadSliderImage' => 1, 'link' => Context::getContext()->link));
         die(Tools::jsonEncode($tpl->fetch()));
     }
 }
Example #2
0
 public function initFormAttachments($obj)
 {
     if (!$this->default_form_language) {
         $this->getLanguages();
     }
     $data = $this->createTemplate($this->tpl_form);
     $data->assign('default_form_language', $this->default_form_language);
     if ((bool) $obj->id) {
         if ($this->product_exists_in_shop) {
             $attachment_name = array();
             $attachment_description = array();
             foreach ($this->_languages as $language) {
                 $attachment_name[$language['id_lang']] = '';
                 $attachment_description[$language['id_lang']] = '';
             }
             $iso_tiny_mce = $this->context->language->iso_code;
             $iso_tiny_mce = file_exists(_PS_JS_DIR_ . 'tiny_mce/langs/' . $iso_tiny_mce . '.js') ? $iso_tiny_mce : 'en';
             $attachment_uploader = new HelperUploader('attachment_file');
             $attachment_uploader->setMultiple(false)->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminProducts') . '&ajax=1&id_product=' . (int) $obj->id . '&action=AddAttachment')->setPostMaxSize(Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024)->setTemplate('attachment_ajax.tpl');
             $data->assign(array('obj' => $obj, 'table' => $this->table, 'ad' => __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_), 'iso_tiny_mce' => $iso_tiny_mce, 'languages' => $this->_languages, 'id_lang' => $this->context->language->id, 'attach1' => Attachment::getAttachments($this->context->language->id, $obj->id, true), 'attach2' => Attachment::getAttachments($this->context->language->id, $obj->id, false), 'default_form_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'attachment_name' => $attachment_name, 'attachment_description' => $attachment_description, 'PS_ATTACHMENT_MAXIMUM_SIZE' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE'), 'attachment_uploader' => $attachment_uploader->render()));
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before adding attachements.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before adding attachements.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
Example #3
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();
    }
Example #4
0
 public function generate()
 {
     $this->tpl = $this->createTemplate($this->base_tpl);
     if (is_null($this->submit_action)) {
         $this->submit_action = 'submitAdd' . $this->table;
     }
     $categories = true;
     $color = true;
     $date = true;
     $tinymce = true;
     $textarea_autosize = true;
     $file = true;
     foreach ($this->fields_form as $fieldset_key => &$fieldset) {
         if (isset($fieldset['form']['tabs'])) {
             $tabs[] = $fieldset['form']['tabs'];
         }
         if (isset($fieldset['form']['input'])) {
             foreach ($fieldset['form']['input'] as $key => &$params) {
                 // If the condition is not met, the field will not be displayed
                 if (isset($params['condition']) && !$params['condition']) {
                     unset($this->fields_form[$fieldset_key]['form']['input'][$key]);
                 }
                 switch ($params['type']) {
                     case 'select':
                         $field_name = (string) $params['name'];
                         // If multiple select check that 'name' field is suffixed with '[]'
                         if (isset($params['multiple']) && $params['multiple'] && stripos($field_name, '[]') === false) {
                             $params['name'] .= '[]';
                         }
                         break;
                     case 'categories':
                         if ($categories) {
                             if (!isset($params['tree']['id'])) {
                                 throw new PrestaShopException('Id must be filled for categories tree');
                             }
                             $tree = new HelperTreeCategories($params['tree']['id'], isset($params['tree']['title']) ? $params['tree']['title'] : null);
                             if (isset($params['name'])) {
                                 $tree->setInputName($params['name']);
                             }
                             if (isset($params['tree']['selected_categories'])) {
                                 $tree->setSelectedCategories($params['tree']['selected_categories']);
                             }
                             if (isset($params['tree']['disabled_categories'])) {
                                 $tree->setDisabledCategories($params['tree']['disabled_categories']);
                             }
                             if (isset($params['tree']['root_category'])) {
                                 $tree->setRootCategory($params['tree']['root_category']);
                             }
                             if (isset($params['tree']['use_search'])) {
                                 $tree->setUseSearch($params['tree']['use_search']);
                             }
                             if (isset($params['tree']['use_checkbox'])) {
                                 $tree->setUseCheckBox($params['tree']['use_checkbox']);
                             }
                             if (isset($params['tree']['set_data'])) {
                                 $tree->setData($params['tree']['set_data']);
                             }
                             $this->context->smarty->assign('categories_tree', $tree->render());
                             $categories = false;
                         }
                         break;
                     case 'file':
                         $uploader = new HelperUploader();
                         $uploader->setId(isset($params['id']) ? $params['id'] : null);
                         $uploader->setName($params['name']);
                         $uploader->setUrl(isset($params['url']) ? $params['url'] : null);
                         $uploader->setMultiple(isset($params['multiple']) ? $params['multiple'] : false);
                         $uploader->setUseAjax(isset($params['ajax']) ? $params['ajax'] : false);
                         $uploader->setMaxFiles(isset($params['max_files']) ? $params['max_files'] : null);
                         if (isset($params['files']) && $params['files']) {
                             $uploader->setFiles($params['files']);
                         } elseif (isset($params['image']) && $params['image']) {
                             // Use for retrocompatibility
                             $uploader->setFiles(array(0 => array('type' => HelperUploader::TYPE_IMAGE, 'image' => isset($params['image']) ? $params['image'] : null, 'size' => isset($params['size']) ? $params['size'] : null, 'delete_url' => isset($params['delete_url']) ? $params['delete_url'] : null)));
                         }
                         if (isset($params['file']) && $params['file']) {
                             // Use for retrocompatibility
                             $uploader->setFiles(array(0 => array('type' => HelperUploader::TYPE_FILE, 'size' => isset($params['size']) ? $params['size'] : null, 'delete_url' => isset($params['delete_url']) ? $params['delete_url'] : null, 'download_url' => isset($params['file']) ? $params['file'] : null)));
                         }
                         if (isset($params['thumb']) && $params['thumb']) {
                             // Use for retrocompatibility
                             $uploader->setFiles(array(0 => array('type' => HelperUploader::TYPE_IMAGE, 'image' => isset($params['thumb']) ? '<img src="' . $params['thumb'] . '" alt="' . (isset($params['title']) ? $params['title'] : '') . '" title="' . (isset($params['title']) ? $params['title'] : '') . '" />' : null)));
                         }
                         $uploader->setTitle(isset($params['title']) ? $params['title'] : null);
                         $params['file'] = $uploader->render();
                         break;
                     case 'color':
                         if ($color) {
                             // Added JS file
                             $this->context->controller->addJqueryPlugin('colorpicker');
                             $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_CORE_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en';
                             $this->tpl_vars['path_css'] = _THEME_CSS_DIR_;
                             $this->tpl_vars['ad'] = __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_);
                             $this->tpl_vars['tinymce'] = true;
                             $this->context->controller->addJS(_PS_JS_DIR_ . 'tiny_mce/tiny_mce.js');
                             $this->context->controller->addJS(_PS_JS_DIR_ . 'admin/tinymce.inc.js');
                             $tinymce = false;
                         }
                         if ($textarea_autosize) {
                             $this->context->controller->addJqueryPlugin('autosize');
                             $textarea_autosize = false;
                         }
                         break;
                     case 'shop':
                         $disable_shops = isset($params['disable_shared']) ? $params['disable_shared'] : false;
                         $params['html'] = $this->renderAssoShop($disable_shops);
                         if (Shop::getTotalShops(false) == 1) {
                             if (isset($this->fields_form[$fieldset_key]['form']['force']) && !$this->fields_form[$fieldset_key]['form']['force'] || !isset($this->fields_form[$fieldset_key]['form']['force'])) {
                                 unset($this->fields_form[$fieldset_key]['form']['input'][$key]);
                             }
                         }
                         break;
                 }
             }
         }
     }
     $this->tpl->assign(array('title' => $this->title, 'toolbar_btn' => $this->toolbar_btn, 'show_toolbar' => $this->show_toolbar, 'toolbar_scroll' => $this->toolbar_scroll, 'submit_action' => $this->submit_action, 'firstCall' => $this->first_call, 'current' => $this->currentIndex, 'token' => $this->token, 'table' => $this->table, 'identifier' => $this->identifier, 'name_controller' => $this->name_controller, 'languages' => $this->languages, 'current_id_lang' => $this->context->language->id, 'defaultFormLanguage' => $this->default_form_language, 'allowEmployeeFormLang' => $this->allow_employee_form_lang, 'form_id' => $this->id, 'tabs' => isset($tabs) ? $tabs : null, 'fields' => $this->fields_form, 'fields_value' => $this->fields_value, 'required_fields' => $this->getFieldsRequired(), 'vat_number' => Module::isInstalled('vatnumber') && file_exists(_PS_MODULE_DIR_ . 'vatnumber/ajax.php'), 'module_dir' => _MODULE_DIR_, 'base_url' => $this->context->shop->getBaseURL(), 'contains_states' => isset($this->fields_value['id_country']) && isset($this->fields_value['id_state']) ? Country::containsStates($this->fields_value['id_country']) : null, 'show_cancel_button' => $this->show_cancel_button, 'back_url' => $this->back_url));
     return parent::generate();
 }
Example #5
0
 /**
  * Update product download
  *
  * @param int $edit
  * @return bool
  */
 public function updateDownloadProduct($edit = 0)
 {
     $app = JFactory::getApplication();
     if ((int) $app->input->get('is_virtual_file') == 1) {
         if (isset($_FILES['virtual_product_file_uploader']) && $_FILES['virtual_product_file_uploader']['size'] > 0) {
             $virtual_product_filename = JeproshopProductDownloadModelProductDownload::getNewFilename();
             $helper = new HelperUploader('virtual_product_file_uploader');
             $files = $helper->setPostMaxSize(Tools::getOctets(ini_get('upload_max_filesize')))->setSavePath(_PS_DOWNLOAD_DIR_)->upload($_FILES['virtual_product_file_uploader'], $virtual_product_filename);
         } else {
             $virtual_product_filename = $app->input->get('virtual_product_filename', JeproshopProductDownloadModelProductDownload::getNewFilename());
         }
         $this->setDefaultAttribute(0);
         //reset cache_default_attribute
         if ($app->input->get('virtual_product_expiration_date') && !JeproshopTools::isDate($app->input->get('virtual_product_expiration_date'))) {
             if (!$app->input->get('virtual_product_expiration_date')) {
                 JText::_('The expiration-date attribute is required.');
                 $this->context->controller->has_errors = true;
                 return false;
             }
         }
         // Trick's
         if ($edit == 1) {
             $product_download_id = (int) JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $this->product_id);
             if (!$product_download_id) {
                 $product_download_id = (int) $app->input->get('virtual_product_id');
             }
         } else {
             $product_download_id = $app->input->get('virtual_product_id');
         }
         $is_sharable = $app->input->get('virtual_product_is_sharable');
         $virtual_product_name = $app->input->get('virtual_product_name');
         $virtual_product_nb_days = $app->input->get('virtual_product_nb_days');
         $virtual_product_nb_downloadable = $app->input->get('virtual_product_nb_downloadable');
         $virtual_product_expiration_date = $app->input->get('virtual_product_expiration_date');
         $download = new JeproshopProductDownloadModelProductDownload((int) $product_download_id);
         $download->product_id = (int) $this->product_id;
         $download->display_filename = $virtual_product_name;
         $download->filename = $virtual_product_filename;
         $download->date_add = date('Y-m-d H:i:s');
         $download->date_expiration = $virtual_product_expiration_date ? $virtual_product_expiration_date . ' 23:59:59' : '';
         $download->nb_days_accessible = (int) $virtual_product_nb_days;
         $download->nb_downloadable = (int) $virtual_product_nb_downloadable;
         $download->published = 1;
         $download->is_sharable = (int) $is_sharable;
         if ($download->save()) {
             return true;
         }
     } else {
         /* un-active download product if checkbox not checked */
         if ($edit == 1) {
             $product_download_id = (int) JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $this->product_id);
             if (!$product_download_id) {
                 $product_download_id = (int) $app->input->get('virtual_product_id');
             }
         } else {
             $product_download_id = JeproshopProductDownloadModelProductDownload::getIdFromProductId($this->product_id);
         }
         if (!empty($product_download_id)) {
             $product_download = new JeproshopProductDownloadModelProductDownload((int) $product_download_id);
             $product_download->date_expiration = date('Y-m-d H:i:s', time() - 1);
             $product_download->published = 0;
             return $product_download->save();
         }
     }
     return false;
 }