<?php class ControllerModuleICustomFooter extends Controller {

	private $error = array();
	function findTextBetween($word1, $word2, $content) {
		$between=str_replace($word1, '',substr($content, strpos($content, $word1), strpos($content, $word2) - strpos($content, $word1)));
		return $between;
	}
	
	function uploadIcon() {
		$currenttemplate = $this->config->get('config_template');
		if ((($_FILES["file"]["type"] == "image/gif")
		|| ($_FILES["file"]["type"] == "image/jpeg")
		|| ($_FILES["file"]["type"] == "image/png"))
		&& ($_FILES["file"]["size"] < 100000))
		  {
		  if ($_FILES["file"]["error"] > 0)
			{
			echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
			}
		  else
			{
			//echo "Upload: " . $_FILES["file"]["name"] . "<br />";
			//echo "Type: " . $_FILES["file"]["type"] . "<br />";
			//echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
			//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
		
			if (file_exists("upload/" . $_FILES["file"]["name"]))
			  {
			  echo $_FILES["file"]["name"] . " already exists. ";
			  }
			else
			  {
			  $extension = $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
			  $dir = '../catalog/view/theme/'.$currenttemplate.'/image/icustomfooter/paymenticons/';
			  move_uploaded_file($_FILES["file"]["tmp_name"],
			  $dir . '00_' . $_POST['iconTitle'] . '.'.$extension);
			  }
			}
		  }
		else
		  {
		  echo "Invalid file";
		  }
	}
	

	
	public function index() {
		
		//Language 
		$this->load->language('module/icustomfooter');
		
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->data['heading_title'] = $this->language->get('heading_title');
		$this->data['text_enabled'] = $this->language->get('text_enabled');
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_content_top'] = $this->language->get('text_content_top');
		$this->data['text_content_bottom'] = $this->language->get('text_content_bottom');		
		$this->data['text_column_left'] = $this->language->get('text_column_left');
		$this->data['text_column_right'] = $this->language->get('text_column_right');
		
		$this->data['entry_layout'] = $this->language->get('entry_layout');
		$this->data['entry_position'] = $this->language->get('entry_position');
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');
		$this->data['button_add_module'] = $this->language->get('button_add_module');
		$this->data['button_remove'] = $this->language->get('button_remove');
		
		$this->data['aboutus'] = $this->language->get('aboutus');
		$this->data['contactus'] = $this->language->get('contactus');
		$this->data['googlemaps'] = $this->language->get('googlemaps');
		$this->data['contactform'] = $this->language->get('contactform');
		$this->data['twitter'] = $this->language->get('twitter');
		$this->data['facebook'] = $this->language->get('facebook');
		$this->data['youtube'] = $this->language->get('youtube');
		$this->data['customcolumn'] = $this->language->get('customcolumn');
		$this->data['socialbuttons'] = $this->language->get('socialbuttons');
		$this->data['footercustomization'] = $this->language->get('footercustomization');
		$this->data['supportandsettings'] = $this->language->get('supportandsettings');
		$this->data['assistance'] = $this->language->get('assistance');
		$this->data['globalsettings'] = $this->language->get('globalsettings');

		$this->data['assistancetitle'] = $this->language->get('assistancetitle');
		$this->data['assistancetext'] = $this->language->get('assistancetext');
		$this->data['yes'] = $this->language->get('yes');
		$this->data['no'] = $this->language->get('no');
		$this->data['white'] = $this->language->get('white');
		$this->data['dark'] = $this->language->get('dark');
		$this->data['hidewhatunfits'] = $this->language->get('hidewhatunfits');
		$this->data['showscrollers'] = $this->language->get('showscrollers');
		$this->data['dashed'] = $this->language->get('dashed');
		$this->data['dotted'] = $this->language->get('dotted');
		$this->data['solid'] = $this->language->get('solid');
		$this->data['double'] = $this->language->get('double');
		$this->data['groove'] = $this->language->get('groove');
		$this->data['ridge'] = $this->language->get('ridge');
		$this->data['inset'] = $this->language->get('inset');
		$this->data['outset'] = $this->language->get('outset');
		$this->data['noline'] = $this->language->get('noline');
		$this->data['defaultfont'] = $this->language->get('defaultfont');
		$this->data['greenicons'] = $this->language->get('greenicons');
		$this->data['whiteicons'] = $this->language->get('whiteicons');
		$this->data['blueicons'] = $this->language->get('blueicons');
		$this->data['preview'] = $this->language->get('preview');
		$this->data['defaultforthefooter'] = $this->language->get('defaultforthefooter');

		$this->data['titleofthecolumn'] = $this->language->get('titleofthecolumn');
		$this->data['aboutus_text'] = $this->language->get('aboutus_text');
		$this->data['showcolumn'] = $this->language->get('showcolumn');
		$this->data['contactus_iconset'] = $this->language->get('contactus_iconset');
		$this->data['contactus_title'] = $this->language->get('contactus_title');
		$this->data['contactus_text'] = $this->language->get('contactus_text');
		$this->data['contactus_address'] = $this->language->get('contactus_address');
		$this->data['contactus_phone'] = $this->language->get('contactus_phone');
		$this->data['contactus_fax'] = $this->language->get('contactus_fax');
		$this->data['contactus_email'] = $this->language->get('contactus_email');
		$this->data['contactus_skype'] = $this->language->get('contactus_skype');
		$this->data['maps_longlat']    = $this->language->get('maps_longlat');
		$this->data['maps_preview']    = $this->language->get('maps_preview');
		$this->data['contactform_sendemailsto']  = $this->language->get('contactform_sendemailsto');
		$this->data['twitter_numberoftweets'] = $this->language->get('twitter_numberoftweets');
		$this->data['twitter_keyword']        = $this->language->get('twitter_keyword');
		$this->data['facebook_pageurl']        = $this->language->get('facebook_pageurl');
		$this->data['facebook_widgetheight']        = $this->language->get('facebook_widgetheight');
		$this->data['youtube_url']        = $this->language->get('youtube_url');
		$this->data['youtube_width']        = $this->language->get('youtube_width');
		$this->data['youtube_height']        = $this->language->get('youtube_height');
		$this->data['custom_text']        = $this->language->get('custom_text');
		$this->data['showsocialbuttons']        = $this->language->get('showsocialbuttons');
		$this->data['facebooklikebutton']        = $this->language->get('facebooklikebutton');
		$this->data['pinterestpin']        = $this->language->get('pinterestpin');
		$this->data['googleplusbutton']        = $this->language->get('googleplusbutton');
		$this->data['showcustomfooter']        = $this->language->get('showcustomfooter');
		$this->data['footerwidth']        = $this->language->get('footerwidth');
		$this->data['hideoriginalfooter']        = $this->language->get('hideoriginalfooter');
		$this->data['hidepoweredby']        = $this->language->get('hidepoweredby');
		$this->data['footerfontfamily']        = $this->language->get('footerfontfamily');
		$this->data['footerbackgroundstyle']        = $this->language->get('footerbackgroundstyle');
		$this->data['whencontentoverflows']        = $this->language->get('whencontentoverflows');
		$this->data['columnheight'] = $this->language->get('columnheight');
		$this->data['columntitlecolor'] = $this->language->get('columntitlecolor');
		$this->data['columnlinestyle'] = $this->language->get('columnlinestyle');

		//Settings and Layouts
		$this->load->model('setting/setting');

		if ($this->request->server['REQUEST_METHOD'] == 'POST') {		
			
			if (isset($this->request->post)) {
				//var_dump($this->request->post);
				if (!empty($_REQUEST['iconTitle'])) {
					$this->uploadIcon();
				} else {
					
					
					if (!empty($this->request->post['data'])) {
						$data = $this->request->post['data'];
						$footerwidth = (!empty($data['Settings']['Width'])) ? $data['Settings']['Width'] : 960;
						
						$this->model_setting_setting->editSetting('icustomfooter',$data);
					}
				
				}
				
			}

			
			//$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
		}
		$data = $this->model_setting_setting->getSetting('icustomfooter');
		if (empty($data)) {
			$data = $this->getDefaultSettings();	
		}
		//$this->model_setting_setting->deleteSetting('icustomfooter');
		$this->data['data'] = $data; 
		$this->load->model('design/layout');
		
		$this->data['layouts'] = $this->model_design_layout->getLayouts();
						
		$this->template = 'module/icustomfooter.tpl';
		$this->children = array(
			'common/header',
			'common/footer'
		);
		
		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}

  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_module'),
			'href'      => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('module/icustomfooter', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
		$this->data['action'] = $this->url->link('module/icustomfooter', 'token=' . $this->session->data['token'], 'SSL');
		
		$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');

		$this->data['systemlanguages'] = $this->getSystemLanguages();
	
		$this->response->setOutput($this->render());
		
		
		
 		
	}
	
	function getSystemLanguages() {
		$this->load->model('localisation/language');
		$languages = $this->model_localisation_language->getLanguages(array());
		return $languages;
	}
	
	function getDefaultSettings() {
		$settings_json = '{"en":{"Widgets":{"AboutUs":{"Show":"true","Title":"About us","Text":"&lt;p&gt;\r\n\tiCustomFooter is a widely popular custom footer creation module. It is light-weight piece of software that comes with preset Twitter, Facebook, YouTube and Pinterest integrations. Other options include text editing via Rich Text Editor and controlling the visibility of each widget. Should you have any concerns or questions please visit our support page from the link in the module.&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tEnjoy iCustomFooter!&lt;\/p&gt;\r\n"},"Contacts":{"Show":"true","IconSet":"","Title":"Contact us","Text":"&lt;p&gt;\r\n\tWork days 9am - 6pm&lt;\/p&gt;\r\n","Address1":"1 Infinite Loop","Address2":"Cupertino, CA 95014","Phone1":"800-692-7753","Phone2":"1-800-MY-APPLE","Fax1":"800-692-7753","Fax2":"1-800-MY-APPLE","Email1":"some@apple.com","Email2":"other@apple.com","Skype1":"appleskype","Skype2":"petermarretc"},"GoogleMaps":{"Show":"true","Title":"Google Maps","Longitude":"37.0625","Latitude":"-95.677068","Code":"&lt;iframe width=&quot;210&quot; height=&quot;210&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; src=&quot;https:\/\/maps.google.com\/maps?ie=UTF8&amp;hq=&amp;t=m&amp;ll=undefined,undefined&amp;spn=0.020044,0.025749&amp;z=15&amp;output=embed&quot;&gt;&lt;\/iframe&gt;"},"ContactForm":{"Show":"true","UseCaptcha":"true","Title":"Drop us a line","Email":"conicgp@gmail.com","EmailSubject":"iCustomFooter Message","LabelName":"Your name:","LabelEmail":"Your email:","LabelMessage":"Message","LabelCaptcha":"Code:","LabelSend":"Send message","LabelSuccess":"Your message was sent, thanks!","LabelRequired":"is a required field","LabelNotValid":"is not valid","LabelInvalidCaptcha":"Invalid CAPTCHA code"},"Twitter":{"Show":"true","NumberOfTweets":"2","Title":"Tweet feed","Method":"profile","Profile":"iSenseLabs","Keyword":"isense"},"Facebook":{"Show":"true","Title":"Facebook","URL":"http:\/\/www.facebook.com\/iSenseLabs","Height":"270"},"YouTube":{"Show":"true","Title":"YouTube","URL":"ShkYDPN5Knc","Width":"","Height":""},"Custom":{"Show":"true","Title":"Custom column 1","Text":"&lt;p&gt;\r\n\tIn this column you can put any custom content you want via the admin panel. You can edit it though a rich text editor which means you can format the text, upload images, add flash, links and others. You can also change the title of each column in iCustomFooter.&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tAs Norman Vincent Pealse says,&amp;nbsp;&lt;em&gt;\u201cEvery problem has in it the seeds of its own solution. If you don\u2019t have any problems, you don\u2019t get any seeds.\u201d&lt;\/em&gt;&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tEnjoy the custom column!&lt;\/p&gt;\r\n"},"Custom2":{"Show":"false","Title":"Custom column 2","Text":"&lt;p&gt;\r\n\tIn this column you can put any custom content you want via the admin panel. You can edit it though a rich text editor which means you can format the text, upload images, add flash, links and others. You can also change the title of each column in iCustomFooter.&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tAs Norman Vincent Pealse says,&amp;nbsp;&lt;em&gt;\u201cEvery problem has in it the seeds of its own solution. If you don\u2019t have any problems, you don\u2019t get any seeds.\u201d&lt;\/em&gt;&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tEnjoy the custom column!&lt;\/p&gt;\r\n"},"Custom3":{"Show":"false","Title":"Custom column 3","Text":"&lt;p&gt;\r\n\tIn this column you can put any custom content you want via the admin panel. You can edit it though a rich text editor which means you can format the text, upload images, add flash, links and others. You can also change the title of each column in iCustomFooter.&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tAs Norman Vincent Pealse says,&amp;nbsp;&lt;em&gt;\u201cEvery problem has in it the seeds of its own solution. If you don\u2019t have any problems, you don\u2019t get any seeds.\u201d&lt;\/em&gt;&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tEnjoy the custom column!&lt;\/p&gt;\r\n"},"Custom4":{"Show":"false","Title":"Custom column 4","Text":"&lt;p&gt;\r\n\tIn this column you can put any custom content you want via the admin panel. You can edit it though a rich text editor which means you can format the text, upload images, add flash, links and others. You can also change the title of each column in iCustomFooter.&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tAs Norman Vincent Pealse says,&amp;nbsp;&lt;em&gt;\u201cEvery problem has in it the seeds of its own solution. If you don\u2019t have any problems, you don\u2019t get any seeds.\u201d&lt;\/em&gt;&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tEnjoy the custom column!&lt;\/p&gt;\r\n"},"Custom5":{"Show":"false","Title":"Custom column 5","Text":"&lt;p&gt;\r\n\tIn this column you can put any custom content you want via the admin panel. You can edit it though a rich text editor which means you can format the text, upload images, add flash, links and others. You can also change the title of each column in iCustomFooter.&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tAs Norman Vincent Pealse says,&amp;nbsp;&lt;em&gt;\u201cEvery problem has in it the seeds of its own solution. If you don\u2019t have any problems, you don\u2019t get any seeds.\u201d&lt;\/em&gt;&lt;\/p&gt;\r\n&lt;p&gt;\r\n\tEnjoy the custom column!&lt;\/p&gt;\r\n"},"SocialButtons":{"Show":"true","FacebookLike":{"Show":"true"},"TwitterPin":{"Show":"true"},"PinterestPin":{"Show":"true"},"GooglePlus":{"Show":"true"}},"PaymentIcons":{"Show":"true"}},"Positions":{"aboutus":"1","contacts":"2","googlemaps":"3","contactform":"4","twitter":"5","facebook":"6","youtube":"8","custom1":"9","custom2":"10","custom3":"11","custom4":"12","custom5":"13"}},"Settings":{"Show":"true","ResponsiveDesign":"yes","FooterWidth":"980","HideOriginalFooter":"","HidePoweredBy":"","FontFamily":"fontfamilyinherit","BackgroundPattern":"whitebgpattern","ColumnContentOverflow":"overflowhidden","ColumnHeight":"330","ColumnWidth":"220","ColumnColor":"","ColumnLineStyle":"dashed","CustomCSS":"\/* Write your Custom CSS here *\/\r\n"}}';
		
		$settings = json_decode($settings_json,true);
		
		$languages = $this->getSystemLanguages();
		foreach($languages as $l) {
			if (strtolower($l['code']) != 'en') {
				$settings[$l['code']] = $settings['en'];
			}
		}
		
		
		
		return $settings;
		
	}

	public function install() {
		$this->load->model('setting/setting');
		$this->model_setting_setting->editSetting('icustomfooter',$this->getDefaultSettings());
	}
	
} ?>