<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Admin_action_custom extends CI_Controller {
		
		public function add_bike(){
			$name=$this->input->post('name');
			$title=$this->input->post('title');
			$desc=$this->input->post('desc');
			$cat=$this->input->post('cat');
			$features=$this->input->post('features');
			
			$op1=$this->input->post('op1');
			$op2=$this->input->post('op2');
			$op3=$this->input->post('op3');
			$op4=$this->input->post('op4');
			$op5=$this->input->post('op5');
			$op6=$this->input->post('op6');
			$op7=$this->input->post('op7');
			$op8=$this->input->post('op8');
			$op9=$this->input->post('op9');
			$op10=$this->input->post('op10');
			$op11=$this->input->post('op11');
			$op12=$this->input->post('op12');
			$op13=$this->input->post('op13');
			$op14=$this->input->post('op14');
			$op15=$this->input->post('op15');
			$op16=$this->input->post('op16');
			$op17=$this->input->post('op17');
			$op18=$this->input->post('op18');
			$op19=$this->input->post('op19');
			$op20=$this->input->post('op20');
			$op21=$this->input->post('op21');
			$op22=$this->input->post('op22');
			$op23=$this->input->post('op23');
			
			
			@$type=$this->input->post('type');
			if($name !='' && $title !=''){

				// check for unique name
				$get_list_dtas=$this->db->query("select * from su_bikes where sb_name ='$name' ");
				if($get_list_dtas->num_rows() >0){
					echo "This is not a unique name please use different name, Thankx"; die;
				}


			if (!empty($_FILES['file2']['name'])) {
			$file_get_res=uploadonlyimage('file2',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover2=substr($file_get_res,6);
			} }else{ 
				$cover2='';
			}if (!empty($_FILES['file3']['name'])) {
			$file_get_res=uploadonlyimage('file3',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover3=substr($file_get_res,6);
			} }else{ 
				$cover3='';
			}if (!empty($_FILES['file4']['name'])) {
			$file_get_res=uploadonlyimage('file4',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover4=substr($file_get_res,6);
			} }else{ 
				$cover4='';
			}if (!empty($_FILES['file5']['name'])) {
			$file_get_res=uploadonlyimage('file5',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover5=substr($file_get_res,6);
			} }else{ 
				$cover5='';
			}

			if (!empty($_FILES['file']['name'])) {
			$file_get_res=uploadonlyimage('file',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
			} }else{ $cover=''; echo 'Please select image for your bike.'; die; }

			if (!empty($_FILES['file6']['name'])) {
			$file_get_res=uploadonlyimage('file6',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover6=substr($file_get_res,6);
			} }else{ $cover6=''; echo 'Please select image for your bike.'; die; }


			if (!empty($_FILES['file7']['name'])) {
			$file_get_res=uploadonlyimage('file7',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover7=substr($file_get_res,6);
			} }else{ $cover7='';  }
	
		if (!empty($_FILES['file8']['name'])) {
			$file_get_res=uploadonlyimage('file8',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover8=substr($file_get_res,6);
			} }else{ $cover8='';  }
if (!empty($_FILES['file9']['name'])) {
			$file_get_res=uploadonlyimage('file9',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover9=substr($file_get_res,6);
			} }else{ $cover9='';  }
if (!empty($_FILES['file10']['name'])) {
			$file_get_res=uploadonlyimage('file10',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover10=substr($file_get_res,6);
			} }else{ $cover10='';  }
if (!empty($_FILES['file11']['name'])) {
			$file_get_res=uploadonlyimage('file11',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover11=substr($file_get_res,6);
			} }else{ $cover11='';  }

				$addadatasto=$this->db->query("insert into su_bikes (sb_ctid,sb_name,sb_title,sb_desc,sb_features,sb_op1,sb_op2,sb_op3,sb_op4,sb_op5,sb_op6,sb_op7,sb_op8,sb_op9,sb_op10,sb_op11,sb_op12,sb_op13,sb_op14,sb_op15,sb_op16,sb_op17,sb_op18,sb_op19,sb_op20,sb_op21,sb_op22,sb_op23,sb_img1,sb_img2,sb_img3,sb_img4,sb_img5,sb_img6,sb_status,sb_img7,sb_img8,sb_img9,sb_img10,sb_img11) values ('$cat','$name','$title','$desc','$features','$op1','$op2','$op3','$op4','$op5','$op6','$op7','$op8','$op9','$op10','$op11','$op12','$op13','$op14','$op15','$op16','$op17','$op18','$op19','$op20','$op21','$op22','$op23','$cover','$cover2','$cover3','$cover4','$cover5','$cover6','$type','$cover7','$cover8','$cover9','$cover10','$cover11')");
				echo 'YNAPS_SUCCESS';
			}else{
				echo 'Please add name and title of the bike';
			}
		}public function edit_bike(){
			$name=$this->input->post('name');
			$title=$this->input->post('title');
			$desc=$this->input->post('desc');
			$cat=$this->input->post('cat');
			$features=$this->input->post('features');
			
			$op1=$this->input->post('op1');
			$op2=$this->input->post('op2');
			$op3=$this->input->post('op3');
			$op4=$this->input->post('op4');
			$op5=$this->input->post('op5');
			$op6=$this->input->post('op6');
			$op7=$this->input->post('op7');
			$op8=$this->input->post('op8');
			$op9=$this->input->post('op9');
			$op10=$this->input->post('op10');
			$op11=$this->input->post('op11');
			$op12=$this->input->post('op12');
			$op13=$this->input->post('op13');
			$op14=$this->input->post('op14');
			$op15=$this->input->post('op15');
			$op16=$this->input->post('op16');
			$op17=$this->input->post('op17');
			$op18=$this->input->post('op18');
			$op19=$this->input->post('op19');
			$op20=$this->input->post('op20');
			$op21=$this->input->post('op21');
			$op22=$this->input->post('op22');
			$op23=$this->input->post('op23');
			$flid=$this->input->post('flid');
			
			
			@$type=$this->input->post('type');
			
			if($name !='' && $title !=''){

				// check for unique name
				$get_list_dtas=$this->db->query("select * from su_bikes where sb_name ='$name' and sb_id !='$flid' ");
				if($get_list_dtas->num_rows() >0){
					echo "This is not a unique name please use different name, Thankx"; die;
				}


			if (!empty($_FILES['file2']['name'])) {
			$file_get_res=uploadonlyimage('file2',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover2=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img2='$cover2' where sb_id='$flid' ");
			} }if (!empty($_FILES['file3']['name'])) {
			$file_get_res=uploadonlyimage('file3',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover3=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img3='$cover3' where sb_id='$flid' ");
			} }if (!empty($_FILES['file4']['name'])) {
			$file_get_res=uploadonlyimage('file4',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover4=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img4='$cover4' where sb_id='$flid' ");
			} }if (!empty($_FILES['file5']['name'])) {
			$file_get_res=uploadonlyimage('file5',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover5=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img5='$cover5' where sb_id='$flid' ");
			} }

			if (!empty($_FILES['file6']['name'])) {
			$file_get_res=uploadonlyimage('file6',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover6=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img6='$cover6' where sb_id='$flid' ");
			} }if (!empty($_FILES['file7']['name'])) {
			$file_get_res=uploadonlyimage('file7',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover7=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img7='$cover7' where sb_id='$flid' ");
			} }if (!empty($_FILES['file8']['name'])) {
			$file_get_res=uploadonlyimage('file8',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover8=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img8='$cover8' where sb_id='$flid' ");
			} }if (!empty($_FILES['file9']['name'])) {
			$file_get_res=uploadonlyimage('file9',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover9=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img9='$cover9' where sb_id='$flid' ");
			} }if (!empty($_FILES['file10']['name'])) {
			$file_get_res=uploadonlyimage('file10',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover10=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img10='$cover10' where sb_id='$flid' ");
			} }if (!empty($_FILES['file11']['name'])) {
			$file_get_res=uploadonlyimage('file11',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover11=substr($file_get_res,6);
			$update_details=$this->db->query("update su_bikes set sb_img11='$cover11' where sb_id='$flid' ");
			} }

			if (!empty($_FILES['file']['name'])) {
			$file_get_res=uploadonlyimage('file',"assets/avator/upload/bike/",'65');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $cover=substr($file_get_res,6);
				$update_details=$this->db->query("update su_bikes set sb_img1='$cover' where sb_id='$flid' ");
			} }

				
			// $addadatasto=$this->db->query("insert into su_bikes (sb_ctid,sb_name,sb_title,sb_desc,sb_features,sb_op1,sb_op2,sb_op3,sb_op4,sb_op5,sb_op6,sb_op7,sb_op8,sb_op9,sb_op10,sb_op11,sb_op12,sb_op13,sb_op14,sb_op15,sb_op16,sb_op17,sb_op18,sb_op19,sb_op20,sb_op21,sb_op22,sb_op23,sb_img1,sb_img2,sb_img3,sb_img4,sb_img5,sb_img6,sb_status) values ('$cat','$name','$title','$desc','$features','$op1','$$op2','$op3','$op4','$op5','$op6','$op7','$op8','$op9','$op10','$op11','$op12','$op13','$op14','$op15','$op16','$op17','$op18','$op19','$op20','$op21','$op22','$op23','$cover','$cover2','$cover3','$cover4','$cover5','$cover6','$type')");
				
			$update_details=$this->db->query("update sb_ctid='$cat' where sb_id='$flid' ");


			$update_details=$this->db->query("update su_bikes set sb_name='$name',sb_title='$title',sb_desc='$desc',sb_features='$features',sb_op1='$op1',sb_op2='$op2',sb_op3='$op3',sb_op4='$op4',sb_op5='$op5',sb_op6='$op6',sb_op7='$op7',sb_op8='$op8',sb_op9='$op9',sb_op10='$op10',sb_op11='$op11',sb_op12='$op12',sb_op13='$op13',sb_op14='$op14',sb_op15='$op15',sb_op16='$op16',sb_op17='$op17',sb_op18='$op18',sb_op19='$op19',sb_op20='$op20',sb_op21='$op21',sb_op22='$op22',sb_op23='$op23' where sb_id='$flid' ");
				echo 'YNAPS_SUCCESS';
			}else{
				echo 'Please add name and title of the bike';
			}
		}

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

			if($_SESSION['aid'] !='' ){
				switch($what){
					case 'course':
						$del_datas=$this->db->query("delete from x_cou_courses where cou_id='$id' ");
						redirect($_SERVER['HTTP_REFERER'].'?msg=success');
					break;
				}
			}else{
				redirect(base_url('index.php/logout'));
			}

		}

		function modify(){
			get_admin_rights();
			$op=$this->input->GET('what');
			$id=$this->input->GET('id');
			if($_SESSION['aid'] !='' && $_SESSION['auth-rights'] =='2' ){

			if (strpos($_SERVER['HTTP_REFERER'],'?') !== false) {$add='&msg=success';}else{$add='?msg=success';}

			switch($op){
			case 'paid':
			$this->db->query("update `x-orders` set chk_payment_status='1' where or_order_id='$id' ");
				redirect($_SERVER['HTTP_REFERER'].$add);
				break;
			case 'unpaid':
			$this->db->query("update `x-orders` set chk_payment_status='0' where or_order_id='$id' ");
				redirect($_SERVER['HTTP_REFERER'].$add);
				break;
			case 'Confirmed':
			$this->db->query("update `x-orders` set checkout_status='1' where or_order_id='$id' ");
				redirect($_SERVER['HTTP_REFERER'].$add);
				break;
			case 'Cancelled':
			$this->db->query("update `x-orders` set checkout_status='2' where or_order_id='$id' ");
				redirect($_SERVER['HTTP_REFERER'].$add);
				break;
			case 'Shipped':
			$this->db->query("update `x-orders` set checkout_status='3' where or_order_id='$id' ");
				redirect($_SERVER['HTTP_REFERER'].$add);
				break;
			case 'Completed':
			$this->db->query("update `x-orders` set checkout_status='4' where or_order_id='$id' ");
				redirect($_SERVER['HTTP_REFERER'].$add);
				break;
			default:
				echo "Not matched";
			}
		}
	}
	function add_gen_product(){		
		//$inv_invoice_id=$this->input->post('inv_invoice_id');
		$inv_order_id=$this->input->post('inv_order_id');
		// $inv_cust_name=$this->input->post('inv_cust_name');
		// $inv_cust_email=$this->input->post('inv_cust_email');
		// $inv_cust_phone=$this->input->post('inv_cust_phone');
		// $inv_cust_addr=addslashes($this->input->post('inv_cust_addr'));
		// $inv_discount=@$this->input->post('inv_discount');
		// $inv_delivery=@$this->input->post('inv_delivery');
		// $inv_gst=@$this->input->post('inv_gst');
		$inv_pid=@$this->input->post('inv_pid');
		$edit=@$this->input->post('edit');
		//if($inv_order_id!='' && $inv_cust_name!='' && $inv_cust_email!='' && $inv_cust_phone!='' && $inv_cust_addr!=''){
		if($inv_order_id!=''){
			$total=0;
			$product_details=array();
			for($i=1; $i<$inv_pid; $i++){
				$inv_prod=$inv_prod_batch=$inv_prod_mfg='';
				$inv_prod_price=$inv_prod_qty=$sum=$inv_prod_dis=0;
				$inv_prd='inv_prod'.$i;
				if(isset($_POST[$inv_prd]) && $_POST[$inv_prd]!=''){
					$inv_prod=@$this->input->post($inv_prd);
				}
				$inv_prod_pr='inv_prod'.$i.'_price';
				if(isset($_POST[$inv_prod_pr]) && $_POST[$inv_prod_pr]!=''){
					$inv_prod_price=@$this->input->post($inv_prod_pr);
				}
				$inv_prod_q='inv_prod'.$i.'_qty';
				if(isset($_POST[$inv_prod_q]) && $_POST[$inv_prod_q]!=''){
					$inv_prod_qty=@$this->input->post($inv_prod_q);
				}
				
				if($inv_prod_price>0 && $inv_prod_qty>0){
					$sum=($inv_prod_price * $inv_prod_qty);
					$total+=$sum;
					array_push($product_details, array($inv_prod, $inv_prod_price, $inv_prod_qty, $sum));
				}
				
			}//for
//print_r($product_details);die;
			
		        $products=serialize($product_details);
		        if($edit=='0'){
					$getInvoice=$this->db->query("INSERT INTO `x_gen_products`(  `gp_products`, gp_order_id) VALUES ( '$products', '$inv_order_id')");
		        }
		        
				echo 'YNAPS_SUCCESS';die;
		}else{
			echo "Please enter Order ID to generate";die;
		}
		
	}

		////////////////////////////////////////////////////////
	}