<?php
/**
* 2007-2014 PrestAddon
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestaddon.com for more information.
*
*  @author    PrestAddon SA <admin@prestaddon.com>
*  @copyright 2007-2014 PrestAddon
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

if (!defined('_PS_VERSION_'))
	exit;
class VtemThemeOptions extends Module {
	public function __construct()
	{
		$this->name = 'vtemthemeoptions';
		parent::__construct();
		$this->tab = 'others';
		$this->version = '1.0';
		$this->author = 'PrestAddon';
		$this->displayName = $this->l('VTEM Theme Options');
		$this->description = $this->l('This module will make layout and style for the theme.');
	}
	public function install()
	{
		if (!parent::install()
			|| !$this->registerHook('header')
			|| !Configuration::updateValue($this->name.'_CustomCSS', '')
			|| !Configuration::updateValue($this->name.'_vtemthemestyle', 'style1')
			|| !Configuration::updateValue($this->name.'_templatelogo', false)
			|| !Configuration::updateValue($this->name.'_googlefont', false)
			|| !Configuration::updateValue($this->name.'_menufont', '----- None ------')
			|| !Configuration::updateValue($this->name.'_titlefont', '----- None ------')
			|| !Configuration::updateValue($this->name.'_contentfont', '----- None ------')
			|| !Configuration::updateValue($this->name.'_customelements', '.price, .price-discount, #old_price_display')
			|| !Configuration::updateValue($this->name.'_showfrontend', true)
			|| !Configuration::updateValue($this->name.'_vtemie7warning', true))
			return false;
		return true;
	}
	private function postProcess()
	{
		Configuration::updateValue($this->name.'_CustomCSS', Tools::getValue('CustomCSS'));
		Configuration::updateValue($this->name.'_vtemthemestyle', Tools::getValue('vtemthemestyle'));
		Configuration::updateValue($this->name.'_templatelogo', Tools::getValue('templatelogo'));
		Configuration::updateValue($this->name.'_googlefont', Tools::getValue('googlefont'));
		Configuration::updateValue($this->name.'_menufont', Tools::getValue('menufont'));
		Configuration::updateValue($this->name.'_titlefont', Tools::getValue('titlefont'));
		Configuration::updateValue($this->name.'_contentfont', Tools::getValue('contentfont'));
		Configuration::updateValue($this->name.'_customelements', Tools::getValue('customelements'));
		Configuration::updateValue($this->name.'_vtemie7warning', Tools::getValue('vtemie7warning'));
		Configuration::updateValue($this->name.'_showfrontend', Tools::getValue('showfrontend'));
	}
	public function getContent()
	{
		$output = '';
		$errors = array();
		if (Tools::isSubmit('vtemthemeoptionssubmit'))
		{
			$this->postProcess();
			if (isset($errors) && count($errors))
				$output .= $this->displayError(implode('<br />', $errors));
			else
				$output .= $this->displayConfirmation($this->l('Your settings have been updated.'));
		}
		return $output.$this->displayForm();
	}
	private function displayForm()
	{
		$vtemthemestyles = array('style1', 'style2', 'style3', 'style4','style5');
		$googlefonts = array('----- None ------', 'Merienda', 'Russo+One', 'Trocchi', 'Della+Respira', 'Audiowide' ,'Press+Start+2P', 'Chau+Philomene+One',
		'Oxygen', 'Oleo+Script', 'Great+Vibes', 'Lovers+Quarrel', 'Belleza', 'Berkshire+Swash', 'Rosarivo', 'Averia+Serif+Libre', 'Marmelad', 'Dosis',
		'Crushed', 'Chango', 'Happy+Monkey', 'Fredoka+One','Antic+Slab', 'Bad+Script','Gochi+Hand', 'Londrina+Shadow', 'Italiana', 'Playball',
		'Averia+Sans+Libre', 'PT+Mono', 'Plaster', 'Imprima', 'Sail', 'Lusitana', 'Londrina+Solid', 'Bree+Serif', 'Graduate', 'Unkempt', 'Karla', 'Magra',
		'Shadows+Into+Light+Two', 'Jockey+One', 'Averia+Gruesa+Libre', 'Titan+One', 'Modern+Antiqua', 'Pontano+Sans', 'Germania+One', 'Average',
		'Metamorphous', 'Revalia', 'Poiret One', 'Cutive', 'Sarina', 'Stint+Ultra+Condensed', 'Fascinate+Inline', 'Montserrat', 'Norican', 'Basic',
		'Condiment', 'Mystery Quest', 'Exo', 'Miniver', 'Crete+Round', 'Antic+Didone', 'Chelsea+Market', 'Mrs+Sheppards', 'Patua+One', 'Viga','Cookie',
		'Electrolize', 'Unlock', 'Butcherman', 'Macondo+Swash+Caps', 'Limelight', 'Share', 'Crafty+Girls', 'Shojumaru', 'Mr+De+Haviland', 'Lilita+One',
		'Lobster', 'Asap', 'Ropa+Sans', 'Macondo', 'Port+Lligat+Sans', 'Prata', 'Diplomata+SC', 'Noticia+Text', 'Righteous', 'Mr+Bedfort', 'Bilbo',
		'Short+Stack', 'Parisienne', 'Overlock+SC', 'Knewave', 'Trochut', 'Krona+One', 'Boogaloo', 'Belgrano', 'Enriqueta', 'Architects+Daughter',
		'Nosifer', 'Gudea', 'Erica+One', 'Arapey', 'Henny+Penny', 'Allura', 'Mate+SC', 'Glegoo', 'Cantata+One', 'Fredericka+the+Great', 'Cambo', 'Ruda',
		'Abel', 'Ruthie', 'Open+Sans+Condensed', 'Amatic+SC', 'Bilbo+Swash+Caps', 'Piedra', 'Signika+Negative','Seaweed+Script','Advent+Pro','Spicy+Rice',
		'Chicle', 'Voces', 'Simonetta', 'Kotta+One', 'Averia+Libre', 'Stoke', 'Wire+One', 'Special+Elite', 'Lemon', 'Allerta+Stencil', 'Muli', 'Overlock',
		'Nova+Round', 'Baumans', 'Ruluko', 'Waiting+for+the+Sunrise', 'Original+Surfer', 'Niconne', 'Sansita+One', 'Radley', 'Abril+Fatface',
		'Ubuntu+Condensed', 'Esteban', 'Spirax', 'Fjord+One', 'Loved+by+the+King', 'Coda','Rouge+Script','Stardos+Stencil','Alex+Brush','Delius+Unicase',
		'Six+Caps', 'Bowlby+One', 'Trykker', 'Yeseva+One', 'Italianno', 'Fugaz+One', 'Damion', 'Merienda+One', 'Chivo', 'Spinnaker', 'Princess+Sofia',
		'Passion+One', 'Pinyon+Script', 'Snippet', 'Iceberg', 'Iceland', 'Candal', 'Smythe', 'Walter+Turncoat', 'Sofia', 'Concert+One', 'Kaushan+Script',
		'Andika', 'Oswald', 'Yanone+Kaffeesatz', 'Corben', 'Balthazar', 'Poly', 'Gorditas', 'Acme', 'Habibi', 'Convergence', 'Doppio+One',
		'Mrs+Saint+Delafield', 'Miltonian+Tattoo', 'Annie+Use+Your+Telescope', 'Ovo', 'Goudy+Bookletter+1911', 'Zeyada', 'Inconsolata', 'Tangerine',
		'League+Script', 'Comfortaa', 'MedievalSharp', 'Leckerli+One', 'Amaranth', 'Lekton', 'Cantarell', 'DidactGothic', 'Maven+Pro', 'Give+You+Glory',
		'Monoton', 'Devonshire', 'Numans', 'Cedarville+Cursive', 'La+Belle+Aurore', 'Michroma', 'Gravitas+One', 'Neuton', 'Tulpen+One', 'Nixie+One',
		'Dorsa', 'Miltonian', 'Alike+Angular', 'Homenaje', 'Handlee', 'Nova+Flat', 'Judson', 'Tienne', 'Anton', 'Aladin', 'Dancing+Script',
		'Gloria+Hallelujah', 'Aubrey', 'Hammersmith+One', 'Varela', 'Nova Slim', 'Cabin+Condensed', 'Nova+Oval', 'Play', 'Megrim', 'Kreon', 'Cabin',
		'Kelly+Slab', 'Pacifico', 'Dynalight', 'Ruge Boogie', 'Carme', 'Mate', 'Felipa', 'Ubuntu', 'Geostar+Fill', 'Metrophobic', 'Actor', 'Poller One',
		'Squada+One', 'Dawning+of+a+New+Day', 'Wallpoet', 'Quicksand', 'PT+Sans+Caption', 'Nova+Square', 'Rochester', 'Nova+Script', 'Delius+Swash+Caps',
		'Montez', 'Goblin+One', 'Geostar', 'Marck+Script', 'Sigmar+One', 'Allan', 'Nova+Cut', 'Federant', 'Smokum', 'PT+Sans+Narrow', 'Caudex',
		'IM+Fell+Great+Primer+SC', 'Petrona', 'Sevillana', 'Economica', 'Asset', 'News+Cycle', 'Frijole', 'Astloch', 'Sunshiney', 'Linden+Hill',
		'Slackey', 'Flamenco', 'Droid+Sans+Mono', 'Calligraffitti', 'Neucha', 'Coda+Caption', 'Arvo', 'IM+Fell+Double+Pica', 'Molengo', 'Prociono',
		'Signika', 'Droid+Serif', 'Quattrocento+Sans', 'Changa+One', 'Aguafina+Script', 'Rock+Salt', 'Rokkitt', 'Shadows+Into+Light', 'Expletus+Sans',
		'Sancreek', 'Andada', 'Medula+One', 'Kristi', 'IM+Fell+English+SC', 'Lora', 'Prosto+One', 'Black+Ops+One', 'Gentium+Book+Basic',
		'IM+Fell+Great+Primer', 'Arimo', 'Coustard', 'Tinos', 'Alegreya+SC', 'IM+Fell+French+Canon', 'Kenia', 'PT+Sans', 'Forum', 'Shanti', 'Kameron',
		'IM+Fell+Double+Pica+SC', 'Permanent+Marker', 'Merriweather', 'Cabin+Sketch', 'Raleway', 'PT+Serif', 'Duru+Sans', 'VT323', 'Supermercado+One',
		'Sirin Stencil', 'Ewert', 'Adamina', 'Alike', 'Mako', 'Pompiere', 'Anonymous+Pro', 'Quattrocento', 'Cherry+Cream+Soda', 'Playfair+Display',
		'Fontdiner+Swanky', 'Rosario', 'Lancelot', 'Swanky+and+Moo+Moo', 'IM+Fell+DW+Pica', 'PT+Serif+Caption', 'Bentham', 'Yellowtail', 'Delius',
		'UnifrakturCook', 'Buda', 'Maiden+Orange', 'Istok+Web', 'Arbutus', 'Josefin+Sans', 'Just+Another+Hand', 'Alice', 'Vidaloka', 'Luckiest+Guy',
		'Engagement', 'Indie+Flower', 'Meddon', 'Kranky', 'Holtwood+One+SC', 'Monsieur+La+Doulaise', 'Flavors', 'Volkhov', 'Aldrich', 'Ubuntu+Mono',
		'Antic', 'Jim+Nightshade', 'Atomic+Age', 'Cuprum', 'Cousine', 'Jura', 'Homemade+Apple', 'Irish Grover', 'Paytone+One', 'Droid+Sans', 'Podkova',
		'Inder', 'Ribeye+Marrow', 'Schoolbell', 'UnifrakturMaguntia', 'Caesar+Dressing', 'Arizonia', 'Sniglet', 'Philosopher', 'Unna', 'Puritan', 'Vibur',
		'Redressed', 'Inika', 'Cardo', 'Sonsie+One', 'Passero+One', 'Patrick+Hand', 'Yesteryear', 'Nova+Mono', 'Tenor+Sans', 'Nobile', 'Armata',
		'Covered+By+Your+Grace', 'Crimson+Text', 'Monofett', 'Fanwood+Text', 'Contrail+One', 'Ceviche+One','Nunito','Bonbon','Almendra','Ruslan+Display',
		'Open+Sans', 'Federo', 'Josefin+Slab', 'Allerta', 'Old+Standard+TT', 'Bitter', 'Miss+Fajardose', 'Buenard', 'Francois+One', 'Asul', 'Carter+One',
		'Over+the+Rainbow', 'Mountains+of+Christmas', 'Vast Shadow', 'Artifika', 'Fondamento','Questrial','IM+Fell+DW+Pica+SC','Lato','Mr+Dafoe','Julee',
		'Rationale', 'Almendra+SC', 'Geo', 'Telex', 'Reenie+Beanie', 'Diplomata', 'Bevan', 'Ultra', 'Vollkorn', 'IM+Fell+English', 'Copse', 'EB+Garamond',
		'Sorts+Mill+Goudy', 'Aclonica', 'Cagliostro', 'Varela+Round', 'Chewy', 'Wellfleet', 'Ribeye', 'Dr+Sugiyama', 'Love+Ya+Like+A+Sister', 'Qwigley',
		'Stint+Ultra+Expanded', 'Lustria', 'Gruppo', 'Days+One', 'Trade+Winds', 'Nothing+You+Could+Do', 'Sue+Ellen+Francisco', 'Orbitron', 'Codystar',
		'Euphoria+Script', 'Rammetto+One', 'Lobster+Two', 'Bowlby+One+SC', 'Quantico', 'Jolly+Lodger','Rancho','Montaga','Galdeano','Marvel','Amethysta',
		'Emblema+One', 'Uncial+Antiqua', 'Fresca', 'Creepster', 'Bangers', 'Herr+Von+Muellerhoff', 'Eater','IM+Fell+French+Canon+SC','Voltaire','Satisfy',
		'Salsa', 'Syncopate', 'Gentium+Basic', 'Brawler', 'Bubblegum+Sans', 'Alegreya', 'Ledger', 'Londrina+Outline', 'Butterfly+Kids', 'Coming+Soon',
		'Glass+Antiqua', 'Alfa+Slab+One', 'Marko+One', 'Oldenburg', 'Londrina+Sketch', 'Junge', 'The+Girl+Next+Door', 'Fascinate', 'Port+Lligat+Slab',
		'Emilys+Candy', 'Forte');
		$output = '';
		$output .= '<script type="text/javascript" src="../js/jquery/plugins/jquery.tablednd.js"></script>
			<script type="text/javascript" src="../modules/'.$this->name.'/views/templates/admin/js/form.js"></script>
			<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
				<fieldset>
				<legend><img src="../img/admin/cog.gif" alt="" class="middle" />'.$this->l('Settings').'</legend>
					<label>'.$this->l('Theme style').'</label>
					<div class="margin-form">
						<select id="vtemthemestyle" name = "vtemthemestyle">';
						foreach ($vtemthemestyles as $vtemthemestyle)
						{
							$output .= '<option value="'.$vtemthemestyle.'"'.(Tools::getValue('vtemthemestyle', Configuration::get($this->name
							.'_vtemthemestyle')) == $vtemthemestyle ? ' selected="selected"' : '' ).'>'.$this->l($vtemthemestyle).'</option>';
						}
						$output .= '</select><p class="clear">'.$this->l('Select a style for the theme').'</p>
					</div>
					
					<label>'.$this->l('Google Font Directory').'</label>
					<div class="margin-form">
						<input type="radio" name="googlefont" value="0" '
						.(!Tools::getValue('googlefont', Configuration::get($this->name.'_googlefont')) ? 'checked="checked" ' : '')
						.'/><span class="radio_text">'.$this->l('No').'</span>
					   <input type="radio" name="googlefont" class="select-option" value="1" '
						.(Tools::getValue('googlefont', Configuration::get($this->name.'_googlefont')) ? 'checked="checked" ' : '')
						.'/><span class="radio_text">'.$this->l('Yes').'</span>
						<p class="clear">'.$this->l('You select "YES" to enable Google Fonts on your website.').'</p>
					</div>
					<label class="googlefont-1">'.$this->l('Menu Font').'</label>
					<div class="margin-form googlefont-1">
						<select id="menufont" name="menufont">';
						foreach ($googlefonts as $googlefont)
						{
							$output .= '<option value="'.$googlefont.'"'.(Tools::getValue('menufont', Configuration::get($this->name
							.'_menufont')) == $googlefont ? ' selected="selected"' : '').'>'.str_replace('+', ' ', $this->l($googlefont)).'</option>';
						}
						$output .= '</select><p class="clear">'.$this->l('Select a Google Font for the Main Menu').'</p>
					</div>
					<label class="googlefont-1">'.$this->l('Title Font').'</label>
					<div class="margin-form googlefont-1">
						<select id="titlefont" name="titlefont">';
						foreach ($googlefonts as $googlefont)
						{
							$output .= '<option value="'.$googlefont.'"'.(Tools::getValue('titlefont', Configuration::get($this->name
							.'_titlefont')) == $googlefont ? ' selected="selected"' : '').'>'.str_replace('+', ' ', $this->l($googlefont)).'</option>';
						}
						$output .= '</select><p class="clear">'.$this->l('Select a Google Font for the Module titles, Article titles,...').'</p>
					</div>
					<label class="googlefont-1">'.$this->l('Content Font').'</label>
					<div class="margin-form googlefont-1">
						<select id="contentfont" name="contentfont">';
						foreach ($googlefonts as $googlefont)
						{
							$output .= '<option value="'.$googlefont.'"'.(Tools::getValue('contentfont', Configuration::get($this->name
							.'_contentfont')) == $googlefont ? ' selected="selected"' : '').'>'.str_replace('+', ' ', $this->l($googlefont))
							.'</option>';
						}
						$output .= '</select><p class="clear">'.$this->l('Select a Google Font for the contents').'</p>
					</div>
					<label class="googlefont-1">'.$this->l('Content elements').'</label>
					<div class="margin-form googlefont-1">
						<input type="text" name="customelements" size="26" value="'.Tools::getValue('customelements', Configuration::get($this->name
						.'_customelements')).'"/>
						<p class="clear">'.$this->l('Set Google Font for your elements (ex : body, div.class, p#id, ...).').'</p>
					</div>
					
					<label>'.$this->l('IE7 Warning').'</label>
					<div class="margin-form">
					   <input type="radio" name="vtemie7warning" value="0" '.(!Tools::getValue('vtemie7warning', Configuration::get($this->name
						.'_vtemie7warning')) ? 'checked="checked" ' : '').'/><span class="radio_text">'.$this->l('No').'</span>
					   <input type="radio" name="vtemie7warning" value="1" '.(Tools::getValue('vtemie7warning', Configuration::get($this->name
						.'_vtemie7warning')) ? 'checked="checked" ' : '').'/><span class="radio_text">'.$this->l('Yes').'</span>
						<p class="clear">'.$this->l('Display warning when viewing the theme on IE7.').'</p>
					</div>
					<label>'.$this->l('Show panel').'</label>
					<div class="margin-form">
					    <input type="radio" name="showfrontend" value="0" '.(!Tools::getValue('showfrontend', Configuration::get($this->name
						.'_showfrontend')) ? 'checked="checked" ' : '').'/><span class="radio_text">'.$this->l('No').'</span>
					   <input type="radio" name="showfrontend" value="1" '.(Tools::getValue('showfrontend', Configuration::get($this->name
						.'_showfrontend')) ? 'checked="checked" ' : '').'/><span class="radio_text">'.$this->l('Yes').'</span>
						<p class="clear">'.$this->l('Show stylish control panel outside the Front-Office.').'</p>
					</div>
					<label>'.$this->l('Default logo').'</label>
					<div class="margin-form">
					    <input type="radio" name="templatelogo" value="0" '.(!Tools::getValue('templatelogo', Configuration::get($this->name
						.'_templatelogo')) ? 'checked="checked" ' : '').'/><span class="radio_text">'.$this->l('No').'</span>
					   <input type="radio" name="templatelogo" value="1" '.(Tools::getValue('templatelogo', Configuration::get($this->name
						.'_templatelogo')) ? 'checked="checked" ' : '').'/><span class="radio_text">'.$this->l('Yes').'</span>
						<p class="clear">'.$this->l('Select "YES" to display the Logo from the template.').'</p>
					</div>
					<label>'.$this->l('Custom CSS').'</label>
					<div class="margin-form">
						<textarea type="text" name="CustomCSS" rows="8" cols="50">'.Tools::getValue('CustomCSS', Configuration::get($this->name.'_CustomCSS'))
						.'</textarea>
						<p class="clear">'.$this->l('You can add your CSS to the theme.').'</p>
					</div>
					<br /><br />
					<center>
					<input type="submit" name="vtemthemeoptionssubmit" value="'.$this->l('Save').'" class="vtbutton button btn btn-default" />
				    </center>
				</fieldset>
			</form>';
			return $output;
	}
	public function hookHeader()
	{
		$this->context->smarty->assign(array('CustomCSS' => Configuration::get($this->name.'_CustomCSS'),
									'vtemthemestyle' => Configuration::get($this->name.'_vtemthemestyle'),
									'templatelogo' => Configuration::get($this->name.'_templatelogo'),
									'googlefont' => Configuration::get($this->name.'_googlefont'),
									'menufont' => Configuration::get($this->name.'_menufont'),
									'titlefont' => Configuration::get($this->name.'_titlefont'),
									'contentfont' => Configuration::get($this->name.'_contentfont'),
									'customelements' => Configuration::get($this->name.'_customelements'),
									'showfrontend' => Configuration::get($this->name.'_showfrontend'),
									'vtemie7warning' => Configuration::get($this->name.'_vtemie7warning')));
		return $this->display(__FILE__, 'vtemthemeoptions.tpl');
	}
}
?>