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

class Action extends CI_Controller {
	function __construct(){
		parent::__construct();
	}
	/**
	 * 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 https://codeigniter.com/user_gfavIde/general/urls.html
	 */
	public function signup()
	{

		$this->load->library('form_validation');
		$this->form_validation->set_rules('email','email','required');
		$this->form_validation->set_rules('name','name','required');
		$this->form_validation->set_rules('phone','phone','required');
		$this->form_validation->set_rules('pass','pass','required');
		// $this->form_validation->set_rules('code','code','required');

		

		@$captcha=$this->input->post('g-recaptcha-response');
        $this->load->view('inc/recaptchalib');
        if(!$captcha){ echo 'Please check the the captcha form.'; die; }
        $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfgnxAUAAAAAD9TwtAKzP0dmqZenOeWb0OMCmrN&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
        // if($response['success'] == false){ echo 'Sorry, Captcha failed !!'; die; }

		//print_r($_POST);die;
		if($this->form_validation->run()){

			// $refer='0';

			$name=$this->input->post('name');
			$email=$this->input->post('email');
			$phone=preg_replace('/[^0-9]/', '', $this->input->post('phone'));
			$pass=$this->input->post('pass');
			// $code=$this->input->post('code');
			//$user_type=$this->input->post('user_type');
			// $refer=$this->input->post('refer');
			

			check_mobile($phone);
			emailCHECK($email);

			// check_mobile($phone);
			// $phone=$code.$phone;
			// check password
			check_passwords($pass,'PD001');
			
			$randon=rand('11111','99999');
			$signup_data=array(
				'name' =>$name,
				'email' =>$email,
				'contact' =>$phone,
				'pass' =>sha1($pass),
				//'user_dob' =>$dob,
				'cover' =>'cover.jpg',
				'photo' =>'photo.jpg',
				'user_status' => '1'
				//'user_type' =>$user_type,
				// 'user_reffer_by' =>$refer,
				// 'user_reffer' =>$randon,
			);
			$receive=$this->ynaps_model->signup($signup_data,$email,$phone);
			if($receive =='YNAPS_SUCCESS'){
				
			// create dir
			$yid=$_SESSION['yid'];
			$dirPath = "assets/mem/$yid";
			$dirPath2 = "assets/mem/$yid/img/";
			mkdir($dirPath, 0777, TRUE);
			mkdir($dirPath2, 0777, TRUE);

			$file = base_url().'assets/avator/main-profile.jpg';
			$file2 = base_url().'assets/avator/cover.jpg';
			$tocoppy="$dirPath2/photo.jpg";
			$tocoppy2="$dirPath2/cover.jpg";
			$abch=copy($file, $tocoppy);
			$abch2=copy($file2, $tocoppy2);

				//send email
			$site_details=db_variables();
			$site_brief=$site_details['site_brief'];
			$site_name=$site_details['site_name'];
			$site_email=$site_details['site_email'];
			$site_address=$site_details['site_address'];

			$hash=sha1($email);
            $code=rand(1111,9999);
            
            $_SESSION['signup_code_email']=$code;

            $emaillist_act=array("$email","$site_email");
            $json_string = array( 'to' =>$emaillist_act,'category' => 'signup-form');
            $tos="$email";
            $subject09="Welcome to $site_name | your OTP is $code";
            $preheader="Welcome to $site_name family.";
            $greet="Hi, $name";
            $message="Thank you for joining $site_name. <br/> Please enter the OTP as $code to verify your email.";
            $link=base_url('otp-verify');
            $linkname='Browse Website';
            $message2="$site_brief";
            $greet2='Thank you so much';
            $myName_emailis="Membership";
            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
            send_email($tos,$subject09,$messageto90,$site_name,$json_string);
				//send sms

            //$theOpt_ph=rand(1111,9999);
            //$_SESSION['signup_code_phone']=$theOpt_ph;
            $sms_mess="Thank you for joining $site_name. Please enter the OTP as $code to verify your Mobile.";
            // send_sms($phone,$sms_mess);

				// create session
            	@session_start();
                $_SESSION['yid']=$yid;
                $_SESSION['name']=$name;
            	$_SESSION['email']=$email;
                $_SESSION['phone']=$phone;
                //$_SESSION['user_type']=$user_type;
                $_SESSION['verify']='0';
                $_SESSION['photo']='photo.jpg';
                $_SESSION['plan']='0';

                echo 'YNAPS_SUCCESS'; die;
			}else{
			echo $receive; die;
			}


			//true
		}else{
			// false
			echo 'Please enter all the required details.'; die;
		}
	}

	function opt_verify(){
		$ecode_re_em=$_SESSION['signup_code_email'];
		//$ecode_re_mo=$_SESSION['signup_code_phone'];
		$yid=$_SESSION['yid'];

		$motp=$this->input->post('motp');
	
		$eotp=$this->input->post('eotp');
		$dal='0';

		if($eotp == $ecode_re_em){
			$update_mem=$this->db->query("update site_mem set user_email_status='1' where mid='$yid' ");
		}else{
			$dal='1';
			echo "Email OTP does not matces, please check your email OTP.";
		}

		// if($motp == $ecode_re_mo){
		// 	$update_mem=$this->db->query("update site_mem set user_phone_status='1' where mid='$yid' ");
		// }else{
		// 	$dal='1';
		// 	echo "Mobile OTP does not matches, please check your Mobile OTP.";
		// }
		if($dal =='0'){
			echo 'YNAPS_SUCCESS';		
		}

	}

	function login(){
		$this->load->library('form_validation');
		$this->form_validation->set_rules('email','email','required');
		$this->form_validation->set_rules('pass','pass','required');
		if($this->form_validation->run()){

			$email=$this->input->post('email');
			$pass=$this->input->post('pass');
			if($this->ynaps_model->login($email,$pass)){

				$cookie = array(
                    'name'   => 'user-email',
                    'value'  => $email,
                    'expire' =>  865000,
                    'secure' => false
                );
                $this->input->set_cookie($cookie);

				echo 'YNAPS_SUCCESS';
			}else{
				echo 'Please check your login details, email and password combination does not match'; die;
			}
			//true
		}else{
			// false
			echo 'Please enter your email and passowrd.'; die;
		}
	}

