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

class Studio extends CI_Controller {
	private $upload_config;
     public function __construct() {
        parent:: __construct();
		parse_str($_SERVER['QUERY_STRING'], $_GET);				
		//$this->load->library('grocery_crud');
		date_default_timezone_set('Asia/Calcutta');
		$email = array(
						'protocol' => 'smtp',
						'smtp_host' => 'mail.apexsoftindia.com',
						'smtp_port' => 25,
						'smtp_user' => 'test@apexsoftindia.com',
						'smtp_pass' => '9787119377',
						/*'smtp_host' => 'ssl://smtp.gmail.com',
						'smtp_port' => 465,
						'smtp_user' => 'vigneshteamwork@gmail.com',
						'smtp_pass' => 'teamwork007',*/
						'mailtype' => 'html',
						'charset' => 'utf-8'
					);
		$this->session->set_userdata(array('config'=>$email));
    }
	
	// Login Page Process Start
	function check_cur_mail(){
	$config = array();
	$config['useragent']           = "CodeIgniter";
	$config['mailpath']            = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
	$config['protocol']            = "smtp";
	$config['smtp_host']           = "localhost";
	$config['smtp_port']           = "25";
	$config['mailtype'] = 'html';
	$config['charset']  = 'utf-8';
	$config['newline']  = "\r\n";
	$config['wordwrap'] = TRUE;

	$this->load->library('email');
	$this->email->initialize($config);

	$this->email->from('dev@jananitravels.in', 'admin');
	$this->email->to('dev@jananitravels.in');
	$this->email->cc('dev@jananitravels.in'); 
	$this->email->bcc('dev@jananitravels.in'); 
	$this->email->subject('Registration Verification: Continuous Imapression');
	$msg = "Test";

	$this->email->message($msg);   
	//$this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));

	if (!$this->email->send()){
	show_error($this->email->print_debugger());
	}else{
	echo "Success <br>";
	}
	}
	public function index()
	{
		$data['page_title']="Login";
		$data['message'] = "";
		$this->load->view('login', $data);
	}
	function check_login(){
		$uname=$this->input->post('uname');
		$pwd=$this->input->post('pwd');
		if($uname=='' || $pwd==''){
			echo "<div class='alert alert-warning'>
					<a href='#' class='close' data-dismiss='alert'>&times;</a>
					<strong>Warning !</strong> Please fill Username &amp; Password.
				</div>";
		}else{
			$query=$this->db->get_where('admin_settings', array('uname'=>$uname, 'pwd'=>$pwd, 'status'=>'Active'));
			$query_user=$this->db->get_where('user', array('usercode'=>$uname, 'pwd'=>$pwd, 'status'=>'yes'));
			$query_client=$this->db->get_where('client', array('client_code'=>$uname, 'pwd'=>$pwd, 'status'=>'yes'));
			if($query->num_rows()>0){
					foreach($query->result() as $row){
						$user_id = $row->admin_id;
						$this->session->set_userdata(array('user_id'=>$user_id));
						$this->session->set_userdata(array('uname'=>$uname));
						$this->session->set_userdata(array('user_type'=>'admin'));
					}
			}elseif($query_user->num_rows()>0){
					foreach($query_user->result() as $row){
						$user_id = $row->usercode;
						$this->session->set_userdata(array('user_id'=>$user_id));
						$this->session->set_userdata(array('uname'=>$uname));
						$this->session->set_userdata(array('user_type'=>'user'));
					}
			}elseif($query_client->num_rows()>0){
					foreach($query_client->result() as $row){
						$user_id = $row->client_code;
						$this->session->set_userdata(array('user_id'=>$user_id));
						$this->session->set_userdata(array('uname'=>$uname));
						$this->session->set_userdata(array('user_type'=>'client'));
					}
			}else{
					echo "<div class='alert alert-danger'>
							<a href='#' class='close' data-dismiss='alert'>&times;</a>
							   <strong>Error!</strong> Invalid Username / Password.
						</div>";
			}
		}
	}
	
	// Login Page process End
	
	// Forget Password Process Start
	
	public function forget_password()
	{
		$data['page_title']="Forget Password";
		$data['message'] = "";
		$this->load->view('forget_password', $data);
	}
	function src_forget_password(){
		extract ($_POST);
		$data['page_title']="Forget Password";
		$data['message']="";
		
		$this->form_validation->set_error_delimiters('<div id="error_message">', '</div>');
		$this->form_validation->set_rules('email_id', 'Email Id', 'required|valid_email');
		
		if ($this->form_validation->run() == FALSE){
			$data['message']="<div class='alert alert-danger alert-dismissable'>
								<a href='#' class='close' data-dismiss='alert alert-error'></a>
								 <strong>Warring !</strong> Invalid Mail Id
							</div>";
			$data['page_title'] = "Forget Password";	
			$this->load->view('forget_password', $data);
		}else{
			$query=$this->db->get_where('admin_settings', array('email_id'=>$email_id , 'status'=>'Active'));
				foreach($query->result() as $row){
							$name = $row->uname;
							$email_id = $row->email_id;
							$pwd = $row->pwd;
					}
			if($query->num_rows()>0){
				//load email library
				//$config_mail = $this->load->library('email', $this->session->userdata('config'));
				//$this->email->set_newline("\r\n");
				$config = array();
				$config['useragent'] = "CodeIgniter";
				$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
				$config['protocol'] = "smtp";
				$config['smtp_host'] = "localhost";
				$config['smtp_port'] = "25";
				$config['mailtype'] = 'html';
				$config['charset']  = 'utf-8';
				$config['newline']  = "\r\n";
				$config['wordwrap'] = TRUE;

				$this->load->library('email');
				$this->email->initialize($config);

				//set email information and content
				$this->email->from('dev@jananitravels.in', 'Matrimony');
				//$this->email->from($config_mail,'Matrimony');
				$this->email->to($email_id);
				$message = "Dear ".$name."<br/><br/>Welcome to Travels,<br>
					Here is your login details<br><br>
					<b>Username : </b>".$name."<br>
					<b>Password : </b>".$pwd."<br>
					Please, keep the above details are very confidential.
					<a href='".base_url()."'>Click Here to login</a><br><br>";
				$this->email->subject('Forget Password');
				$this->email->message($message);
				if (!$this->email->send()){
					show_error($this->email->print_debugger());
				}else{
					$data['message']="<div class='alert alert-success alert-dismissable'>
									<a href='#' class='close' data-dismiss='alert alert-error'></a>
									 <strong>Success !</strong> Password Send Your Mail ID.
								</div>";
					$data['page_title'] = "Forget Password";	
					$this->load->view('forget_password', $data);
				}
			}else{
					$data['message']="<div class='alert alert-danger alert-dismissable'>
									<a href='#' class='close' data-dismiss='alert alert-error'></a>
									 <strong>Warring !</strong> This Mail Id not registered.
								</div>";
					$data['page_title'] = "Forget Password";	
					$this->load->view('forget_password', $data);
			}
		}
	}
	
	// Forget Password Process End
	
	function logout(){
		$this->session->unset_userdata('user_id');
		$this->session->unset_userdata('uname');
		$data['page_title']="Login";
		$data['message'] = "";
				
		$this->load->view('login', $data);
	}
	
	// Start Admin Process 
	
	function admin_panel(){
		$data['page_title']="Dasboard";
		$data['message'] = "";
				
		$this->load->view('admin/admin_panel', $data);
	}
	
	// Start Change Password
	
