<?php
        //$D = '{"b_group":"","email":"123.myindia@gmail.com","mobile":"9762811448","name":"Vinod","password":"Vinod@123","sign_up_step2":"1"}';
        //$_POST = (array)json_decode($D); 
        include_once('../config1.php');  
        include_once('date_calculation.php'); 
        include_once('custom-functions.php'); 
        include_once('EmailConfigure.php'); 
        $Data = json_encode($_POST);  
        mysql_query("insert into test (name) values('$Data')");  
          
       
       
         
        /************** registration ****************/   
        //https://www.meerindia.com/my-local-app/ws/registration-login.php?check_sign_up=1&login_credentials=login_credentials
        //check_sign_up=1&login_credentials = login_credentials 
        //$_POST['login_check'] = 1;
        //$_POST['login_credentials'] = '9762811448'; 
        
     
              
			if(isset($_POST['check_sign_up']))
			{        
				$emailErr = $_POST['login_credentials'];
				$set ="";
				$mobSet=0;
				$data['mobile']='';
				
				if (!filter_var($emailErr, FILTER_VALIDATE_EMAIL)) 
			         $set = 0;
			    else  if(!preg_match("/^[0-9]{10}$/", $emailErr)) 
				     $set = 0; 
				     
				if (filter_var($emailErr, FILTER_VALIDATE_EMAIL)) 
				{
					  $set = 1;
					  $data['account_exist'] = 2;	 // filled email  to reg form
				}else  if(preg_match("/^[0-9]{10}$/", $emailErr)) 
				{ 	
					  $set = 1;  
					  $data['account_exist'] = 3;	 // filled mobile  to reg form
				      $mobSet=1;
				} 
				 
				if ($set==0) 
				{
					$data['account_exist'] = 0;   //shows error
				}else
				{	 	
    				$query = mysql_query("SELECT * FROM users WHERE  ( email='$_POST[login_credentials]' || ph='$_POST[login_credentials]') ");
    				if (mysql_num_rows($query) > 0)   
    				{
    					$data['account_exist'] = 1; 
    					if($mobSet==1)
    					    $data['mobile'] = 1; 
    					 
    				}
				}  
				
				$ary['status'] = "200";
				$ary['message'] = "Success";
				$ary['data'] = $data;
				echo  json_encode($ary);
				die; 
			}    
			
			if(isset($_POST['sign_up_step1']))
			{      
				if($_POST['email']!='')
				{     
					$query = mysql_query("SELECT * FROM users WHERE  ( email='$_POST[email]' || ph='$_POST[mobile]') "); 
					if (mysql_num_rows($query) > 0)    
					{  
						$query = mysql_query("SELECT * FROM users WHERE  ph='$_POST[mobile]'  "); 
						if (mysql_num_rows($query) > 0) 
						$ary['message'] = "Phone no is already exist!";   
							
						$query = mysql_query("SELECT * FROM users WHERE  email='$_POST[email]'  "); 
						if (mysql_num_rows($query) > 0) 
								$ary['message'] = "Email  is already exist!";  	
						
						$data['acccount_create'] = 0;   
						$ary['status'] = "200";
						
						$ary['data'] = $data;
						echo  json_encode($ary);  
						die;   
					}else{    
						$val = strtoupper( substr((rand(43577,134)),0,4)); 	   
						$Success_msg = "Dear User,Your OTP for Laai Bhari is: $val Kindly do not share your OTP with any other";    
						$xml_data ='<?xml version="1.0"?>
						<parent>
						<child>
						<user>KalpanaG</user>
						<key>dacc4ff030XX</key>
						<mobile>'.$_POST['mobile'].'</mobile>
						<message>Dear User,Your OTP for Laai Bhari is: '.$val.' Kindly do not share your OTP with any other</message>
						<accusage>1</accusage>
						<senderid>LBHARI</senderid>
						</child>
						</parent>'; 
						
						 
						$URL = "http://103.233.79.246/submitsms.jsp?";  
						$ch = curl_init($URL);
						curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
						curl_setopt($ch, CURLOPT_POST, 1);
						curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
						curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
						curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
						$output = curl_exec($ch);
						curl_close($ch);     
					
						$data['acccount_create'] = 1;   
						$ary['status'] = "200";
						$ary['message'] = "Success";
						$data['otp'] = $val; 
						$ary['data'] = $data;	
						echo  json_encode($ary);  
						die;     
					}
				}else if($_POST['email']=='')
				{
					$query = mysql_query("SELECT * FROM users WHERE ph='$_POST[mobile]' "); 
					if (mysql_num_rows($query) > 0)    
					{  
						$query = mysql_query("SELECT * FROM users WHERE  ph='$_POST[mobile]'  "); 
						if (mysql_num_rows($query) > 0) 
						$ary['message'] = "Phone no is already exist!";     
					
						$data['acccount_create'] = 0;   
						$ary['status'] = "200";
						
						$ary['data'] = $data;
						echo  json_encode($ary);  
						die;   
					}else{    
						$val = strtoupper( substr((rand(43577,134)),0,4)); 	   
						$Success_msg = "Dear User,Your OTP for Laai Bhari is: $val Kindly do not share your OTP with any other";    
						$xml_data ='<?xml version="1.0"?>
						<parent>
						<child>
						<user>KalpanaG</user>
						<key>dacc4ff030XX</key>
						<mobile>'.$_POST['mobile'].'</mobile>
						<message>Dear User,Your OTP for Laai Bhari is: '.$val.' Kindly do not share your OTP with any other</message>
						<accusage>1</accusage>
						<senderid>LBHARI</senderid>
						</child>
						</parent>'; 
						
						 
						$URL = "http://103.233.79.246/submitsms.jsp?";  
						$ch = curl_init($URL);
						curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
						curl_setopt($ch, CURLOPT_POST, 1);
						curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
						curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
						curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
						$output = curl_exec($ch);
						curl_close($ch);     
					
						$data['acccount_create'] = 1;   
						$ary['status'] = "200";
						$ary['message'] = "Success";
						$data['otp'] = $val; 
						$ary['data'] = $data;	
						echo  json_encode($ary);  
						die;     
					}
				}     
			}
			
			
			
			if(isset($_POST['send_login_otp']))
			{    
               $val = strtoupper( substr((rand(43577,134)),0,4)); 	   
						$Success_msg = "Dear User,Your OTP for Laai Bhari is: $val Kindly do not share your OTP with any other";    
						$xml_data ='<?xml version="1.0"?>
						<parent>
						<child>
						<user>KalpanaG</user>
						<key>dacc4ff030XX</key>
						<mobile>'.$_POST['mobile'].'</mobile>
						<message>Dear User,Your OTP for Laai Bhari is: '.$val.' Kindly do not share your OTP with any other</message>
						<accusage>1</accusage>
						<senderid>LBHARI</senderid>
						</child>
						</parent>'; 
						
						 
						$URL = "http://103.233.79.246/submitsms.jsp?";  
						$ch = curl_init($URL);
						curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
						curl_setopt($ch, CURLOPT_POST, 1);
						curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
						curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
						curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
						$output = curl_exec($ch);
						curl_close($ch); 
						
						$ary['status'] = "200";
                    $ary['message'] = "Success";
                    $data['otp'] = $val;
                    $ary['data'] = $data;	
                    echo  json_encode($ary);  
                    die;   
			}
			
			 
			
			/************** Login ****************/ 
			//https://www.meerindia.com/my-local-app/ws/registration-login.php?login_check=1&login_credentials=login_credentials&&password=password
			//login_check=1&login_credentials=login_credentials&&password=password 
			  
		 
			if($_POST['otp_check'])
			{    
			    $result = mysql_query("select * from users where  ( email='$_POST[login_credentials]' || ph='$_POST[login_credentials]' )  ");    
				if(mysql_num_rows($result)>0)
				{ 
					$row = mysql_fetch_object($result);  
					$old_date = $row->register_date; 
					$old_date_timestamp = strtotime($old_date);
					$register_date =  date('d-M-Y', $old_date_timestamp);
			
					$data['cust_id'] = $row->cust_id; 
					$data['email']= $row->email;   
					$data['phone']= $row->ph; 
					$data['name']= $row->name; 
					$data['register_date']= $register_date;  
					$data['email_varify']= $row->email_varify; 
					if($row->profile_pic!='')
						$data['profile_image1'] =   ROOTPATH."/uploads/users/".$row->cust_id."/profile-pic/".$row->profile_pic;
					else					 
						$data['profile_image1'] =   ROOTPATH."/uploads/mail-images/profile_icon.png";
					 
					$data['profile_image2']=  ROOTPATH."/uploads/temp-ads/temp_back.jpg"; 
					mysql_query("update users set token_id = '$_POST[token_id]' where cust_id = '$row->cust_id' ");  
             
					 $ary['message'] = "Success";
					 $ary['status'] = "200";
					 $ary['data'] = $data; 
					 echo  json_encode($ary);
					 die; 
				}
			}  
			
			
			 
		 
			if($_POST['login_check'])  
			{  
			     
				$result = mysql_query("select password from users where  ( email='$_POST[login_credentials]' || ph='$_POST[login_credentials]' )    ");      
				$row1 = mysql_fetch_object($result);
		 
				$decrypted = openssl_decrypt(hex2bin($row1->password),'AES-128-CBC',$Pwdkey);    
				//echo $decrypted.':'.$_POST['password'];die; 
                if($decrypted==$_POST['password'])
                { 
    				$result = mysql_query("select * from users where  ( email='$_POST[login_credentials]' || ph='$_POST[login_credentials]' )  and password='$row1->password' ");    
    				if(mysql_num_rows($result)>0)
    				{ 
    					$row = mysql_fetch_object($result);   
    					$old_date = $row->register_date; 
    					$old_date_timestamp = strtotime($old_date);
    					$register_date =  date('d-M-Y', $old_date_timestamp);
    			
    					$data['cust_id'] = $row->cust_id; 
    					$data['email']= $row->email;   
    					$data['phone']= $row->ph; 
    					$data['name']= $row->name; 
    					$data['register_date']= $register_date;  
    					$data['email_varify']= $row->email_varify; 
    					if($row->profile_pic!='')
    						$data['profile_image1'] =   ROOTPATH."/uploads/users/".$row->cust_id."/profile-pic/".$row->profile_pic;
    					else					 
    						$data['profile_image1'] =   ROOTPATH."/uploads/mail-images/profile_icon.png";
    					
    					
    					$data['profile_image2']=  ROOTPATH."/uploads/temp-ads/temp_back.jpg"; 
    					mysql_query("update users set token_id = '$_POST[token_id]' where cust_id = '$row->cust_id' ");    
    					 
    			 
    					 $ary['message'] = "Success";
    					 $ary['status'] = "200";
    					 $ary['data'] = $data; 
    					 echo  json_encode($ary);
    					 die; 
    				}
                }
				else
				{ 	 
					 $data['account_exist'] = 0;
					 $ary['status'] = "200";
					 $ary['message'] = "failure";
					 $ary['data'] = "Invalid Credentials";
					 echo  json_encode($ary);
					 die;
				}  
			}   	 

			//https://www.meerindia.com/my-local-app/ws/registration-login.php?my_account=1&cust_id=cust_id
			//my_account=1&cust_id=cust_id   
			 
			  
			
			
			
			if(isset($_POST['my_account']))
			{     
				$result = mysql_query("select * from users  where cust_id='$_POST[cust_id]' "); 
				$row = mysql_fetch_object($result);   
				$data['add_posted'] = $row->post_added;
				$data['add_responded'] = $row->post_responded; 
				$ary['adv_img'] = ROOTPATH.'/uploads/temp-ads/DGH13RT.jpg'; 

				$old_date = $row->register_date;
				$old_date_timestamp = strtotime($old_date);
				$register_date =  date('d-M-Y', $old_date_timestamp);   
				$data['active_since'] = $register_date;
				
				/********** alert section start **************/
				
				$user_alerts = $row->user_alerts;  
				if($user_alerts!='')
				{
				
					$user_alerts_arry = explode(",",$user_alerts);    
					$alert_tabel = "alert_tabel_".$user_alerts_arry[0];     
	 
					$query_result = mysql_query("select category_id,id,posted_date  from $alert_tabel where cust_id='$_POST[cust_id]'  and alert_for = 2 ");   
					
					$find_row  = mysql_fetch_object($query_result);
					{     
						$city_tabel = "city_tabel_".$user_alerts_arry[0];  
						if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$city_tabel."'"))==1) 
						{     
							 
							$query_result1 = mysql_query("select COUNT(*)  from $city_tabel where category_id=$find_row->category_id ");   
							$find_row1  = mysql_fetch_row($query_result1);    
						
							$cat_id_result = mysql_query("select name from job_categories where id=$find_row->category_id ");
							$cat_id_name = mysql_fetch_row($cat_id_result); 
							$alert_details['heading'] = $cat_id_name[0];
							$alert_details['id'] = $find_row->id; 
							$posted_date = get_date_difer($find_row->posted_date);
							$alert_details['posted_date'] = $posted_date;  
							$alert_details['city_id'] = $user_alerts_arry[0];  
							$alert_details['alert_for'] = 2;  
							 
						}else
						{   
							$cat_id_result = mysql_query("select name from job_categories where id=$find_row->category_id ");
							$cat_id_name = mysql_fetch_row($cat_id_result); 
							$alert_details['heading'] = $cat_id_name[0];
							$alert_details['id'] = $find_row->id;
							$posted_date = get_date_difer($find_row->posted_date);
							$alert_details['posted_date'] = $posted_date;
							$alert_details['city_id'] = $user_alerts_arry[0];  
							$alert_details['alert_for'] = 2;   
						}  
						$data['alert_data']   = (object) $alert_details;  
						 
					}
					
					$user_alerts = $row->user_alerts;  
					$user_alerts_arry = explode(",",$user_alerts); 
					 
					$ct= 0; 
					foreach($user_alerts_arry as $dt)
					{ 
						$alert_tabel = "alert_tabel_".$dt;     
						$query_result = mysql_query("select  COUNT(*) as total_alert_count  from $alert_tabel where cust_id='$_POST[cust_id]'  and alert_for = 2 ");   
						$find_row  = mysql_fetch_row($query_result);    
						$ct +=	$find_row[0];   
					}      
					$data['alert_count']  = $ct;  
				}else
				{
					$data['alert_data'] = null;
				}
				
				
				/********** alert section end **************/
				
				 
				$alert_details = null;
				$user_jobs = $row->user_jobs;  
				if($user_jobs!='')
				{
					$user_alerts_arry = explode(",",$user_jobs);  
					//foreach($user_alerts_arry as $dt)
					$job_tabel = "city_tabel_".$user_alerts_arry[0];     
					$query_result = mysql_query("select category_id,id,posted_date,heading,post_id  from $job_tabel where cust_id='$_POST[cust_id]'   ");   
					
					$find_row  = mysql_fetch_object($query_result);
					if($find_row->post_id == 2)
					{
						$rst = mysql_query("select name from service_categories where id = $find_row->category_id ");
						$service = mysql_fetch_row($rst);
						$alert_details['heading']  = $service[0];
					}
					else
						$alert_details['heading'] = $find_row->heading;
					
					$alert_details['id'] = $find_row->id;
					$posted_date = get_date_difer($find_row->posted_date);
					$alert_details['posted_date'] = $posted_date;
					$alert_details['city_id'] = $user_alerts_arry[0];     
					$alert_details['category_id'] = $find_row->category_id; 
					$alert_details['post_id'] = $find_row->post_id; 
					$alert_details['alert_for'] = 2;   
					$data['job_data']   = (object) $alert_details;  	   
					
					/********** job list section end **************/
					
					
					$user_jobs = $row->user_jobs;  
					$user_alerts_arry = explode(",",$user_jobs); 
					 
					$ct= 0; 
					foreach($user_alerts_arry as $dt)
					{ 
						$job_tabel = "city_tabel_".$dt;       
						$query_result = mysql_query("select COUNT(*) as total_job_count  from $job_tabel where cust_id='$_POST[cust_id]'   ");   
						$find_row  = mysql_fetch_row($query_result);   
						$ct +=	$find_row[0];   
					} 
					$data['job_count']  = $ct; 
				}else
				{
					$data['job_data'] = null;
				}     		
				
				  
				$ary['data'] = $data; 
				$ary['status'] = "200";
				$ary['message'] = "Success";
				echo  json_encode($ary);
				die;   
			}  
			
			if(isset($_POST['sign_up_step2'])) // Sign Up
			{   
					
				$cust_id =  strtoupper( substr(md5(time()),0,10)); 	
				$register_date  = date("Y-m-d"); 
				$email = $_POST['email'];
				
				$valid_id= md5(time()); 
                $password= $_POST['password'];
                $encrypted_pwd = bin2hex(openssl_encrypt($password,'AES-128-CBC', $Pwdkey));     
			 
				mysql_query("insert into users (name,password,email,ph,cust_id,register_date,valid_id,mobile_verify,account_status,registered_user,is_active,otp) values('$_POST[name]','$encrypted_pwd','$_POST[email]','$_POST[mobile]','$cust_id','$register_date','$valid_id',1,1,1,1,1)");        
                $mobile = $_POST['mobile'];
                $val = $_POST['password']; 
                $mobile=$ph;
                $msg="Thank you for being part of $SITE_NAME. Your login credentials are as: Email ID : $email, Mobile No : $ph, Password : $password Kindly do not share your login credentials with any other";
                SendSMS($mobile,$msg);   
                $link =  ROOTPATH.'/login/validate_email.php?valid_id='.$valid_id; 
                sign_up_step2($email,$link);   
               	$data['acccount_create'] = 1;   
    			$ary['status'] = "200";
    			$ary['message'] = "Success";
    			$ary['data'] = $data; 
    			echo  json_encode($ary);  
    			die;  
			}   
			
			if(isset($_POST['view_all_job']))
			{     
				$result = mysql_query("select * from users  where cust_id='$_POST[cust_id]' ");
				$row = mysql_fetch_object($result);     
				/********** job list section start **************/
				$alert_details = null;
				$user_jobs = $row->user_jobs;  
				$user_alerts_arry = explode(",",$user_jobs); 
				 
				$key= 0;
				foreach($user_alerts_arry as $dt)
				{ 
					$job_tabel = "city_tabel_".$dt;       
					$query_result = mysql_query("select category_id,id,posted_date,heading,post_id  from $job_tabel where cust_id='$_POST[cust_id]'   ");   
					
					while($find_row  = mysql_fetch_object($query_result))
					{     
						$alert_details['heading'] = $find_row->heading;
						
						if($find_row->post_id == 2)
						{
							$rst = mysql_query("select name from service_categories where id = $find_row->category_id ");
							$service = mysql_fetch_row($rst);
							$alert_details['heading']  = $service[0];
						}
						else
							$alert_details['heading'] = $find_row->heading;
					
					
						$alert_details['id'] = $find_row->id;
						$posted_date = get_date_difer($find_row->posted_date);
						$alert_details['posted_date'] = $posted_date;
						$alert_details['city_id'] = $dt;
						$alert_details['category_id'] = $find_row->category_id; 
						$alert_details['alert_for'] = 2;   
						$alert_details['post_id'] = $find_row->post_id; 
						$data[$key]  = (object) $alert_details;  
						$key++;  
					}
				}	   
				
				/********** job list section end **************/  
				  
				$ary['data'] = $data; 
				$ary['status'] = "200";
				$ary['message'] = "Success";
				echo  json_encode($ary);
				die;   
			}
			  
			    
			
			if(isset($_POST['view_all_alert']))
			{     
				$result = mysql_query("select * from users  where cust_id='$_POST[cust_id]' ");
				$row = mysql_fetch_object($result);  
				  
				
				/********** alert section start **************/
				
				$user_alerts = $row->user_alerts;  
				$user_alerts_arry = explode(",",$user_alerts); 
				 
				$key= 0;
				foreach($user_alerts_arry as $dt)
				{ 
					$alert_tabel = "alert_tabel_".$dt;     
					$query_result = mysql_query("select category_id,id,posted_date  from $alert_tabel where cust_id='$_POST[cust_id]'  and alert_for = 2 ");   
					
					while($find_row  = mysql_fetch_object($query_result))
					{     
						$city_tabel = "city_tabel_".$dt;    
						if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$city_tabel."'"))==1) 
						{     
							$query_result1 = mysql_query("select COUNT(*) as alert_count  from $city_tabel where category_id=$find_row->category_id ");     
							$find_row1  = mysql_fetch_row($query_result1);    
						
							$cat_id_result = mysql_query("select name from job_categories where id=$find_row->category_id ");
							$cat_id_name = mysql_fetch_row($cat_id_result); 
							$alert_details['heading'] = $cat_id_name[0];
							$alert_details['id'] = $find_row->id;
							 
							$posted_date = get_date_difer($find_row->posted_date);
							$alert_details['posted_date'] = $posted_date;
							$alert_details['city_id'] = $dt;
							$alert_details['similar_job_count'] = $find_row1[0];
							$alert_details['alert_for'] = 2;  
							 
						}else
						{   
							$cat_id_result = mysql_query("select name from job_categories where id=$find_row->category_id ");
							$cat_id_name = mysql_fetch_row($cat_id_result); 
							$alert_details['heading'] = $cat_id_name[0];
							$alert_details['id'] = $find_row->id;
							$posted_date = get_date_difer($find_row->posted_date);
							$alert_details['posted_date'] = $posted_date;
							$alert_details['city_id'] = $dt;
							$alert_details['similar_job_count'] = 0;
							$alert_details['alert_for'] = 2;   
						}  
						$data[$key]  = (object) $alert_details;  
						$key++;  
					}
				}	   
				
				/********** alert section end **************/    
				  
				$ary['data'] = $data; 
				$ary['status'] = "200";
				$ary['message'] = "Success";
				echo  json_encode($ary);
				die;   
			}

			if(isset($_POST['get_edit_profile']))
			{	  
				$result = mysql_query("select name,address,ph,email from users  where cust_id = '$_POST[cust_id]'  ");  
				$rw = mysql_fetch_object($result);
				
				$data['name'] = $rw->name;
				$data['address'] = $rw->address;
				$data['mobile'] = $rw->ph;
				$data['email'] = $rw->email;
				
				$ary['data'] = $data; 
				$ary['status'] = "200";
				$ary['message'] = "Success";
				echo  json_encode($ary);
				die;  
				
			}
			
			//https://www.meerindia.com/my-local-app/ws/registration-login.php?edit_profile=1&cust_id=cust_id&name=name&address=address&mobile=mobile&&profile_pic=profile_pic&password=password&current_password=current_password   
			if(isset($_POST['edit_profile']))
			{  
				if($_FILES['profile_pic']['name']!='')
				{  
					$cust_id = $_POST['cust_id']; 
					$path  = ABS_PATH.'/uploads/users/'.$cust_id;
					if (!file_exists($path))
						mkdir($path,0777);

					$path  = ABS_PATH.'/uploads/users/'.$cust_id.'/profile-pic';  
					if (!file_exists($path))
						mkdir($path,0777);
					
					$files = glob(ABS_PATH.'/uploads/users/'.$cust_id.'/profile-pic'.'/*'); // get all file names 
					foreach($files as $file)
					{ // iterate files
						if(is_file($file))
						unlink($file); // delete file
					}
					 
					$filename = strtoupper( substr(md5(time()),0,16)); 	
					$RD = explode(".",$_FILES['profile_pic']['name']);			
					$target_file = $path.'/'.$filename.'.'.end($RD); 
					$Fname = $filename.'.'.end($RD); 
					move_uploaded_file($_FILES['profile_pic']['tmp_name'],$target_file);           
					
					
					
					$inFile = $path.'/'.$Fname; 
					$filename = strtoupper( substr(md5(time()),0,16)); 
					$outFile = $path.'/'.$filename.'.'.end($RD);  
					$Fname	 = $filename.'.'.end($RD);   
					$cmd_x			= 'convert '.$inFile.'  -resize "180x220!" '.$outFile.' 2>&1'; 	 		  
					shell_exec($cmd_x);    
					mysql_query("update  users set profile_pic='$Fname' where cust_id = '$_POST[cust_id]'  ");  
					$data['profile_image1'] =   ROOTPATH."/uploads/users/".$_POST['cust_id']."/profile-pic/".$Fname;  
					
					
					$filename = strtoupper( substr(md5(time()),0,12)); 	
					$RD = explode(".",$_FILES['profile_large']['name']);			
					$target_file = $path.'/'.$filename.'.'.end($RD); 
					$Fname = $filename.'.'.end($RD); 
					move_uploaded_file($_FILES['profile_large']['tmp_name'],$target_file);           
					mysql_query("update  users set profile_pic_2='$Fname' where cust_id = '$_POST[cust_id]'  ");  
					$data['profile_image2'] =  ROOTPATH."/uploads/temp-ads/temp_back.jpg"; 
					
					
					$data['profile_pic_udapted'] = 1; 
					$ary['message'] = "Success";
					$ary['status'] = "200";
					$ary['data'] = $data; 
					echo  json_encode($ary);
					die; 
				}else
				{   
					if($_POST['email'])
					{
						$query = mysql_query("SELECT email  FROM users WHERE  email='$_POST[email]' and cust_id!='$_POST[cust_id]' "); 
						if (mysql_num_rows($query) > 0)    
							$data['profile_update'] = 3;         
						else 
						mysql_query("update  users set email='$_POST[email]'   where cust_id = '$_POST[cust_id]'  ");   
					}
					
					mysql_query("update  users set name='$_POST[name]' , address='$_POST[address]' , ph='$_POST[mobile]'  where cust_id = '$_POST[cust_id]'  ");   
					if($_POST['current_password'])
					{
						$rw = mysql_query("select password from  users  where cust_id = '$_POST[cust_id]'  ");  
						$password_test = mysql_fetch_row($rw);
						
						$ct_pwd = $_POST['current_password'];
						
						if($password_test[0] ==$ct_pwd)
						{
							mysql_query("update  users set  password='$_POST[password]'   where cust_id = '$_POST[cust_id]'  ");  
							$data['password_change'] = 1 ;	
						}else
							$data['password_change'] = 0 ;	    
					} 
					$data['profile_update'] = 1;       
					
					$ary['message'] = "Success";
					$ary['status'] = "200";
					$ary['data'] = $data; 
					echo  json_encode($ary);
					die; 
				}  
			}		  
			
			//https://www.meerindia.com/my-local-app/ws/registration-login.php?sign_up_step1_varify=1&mobile=mobile&cust_id=cust_id
			//sign_up_step1_varify=1&mobile=mobile 

			if(isset($_POST['sign_up_step1_varify']))
			{        
				$query = mysql_query("SELECT cust_id FROM users WHERE  ph='$_POST[mobile]' and cust_id!='$_POST[cust_id]' "); 
				if (mysql_num_rows($query) > 0)    
				{  
					$data['acccount_create'] = 0; 
					$ary['message'] = "Phone no is already exist!";     
					$ary['data'] = $data;
					$ary['status'] = "200";
					echo  json_encode($ary);  
					die;   
				}
				else 
				{	
				
					$val = strtoupper( substr((rand(43577,134)),0,4)); 	   
					$Success_msg = "Dear User,Your OTP for Laai Bhari is: $val Kindly do not share your OTP with any other";    
					$xml_data ='<?xml version="1.0"?>
					<parent>
					<child>
					<user>KalpanaG</user>
					<key>dacc4ff030XX</key>
					<mobile>'.$_POST['mobile'].'</mobile>
					<message>Dear User,Your OTP for Laai Bhari is: '.$val.' Kindly do not share your OTP with any other</message>
					<accusage>1</accusage>
					<senderid>LBHARI</senderid>
					</child>
					</parent>'; 
					
					 
					$URL = "http://103.233.79.246/submitsms.jsp?";  
					$ch = curl_init($URL);
					curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
					curl_setopt($ch, CURLOPT_POST, 1);
					curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
					curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
					curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
					$output = curl_exec($ch);
					curl_close($ch);     
				
					$data['acccount_create'] = 1;   
					$ary['status'] = "200";
					$ary['message'] = "Success";
					$data['otp'] = $val; 
					$ary['data'] = $data;	
					echo  json_encode($ary);  
					die;     
				}   
			}   
			
			if(isset($_POST['get_complete_profile']))
			{	  
				$result = mysql_query("select COUNT(*)  as ct from user_profile where cust_id ='$_POST[cust_id]' ");
				$count = mysql_fetch_row($result);      
				
				if($count[0] > 0)
				{
					$result = mysql_query("select * from user_profile where cust_id ='$_POST[cust_id]' ");
					$rw = mysql_fetch_object($result); 
					$data['upload_resume'] = ROOTPATH."uploads/users/".$_POST['cust_id']."/resume/".$rw->upload_resume;
					$data['salary'] = $rw->salary;
					$data['idproof'] = $rw->idproof;
					$data['designation'] = $rw->designation;   
					$data['workedfor'] = $rw->workedfor;   
					$data['special'] = $rw->special;   
					$data['yearsofworking'] = $rw->yearsofworking;   
					$data['job_comfort'] = $rw->job_comfort;   
					$data['language'] = $rw->language;   
					$data['education'] = $rw->education;   
					$data['passport'] = $rw->passport;   
					$data['all_city_id'] = $rw->all_city_id;   
					
					$ary['data'] = $data; 
					$ary['status'] = "200";
					$ary['message'] = "Success";
				}else
				{
					$ary['data'] = $data; 
					$ary['status'] = "200";
					$ary['message'] = "Success";
				}   			 
				echo  json_encode($ary);
				die;   
			} 
			
			if(isset($_POST['complet_profile_resume']))
			{ 	   
				$result = mysql_query("select COUNT(*)  as ct from user_profile where cust_id ='$_POST[cust_id]' ");
				$count = mysql_fetch_row($result);    
				$cust_id = 	$_POST['cust_id']; 
				if($count[0] > 0)
				{      
					$files = glob(ABS_PATH.'/uploads/users/'.$cust_id.'/resume/*'); // get all file names 
					foreach($files as $file)
					{ // iterate files
						if(is_file($file))
						unlink($file); // delete file
					} 
					
					$path  = ABS_PATH.'/uploads/users/'.$cust_id.'/resume';   
					if($_FILES['upload_resume']['name']!='')
					{ 
						$filename = strtoupper( substr(md5(time()),0,16)); 	
						$RD = explode(".",$_FILES['upload_resume']['name']);			
						$target_file = $path.'/'.$filename.'.'.end($RD); 
						$Fname = $filename.'.'.end($RD); 
						move_uploaded_file($_FILES['upload_resume']['tmp_name'],$target_file);            
					}else
						$Fname = '';
					
					mysql_query("update user_profile set upload_resume='$Fname'  where cust_id ='$_POST[cust_id]' "); 	  
				}else
				{  
					$path  = ABS_PATH.'/uploads/users/'.$cust_id; 
					if (!file_exists($path))
					{			 
						mkdir($path,0777);			 
					}  
					
					$path  = ABS_PATH.'/uploads/users/'.$cust_id.'/resume'; 
					if (!file_exists($path))
					{			 
						mkdir($path,0777);			 
					}  
					if($_FILES['upload_resume']['name']!='')
					{ 
						$filename = strtoupper( substr(md5(time()),0,16)); 	
						$RD = explode(".",$_FILES['upload_resume']['name']);			
						$target_file = $path.'/'.$filename.'.'.end($RD); 
						$Fname = $filename.'.'.end($RD); 
						move_uploaded_file($_FILES['upload_resume']['tmp_name'],$target_file);            
					}else
						$Fname = '';
					
					mysql_query("insert into  user_profile  (cust_id,upload_resume) values('$_POST[cust_id]','$Fname') ");     
				}           
				
				$data['reume_updated'] = 1; 
				$ary['data'] = $data; 
				$ary['message'] = "Success";
				$ary['status'] = "200";  
				echo json_encode($ary);   
				die;    
			}
			 
			if(isset($_POST['complet_profile']))
			{    
				$result = mysql_query("select COUNT(*)  as ct from user_profile where cust_id ='$_POST[cust_id]' ");
				$count = mysql_fetch_row($result);    
				
				if($count[0] > 0)
				{    
					mysql_query("update user_profile set salary='$_POST[salary]',idproof='$_POST[idproof]',designation='$_POST[designation]',workedfor='$_POST[workedfor]',special='$_POST[special]',yearsofworking='$_POST[yearsofworking]', job_comfort='$_POST[job_comfort]',language='$_POST[language]',education='$_POST[education]',passport='$_POST[passport]',all_city_id='$_POST[all_city_id]' where cust_id ='$_POST[cust_id]' "); 	  
				}else
				{     
					mysql_query("insert into  user_profile  (salary,idproof,designation,workedfor,special,yearsofworking,job_comfort,language,education,passport,all_city_id,cust_id) values('$_POST[salary]','$_POST[idproof]','$_POST[designation]','$_POST[workedfor]','$_POST[special]','$_POST[yearsofworking]','$_POST[job_comfort]','$_POST[language]','$_POST[education]','$_POST[passport]','$_POST[all_city_id]','$_POST[cust_id]') ");     
				} 
				$data['updated'] = 1; 
				$ary['data'] = $data; 
				$ary['message'] = "Success";
				$ary['status'] = "200";  
				echo json_encode($ary);   
				die; 
			}  
			  
			 
			
			if(isset($_POST['candidate_search']))
			{	  
				$city_id = $_POST['city_id'];  
				$result = mysql_query("select *  from user_profile where all_city_id like '%$city_id%' ");  
				if (mysql_num_rows($result) > 0)  
				{   
					$start=0;
					$limit=8;
					$id=1;	
					
					if($_POST['index'])
					{
						$id=$_POST['index'];
						$start=($id-1)*$limit;
					}  
					if($_POST['index'] < 2)
					{
						$rows=mysql_num_rows(mysql_query("select *  from user_profile where all_city_id like '%$city_id%' "));  
						$total=ceil($rows/$limit); 
						$ary['count'] = $rows; 
					} 
					$result = mysql_query("select *  from user_profile where all_city_id like '%$city_id%'  order by id LIMIT $start, $limit "); 	 
					$key = 0;
					while($rw = mysql_fetch_object($result))
					{  
						
						$result1 = mysql_query("select name,address,register_date,video_resume from users where cust_id = '$rw->cust_id'");
						$user_d = mysql_fetch_object($result1);
						
							
						$old_date = $user_d->register_date; 
						$old_date_timestamp = strtotime($old_date);
						$register_date =  date('d-M-Y', $old_date_timestamp);
				
						
						if($rw->upload_resume!='')
							$alert_details['upload_resume'] = 'Available'; 
						
						$alert_details['name'] = $user_d->name;
						$alert_details['posted_on'] = $register_date;
						$alert_details['address'] = $user_d->address;
						$alert_details['salary'] = $rw->salary;
						$alert_details['idproof'] = $rw->idproof;
						$alert_details['designation'] = $rw->designation;   
						$alert_details['workedfor'] = $rw->workedfor;   
						$alert_details['special'] = $rw->special;   
						$alert_details['yearsofworking'] = $rw->yearsofworking.' Years';
						if($user_d->video_resume==1)
							$alert_details['video_resume'] = 'https://www.laaibhari.com';   
						else
							$alert_details['video_resume'] = 'https://www.laaibhari.com';    
			 
						$job_comfort='';
						$job_comfort_ary=explode(",",$rw->job_comfort);
						if($job_comfort_ary[0]==1) 
							$job_comfort ="Full Time";
						else if($job_comfort_ary[0]==2) 
							$job_comfort ="Part Time";
						
						if($job_comfort_ary[1]==1) 
							$job_comfort .=", Full Time";
						else if($job_comfort_ary[1]==2) 
							$job_comfort .=", Part Time"; 
						
						
						$alert_details['job_comfort'] = $job_comfort;   
						$alert_details['language'] = $rw->language;   
						$alert_details['education'] = $rw->education;   
						$alert_details['passport'] = $rw->passport;     
						//$alert_details['video_resume'] = "Not Available";
						$alert_details['cust_id'] = $rw->cust_id;     
						$data[$key]  = (object) $alert_details;  
						$key++;      
					}
				} 
				$ary['total'] = $total;
				$ary['data'] = $data; 
				$ary['status'] = "200";
				$ary['message'] = "Success";
				echo  json_encode($ary);
				die;   
			} 
?>