	function password_reset(){
    		$site_details=db_variables();
			$site_brief=$site_details['site_brief'];
			$site_name=$site_details['site_name'];
			$site_email=$site_details['site_email'];
			$site_address=$site_details['site_address'];

			// google captcha not needed here
    	@$captcha=$this->input->post('g-recaptcha-response');
        $this->load->view('inc/recaptchalib');
        if(!$captcha){ echo 'Please check the the captcha form.'; die; }
        $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfgnxAUAAAAAD9TwtAKzP0dmqZenOeWb0OMCmrN&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
        //if($response['success'] == false){ echo 'Sorry, Captcha failed !!'; die; }

			$email=$this->input->post('email');
			$hash=sha1($email);
            $code=rand(1111,9999);

        	if(@$email ==''){
        		echo "Please enter your email"; die;
        	}

        	// check user and set pin
        	$getdats=$this->db->query("SELECT email from site_mem where email='$email' ");
        	if($getdats->num_rows() > 0 ){
        		$updatethepin=$this->db->query("UPDATE site_mem set pass_reset='$code' where email='$email' ");
        	}else{
        		echo "No user exists with this email"; die;
        	}


			
            $emaillist_act=array("$email","$site_email");
            $json_string = array( 'to' =>$emaillist_act,'category' => 'signup-form');
            $tos="$email";
            $subject09="Password Reset";
            $preheader="Hello you requested to reset your passwrod...";
            $greet="Hi,";
            $message="Hello you requested to reset your passwrod, please click the link below to reset your password.";
            $link=base_url('index.php/main/reset_password')."?mail=".$email.'&ha='.sha1($email).'90&c='.$code;
            $linkname='Password reset';
            $message2="$site_brief";
            $greet2='Thank you so much';
            $myName_emailis="Password Reset";
            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
            send_email($tos,$subject09,$messageto90,$site_name,$json_string);
            echo "YNAPS_SUCCESS";

    }
    function password_reset2(){
    	$e=$this->input->post('e');
    	$pass=$this->input->post('pass1');
    	$pass2=$this->input->post('pass2');

    	if($pass == $pass2){
    		$pass=sha1($pass);
    		$updatepass=$this->db->query("update site_mem set pass='$pass',pass_reset='',pass_nc='' where email='$e' ");
    		echo "YNAPS_SUCCESS";
    	}else{
    		echo 'The two passwords do not match'; die;
    	}
    }function password_change(){
    	$pass=$this->input->post('pass');
    	$pass1=$this->input->post('pass1');
    	$pass2=$this->input->post('pass2');
    	$yid=$_SESSION['yid'];

    	$hegtepass=$this->db->query("select pass from site_mem where mid='$yid'");
    	$passa_Sdat=$hegtepass->row_Array();

    	if($passa_Sdat['pass'] != sha1($pass) ){
    		echo 'The Old password do not match please try again.'; die;
    	}
    	if($pass1 ==''){
    		echo 'Please enter new password'; die;
    	}
    	if($pass1 == $pass2){
    		$pass=sha1($pass1);
    		$updatepass=$this->db->query("update site_mem set pass='$pass' where mid='$yid' ");
    		echo "YNAPS_SUCCESS";
    	}else{
    		echo 'The two passwords do not match'; die;
    	}
    }

	function edit(){

			check_session('3','1');

			$name=$this->input->post('name');
			// $code=$this->input->post('code'); 
			// $phone=$this->input->post('phone');
			// $add=$this->input->post('add');

			// $country=@$this->input->post('country');
			// $state=@$this->input->post('state');
			// $state_name=getState($state,"st_name",$selected=0);
			
			// $city=@$this->input->post('city');
			// $city_name=getCity($city,"ct_name",$selected=0);
			$zip=$this->input->post('zip');
			// $gender=$this->input->post('gender');
			// $dob=date_format_1($this->input->post('dob'),'sql');
			// $about=$this->input->post('about');

			// $fb=$this->input->post('fb');
			// $tw=$this->input->post('tw');
			// $ins=$this->input->post('ins');
			//$yt=$this->input->post('yt');
			//$bl=$this->input->post('bl');

			// $phone=$code.$phone;

			$yid=$_SESSION['yid'];


			if($name !=''){

				// $update_data=$this->db->query("update site_mem set name='$name',contact='$phone',address='$add',user_state='$state',user_city='$city',user_zip='$zip',gender='$gender',about='$about',fb='$fb',tw='$tw',insta='$ins',user_dob='$dob',user_state_name='$state_name',user_city_name='$city_name',user_country='$country' where mid='$yid' ");

				$update_data=$this->db->query("UPDATE site_mem set name='$name' where mid='$yid' ");
				if ($update_data) {
					echo 'YNAPS_SUCCESS'; die;
				}else{
					echo 'Sorry! Invalid Data not updated';
				}
				
				
			}else{
				echo 'Please enter your Name to continue.';
			}
	}
	
	function sm(){
			check_session('3','1');
			$user_profile=$this->input->post('user_profile');

			$fb=$this->input->post('fb');
			$tw=$this->input->post('tw');
			$ins=$this->input->post('ins');
			$yt=$this->input->post('yt');
			$bl=$this->input->post('bl');
			$ln=$this->input->post('ln');

			$yid=$_SESSION['yid'];
			$update_data=$this->db->query("update site_mem set fb='$fb',tw='$tw',insta='$ins',edln='$ln',blog='$bl' where mid='$yid' ");
				echo 'YNAPS_SUCCESS'; die;
		}

	function photo(){ 
		$yid=$_SESSION['yid'];
		$cvr_prf=$_POST['cvr_prf'];
		$file_get_res=uploadonlyimage('file_name',"assets/mem/$yid/img/",'90');
		if(substr($file_get_res,0,6) =='SUCCXX'){
    	$NewImageName=substr($file_get_res,6);
    	$setDATA_base=$this->db->query("UPDATE site_mem set $cvr_prf='$NewImageName' where mid='$yid'");
		$_SESSION['profile']=$NewImageName;
    	echo 'YNAPS_SUCCESS'; }
	}

	function generate_otp($email,$phone){
		@session_start();
		if( isset($_SESSION['otp']) && $_SESSION['otp'] !=''){
			$otp=$_SESSION['otp'];
			$_SESSION['otp_email']=$email;
			$_SESSION['otp_phone']=$phone;
		}else{ $otp=rand(1111,9999); }
		$_SESSION['otp']=$otp;

		//email and sms

			$site_details=db_variables();
			$site_brief=$site_details['site_brief'];
			$site_name=$site_details['site_name'];
			$site_email=$site_details['site_email'];
			$site_address=$site_details['site_address'];

			$hash=sha1($email);
            $code=rand(1111,9999);
            $emaillist_act=array("$email","$site_email");
            $json_string = array( 'to' =>$emaillist_act,'category' => 'signup-form');
            $tos="$site_email";
            $subject09="OTP for your contact";
            $preheader="Hello you requested for an OTO...";
            $greet="Hi,";
            $message="Your OTP as requested on $site_name is <b>$otp</b> .";
            $link=base_url('index.php')."?mail=".$email.'&ha='.sha1($email).'90';
            $linkname='Browse website';
            $message2="$site_brief";
            $greet2='Thank you so much';
            $myName_emailis="Password Reset";
            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
            send_email($tos,$subject09,$messageto90,$site_name,$json_string);

            $sms_mess="Your OTP as requested on $site_name is $otp. Please do not share.";
            send_sms($phone,$sms_mess);
	}

	function send_otp($email,$phone){
     	$this->generate_otp($email,$phone);
     	return 'YNAPS_SUCCESS'; die;
    }

