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

class Admin_action extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function login()
	{
    $id=$this->input->post('u');
	$pass0=$this->input->post('p');
	if($id !='' && $pass0 !=''){
    $pass=sha1($_POST['p']);
    $getlogins=$this->db->query("select aid,user,pass,last_date,last_ip,rights from admin where user='$id' ");
    $admin_data=$getlogins->row_array();
    $user=$admin_data['user'];
    $pass1=$admin_data['pass'];
    if($id == $user  && $pass == $pass1){
    	if (session_status() == PHP_SESSION_NONE) { session_start(); }
        $_SESSION['auth-admin']='1';
        $_SESSION['auth-date']=$admin_data['last_date'];
        $_SESSION['auth-ip']=$admin_data['last_ip'];
        $_SESSION['auth-rights']=$admin_data['rights'];
        $_SESSION['aid']=$admin_data['aid'];

        ob_end_flush(); redirect(base_url('index.php/admin/dash') );
	}else{
		ob_end_flush(); redirect(base_url('index.php/admin/index?msg=Login Failed'));
	}
	}else{
	ob_end_flush(); redirect(base_url('index.php/admin/index?msg=Login Failed'));
	}
}
public function help (){
	echo 'ok, please call us at 9034664487';
}

public function admin(){
	get_admin_rights();
	$name=$this->input->post('name');
	$u=$this->input->post('u');
	$pass=$this->input->post('pass');
	$email=$this->input->post('email');
	$rights=$this->input->post('rights');
	$todo=$this->input->post('todo');
	$p=sha1($pass);
	if($u !='' && ($pass !='' || $todo !='-1') ){
		if($todo !='-1'){
			$aid=$todo;
		$checkusername=$this->db->query("select * from admin where user='$u' and aid !='$todo' ");
		if($checkusername->num_rows() !='0'){
			echo "Please use different username this is not availabe."; die;
		}else{
			$update_members=$this->db->query("update admin set user='$u',email='$email',name='$name',rights='$rights' where aid='$aid' ");
			if($pass !=''){
				$update_members=$this->db->query("update admin set pass='$p' where aid='$aid' ");
			}
			echo 'YNAPS_SUCCESS'; die;
		}
		}else{
		$checkusername=$this->db->query("select * from admin where user='$u' ");
		if($checkusername->num_rows() !='0'){
			echo "Please use different username this is not availabe."; die;
		}else{
			$adduser_admin=$this->db->query("insert into admin (user,pass,rights,name,email) values ('$u','$p','$rights','$name','$email') ");
			echo 'YNAPS_SUCCESS'; die;
		}}
	}else{
		echo "Please enter username and password."; die;
	}
	
}

public function add_tags (){
	$name=$this->input->post('name');
	$sort=$this->input->post('sort');
	$display=$this->input->post('display');
	$desc=$this->input->post('desc');
	$theid=$this->input->post('theid');
	$stg_type=$this->input->post('stg_type');
	if(trim($name) ==''){
		echo 'Please enter the tag name.'; die;
	}
	$gethecount=$this->db->query("select stg_name from site_tags_skills where stg_name='$name' and stg_type='$stg_type' ");
	if($gethecount -> num_rows() !='0'){
		echo 'Tag with this name already exists please choose another name.'; die;
	}

	if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/cat/",'65');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
		} }else{ $cover=''; }

		if($theid !='0' && $theid !='-1'){
			$getlogins=$this->db->query("update site_tags_skills set stg_name='$name' where stg_tgid='$theid' ");
		}else{
		$getlogins=$this->db->query("insert into site_tags_skills (stg_name,stg_type) values ('$name','$stg_type')");
		}

	echo 'YNAPS_SUCCESS';
}

public function add_cat (){
	$name=$this->input->post('name');
	$sort=$this->input->post('sort');
	$display=$this->input->post('display');
	$desc=$this->input->post('desc');
	$theid=$this->input->post('theid');
	if(trim($name) ==''){
		echo 'Please enter the catagory name.'; die;
	}
	
	if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/cat/",'65');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
		} }else{ $cover=''; }

		if($theid !='0' && $theid !='-1'){
			$getlogins=$this->db->query("update site_catagory set name='$name',sid='$sort',display='$display',details='$desc' where ctid='$theid' ");
		}else{

			$gethecount=$this->db->query("select name from site_catagory where name='$name' ");
			if($gethecount -> num_rows() !='0'){
				echo 'Catagory with this name already exists please choose another name.'; die;
			}
			
		$getlogins=$this->db->query("insert into site_catagory (name,sid,display,img,details) values ('$name','$sort','$display','$cover','$desc')");
		}

	echo 'YNAPS_SUCCESS';
}