	function change_password(){
		$data['page_title']="Change Password";
		$data['message'] = "";

		$this->load->view('admin/change_password', $data);
	}
	function src_change_password(){
	extract($_POST);
		$data['page_title']="Change Password";
		$data['message']="";
		$this->form_validation->set_error_delimiters('<div id="error_message">', '</div>');
		$this->form_validation->set_rules('current_pwd', 'Current Password', 'required');
		$this->form_validation->set_rules('new_pwd', 'New password', 'required');
		$this->form_validation->set_rules('con_new_pwd', 'Verify Password', 'required|matches[new_pwd]');
		
		if ($this->form_validation->run() == FALSE){
			$data['message']="<div class='alert alert-warning'>
					<a href='#' class='close' data-dismiss='alert'>&times;</a>
					<strong>Warning !</strong> ".validation_errors()."
				</div>";
			$this->load->view('admin/change_password', $data);
		}else{
			$user_id=$this->session->userdata('user_id');
			
			if($this->session->userdata('user_type') == 'admin'){
				$this->db->select('*');
				$this->db->from('admin_settings');
				$this->db->where('admin_id',$user_id);
				$this->db->where('pwd',$current_pwd);
				$check_pwd = $this->db->get();
				if($check_pwd->num_rows()>0){
					$query = $this->db->update('admin_settings',array('pwd'=>$new_pwd),array('admin_id'=>$user_id));
					$data['message']="<div class='alert alert-success'>
							<a href='#' class='close' data-dismiss='alert'>&times;</a>
							<strong>Success !</strong> Your Password is Change Successfully.
						</div>";
					$this->load->view('admin/change_password', $data);
				}else{
					$data['message']="<div class='alert alert-danger'>
							<a href='#' class='close' data-dismiss='alert'>&times;</a>
							<strong>Warning !</strong> Current Password is not valid.
						</div>";
					$this->load->view('admin/change_password', $data);
				}
			}elseif($this->session->userdata('user_type') == 'client'){
				$this->db->select('*');
				$this->db->from('client');
				$this->db->where('client_code',$user_id);
				$this->db->where('pwd',$current_pwd);
				$check_pwd = $this->db->get();
				if($check_pwd->num_rows()>0){
					$query = $this->db->update('client',array('pwd'=>$new_pwd),array('client_code'=>$user_id));
					$data['message']="<div class='alert alert-success'>
							<a href='#' class='close' data-dismiss='alert'>&times;</a>
							<strong>Success !</strong> Your Password is Change Successfully.
						</div>";
					$this->load->view('admin/change_password', $data);
				}else{
					$data['message']="<div class='alert alert-danger'>
							<a href='#' class='close' data-dismiss='alert'>&times;</a>
							<strong>Warning !</strong> Current Password is not valid.
						</div>";
					$this->load->view('admin/change_password', $data);
				}
			}else{
				$this->db->select('*');
				$this->db->from('user');
				$this->db->where('usercode',$user_id);
				$this->db->where('pwd',$current_pwd);
				$check_pwd = $this->db->get();
				if($check_pwd->num_rows()>0){
					$query = $this->db->update('user',array('pwd'=>$new_pwd),array('usercode'=>$user_id));
					$data['message']="<div class='alert alert-success'>
							<a href='#' class='close' data-dismiss='alert'>&times;</a>
							<strong>Success !</strong> Your Password is Change Successfully.
						</div>";
					$this->load->view('admin/change_password', $data);
				}else{
					$data['message']="<div class='alert alert-danger'>
							<a href='#' class='close' data-dismiss='alert'>&times;</a>
							<strong>Warning !</strong> Current Password is not valid.
						</div>";
					$this->load->view('admin/change_password', $data);
				}
			}
			
			
		}
	}
	
	// End Change Password
	
	// Start Users
	
