public function initFieldsForm()
    {
        $obj = $this->loadObject(true);
        $scene_image_types = ImageType::getImagesTypes('scenes');
        $large_scene_image_type = null;
        $thumb_scene_image_type = null;
        foreach ($scene_image_types as $scene_image_type) {
            if ($scene_image_type['name'] == 'scene_default') {
                $large_scene_image_type = $scene_image_type;
            }
            if ($scene_image_type['name'] == 'm_scene_default') {
                $thumb_scene_image_type = $scene_image_type;
            }
        }
        $fields_form = array('legend' => array('title' => $this->l('Image Maps'), 'icon' => 'icon-picture'), 'description' => '
				<h4>' . $this->l('How to map products in the image:') . '</h4>
				<p>
					' . $this->l('When a customer hovers over the image, a pop-up appears displaying a brief description of the product.') . '
					' . $this->l('The customer can then click to open the full product page.') . '<br/>
					' . $this->l('To achieve this, please define the \'mapping zone\' that, when hovered over, will display the pop-up.') . '
					' . $this->l('Left click with your mouse to draw the four-sided mapping zone, then release.') . '<br/>
					' . $this->l('Then begin typing the name of the associated product, and  a list of products will appear.') . '
					' . $this->l('Click the appropriate product and then click OK. Repeat these steps for each mapping zone you wish to create.') . '<br/>
					' . $this->l('When you have finished mapping zones, click "Save Image Map."') . '
				</p>', 'input' => array(array('type' => 'text', 'label' => $this->l('Image map name'), 'name' => 'name', 'lang' => true, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'switch', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))), 'submit' => array('title' => $this->l('Save')));
        $this->fields_form = $fields_form;
        $image_to_map_desc = '';
        $image_to_map_desc .= '<div class="help-block">' . $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('File size:') . ' ' . Tools::getMaxUploadSize() / 1024 . '' . $this->l('Kb max.') . ' ' . sprintf($this->l('If an image is too large, it will be reduced to %1$d x %2$dpx (width x height).'), $large_scene_image_type['width'], $large_scene_image_type['height']) . $this->l('If an image is deemed too small, a white background will be added in order to achieve the correct image size.') . '<br />' . $this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).') . '</div>';
        if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . $obj->id . '-scene_default.jpg')) {
            $this->addJqueryPlugin('autocomplete');
            $this->addJqueryPlugin('imgareaselect');
            $this->addJs(_PS_JS_DIR_ . 'admin/scenes.js');
            $image_to_map_desc .= '<div class="panel panel-default"><span class="thumbnail row-margin-bottom"><img id="large_scene_image" alt="" src="' . _THEME_SCENE_DIR_ . $obj->id . '-scene_default.jpg?rand=' . (int) rand() . '" /></span>';
            $image_to_map_desc .= '
				<div id="ajax_choose_product" class="row" style="display:none;">
					<div class="col-lg-12">
					<p class="alert alert-info">' . $this->l('Begin typing the first few letters of the product name, then select the product you are looking for from the drop-down list:') . '
					</p>
					<div class="input-group row-margin-bottom">
						<span class="input-group-addon">
							<i class="icon-search"></i>
						</span>
						<input type="text" value="" id="product_autocomplete_input" />
					</div>
					<button type="button" class="btn btn-default" onclick="undoEdit();"><i class="icon-remove"></i>&nbsp;' . $this->l('Delete') . '</button>
					<button type="button" class="btn btn-default" onclick="$(this).prev().search();"><i class="icon-check-sign"></i>&nbsp;' . $this->l('Ok') . '</button>
					</div>
				</div>
				';
            if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . 'thumbs/' . $obj->id . '-m_scene_default.jpg')) {
                $image_to_map_desc .= '</div><hr/><img class="thumbnail" id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="' . _THEME_SCENE_DIR_ . 'thumbs/' . $obj->id . '-m_scene_default.jpg?rand=' . (int) rand() . '" />';
            }
            $img_alt_desc = '';
            $img_alt_desc .= $this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.') . '<br />' . $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('File size:') . ' ' . Tools::getMaxUploadSize() / 1024 . '' . $this->l('Kb max.') . ' ' . sprintf($this->l('Automatically resized to %1$d x %2$dpx (width x height).'), $thumb_scene_image_type['width'], $thumb_scene_image_type['height']) . '.<br />' . $this->l('Note: To change image dimensions, please change the \'m_scene_default\' image type settings to the desired size (in Back Office > Preferences > Images).');
            $input_img_alt = array('type' => 'file', 'label' => $this->l('Alternative thumbnail'), 'name' => 'thumb', 'desc' => $img_alt_desc);
            $selected_cat = array();
            if (Tools::isSubmit('categories')) {
                foreach (Tools::getValue('categories') as $row) {
                    $selected_cat[] = $row;
                }
            } elseif ($obj->id) {
                foreach (Scene::getIndexedCategories($obj->id) as $row) {
                    $selected_cat[] = $row['id_category'];
                }
            }
            $this->fields_form['input'][] = array('type' => 'categories', 'label' => $this->l('Categories'), 'name' => 'categories', 'tree' => array('id' => 'categories-tree', 'title' => 'Categories', 'selected_categories' => $selected_cat, 'use_search' => true, 'use_checkbox' => true));
        } else {
            $image_to_map_desc .= '<span>' . $this->l('Please add a picture to continue mapping the image.') . '</span>';
        }
        if (Shop::isFeatureActive()) {
            $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso');
        }
        $this->fields_form['input'][] = array('type' => 'file', 'label' => $this->l('Image to be mapped'), 'name' => 'image', 'display_image' => true, 'desc' => $image_to_map_desc);
        if (isset($input_img_alt)) {
            $this->fields_form['input'][] = $input_img_alt;
        }
    }