public function edit_cat(){
	$id=$this->input->post('id');
	$name=$this->input->post('name');
	$sort=$this->input->post('sort');
	$display=$this->input->post('display');
	$desc=$this->input->post('desc');

	if(trim($name) ==''){
		echo 'Please enter the catagory name.'; die;
	}
	$gethecount=$this->db->query("select name from site_catagory where name='$name' and ctid !='$id' ");
	if($gethecount -> num_rows() !='0'){
		echo 'Catagory with this name already exists please choose another name.'; die;
	}
	if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/cat/",'65');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			$getlogins=$this->db->query("update site_catagory set img='$cover' where ctid='$id' ");
		} }

	$getlogins=$this->db->query("update site_catagory set name='$name',sid='$sort',display='$display',details='$desc' where ctid='$id' ");
	echo 'YNAPS_SUCCESS';
}

public function delete_cat(){
	$id=$this->input->post('id');
	$getlogins=$this->db->query("delete from site_catagory where ctid='$id'");
	echo 'YNAPS_SUCCESS';
}

public function add_sub_cat(){
	$name=addslashes($this->input->post('name'));
	$sort=$this->input->post('sort');
	$cat=$this->input->post('cat');
	$desc=addslashes($this->input->post('desc'));
	$theid=addslashes($this->input->post('theid'));

	if(trim($name) ==''){
		echo 'Please enter the sub catagory name.'; die;
	}
	if(trim($cat) ==''){
		echo 'Please select catagory name.'; die;
	}
	$gethecount=$this->db->query("select sc_name from site_sub_cat where sc_name='$name' and sc_ctid='$cat' ");
	if($gethecount -> num_rows() !='0'){
		echo 'Sub Catagory with this name already exists in this catagory please choose another name.'; die;
	}

	if($theid !='0' && $theid !='-1'){
		$getlogins=$this->db->query("update site_sub_cat set sc_name='$name',sc_sort='$sort',sc_ctid='$cat',sc_text='$desc' where sc_id='$theid' ");
	}else{
	$getlogins=$this->db->query("insert into site_sub_cat (sc_name,sc_ctid,sc_sort,sc_text) values ('$name','$cat','$sort','$desc')");
	}
	echo 'YNAPS_SUCCESS';

}

public function edit_sub_cat(){
	$id=$this->input->post('id');
	$name=addslashes($this->input->post('name'));
	$sort=$this->input->post('sort');
	$cat=$this->input->post('cat');
	$desc=addslashes($this->input->post('desc'));

	if(trim($name) ==''){
		echo 'Please enter the sub catagory name.'; die;
	}
	$gethecount=$this->db->query("select sc_name from site_sub_cat where sc_name='$name' and sc_ctid='$cat' and sc_id !='$id' ");
	if($gethecount -> num_rows() !='0'){
		echo 'sub Catagory with this name already exists in this catagory please choose another name.'; die;
	}
	$getlogins=$this->db->query("update site_sub_cat set sc_name='$name',sc_sort='$sort',sc_ctid='$cat',sc_text='$desc' where sc_id='$id' ");
	echo 'YNAPS_SUCCESS';
}

public function delete_sub_cat(){
	$id=$this->input->post('id');
	$getlogins=$this->db->query("delete from site_sub_cat where sc_id='$id'");
	echo 'YNAPS_SUCCESS';
}
public function add_sub_cat2(){
	$name=$this->input->post('name');
	$sort=$this->input->post('sort');
	@$cat=$this->input->post('cat');
	$scat=$this->input->post('scat');

	if(trim($name) =='' || $scat ==''){
		echo 'Please enter the sub catagory name.'; die;
	}
	// if(trim($cat) ==''){
	// 	echo 'Please select catagory name.'; die;
	// }
	$gethecount=$this->db->query("select mr_sub2_name from mr_sub2 where mr_sub2_name='$name' and mr_sub2_sid='$scat' ");
	if($gethecount -> num_rows() !='0'){
		echo 'Sub Catagory with this name already exists in this catagory please choose another name.'; die;
	}
	$getlogins=$this->db->query("insert into mr_sub2 (mr_sub2_cid,mr_sub2_sid,mr_sub2_name,mr_sub2_sort) values ('$cat','$scat','$name','$sort')");
	echo 'YNAPS_SUCCESS';

}

public function edit_sub_cat2(){
	$id=$this->input->post('id');
	$name=$this->input->post('name');
	$sort=$this->input->post('sort');
	$cat=$this->input->post('cat');
	$scat=$this->input->post('scat');

	if(trim($name) ==''){
		echo 'Please enter the sub catagory name.'; die;
	}
	$gethecount=$this->db->query("select mr_sub2_name from mr_sub2 where mr_sub2_name='$name' and mr_sub2_sid='$scat' ");
	if($gethecount -> num_rows() !='0'){
		echo 'sub Catagory with this name already exists in this catagory please choose another name.'; die;
	}
	$getlogins=$this->db->query("update mr_sub2 set mr_sub2_name='$name',mr_sub2_sort='$sort',mr_sub2_sid='$scat' where mr_sub2_id='$id' ");
	echo 'YNAPS_SUCCESS';
}

public function delete_sub_cat2(){
	$id=$this->input->post('id');
	$getlogins=$this->db->query("delete from mr_sub2 where mr_sub2_id='$id'");
	echo 'YNAPS_SUCCESS';
}


