<?php
ini_set('display_errors', 0);


include_once("../inc/db_config.php");


date_default_timezone_set('Asia/Dhaka');

$today=date('Y-m-d');
$notification_date=date('Y-m-d', strtotime($today. ' + 1 days'));

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='sms_api' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
$sms_api = $settingsSQL->value;


$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='pr_no' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
$pr_no = $settingsSQL->value;

$sqlT = "SELECT t1.*,t2.cell_1,t2.cell_2,t2.booking_name FROM `pr_meetings` as t1 left join bookings as t2 on t1.temp_id=t2.id left join events as t3 on t1.temp_id=t3.temp_id where t1.date='$notification_date' AND t1.status!='checked' AND t3.pr='checked' ";
$sqlT = mysqli_query($connection, $sqlT);
while ($list = mysqli_fetch_object($sqlT)) {
 $temp_id = $list->temp_id;
 $meeting_date = $list->date;
 $meeting_date = date('d/m/Y', strtotime($meeting_date));
 $meeting_time = $list->time;
 $meeting_time = date('h:i a', strtotime($meeting_time));
 $diary_of= $list->booking_name;
 $cell_1= $list->cell_1;  $cell_1 = '880' . substr(preg_replace('/\D/', '',  $cell_1), -10);
 $cell_2= $list->cell_2;  $cell_2 = '880' . substr(preg_replace('/\D/', '',  $cell_2), -10);

 $sms_for_client="Hi, this is just a friendly reminder for your appointment with Prito Reza.
Date:".$meeting_date."
Time:".$meeting_time."
Place: Wedding Diary Office
Thanks";

 $sms_for_client=urlencode($sms_for_client);
 
 $sms_for_pr="Hi, this is just a friendly reminder for you, tomorrow you have an appointment with wedding Client at (".$meeting_time."),
 Thanks"; 
 
 $sms_for_pr=urlencode($sms_for_pr);
 
 $fullNumber_cl=$cell_1.",".$cell_2;
 
 $orginal_text = ["%text%", "%number%"];
		  $replace_text = [$sms_for_client, $fullNumber_cl];
		   $curl_url = str_replace($orginal_text, $replace_text, $sms_api);
		    $curl = curl_init();
		  curl_setopt_array($curl, array(
  CURLOPT_CONNECTTIMEOUT => 20,
  CURLOPT_TIMEOUT => 520,
  CURLOPT_RETURNTRANSFER => 1,
 CURLOPT_URL =>$curl_url,
   CURLOPT_USERAGENT =>'jadukor IT Browser'
 ));
 
$resp = curl_exec($curl);
 curl_close($curl);

$orginal_text = ["%text%", "%number%"];
		  $replace_text = [$sms_for_pr, $pr_no];
		   $curl_url = str_replace($orginal_text, $replace_text, $sms_api);
		    $curl = curl_init();
		  curl_setopt_array($curl, array(
   CURLOPT_CONNECTTIMEOUT => 20,
  CURLOPT_TIMEOUT => 520,
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_URL =>$curl_url,
   CURLOPT_USERAGENT =>'jadukor IT Browser'
 ));
 
$resp = curl_exec($curl);
curl_close($curl);

 
 ?>
 <?php echo $meeting_date; ?>&#13;Meeting Time: <?php echo $meeting_time; ?>
&#13;Client: <?php echo $diary_of; ?>
&#13;Client Cell: <?php echo $cell_1; ?>
 &#13;Client Cell: <?php echo $cell_2; ?> 
 &#13;Client Cell: <?php echo  $pr_no; ?> 
 
</br>
 <?php
 
}

//$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='sms_api' ");
//$settingsSQL = mysqli_fetch_object($settingsSQL);
//$sms_api = $settingsSQL->value;


?>