	function otp_verify($otp){
		@session_start();
		$otp=$this->input->post('otp');
		$function=$this->input->post('function');
		if($otp == $_SESSION['otp']){
			$_SESSION['otp_time_limit']='';
			$_SESSION['otp']='';
			//add your function here
			// $this->share_details_listing();
			return 'YNAPS_SUCCESS';
		}else{
			$email=$_SESSION['otp_email'];
			$phone=$_SESSION['otp_phone'];
			if(isset($_SESSION['otp_time_limit']) && $_SESSION['otp_time_limit'] !=''){
			$CURRENTTIME = date('Y-m-d H:i:s');
    		$OFFICETIME  = @$_SESSION['otp_time_limit'];
			if ($CURRENTTIME  > $OFFICETIME) {
				$this->generate_otp($email,$phone);
				echo 'Sorry, wrong OTP but we have sent you an OTP again.'; die;
			}else{
				echo 'Wrong OTP, please wait for 30 seconds for another OTP. Enter any otp after 30 seconds to resend it.'; die;
			}
			}else{
				$this->generate_otp($email,$phone);
				$_SESSION['otp_time_limit']=date("Y-m-d H:i:s",strtotime(date("Y-m-d H:i:s")." +30 seconds"));
				echo 'Sorry, wrong OTP but we have sent you an OTP again.'; die;
			}
		}
	}


	function order_now(){
		$email=$this->input->post('email');	
		$phone=$this->input->post('phone');	
		$name=$this->input->post('name');	
		$message=$this->input->post('mess');
		$address=$this->input->post('address');
		$order_id=$_SESSION['order_id'];
		
	
		$date=date('Y-m-d H:i:s');
		
	
		if(isset($_SESSION['yid']) && $_SESSION['yid'] !='' ){
			$yid=$_SESSION['yid'];
		}else{
			// check if the user exists
			$yid=0;
		}
		
		if($email !=''){
			$addorder=$this->db->query("insert into site_order (so_order_id,so_mid,so_status,so_name,so_message,so_email,so_phone,so_date,so_add) values ('$order_id','$yid','0','$name','$message','$email','$phone',now(),'$address') ");
			echo 'YNAPS_SUCCESS';
		}
		else{
			echo 'Please refresh the page to continue.';
		}
	
	
	}


			function contact(){
    		$name=$this->input->post('name');
			$email=$this->input->post('email');
			$phone=$this->input->post('phone');
			$subject=$this->input->post('subject');
			$mess=addslashes($this->input->post('mess'));
			$type=$this->input->post('type');
			$NAMES=$this->input->post('NAMES');


			// check_mobile($phone);
			// emailCHECK($email);

			if($NAMES !=''){
				echo 'Success, Please call us at 9034664487'; die;
			}

			// google captcha not needed here
    	@$captcha=$this->input->post('g-recaptcha-response');
        $this->load->view('inc/recaptchalib');
        if(!$captcha){ echo 'Please check the the captcha form.'; die; }
        $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfgnxAUAAAAAD9TwtAKzP0dmqZenOeWb0OMCmrN&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
        // if($response['success'] == false){ echo 'Sorry, Captcha failed !!'; die; }

        $ip=$this->input->ip_address();
        $date=date('Y-m-d H:i:s');
        $alldetails='';

        	if($email !=''){
            $this->db->query("insert into site_contact (name,email,phone,subject,msg,date,ip,skype,con_type) values ('$name','$email','$phone','$subject','$mess','$date','$ip','','$type')");

            $site_details=db_variables();
			$site_brief=$site_details['site_brief'];
			$site_name=$site_details['site_name'];
			$site_email=$site_details['site_email'];
			$site_address=$site_details['site_address'];

            $hash=sha1($email);
            $code=rand(1111,9999);
            $emaillist_act=array("$site_email","$site_email");
            $json_string = array( 'to' =>$emaillist_act,'category' => 'signup-form');
            $tos="$email";
            $subject092="Hi you received a message from $name for $type.";
            $subject09="Hi $name, We have received your message.";
            $preheader="Hi $name, We have received your message.";
            $greet="Hi, $name";
            $message="Thank you for contacting $site_name, We have received your message with following details and will get back to you within next 24 to 48 hrs<br/><br/>Name: $name<br/>Email: $email<br/>Phone: $phone<br/>Message: $mess<br/> <br/>Date: $date<br/>IP: $ip";
            $link=base_url();
            $linkname='Browse Website';
            $message2="$site_brief";
            $greet2='Thank you so much';
            $myName_emailis="Contact Request";
            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
            send_email($tos,$subject09,$messageto90,$site_name,$json_string);
            send_email($site_email,$subject092,$messageto90,$site_name,$json_string);

                echo 'YNAPS_SUCCESS'; die;
        }else{
           echo 'Please fill your name and phone.'; die;
        }

    }

    function call_back(){
    	$mobile=$this->input->post("mobile");
        $email=$this->input->post("email");
        $name=$this->input->post("name");
        $mess=$this->input->post("mess");

        // @$captcha=$this->input->post('g-recaptcha-response');
        // $this->load->view('inc/recaptchalib');
        // if(!$captcha){ echo 'Please check the the captcha form.'; die; }
        // $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfgnxAUAAAAAD9TwtAKzP0dmqZenOeWb0OMCmrN&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
        // if($response['success'] == false){ echo 'Sorry, Captcha failed !!'; die; }
        
        if($mobile !='' && strlen($mobile) > 9){
        $dbinsert=$this->db->query("insert into site_callback (cl_name,cl_email,cl_mobile,cl_date,cl_ip) values ('$name','$email','$mobile',now(),'')");

			$site_details=db_variables();
			$site_brief=$site_details['site_brief'];
			$site_name=$site_details['site_name'];
			$site_email=$site_details['site_email'];
			$site_address=$site_details['site_address'];

			$hash=sha1($email);
            $emaillist_act=array("$email","$site_email");
            $json_string = array( 'to' =>$emaillist_act,'category' => 'signup-form');
            $tos="$site_email";
            $subject09="Callback from $mobile";
            $preheader="We have received your callback request";
            $greet="Hi, $name";
            $message="We have received your request to call you back on the phone number $mobile, we will be calling you soon.";
            $link=base_url();
            $linkname='Shop Now';
            $message2="$site_brief";
            $greet2='Thank you so much';
            $myName_emailis="Membership";
            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
            send_email($tos,$subject09,$messageto90,$site_name,$json_string);


		$message2="Hi, We will call you back soon, $site_name";
        send_sms($mobile,$message2);

        echo 'YNAPS_SUCCESS'; die;
        }else{
            echo 'Please fill your mobile number'; die;
        }
    }

    function account_verify(){
    	$email=$this->input->post('email');
		$phone=$this->input->post('phone');
		$yid=$_SESSION['yid'];
		$cvr_prf=$_FILES['image_name']['name'];
		$file_get_res=uploadonlyimage('image_name',"assets/mem/$yid/img/",'90');
		if( substr($file_get_res,0,6) =='SUCCXX'){
    	$NewImageName=substr($file_get_res,6);
    	$setDATA_base=$this->db->query("update site_mem set ID='$NewImageName' where mid='$yid'");

     	$this->send_otp($email,$phone);
     	echo 'YNAPS_SUCCESS'; die; }else{
     		echo 'ID card image issue.'; die;
     	}
    }