// Add sliders etc
function add_image(){
@$what=$this->input->post('what');
@$link=addslashes($this->input->post('link'));
@$sort=$this->input->post('sort');
@$text=addslashes($this->input->post('text'));
@$ex=$this->input->post('ex');
@$head=$this->input->post('head');
@$typename=$this->input->post('typename');
@$img_text2=$this->input->post('img_text2');
	switch ($what){
	case 'logo':
		if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			$getlogins=$this->db->query("insert into site_img (img_place,img_link,img_name,img_sort,img_text,img_ex) values ('$what','$link','$cover','$sort','$text','$ex')");
				echo 'YNAPS_SUCCESS'; die;
		} }else{ echo 'Please select the image'; }
	break;case 'slider1':
		if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			$getlogins=$this->db->query("insert into site_img (img_place,img_link,img_name,img_sort,img_text,img_ex) values ('$what','$link','$cover','$sort','$text','$ex')");
				echo 'YNAPS_SUCCESS'; die;
		} }else{ echo 'Please select the image'; }
	break;case 'about':
		if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			$getlogins=$this->db->query("insert into site_img (img_place,img_link,img_name,img_sort,img_text,img_ex) values ('$what','$link','$cover','$sort','$text','$ex')");
				echo 'YNAPS_SUCCESS'; die;
		} }else{ echo 'Please select the image'; }
	break;	
	default:
	if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			$getlogins=$this->db->query("insert into site_img (img_place,img_link,img_name,img_sort,img_text,img_ex,img_head,img_text2) values ('$typename','$link','$cover','$sort','$text','$ex','$head','$img_text2')");
				echo 'YNAPS_SUCCESS'; die;
		} }else{ echo 'Please select the image'; }
	break;
	} }

function edit_image(){
$id=$this->input->post('imageid');
$what=$this->input->post('what');
$link=addslashes($this->input->post('link'));
$sort=$this->input->post('sort');
$text=addslashes($this->input->post('text'));
$img_text2=addslashes($this->input->post('img_text2'));

@$head=$this->input->post('head');
// @$typename=$this->input->post('typename');
	
	if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			$getlogins=$this->db->query("update site_img set img_link='$link',img_name='$cover',img_sort='$sort',img_text='$text' where img_id='$id'");
			echo 'YNAPS_SUCCESS'; die;
		} }else{ $getlogins=$this->db->query("update site_img set img_link='$link',img_sort='$sort',img_text='$text',img_head='$head',img_text2='$img_text2' where img_id='$id'");  
		echo 'YNAPS_SUCCESS'; die;
		 }
		}

function site_blog(){
@$what=$this->input->post('what');
@$comment=addslashes($this->input->post('comment'));
// if(str_word_count($comment) < 150 ){echo "The blog content should be atleast 150 words long."; die;}
@$scomment=addslashes($this->input->post('scomment'));
@$title=addslashes($this->input->post('title'));
@$types=$this->input->post('types');
@$blogid=$this->input->post('blogid');
@$blog_link=$this->input->post('blog_link');
@$till_date=$this->input->post('till_date');
$ip=$this->input->ip_address();
if($title!='' && $comment!=''){
	switch ($what){
	  case 'add_blog':
		if (!empty($_FILES['file_name']['name'])) {
		$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			$getlogins=$this->db->query("insert into site_blogs (title,scomment,comment,blog_time,blog_ip,blog_img,blog_link,blog_type,blog_till_date) values ('$title','$scomment','$comment',now(),'$ip','$cover','$blog_link','$types','$till_date')");
				echo 'YNAPS_SUCCESS'; die;
		} }else{ echo 'Please select the image'; }
		break;
	  case 'edit_blog':
	    $cover='';
		if (!empty($_FILES['file_name']['name'])) {
			$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
			if( substr($file_get_res,0,6) =='SUCCXX'){ 
				$cover=substr($file_get_res,6);
				$getlogins=$this->db->query("update site_blogs set title='$title',scomment='$scomment',comment='$comment ',blog_img='$cover',blog_link='$blog_link',blog_till_date='$till_date' where blog_id='$blogid'");
			}
		}
		else
		  $getlogins=$this->db->query("update site_blogs set title='$title',scomment='$scomment',comment='$comment',blog_link='$blog_link' where blog_id='$blogid'");	
		echo 'YNAPS_SUCCESS'; die;
		break;
	}
}//if
}