	function user_list(){
		$data['page_title']="Users List";
		$data['message'] = "";

		$this->load->view('admin/user_list', $data);
	}
	function user_view(){
		$user_id = $this->uri->segment(3);
		$data['page_title']="Users Details";
		$data['message'] = "";
		$data['user_id'] = $user_id;
		$this->load->view('admin/user_view', $data);
	}
	function add_user(){
		$data['page_title']="Add Users";
		$data['message'] = "";

		$this->load->view('admin/add_user', $data);
	}
	public function src_add_user()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Name', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Users";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_user', $data);
		}else{
			$this->db->select('*');
			$this->db->from('user');
			$this->db->order_by('user_id','desc');
			$this->db->limit(1);
			$last_rec_list = $this->db->get();
			if($last_rec_list->num_rows()>0){
			foreach($last_rec_list->result() as $last_row){
			$user_id = $last_row->user_id + 1;
			}
			}else{
			$user_id = 1;
			}
			$usercode = "YASH_".$user_id;
			$data = array(
					   'name' 		=> $name,
					   'email_id' 	=> $email_id,
					   'mobile_no' 	=> $mobile_no,
					   'usercode' 	=> $usercode,
					   'pwd' 		=> '12345',
					   'status' 	=> 'yes'
			);
			$insert_user  = $this->db->insert('user', $data);
				if($insert_user!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Users Details Stored Successfully.
									 </div>";
					$data['page_title'] = "Add Users";	
					$this->load->view('admin/add_user', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Users Details Stored Failed.
									</div>";
					$data['page_title'] = "Add Users";	
					$this->load->view('admin/add_user', $data);
				}
		}
	}
	function edit_user(){
	$user_id = $this->uri->segment(3);
		$data['page_title']="Update Users";
		$data['message'] = "";
		$data['user_id'] = $user_id;
		$this->load->view('admin/edit_user', $data);
	}
	public function src_user_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Name', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update Users";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['user_id'] = $user_id;
			$this->load->view('admin/edit_user', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('user');
			$this->db->where('name',$name);
			$this->db->where('user_id != ',$user_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Users Name is Already Exist.
									</div>";
				$data['page_title'] = "Update Users";	
				$data['user_id'] = $user_id;
				$this->load->view('admin/edit_user', $data);
			}else{
				$update_user  = $this->db->update('user', array( 'name' => $name,'email_id' => $email_id,'mobile_no' => $mobile_no,'pwd' => $pwd,'status'=>'yes'), array('user_id'=>$user_id));
				if($update_user!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Users Details Update Successfully.
									 </div>";
					$data['page_title'] = "Update Users";	
					$data['user_id'] = $user_id;
					$this->load->view('admin/edit_user', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Users Details Update Failed.
									</div>";
					$data['page_title'] = "Update Users";	
					$data['user_id'] = $user_id;
					$this->load->view('admin/edit_user', $data);
				}
			}
		}
	}
	function delete_user(){
		$id=$this->input->post('user_id');
		$delete_user=$this->db->delete('user', array('user_id'=>$id));
				if($delete_user!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Users Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Users Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_user()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Users ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Users List";
			$this->load->view('admin/user_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_user=$this->db->delete('user', array('user_id'=>$checked_id[$i]));
			}
				if($delete_user!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Users Details Delete Successfully.
										</div>";
					$data['page_title']="Users List";
					$this->load->view('admin/user_list', $data);
					redirect('studio/user_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Users Details Delete Failed.
										</div>";
					$data['page_title']="Users List";
					$this->load->view('admin/user_list', $data);
					redirect('studio/user_list');
				}
		}
	}
	
	// End Users
	
	// Start News Master
	
	function news_list(){
		$data['page_title']="News List";
		$data['message'] = "";

		$this->load->view('admin/news_list', $data);
	}
	function news_view(){
		$star_id = $this->uri->segment(3);
		$data['page_title']="News Details";
		$data['message'] = "";
		$data['news_id'] = $news_id;
		$this->load->view('admin/news_view', $data);
	}
	function add_news(){
		$data['page_title']="Add News";
		$data['message'] = "";

		$this->load->view('admin/add_news', $data);
	}
	public function src_add_news()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('news', 'News', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add News";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_news', $data);
		}else{
			$data = array(
					   'news' 		=> $news,
					   'status' 		=> 'yes'
			);
			$insert_news  = $this->db->insert('news', $data);
				if($insert_news!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your News Details Stored Successfully.
									 </div>";
					$data['page_title'] = "Add News";	
					$this->load->view('admin/add_news', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your News Details Stored Failed.
									</div>";
					$data['page_title'] = "Add News";	
					$this->load->view('admin/add_news', $data);
				}
		}
	}
	function edit_news(){
	$news_id = $this->uri->segment(3);
		$data['page_title']="Update News";
		$data['message'] = "";
		$data['news_id'] = $news_id;
		$this->load->view('admin/edit_news', $data);
	}
	public function src_news_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('news', 'News Name', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update News";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['news_id'] = $news_id;
			$this->load->view('admin/edit_news', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('news');
			$this->db->where('news',$news);
			$this->db->where('news_id != ',$news_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> News is Already Exist.
									</div>";
				$data['page_title'] = "Update News";	
				$data['news_id'] = $news_id;
				$this->load->view('admin/edit_news', $data);
			}else{
				$update_news  = $this->db->update('news', array( 'news'=> $news,'status'=>'yes'), array('news_id'=>$news_id));
				if($update_news!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your News Details Update Successfully.
									 </div>";
					$data['page_title'] = "Update News";	
					$data['news_id'] = $news_id;
					$this->load->view('admin/edit_news', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your News Details Update Failed.
									</div>";
					$data['page_title'] = "Update News";	
					$data['news_id'] = $news_id;
					$this->load->view('admin/edit_news', $data);
				}
			}
		}
	}
	function delete_news(){
		$id=$this->input->post('news_id');
		$delete_news=$this->db->delete('news', array('news_id'=>$id));
				if($delete_news!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your News Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your News Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_news()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'News ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="News List";
			$this->load->view('admin/news_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_caste=$this->db->delete('news', array('news_id'=>$checked_id[$i]));
			}
				if($delete_caste!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your News Details Delete Successfully.
										</div>";
					$data['page_title']="News List";
					$this->load->view('admin/news_list', $data);
					redirect('studio/news_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your News Details Delete Failed.
										</div>";
					$data['page_title']="News List";
					$this->load->view('admin/news_list', $data);
					redirect('studio/news_list');
				}
		}
	}
	
	// End News Master
	
	// Newsletter Start
	
	function newsletter(){
		$data['page_title']="Newsletter";
		$data['message'] = "";
		
		$this->load->view('admin/newsletter', $data);
	}
	
	function src_newsletter(){
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('customer_id', 'Member ID', 'required');
		$this->form_validation->set_rules('message', 'Member ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Newsletter";
			$this->load->view('admin/newsletter', $data);
		}else{
			$cnt = count($user_id);
			for($i=0;$i<$cnt;$i++){
				$user_id[$i];
				
				$this->db->select('*');
				$this->db->from('customer');
				$this->db->where('customer_id',$customer_id[$i]);
					$members_list = $this->db->get();
						if($members_list->num_rows()>0){
							foreach($members_list->result() as $row){
								$email_id = $row->email_id;
								//load email library
								$config_mail = $this->load->library('email', $this->session->userdata('config'));
								$this->email->set_newline("\r\n");

								//set email information and content
								$this->email->from($config_mail,'Yash Photography');
								$this->email->to($email_id);
								$this->email->subject('Yash Photography');
								$this->email->message($message);
								if (!$this->email->send()) {
									show_error($this->email->print_debugger());
								}
							}
						}
			}
			
			$data['message'] = "<div class='alert alert-success fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-check'></i>
								<strong>Success!</strong> Message Send Successfully
								</div>";
			$data['page_title']="Newsletter";
			$this->load->view('admin/newsletter', $data);			
		}
	}
	
	
	// Newsletter End

	// Start Client Master
	
	function client_list(){
		$data['page_title']="Client List";
		$data['message'] = "";

		$this->load->view('admin/client_list', $data);
	}
	function client_view(){
		$client_id = $this->uri->segment(3);
		$data['page_title']="Client Details";
		$data['message'] = "";
		$data['client_id'] = $client_id;
		$this->load->view('admin/client_view', $data);
	}
	function add_client(){
		$data['page_title']="Add Client";
		$data['message'] = "";

		$this->load->view('admin/add_client', $data);
	}
	public function src_add_client()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Client Name', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Client";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_client', $data);
		}else{
				$this->db->select('*');
				$this->db->from('client');
				$this->db->where('status','yes');
				$this->db->order_by('client_id','desc');
				$this->db->limit(1);
				$get_branch_details = $this->db->get();
				$unique_text = "CLIENT";
				if($get_branch_details->num_rows()>0){
					foreach($get_branch_details->result() as $row){
						$get_unique_id = $row->client_id;
						$increment_unique_id = $get_unique_id + 1;
						$get_len = strlen($increment_unique_id);
						if($get_len == '1'){
							$client_code = $unique_text."00".$increment_unique_id;
						}elseif($get_len == '2'){
							$client_code = $unique_text."0".$increment_unique_id;
						}else{
							$client_code = $unique_text.$increment_unique_id;
						}
					}
				}else{
					$increment_unique_id = 1;
					$client_code = $unique_text."".'1';
				}
			$data = array(
						'client_code' 		=> $client_code,
						'name' 				=> $name,
						'mobile_no' 		=> $mobile_no,
						'email_id' 			=> $email_id,
						'address' 			=> $address,
						'pwd' 				=> '123456',	
						'status' 			=> 'yes'
			);
			$insert_client  = $this->db->insert('client', $data);
				if($insert_client!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Client Details Stored Successfully.
										</div>";
					$data['page_title'] = "Add Client";	
					$this->load->view('admin/add_client', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Client Details Stored Failed.
									</div>";
					$data['page_title'] = "Add Client";	
					$this->load->view('admin/add_client', $data);
				}
		}
	}
	function edit_client(){
	$client_id = $this->uri->segment(3);
		$data['page_title']="Update Client";
		$data['message'] = "";
		$data['client_id'] = $client_id;
		$this->load->view('admin/edit_client', $data);
	}
	public function src_client_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Client Name', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update Client";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['client_id'] = $client_id;
			$this->load->view('admin/edit_client', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('client');
			$this->db->where('name',$name);
			$this->db->where('client_id != ',$client_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Client Name is Already Exist.
									</div>";
				$data['page_title'] = "Update Client";	
				$data['client_id'] = $client_id;
				$this->load->view('admin/edit_client', $data);
			}else{
				$update_client  = $this->db->update('client', array('name' => $name,'mobile_no' => $mobile_no,'email_id' => $email_id,'address' => $address,'status' => 'yes'), array('client_id'=>$client_id));
				if($update_client!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Client Details Update Successfully.
										</div>";
					$data['page_title'] = "Update Client";	
					$data['client_id'] = $client_id;
					$this->load->view('admin/edit_client', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Client Details Update Failed.
									</div>";
					$data['page_title'] = "Update Client";	
					$data['client_id'] = $client_id;
					$this->load->view('admin/edit_client', $data);
				}
			}
		}
	}
	function delete_client(){
		$id=$this->input->post('client_id');
		$delete_client=$this->db->delete('client', array('client_id'=>$id));
				if($delete_client!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Client Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Client Details Delete Failed.
						</div>";
				}
	}

	public function delete_selected_client()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Client ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Client List";
			$this->load->view('admin/client_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_client=$this->db->delete('client', array('client_id'=>$checked_id[$i]));
			}
				if($delete_client!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Client Details Delete Successfully.
										</div>";
					$data['page_title']="Client List";
					$this->load->view('admin/client_list', $data);
					redirect('studio/client_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Client Details Delete Failed.
										</div>";
					$data['page_title']="Client List";
					$this->load->view('admin/client_list', $data);
					redirect('studio/client_list');
				}
		}
	}

	// End Client Master
	
	// Start Customer Master
	
	function customer_list(){
		$data['page_title']="Customer List";
		$data['message'] = "";

		$this->load->view('admin/customer_list', $data);
	}
	function customer_view(){
		$customer_id = $this->uri->segment(3);
		$data['page_title']="Customer Details";
		$data['message'] = "";
		$data['customer_id'] = $customer_id;
		$this->load->view('admin/customer_view', $data);
	}
	function add_customer(){
		$data['page_title']="Add Customer";
		$data['message'] = "";

		$this->load->view('admin/add_customer', $data);
	}
	public function src_add_customer()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Customer Name', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Customer";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_customer', $data);
		}else{
				$this->db->select('*');
				$this->db->from('customer');
				$this->db->where('status','yes');
				$this->db->order_by('customer_id','desc');
				$this->db->limit(1);
				$get_branch_details = $this->db->get();
				$unique_text = "YASH";
				if($get_branch_details->num_rows()>0){
					foreach($get_branch_details->result() as $row){
						$get_unique_id = $row->customer_id;
						$increment_unique_id = $get_unique_id + 1;
						$get_len = strlen($increment_unique_id);
						if($get_len == '1'){
							$customer_code = "YASH00".$increment_unique_id;
						}elseif($get_len == '2'){
							$customer_code = "YASH0".$increment_unique_id;
						}else{
							$customer_code = "YASH".$increment_unique_id;
						}
					}
				}else{
					$increment_unique_id = 1;
					$customer_code = $unique_text."".'1';
				}
			$data = array(
					   'customer_code' 		=> $customer_code,
					   'name' 				=> $name,
					   'mobile_no' 			=> $mobile_no,
					   'email_id' 			=> $email_id,
					   'address' 			=> $address,
					   'status' 			=> 'yes'
			);
			$insert_customer  = $this->db->insert('customer', $data);
				if($insert_customer!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Customer Details Stored Successfully.
									 </div>";
					$data['page_title'] = "Add Customer";	
					$this->load->view('admin/add_customer', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Customer Details Stored Failed.
									</div>";
					$data['page_title'] = "Add Customer";	
					$this->load->view('admin/add_customer', $data);
				}
		}
	}
	function edit_customer(){
	$customer_id = $this->uri->segment(3);
		$data['page_title']="Update Customer";
		$data['message'] = "";
		$data['customer_id'] = $customer_id;
		$this->load->view('admin/edit_customer', $data);
	}
	public function src_customer_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Customer Name', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update Customer";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['customer_id'] = $customer_id;
			$this->load->view('admin/edit_customer', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('customer');
			$this->db->where('name',$name);
			$this->db->where('customer_id != ',$customer_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Customer Name is Already Exist.
									</div>";
				$data['page_title'] = "Update Customer";	
				$data['customer_id'] = $customer_id;
				$this->load->view('admin/edit_customer', $data);
			}else{
				$update_customer  = $this->db->update('customer', array('name' => $name,'mobile_no' => $mobile_no,'email_id' => $email_id,'address' => $address,'status' => 'yes'), array('customer_id'=>$customer_id));
				if($update_customer!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Customer Details Update Successfully.
									 </div>";
					$data['page_title'] = "Update Customer";	
					$data['customer_id'] = $customer_id;
					$this->load->view('admin/edit_customer', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Customer Details Update Failed.
									</div>";
					$data['page_title'] = "Update Customer";	
					$data['customer_id'] = $customer_id;
					$this->load->view('admin/edit_customer', $data);
				}
			}
		}
	}
	function delete_customer(){
		$id=$this->input->post('customer_id');
		$delete_customer=$this->db->delete('customer', array('customer_id'=>$id));
				if($delete_customer!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Customer Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Customer Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_customer()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Customer ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Customer List";
			$this->load->view('admin/customer_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_customer=$this->db->delete('customer', array('customer_id'=>$checked_id[$i]));
			}
				if($delete_customer!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Customer Details Delete Successfully.
										</div>";
					$data['page_title']="Customer List";
					$this->load->view('admin/customer_list', $data);
					redirect('studio/customer_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Customer Details Delete Failed.
										</div>";
					$data['page_title']="Customer List";
					$this->load->view('admin/customer_list', $data);
					redirect('studio/customer_list');
				}
		}
	}
	
	// End Customer Master
	
	// Start Masters 
	
	private function set_main_page_banners()
	{   
		$config = array();
		$config['upload_path'] = 'uploads/main_page_banners/';
		//$config['allowed_types'] = '*';
		$config['allowed_types'] = 'gif|jpg|png|jpeg';
		$config['max_size']      = '10240';
		$config['overwrite']     = FALSE;

		return $config;
	}
	
	// Start Bus Images Master
	
	function main_page_banners_list(){
		$data['page_title']="Main Page Banner's Images List";
		$data['message'] = "";

		$this->load->view('admin/main_page_banners_list', $data);
	}
	function main_page_banners_view(){
		$main_page_banners_id = $this->uri->segment(3);
		$data['page_title']="Main Page Banner's Images Details";
		$data['message'] = "";
		$data['main_page_banners_id'] = $main_page_banners_id;
		$this->load->view('admin/main_page_banners_view', $data);
	}
	function add_main_page_banners(){
		$data['page_title']="Add Main Page Banner's Images";
		$data['message'] = "";

		$this->load->view('admin/add_main_page_banners', $data);
	}
	public function src_add_main_page_banners()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Main Page Banners', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Main Page Banner's Images";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_main_page_banners', $data);
		}else{
			$img_cn = '100';
			$flag[] = '';
			$this->load->library('Upload');
			$files = $_FILES;
			if($files['userfile']['name'] != ''){
			if(count($files['userfile']['name']) <= $img_cn){
				for($x=0;$x<count($files['userfile']['name']);$x++){
					$file_name = $_FILES['userfile']['name'][$x];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					if($ext == 'jpg' || $ext == 'png' || $ext == 'JPG' || $ext == 'PNG'){
					$flag[] = '0';
					}else{
					$flag[] = '1';
					}
				}
				if (in_array("1", $flag)){
					$data['message']="<div class='alert alert-danger fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-warning'></i>
					<strong>Warning !</strong> Please Select Only JPG and PNG.
					</div>";
				}else{
					for($o=0;$o<count($files['userfile']['name']);$o++){
					$_FILES['userfile']['name']= $files['userfile']['name'][$o];
					$_FILES['userfile']['type']= $files['userfile']['type'][$o];
					$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$o];
					$_FILES['userfile']['error']= $files['userfile']['error'][$o];
					$_FILES['userfile']['size']= $files['userfile']['size'][$o];    

					$this->upload->initialize($this->set_main_page_banners());
					$check_upload = $this->upload->do_upload();
									
					$file_name = $files['userfile']['name'][$o];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					$first_char = substr(microtime(), 2);
					$first_char = str_replace(' ', '_', $first_char);
					$main_page_new_name = $first_char."".$o."".date('YmdHisu').".".$ext;
					rename("uploads/main_page_banners/".$files['userfile']['name'][$o]."", "uploads/main_page_banners/".$main_page_new_name."");
									
					$data = array (
					'name' 		=> $name,
					'url' 		=> $main_page_new_name,
					'status'	=> 'yes'
					);
					$insert_main_page_banners  = $this->db->insert('main_page_banners', $data);
					}
					$data['message']="<div class='alert alert-success fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-success'></i>
					<strong>Sucess !</strong> Your Main Page Banner's Images Details Stored Successfully.
					</div>";
				}
			}
			}else{
				$data['message']="<div class='alert alert-danger fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> Please Select Images.
							</div>";
			}
			$data['page_title'] = "Add Main Page Banner's Images";	
			$this->load->view('admin/add_main_page_banners', $data);
		}
	}
	function delete_main_page_banners(){
		$id=$this->input->post('main_page_banners_id');
		$delete_main_page_banners=$this->db->delete('main_page_banners', array('main_page_banners_id'=>$id));
				if($delete_main_page_banners!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Main Page Banner's Images Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Main Page Banner's Images Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_main_page_banners()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Main Page Banners Images ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Main Page Banner's Images List";
			$this->load->view('admin/main_page_banners_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_main_page_banners=$this->db->delete('main_page_banners', array('main_page_banners_id'=>$checked_id[$i]));
			}
				if($delete_main_page_banners!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Main Page Banner's Images Details Delete Successfully.
										</div>";
					$data['page_title']="Main Page Banner's Images List";
					$this->load->view('admin/main_page_banners_list', $data);
					redirect('studio/main_page_banners_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Main Page Banner's Images Details Delete Failed.
										</div>";
					$data['page_title']="Main Page Banner's Images List";
					$this->load->view('admin/main_page_banners_list', $data);
					redirect('studio/main_page_banners_list');
				}
		}
	}
	
	// End Main Page Banner's Master
	
	private function set_home_page_banners()
	{   
		$config = array();
		$config['upload_path'] = 'uploads/home_page_banners/';
		//$config['allowed_types'] = '*';
		$config['allowed_types'] = 'gif|jpg|png|jpeg';
		$config['max_size']      = '10240';
		$config['overwrite']     = FALSE;

		return $config;
	}
	
	// Start Home Page Banner's Master
	
	function home_page_banners_list(){
		$data['page_title']="Home Page Banner's Images List";
		$data['message'] = "";

		$this->load->view('admin/home_page_banners_list', $data);
	}
	function home_page_banners_view(){
		$home_page_banners_id = $this->uri->segment(3);
		$data['page_title']="Home Page Banner's Images Details";
		$data['message'] = "";
		$data['home_page_banners_id'] = $home_page_banners_id;
		$this->load->view('admin/home_page_banners_view', $data);
	}
	function add_home_page_banners(){
		$data['page_title']="Add Home Page Banner's Images";
		$data['message'] = "";

		$this->load->view('admin/add_home_page_banners', $data);
	}
	public function src_add_home_page_banners()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Home Page Banners', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Home Page Banner's Images";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_home_page_banners', $data);
		}else{
			$img_cn = '100';
			$flag[] = '';
			$this->load->library('Upload');
			$files = $_FILES;
			if($files['userfile']['name'] != ''){
			if(count($files['userfile']['name']) <= $img_cn){
				for($x=0;$x<count($files['userfile']['name']);$x++){
					$file_name = $_FILES['userfile']['name'][$x];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					if($ext == 'jpg' || $ext == 'png' || $ext == 'JPG' || $ext == 'PNG'){
					$flag[] = '0';
					}else{
					$flag[] = '1';
					}
				}
				if (in_array("1", $flag)){
					$data['message']="<div class='alert alert-danger fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-warning'></i>
					<strong>Warning !</strong> Please Select Only JPG and PNG.
					</div>";
				}else{
					for($o=0;$o<count($files['userfile']['name']);$o++){
					$_FILES['userfile']['name']= $files['userfile']['name'][$o];
					$_FILES['userfile']['type']= $files['userfile']['type'][$o];
					$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$o];
					$_FILES['userfile']['error']= $files['userfile']['error'][$o];
					$_FILES['userfile']['size']= $files['userfile']['size'][$o];    

					$this->upload->initialize($this->set_home_page_banners());
					$check_upload = $this->upload->do_upload();
									
					$file_name = $files['userfile']['name'][$o];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					$first_char = substr(microtime(), 2);
					$first_char = str_replace(' ', '_', $first_char);
					$home_page_new_name = $first_char."".$o."".date('YmdHisu').".".$ext;
					rename("uploads/home_page_banners/".$files['userfile']['name'][$o]."", "uploads/home_page_banners/".$home_page_new_name."");
									
					$data = array (
					'name' 		=> $name,
					'url' 		=> $home_page_new_name,
					'status'	=> 'yes'
					);
					$insert_home_page_banners  = $this->db->insert('home_page_banners', $data);
					}
					$data['message']="<div class='alert alert-success fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-success'></i>
					<strong>Sucess !</strong> Your Home Page Banner's Images Details Stored Successfully.
					</div>";
				}
			}
			}else{
				$data['message']="<div class='alert alert-danger fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> Please Select Images.
							</div>";
			}
			$data['page_title'] = "Add Home Page Banner's Images";	
			$this->load->view('admin/add_home_page_banners', $data);
		}
	}
	function delete_home_page_banners(){
		$id=$this->input->post('home_page_banners_id');
		$delete_main_page_banners=$this->db->delete('home_page_banners', array('home_page_banners_id'=>$id));
				if($delete_main_page_banners!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Home Page Banner's Images Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Home Page Banner's Images Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_home_page_banners()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Home Page Banners Images ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Home Page Banner's Images List";
			$this->load->view('admin/home_page_banners_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_home_page_banners=$this->db->delete('home_page_banners', array('home_page_banners_id'=>$checked_id[$i]));
			}
				if($delete_main_page_banners!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Home Page Banner's Images Details Delete Successfully.
										</div>";
					$data['page_title']="Home Page Banner's Images List";
					$this->load->view('admin/main_page_banners_list', $data);
					redirect('studio/home_page_banners_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Home Page Banner's Images Details Delete Failed.
										</div>";
					$data['page_title']="Home Page Banner's Images List";
					$this->load->view('admin/main_page_banners_list', $data);
					redirect('studio/home_page_banners_list');
				}
		}
	}
	
	// End Home Page Banner's Master
	
	// Start Photo Category Master
	
	function photo_category_list(){
		$data['page_title']="Photo Category List";
		$data['message'] = "";

		$this->load->view('admin/photo_category_list', $data);
	}
	function photo_category_view(){
		$photo_category_id = $this->uri->segment(3);
		$data['page_title']="Photo Category Details";
		$data['message'] = "";
		$data['photo_category_id'] = $photo_category_id;
		$this->load->view('admin/photo_category_view', $data);
	}
	function add_photo_category(){
		$data['page_title']="Add Photo Category";
		$data['message'] = "";

		$this->load->view('admin/add_photo_category', $data);
	}
	public function src_add_photo_category()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('photo_category_name', 'Photo Category Name', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Photo Category";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_photo_category', $data);
		}else{
			$data = array(
					   'photo_category_name' 		=> $photo_category_name,
					   'status' 			=> 'yes'
			);
			$insert_photo_category  = $this->db->insert('photo_category', $data);
				if($insert_photo_category!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Photo Category Details Stored Successfully.
									 </div>";
					$data['page_title'] = "Add Photo Category";	
					$this->load->view('admin/add_photo_category', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Photo Category Details Stored Failed.
									</div>";
					$data['page_title'] = "Add Photo Category";	
					$this->load->view('admin/add_photo_category', $data);
				}
		}
	}
	function edit_photo_category(){
	$photo_category_id = $this->uri->segment(3);
		$data['page_title']="Update Photo Category";
		$data['message'] = "";
		$data['photo_category_id'] = $photo_category_id;
		$this->load->view('admin/edit_photo_category', $data);
	}
	public function src_photo_category_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('photo_category_name', 'Photo Category Name', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update Photo Category";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['photo_category_id'] = $photo_category_id;
			$this->load->view('admin/edit_photo_category', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('photo_category');
			$this->db->where('photo_category_name',$photo_category_name);
			$this->db->where('photo_category_id != ',$photo_category_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Photo Category Name is Already Exist.
									</div>";
				$data['page_title'] = "Update Photo Category";	
				$data['photo_category_id'] = $photo_category_id;
				$this->load->view('admin/edit_photo_category', $data);
			}else{
				$update_photo_category  = $this->db->update('photo_category', array( 'photo_category_name'=> $photo_category_name,'status'=>'yes'), array('photo_category_id'=>$photo_category_id));
				if($update_photo_category!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Photo Category Details Update Successfully.
									 </div>";
					$data['page_title'] = "Update Photo Category";	
					$data['photo_category_id'] = $photo_category_id;
					$this->load->view('admin/edit_photo_category', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Photo Category Details Update Failed.
									</div>";
					$data['page_title'] = "Update Photo Category";	
					$data['photo_category_id'] = $photo_category_id;
					$this->load->view('admin/edit_photo_category', $data);
				}
			}
		}
	}
	function delete_photo_category(){
		$id=$this->input->post('photo_category_id');
		$delete_photo_category=$this->db->delete('photo_category', array('photo_category_id'=>$id));
				if($delete_photo_category!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Photo Category Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Photo Category Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_photo_category()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Photo Category ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Photo Category List";
			$this->load->view('admin/photo_category_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_photo_category=$this->db->delete('photo_category', array('photo_category_id'=>$checked_id[$i]));
			}
				if($delete_photo_category!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Photo Category Details Delete Successfully.
										</div>";
					$data['page_title']="Photo Category List";
					$this->load->view('admin/photo_category_list', $data);
					redirect('studio/photo_category_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Photo Category Details Delete Failed.
										</div>";
					$data['page_title']="Photo Category List";
					$this->load->view('admin/photo_category_list', $data);
					redirect('studio/photo_category_list');
				}
		}
	}
	
	// End Photo Category Master
	
	// Start Function Category Master
	
	function function_category_list(){
		$data['page_title']="Function Category List";
		$data['message'] = "";

		$this->load->view('admin/function_category_list', $data);
	}
	function function_category_view(){
		$function_category_id = $this->uri->segment(3);
		$data['page_title']="Function Category Details";
		$data['message'] = "";
		$data['function_category_id'] = $function_category_id;
		$this->load->view('admin/function_category_view', $data);
	}
	function add_function_category(){
		$data['page_title']="Add Function Category";
		$data['message'] = "";

		$this->load->view('admin/add_function_category', $data);
	}
	public function src_add_function_category()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('function_category_name', 'Function Category Name', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Function Category";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_function_category', $data);
		}else{
			$data = array(
					   'function_category_name' 		=> $function_category_name,
					   'status' 			=> 'yes'
			);
			$insert_function_category  = $this->db->insert('function_category', $data);
				if($insert_function_category!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Function Category Details Stored Successfully.
									 </div>";
					$data['page_title'] = "Add Function Category";	
					$this->load->view('admin/add_function_category', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Function Category Details Stored Failed.
									</div>";
					$data['page_title'] = "Add Function Category";	
					$this->load->view('admin/add_function_category', $data);
				}
		}
	}
	function edit_function_category(){
	$function_category_id = $this->uri->segment(3);
		$data['page_title']="Update Function Category";
		$data['message'] = "";
		$data['function_category_id'] = $function_category_id;
		$this->load->view('admin/edit_function_category', $data);
	}
	public function src_function_category_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('function_category_name', 'Function Category Name', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update Function Category";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['function_category_id'] = $function_category_id;
			$this->load->view('admin/edit_function_category', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('function_category');
			$this->db->where('function_category_name',$function_category_name);
			$this->db->where('function_category_id != ',$function_category_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Function Category Name is Already Exist.
									</div>";
				$data['page_title'] = "Update Function Category";	
				$data['function_category_id'] = $function_category_id;
				$this->load->view('admin/edit_function_category', $data);
			}else{
				$update_function_category  = $this->db->update('function_category', array( 'function_category_name'=> $function_category_name,'status'=>'yes'), array('function_category_id'=>$function_category_id));
				if($update_function_category!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Function Category Details Update Successfully.
									 </div>";
					$data['page_title'] = "Update Function Category";	
					$data['function_category_id'] = $function_category_id;
					$this->load->view('admin/edit_function_category', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Function Category Details Update Failed.
									</div>";
					$data['page_title'] = "Update Function Category";	
					$data['function_category_id'] = $function_category_id;
					$this->load->view('admin/edit_function_category', $data);
				}
			}
		}
	}
	function delete_function_category(){
		$id=$this->input->post('function_category_id');
		$delete_function_category=$this->db->delete('function_category', array('function_category_id'=>$id));
				if($delete_function_category!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Function Category Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Function Category Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_function_category()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Function Category ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Function Category List";
			$this->load->view('admin/photo_category_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_function_category=$this->db->delete('functioncategory', array('function_category_id'=>$checked_id[$i]));
			}
				if($delete_function_category!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Function Category Details Delete Successfully.
										</div>";
					$data['page_title']="Function Category List";
					$this->load->view('admin/function_category_list', $data);
					redirect('studio/function_category_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Function Category Details Delete Failed.
										</div>";
					$data['page_title']="Function Category List";
					$this->load->view('admin/function_category_list', $data);
					redirect('studio/function_category_list');
				}
		}
	}
	
	// End Function Category Master
	
	// Start Photo Session 
	private function set_photo()
	{   
		$config = array();
		$config['upload_path'] = 'uploads/photo/';
		//$config['allowed_types'] = '*';
		$config['allowed_types'] = 'gif|jpg|png|jpeg';
		$config['max_size']      = '10240';
		$config['overwrite']     = FALSE;

		return $config;
	}
	function photo_list(){
		$data['page_title']="Photo's List";
		$data['message'] = "";

		$this->load->view('admin/photo_list', $data);
	}
	function photo_view(){
		$photo_id = $this->uri->segment(3);
		$data['page_title']="Photo's Details";
		$data['message'] = "";
		$data['photo_id'] = $photo_id;
		$this->load->view('admin/photo_view', $data);
	}
	function add_photo(){
		$data['page_title']="Add Photo's";
		$data['message'] = "";

		$this->load->view('admin/add_photo', $data);
	}
	public function src_add_photo()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Photo', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Photo's";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_photo', $data);
		}else{
			$img_cn = '100';
			$flag[] = '';
			$this->load->library('Upload');
			$files = $_FILES;
			if($files['userfile']['name'] != ''){
			if(count($files['userfile']['name']) <= $img_cn){
				for($x=0;$x<count($files['userfile']['name']);$x++){
					$file_name = $_FILES['userfile']['name'][$x];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'JPG' || $ext == 'JPEG' || $ext == 'PNG'){
					$flag[] = '0';
					}else{
					$flag[] = '1';
					}
				}
				if (in_array("1", $flag)){
					$data['message']="<div class='alert alert-danger fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-warning'></i>
					<strong>Warning !</strong> Please Select Only JPG and PNG.
					</div>";
				}else{
					$data = array (
					'client_code' 			=> $client_code,
					'function_category_id' 	=> $function_category_id,
					'photo_category_id' 	=> $photo_category_id,
					'name' 					=> $name,
					'status'				=> 'yes'
					);
					$insert_photo  = $this->db->insert('photo', $data);
					$photo_id = $this->db->insert_id();
					for($o=0;$o<count($files['userfile']['name']);$o++){
					$_FILES['userfile']['name']= $files['userfile']['name'][$o];
					$_FILES['userfile']['type']= $files['userfile']['type'][$o];
					$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$o];
					$_FILES['userfile']['error']= $files['userfile']['error'][$o];
					$_FILES['userfile']['size']= $files['userfile']['size'][$o];    

					$this->upload->initialize($this->set_photo());
					$check_upload = $this->upload->do_upload();
									
					$file_name = $files['userfile']['name'][$o];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					$first_char = substr(microtime(), 2);
					$first_char = str_replace(' ', '_', $first_char);
					$photo_name = $first_char."".$o."".date('YmdHisu').".".$ext;
					rename("uploads/photo/".$files['userfile']['name'][$o]."", "uploads/photo/".$photo_name."");
									
					$data = array (
					'photo_id' 	=> $photo_id,
					'type' 		=> 'normal',
					'url' 		=> $photo_name,
					'status'	=> 'yes'
					);
					$insert_photo_details  = $this->db->insert('photo_details', $data);
					}
					$data['message']="<div class='alert alert-success fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-success'></i>
					<strong>Sucess !</strong> Your Photo's Details Stored Successfully.
					</div>";
				}
			}
			}else{
				$data['message']="<div class='alert alert-danger fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> Please Select Images.
							</div>";
			}
			$data['page_title'] = "Add Photo's Images";	
			$this->load->view('admin/add_photo', $data);
		}
	}
	function add_more_photo(){
		$photo_id = $this->uri->segment(3);
		$data['page_title']="Add more Photo's";
		$data['message'] = "";
		$data['photo_id'] = $photo_id;
		$this->load->view('admin/add_more_photo', $data);
	}
	public function src_add_more_photo()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('photo_id', 'Photo', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add more Photo's";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_more_photo', $data);
		}else{
			$img_cn = '100';
			$flag[] = '';
			$this->load->library('Upload');
			$files = $_FILES;
			if($files['userfile']['name'] != ''){
			if(count($files['userfile']['name']) <= $img_cn){
				for($x=0;$x<count($files['userfile']['name']);$x++){
					$file_name = $_FILES['userfile']['name'][$x];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'JPG' || $ext == 'JPEG' || $ext == 'PNG'){
					$flag[] = '0';
					}else{
					$flag[] = '1';
					}
				}
				if (in_array("1", $flag)){
					$data['message']="<div class='alert alert-danger fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-warning'></i>
					<strong>Warning !</strong> Please Select Only JPG and PNG.
					</div>";
				}else{
					$photo_id = $photo_id;
					for($o=0;$o<count($files['userfile']['name']);$o++){
					$_FILES['userfile']['name']= $files['userfile']['name'][$o];
					$_FILES['userfile']['type']= $files['userfile']['type'][$o];
					$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$o];
					$_FILES['userfile']['error']= $files['userfile']['error'][$o];
					$_FILES['userfile']['size']= $files['userfile']['size'][$o];    

					$this->upload->initialize($this->set_photo());
					$check_upload = $this->upload->do_upload();
									
					$file_name = $files['userfile']['name'][$o];
					$ext = pathinfo($file_name, PATHINFO_EXTENSION);
					$first_char = substr(microtime(), 2);
					$first_char = str_replace(' ', '_', $first_char);
					$photo_name = $first_char."".$o."".date('YmdHisu').".".$ext;
					rename("uploads/photo/".$files['userfile']['name'][$o]."", "uploads/photo/".$photo_name."");
									
					$data = array (
					'photo_id' 	=> $photo_id,
					'type' 		=> 'normal',
					'url' 		=> $photo_name,
					'status'	=> 'yes'
					);
					$insert_photo_details  = $this->db->insert('photo_details', $data);
					}
					$data['message']="<div class='alert alert-success fade in'>
					<button class='close' data-dismiss='alert'>×</button>
					<i class='fa-fw fa fa-success'></i>
					<strong>Sucess !</strong> Your Photo's Details Stored Successfully.
					</div>";
				}
			}
			}else{
				$data['message']="<div class='alert alert-danger fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> Please Select Images.
							</div>";
			}
			$data['page_title'] = "Add Photo's Images";	
			$this->load->view('admin/add_photo', $data);
		}
	}
	function edit_photo(){
	$photo_id = $this->uri->segment(3);
		$data['page_title']="Update Photo";
		$data['message'] = "";
		$data['photo_id'] = $photo_id;
		$this->load->view('admin/edit_photo', $data);
	}
	public function src_photo_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('name', 'Name', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update Photo";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['photo_id'] = $photo_id;
			$this->load->view('admin/edit_photo', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('photo');
			$this->db->where('name',$name);
			$this->db->where('photo_id != ',$photo_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Photo Name is Already Exist.
									</div>";
				$data['page_title'] = "Update Photo";	
				$data['photo_id'] = $photo_id;
				$this->load->view('admin/edit_photo', $data);
			}else{
				$update_photo  = $this->db->update('photo', array( 'client_code' => $client_code,'function_category_id' => $function_category_id,'photo_category_id' => $photo_category_id,'name' => $name,'status'=>'yes'), array('photo_id'=>$photo_id));
				if($update_photo!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Photo Details Update Successfully.
									 </div>";
					$data['page_title'] = "Update Photo";	
					$data['photo_id'] = $photo_id;
					$this->load->view('admin/edit_photo', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Photo Details Update Failed.
									</div>";
					$data['page_title'] = "Update Photo";	
					$data['photo_id'] = $photo_id;
					$this->load->view('admin/edit_photo', $data);
				}
			}
		}
	}
	function del_test(){
		unlink("uploads/test.jpg");
	}
	function delete_photo_album(){
		extract ($_POST);
		
		
		if (array_key_exists('delete_file', $_POST)) {
		  $filename = $_POST['delete_file'];
		  if (file_exists("uploads/photo/".$filename)) {
			unlink("uploads/photo/".$filename);
			//echo 'File '.$filename.' has been deleted';
		  } else {
			//echo 'Could not delete '.$filename.', file does not exist';
		  }
		}
		
		$delete_photo_album=$this->db->delete('photo_details', array('photo_details_id'=>$photo_details_id));
		
				if($delete_photo_album!=false){
					redirect('studio/photo_list');
				}else{
					redirect('studio/photo_list');
				}
	}
	function delete_photo(){
		$id=$this->input->post('photo_id');
		$delete_photo=$this->db->delete('photo', array('photo_id'=>$id));
				if($delete_photo!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Photo's Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Photo's Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_photo()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Photo ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Photo's List";
			$this->load->view('admin/photo_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_photo=$this->db->delete('photo', array('photo_id'=>$checked_id[$i]));
			}
				if($delete_photo!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Photo's Details Delete Successfully.
										</div>";
					$data['page_title']="Photo's List";
					$this->load->view('admin/photo_list', $data);
					redirect('studio/photo_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Photo's Details Delete Failed.
										</div>";
					$data['page_title']="Photo's List";
					$this->load->view('admin/photo_list', $data);
					redirect('studio/photo_list');
				}
		}
	}
	
	// End Photo Session 
	
	// Start Video Session
	
	function video_list(){
		$data['page_title']="Video List";
		$data['message'] = "";

		$this->load->view('admin/video_list', $data);
	}
	function video_view(){
		$video_id = $this->uri->segment(3);
		$data['page_title']="Video Details";
		$data['message'] = "";
		$data['video_id'] = $video_id;
		$this->load->view('admin/video_view', $data);
	}
	function add_video(){
		$data['page_title']="Add Video";
		$data['message'] = "";

		$this->load->view('admin/add_video', $data);
	}
	public function src_add_video()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('title', 'Video Name', 'required');
		$this->form_validation->set_rules('url', 'URL', 'required');
		
		if ($this->form_validation->run() == false){
			$data['page_title']="Add Video";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$this->load->view('admin/add_video', $data);
		}else{
			$data = array(
					   'title' 				=> $title,
					   'url' 				=> $url,
					   'status' 			=> 'yes'
			);
			$insert_video  = $this->db->insert('video', $data);
				if($insert_video!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Video Details Stored Successfully.
									 </div>";
					$data['page_title'] = "Add Video";	
					$this->load->view('admin/add_video', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Video Details Stored Failed.
									</div>";
					$data['page_title'] = "Add Video";	
					$this->load->view('admin/add_video', $data);
				}
		}
	}
	function edit_video(){
	$video_id = $this->uri->segment(3);
		$data['page_title']="Update Video";
		$data['message'] = "";
		$data['video_id'] = $video_id;
		$this->load->view('admin/edit_video', $data);
	}
	public function src_video_edit()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('title', 'Video Name', 'required');
		$this->form_validation->set_rules('url', 'URL', 'required');

		if ($this->form_validation->run() == false){
			$data['page_title']="Update Video";
			$data['message'] = "<div class='alert alert-warning fade in'>
									<button class='close' data-dismiss='alert'>×</button>
									<i class='fa-fw fa fa-warning'></i>
									<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['video_id'] = $video_id;
			$this->load->view('admin/edit_video', $data);
		}else{
			
			$this->db->select('*');
			$this->db->from('video');
			$this->db->where('url',$url);
			$this->db->where('video_id != ',$video_id);
			$check_duplicate = $this->db->get();
			if($check_duplicate->num_rows()>0){
				$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Video Name is Already Exist.
									</div>";
				$data['page_title'] = "Update Video";	
				$data['video_id'] = $video_id;
				$this->load->view('admin/edit_video', $data);
			}else{
				$update_video  = $this->db->update('video', array('title' => $title,'url' => $url), array('video_id'=>$video_id));
				if($update_video!=false){
					$data['message']="<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Video Details Update Successfully.
									 </div>";
					$data['page_title'] = "Update Video";	
					$data['video_id'] = $video_id;
					$this->load->view('admin/edit_video', $data);
				}else{
					$data['message']="<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Video Details Update Failed.
									</div>";
					$data['page_title'] = "Update Video";	
					$data['video_id'] = $video_id;
					$this->load->view('admin/edit_video', $data);
				}
			}
		}
	}
	function delete_video(){
		$id=$this->input->post('video_id');
		$delete_video=$this->db->delete('video', array('video_id'=>$id));
				if($delete_video!=false){
					echo "<div class='alert alert-success fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-check'></i>
							<strong>Success!</strong> Your Video Details Delete Successfully.
						</div>";
				}else{
					echo "<div class='alert alert-warning fade in'>
							<button class='close' data-dismiss='alert'>×</button>
							<i class='fa-fw fa fa-warning'></i>
							<strong>Warning !</strong> Your Video Details Delete Failed.
						</div>";
				}
	}
	
	public function delete_selected_video()
	{
		extract ($_POST);
		$this->form_validation->set_error_delimiters('<div id="alert alert-danger alert-dismissable">', '</div>');
		$this->form_validation->set_rules('checked_id', 'Video ID', 'required');

		if ($this->form_validation->run() == false){
			$data['message'] = "<div class='alert alert-warning fade in'>
								<button class='close' data-dismiss='alert'>×</button>
								<i class='fa-fw fa fa-warning'></i>
								<strong>Warning !</strong> ".validation_errors()."
								</div>";
			$data['page_title']="Video List";
			$this->load->view('admin/video_list', $data);
		}else{
			$cnt = count($checked_id);
			for($i=0;$i<$cnt;$i++){
				$delete_video=$this->db->delete('video', array('video_id'=>$checked_id[$i]));
			}
				if($delete_video!=false){
					$data['message'] = "<div class='alert alert-success fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-check'></i>
										<strong>Success!</strong> Your Video Details Delete Successfully.
										</div>";
					$data['page_title']="Video List";
					$this->load->view('admin/video_list', $data);
					redirect('studio/video_list');
				}else{
					$data['message'] = "<div class='alert alert-warning fade in'>
										<button class='close' data-dismiss='alert'>×</button>
										<i class='fa-fw fa fa-warning'></i>
										<strong>Warning !</strong> Your Video Details Delete Failed.
										</div>";
					$data['page_title']="Video List";
					$this->load->view('admin/video_list', $data);
					redirect('studio/video_list');
				}
		}
	}
	
	// End Video Session

	// Start Gallery Session

	function gallery(){
		$data['page_title']="Gallery";
		$data['message'] = "";
		
		if($this->session->userdata('uname') == 'admin'){
			$data['clients'] = $this->db->get_where('client', array('status'=>'yes'))->result();
		}else{
			$data['clients'] = $this->db->get_where('client', array('status'=>'yes', 'client_code'=>$this->session->userdata('uname')))->result();
		}
		$data['photo_categories'] = $this->db->get_where('photo_category', array('status'=>'yes'))->result();
		$data['function_categories'] = $this->db->get_where('function_category', array('status'=>'yes'))->result();

		$this->load->view('admin/gallery', $data);
	}
	
	function get_gallery_photos(){
		$client_code = $this->input->post('client_code');
		$photo_category_id = $this->input->post('photo_category_id');
		$function_category_id = $this->input->post('function_category_id');
		$page = $this->input->post('page');
		if(!$page){
			$page = 0;
		}
		$limit = 12;

		// Base query for counting
		$this->db->start_cache();
		$this->db->from('photo_details pd');
		$this->db->join('photo p', 'p.photo_id = pd.photo_id');
		
		if($client_code) {
			$this->db->where('p.client_code', $client_code);
		}
		if($photo_category_id) {
			$this->db->where('p.photo_category_id', $photo_category_id);
		}
		if($function_category_id) {
			$this->db->where('p.function_category_id', $function_category_id);
		}
		$this->db->where('p.status', 'yes');
		$this->db->where('pd.status', 'yes');
		$this->db->stop_cache();

		$total_rows = $this->db->count_all_results();

		// Query for results
		$this->db->select('pd.photo_details_id, pd.url, pd.type, p.name as album_name');
		$this->db->limit($limit, $page);
		$this->db->order_by('pd.photo_details_id', 'desc');
		$query = $this->db->get();
		
		$this->db->flush_cache();
		
		$result = array();
		if($query) {
			$result['photos'] = $query->result();
		} else {
			$result['photos'] = array();
		}
		$result['total_rows'] = $total_rows;
		$result['limit'] = $limit;
		
		echo json_encode($result);
	}

	function delete_gallery_photo(){
		$photo_details_id = $this->input->post('photo_details_id');
		
		$this->db->where('photo_details_id', $photo_details_id);
		$query = $this->db->get('photo_details');
		if($query->num_rows() > 0){
			$row = $query->row();
			$file_path = 'uploads/photo/' . $row->url;
			if(file_exists($file_path)){
				unlink($file_path);
			}
			$this->db->delete('photo_details', array('photo_details_id' => $photo_details_id));
			echo 'success';
		} else {
			echo 'error';
		}
	}

	function send_gallery_email(){
		$email_id = $this->input->post('email');
		$selected_photos = $this->input->post('photos'); 

		if(empty($email_id) || empty($selected_photos)) {
			echo 'error'; return;
		}

		$this->load->library('email');
		$config = $this->session->userdata('config');
        if(empty($config) || !is_array($config)) {
             $config = array(
                'protocol' => 'smtp',
                'smtp_host' => 'mail.apexsoftindia.com',
                'smtp_port' => 25,
                'smtp_user' => 'test@apexsoftindia.com',
                'smtp_pass' => '9787119377',
                'mailtype' => 'html',
                'charset' => 'utf-8'
            );
        }
		$this->email->initialize($config);
		$this->email->set_newline("\r\n");

		$this->email->from('test@apexsoftindia.com', 'Studio Admin'); 
		$this->email->to($email_id);
		$this->email->subject('Selected Photos from Gallery');

		$message = '<h3>Here are the photos you selected:</h3><div style="">';
		foreach($selected_photos as $photo){
			$img_url = base_url() . 'uploads/photo/' . $photo;
			$message .= '<div style="display:inline-block; margin:10px; border:1px solid #ccc; padding:5px;"><img src="'.$img_url.'" style="height:150px; display:block;"><br><a href="'.$img_url.'">View Full Size</a></div>';
		}
		$message .= '</div>';

		$this->email->message($message);

		if($this->email->send()){
			echo 'success';
		} else {
			echo 'error';
		}
	}

	function send_gallery_whatsapp(){
		 $mobile = $this->input->post('mobile');
		 $selected_photos = $this->input->post('photos');
		 
		 if(!empty($mobile) && !empty($selected_photos)){
			 // Integration with WhatsApp Gateway would go here
             // For now we return success to show the flow is connected
			 echo 'success';
		 } else {
			 echo 'error';
		 }
	}

	// End Gallery Session
	
}