    function acc_verify(){
    	@session_start();
    	$otp=$this->input->post('otp');
    	$otp_check=$this->otp_verify($otp);
    	if($otp_check == 'YNAPS_SUCCESS'){
    		$yid=$_SESSION['yid'];
    		$verify_acc=$this->db->query("update site_mem set verify='2' where mid='$yid' ");

    		echo 'YNAPS_SUCCESS'; die;
    	}else{
    		return false;
    	}
    }

function subscribe(){

        $email=$this->input->post("email");
        if($email !=''){
        emailCHECK($email,'Error code SU02-');

        	$site_details=db_variables();
			$site_brief=$site_details['site_brief'];
			$site_name=$site_details['site_name'];
			$site_email=$site_details['site_email'];
			$site_address=$site_details['site_address'];

        $checkemals=$this->db->query("select sbc_email from site_subscribe where sbc_email='$email' ");
        if($checkemals->num_rows() !='0'){
            echo "Your Email Id is already is in our Subscription List. If you are not getting our newsletter, add $site_email to your address book to get the newsletter in your inbox."; die;
        }

        $dbinsert=$this->db->query("insert into site_subscribe (sbc_email,sbc_date,sbc_ip) values ('$email',now(),'0')");
            $emaillist_act=array("$email","$site_email");
            $json_string = array( 'to' =>$emaillist_act,'category' => 'signup-form');
            $tos="$site_email";
            $subject09="Welcome to $site_name";
            $preheader="Welcome to $site_name family.";
            $greet="";
            $subject09="Thank you for Subscribing ProfZilla Newsletter";
            $preheader="Thank you for Subscribing ProfZilla....";
            $greet="";
            $message="You have subscribed to receive the ProfZilla Newsletter.<br/>
            Our Newsletter will have the latest blogs, vacancies, queries, listings etc. at your desk.
            ";
            $link=base_url();
            $linkname='Browse';
            $message2="$site_brief";
            $greet2='Thank you so much';
            $myName_emailis="Subscribe";
            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
            send_email($tos,$subject09,$messageto90,$site_name,$json_string);

        echo 'YNAPS_SUCCESS'; die;
        }else{
            echo 'Please fill your email'; die;
        }
}

function update_data(){
$q=$this->input->post("q");
$ans=$this->input->post("ans");
$code=$this->input->cookie('user-covid', TRUE);
if(!isset($code)){ echo "Please refresh the page, we got some errors."; die; }

	$addadates=$this->db->query("select * from co_details where cd_code ='$code' ");
	if($addadates->num_rows() > 0 ){
		// update

		$add_data=$this->db->query("update co_details set cd_q$q='$ans',cd_date=now() where cd_code='$code' ");

		if($q =='7'){
			$result=gethelp_result($code);
				$cookie = array(
                    'name'   => 'user-covid-result',
                    'value'  => $result,
                    'expire' =>  865000,
                    'secure' => false
                );
                $this->input->set_cookie($cookie);

              $add_data=$this->db->query("update users set status='$result' where code='$code' ");
		}

	}else{
		// add
		$add_data=$this->db->query("insert into co_details (cd_q$q,cd_code,cd_date) values ('$ans','$code',now()) ");

	}

	echo 'YNAPS_SUCCESS'; die;
}

function uploade_loc(){
	$lat=$this->input->post("lat");
	$lon=$this->input->post("lon");
	$code=$this->input->cookie('user-covid', TRUE);
	$nomwtime=date('Y/m/d h:i:s');

	$thecheck_90a=$this->db->query("select * from co_loc where cl_code='$code' and cl_lat='$lat' and cl_long='$lon' and DATE(cl_date)=CURDATE() ");
	if($thecheck_90a ->num_rows() =='0'){
		$addtehislocas=$this->db->query("insert into co_loc (cl_code,cl_lat,cl_long,cl_date) values ('$code','$lat','$lon','$nomwtime') ");
	}
}

function newsletter(){
        $email=$this->input->post('email');

        if($email !=''){
        emailCHECK($email,'Error code SU02-');

            $site_details=db_variables();
			$site_brief=$site_details['site_brief'];
			$site_name=$site_details['site_name'];
			$site_email=$site_details['site_email'];
			$site_address=$site_details['site_address'];

        $checkemals=$this->db->query("select sbc_email from site_subscribe where sbc_email='$email' ");
        if($checkemals->num_rows() !='0'){
            echo "Your Email Id is already is in our Subscription List. If you are not getting our newsletter, add $site_email to your address book to get the newsletter in your inbox."; die;
        }
        $ip= $this->input->ip_address();
        $dbinsert=$this->db->query("insert into site_subscribe (sbc_email,sbc_date,sbc_ip) values ('$email',now(),'$ip')");

            $hash=sha1($email);
            $code=rand(1111,9999);
            $emaillist_act=array("$email","$site_email");
            $json_string = array( 'to' =>$emaillist_act,'category' => 'signup-form');
            $tos="$site_email";
            $subject09="you have been subscribed to our newsletter";
            $preheader="you have been subscribed to our newsletter";
            $greet="Hi,";
            $message="You have subscribed to receive the $site_name Newsletter.<br/>
            Our Newsletter will have the latest news at your desk.";
            $link=base_url();
            $linkname='Shop Now';
            $message2="$site_brief";
            $greet2='Thank you so much';
            $myName_emailis="Membership";
            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
            send_email($tos,$subject09,$messageto90,$site_name,$json_string);

        echo 'YNAPS_SUCCESS'; die;
        }else{
            echo 'Please fill your email'; die;
        }
    }
////////////////////////////////// THIS IS CUSTOM/ /////////////////////////////////////

function set_phone(){
	$phone=$this->input->post('phone');
	$loc_details=$this->input->post('loc');

	$code=substr($loc_details,2,4);
	$ISO_loc=substr($loc_details,0,2);
	// $preg=$this->input->post('preg');

	$new_phone=$code.$phone;
	if($code ==''){redirect(base_url('index.php/recharge')."?msg=".urlencode('country not supported'));}else{

	$get_datas=ding_API('GetProviders',"countryIsos=$ISO_loc","",'','');
	$preg=$get_datas['Items']['0']['ValidationRegex'];

	// echo $preg; die;
	//check if the number is good
	///^91[0-9]{10,11}$/
	if (!preg_match("/$preg/", $new_phone)) {
		redirect(base_url('index.php/recharge')."?msg=".urlencode("Your phone number seems to be wrong, please check again."));
	}

	$_SESSION['cr_phone']=$code.$phone;
	$_SESSION['cr_loc']=$ISO_loc;
	$_SESSION['cr_m_step']='1';

	$loc=$this->input->post("loc");
				$cookie = array(
                    'name'   => 'cr_loc',
                    'value'  => $ISO_loc,
                    'expire' =>  865000,
                    'secure' => false
                );
    $this->input->set_cookie($cookie);
	// redirect($_SERVER['HTTP_REFERER']);
	redirect(base_url('index.php/recharge'));
	} }