function services(){
	@$what=$this->input->post('what');
	@$price=$this->input->post('price');
	@$scomment=addslashes($this->input->post('scomment'));
	@$name=addslashes($this->input->post('name'));
	@$service_id=$this->input->post('service_id');
	@$meta_desc=addslashes($this->input->post('meta_desc'));

	if($name!='' && $scomment!=''){
		switch ($what){
		  case 'add_services':
			if (!empty($_FILES['file_name']['name'])) {
			$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
				$getlogins=$this->db->query("insert into `x-services` (service_name,price,service_image,service_description,service_meta_desc) values ('$name','$price','$cover','$scomment', '$meta_desc')");
					echo 'YNAPS_SUCCESS'; die;
			} }else{ echo 'Please select the image'; }
			break;
		  case 'edit_services':
			$cover='';
			if (!empty($_FILES['file_name']['name'])) {
				$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
				if( substr($file_get_res,0,6) =='SUCCXX'){ 
					$cover=substr($file_get_res,6);
					$getlogins=$this->db->query("update `x-services` set service_name='$name',price='$price',service_image='$cover',service_description='$scomment' , service_meta_desc='$meta_desc' where service_id='$service_id'");
				}
			}
			else
			  $getlogins=$this->db->query("update `x-services` set service_name='$name',price='$price',service_description='$scomment' , service_meta_desc='$meta_desc' where service_id='$service_id'");
			echo 'YNAPS_SUCCESS'; die;
			break;
		}
	}
	}









 function sm(){
 	get_admin_rights();
 	$fb=$this->input->post('fb');
 	$tw=$this->input->post('tw');
 	$yt=$this->input->post('yt');
 	$vi=$this->input->post('vi');
 	$blog=$this->input->post('blog');
 	$linkedin=$this->input->post('linkedin');
 	$insta=$this->input->post('insta');
 	$getlogins=$this->db->query("update admin_socialm set fb='$fb',tw='$tw',yt='$yt',vimeo='$vi',insta='$insta',blog='$blog',linkedin='$linkedin' ");
	echo 'YNAPS_SUCCESS';
 }

 function app(){
 	get_admin_rights();
 	$ios=$this->input->post('ios');
 	$and=$this->input->post('and');
 	$getlogins=$this->db->query("update admin_socialm set app_and='$and',app_ios='$ios'");
	echo 'YNAPS_SUCCESS';
 }

 function google(){
 	$step=$this->input->post('step');
 	switch($step){
 		case '1':
 			$name=$this->input->post('name');
 			$email=$this->input->post('email');
 			$phone=$this->input->post('phone');
 			$add=$this->input->post('add');
 			$web=$this->input->post('web');

 			if($name !='' && $email !='' && $phone !=''){
 				$update_admins=$this->db->query("update admin_files set founder='$name',email='$email',phone='$phone',address='$add',name='$web' where asid='1' ");
 			}else{
 				echo 'please enter name , email and phone'; die;
 			}
 			echo 'YNAPS_SUCCESS';

 		break;

 		case '1.1':
 			$map=addslashes($this->input->post('map'));

 			if($map !=''){
 				$update_admins=$this->db->query("update admin_files set map='$map' where asid='1' ");
 			}else{
 				echo 'Please enter Map code.'; die;
 			}
 			echo 'YNAPS_SUCCESS';

 		break;

 		case '2':
 			$about=addslashes($this->input->post('about'));
 			$brief=$this->input->post('brief');

 			if($about !='' && $brief ){
 				$update_admins=$this->db->query("update admin_files set brief='$brief' where asid='1' ");
 				$update_admins=$this->db->query("update admin_pages set content='$about' where name='about' ");
 			}else{
 				echo 'Please details'; die;
 			}
 			echo 'YNAPS_SUCCESS';

 		break;

 		case '3':
 			$ga=addslashes($this->input->post('ga'));
 			$ad=addslashes($this->input->post('ad'));
 			$map=addslashes($this->input->post('map'));
 			$f=addslashes($this->input->post('f'));
 			$f2=addslashes($this->input->post('f2'));
 			$chat=addslashes ($this->input->post('chat'));
 			$update_admins=$this->db->query("update admin_files set ga='$ga',ad='$ad',map='$map',f='$f',f2='$f2',chat='$chat' where asid='1' ");
 			echo 'YNAPS_SUCCESS';

 		break;
 	}
 }

 function add_testimonials(){
 		get_admin_rights();
 	$todo=$this->input->post('todo');
 		$name=$this->input->post('name');
 		$desi=$this->input->post('desi');
 		$company=$this->input->post('company');
 		$text=addslashes($this->input->post('text'));
 		$order=$this->input->post('order');
 		
 		if($todo !='-1'){
 		@$cvr_prf=$_FILES['image_name']['name'];
 		if($cvr_prf !=''){
		$file_get_res=uploadonlyimage('image_name',"assets/avator/webimg/t/",'75');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $NewImageName=substr($file_get_res,6);
			$addtesti=$this->db->query("update admin_testimonials set image='$NewImageName'where tid='$todo'  ");
		}}
		$addtesti=$this->db->query("update admin_testimonials set name='$name',role='$desi',company='$company',text='$text',li='$order' where tid='$todo' ");
		echo 'YNAPS_SUCCESS'; die;
 		}else{
 		$cvr_prf=$_FILES['image_name']['name'];
		$NewImageName='';
		$file_get_res=uploadonlyimage('image_name',"assets/avator/webimg/t/",'75');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $NewImageName=substr($file_get_res,6); }

 		$addtesti=$this->db->query("insert into admin_testimonials (name,image,role,company,text,li) values ('$name','$NewImageName','$desi','$company','$text','$order')");
 		echo 'YNAPS_SUCCESS'; die;
 		}
 }

 function edit_testimonials(){
 		get_admin_rights();
 		$name=$this->input->post('name');
 		$desi=$this->input->post('desi');
 		$company=$this->input->post('company');
 		$text=addslashes($this->input->post('text'));
 		$order=$this->input->post('order');
 		$id=$this->input->post('id');

 		if($text ==''){
 			$addtesti=$this->db->query("delete from admin_testimonials where tid='$id' ");
 			ob_end_flush(); redirect($_SERVER['HTTP_REFERER']);
 		}

 		$cvr_prf=$_FILES['image_name']['name'];
 		if($cvr_prf !=''){
		$file_get_res=uploadonlyimage('image_name',"assets/avator/webimg/t/",'75');
		if( substr($file_get_res,0,6) =='SUCCXX'){ $NewImageName=substr($file_get_res,6);
			$addtesti=$this->db->query("update admin_testimonials set image='$NewImageName' ");
		}}
		$addtesti=$this->db->query("update admin_testimonials set name='$name',role='$desi',company='$company',text='$text',li='$order' where tid='$id' ");
 		ob_end_flush(); redirect($_SERVER['HTTP_REFERER']);
 }



