<?php
/************************************************************************************************/
/*						MODULES PRESTASHOP 1.2.5 - FancyZoom									*/
/*	Version 2.00 - 16/04/2010																	*/
/*	Auteur : JC BARON <jc.baron@cc-web.fr>														*/
/************************************************************************************************/
class fancyzoom extends Module
{
	function __construct()
	{
		$this->name = 'fancyzoom';
		$this->tab = 'Tools';
		$this->version = '2.00';
		
		parent::__construct();
		
		$this->displayName = $this->l('Fancy Zoom');
		$this->description = $this->l('Replace advantageously "Thickbox" (Focus on the product images)');
	}

	function install()
	{
		if ( 
			parent::install() == false
			OR $this->registerHook('productfooter') == false
			OR Configuration::updateValue('JQZ_USED_BEFORE', Configuration::get('PS_DISPLAY_JQZOOM')) == false 
			OR Configuration::updateValue('JQZ_USE', 0) == false
			OR Configuration::updateValue('JQZ_ZOOMTYPE', 'standard') == false
			OR Configuration::updateValue('JQZ_ZOOMWIDTH', 250) == false
			OR Configuration::updateValue('JQZ_ZOOMHEIGHT', 130) == false
			OR Configuration::updateValue('JQZ_DECALAGE_TOP', 0) == false
			OR Configuration::updateValue('JQZ_DECALAGE_LEFT', 0) == false
			OR Configuration::updateValue('JQZ_TITLEBGCOLOR', '#CCCCCC') == false
			OR Configuration::updateValue('JQZ_TITLETEXTCOLOR', '#FFFFFF') == false
		) return false;
		return true;
	}
	
