* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7040 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminScenesControllerCore extends AdminController
{
public function __construct()
{
$this->table = 'scene';
$this->className = 'Scene';
$this->lang = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->identifier = 'id_scene';
$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'),
'filter_key' => 'b!name'
),
'active' => array(
'title' => $this->l('Activated'),
'width' => 70,
'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 && (isset($_FILES['image']) || isset($_FILES['thumb'])))
{
$images_types = ImageType::getImagesTypes('scenes');
foreach ($images_types as $k => $image_type)
{
$theme = (Shop::isFeatureActive() ? '-'.$image_type['id_theme'] : '');
if ($image_type['name'] == 'large_scene' && isset($_FILES['image']))
imageResize(
$_FILES['image']['tmp_name'],
_PS_SCENE_IMG_DIR_.$obj->id.'-'.stripslashes($image_type['name']).$theme.'.jpg',
(int)$image_type['width'],
(int)$image_type['height']
);
else if ($image_type['name'] == 'thumb_scene')
{
if (isset($_FILES['thumb']) && !$_FILES['thumb']['error'])
$tmp_name = $_FILES['thumb']['tmp_name'];
else
$tmp_name = $_FILES['image']['tmp_name'];
imageResize(
$tmp_name,
_PS_SCENE_THUMB_IMG_DIR_.$obj->id.'-'.stripslashes($image_type['name']).$theme.'.jpg',
(int)$image_type['width'],
(int)$image_type['height']
);
}
}
}
return true;
}
public function renderForm()
{
$this->initFieldsForm();
$content = '';
if (!($obj = $this->loadObject(true)))
return;
$langtags = 'name';
$active = $this->getFieldValue($obj, 'active');
$products = $obj->getProducts(true, $this->context->language->id, false, $this->context);
$this->tpl_form_vars['products'] = $obj->getProducts(true, $this->context->language->id, false, $this->context);
return parent::renderForm();
}
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'] == 'large_scene')
$large_scene_image_type = $scene_image_type;
if ($scene_image_type['name'] == 'thumb_scene')
$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.').' '
.$this->l('If larger than the image size setting, the image will be reduced to ')
.' '.$large_scene_image_type['width'].'x'.$large_scene_image_type['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'))
{
$this->addJqueryPlugin('autocomplete');
$this->addJqueryPlugin('imgareaselect');
$this->addJs(_PS_JS_DIR_.'admin-scene-cropping.js' );
$image_to_map_desc .= '
';
$image_to_map_desc .= '