<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Setting extends CI_Controller {
     
	public function __construct()
	{ 
		parent::__construct();
		if(!isset($_SESSION['admin_uid']))
		{
			redirect(base_url().'adminlogin');
		}
	}
	
	public function site_setting(){
		
		$setting_data_query = $this->Data_access_model->select_all('hs_setting');
		if($setting_data_query->num_rows() > 0){

			$data['all_web_settings'] =$setting_data_query->result();
		}else{ 
			$data['all_web_settings'] = '';
		}

		$opening_schedule_query = $this->Data_access_model->select_all('hs_opening_schedule');
		if($opening_schedule_query->num_rows() > 0){

			$data['opening_schedule'] =$opening_schedule_query->result();
		}else{ 
			$data['opening_schedule'] = '';
		}	
			
       $data['pagetitle'] ='Settings';  
	   $data['active_class']= 17;
	   $data['active_map']=1;
	   $this->load->view('common/header',$data);
	   $this->load->view('setting/general_setting',$data);
	   $this->load->view('common/footer');	
	}
	
	public function update_websettings(){
		
		$this->form_validation->set_rules('valuetext','Value', 'required');
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
			$data = array(
					  'value_text' =>ucwords($this->input->post('valuetext')),
					);
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' => $this->input->post('old_uniqid')),$data); 
			echo 1; 
		}
	}
			
	public function update_section_status(){
		$section_id = $this->input->post('section_id');
		if(!empty($section_id))
		{
			$data = array(
			'value_text' =>$this->input->post('section_value'),
			);
		
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' => $this->input->post('section_id')),$data);    
			if($this->db->affected_rows() > 0){
				echo 1; 
			}else{
				echo 0;
			}
		}
	 }
	 
	 //*********update sender mail address*************//
	public function update_webmail(){
		$resp = 0;
		if($_POST !== '')
		{
			foreach($_POST as $key=>$value)
			{
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>$key),array('value_text'=>$value));
				$resp++;	 
			} 
		}else{
			$resp = 0;
		}
		
		if($resp >0)
		{
			echo 1;
		}else{
			echo 0;
		}
	}
	
	 //*********update smtp mail setting*************//
	public function update_smtp_setting(){
		$resp = 0;
		foreach($_POST as $key=>$value)
		{
			$this->Data_access_model->update_data('hs_setting',array('key_text' =>$key),array('value_text'=>$value));
			$resp++;	 
		} 
		 
		if($resp >0)
		{
			echo 1;
		}else{
			echo 0;
		}
	}
	
	//update opening time status 
	public function update_opening_schedule_status(){
		$schdule_id = $this->input->post('schedule_id');
		if(!empty($schdule_id))
		{
			$data=array('schedule_status' =>$this->input->post('schedule_value'));
			$this->Data_access_model->update_data('hs_opening_schedule',array('schedule_id' => $this->input->post('schedule_id')),$data);    
			if($this->db->affected_rows() > 0){
				echo 1; 
			}else{
				echo 0;
			}
		}
	}
	 
	public function update_opening_hours(){
		
		$this->form_validation->set_rules('update_open_time','Value', 'required');
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
		}else{  
			$data = array(
			'schedule_time' =>ucwords($this->input->post('update_open_time')),
			);
			$this->Data_access_model->update_data('hs_opening_schedule',array('schedule_id' => $this->input->post('old_openid')),$data); 
			echo 1;
		}
	}
   
	public function update_website_image(){
		$img_counter = 0;
		if(isset($_FILES['preloader_img']) && $_FILES['preloader_img']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('preloader_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
				$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['max_height']	= "115";
				$config['max_width'] = "260";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				}  
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'preloader_img'),$data);   
				$img_counter++;    
        }
		
		if(isset($_FILES['favicon_img']) && $_FILES['favicon_img']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('favicon_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
				$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "55";
				$config['width'] = "181";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'favicon_img'),$data);   
				$img_counter++;    
        }
		
		if(isset($_FILES['logo_img']) && $_FILES['logo_img']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('logo_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
				$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "150";
				$config['width'] = "311";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'logo_img'),$data);   
				$img_counter++;   
        }
		
		
		if(isset($_FILES['booking_section_img']) && $_FILES['booking_section_img']['name'] !=="")
		{
			$config['upload_path'] = './uploads/website_images';
            $config['allowed_types'] = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('booking_section_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
				$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "521";
				$config['width'] = "370";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'bookingsection_img'),$data);$img_counter++;   
        }
		
        if(isset($_FILES['banner_section_img']) && $_FILES['banner_section_img']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('banner_section_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
				$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "747";
				$config['width'] = "463";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
				
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'bannersection_img'),$data); $img_counter++; 
        }		
		
		if(isset($_FILES['footer_logo_img']) && $_FILES['footer_logo_img']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('footer_logo_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
					$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "55";
				$config['width'] = "181";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
				
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'footerlogo_img'),$data);   
				$img_counter++;  
        }		
		    
		 	
		
		if(isset($_FILES['mobileapp_img']) && $_FILES['mobileapp_img']['name'] !=="")
		{
			$config['upload_path'] = './uploads/website_images';
            $config['allowed_types'] = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('mobileapp_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
				$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "500";
				$config['width'] = "339";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'mobileapp_img'),$data);   
				$img_counter++;    
        }
		
		if(isset($_FILES['googlestore_img']) && $_FILES['googlestore_img']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('googlestore_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
					$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "60";
				$config['width'] = "175";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'googlestore_img'),$data);   
				$img_counter++;    
        }
		
		if(isset($_FILES['iosstore_img']) && $_FILES['iosstore_img']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('iosstore_img'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
					$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "60";
				$config['width'] = "175";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
				$data = array('value_text' =>$web_image);
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>'iosstore_img'),$data);   
				$img_counter++;    
        }
		
		if($img_counter > 0){
			echo 1;
		}else{
			echo 0;
		}
	}
	
	public function manage_slider(){
        $slider_query = $this->Data_access_model->select_all('hs_banner_slider');
		if($slider_query->num_rows() > 0){
			$data['all_sliders'] =$slider_query->result();
		}else{ 
			$data['all_sliders'] = '';
		}
        $data['pagetitle'] ='Manage Sliders';
		$data['active_class']= 16;
        $this->load->view('common/header',$data);
		$this->load->view('manage_offer/banner_slider',$data);
		$this->load->view('common/footer');	
	}	
	
	public function add_slider(){
		$data['pagetitle'] ='Add Slider';
		$data['active_class']= 16;
        $this->load->view('common/header',$data);
		$this->load->view('manage_offer/add_slider');
		$this->load->view('common/footer');	
	}
	
	public function update_slider(){
        if($this->uri->segment(3)){
			$old_slider_id = $this->uri->segment(3);
			$where_data =array('slider_id' =>$old_slider_id,);
			$query=$this->Data_access_model->select_data('*','hs_banner_slider',$where_data);
		
		    if($query->num_rows() > 0){
				$data['slider_details'] = $query->result();
			}else{
				$data['slider_details'] ='';
			}
		}
		$data['pagetitle'] ='Update Slider';
		$data['active_class']= 16;
		$this->load->view('common/header',$data);
		$this->load->view('manage_offer/update_slider',$data);
		$this->load->view('common/footer');	
	}
	 
	
	public function addslider(){
		   
		//*******slider back image************//
		if(isset($_FILES['slider_image']) && $_FILES['slider_image']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
			$config['allowed_types']    = 'gif|jpg|png|jpeg';
			$this->load->library('upload');
			$this->upload->initialize($config);
			if (!$this->upload->do_upload('slider_image'))
			{
				 echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
					$imagename = $path['file_name'];
				}
		 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "747";
				$config['width'] = "463";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
		 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
		}

		//*******slider back image************//
		if(isset($_FILES['slider_backimage']) && $_FILES['slider_backimage']['name'] !=="")
		{
			$config['upload_path']  = './uploads/website_images';
			$config['allowed_types'] = 'gif|jpg|png|jpeg';
			$this->load->library('upload');
			$this->upload->initialize($config);
			if (!$this->upload->do_upload('slider_backimage'))
			{
			 echo 0;
			}
			else
			{  
				$s_imgdata = array('upload_data' => $this->upload->data());
				foreach($s_imgdata as  $path){
					$s_imagename = $path['file_name'];
				}

				$slider_backimg ='uploads/website_images/'.$s_imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$s_imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "950";
				$config['width'] = "1920";
				$config['new_image'] ='./uploads/website_images/'.$s_imagename;
				//you should have write permission here//
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				}
			} 
		}
					
		if(isset($slider_backimg) && isset($web_image)){
			$data = array('slider_heading' =>$this->input->post('slider_heading'),
			'slider_title'=>$this->input->post('slider_title'),
			'slider_subtitle' =>$this->input->post('slider_subtitle'),
			'slider_button1' =>$this->input->post('slider_button1'),
			'button1_url' =>$this->input->post('button1_url'),
			'slider_button2'  =>$this->input->post('slider_button2'),
			'button2_url' =>$this->input->post('button2_url'),
			'slider_backimage' =>$slider_backimg,
			'slider_image' =>$web_image,
				);
		}else if(isset($slider_backimg)){
			$data = array('slider_heading' =>$this->input->post('slider_heading'),
			'slider_title'=>$this->input->post('slider_title'),
			'slider_subtitle' =>$this->input->post('slider_subtitle'),
			'slider_button1' =>$this->input->post('slider_button1'),
			'button1_url' =>$this->input->post('button1_url'),
			'slider_button2'  =>$this->input->post('slider_button2'),
			'button2_url' =>$this->input->post('button2_url'),
			'slider_backimage' =>$slider_backimg,
				);
		}else if(isset($web_image)){
			$data = array('slider_heading' =>$this->input->post('slider_heading'),
			'slider_title'=>$this->input->post('slider_title'),
			'slider_subtitle' =>$this->input->post('slider_subtitle'),
			'slider_button1' =>$this->input->post('slider_button1'),
			'button1_url' =>$this->input->post('button1_url'),
			'slider_button2'  =>$this->input->post('slider_button2'),
			'button2_url' =>$this->input->post('button2_url'),
			'slider_image' =>$web_image,
				);
		}else{
			$data = array(  'slider_heading' =>$this->input->post('slider_heading'),
			'slider_title'=>$this->input->post('slider_title'),
			'slider_subtitle' =>$this->input->post('slider_subtitle'),
			'slider_button1' =>$this->input->post('slider_button1'),
			'button1_url' =>$this->input->post('button1_url'),
			'slider_button2'  =>$this->input->post('slider_button2'),
			'button2_url' =>$this->input->post('button2_url'),
			);
			}
		$this->Data_access_model->insert_data('hs_banner_slider',$data);
		if($this->db->affected_rows() > 0){ 
			echo 1;
		}
	}
	
	public function updateslider(){
		//************slider background image*********//
		if(isset($_FILES['upslider_backimage']) && $_FILES['upslider_backimage']['name'] !=="")
		{
			$config['upload_path']      = './uploads/website_images';
			$config['allowed_types']    = 'gif|jpg|png|jpeg';
			$this->load->library('upload');
			$this->upload->initialize($config);
			if (!$this->upload->do_upload('upslider_backimage'))
			{
				echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
				$imagename = $path['file_name'];
				}
				//***image resize ***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "950";
				$config['width'] = "1920";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..

				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
				$slider_backimg ='uploads/website_images/'.$imagename;
			}
		}
		//******slider image*******//  
		if(isset($_FILES['upslider_image']) && $_FILES['upslider_image']['name'] !=="")
		{
			$config['upload_path'] = './uploads/website_images';
			$config['allowed_types'] = 'gif|jpg|png|jpeg';
			$this->load->library('upload');
			$this->upload->initialize($config);
			if (!$this->upload->do_upload('upslider_image'))
			{
				echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
					$imagename = $path['file_name'];
				}
				//***image resize ***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "747";
				$config['width'] = "463";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..

				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
				$web_image ='uploads/website_images/'.$imagename;
			}
		}

		if(isset($slider_backimg) && isset($web_image)){
			$data = array('slider_heading' =>$this->input->post('upslider_heading'),
			'slider_title' =>$this->input->post('upslider_title'),
			'slider_subtitle' =>$this->input->post('upslider_subtitle'),
			'slider_button1'  =>$this->input->post('upslider_button1'),
			'button1_url' =>$this->input->post('upslider_btn1url'),
			'slider_button2'  =>$this->input->post('upslider_button2'),
			'button2_url' =>$this->input->post('upslider_btn2url'),
			'slider_backimage' =>$slider_backimg,
			'slider_image' =>$web_image,
			);
		}else if(isset($slider_backimg)){
			$data = array('slider_heading' =>$this->input->post('upslider_heading'),
			'slider_title' =>$this->input->post('upslider_title'),
			'slider_subtitle' =>$this->input->post('upslider_subtitle'),
			'slider_button1'  =>$this->input->post('upslider_button1'),
			'button1_url' =>$this->input->post('upslider_btn1url'),
			'slider_button2'  =>$this->input->post('upslider_button2'),
			'button2_url' =>$this->input->post('upslider_btn2url'),
			'slider_backimage' =>$slider_backimg,
			);
		}else if(isset($web_image)){
			$data = array('slider_heading' =>$this->input->post('upslider_heading'),
			'slider_title' =>$this->input->post('upslider_title'),
			'slider_subtitle' =>$this->input->post('upslider_subtitle'),
			'slider_button1'  =>$this->input->post('upslider_button1'),
			'button1_url' =>$this->input->post('upslider_btn1url'),
			'slider_button2'  =>$this->input->post('upslider_button2'),
			'button2_url' =>$this->input->post('upslider_btn2url'),
			'slider_image' =>$web_image,
			);
		}else{
			$data = array('slider_heading' =>$this->input->post('upslider_heading'),
			'slider_title' =>$this->input->post('upslider_title'),
			'slider_subtitle' =>$this->input->post('upslider_subtitle'),
			'slider_button1'  =>$this->input->post('upslider_button1'),
			'button1_url' =>$this->input->post('upslider_btn1url'),
			'slider_button2'  =>$this->input->post('upslider_button2'),
			'button2_url' =>$this->input->post('upslider_btn2url'),
			);
		}

		$this->Data_access_model->update_data('hs_banner_slider',array('slider_id' =>$this->input->post('old_slider_id')),$data); 
		echo 1;
	}
	
	public function update_slider_status(){
		$data=array(
		'slider_status' =>$this->input->post('slider_value'),
		);
		$this->Data_access_model->update_data('hs_banner_slider',array('slider_id' => $this->input->post('slider_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	}
	 
	public function delete_slider(){
		if($this->uri->segment(3)){
			$old_slider_id =$this->uri->segment(3);
			$this->Data_access_model->delete_data('hs_banner_slider',array('slider_id' =>$old_slider_id));
			redirect(base_url("setting/manage_slider"));
		}
	}
	
	public function update_map_locatiion(){
      	    
		$lat = $this->input->post('latitude');
		$lng = $this->input->post('longitude');
		$map_api = $this->input->post('map_apikey');
		if(!empty($map_api)){
			$this->Data_access_model->update_data('hs_setting',array('key_text' =>'map_apikey'),array('value_text' =>$map_api));
			$api_resp =1;
		}

		if(!empty($lat) && !empty($lng)){
			$this->Data_access_model->update_data('hs_setting',array('key_text' =>'map_latitude'),array('value_text' =>$lat));
			$this->Data_access_model->update_data('hs_setting',array('key_text' =>'map_longitude'),array('value_text' =>$lng));
			$latlng_resp = 2;
		}
			
		if(isset($api_resp) && isset($latlng_resp) ){
			echo 1;
		}else if(isset($api_resp)){
			echo 1;
		}else if(isset($latlng_resp)){
			echo 1;
		}else{
			echo 0;
		}
	}

	public function compliance_page(){
		
		$data['pagetitle'] ='Compliance Pages';
		$data['active_class']= 17;
		$this->load->view('common/header',$data);
		$this->load->view('setting/compliance_pages',$data);
		$this->load->view('common/footer');	
	}
	
	public function update_term_condition(){
		
		$tc_pageid = $this->input->post('tc_page_id');
		$term_condition = $this->input->post('term_condition');
		$termdate_id = $this->hs->getsetting_uniq_id('termupdate_date');
		$tdate_id = $termdate_id['uniq_id'];
        $term_date = date('d M Y');
 	
		if(!empty($tc_pageid)){
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' =>$tc_pageid),array('value_text' =>$term_condition));
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' =>$tdate_id),array('value_text' =>$term_date),array('value_text' =>$term_date));
			echo 1;
		}else{
			echo 0;
		}
	}
	
	public function update_privacy_policy(){
		
		$pp_pageid = $this->input->post('pp_page_id');
		$privacy_policy = $this->input->post('pp_content');
		$pp_date_id = $this->hs->getsetting_uniq_id('privacyupdate_date');
		$ppdate_id = $pp_date_id['uniq_id'];
		$pp_update_date = date('d M Y');			
		if(!empty($pp_pageid)){
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' =>$pp_pageid),array('value_text' =>$privacy_policy));
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' =>$ppdate_id),array('value_text' =>$pp_update_date));
			echo 1;
		}else{
			echo 0;
		}
	}
	
	public function gdpr_cookie_update(){
	 
		$update_resp = 0;
		foreach($_POST as $key =>$value){
			if(!empty($key) && !empty($value)){
				$this->Data_access_model->update_data('hs_setting',array('key_text' =>$key),
				array('value_text' =>$value));
				$update_resp ++;
			}
		}
		$image_resp =0;
		if(isset($_FILES['gdpr_image']) && $_FILES['gdpr_image']['name'] !==""){
			
			$config['upload_path']      = './uploads/website_images';
            $config['allowed_types']    = 'gif|jpg|png|jpeg';
            $this->load->library('upload');
            $this->upload->initialize($config);
			if (!$this->upload->do_upload('gdpr_image'))
			{
				$error = array('error' => $this->upload->display_errors());
				echo 0;
			}
			else
			{  
				$imgdata = array('upload_data' => $this->upload->data());
				foreach($imgdata as  $path){
					$imagename = $path['file_name'];
				}
				 
				$web_image ='uploads/website_images/'.$imagename;
				//***image resize for***// 
				$config['image_library'] = 'gd2';
				$config['source_image']	='./uploads/website_images/'.$imagename;
				$config['create_thumb'] = FALSE;
				$config['maintain_ratio'] = FALSE;
				$config['height']	= "115";
				$config['width'] = "115";
				$config['new_image'] ='./uploads/website_images/'.$imagename;
				//you should have write permission here..
				 
				$this->image_lib->initialize($config);
				if(!$this->image_lib->resize()){
					$error['resize'] = $this->image_lib->display_errors();
				} 
			} 
		
			$this->Data_access_model->update_data('hs_setting',array('key_text' =>'gdpr_image'),
			array('value_text' =>$web_image));
			if($this->db->affected_rows() > 0){
				$image_resp++; 
			}
		}
	
		if($update_resp >0 && $image_resp >0){
			echo 1;
		}else if($update_resp >0){
			echo 1;
		}else if($image_resp >0){ 
			echo 1;
		}else{
			echo 0;
		}
	}
 
	public function payment_setting(){
		$data['pagetitle'] ='Payment Setting';
		$data['active_class']= 17;
		$this->load->view('common/header',$data);
		$this->load->view('setting/payment_setting',$data);
		$this->load->view('common/footer');	
	}

	public function paypal_setting_update(){
		if(!empty($_POST['paypal_email'])){
			$paypalemail = $_POST['paypal_email'];
			$this->Data_access_model->update_data('hs_setting',array('key_text'=>'paypal_email'),
			array('value_text' =>$paypalemail));
			echo 1;
		}
	}

	public function payumoney_setting_update(){
		if(!empty($_POST['payumoney_key']) && !empty($_POST['payumoney_salt']) ){
			$response = 0;
			foreach($_POST as $key=>$value){
				$this->Data_access_model->update_data('hs_setting',array('key_text'=>$key),
				array('value_text' =>$value));
				$response++;
			}
			
			if($response > 0){
				echo 1;
			}else{
				echo 0;
			}
		}
	}
	
	public function currency_setting_update(){
		if(!empty($_POST['currency_convert_api']) && !empty($_POST['currency_code']) && !empty($_POST['currency_symbol'])){
			$response = 0;
			foreach($_POST as $key=>$value){
				$this->Data_access_model->update_data('hs_setting',array('key_text'=>$key),
				array('value_text' =>$value));
				$response++;
			}
			
			if($response > 0){
				echo 1;
			}else{
				echo 0;
			}
		}
	}

	public function payment_option_status(){
	    $payopt_id = $this->input->post('payopt_id');
		if(!empty($payopt_id)){
			$data=array(
			'value_text' =>$this->input->post('payopt_value'),
			);
		
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' =>$payopt_id),$data);    
		    if($this->db->affected_rows() > 0){
			    echo 1; 
	        }else{
				echo 0;
		    }
		}
	 }
	 
	 public function smtp_option_status(){
	    $smtp_id = $this->input->post('smtp_opt_id');
		if(!empty($smtp_id)){
			$data=array(
			'value_text' =>$this->input->post('smtp_opt_value'),
			);
		
			$this->Data_access_model->update_data('hs_setting',array('uniq_id' =>$smtp_id),$data);    
		    if($this->db->affected_rows() > 0){
			    echo 1; 
	        }else{
				echo 0;
		    }
		}
	 }
	 
	 
	public function order_status(){
	    $odrid = $this->input->post('odr_id');
		if(!empty($odrid)){
			$order_status = $this->input->post('odr_value');
			$data=array(
			'order_status' =>$this->input->post('odr_value'),
			);
		
			$this->Data_access_model->update_data('hs_user_orders',array('order_id' =>$odrid),$data);    
		    if($this->db->affected_rows() > 0)
			{
				if($order_status != 0)
				{
					$order_details = $this->Data_access_model->select_data('*','hs_user_orders',array('order_id' =>$odrid));
					if($order_details->num_rows() > 0)
					{
						$order_info = $order_details->row();
					
						$order_number = $order_info->order_uniqid;
						$order_uid = $order_info->order_uid;
						
						$user_detail = $this->Data_access_model->select_data('*','hs_user',array('user_id' =>$order_uid));
						if($user_detail->num_rows() > 0)
						{
							$user_info = $user_detail->row();
							$uname = $user_info->user_name;
							$user_email = $user_info->user_email;
						}
						
						if($order_status ==  1)
						{
							$email_content = $this->hs->getwebsettings('odr_intransit_template');  
							$subject = $this->hs->getwebsettings('odr_intransit_subject');
					
						}else if($order_status == 2)
						{
							$email_content = $this->hs->getwebsettings('odr_delivered_template');  
							$subject = $this->hs->getwebsettings('odr_delivered_subject');
					
						}else if($order_status == 3)
						{
							$email_content = $this->hs->getwebsettings('odr_canceled_template');  
							$subject = $this->hs->getwebsettings('odr_canceled_subject');
						}

						$email_content = str_replace("[username]",$uname, $email_content);
						$email_content = str_replace("[order_number]", $order_number,$email_content);
						$email_content = str_replace("[break]", "<br>", $email_content);
						$data['emcontent'] = $email_content;
					
						$email_template = $this->load->view('theme/email_template',$data,true);
						//sending mail
						$this->hs->send_mail($user_email,$subject,$email_template);
					}
				}	
					echo 1; 
	        }else{
				echo 0;
		    }
		}
	 }
	
	public function email_setting(){
		$data['pagetitle'] ='Email Setting';
		$data['active_class']= 17;
		$this->load->view('common/header',$data);
		$this->load->view('setting/email_setting',$data);
		$this->load->view('common/footer');	
	 }
}
