<?php
class ControllerModulefuturaInformacoesEmpresa extends Controller {
	private $error = array();
 
	public function index() {
		$this->language->load('module/futura_InformacoesEmpresa'); 

		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('setting/setting');
		
		$this->load->model('localisation/language');
		$this->data['languages'] = $this->model_localisation_language->getLanguages();
		
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$this->model_setting_setting->editSetting('InformacoesEmpresa', $this->request->post);

				
			$this->session->data['success'] = $this->language->get('text_success');
			$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
		}

		$this->data['heading_title'] = $this->language->get('heading_title');
		$this->data['entry_inf_telefone'] = $this->language->get('entry_inf_telefone');
		$this->data['entry_inf_email'] = $this->language->get('entry_inf_email');
		$this->data['entry_inf_dados'] = $this->language->get('entry_inf_dados');
		$this->data['entry_inf_status_email'] = $this->language->get('entry_inf_status_email');
		
		
		$this->data['entry_inf_twitter'] = $this->language->get('entry_inf_twitter');
		$this->data['entry_inf_facebook'] = $this->language->get('entry_inf_facebook');
		$this->data['entry_inf_blogger'] = $this->language->get('entry_inf_blogger');
		$this->data['entry_inf_youtube'] = $this->language->get('entry_inf_youtube');
                $this->data['entry_new_pattern_purchase'] = $this->language->get('entry_new_pattern_purchase');	
                $this->data['text_enabled'] = $this->language->get('text_enabled');	
                $this->data['text_disabled'] = $this->language->get('text_disabled');                
                

		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');
		$this->data['tab_inf_contatos'] = $this->language->get('tab_inf_contatos');	
		$this->data['tab_inf_rsociais'] = $this->language->get('tab_inf_rsociais');
                $this->data['tab_inf_config'] = $this->language->get('tab_inf_config');

 		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
 
  		if (isset($this->error['title'])) {
			$this->data['error_title'] = $this->error['title'];
		} else {
			$this->data['error_title'] = '';
		}
		
  		$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('heading_title'),
			'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/futura_InformacoesEmpresa', 'token=' . $this->session->data['token'], 'SSL'),
			'separator' => ' :: '
		);		
		
		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
		
			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}

		$this->data['action'] = $this->url->link('module/futura_InformacoesEmpresa', 'token=' . $this->session->data['token'], 'SSL');
		
		$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
		
		$this->data['token'] = $this->session->data['token'];


		if (isset($this->request->post['config_inf_telefone'])) {
			$this->data['config_inf_telefone'] = $this->request->post['config_inf_telefone'];
		} else {
			$this->data['config_inf_telefone'] = $this->config->get('config_inf_telefone');
		}
		
		if (isset($this->request->post['config_inf_email'])) {
			$this->data['config_inf_email'] = $this->request->post['config_inf_email'];
		} else {
			$this->data['config_inf_email'] = $this->config->get('config_inf_email');
		}
		
		if (isset($this->error['error_inf_status_email'])) {
		    $this->data['error_inf_status_email'] = $this->error['error_inf_status_email'];
		    $this->data['error_warning'] = 'Uma ou mais informações informadas são invalidas, favor, reveja as configurações!';
		} else {
		    $this->data['error_inf_status_email'] = '';		
		}
		
		if (isset($this->request->post['config_inf_status_email'])) {
		    $this->data['config_inf_status_email'] = $this->request->post['config_inf_status_email'];
		} else {
		    $this->data['config_inf_status_email'] = $this->config->get('config_inf_status_email');
		}
		
		
		if (isset($this->request->post['config_inf_dados'])) {
		    $this->data['config_inf_dados'] = $this->request->post['config_inf_dados'];
		} else {
		    $this->data['config_inf_dados'] = $this->config->get('config_inf_dados');
		}	
		
		if (isset($this->request->post['config_inf_twitter'])) {
		    $this->data['config_inf_twitter'] = $this->request->post['config_inf_twitter'];
		} else {
		    $this->data['config_inf_twitter'] = $this->config->get('config_inf_twitter');
		}	
		
		if (isset($this->request->post['config_inf_facebook'])) {
		    $this->data['config_inf_facebook'] = $this->request->post['config_inf_facebook'];
		} else {
		    $this->data['config_inf_facebook'] = $this->config->get('config_inf_facebook');
		}	
		
		if (isset($this->request->post['config_inf_blogger'])) {
		    $this->data['config_inf_blogger'] = $this->request->post['config_inf_blogger'];
		} else {
		    $this->data['config_inf_blogger'] = $this->config->get('config_inf_blogger');
		}	
		
		if (isset($this->request->post['config_inf_youtube'])) {
		    $this->data['config_inf_youtube'] = $this->request->post['config_inf_youtube'];
		} else {
		    $this->data['config_inf_youtube'] = $this->config->get('config_inf_youtube');
		}
                
		if (isset($this->request->post['config_new_pattern_purchase'])) {
		    $this->data['config_new_pattern_purchase'] = $this->request->post['config_new_pattern_purchase'];
		} else {
		    $this->data['config_new_pattern_purchase'] = $this->config->get('config_new_pattern_purchase');
		}                
						
		$this->template = 'module/futura_InformacoesEmpresa.tpl';
		$this->children = array(
			'common/header',
			'common/footer'
		);
				
		$this->response->setOutput($this->render());
	}

	protected function validate() {
		if (!$this->user->hasPermission('modify', 'module/futura_InformacoesEmpresa')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		if (($this->request->post['config_inf_status_email'] == 'enable')&&(!$this->request->post['config_inf_email'])){
		    $this->error['error_inf_status_email'] = 'Quando o Status email estiver habilitado, o campo email deverá estar preenchido!'; 
		}
		
		if (!$this->error) {
			return true;
		} else {
			return false;
		}
	}
	
	public function template() {
		if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			$server = HTTPS_CATALOG;
		} else {
			$server = HTTP_CATALOG;
		}
		
		if (file_exists(DIR_IMAGE . 'templates/' . basename($this->request->get['template']) . '.png')) {
			$image = $server . 'image/templates/' . basename($this->request->get['template']) . '.png';
		} else {
			$image = $server . 'image/no_image.jpg';
		}
		
		$this->response->setOutput('<img src="' . $image . '" alt="" title="" style="border: 1px solid #EEEEEE;" />');
	}		
		
	
}
?>