<?php
		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')"); 
		
		/*$Data1 = json_decode(file_get_contents( 'php://input' ), true ); 
		$Data2 = json_encode($Data1);  
		mysql_query("insert into test (name) values('$Data2')");
	 	*/
	 	
		//$A = '{"create_alart":"1","type":"3","alert_for":"2","category_id":"60","city_id":"5","location_id":"758,759","cust_id":"427888"}';
        //$_POST = (array)json_decode($A);
       // print_r($_POST); 
       
        $Getdata1 = json_decode( file_get_contents( 'php://input' ), true );      
		$Getdata2 =  json_encode($Getdata1); 
		mysql_query("insert into test (name) values('$Getdata2')");
		
		//$Grabdata1 = json_encode($Getdata1); 
		
		/*************** JOB SECTION  START************************/              		
		/*
			$Ticket_data =  "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
			<html xmlns='http://www.w3.org/1999/xhtml'>
			<head>
			<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
			<title>Newsletter</title>
			</head>
			<body>
			<div style='width:600px; margin:0px auto; border:1px solid #ddd; background:#f9f9f9; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#444; '>
			<table width='100%' border='0' cellspacing='0' cellpadding='0'>
			<tr>
			<td height='150' align='center' valign='middle' bgcolor='#FFFFFF'><img  src='".MAIN_ROOTPATH."/uploads/mail-images/banner.png' alt='img' /></td>
			</tr>
			<tr>
			<td style='background:url('".MAIN_ROOTPATH."/uploads/mail-images/shadow.png) repeat-x left top;'>&nbsp;</td>
			</tr>
			<tr>
			<td>
			<div style=' display:block;padding:1px 20px 15px; color:#333; font-size:19px; line-height:28px ; text-align:left;'>Hello ".$name.",<br />
			<span style='color:#e90021;'>Job Apply! </span>Candidate apply for job   
			</div>
			</td>
			</tr>   
			<tr>
			<td bgcolor='#f3f3f3'>
			<div style='padding:20px; display:block;'>
			<div style='width:20%; text-align:center; float:left; display:inline-block; padding-bottom:20px;'>
			<img  src='".MAIN_ROOTPATH."/uploads/mail-images/alert.png' width='49' height='43' alt='img' />
			</div>
			<div style='width:79%; float:right; text-transform:uppercase; display:inline-block; font-weight:bold; color:#333; font-size:15px;'>
			Beware of fraud Agents!
			Do not pay money for getting a job
			</div>
			<div style='clear:both'></div>
			<p style=' border-top:1px dotted #b9b9b9; margin:0px; padding-top:17px; font-size:13px; color:#666;'>
			 <a href='http://www.laaibhari.com' style='color:#008acc'>Lai Bhari</a> is the fastest growing site in india , get quick and guaranteed response. Become paid member and enjoy more response from Laai Bhari.
			</p>
			</div>
			</td>
			</tr>  
			</table> 
			</div> 
			</body>
			</html>  
			"; 
			echo $Ticket_data ;		
			die;	
		*/	
	 

		   
		if(isset($_POST['similar_jobs']))
		{      
			$alert_tabel = "alert_tabel_".$_POST['city_id'];   
			$query_result = mysql_query("select type,category_id, location_id,id,posted_date  from $alert_tabel where cust_id='$_POST[cust_id]'  and alert_for = 2 and id=$_POST[alert_id] ");   
			$key= 0;
			$find_row  = mysql_fetch_object($query_result);    
			
			$jb_name_R = mysql_query("select  name from job_categories where id = $find_row->category_id ");
			$jb_name = mysql_fetch_object($jb_name_R);  
			$city_tabel = "city_tabel_".$_POST['city_id'];     
			
			if($find_row->location_id=='')
				$location_id = "";
			else
				$location_id = " and  location_id IN (".$find_row->location_id.")" ; 
			
			 
			$query_result1 = mysql_query("select id,heading,location_id,posted_date,company,user_type  from $city_tabel where category_id=$find_row->category_id $location_id   ");   
			
			while($row  = mysql_fetch_object($query_result1))  
			{    
				$test_ary[$key]['id'] = $row->id; 
				$test_ary[$key]['heading'] = $row->heading; 

				$location_id_R = mysql_query("select  location_name from city_lacations where id = $row->location_id ");
				$location_id = mysql_fetch_object($location_id_R);
				if($location_id->location_name=='') 
				$test_ary[$key]['locality'] = "Whole City";
				else 
				$test_ary[$key]['locality'] = $location_id->location_name; 

				$posted_date = get_date_difer($row->posted_date);
				$test_ary[$key]['posted_date'] = $posted_date;   
				$test_ary[$key]['posted_by'] = $row->company;      
				$test_ary[$key]['role'] = $jb_name->name; 
				$test_ary[$key]['paid_type'] = $row->user_type; 
				$test_ary[$key]['city_id'] = $_POST['city_id'];   
				$key++;
			}
			   	

			$key=0; 
			$ct = 1;
			for($i=0;$i<count($test_ary);$i++) 
			{     
				if($ct==5) 
				{
					$find_job['row_type'] = 1; 
					$find_job['adv_img'] = "https://www.laaibhari.com/ws/seekers1.jpg"; 
					$ct = 1;
					$i = $i-1;
				}else
				{
					$find_job['row_type'] = 0; 
					$find_job['id'] = $test_ary[$i]['id'];
					$find_job['heading'] = $test_ary[$i]['heading'];
					$find_job['locality'] = $test_ary[$i]['locality'];
					$find_job['posted_date'] = $test_ary[$i]['posted_date'];
					$find_job['posted_by'] = $test_ary[$i]['posted_by'];
					$find_job['role'] = $test_ary[$i]['role'];
					$find_job['paid_type'] = $test_ary[$i]['paid_type'];
					$find_job['city_id'] = $test_ary[$i]['city_id'];
					$ct++;
				} 
				$data[$key]  = (object)$find_job;   
				$key++;
			}      
	

			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;   	  
		}  
		 
	    
		if(isset($_POST['PostJobSetp2']))
        {
        	$catId=$_POST['catId']; 
    		$resultdata = mysql_query("select id,category_id,account_id,heading,parameters,type,parameters_type from more_subjob_categories order by byOrder"); 
            $more_subjob_ary1=array();
            $more_subjob_ary2=array();
            while($more_subjob = mysql_fetch_object($resultdata))
            {
              if($more_subjob->category_id==$catId)
              {
                  $more_subjob_ary1[]=$more_subjob;
              }
              
              if($more_subjob->parameters_type==0)
              {
                  $more_subjob_ary2[]=$more_subjob;
              }
            } 
    		  
            $more_subjob_ary=array_merge($more_subjob_ary1,$more_subjob_ary2);
            $new_ary['job_creadted'] = 1; 
            $new_ary['message'] = "Success";
            $new_ary['status'] = "200";
            foreach($more_subjob_ary as $key=>$dt)
            {
    			$job_data["Record"]['type']=$dt->type;
    			unset($ABCD);
    			$ABCD = explode(",",$dt->parameters); 
    			 
            	//$job_data["Record"]['parameters']=$dt->parameters;
            	$job_data["Record"]['caption']=$dt->heading;
            	$job_data["Record"]['heading']=$ABCD;
            	$total_para=explode(',',$dt->parameters);
            	$job_data["Record"]['total_para']=count($total_para);
            	
            	$new_ary["data"][$key] = (object)$job_data; 
            }
            $Fdata = (object)$new_ary;   
            echo json_encode($Fdata);   
            die;
		}
		    
	   
	   
	     if(isset($_POST['post_job_2']))
	     {
	         
	         	$data['job_creadted'] = 1;  
				$ary['message'] = "Success";
				$ary['status'] = "200";
				$ary['data'] = $data; 
				echo json_encode($ary);   
				die; 
	     }
	   
	    if(isset($_POST['post_job']))
		{ 
		   				
			if($_POST['location_id'])
				$location_id = $_POST['location_id'];
			else
				$location_id = 0;
			
			if($_POST['sub_category_id'])
				$sub_category_id = $_POST['sub_category_id'];
			else
				$sub_category_id = 0;
			
			 
			$posted_date =  date('Y-m-d H:i:s');
			$tabel_name = "city_tabel_".$_POST['city_id'];    
			
			$result = mysql_query("select user_type from paid_members where cust_id ='$_POST[cust_id]' and post_id = $_POST[post_id] and category_id = $_POST[category_id] and city_id = $_POST[city_id] ");
			$user_type_ary = mysql_fetch_row($result);
			
			if( (empty($user_type_ary)) || ($user_type_ary==null) )
				$user_type = 0;
			else
				$user_type = $user_type_ary[0];   
			 
			$UserName = mysql_fetch_object(mysql_query("select name from users where cust_id = '$_POST[cust_id]'  "));
			$name = $UserName->name;
			
			$UserName = mysql_fetch_object(mysql_query("select name from  job_categories where id = $_POST[category_id]  "));
			$catgory_name = $UserName->name;
			$heading = $_POST['heading'];
			
			$UserName = mysql_fetch_object(mysql_query("select name from  all_cities where id = $_POST[city_id]  "));
			$city_name = $UserName->name;	 
		 
			 			
			if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tabel_name."'"))==1) 
				echo mysql_query("insert into $tabel_name   (type,category_id,heading,sub_category_id,min_salary,max_salary,description,location_id,contact_email,contact_mobile,cust_id,posted_date,company,privacy,post_id,user_type) values  ($_POST[type],$_POST[category_id],'$_POST[heading]',$sub_category_id,'$_POST[min_salary]','$_POST[max_salary]','$_POST[description]',$location_id,'$_POST[contact_email]','$_POST[contact_mobile]','$_POST[cust_id]','$posted_date','$_POST[company]',$_POST[privacy],$_POST[post_id],$user_type) ");       
			else 
			{   
				
				mysql_query("CREATE TABLE $tabel_name ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, posted_date varchar(200) NOT NULL, company varchar(200) NOT NULL, type tinyint(1) NOT NULL COMMENT 'work from home => 1 part time => 2 full time => 3 internship job => 4', heading text NOT NULL, category_id int(11) NOT NULL,   sub_category_id varchar(200) NOT NULL,  min_salary varchar(200) NOT NULL,  max_salary varchar(200) NOT NULL,  min_expr int(11) NOT NULL,  max_expr int(11) NOT NULL, description text NOT NULL, location_id varchar(200) NOT NULL,  contact_email varchar(200) NOT NULL,  contact_mobile varchar(200) NOT NULL,  cust_id varchar(200) NOT NULL,add_view int(11) NOT NULL,privacy int(11) NOT NULL,post_id int(11) NOT NULL,user_type tinyint(1) NOT NULL,enq tinyint(1) NOT NULL,service_image varchar(200) NOT NULL,url varchar(200) NOT NULL,status tinyint(1) NOT NULL,reason varchar(200) NOT NULL,job_date varchar(200) NOT NULL,edit_count int(11) NOT NULL)  ");
				 
				mysql_query("insert into $tabel_name   (type,category_id,heading,sub_category_id,min_salary,max_salary,description,location_id,contact_email,contact_mobile,cust_id,posted_date,company,privacy,post_id,user_type) values  ($_POST[type],$_POST[category_id],'$_POST[heading]',$sub_category_id,'$_POST[min_salary]','$_POST[max_salary]','$_POST[description]',$location_id,'$_POST[contact_email]','$_POST[contact_mobile]','$_POST[cust_id]','$posted_date','$_POST[company]',$_POST[privacy],$_POST[post_id],$user_type) ");    
			}   
			
				$last_id =  mysql_insert_id(); 
				$user_job_query = mysql_query("select user_jobs  from users where cust_id='$_POST[cust_id]' ");
				$user_job_ct =  mysql_fetch_row($user_job_query);    
				mysql_query("update users set post_added = post_added+1 where cust_id='$_POST[cust_id]' "); 
				$city_id = $_POST['city_id'];
				if (!preg_match('/'.$city_id.'/',$user_job_ct[0]))
				{  
					$user_jobs =$user_job_ct[0].",".$_POST['city_id']; 
					$user_jobs = trim($user_jobs,",");  
					mysql_query("update users set user_jobs = '$user_jobs' where cust_id='$_POST[cust_id]' ");
				} 
				 
				$alert_tabel = "alert_tabel_".$_POST['city_id'];    
				$lc_id ='%'.$_POST['location_id'].'%'; 	 
				if($_POST['location_id'])
					$location_id = " and location_id like '".$lc_id."' and";
				else
					$location_id = " and";     
				
				
				if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$alert_tabel."'"))==1)  
				{    
					$query_result = mysql_query("select cust_id from $alert_tabel  where type=$_POST[type]   and category_id = $_POST[category_id]   $location_id    alert_for = 2     "); 
					if(mysql_num_rows($query_result)>0)
					{  
						while($row = mysql_fetch_object($query_result ))
						{     
							$rst = mysql_query("select token_id from users where cust_id = '$row->cust_id'  ");
							$token_id = mysql_fetch_object($rst); 
							$url = 'https://fcm.googleapis.com/fcm/send'; 
							$Token = $token_id->token_id;  
							//$fields = array('to' => $Token ,'notification' => array( 'body'=>'{"message": "New Job Posted","job_id": "'.$last_id.'","city_id": "'.$_POST['city_id'].'"}', 'title' => $_POST['heading']));  	  
							
							$fields = array("to" => $Token ,"data" => array("message"=>"New Job Posted","job_id" => $last_id ,"city_id" => $_POST['city_id']  ));  	     

							define('GOOGLE_API_KEY', 'AAAA7mjq6VI:APA91bF6m_VIWv8vQJPB0S3-RJz6xIKhkzXYaJv95WZPgnJsO3c2-nHwji_LNPFQSwOibEIaCzwdEkX9BymdSfrQRPHTOuNSMpIn-o8jBZK7Mv94ds2jQ-nJQ7XlEcImoHQutOJcHGwO'); 
							$headers = array(
							'Authorization:key='.GOOGLE_API_KEY,
							'Content-Type: application/json'
							);  						
							 

							$curl = curl_init(); 
							curl_setopt_array($curl, array(
							CURLOPT_URL => $url,
							CURLOPT_RETURNTRANSFER => true,
							CURLOPT_ENCODING => "",
							CURLOPT_MAXREDIRS => 10,
							CURLOPT_TIMEOUT => 30,
							CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
							CURLOPT_CUSTOMREQUEST => "POST",
							CURLOPT_POSTFIELDS =>json_encode($fields),
							CURLOPT_HTTPHEADER => $headers,
							CURLOPT_SSL_VERIFYPEER => false,
							)); 
							curl_exec($curl);  
						}  
					}  
				
				}
				
    
                  
					$subject = "You job posted on ".$SITE_NAME;
					PostJob($_POST['contact_email'],$subject,$name,$catgory_name,$heading,$city_name);  
					$data['job_creadted'] = 1; 
					$data['latinsertedId'] = $last_id;
					$data['city_id'] = $_POST['city_id'];
					$ary['message'] = "Success";
					$ary['status'] = "200";
					$ary['data'] = $data; 
					echo json_encode($ary);   
					die; 
		} 
		
		if(isset($_POST['find_job']))
		{   		
			 
			if($_POST['category_id'] || $_POST['category_id']!='') 
				$category_id = $_POST['category_id']; 
			else
				$category_id = 0; 
			
			if($_POST['type'] || $_POST['type']!='')    
					$type = $_POST['type'];       
			else
				 $type = 0;
			 
		 
			$temp_rr = mysql_query("select ph from users where token_id = '$_POST[token_id]' ");      
			$test_rr = mysql_fetch_object($temp_rr);
			mysql_query("insert into views (city_id,post_id,cateory_id,type,ph) values($_POST[city_id],1,$category_id,$type,'$test_rr->ph') ");      
			
			$tabel_name = "city_tabel_".$_POST['city_id'];    
			if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tabel_name."'"))==1) 
			{      
				if($_POST['type'] || $_POST['type']!='')    
					$type = " type=".$_POST['type'];       
				else
				 $type = "";  
				
				if($_POST['location_id'] || $_POST['location_id']!='') 
					$location_id = " and location_id IN ( ".$_POST['location_id']." )" ;   
				else
					$location_id = ""; 
				
				if($_POST['category_id'] || $_POST['category_id']!='') 
					$category_id = " category_id=".$_POST['category_id']; 
				else
					$category_id = ""; 
				
				if($_POST['sorting_type']==1)  
						$sorting_type = " order by  user_type desc,id desc" ;    
				else
					$sorting_type = " order by user_type desc,id desc";  
				
				$start=0;
				$limit=100;
				$id=1;	
				
				if($_POST['index'])
				{
					$id=$_POST['index'];
					$start=($id-1)*$limit;
				}   
				
				if($type=='')
				{	   
					if($_POST['index'] < 2)
					{
						$rows=mysql_num_rows(mysql_query("select * from $tabel_name where post_id=1 and  $category_id  $location_id  ")); 
						$total=ceil($rows/$limit); 
						$ary['total'] = $total; 
						$ary['count'] = $rows; 
						//$_POST['token_id'] = 1;
					}       
					$result= mysql_query("select id,heading,location_id,posted_date,company,user_type,max_salary from $tabel_name where    $category_id  and post_id = 1 and status = 1   $location_id $sorting_type  LIMIT $start, $limit  ");    
					$jb_name_R = mysql_query("select  name from job_categories where id = $_POST[category_id] ");
					$jb_name = mysql_fetch_object($jb_name_R);    
					$key=0; 
					while($row = mysql_fetch_object($result))
					{ 
						
						$test_ary[$key]['id'] = $row->id; 
						$test_ary[$key]['heading'] = $row->heading; 
						
						$location_id_R = mysql_query("select  location_name from city_lacations where id = $row->location_id ");
						$location_id = mysql_fetch_object($location_id_R);
						if($location_id->location_name=='') 
							$test_ary[$key]['locality'] = "Whole City";
						else 
							$test_ary[$key]['locality'] = $location_id->location_name; 
						
						$posted_date = get_date_difer($row->posted_date);
						$test_ary[$key]['posted_date'] = $posted_date;  

						$test_ary[$key]['posted_by'] = $row->company;      
						$test_ary[$key]['role'] = $jb_name->name; 
						$test_ary[$key]['paid_type'] = $row->user_type; 
						$test_ary[$key]['city_id'] = $_POST['city_id'];
						$test_ary[$key]['salary'] = $row->max_salary; 
						$test_ary[$key]['applidJob'] = 1;   
						$key++;
					}  
					
					$key=0; 
					$ct = 1;
					for($i=0;$i<count($test_ary);$i++) 
					{    
				
						if($ct==5) 
						{
							$find_job['row_type'] = 1; 
							$find_job['adv_img'] = ROOTPATH.'/uploads/temp-ads/RGT234FG.jpg'; 
							$ct = 1;
							$i = $i-1;
						}else
						{
							$find_job['row_type'] = 0; 
							$find_job['id'] = $test_ary[$i]['id'];
							$find_job['heading'] = $test_ary[$i]['heading'];
							$find_job['locality'] = $test_ary[$i]['locality'];
							$find_job['posted_date'] = $test_ary[$i]['posted_date'];
							$find_job['posted_by'] = $test_ary[$i]['posted_by'];
							$find_job['role'] = $test_ary[$i]['role'];
							$find_job['paid_type'] = $test_ary[$i]['paid_type'];
							$find_job['city_id'] = $test_ary[$i]['city_id'];
							$find_job['salary'] = $test_ary[$key]['salary'];
						    $find_job['applidJob'] = 1;  
							$ct++;
						} 
						$data[$key]  = (object)$find_job;   
						$key++;
					}      
					
					
					$items = Array('NHCTTD123_2.jpg');    
					$ary['full_screen_adv_img'] = ROOTPATH.'/uploads/temp-ads/'.$items[array_rand($items)];	 
					$ary['message'] = "Success";
					$ary['status'] = "200";  
					$ary['data'] = $data;   
					echo  json_encode($ary);  
					die;      
				}else
				{  
			 
					if($_POST['index'] < 2)
					{
						$rows=mysql_num_rows(mysql_query("select * from $tabel_name where  post_id=1 and status = 1   and  $type   $location_id    ")); 
						$total=ceil($rows/$limit); 
						$ary['total'] = $total; 
						$ary['count'] = $rows;
					}
					
					$result= mysql_query("select  id,heading,location_id,posted_date,company,category_id,user_type from $tabel_name where $type  and  post_id = 1  $location_id  $sorting_type    LIMIT $start, $limit "); 
					$key=0; 
					while($row = mysql_fetch_object($result))
					{   						
						
						$location_id_R = mysql_query("select  location_name from city_lacations where id = $row->location_id ");
						$location_id = mysql_fetch_object($location_id_R);
						
						if($location_id->location_name=='') 
							$test_ary[$key]['locality'] = "Whole City";
						else 
							$test_ary[$key]['locality'] = $location_id->location_name;   
						
						$test_ary[$key]['id'] = $row->id; 
						$test_ary[$key]['heading'] = $row->heading;  
						
						$jb_name_R = mysql_query("select  name from job_categories where id = $row->category_id");
						$jb_name = mysql_fetch_object($jb_name_R);  
						$test_ary[$key]['role'] = $jb_name->name;  
						$test_ary[$key]['posted_by'] = $row->company;      
						
						$posted_date = get_date_difer($row->posted_date);
						$test_ary[$key]['posted_date'] = $posted_date;      
						$test_ary[$key]['paid_type'] = $row->user_type;
						$test_ary[$key]['city_id'] = $_POST['city_id'];  
						$test_ary[$key]['salary'] = $row->max_salary; 
						$test_ary[$key]['applidJob'] = 1; 
						$key++;
					}  
					
					
					$key=0; 
					$ct = 1;
					for($i=0;$i<count($test_ary);$i++) 
					{    				
						if($ct==5) 
						{
							$find_job['row_type'] = 1; 
							$find_job['adv_img'] = ROOTPATH.'/uploads/temp-ads/RGT234FG.jpg'; 
							$ct = 1;
							$i = $i-1;
						}else
						{
							$find_job['row_type'] = 0; 
							$find_job['id'] = $test_ary[$i]['id'];
							$find_job['heading'] = $test_ary[$i]['heading'];
							$find_job['locality'] = $test_ary[$i]['locality'];
							$find_job['posted_date'] = $test_ary[$i]['posted_date'];
							$find_job['posted_by'] = $test_ary[$i]['posted_by'];
							$find_job['role'] = $test_ary[$i]['role'];
							$find_job['paid_type'] = $test_ary[$i]['paid_type'];
							$find_job['city_id'] = $test_ary[$i]['city_id'];
							$find_job['salary'] = $test_ary[$key]['salary'];
					    	$find_job['applidJob'] = 1; 
							$ct++;
						} 
						$data[$key]  = (object)$find_job;   
						$key++;
					}   

					$items = Array('NHCTTD123_2.jpg');    
					$ary['full_screen_adv_img'] = ROOTPATH.'/uploads/temp-ads/'.$items[array_rand($items)];	 
					$ary['message'] = "Success";
					$ary['status'] = "200"; 
					$ary['data'] = $data;   
					echo  json_encode($ary);  
					die;      
				}
			}else
			{
				$ary['message'] = "Success";
				$ary['status'] = "200";
				$ary['data'] = $data;   
				echo  json_encode($ary);  
				die;   
			}
		} 
	 
		if(isset($_POST['find_service']))
		{       
  
  			if($_POST['category_id'] || $_POST['category_id']!='') 
					$category_id = $_POST['category_id']; 
				else
					$category_id = 0;
				
			mysql_query("insert into views (city_id,post_id,cateory_id) values($_POST[city_id],2,$category_id) ");       
			$tabel_name = "city_tabel_".$_POST['city_id'];    
			if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tabel_name."'"))==1) 
			{     
				
				if($_POST['location_id'] || $_POST['location_id']!='') 
					$location_id = " location_id IN ( ".$_POST['location_id']." ) and" ;   
				else
					$location_id = ""; 
				
				if($_POST['category_id'] || $_POST['category_id']!='') 
					$category_id = " and category_id=".$_POST['category_id']; 
				else
					$category_id = ""; 
				
				if($_POST['sorting_type']==1)  
						$sorting_type = " order by  user_type desc,id desc" ;    
				else
					$sorting_type = " order by user_type desc,id";  
				
				    
				
				$start=0;
				$limit=100;
				$id=1;	
				
				if($_POST['index'])
				{
					$id=$_POST['index'];
					$start=($id-1)*$limit;
				}  
			 
				if($_POST['index'] < 2)
				{
					$rows=mysql_num_rows(mysql_query("select * from $tabel_name where   post_id = 2  $category_id    "));  
					$total=ceil($rows/$limit); 
					
				}
				
				$result= mysql_query("select  id,heading,location_id,posted_date,company,category_id,user_type,service_image,cust_id from $tabel_name where $location_id  post_id = 2   $category_id  $sorting_type    LIMIT $start, $limit "); 
				 
				$key=0;
				while($row = mysql_fetch_object($result))
				{     
					$location_id_R = mysql_query("select  location_name from city_lacations where id = $row->location_id ");
					$location_id = mysql_fetch_object($location_id_R);
					
					if($location_id->location_name=='') 
						$find_job['locality'] = "Whole City";
					else 
						$find_job['locality'] = $location_id->location_name;   
					
					$find_job['id'] = $row->id; 
					$find_job['heading'] = $row->heading;  
					
					$jb_name_R = mysql_query("select  name from service_categories where id = $row->category_id");
					$jb_name = mysql_fetch_object($jb_name_R);  
					$find_job['role'] = $jb_name->name;  
					$find_job['posted_by'] = $row->company;      
					
					$posted_date = get_date_difer($row->posted_date);
					$find_job['posted_date'] = $posted_date;      
					$find_job['paid_type'] = $row->user_type;
					$find_job['city_id'] = $_POST['city_id'];
					
					if($row->service_image!='')					
						$find_job['service_image'] = ROOTPATH.'/uploads/'.$row->cust_id.'/service-pic/'.$row->service_image;
					else
						$find_job['service_image'] = ROOTPATH.'/uploads/mail-images/service_image.jpg';
					
					$data[$key]  = (object) $find_job;  
					$key++;
				}      
				
				$ary['count'] = $key;   
				$items = Array('NHCTTD123_2.jpg');    
				$ary['adv_img'] = ROOTPATH.'/uploads/temp-ads/'.$items[array_rand($items)];	  
				$ary['message'] = "Success";
				$ary['status'] = "200";
				$ary['total'] = $total;
				$ary['data'] = $data;   
				echo  json_encode($ary);  
				die;      
				 
			}else
			{
				$ary['message'] = "Success";
				$ary['status'] = "200";
				$ary['data'] = $data;   
				echo  json_encode($ary);  
				die;   
			}
		} 
		  
		
		if(isset($_POST['job_details']))
		{      
			$tabel_name = "city_tabel_".$_POST['city_id'];        
			$rst = mysql_query("select name from all_cities where id = $_POST[city_id]");
			$service = mysql_fetch_row($rst);
			$city_name = $service[0]; 
			
			mysql_query("update  $tabel_name set add_view=add_view+1 where id=$_POST[job_id]  ");      
			$result= mysql_query("select * from $tabel_name where  id=$_POST[job_id]  ");   
			$row = mysql_fetch_object($result);
			$data['post_id'] = $row->post_id;  
			if($row->post_id ==2)
			{
				 
				
				$rst = mysql_query("select name from service_categories where id = $row->category_id ");
				$service = mysql_fetch_row($rst);
				$data['heading']  = $service[0];
				    
				$jb_name_R = mysql_query("select  name from service_categories where id = $row->category_id ");
				$jb_name = mysql_fetch_object($jb_name_R);
				$data['service_categories'] = $jb_name->name; 
				
				if( $row->sub_category_id!=0)
				$jb_name_R = mysql_query("select  name from sub_service_categories where id = $row->sub_category_id ");
				$jb_name = mysql_fetch_object($jb_name_R);
				
				if($jb_name->name!='') 
					$data['service_sub_categories'] = $jb_name->name;    
				else
					$data['service_sub_categories'] = "Not Available";    
				
				
			}
			else 
			{				
				$data['heading'] = $row->heading;     
				$jb_name_R = mysql_query("select  name from job_categories where id = $row->category_id ");
				$jb_name = mysql_fetch_object($jb_name_R);
				$data['role'] = $jb_name->name;  
				$data['min_salary'] = $row->min_salary;    
				$data['max_salary'] = $row->max_salary;
			}
			
			
			$location_id_R = mysql_query("select  location_name from city_lacations where id = $row->location_id ");
			$location_id = mysql_fetch_object($location_id_R);
			if($location_id->location_name=='') 
				$data['locality'] = $city_name." ( Whole City )";
			else
				$data['locality'] = $location_id->location_name.', '.$city_name; 
			
			    
			$data['company'] = $row->company;    
			$data['description'] = $row->description;    

			$posted_date = get_date_difer($row->posted_date);
			$data['posted_date'] = $posted_date;    
			$data['add_view'] = $row->add_view;    
			$data['applidJob'] = 1; 
			
			if($row->privacy==0)
			{
				$display_mobile_result = mysql_query("select display_mobile from users where   ph='$row->contact_mobile' ");
				$display_mobile = mysql_fetch_object($display_mobile_result);
				
				if($display_mobile->display_mobile=='')  
					$data['contact_mobile'] = $row->contact_mobile;   
				else
					$data['contact_mobile'] = $display_mobile->display_mobile;   
			}
			else			 
				$data['contact_mobile'] = "Not Displayed"; 
			 
			$data['adv_img'] = "https://www.meerindia.com/my-local-app/ws/seekers.jpg"; 
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;
		}	
		
		if(isset($_POST['applay_job']))
		{        
			$abcd = json_encode($_POST); 
			mysql_query("insert into test (name) values('$abcd') ");      
			
			/*
			
			$city = "city_tabel_".$_POST['city_id'];
			$result = mysql_query("select  t1.email,t1.name from  $city as t1 inner join user as t2 on t1.cust_id  = t2.cust_id where t1.cust_id  ");
				$category_id  = mysql_fetch_object($result);   
			
			$result = mysql_query("select email,name from users where cust_id = '$_POST[city_id]'");
			$email  = mysql_fetch_object($result); 
			
			if($email->email!='')
			{  
				$result = mysql_query("select name from all_cities where id =  $_POST[city_id] ");
					$city_id  = mysql_fetch_object($result);
			
				$city = "city_tabel_".$_POST['city_id'];
				$result = mysql_query("select category_id from $city where id =  $_POST[job_id] ");
					$category_id  = mysql_fetch_object($result); 
				
				$result = mysql_query("select name from job_categories  where id =  $category_id->category_id ");
					$category_name  = mysql_fetch_object($result);   
			   	
				if($_POST['location_id'])
				{
					$result = mysql_query("select location_name from city_lacations  where id =  $_POST[location_id] ");
						$location_id  = mysql_fetch_object($result);  
						$location_name = " , ".$location_id->location_name;
				}else
					$location_name = "";
				
				 
				$msg = "For ".$category_name ->name." , From ".$city_id->name." ".$location_name; 
				$employyer_name = $email->name;
				
				job_apply_calling($email->email,$employyer_name,$msg);  
			
			}*/
			
			
			/*
				$_POST['city_id'];
				$_POST['job_id'];
				$_POST['custom_id'];   
				$_POST['name'];
				$_POST['mobile'];
				$_POST['email'];
				$_POST['city_id'];
				$_POST['location_id'];     
			*/     

			$data['job_applay'] = 1;  
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;
		}
		 
		if(isset($_POST['del_job']))
		{      
		
			$job_tabel = "city_tabel_".$_POST['city_id'];   
			mysql_query(" delete from  $job_tabel   where id= $_POST[job_id]  ");          
			$ct_result = mysql_query("select  cust_id  from  $job_tabel  where cust_id='$_POST[cust_id]' ");  
			$del_count = mysql_num_rows($ct_result); 
			if($del_count < 1)
			{
				$result = mysql_query("select user_jobs from users where cust_id='$_POST[cust_id]' ");
				$user_alerts = mysql_fetch_row($result);    
				$test_array = explode(",",$user_alerts[0]);  
				$key = array_search($_POST['city_id'],$test_array); 
				unset($test_array[$key]);   
				$str = implode(",",$test_array);  
				mysql_query("update users set user_jobs= '$str' where cust_id='$_POST[cust_id]' ");  
			}
			
			$data['alert_update'] = 'Alert Updated';  
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;   
		}  
		
		
		
		
		if(isset($_POST['send_edit_job']))
		{
			$posted_date =  date('Y-m-d H:i:s');
			$job_tabel = "city_tabel_".$_POST['city_id'];   
			mysql_query("update  $job_tabel set location_id=$_POST[location_id] , heading = '$_POST[heading]', max_salary ='$_POST[max_salary]' ,  min_salary ='$_POST[min_salary]' , description = '$_POST[description]' , expr = $_POST[expr], company = '$_POST[company]' , privacy=$_POST[privacy], posted_date='$posted_date'  where id= $_POST[job_id]  ");   
			$data['alert_update'] = 'Alert Updated';  
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;   
		}
		
		 
		if(isset($_POST['get_edit_job']))
		{
			$job_tabel = "city_tabel_".$_POST['city_id'];      
			$result = mysql_query("select *  from $job_tabel  where id= $_POST[job_id]  "); 
			$row = mysql_fetch_object($result);
			
			$data['type'] = $row ->type;
			$data['post_id'] = $row ->post_id;
			
	
			if($row->post_id == 2)
			{  
				
				$rst = mysql_query("select name from service_categories where id = $row->category_id ");
				$service = mysql_fetch_row($rst);
				$data['heading']  = $service[0];
				
				$jb_name_R = mysql_query("select  name from service_categories where id = $row->category_id ");
				$jb_name = mysql_fetch_object($jb_name_R);
				$data['service_categories'] = $jb_name->name; 
				
				if( $row->sub_category_id!=0)
				$jb_name_R = mysql_query("select  name from sub_service_categories where id = $row->sub_category_id ");
				$jb_name = mysql_fetch_object($jb_name_R);
				$data['service_sub_categories'] = $jb_name->name;  
				
			}
			else
			{
				$data['heading'] = $row->heading;
				$data['min_salary'] = $row->min_salary;  
				$data['max_salary'] = $row->max_salary; 
			}
			
			$data['company'] = $row ->company;    
			$data['location_id'] = $row->location_id;   
			$data['category_id'] = $row->category_id;    
			$data['expr'] = $row->expr;  
			$data['description'] = $row->description;  
			$data['contact_email'] = $row->contact_email;  
			$data['contact_mobile'] = $row->contact_mobile;    
			
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;   
		}  
		
		/*************** JOB SECTION  END************************/
		
		
		/*************** ALERT SECTION ************************/     
		
		if(isset($_POST['create_alart']))
		{       
			$tabel_name = "alert_tabel_".$_POST['city_id'];    
			$posted_date =  date('Y-m-d');   
 
			$Nm = mysql_fetch_object(mysql_query("select email,name from users where  cust_id='$_POST[cust_id]' "));
			$name  = $Nm->name;
			$email = $Nm->email; 
			
			$Nm = mysql_fetch_object(mysql_query("select name from users where  cust_id='$_POST[cust_id]' "));
			$name  = $Nm->name;
			
			if($_POST['type']==1)
				$jtype = 'Work From Home';
			else if($_POST['type']==2)
				$jtype = 'Part Time';
			else if($_POST['type']==3)
				$jtype = 'Full Time';
			else if($_POST['type']==4)
				$jtype = 'Internships';  
			
			$Nm = mysql_fetch_object(mysql_query("select name from all_cities where  id=$_POST[city_id] "));
			$city_name = $Nm->name; 
			
			$Nm = mysql_fetch_object(mysql_query("select name from job_categories where  id=$_POST[category_id] "));
			$catgory_name  = $Nm->name; 
			
			if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tabel_name."'"))==1) 
			{        
				 
				$ct_tbl = mysql_query("select * from  $tabel_name where category_id = $_POST[category_id] and cust_id='$_POST[cust_id]' ");
				if($tbl_count = mysql_num_rows($ct_tbl) > 4) 
				{
					$data['alert_created'] = 2;
				}else
				{ 
					$ct_tbl = mysql_query("select * from  $tabel_name where type=$_POST[type] and alert_for = $_POST[alert_for] and category_id = $_POST[category_id] and location_id='$_POST[location_id]' and cust_id='$_POST[cust_id]' "); 
					if($tbl_count = mysql_num_rows($ct_tbl) > 0)    
						$data['alert_created'] = 3;    
					else 
					{  
						mysql_query("insert into $tabel_name   (type,alert_for,category_id,location_id,cust_id,posted_date) values  ($_POST[type],$_POST[alert_for],$_POST[category_id],'$_POST[location_id]','$_POST[cust_id]','$posted_date') ");    
						$data['alert_created'] = 1; 
					} 
				}
				
			}else
			{   
				mysql_query("CREATE TABLE $tabel_name ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, posted_date varchar(200) NOT NULL, type tinyint(1) NOT NULL COMMENT 'work from home => 1 part time => 2 full time => 3 internship job => 4', alert_for int(11) NOT NULL,category_id int(11) NOT NULL,location_id varchar(200) NOT NULL, cust_id varchar(200) NOT NULL)  ");
				
				mysql_query("insert into $tabel_name   (type,alert_for,category_id,location_id,cust_id,posted_date) values  ($_POST[type],$_POST[alert_for],$_POST[category_id],'$_POST[location_id]','$_POST[cust_id]','$posted_date') ");        
				$data['alert_created'] = 1; 
			}   
			
			$user_alerts_query = mysql_query("select user_alerts   from users where cust_id='$_POST[cust_id]' ");
			$user_alerts_ct =  mysql_fetch_row($user_alerts_query);    
			
			$city_id = $_POST['city_id'];
			if (!preg_match('/'.$city_id.'/',$user_alerts_ct[0]))
			{  
				$user_alerts =$user_alerts_ct[0].",".$_POST['city_id']; 
				$user_alerts = trim($user_alerts,",");    
				mysql_query("update users set user_alerts = '$user_alerts' where cust_id='$_POST[cust_id]' ");
			}  	
            
            $to=$email;
            $subject = "Alert created on $SITE_NAME";  
            $attachment=''; 
			creatAlert($to,$subject,$name,$jtype,$catgory_name,$city_name,$loc_name); 
			
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;      
		}   
		 
		
		if(isset($_POST['del_edit_alert']))
		{      
			$alert_tabel = "alert_tabel_".$_POST['city_id'];   
			mysql_query("delete from  $alert_tabel   where id= $_POST[alert_id]  ");   

			$ct_result = mysql_query("select  cust_id  from  $alert_tabel  where cust_id='$_POST[cust_id]' ");   
			$del_count = mysql_num_rows($ct_result); 
			if($del_count < 1)  
			{	  
				$result = mysql_query("select user_alerts from users where cust_id='$_POST[cust_id]' ");
				$user_alerts = mysql_fetch_row($result);    
				$test_array = explode(",",$user_alerts[0]);  
				$key = array_search($_POST['city_id'],$test_array); 
				unset($test_array[$key]);   
				$str = implode(",",$test_array);  
				mysql_query("update users set user_alerts= '$str' where cust_id='$_POST[cust_id]' ");   
			} 
			$data['alert_update'] = 'Alert Updated';  
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;   
		}
		 
		if(isset($_POST['view_edit_alert']))
		{
			$alert_tabel = "alert_tabel_".$_POST['city_id'];    
			$result = mysql_query("select *  from $alert_tabel  where id= $_POST[alert_id]  "); 
			$row = mysql_fetch_object($result);
			$data['id'] = $row ->id;
			$data['type'] = $row ->type;
			$data['alert_for'] = $row ->alert_for;   
			
			$posted_date = get_date_difer($row->posted_date);
			$find_job['posted_date'] = $posted_date;
			$data['category_id'] = $row->category_id; 
			$data['location_id'] = $row->location_id;  
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;  
			
		}
		
		
		
		
		if(isset($_POST['send_edit_alert']))
		{
			$alert_tabel = "alert_tabel_".$_POST['city_id'];   
			mysql_query(" update  $alert_tabel set location_id='$_POST[location_id]'  where id= $_POST[alert_id]  ");   
			$data['alert_update'] = 'Alert Updated';  
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;   
		}
		
		 
		if(isset($_POST['get_edit_alert']))
		{
			$alert_tabel = "alert_tabel_".$_POST['city_id'];    
			$result = mysql_query("select *  from $alert_tabel  where id= $_POST[alert_id]  "); 
			$row = mysql_fetch_object($result);
			$data['type'] = $row ->type;
			$data['alert_for'] = $row ->alert_for;   
			$data['posted_date'] = $row->posted_date; 
			$data['category_id'] = $row->category_id; 
			$data['location_id'] = $row->location_id;  
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data;   
			echo  json_encode($ary);  
			die;  
			
		}    
		
		///***************** Service ********************////////
		
		if(isset($_POST['post_service']))
		{      
			if($_POST['location_id'])
				$location_id = $_POST['location_id'];
			else
				$location_id = 0;
			
			if($_POST['sub_category_id'])
				$sub_category_id = $_POST['sub_category_id'];
			else
				$sub_category_id = 0;
			
			$posted_date =  date('Y-m-d H:i:s');
			$tabel_name = "city_tabel_".$_POST['city_id'];   
			
			if($_POST['privacy'])
					$_POST['privacy'] = 1;
			else
				$_POST['privacy'] = 0;  
			
			$result = mysql_query("select user_type from paid_members where cust_id ='$_POST[cust_id]' and post_id = $_POST[post_id] and category_id = $_POST[category_id] and city_id = $_POST[city_id] ");
			$user_type_ary = mysql_fetch_row($result);
			
			if( (empty($user_type_ary)) || ($user_type_ary==null) )
				$user_type = 0;
			else
				$user_type = $user_type_ary[0];  
			
				
			if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tabel_name."'"))==1) 
			{      
				mysql_query("insert into $tabel_name   (category_id,sub_category_id,description,location_id,contact_email,contact_mobile,cust_id,posted_date,company,privacy,post_id,user_type) values  ($_POST[category_id],$sub_category_id,'$_POST[description]',$location_id,'$_POST[contact_email]','$_POST[contact_mobile]','$_POST[cust_id]','$posted_date','$_POST[company]',$_POST[privacy],$_POST[post_id],$user_type) ");    
			}
			else 
			{     
				mysql_query("CREATE TABLE $tabel_name ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, posted_date varchar(200) NOT NULL, company varchar(200) NOT NULL, type tinyint(1) NOT NULL COMMENT 'work from home => 1 part time => 2 full time => 3 internship job => 4', heading text NOT NULL, category_id int(11) NOT NULL,   sub_category_id int(11) NOT NULL,  min_salary varchar(200) NOT NULL,  max_salary varchar(200) NOT NULL,  expr int(11) NOT NULL,  description text NOT NULL, location_id int(11) NOT NULL,  contact_email varchar(200) NOT NULL,  contact_mobile varchar(200) NOT NULL,  cust_id varchar(200) NOT NULL,add_view int(11) NOT NULL,privacy int(11) NOT NULL,post_id int(11) NOT NULL,user_type tinyint(1) NOT NULL,service_image varchar(200) NOT NULL)  "); 
				
				mysql_query("insert into $tabel_name   (category_id,sub_category_id,description,location_id,contact_email,contact_mobile,cust_id,posted_date,company,privacy,post_id,user_type) values  ($_POST[category_id],$sub_category_id,'$_POST[description]',$location_id,'$_POST[contact_email]','$_POST[contact_mobile]','$_POST[cust_id]','$posted_date','$_POST[company]',$_POST[privacy],$_POST[post_id],$user_type) ");        
				
			}   
			
			$last_id = mysql_insert_id(); 
			$user_job_query = mysql_query("select user_jobs  from users where cust_id='$_POST[cust_id]' ");
			$user_job_ct =  mysql_fetch_row($user_job_query);    
			mysql_query("update users set post_added = post_added+1 where cust_id='$_POST[cust_id]' "); 
			$city_id = $_POST['city_id'];
			if (!preg_match('/'.$city_id.'/',$user_job_ct[0]))
			{  
				$user_jobs =$user_job_ct[0].",".$_POST['city_id']; 
				$user_jobs = trim($user_jobs,",");  
				mysql_query("update users set user_jobs = '$user_jobs' where cust_id='$_POST[cust_id]' ");
			}        
			
			if($_FILES['service_pic']['name'])
			{     
				$cust_id = $_POST['cust_id'];   
				$path  = ABS_PATH.'/uploads/'.$cust_id;
				if (!file_exists($path))
					mkdir($path,0777);			  
				
				$path  = ABS_PATH.'/uploads/'.$cust_id.'/service-pic';  	
				if (!file_exists($path))   
					mkdir($path,0777);  
					
				 
				$filename = strtoupper( substr(md5(time()),0,16)); 	
				$RD = explode(".",$_FILES['service_pic']['name']);			
				$target_file = $path.'/'.$filename.'.'.end($RD); 
				$Fname = $filename.'.'.end($RD); 
				move_uploaded_file($_FILES['service_pic']['tmp_name'],$target_file);           
				mysql_query("update $tabel_name set service_image = '$Fname' where id= $last_id ");
			} 
			$data['service_creadted'] = 1; 
			$ary['message'] = "Success";
			$ary['status'] = "200";
			$ary['data'] = $data; 
			echo json_encode($ary);   
			die; 
		}           
		/******************** 	END ALERT ************************/  
?>