	function redo(){
	$_SESSION['cr_phone']='';
	$_SESSION['cr_loc']='';
	$_SESSION['cr_m_step']='';
	redirect($_SERVER['HTTP_REFERER']);
	}

	function add_oper(){
		$ope=$this->input->post('ope');
		$_SESSION['cr_operator']=$ope;
		redirect(base_url('index.php/recharge'));
	}

function order_process(){
$pro=$this->input->post('pro');
$sku=$this->input->post('sku');
$operator=$this->input->post('operator');
$operator_logo=$this->input->post('operator_logo');

$get_datas=ding_API('GetProducts',"skuCodes=$sku",'','','');

$_SESSION['cr_ch_SKU']=$sku;
$_SESSION['cr_ch_benif']=$get_datas['Items']['0']['DefaultDisplayText'];
$_SESSION['cr_ch_dur']=$get_datas['Items']['0']['ValidityPeriodIso'];
$_SESSION['cr_ch_cost']=$get_datas['Items']['0']['Minimum']['ReceiveValue'];
$_SESSION['cr_ch_currency']=$get_datas['Items']['0']['Minimum']['ReceiveCurrencyIso'];
$_SESSION['cr_ch_country']=$get_datas['Items']['0']['RegionCode'];

$_SESSION['cr_order_type']='m';

$_SESSION['operator']=$operator;
$_SESSION['operator_logo']=$operator_logo;

$_SESSION['cr_m_step']='2';
redirect(base_url('index.php/checkout'));

}

function order_process_gift(){
$pro=$this->input->post('pro');
$sku=$this->input->post('sku');
$operator=$this->input->post('operator');
$operator_logo=$this->input->post('operator_logo');

$get_datas=ding_API('GetProducts',"skuCodes=$sku",'','','');

$_SESSION['cr_ch_SKU']=$sku;
$_SESSION['cr_ch_benif']=$get_datas['Items']['0']['DefaultDisplayText'];
$_SESSION['cr_ch_dur']=$get_datas['Items']['0']['ValidityPeriodIso'];
$_SESSION['cr_ch_cost']=$get_datas['Items']['0']['Minimum']['ReceiveValue'];
$_SESSION['cr_ch_currency']=$get_datas['Items']['0']['Minimum']['ReceiveCurrencyIso'];
$_SESSION['cr_ch_country']=$get_datas['Items']['0']['RegionCode'];

$_SESSION['operator']=$operator;
$_SESSION['operator_logo']=$operator_logo;

$_SESSION['cr_m_step']='2';
$_SESSION['cr_card']='G';
$_SESSION['cr_order_type']='G';

redirect(base_url('index.php/checkout'));
}

function checkout_email(){
		$order_id=$_SESSION['order_id'];
		$amount=$_SESSION['cr_ch_cost'];
		$benif=$_SESSION['cr_ch_benif'];
		$provider=$_SESSION['operator'];
		@$type=$_SESSION['cr_order_type'];
		$phone=@$_SESSION['cr_phone'];

		$currency=@$_SESSION['cr_ch_currency'];
		$user_country=@$_SESSION['cr_ch_country'];
		$cr_token=@$_SESSION['cr_token'];
		$cr_ch_SKU=@$_SESSION['cr_ch_SKU'];
		
		$order_typ=@$_SESSION['phone'];
		$crypto_type=@$_SESSION['phone'];
		$pro_logo=@$_SESSION['operator_logo'];

		$email=$this->input->post('email');
		// check email

		// add to database the order id, emaiil
		$get_check_data=$this->db->query("select * from cr_orders where or_orid ='$order_id' ");
		$check_numdata=$get_check_data->num_rows();


		if($check_numdata =='0'){
			// echo 'sje'; die;
		$the_add_data=$this->db->query("insert into cr_orders (or_orid,or_email,or_amount,or_type,or_provider,or_benif,or_phone,or_date_created,or_status,currency,user_country,cr_token,cr_ch_SKU,pro_logo) values ('$order_id','$email','$amount','$type','$provider','$benif','$phone',now(),'0','$currency','$user_country','$cr_token','$cr_ch_SKU','$pro_logo') ");
		}else{
			// echo 'sjess'; die;
			$the_add_data=$this->db->query("update cr_orders set or_email ='$email' where or_orid ='$order_id' ");
		}

				$cookie = array(
                    'name'   => 'cr_email',
                    'value'  => $email,
                    'expire' =>  865000,
                    'secure' => false
                );
                $this->input->set_cookie($cookie);

                $_SESSION['email_process']=$email;

		echo 'YNAPS_SUCCESS'; die;
		// send email
}

function smart_search(){
	$url='';
	$params=array();
	$q=xss_clean($_GET['q']);
	if($q!=''){
		$params[]='q='.url_smart($q);
	}
	if(isset($_GET['pr'])) {
		$pr=xss_clean($_GET['pr']);
		$thepr=@implode(',$pr, ');
		$params[]='pr='.$thepr;
	}
	if(isset($_GET['ln'])) {
		$ln=xss_clean($_GET['ln']);
		$theln=@implode(',$ln, ');
		$params[]='ln='.$theln;	
	}

	$price=xss_clean($_GET['price']);
	if($price!=''){
		$params[]='price='.$price;
	}
	$kid=xss_clean($_GET['kid']);
	if($kid!=''){
		$params[]='kid='.$kid;
	}
	$level=xss_clean($_GET['level']);
	if($level!=''){
		$params[]='level='.$level;
	}
	$mode=xss_clean($_GET['mode']);
	if($mode!=''){
		$params[]='mode='.$mode;
	}

	if (count(@$params) > 0) {
	 		$url='?'.implode( @$params, '&');
	 }

	redirect(base_url('search'.$url));
}

function family(){
		$name=$this->input->post('name');
		$relation=$this->input->post('relation');
		$email=$this->input->post('email');
		$phone=$this->input->post('phone');
		$gender=$this->input->post('gender');
		$dob=$this->input->post('dob');
		$state=$this->input->post('state');
		$city=$this->input->post('city');
		$zip=$this->input->post('zip');

		$yid=$_SESSION['yid'];

		$user_state_name=getState($this->input->post('state'),'st_name');
		$user_city_name=getCity($this->input->post('city'),'ct_name');

		if($name !='' && $phone !='' && $email !=''){
			// check for unique email and phone
			$chec_details=$this->db->query("select * from site_mem where email='$email' or contact ='$phone' ");
			if($chec_details->num_rows() > 0){
				echo "We already have an account with the provided email / phone, can you provide us an alternate email and phone so that your family member can login."; die;
			}else{
				$code_pass=rand(11111,99999);
				$pass=sha1($code_pass);
				$addmember=$this->db->query("insert into site_mem (name,email,pass,contact,user_relationship,gender,user_state,user_city,user_city_name,user_state_name,user_zip,user_dob,user_owner) values ('$name','$email','$pass','$phone','$relation','$gender','$state','$city','$user_city_name','$user_state_name','$zip','$dob','$yid')");
				 $inserted_id = $this->db->insert_id();

				$dirPath = "assets/mem/$inserted_id";
				$dirPath2 = "assets/mem/$inserted_id/img/";
				mkdir($dirPath, 0777, TRUE);
				mkdir($dirPath2, 0777, TRUE);

				$file = base_url().'assets/avator/main-profile.jpg';
				$file2 = base_url().'assets/avator/cover.jpg';
				$tocoppy="$dirPath2/photo.jpg";
				$tocoppy2="$dirPath2/cover.jpg";
				$abch=copy($file, $tocoppy);
				$abch2=copy($file2, $tocoppy2);


				$site_details=db_variables();
				$site_brief=$site_details['site_brief'];
				$site_name=$site_details['site_name'];
				$site_email=$site_details['site_email'];
				$site_address=$site_details['site_address'];
				
				$thenmae=$name;
				$thenmae_real=$_SESSION['name'];
				$tos=$email;
	            $subject09="Hi $thenmae, $thenmae_real created an account for you on $site_name :)";
	            $preheader="";
	            $greet="You got a brand new account.";
	            $message="$thenmae_real created an account for you on $site_name, you can book doctors, find medicines and contact any emergency services with a simple click. <br/> To access your account your login details are:<br/><br/> Email: $email <br/> Password: <b>$code_pass</b>";
	            $link=base_url('login');
	            $linkname='Login Now';
	            $message2="$site_brief";
	            $greet2='Thank you so much, your are a awesome!';
	            $myName_emailis="";
	            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
	            send_email($tos,$subject09,$messageto90,$site_name,'');

				echo 'YNAPS_SUCCESS';
			}

			//addthe user to db
		}else{
			echo "Please enter the basic details to proceed further"; die;
		}
		
	}

function clinic(){
	$name=$this->input->post('name');
		$email=$this->input->post('email');
		$phone=$this->input->post('phone');
		$state=$this->input->post('state');
		$city=$this->input->post('city');
		$zip=$this->input->post('zip');

		$yid=$_SESSION['yid'];
		$date=date('Y-m-d H:i:s');

		$user_state_name=getState($this->input->post('state'),'st_name');
		$user_city_name=getCity($this->input->post('city'),'ct_name');

		if($name !='' && $phone !=''){
			$addthisbusiness=$this->db->query("insert into site_user_business (ub_name,ub_email,ub_phone,ub_city,ub_state,ub_date,ub_city_name,ub_state_name,ub_user_owner) values ('$name','$email','$phone','$city','$state','$date','$user_city_name','$user_state_name','$yid') ");


				$site_details=db_variables();
				$site_brief=$site_details['site_brief'];
				$site_name=$site_details['site_name'];
				$site_email=$site_details['site_email'];
				$site_address=$site_details['site_address'];

				$thenmae=$_SESSION['name'];
				$tos=$_SESSION['email'];
	            $subject09="Congratulations you have created a clinic on $site_name, $name Under Review !";
	            $preheader="";
	            $greet="Hi $thenmae";
	            $message="you have created your clinic on $site_name '$name' and we have it under review, usually it gets reviewed under 24-48 hrs. After its gets reviewed people can find your clinic online.";
	            $link=base_url();
	            $linkname='Checkout our website';
	            $message2="$site_brief";
	            $greet2='Thank you so much, your are a awesome doctor.';
	            $myName_emailis="";
	            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
	            send_email($tos,$subject09,$messageto90,$site_name,'');


			echo 'YNAPS_SUCCESS';
		}else{
			echo "Please enter name and phone of the business."; die;
		}


}

function otp_resend(){
	$what=$_GET['type'];
	if(isset($_SESSION['signup_code_email']) && $_SESSION['signup_code_email'] !='' ){
	$otp_e=$_SESSION['signup_code_email'];
	}else{
		$otp_e=rand('1111,9999');
		$_SESSION['signup_code_email']=$otp_e;
	}if(isset($_SESSION['signup_code_phone']) && $_SESSION['signup_code_phone'] !='' ){
	$otp_p=$_SESSION['signup_code_phone'];
	}else{
		$otp_p=rand('1111,9999');
		$_SESSION['signup_code_phone']=$otp_p;
	}

	$site_details=db_variables();
	$site_brief=$site_details['site_brief'];
	$site_name=$site_details['site_name'];
	$site_email=$site_details['site_email'];
	$site_address=$site_details['site_address'];

//send email otp
if($what=='e'){
echo "sjksj34k";
}
//
// send phone otp
else if($what=='p'){
echo "sjksjk45";
}
// Send both
		else if($what=='2'){
	            $tos=$_SESSION['email'];
	            $subject09="Hi your OTP for website $site_name is $otp_e";
	            $preheader="Your OTP on the website.";
	            $greet="Hi";
	            $message="Thank you for asking the OTP on $site_name. Please enter the OTP as <b>$otp_e</b> to verify your email.";
	            $link=base_url();
	            $linkname='Browse Website';
	            $message2="$site_brief";
	            $greet2='Thank you so much';
	            $myName_emailis="Membership";
	            $messageto90=email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address);
	            send_email($tos,$subject09,$messageto90,$site_name,'');
					
				//send sms
	            $sms_mess="Please enter the OTP as $otp_p to verify your Mobile.";
	            // send_sms($phone,$sms_mess);
	            redirect($_SERVER['HTTP_REFERER'].'?otp=resent');
		}

}