	public function getContent()
	{
		if ( Tools::isSubmit('submitFancyZoom') )
		{
			$output = '';
			$retour = true;
			if ( Tools::getValue('JQZ_USE')=='on' ){
				Configuration::updateValue('JQZ_USED_BEFORE', 	  Configuration::get('PS_DISPLAY_JQZOOM'))==false ? $retour=false : false;
				Configuration::updateValue('PS_DISPLAY_JQZOOM',   0);
				Configuration::updateValue('JQZ_USE', 		  	  Tools::getValue('JQZ_USE'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_ZOOMTYPE', 	 	  Tools::getValue('JQZ_ZOOMTYPE'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_ZOOMWIDTH', 	  Tools::getValue('JQZ_ZOOMWIDTH'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_ZOOMHEIGHT',  	  Tools::getValue('JQZ_ZOOMHEIGHT'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_DECALAGE_TOP',	  Tools::getValue('JQZ_DECALAGE_TOP'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_DECALAGE_LEFT',   Tools::getValue('JQZ_DECALAGE_LEFT'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_TITLEBGCOLOR', 	  Tools::getValue('JQZ_TITLEBGCOLOR'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_TITLETEXTCOLOR',  Tools::getValue('JQZ_TITLETEXTCOLOR'))==false ? $retour=false : false;
			} else {
				Configuration::updateValue('PS_DISPLAY_JQZOOM',   Configuration::get('JQZ_USED_BEFORE'))==false ? $retour=false : false;
				Configuration::updateValue('JQZ_USE', 			  'off')==false ? $retour=false : false;
			}
			if ( $retour==false )
				$output .= $this->displayError($this->l('Error'));
			else
				$output .= $this->displayConfirmation($this->l('Settings updated'));
		}
		$output .= '
		<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
			<fieldset>
				<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->displayName.' version '.$this->version.'</legend>
				<table width="800" align="center">
					<tr>
						<td width="230">'.$this->l('Use JQZoom Evolution').'</td>
						<td width="270"><input type="checkbox" id="JQZ_USE" name="JQZ_USE" '.( Configuration::get('JQZ_USE')=='on' ? 'checked' : false).' onclick="UseJQZoom()" style="cursor:pointer" /></td>
						<td rowspan="11" style="border:1px solid #ECECEC; background:#FFF; padding:10px;" align="center">
							<img src="'.$this->_path.'ce001.jpg" height="180"  />
						</td>
					</tr>
					<tr>
						<td width="230">'.$this->l('Zoom Type').'</td>
						<td>
							<select name="JQZ_ZOOMTYPE" id="JQZ_ZOOMTYPE" style="width:144px" class="JQZ_SETTINGS">
								<option value="standard" '.( Configuration::get('JQZ_ZOOMTYPE')=='standard' ? 'selected="selected"' : false).'>Standard</option>
								<option value="reverse"'.( Configuration::get('JQZ_ZOOMTYPE')=='reverse' ? 'selected="selected"' : false).'>Reverse</option>
							</select>
						</td>
					</tr>
					<tr>
						<td width="230">'.$this->l('Zoom width').'</td>
						<td><input type="text" name="JQZ_ZOOMWIDTH" value="'.Configuration::get('JQZ_ZOOMWIDTH').'" class="JQZ_SETTINGS" /></td>
					</tr>
					<tr>
						<td width="230">'.$this->l('Zoom height').'</td>
						<td><input type="text"  name="JQZ_ZOOMHEIGHT" value="'.Configuration::get('JQZ_ZOOMHEIGHT').'" class="JQZ_SETTINGS" /></td>
					</tr>
					<tr>
						<td colspan="2">'.$this->l('Frame shift').'</td>
					</tr>
					<tr>
						<td width="230">&nbsp;&nbsp;&#8226;&nbsp;'.$this->l('top').'</td>
						<td><input type="text"  name="JQZ_DECALAGE_TOP" value="'.Configuration::get('JQZ_DECALAGE_TOP').'" class="JQZ_SETTINGS" /></td>
					</tr>
					<tr>
						<td width="230">&nbsp;&nbsp;&#8226;&nbsp;'.$this->l('left').'</td>
						<td><input type="text"  name="JQZ_DECALAGE_LEFT" value="'.Configuration::get('JQZ_DECALAGE_LEFT').'" class="JQZ_SETTINGS" /></td>
					</tr>
					<tr>
						<td width="230">'.$this->l('Title background color').'</td>
						<td><input type="text"  name="JQZ_TITLEBGCOLOR" value="'.Configuration::get('JQZ_TITLEBGCOLOR').'" class="JQZ_SETTINGS" /></td>
					</tr>
					<tr>
						<td width="230">'.$this->l('Title text color').'</td>
						<td><input type="text"  name="JQZ_TITLETEXTCOLOR" value="'.Configuration::get('JQZ_TITLETEXTCOLOR').'" class="JQZ_SETTINGS" /></td>
					</tr>
				</table><br />
				<center><input type="submit" name="submitFancyZoom" value="'.$this->l('Save').'" class="button" style="width:120px" /></center>
			</fieldset>
		</form>
		<script>
			UseJQZoom = function(){
				if ( $("#JQZ_USE").is(":checked") ){
					$(".JQZ_SETTINGS").attr("disabled", false);
					$(".JQZ_SETTINGS").css("color", "#000000");
				} else {
					$(".JQZ_SETTINGS").attr("disabled", true);
					$(".JQZ_SETTINGS").css("color", "#999");
				}
			}
			$(document).ready(function() {
					UseJQZoom();
			} );
		</script>
		';
		return $output;
	}
	
	function hookproductfooter($params)
	{
		global $smarty;
		$smarty->assign('dossierjs', 	  $this->_path);
		$smarty->assign('jqzoom', 		  (Configuration::get('JQZ_USE')=='on' ? true : false) );
		$smarty->assign('zoomType',  	  "'".Configuration::get('JQZ_ZOOMTYPE')."'");
		$smarty->assign('zoomWidth',  	  Configuration::get('JQZ_ZOOMWIDTH'));
		$smarty->assign('zoomHeight',  	  Configuration::get('JQZ_ZOOMHEIGHT'));
		$smarty->assign('decalage',  	  "'".Configuration::get('JQZ_DECALAGE_TOP')."px 0px 0px ".Configuration::get('JQZ_DECALAGE_LEFT')."px'");
		$smarty->assign('titleBgColor',   "'".Configuration::get('JQZ_TITLEBGCOLOR')."'");
		$smarty->assign('titleTextColor', "'".Configuration::get('JQZ_TITLETEXTCOLOR')."'");
		return $this->display(__FILE__,   'fancyzoom.tpl');
	}
}

?>