Esempio n. 2
0
    public function displayForm($isMainTab = true)
    {
        global $currentIndex, $cookie;
        parent::displayForm();
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        $langtags = 'name';
        $active = $this->getFieldValue($obj, 'active');
        echo '
		<script type="text/javascript">';
        echo 'startingData = new Array();' . "\n";
        foreach ($obj->getProducts() as $key => $product) {
            $productObj = new Product((int) $product['id_product'], true, (int) $cookie->id_lang);
            echo 'startingData[' . $key . '] = new Array(\'' . $productObj->name . '\', ' . $product['id_product'] . ', ' . $product['x_axis'] . ', ' . $product['y_axis'] . ', ' . $product['zone_width'] . ', ' . $product['zone_height'] . ');';
        }
        echo '</script>
		<form id="scenesForm" action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" method="post" enctype="multipart/form-data">
		' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '') . '
			<fieldset><legend><img src="../img/admin/photo.gif" />' . $this->l('Image Maps') . '</legend>';
        echo '
					<label>' . $this->l('How to map products in the image:') . ' </label>
					<div class="margin-form">
						' . $this->l('When a customer hovers over the image with the mouse, a pop-up appears displaying a brief description of the product. The customer can then click to open the product\'s full product page. To achieve this, please define the \'mapping zone\' that, when hovered over, will display the pop-up. Left-click with your mouse to draw the four-sided mapping zone, then release. Then, begin typing the name of the associated product. A list of products appears. Click the appropriate product, then click OK. Repeat these steps for each mapping zone you wish to create. When you have finished mapping zones, click Save Image Map.') . '
					</div>
					';
        echo '<label>' . $this->l('Image map name:') . ' </label>
				<div class="margin-form">';
        foreach ($this->_languages as $language) {
            echo '
					<div id="name_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;">
						<input type="text" style="width: 260px" name="name_' . $language['id_lang'] . '" id="name_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'name', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /><sup> *</sup>
					</div>';
        }
        $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'name');
        echo '		<div class="clear"></div>
				</div>';
        echo '<label>' . $this->l('Status:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ((!$obj->id or Tools::getValue('active', $obj->active)) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="' . $this->l('Activated') . '" title="' . $this->l('Activated') . '" /></label>
					<input type="radio" name="active" id="active_off" value="0" ' . ((!Tools::getValue('active', $obj->active) and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="' . $this->l('Deactivated') . '" title="' . $this->l('Deactivated') . '" /></label>
					<p>' . $this->l('Activate or deactivate the image map') . '</p>
				</div>';
        $sceneImageTypes = ImageType::getImagesTypes('scenes');
        $largeSceneImageType = NULL;
        $thumbSceneImageType = NULL;
        foreach ($sceneImageTypes as $sceneImageType) {
            if ($sceneImageType['name'] == 'large_scene') {
                $largeSceneImageType = $sceneImageType;
            }
            if ($sceneImageType['name'] == 'thumb_scene') {
                $thumbSceneImageType = $sceneImageType;
            }
        }
        echo '<label>' . $this->l('Image to be mapped:') . ' </label>
				<div class="margin-form">
					<input type="hidden" id="stay_here" name="stay_here" value="" />
					<input type="file" name="image" id="image_input" /> <input type="button" value="' . $this->l('Upload image') . '" onclick="{$(\'#stay_here\').val(\'true\');$(\'#scenesForm\').submit();}" class="button" /><br/>
					<p>' . $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('File size:') . ' ' . $this->maxImageSize / 1000 . '' . $this->l('KB max.') . ' ' . $this->l('If larger than the image size setting, the image will be reduced to ') . ' ' . $largeSceneImageType['width'] . 'x' . $largeSceneImageType['height'] . 'px ' . $this->l('(width x height). If smaller than the image-size setting, a white background will be added in order to achieve the correct image size.') . '.<br />' . $this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).') . '</p>';
        if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . $obj->id . '-large_scene.jpg')) {
            echo '<img id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="' . _THEME_SCENE_DIR_ . $obj->id . '-large_scene.jpg" /><br />';
            echo '
					<div id="ajax_choose_product" style="display:none; padding:6px; padding-top:2px; width:600px;">
						' . $this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:') . '<br /><input type="text" value="" id="product_autocomplete_input" /> <input type="button" class="button" value="' . $this->l('OK') . '" onclick="$(this).prev().search();" /><input type="button" class="button" value="' . $this->l('Delete') . '" onclick="undoEdit();" />
					</div>
			';
            echo '
					<link rel="stylesheet" type="text/css" href="' . __PS_BASE_URI__ . 'css/jquery.autocomplete.css" />
					<link rel="stylesheet" type="text/css" href="' . __PS_BASE_URI__ . 'js/jquery/imgareaselect/imgareaselect-default.css" />
					<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/jquery/jquery.autocomplete.js"></script>
					<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/jquery/imgareaselect/jquery.imgareaselect.pack.js"></script>
					<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/admin-scene-cropping.js"></script>
		';
            echo '</div>';
            echo '<label>' . $this->l('Alternative thumbnail:') . ' </label>
				<div class="margin-form">
					<input type="file" name="thumb" id="thumb_input" />&nbsp;&nbsp;' . $this->l('(optional)') . '
					<p>' . $this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.') . '<br />' . $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('Filesize:') . ' ' . $this->maxImageSize / 1000 . '' . $this->l('Kb max.') . ' ' . $this->l('Automatically resized to') . ' ' . $thumbSceneImageType['width'] . 'x' . $thumbSceneImageType['height'] . 'px ' . $this->l('(width x height)') . '.<br />' . $this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).') . '</p>
					';
            if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . 'thumbs/' . $obj->id . '-thumb_scene.jpg')) {
                echo '<img id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="' . _THEME_SCENE_DIR_ . 'thumbs/' . $obj->id . '-thumb_scene.jpg" /><br />';
            }
            echo '</div>
			 ';
            echo '<label>' . $this->l('Category:') . ' </label>
				<div class="margin-form">
					<div style="overflow: auto; min-height: 300px; padding-top: 0.6em;" id="categoryList">
						<table cellspacing="0" cellpadding="0" class="table" style="width: 600px;">
								<tr>
									<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'categoryBox[]\', this.checked)" /></th>
									<th>' . $this->l('ID') . '</th>
									<th>' . $this->l('Image map name:') . '</th>
								</tr>';
            $categories = Category::getCategories((int) $cookie->id_lang, false);
            $done = array();
            $index = array();
            if (Tools::isSubmit('categoryBox')) {
                foreach (Tools::getValue('categoryBox') as $k => $row) {
                    $index[] = $row;
                }
            } elseif ($obj->id) {
                foreach (Scene::getIndexedCategories($obj->id) as $k => $row) {
                    $index[] = $row['id_category'];
                }
            }
            $this->recurseCategoryForInclude($index, $categories, $categories[0][1], 1, null);
            echo '</table>
						<p style="padding:0px; margin:0px 0px 10px 0px;">' . $this->l('Mark all checkbox(es) of the categories for which the image map is to appear.') . '<sup> *</sup></p>
					</div>
				</div>';
            echo '
					<div id="save_scene" class="margin-form" ' . ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . $obj->id . '-large_scene.jpg') ? '' : 'style="display:none;"') . '>
						<input type="submit" value="' . $this->l('Save Image Map(s)') . '" class="button" />
					</div>';
        } else {
            echo '
					<br/><span class="bold">' . $this->l('Please add a picture to continue mapping the image...') . '</span><br/><br/>';
        }
        echo '<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div>
			</fieldset>
		</form>';
    }
    public function initFieldsForm()
    {
        $obj = $this->loadObject(true);
        $scene_image_types = ImageType::getImagesTypes('scenes');
        $large_scene_image_type = null;
        $thumb_scene_image_type = null;
        foreach ($scene_image_types as $scene_image_type) {
            if ($scene_image_type['name'] == 'scene_default') {
                $large_scene_image_type = $scene_image_type;
            }
            if ($scene_image_type['name'] == 'm_scene_default') {
                $thumb_scene_image_type = $scene_image_type;
            }
        }
        $fields_form = array('legend' => array('title' => $this->l('Image Maps'), 'image' => '../img/admin/photo.gif'), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'), 'input' => array(array('type' => 'description', 'name' => 'description', 'label' => $this->l('How to map products in the image:'), 'text' => $this->l('When a customer hovers over the image with the mouse, a pop-up appears displaying a brief description of the product.') . $this->l('The customer can then click to open the product\'s full product page.') . $this->l('To achieve this, please define the \'mapping zone\' that, when hovered over, will display the pop-up.') . $this->l('Left-click with your mouse to draw the four-sided mapping zone, then release.') . $this->l('Then, begin typing the name of the associated product. A list of products appears.') . $this->l('Click the appropriate product, then click OK. Repeat these steps for each mapping zone you wish to create.') . $this->l('When you have finished mapping zones, click Save Image Map.')), array('type' => 'text', 'label' => $this->l('Image map name:'), 'name' => 'name', 'lang' => true, 'size' => 48, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'radio', 'label' => $this->l('Status:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))));
        $this->fields_form = $fields_form;
        $image_to_map_desc = '';
        $image_to_map_desc .= $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('File size:') . ' ' . Tools::getMaxUploadSize() / 1024 . '' . $this->l('kB max.') . ' ' . sprintf($this->l('If larger than the image size setting, the image will be reduced to %1$d x %2$dpx (width x height).'), $large_scene_image_type['width'], $large_scene_image_type['height']) . $this->l('If smaller than the image size setting, a white background will be added in order to achieve the correct image size.') . '<br />' . $this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).');
        if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . $obj->id . '-scene_default.jpg')) {
            $this->addJqueryPlugin('autocomplete');
            $this->addJqueryPlugin('imgareaselect');
            $this->addJs(_PS_JS_DIR_ . 'admin-scene-cropping.js');
            $image_to_map_desc .= '<br /><img id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="' . _THEME_SCENE_DIR_ . $obj->id . '-scene_default.jpg" /><br />';
            $image_to_map_desc .= '
						<div id="ajax_choose_product" style="display:none; padding:6px; padding-top:2px; width:600px;">
							' . $this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:') . '
								<br /><input type="text" value="" id="product_autocomplete_input" /> 
								<input type="button" class="button" value="' . $this->l('OK') . '" onclick="$(this).prev().search();" />
								<input type="button" class="button" value="' . $this->l('Delete') . '" onclick="undoEdit();" />
						</div>
				';
            if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . 'thumbs/' . $obj->id . '-thumb_scene.jpg')) {
                $image_to_map_desc .= '<br/>
					<img id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="' . _THEME_SCENE_DIR_ . 'thumbs/' . $obj->id . '-m_scene_default.jpg" />
					<br />';
            }
            $img_alt_desc = '';
            $img_alt_desc .= $this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.') . '<br />' . $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('Filesize:') . ' ' . Tools::getMaxUploadSize() / 1024 . '' . $this->l('kB max.') . ' ' . sprintf($this->l('Automatically resized to %1$d x %2$dpx (width x height).'), $thumb_scene_image_type['width'], $thumb_scene_image_type['height']) . '.<br />' . $this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).');
            $input_img_alt = array('type' => 'file', 'label' => $this->l('Alternative thumbnail:'), 'name' => 'thumb', 'desc' => $img_alt_desc);
            $selected_cat = array();
            if (Tools::isSubmit('categories')) {
                foreach (Tools::getValue('categories') as $row) {
                    $selected_cat[] = $row;
                }
            } else {
                if ($obj->id) {
                    foreach (Scene::getIndexedCategories($obj->id) as $row) {
                        $selected_cat[] = $row['id_category'];
                    }
                }
            }
            $root_category = Category::getRootCategory();
            if (!$root_category->id) {
                $root_category->id = 0;
                $root_category->name = $this->l('Root');
            }
            $root_category = array('id_category' => (int) $root_category->id, 'name' => $root_category->name);
            $trads = array('Root' => $root_category, 'selected' => $this->l('selected'), 'Check all' => $this->l('Check all'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'search' => $this->l('Search a category'));
            $this->fields_form['input'][] = array('type' => 'categories', 'label' => $this->l('Categories:'), 'name' => 'categories', 'values' => array('trads' => $trads, 'selected_cat' => $selected_cat, 'input_name' => 'categories[]', 'use_radio' => false, 'use_search' => true, 'disabled_categories' => array(4), 'top_category' => Category::getTopCategory(), 'use_context' => true));
        } else {
            $image_to_map_desc .= '<br/><span class="bold">' . $this->l('Please add a picture to continue mapping the image.') . '</span><br/><br/>';
        }
        if (Shop::isFeatureActive()) {
            $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
        }
        $this->fields_form['input'][] = array('type' => 'file', 'label' => $this->l('Image to be mapped:'), 'name' => 'image', 'display_image' => true, 'desc' => $image_to_map_desc);
        if (isset($input_img_alt)) {
            $this->fields_form['input'][] = $input_img_alt;
        }
    }