function delete_acc(){
	$yid=$_SESSION['yid'];
	$upadtsspost=$this->db->query("update site_mem set user_status='2' where mid='$yid' ");


	// email send

	redirect(base_url('logout'));
	// echo 'YNAPS_SUCCESS';
}


function add_startup(){
	$name=$this->input->post('name');
	$step=$this->input->post('step');
	$desig=$this->input->post('desig');
	$email=$this->input->post('email');
	$phone=$this->input->post('phone');
	$start_name=$this->input->post('start_name');
	$webiste=$this->input->post('webiste');
	$fdate=$this->input->post('fdate');
	$state=$this->input->post('state');
	$city=$this->input->post('city');
	$agree=$this->input->post('agree');


	switch($step){
		case '0':
			if($agree !='1'){echo "i am sorry, but to proceed ahead you need to agree with our terms and conditions."; die; }

			$ip=$this->input->ip_address();
			$date=date('Y-m-d H:i:s');
			$yid=$_SESSION['yid'];
				
				if($name != '' && $start_name !=''){

					// check for unique
					$thecheck_90=$this->db->query("select xst_id from  x_soo_startups where xst_mid='$yid' and xst_name='$start_name' ");
					if($thecheck_90->num_rows() > 0){
						echo "Seems like we have exact same startup registered with you before, please check the details."; die;
					}

					// add this startup
					$sendthis_todb=$this->db->query("insert into x_soo_startups (xst_uname,xst_design,xst_mid,xst_name,xst_email,xst_phone,xst_state,xst_city,xst_fdate,xst_structure,xst_status,xst_date_submitted,xst_ip) values ('$name','$desig','$yid','$start_name','$email','$phone','$state','$city','$fdate','0','0','$date','$ip') ");
							
					$inserted_id = $this->db->insert_id();

							$_SESSION['startup_id']=$inserted_id;

						echo 'YNAPS_SUCCESS';

				}else{
					echo "Please enter the details above to proceed."; die;
				}
		break;

		case '1':
		if(@$_SESSION['startup_id'] ==''){echo "Please refresh the form or try logout and login again."; die; }
			$structure=$this->input->post('structure');
			$cpfound=$this->input->post('cpfound');
			$empoyees=$this->input->post('empoyees');
			$sector=$this->input->post('sector');
			$nature=$this->input->post('nature');
			$funded=$this->input->post('funded');
			$desc=$this->input->post('desc');
			$stage=$this->input->post('stage');

			$startup_id=$_SESSION['startup_id'];
			$yid=$_SESSION['yid'];

			if($structure !=''){
				//update the tabale

			$this->db->query("update x_soo_startups set xst_structure='$structure',xst_founders_no='$cpfound',xst_employee='$empoyees',xst_sector='$sector',xst_brief='$desc',xst_nature='$nature',xst_stage='$stage',xst_funding='$funded' where xst_id='$startup_id' and xst_mid='$yid' ");
			echo 'YNAPS_SUCCESS';
			
			}else{
				echo "Please select the necessary fields to proceed further."; die;
			}


		break;

		case '2':
		if(@$_SESSION['startup_id'] ==''){echo "Please refresh the form or try logout and login again."; die; }
			$raised=$this->input->post('raised');
			$seeking=$this->input->post('seeking');
			$how=$this->input->post('how');
			$vid=$this->input->post('vid');
			$xst_mentor=$this->input->post('xst_mentor');

			$startup_id=$_SESSION['startup_id'];
			$yid=$_SESSION['yid'];

			if($raised !=''){
			//update the tabale
			$this->db->query("update x_soo_startups set xst_seed='$raised',xst_seek='$seeking',xst_refer='$how',xst_video='$vid',xst_mentor='$xst_mentor' where xst_id='$startup_id' and xst_mid='$yid' ");
			echo 'YNAPS_SUCCESS';

			}else{
				echo "Please select the necessary fields to proceed further."; die;
			}
		break;

			case 'photo':
				if(@$_SESSION['startup_id'] ==''){echo "Please refresh the form or try logout and login again."; die; }
				
					$yid=$_SESSION['yid'];
					$startup_id=$_SESSION['startup_id'];

					$cvr_prf=$_POST['cvr_prf'];
					$file_get_res=uploadonlyimage('file_name',"assets/mem/$yid/img/",'90');
					if( substr($file_get_res,0,6) =='SUCCXX'){
			    	$NewImageName=substr($file_get_res,6);
			    	$setDATA_base=$this->db->query("update x_soo_startups set $cvr_prf='$NewImageName' where xst_id='$startup_id'");
			    	echo 'YNAPS_SUCCESS'; }

			break;
	}
}

