<?php
ini_set('memory_limit', '-1');
error_reporting(1|0|0);
set_time_limit (0) ;
session_start();		
	//	echo '<br/>Normal Timezone => '.date("Y-m-d H:i:s");
		
		if(function_exists('date_default_timezone_set')) {
			date_default_timezone_set("Asia/Kolkata");
		}
		
 
		
		echo '<br/>Asia/Kolkata Timezone => '.date("Y-m-d H:i:s");
		
		$d=date("Y-m-d H:i:s");
		
		require_once('../wp-config.php');
		
		global $wpdb;
		
		$results = $wpdb->get_results( "SELECT * from sms_details where sent_flag='0' and sent_date_time<=('".$d."') and sent_date_time >=date('2023-09-22')
", OBJECT );
		
		echo "<br/>SELECT * from sms_details where sent_flag='0' and sent_date_time<=('".$d."') and sent_date_time >=date('2023-09-22')";
		echo '<pre>';
		print_r(count($results));		
		echo '</pre>';
 
		//include('sms_common.php');
		if(@count($results) >0 ){
			foreach($results  as $key => $smsData){
				
				/* echo '<pre>';
				print_r($smsData);		
				print_r($smsData->code);		
				print_r($smsData->m_code);		
				echo '</pre>'; */


				//$url = "http://103.27.87.89/lsend.php?usr=4217&pwd=g12345&ph=".trim($rows22['mobile_no'])."&sndr=WNBSKT&csndr=WNBSKT&text=".urlencode(str_replace('	','',$rows22['text_message']));
				//sms_jshine_old_only($rows22['m_code'],$rows22['mobile_no'],$rows22['text_message'],0,$sender_id);	

				$sender_id = 'JSHINE';
				$smsSend = send_scheduled_sms($smsData->m_code,$smsData->mobile_no,$smsData->text_message,0,$sender_id);
				echo $smsData->mobile_no.' -- '.$smsSend.'<br/>';
				if($smsSend){
					$updated = $wpdb->update('sms_details', array('sent_flag'=>'1'), array('code'=>$smsData->code));
					//print_r($updated);
				}
			}			
		}

		
		
		function send_scheduled_sms($cust_id,$mobile,$msg,$save=0,$sender_id='jshine')
		{
				$sender_id='jshine'; 
				
				$sms_Mobile = trim($mobile);
				$sms_Msg = urldecode(str_replace('	','',$msg));
			
				if (!empty($sms_Mobile) && !empty($sms_Msg)) {
						
						$encoded_message = urlencode($sms_Msg);
						$remarks_gateway = 'smsdukan';
						
						$url = 'http://sms.smsdukan.in/app/smsapi/index.php?key=465E03BDB6EAF8&campaign=189&routeid=100344&type=text&contacts='.$sms_Mobile.'&senderid='.$sender_id.'&msg='.$encoded_message;
				// 		$url = "http://private.itswhatsapp.com/wapp/api/send?apikey=e710d25b8d0144dbab1df2aac7169772&mobile=" . $sms_Mobile . "&msg=" . $encoded_message;
						
						if (function_exists('curl_init')) {
						   // initialize a new curl resource
						   $ch = curl_init(); 
				
						   // set the url to fetch
						   curl_setopt($ch, CURLOPT_URL, $url);
				
						   // don't give me the headers just the content
						   curl_setopt($ch, CURLOPT_HEADER, 0); 
				
						   // return the value instead of printing the response to browser
						   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
				
						   // use a user agent to mimic a browser
						   //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0'); 
				
						   $content = curl_exec($ch);
echo 'hiiiii <br/>';
						   print_r($content);
				
						   // remember to always close the session and free all resources 
						   curl_close($ch);
						   return true;
						} else {
							return false;
						}
				
				
				
						/* if($save==1){
						   $s = "INSERT INTO sms_details ";
							$s .= "SET mobile_no='".$mobile."'"; 
							$s .= ",m_code='".($cust_id)."'";	
							$s .= ",sender_id='".($sender_id)."'";
							$s .= ",remarks_gateway='".($remarks_gateway)."'";				
							$s .= ",text_message='".mysql_real_escape_string(trim($msg))."'";
							 $s .= ",sent_date_time='".date('Y-m-d H:i:s',time())."'";
							mysql_query($s);
						} */
				 

				}
				
				
								
		}
		

		// REFFERAL CODE AUTOMATED 07723 kantsverma
		/* $s = "update  customer c , customer_booking  SET sponsor_code_policy=sponsor_code   where customer_code =  c.code and sponsor_code_policy=0";
		$r = mysql_query($s);
				
		$sql_nn2 = "SELECT * from view_booking_payment_sp where sponsor_processed='0' and tamt>=10000 ";
		$rc_nn2 = mysql_query($sql_nn2);
		while($rows222 = mysql_fetch_assoc($rc_nn2))
		{
				$s = "SELECT * from customer where  member_code ='".$rows222['sponsor_code_policy']."'  ";
				//echo '<BR/>'.$s;
				$r = mysql_query($s);
				$cc = mysql_fetch_assoc($r);
				
				$s = "SELECT * from customer where  code ='".$rows222['customer_code']."'  ";
				$r = mysql_query($s);
				$cc2 = mysql_fetch_assoc($r);
		
				if($cc['code']>1)
				{
					$s = "INSERT INTO pw_consolidate SET userid='".$cc['code']."',amt='1000',remarks='You have received 1000 promotional wallets for referring ".$cc2['mobile']."', type='RF',date='".date("Y-m-d")."' ";
					mysql_query($s);
				//echo '<BR/>'.$s;
				}
				
				$s = "update customer_booking SET sponsor_processed=1 where code ='".$rows222['policy_code']."'  ";
				$r = mysql_query($s);
				
		}		 */		
?>
<h1>Access Restricted !!</h1>