* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6850 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ 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 afterImageUpload() { /* Generate image with differents size */ if (!($obj = $this->loadObject(true))) return; 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', (int)($imageType['width']), (int)($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', (int)($imageType['width']), (int)($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 */ public function recurseCategoryForInclude($indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL, $has_suite = array()) { global $done; static $irow; $id_obj = (int)(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; echo ' '.$id_category.' '; for ($i = 2; $i < $level; $i++) echo ''; echo '   '; if ($level > 1) $has_suite[] = ($todo == $doneC ? 0 : 1); if (isset($categories[$id_category])) foreach ($categories[$id_category] AS $key => $row) if ($key != 'infos') $this->recurseCategoryForInclude($indexedCategories, $categories, $categories[$id_category][$key], $key, $id_category_default, $has_suite); } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; $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((int)($cookie->id_lang), false); $done = array(); $index = array(); if (Tools::isSubmit('categories')) foreach (Tools::getValue('categories') 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 '
'.$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').'
'; } public function postProcess() { if (Tools::isSubmit('save_image_map')) { if (!Tools::isSubmit('categories') || !sizeof(Tools::getValue('categories'))) $this->_errors[] = Tools::displayError('You should select at least one category'); if (!Tools::isSubmit('zones') || !sizeof(Tools::getValue('zones'))) $this->_errors[] = Tools::displayError('You should make at least one zone'); } parent::postProcess(); } }