function add_portfolio(){
	$step=$this->input->post('step');
	
	$name=$this->input->post('name');
	$business_name=$this->input->post('business_name');
	$desig=$this->input->post('desig');
	$email=$this->input->post('email');
	$phone=$this->input->post('phone');
	$webiste=$this->input->post('webiste');
	$fdate=$this->input->post('fdate');
	$state=$this->input->post('state');
	$city=$this->input->post('city');
	$agree=$this->input->post('agree');


	switch($step){
		case '0':
			if($agree !='1'){echo "i am sorry, but to proceed ahead you need to agree with our terms and conditions."; die; }

			$ip=$this->input->ip_address();
			$date=date('Y-m-d H:i:s');
			$yid=$_SESSION['yid'];
				
				if($name != '' && $business_name !=''){

					// check for unique
					// $thecheck_90=$this->db->query("select xsi_mid from  x_soo_investors where xsi_mid='$yid'  ");
					// if($thecheck_90->num_rows() > 0){
					// 	echo "You can not add new business here."; die;
					// }

					// add this startup
					// $sendthis_todb=$this->db->query("insert into x_soo_investors (xsi_name,xsi_mid,xsi_email,xsi_phone,xsi_city,xsi_state,xsi_desig,xsi_linkedin,xsi_date,xsi_ip) values ('$name','$yid','$email','$phone','$city','$state','$desig','$webiste','$date','$ip') ");
					// $inserted_id = $this->db->insert_id();
					// $_SESSION['investor_id']=$inserted_id;

					$this->db->query("update x_soo_investors set xsi_name='$name',xsi_email='$email',xsi_phone='$phone',xsi_city='$city',xsi_state='$state',xsi_desig='$desig',xsi_linkedin='$webiste' where xsi_mid='$yid' ");

						echo 'YNAPS_SUCCESS';

				}else{
					echo "Please enter the details above to proceed."; die;
				}
		break;

		case '1':
		// if(@$_SESSION['investor_id'] ==''){echo "Please refresh the form or try logout and login again."; die; }
			$type=$this->input->post('type');
			$invested=$this->input->post('invested');
			$sector=$this->input->post('sector');
			$ticket=$this->input->post('ticket');
			$worth=$this->input->post('worth');
			$stage=$this->input->post('stage');

			// $investor_id=$_SESSION['investor_id'];
			$yid=$_SESSION['yid'];
			if($type !=''){
				//update the tabale
			$this->db->query("update x_soo_investors set xsi_cat='$type',xsi_exp='$invested',xsi_size='$ticket',xsi_worth='$worth',xsi_stage='$stage' where xsi_mid='$yid' ");
			echo 'YNAPS_SUCCESS';
			
			}else{
				echo "Please select the necessary fields to proceed further."; die;
			}


		break;

		case '2':
		// if(@$_SESSION['startup_id'] ==''){echo "Please refresh the form or try logout and login again."; die; }
			$how=$this->input->post('how');
			$curate=$this->input->post('curate');
			$prefer=$this->input->post('prefer');
			$mentor=$this->input->post('mentor');

			$yid=$_SESSION['yid'];

			if($how !=''){
			//update the tabale
			$this->db->query("update x_soo_investors set xsi_curate='$curate',xsi_mentor='$mentor',xsi_invest_pref='$prefer' where xsi_mid='$yid' ");
			echo 'YNAPS_SUCCESS';

			}else{
				echo "Please select the necessary fields to proceed further."; die;
			}
		break;

			case 'photo':
				if(@$_SESSION['startup_id'] ==''){echo "Please refresh the form or try logout and login again."; die; }
				
					$yid=$_SESSION['yid'];
					$startup_id=$_SESSION['startup_id'];

					$cvr_prf=$_POST['cvr_prf'];
					$file_get_res=uploadonlyimage('file_name',"assets/mem/$yid/img/",'90');
					if( substr($file_get_res,0,6) =='SUCCXX'){
			    	$NewImageName=substr($file_get_res,6);
			    	$setDATA_base=$this->db->query("update x_soo_startups set $cvr_prf='$NewImageName' where xst_id='$startup_id'");
			    	echo 'YNAPS_SUCCESS'; }

			break;
	}
}