function user_modify(){
			get_admin_rights();
			$op=$this->input->GET('what');
			$id=$this->input->GET('id');
			if($_SESSION['aid'] !='' && $_SESSION['auth-rights'] =='2' ){
			switch($op){
				case 'active_user':
				$upadtsspost=$this->db->query("update site_mem set user_status='1' where mid='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;case 'ban_user':
				$upadtsspost=$this->db->query("update site_mem set user_status='2' where mid='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;case 'active_data_v':
				$upadtsspost=$this->db->query("update x_cou_datav set dtv_status='0' ");
				$upadtsspost=$this->db->query("update x_cou_datav set dtv_status='1' where dtv_id='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;case 'active_data_v2':
				$upadtsspost=$this->db->query("update site_mem set user_status='2' where mid='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;case 'reset_pass':
				$rand=rand(11111111,9999999);
				$pass=sha1($rand);
				$upadtsspost=$this->db->query("update site_mem set pass_nc='$rand',pass='$pass' where mid='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;
				case 'approve_tm':
				$upadtsspost=$this->db->query("update admin_testimonials set status='1' where tid='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;
				case 'pending_tm':
				$upadtsspost=$this->db->query("update admin_testimonials set status='0' where tid='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;
				default:

				break;
			}}else{
			ob_end_flush(); redirect(base_url('index.php/logout'));
			}
		}

		function delete(){
			$id=$_GET['id'];
			$what=$_GET['what'];

			if($_SESSION['aid'] !='' && $_SESSION['auth-rights'] =='2' ){
				switch($what){
					case 'fl1':
						$del_datas=$this->db->query("delete from u_flavours where fl_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'msg':
						$del_datas=$this->db->query("delete from site_contact where msid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;case 'provid':
						$del_datas=$this->db->query("delete from x_cou_prov where pr_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'clb':
						$del_datas=$this->db->query("delete from site_callback where clid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;
					case 'order':
						$del_datas=$this->db->query("delete from site_order where so_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'subs':
						$del_datas=$this->db->query("delete from site_subscribe where sbc_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'tags':
						$del_datas=$this->db->query("delete from site_tags_skills where stg_tgid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'cats':
						$del_datas=$this->db->query("delete from site_catagory where ctid='$id' ");
						$del_datas=$this->db->query("delete from site_sub_cat where sc_ctid='$id' ");
						$del_datas=$this->db->query("delete from mr_sub2 where mr_sub2_cid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'product':
						$del_datas=$this->db->query("delete from `x-products` where pid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'scat2':
						$del_datas=$this->db->query("delete from mr_sub2 where mr_sub2_sid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'csats':
						$del_datas=$this->db->query("delete from site_sub_cat where sc_id='$id' ");
						$del_datas=$this->db->query("delete from mr_sub2 where mr_sub2_sid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'user':
						$del_datas=$this->db->query("delete from site_mem where mid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;case 'tst':
						$del_datas=$this->db->query("delete from admin_testimonials where tid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;case 'img':
						$del_datas=$this->db->query("delete from site_img where img_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;case 'block_co':
						$del_datas=$this->db->query("delete from admin_pages where pid='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;case 'course_data':
						$del_datas=$this->db->query("delete from x_cou_courses where cou_version='$id' ");
						$del_datas=$this->db->query("delete from x_cou_datav where dtv_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;case 'blog':
						$del_datas=$this->db->query("delete from site_blogs where blog_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
						break;case 'service':
							$del_datas=$this->db->query("delete from `x-services` where service_id='$id' ");
							ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;

					case 'adm':
						$check_last_admin=$this->db->query("select aid from admin");
						if($check_last_admin->num_rows() !='1'){
							$this->db->query("delete from admin where aid='$id' ");
							ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
						}else{
							echo "This is the last Admin you cant delete this."; die;
						}
					break;
				}
			}else{
				ob_end_flush(); redirect(base_url('index.php/logout'));
			}

		}

		function page_data(){
			get_admin_rights();
			$text=addslashes($this->input->post('text'));
			$page=$this->input->post('page');
			$page_id=$this->input->post('page_id');

			// if(){}

			$update_admins=$this->db->query("update admin_pages set content='$text' where pid='$page_id' ");
			echo 'YNAPS_SUCCESS'; die;
		}
		function service_modify(){
			get_admin_rights();
			$op=$this->input->GET('what');
			$id=$this->input->GET('id');
			if($_SESSION['aid'] !='' && $_SESSION['auth-rights'] =='2' ){
			switch($op){
				// case 'active_serv':
				// $upadtsspost=$this->db->query("update x_ps_service set serv_status='1' where serv_id='$id' ");
				// ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				// break;
				case 'active_ord':
					$upadtsspost=$this->db->query("update site_order set so_status='2' where so_id='$id' ");
					ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;
			// case 'ban_serv':
			// 	$upadtsspost=$this->db->query("update x_ps_service set serv_status='2' where serv_id='$id' ");
			// 	ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
			// 	break;
				case 'ban_ord':
					$upadtsspost=$this->db->query("update site_order set so_status='0' where so_id='$id' ");
					ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;
					case 'pen_ord':
						$upadtsspost=$this->db->query("update site_order set so_status='1' where so_id='$id' ");
						ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
						break;
						case 'del_ord':
							$upadtsspost=$this->db->query("update site_order set so_status='3' where so_id='$id' ");
							ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
							break;
			case 'reset_pass':
				$rand=rand(11111111,9999999);
				$pass=sha1($rand);
				$upadtsspost=$this->db->query("update site_mem set pass_nc='$rand',pass='$pass' where mid='$id' ");
				ob_end_flush(); redirect($_SERVER['HTTP_REFERER'].'?msg=success');
				break;
			default:

				break;
			}}else{
			ob_end_flush(); redirect(base_url('index.php/logout'));
			}
		}

		function add_page_data(){
			get_admin_rights();
			$text=addslashes($this->input->post('text'));
			$page=$this->input->post('page');
			$type2=$this->input->post('type2');
			// $checks_sops=$this->db->query("select * from admin_pages where name='$page' ");
			// if($checks_sops->num_rows() >0){echo "Please add a unique name"; die;}
			$update_admins=$this->db->query("insert into admin_pages (content,name,type) values ('$text','$page','$type2') ");
			echo 'YNAPS_SUCCESS'; die;
		}
//////////////////////////////////////////// THIS IS CUSTOM //////////////////////////////////////

		
		function site_prov(){
			@$comment=addslashes($this->input->post('comment'));
			// if(str_word_count($comment) < 150 ){echo "The blog content should be atleast 150 words long."; die;}
			@$scomment=addslashes($this->input->post('scomment'));
			@$title=$this->input->post('title');
			@$blogid=$this->input->post('blogid');
			@$blog_link2=$this->input->post('blog_link2');
			@$blog_link=$this->input->post('blog_link');
			@$pr_priority=$this->input->post('pr_priority');
			@$what=$this->input->post('what');
			$ip=$this->input->ip_address();
			
				switch ($what){
				  case 'add_prov':
					if (!empty($_FILES['file_name']['name'])) {
					$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
					if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
						$getlogins=$this->db->query("insert into x_cou_prov (pr_name,pr_title,pr_image,pr_desc,pr_date,pr_priority) values ('$blog_link','$title','$cover','$scomment',now(),'$pr_priority')");
							echo 'YNAPS_SUCCESS'; die;
					} }else{ echo 'Please select the image'; }
					break;
				  case 'edit_prov':
				    $cover='';
					if (!empty($_FILES['file_name']['name'])) {
						$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
						if( substr($file_get_res,0,6) =='SUCCXX'){ 
							$cover=substr($file_get_res,6);
							$getlogins=$this->db->query("update x_cou_prov set pr_title='$title',pr_desc='$scomment',pr_image='$cover',pr_name='$blog_link',pr_priority='$pr_priority' where pr_id='$blogid'");
							
							if($blog_link2 !=''){
								$getlogins=$this->db->query("update x_cou_courses set cou_merchant_name='$blog_link' where cou_merchant_name='$blog_link2'");
							}

						}
					}
					else
					  $getlogins=$this->db->query("update x_cou_prov set pr_title='$title',pr_desc='$scomment',pr_name='$blog_link',pr_priority='$pr_priority' where pr_id='$blogid'");	
					echo 'YNAPS_SUCCESS'; die;
					break;
				}
			
		}

		function add_versi(){
			@$comment=addslashes($this->input->post('comment'));
			// if(str_word_count($comment) < 150 ){echo "The blog content should be atleast 150 words long."; die;}
			@$scomment=addslashes($this->input->post('scomment'));
			@$title=$this->input->post('title');
			@$blogid=$this->input->post('blogid');
			@$blog_link=$this->input->post('blog_link');
			@$what=$this->input->post('what');
			$ip=$this->input->ip_address();
			
				switch ($what){
				  case 'add_versi':
					$getlogins=$this->db->query("insert into x_cou_datav (dtv_name,dtv_desc,dtv_did,dtv_date,dtv_status) values ('$blog_link','$scomment','$title',now(),'0')");
							echo 'YNAPS_SUCCESS'; die;
					break;
				  case 'edit_prov':
				    $cover='';
					if (!empty($_FILES['file_name']['name'])) {
						$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
						if( substr($file_get_res,0,6) =='SUCCXX'){ 
							$cover=substr($file_get_res,6);
							$getlogins=$this->db->query("update x_cou_datav set pr_title='$title',pr_desc='$scomment',pr_image='$cover',pr_name='$blog_link' where pr_id='$blogid'");
						}
					}
					else
					  $getlogins=$this->db->query("update x_cou_datav set pr_title='$title',pr_desc='$scomment',pr_name='$blog_link' where pr_id='$blogid'");	
					echo 'YNAPS_SUCCESS'; die;
					break;
				}
			
		}
	
// Add this method to your Admin_action controller
// Location: application/controllers/admin_action.php

public function exit_permit(){
    get_admin_rights(); // Check admin permissions
    
    $what = $this->input->post('what');
    $id = $this->input->post('id');
    
    // Collect form data
    $name = addslashes($this->input->post('name'));
    $pass_no = $this->input->post('pass_no');
    $country = $this->input->post('country');
    $start_date = $this->input->post('start_date');
    $end_date = $this->input->post('end_date');
    $ref_no = $this->input->post('ref_no');
    $random_key = $this->input->post('random_key');
    
    // Validation
    if(trim($name) == ''){
        echo "Please enter name."; die;
    }
    if(trim($pass_no) == ''){
        echo "Please enter passport number."; die;
    }
    if(trim($country) == ''){
        echo "Please enter country."; die;
    }
    if(trim($start_date) == ''){
        echo "Please enter start date."; die;
    }
    if(trim($end_date) == ''){
        echo "Please enter end date."; die;
    }
    
    // Generate random key if empty
    if(trim($random_key) == ''){
        $random_key = bin2hex(random_bytes(16)); // Generates 32 character hex string
    }
    
    // Check if key already exists (for add operation)
    if($what == 'add_exit_permit'){
        $check_key = $this->db->query("SELECT pid FROM exit_permit WHERE random_key='$random_key'");
        if($check_key->num_rows() > 0){
            echo "This key already exists. Please use a different key or leave empty for auto-generation."; die;
        }
    }
    
    // Handle image upload
    $cover = '';
    if (!empty($_FILES['file_name']['name'])) {
        $file_get_res = uploadonlyimage('file_name', "assets/avator/upload/", '69');
        if(substr($file_get_res, 0, 6) == 'SUCCXX'){ 
            $cover = substr($file_get_res, 6);
        } else {
            echo "Error uploading image. Please try again."; die;
        }
    }
    
    switch($what){
        case 'add_exit_permit':
            if($cover == ''){
                echo "Please select an image."; die;
            }
            
            $query = "INSERT INTO exit_permit 
                     (name, pass_no, country, start_date, end_date, ref_no, random_key, image1, created_date) 
                     VALUES 
                     ('$name', '$pass_no', '$country', '$start_date', '$end_date', '$ref_no', '$random_key', '$cover', NOW())";
            
            $this->db->query($query);
            echo 'YNAPS_SUCCESS';
            break;
            
        case 'edit_exit_permit':
            if($id == ''){
                echo "Invalid exit permit ID."; die;
            }
            
            // Update query - only update image if new one is uploaded
            if($cover != ''){
                $query = "UPDATE exit_permit SET 
                         name='$name', 
                         pass_no='$pass_no', 
                         country='$country', 
                         start_date='$start_date', 
                         end_date='$end_date', 
                         ref_no='$ref_no', 
                         random_key='$random_key',
                         image1='$cover',
                         updated_date=NOW()
                         WHERE pid='$id'";
            } else {
                $query = "UPDATE exit_permit SET 
                         name='$name', 
                         pass_no='$pass_no', 
                         country='$country', 
                         start_date='$start_date', 
                         end_date='$end_date', 
                         ref_no='$ref_no', 
                         random_key='$random_key',
                         updated_date=NOW()
                         WHERE pid='$id'";
            }
            
            $this->db->query($query);
            echo 'YNAPS_SUCCESS';
            break;
            
        default:
            echo "Invalid operation.";
            break;
    }
}

		function products(){
			@$what=$this->input->post('what');
			$price=$this->input->post('price');
			@$product_id=$this->input->post('product_id');
		
			@$pno = $this->input->post('p_no');
			@$name = $this->input->post('name');
			@$country = $this->input->post('p_country');
			@$v_cat = $this->input->post('v_cat');
			@$v_sub_cat	= $this->input->post('v_sub_cat');
		
			$a_type = $this->input->post('a_type');
			$s_fac  = $this->input->post('s_fac');
			$s_date  = $this->input->post('s_date');
			$e_date = $this->input->post('e_date');
			$duration = $this->input->post('price');
			$desc = $this->input->post('desc');
			$key=$this->input->post('link');
			$key = urlencode($key);
			$ref = $this->input->post('r_no');
		
			if (trim($name)=='') {
				echo "Please Enter Name.";
			}
			if (trim($pno)=='') {
				echo "Please Enter Passport no.";
			}
			if (trim($a_type)=='') {
				echo "Please Enter Price.";
			}
			if(isset($name) && isset($pno) && isset($a_type) ){
				switch ($what){
				  case 'add_products':
					if (!empty($_FILES['file_name']['name'])) {
					$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
					// $file_get_res2=uploadonlyimage('file_name2',"assets/avator/upload/",'69');
		
					if( substr($file_get_res,0,6) =='SUCCXX'){ 
						$cover=substr($file_get_res,6);
						if (!empty($_FILES['file_name2']['name'])) {
							$file_get_res2=uploadonlyimage('file_name2',"assets/avator/upload/",'69');
							if( substr($file_get_res2,0,6) =='SUCCXX'){
								$cover2=substr($file_get_res2,6);
							}else{$cover2='';}
						}else{
							$cover2='';
						}
						
						// echo "insert into  `x-products`( `name`, `image1`, `image2`, `provider_restu_name`, `provider_address`, `provider_phone`, `provider_email`, `title`, `desc`, `discount_code`, `valid`, `discount`, `category`, `star`, `price`, `wk`,`time`,`weekdays`) values ('$name','$cover','$cover2','$restu_name','$provider_address','$provider_phone', '$provider_email', '$title', '$desc', '$discount_code', '$valid', '$discount', '$category', '$star', '$price', '$wk','$time','$weekday')"; die;

					$getlogins=$this->db->query("insert into  `x-products`( `name`, `pass_no`, `country`, `visa_cat`, `visa_sub_cat`, `application_type`, `staying_facility`, `start_date`, `end_date`, `visa_duration`, `image1`, `desc`,`ref_no`  , `random_key`) values ('$name','$pno','$country','$v_cat','$v_sub_cat','$a_type', '$s_fac', '$s_date', '$e_date', '$duration', '$cover', '$desc', '$ref' ,'$key')");
					
							echo 'YNAPS_SUCCESS';
					}else{echo 'Please select correct images';} }else{ echo 'Please select the images'; }
					break;
				  
				  case 'edit_product':
					$cover ='';
					$cover2='';
					
					if (!empty($_FILES['file_name']['name'])) {
					$file_get_res=uploadonlyimage('file_name',"assets/avator/upload/",'69');
		
						if( substr($file_get_res,0,6) =='SUCCXX'){ 
							$cover=substr($file_get_res,6);
							if (!empty($_FILES['file_name2']['name'])) {
		
								$file_get_res2=uploadonlyimage('file_name2',"assets/avator/upload/",'69');
								if( substr($file_get_res2,0,6) =='SUCCXX'){
									$cover2=substr($file_get_res2,6);
									
								}else{$cover2='';}
							}else{
								$cover2='';
							}
		
							$getlogins=$this->db->query("UPDATE `x-products` set name='$name',`pass_no`='$pass_no',`country`='$cover2',`visa_cat`='$v_cat',`visa_sub_cat`='$v_sub_cat',
					`application_type`='$a_type', `staying_facility`='$s_fac',`start_date`='$s_date',`end_date`='$e_date',`visa_duration`='$duration',`image1`='$cover',`desc`='$desc', `ref_no`='$ref', `random_key`='$key'  where pid='$product_id' ");
					    //die($getlogins);
					    //die($this->db->last_query());
		
						echo 'YNAPS_SUCCESS';
						}
					}else{
						$getlogins=$this->db->query("UPDATE `x-products` set name='$name',`pass_no`='$pass_no',`country`='$cover2',`visa_cat`='$v_cat',`visa_sub_cat`='$v_sub_cat',
						`application_type`='$a_type', `staying_facility`='$s_fac',`start_date`='$s_date',`end_date`='$e_date',`visa_duration`='$duration',`image1`='$cover',`desc`='$desc', `ref_no`='$ref', `random_key`='$key' where pid='$product_id' ");
					//die($this->db->last_query());
					echo 'YNAPS_SUCCESS';}
					  
					break;
					
					default:
					echo 'Sorry! action could not be performed, try again.';
					break;
				}
			}else{
				echo 'Please enter product details to continue.';
			}
		}
			
	

//end the class
}


/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */