* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(dirname(__FILE__).'/../../classes/AdminTab.php'); class AdminScenes extends AdminTab { protected $maxImageSize = 1000000; public function __construct() { $this->table = 'scene'; $this->className = 'Scene'; $this->lang = true; $this->edit = true; $this->delete = true; $this->fieldImageSettings = array( array('name' => 'image', 'dir' => 'scenes'), array('name' => 'thumb', 'dir' => 'scenes/thumbs') ); $this->fieldsDisplay = array( 'id_scene' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Image Maps'), 'width' => 150), 'active' => array('title' => $this->l('Activated'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) ); parent::__construct(); } public function delete() { removeZoneProducts(); } function afterImageUpload() { /* Generate image with differents size */ $obj = $this->loadObject(true); if ($obj->id AND (isset($_FILES['image']) OR isset($_FILES['thumb']))) { $imagesTypes = ImageType::getImagesTypes('scenes'); foreach ($imagesTypes AS $k => $imageType) { if ($imageType['name'] == 'large_scene' AND isset($_FILES['image'])) imageResize($_FILES['image']['tmp_name'], _PS_SCENE_IMG_DIR_.$obj->id.'-'.stripslashes($imageType['name']).'.jpg', intval($imageType['width']), intval($imageType['height'])); elseif ($imageType['name'] == 'thumb_scene') { if (isset($_FILES['thumb']) AND !$_FILES['thumb']['error']) $tmpName = $_FILES['thumb']['tmp_name']; else $tmpName = $_FILES['image']['tmp_name']; imageResize($tmpName, _PS_SCENE_THUMB_IMG_DIR_.$obj->id.'-'.stripslashes($imageType['name']).'.jpg', intval($imageType['width']), intval($imageType['height'])); } } } return true; } /** * Build a categories tree * * @param array $indexedCategories Array with categories where product is indexed (in order to check checkbox) * @param array $categories Categories to list * @param array $current Current category * @param integer $id_category Current category id */ function recurseCategoryForInclude($indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL) { global $done; static $irow; $id_obj = intval(Tools::getValue($this->id)); if (!isset($done[$current['infos']['id_parent']])) $done[$current['infos']['id_parent']] = 0; $done[$current['infos']['id_parent']] += 1; $todo = sizeof($categories[$current['infos']['id_parent']]); $doneC = $done[$current['infos']['id_parent']]; $level = $current['infos']['level_depth'] + 1; $img = $level == 1 ? 'lv1.gif' : 'lv'.$level.'_'.($todo == $doneC ? 'f' : 'b').'.gif'; echo ' '.($id_category == 1 ? ' ' : '').' '.$id_category.'   '; if (isset($categories[$id_category])) foreach ($categories[$id_category] AS $key => $row) if ($key != 'infos') $this->recurseCategoryForInclude($indexedCategories, $categories, $categories[$id_category][$key], $key); } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); $obj = $this->loadObject(true); $langtags = 'name'; $active = $this->getFieldValue($obj, 'active'); echo '
'.($obj->id ? '' : '').'
'.$this->l('Image Maps').''; echo '
'.$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.').'
'; echo '
'; foreach ($this->_languages as $language) echo '
*
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'name'); echo '
'; echo '
id OR Tools::getValue('active', $obj->active)) ? 'checked="checked" ' : '').'/> active) AND $obj->id) ? 'checked="checked" ' : '').'/>

'.$this->l('Activate or deactivate the image map').'

'; $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 '

'.$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.').'.
'.$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.'-large_scene.jpg')) { echo '
'; echo ' '; echo ' '; echo '
'; echo '
  '.$this->l('(optional)').'

'.$this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.').'
'.$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)').'.
'.$this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'

'; if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.'thumbs/'.$obj->id.'-thumb_scene.jpg')) echo '
'; echo '
'; echo '
'; $categories = Category::getCategories(intval($cookie->id_lang), false); $done = array(); $index = array(); $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : ($obj->id ? Scene::getIndexedCategories($obj->id) : array()); foreach ($indexedCategories AS $k => $row) $index[] = $row['id_category']; $this->recurseCategoryForInclude($index, $categories, $categories[0][1], 1, null); echo '
'.$this->l('ID').' '.$this->l('Image map name:').'

'.$this->l('Mark all checkbox(es) of the categories for which the image map is to appear.').' *

'; echo '
id && file_exists(_PS_SCENE_IMG_DIR_.$obj->id.'-large_scene.jpg')) ? '' : 'style="display:none;"') .'>
'; } else { echo '
'.$this->l('Please add a picture to continue mapping the image...').'

'; } echo '
* '.$this->l('Required field').'
'; } } ?>