function edit_startup(){
	$edit_step=$this->input->post('edit_step');
	$yid=$_SESSION['yid'];
	switch($edit_step){
		case 'founder':case 'executive':case 'advisor':
				$id=$this->input->post('id');
				$name=$this->input->post('name');
				$desi=$this->input->post('desi');
				$order=$this->input->post('order');
				$link=$this->input->post('link');

				if($edit_step =='executive'){
					$tyspso='ex';
				}else if($edit_step =='advisor'){
					$tyspso='ad';
				}else{
					$tyspso='fo';
				}

				$file_get_res=uploadonlyimage('file_name',"assets/mem/$yid/img/",'90');
				if( substr($file_get_res,0,6) =='SUCCXX'){
		    	$NewImageName=substr($file_get_res,6);
		    		$setDATA_base=$this->db->query("insert into x_soo_people (xsp_name,xsp_link,xsp_photo,xsp_desig,xsp_startup,xsp_mid,xsp_order,xsp_type) values ('$name','$link','$NewImageName','$desi','$id','$yid','$order','$tyspso') ");
			    	echo 'YNAPS_SUCCESS';
		    	}
			break;
			case 'bs':
				$id=$this->input->post('id');
				$phone=$this->input->post('phone');
				$website=$this->input->post('website');
				$mentor=$this->input->post('mentor');
				$about=addslashes($this->input->post('about'));
				$inc=$this->input->post('inc');

				$update_dates=$this->db->query("update x_soo_startups set xst_link='$website',xst_phone='$phone',xst_fdate='$inc',xst_mentor='$mentor',xst_brief='$about' where xst_id='$id' and xst_mid='$yid' ");
				echo 'YNAPS_SUCCESS';
			break;case 'sm':
				$id=$this->input->post('id');
				$fb=$this->input->post('fb');
				$tw=$this->input->post('tw');
				$in=$this->input->post('in');
				$ln=$this->input->post('ln');

				$update_dates=$this->db->query("update x_soo_startups set xst_in='$in',xst_fb='$fb',xst_tw='$tw',xst_ln='$ln' where xst_id='$id' and xst_mid='$yid' ");
				echo 'YNAPS_SUCCESS';
			break;

			default:

			break;
	}
}

function user_favourite(){	
	check_session(3, '');
	$favId=$this->input->post('itemID');

	$yid=$_SESSION['yid'];
	$ip= $this->input->ip_address();

	$CHK_follow=$this->db->query("SELECT * FROM `site_favourites` WHERE `fav_user_id`='$yid' AND `fav_item_id`='$favId' ");
	$exist=$CHK_follow->num_rows();

	if($exist==0){
	$follow=$this->db->query("INSERT INTO `site_favourites`(`fav_user_id`, `fav_item_id`, `ip`, `fav_date`) VALUES ('$yid','$favId','$ip',now())");
	}
	else{
	  $del_follow=$this->db->query("DELETE FROM `site_favourites` WHERE `fav_user_id`='$yid' AND `fav_item_id`='$favId' ");
	}
	
	myfav_items($yid,'reset');
	echo 'YNAPS_SUCCESS'; die;
}

function career(){
	$name=$this->input->post('name');
	$email=$this->input->post('email');
	$phone=$this->input->post('phone');
	$mess=$this->input->post('mess');

	@$captcha=$this->input->post('g-recaptcha-response');
    $this->load->view('inc/recaptchalib');
    if(!$captcha){ echo 'Please check the the captcha form.'; die; }
    $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfgnxAUAAAAAD9TwtAKzP0dmqZenOeWb0OMCmrN&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
    if($response['success'] == false){ echo 'Sorry, Captcha failed !!'; die; }

    $ip=$this->input->ip_address();
    $date=date('Y-m-d H:i:s');
    $alldetails='';

    if($email !=''){
		$NewFileName='';
		if(!isset($_POST["FileUpload1"])){//echo 'in';print_r($_FILES['FileUpload1']);
			$doc=rand(111111,999999).'_career';
			$file_get_res=upload_doc('FileUpload1',"assets/avator/upload/",$doc);
			if( substr($file_get_res,0,6) =='SUCCXX'){
				$NewFileName=substr($file_get_res,6);		
			}
			$this->db->query("insert into site_contact (name,email,phone,msg,date,ip,document,con_type) values ('$name','$email','$phone','$mess','$date','$ip','$NewFileName','1')");
			echo 'YNAPS_SUCCESS'; die;
		}
		else{
			echo "Please upload Document";die;
		}
	}
}

function testimonial(){
 		$name=$this->input->post('name');
 		$role=$this->input->post('role');
 		$company=$this->input->post('company');
 		$mess=addslashes($this->input->post('mess'));
 		$order=$this->input->post('order');

 		@$captcha=$this->input->post('g-recaptcha-response');
        $this->load->view('inc/recaptchalib');
        if(!$captcha){ echo 'Please check the the captcha form.'; die; }
        $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfgnxAUAAAAAD9TwtAKzP0dmqZenOeWb0OMCmrN&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
        // if($response['success'] == false){ echo 'Sorry, Captcha failed !!'; die; }
 		
 		if($role!='' && $company!='' && $name!='' && $mess!=''){
	 		
	 		if(isset($_POST['file_name']) && $_POST['file_name'] !='' ){
	 		$cvr_prf=$_FILES['file_name']['name'];
			// $NewImageName='';
			$file_get_res=uploadonlyimage('file_name',"assets/avator/webimg/t/",'75');
			if( substr($file_get_res,0,6) =='SUCCXX'){ $NewImageName=substr($file_get_res,6); }
	 		}else{
	 			$NewImageName='';
	 		}


	 		$addtesti=$this->db->query("insert into admin_testimonials (name,image,role,company,text,li) values ('$name','$NewImageName','$role','$company','$mess','$order')");
	 		
	 		echo 'YNAPS_SUCCESS'; die;    
	 	}else{
	 		echo "Please enter all the requied fields";}  
        
    }

function compare_courses(){
	$itemID=$this->input->post('itemID');
	if($itemID !=''){
		if(!isset($_SESSION['compare'])){
			$_SESSION['compare']=array();
			$comp_items=$_SESSION['compare'];
		}else{
			$comp_items=$_SESSION['compare'];
		}
		
		if(!in_array($itemID, $comp_items)){
			if(count($comp_items)==3){
				// echo "You have already selected 3 Courses"; die;
				echo "YNAPS_SUCCESS22"; die;
			}
			array_push($_SESSION['compare'], $itemID);
		}else{
			if (($key = array_search($itemID, $comp_items)) !== false) {
			    unset($comp_items[$key]);
			    $_SESSION['compare']=$comp_items;
			}
		}
		echo 'YNAPS_SUCCESS'; die; 
	}
}

// THE MAIN CONTROLER
}
