* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 8929 $ * @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; } 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 '
'; $selectedCat = array(); if (Tools::isSubmit('categories')) foreach (Tools::getValue('categories') AS $k => $row) $selectedCat[] = $row; elseif ($obj->id) foreach (Scene::getIndexedCategories($obj->id) AS $k => $row) $selectedCat[] = $row['id_category']; $trads = array( 'Home' => $this->l('Home'), 'selected' => $this->l('selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All') ); echo '
'; echo Helper::renderAdminCategorieTree($trads, $selectedCat, 'categories'); 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(); } }