<? include "top.php"; ?>
<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
	<title>Bill List</title>
	<link rel="stylesheet" type="text/css" href="src/plugins/datatables/media/css/jquery.dataTables.css">
	<link rel="stylesheet" type="text/css" href="src/plugins/datatables/media/css/dataTables.bootstrap4.css">
	<link rel="stylesheet" type="text/css" href="src/plugins/datatables/media/css/responsive.dataTables.css">
	<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
	<style>
/* Pagination with Rounded Borders */
.pagination {
  display: inline-block;
}

.pagination a {
  color: black;
  float: left;
  padding: 8px 16px;
  text-decoration: none;
  border: 1px solid #000;
}

.pagination a.active {
  background-color: #4CAF50;
  color: white;
  border: 1px solid #4CAF50;
}

.pagination a:hover:not(.active) {background-color: #fff;color: #000;}

.pagination a:first-child {
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
}

.pagination a:last-child {
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
}

</style>
</head>
<body>
	
	<?php include('include/header.php'); ?>
	<?php include('include/sidebar.php');
	require_once 'lib/audit-log.php';

	$action=$_REQUEST['action'];
	if($action=='delete'){

		$cid=$_REQUEST['cid'];

		$getb=f(q("SELECT * FROM cbill WHERE blid='$cid'"));
		$custid=$getb['bl_cid'];
		if($ltype=='1'){

		$getmaxbill=f(q("SELECT MAX(blid) as maxid FROM cbill WHERE bl_cid='$custid'"));
		$maxid=$getmaxbill['maxid'];

		if($maxid==$cid){

		// Log the delete action before performing it
		$additionalData = array(
			'bill_id' => $cid,
			'customer_id' => $custid,
			'amount' => $getb['bl_amt']
		);
		$actionDetails = "Bill deleted for Customer ID: $custid, Bill Amount: " . $getb['bl_amt'] . ", Month: " . $getb['bl_month'] . " " . $getb['bl_year'];
		logAuditAction('BILL_DELETE', $actionDetails, $additionalData);

		$res=mysqli_query($con,"DELETE FROM cbill WHERE blid='$cid'");
		if($res){

			$delpay1=mysqli_query($con,"DELETE FROM tbl_billpay WHERE pay_bill='$cid'");
			$delpay=mysqli_query($con,"DELETE FROM tbl_trans WHERE trn_billid='$cid'");
		}

		if($res){
			?>		
				 <script type="text/javascript">
	            Swal.fire('Bill Deleted','','success');
	             </script>
			<?	

			}else{?>


			 <script type="text/javascript">
            Swal.fire('Bill cannot be deleted','','error');
             </script>


		<?	}

			}else{ ?>


				 <script type="text/javascript">
	            Swal.fire('This bill cannot be deleted, please delete bills after this bill first','','error');
	             </script>



				// $res=mysqli_query($con,"INSERT INTO tbl_lane SET lnname='$lnname',lnarid='$lnarid'");
		<?	}

			
			}


	}
	
	
	if($action=='deletepay'){

		$cid=$_REQUEST['cid'];

		$getb=f(q("SELECT * FROM cbill WHERE blid='$cid'"));
		$custid=$getb['bl_cid'];
		$afterdeletedue=floatval($getb['bl_amt']);
		if($ltype=='1'){

		$getmaxbill=f(q("SELECT MAX(blid) as maxid FROM cbill WHERE bl_cid='$custid'"));
		$maxid=$getmaxbill['maxid'];

		if($maxid==$cid){

		// Log the payment delete action before performing it
		$additionalData = array(
			'bill_id' => $cid,
			'customer_id' => $custid,
			'amount' => $getb['bl_payamt']
		);
		$actionDetails = "Payment deleted for Customer ID: $custid, Payment Amount: " . $getb['bl_payamt'] . ", Bill Month: " . $getb['bl_month'] . " " . $getb['bl_year'];
		logAuditAction('PAYMENT_DELETE', $actionDetails, $additionalData);


	//	$res=mysqli_query($con,"DELETE FROM cbill WHERE blid='$cid'");
	$res=mysqli_query($con,"UPDATE cbill SET bl_stat=0,bl_payamt=0,bl_disc=0,bl_due='$afterdeletedue' WHERE blid='$cid'");
		if($res){

			$delpay1=mysqli_query($con,"DELETE FROM tbl_billpay WHERE pay_bill='$cid'");
			$delpay=mysqli_query($con,"DELETE FROM tbl_trans WHERE trn_billid='$cid'");
		}

		if($res){
			?>		
				 <script type="text/javascript">
	            Swal.fire('Payment Deleted','','success');
	             </script>
			<?	

			}else{?>


			 <script type="text/javascript">
            Swal.fire('Bill cannot be deleted','','error');
             </script>


		<?	}

			}else{ ?>


				 <script type="text/javascript">
	            Swal.fire('This payment cannot be deleted, please delete payment after this bill first','','error');
	             </script>



				// $res=mysqli_query($con,"INSERT INTO tbl_lane SET lnname='$lnname',lnarid='$lnarid'");
		<?	}

			
			}


	}

	


	?>
	<? include "ajax.php"; 
		

	?>

	 <style type="text/css">
         th{
         font-size: 14px !important;
         }
         td{
         font-size: 12px !important;
         }
      </style>
	
	<div class="main-container">
		<div class="pd-ltr-20 customscroll customscroll-10-p height-100-p xs-pd-20-10">
			<div class="min-height-200px">
				<div class="page-header">
					<div class="row">
						<div class="col-md-6 col-sm-12">
							<div class="title">
								<h4>Bill List</h4>
							</div>
							<nav aria-label="breadcrumb" role="navigation">
								<ol class="breadcrumb">
									<li class="breadcrumb-item"><a href="index.php">Home</a></li>
									<li class="breadcrumb-item active" aria-current="page">Bill List</li>
								</ol>
							</nav>
						</div>
						<div class="col-md-6 col-sm-12 text-right">
							
						</div>
					</div>
				</div>
				<!-- Default Basic Forms Start -->
				
				<div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
					<div class="clearfix mb-20">
						<div class="pull-left">
							<h5 class="text-blue">Bill List</h5>
						</div>
					</div>
					<div class="row">
						<table class="stripe hover multiple-select-row data-table-export nowrap">
							<thead>
								<tr>
									<th class="table-plus datatable-nosort">Bill No</th>
									<th>Date</th>
									<th>Customer</th>
									<th>Area</th>
									<th>Bill Amt</th>
									<th>Amt Paid</th>
									<th>Action</th>
									<th>Whatsapp</th>
									<th>Send SMS</th>
								</tr>
							</thead>
							<tbody>
								<?
									$stdt=$_POST['stdt'];
									$enddt=$_POST['enddt'];
									$allusr=$_POST['logusers'];
									$financial_year=$_POST['financial_year'];
									$page=$_REQUEST['page'];

									if($stdt==''){
									$stdt=$_REQUEST['stdt'];

									}
									if($enddt==''){
										$enddt=$_REQUEST['enddt'];

									}

									if($allusr==''){

										$allusr=$_REQUEST['logusers'];

									}
									
									if($financial_year==''){
										$financial_year=$_REQUEST['financial_year'];
									}


									if($stdt==''){

										$stdt=date("Y-m-d");
										$enddt=date("Y-m-d");
									}
									
									// Build financial year filter
									$fy_filter = '';
									if($financial_year != '' && $financial_year != '0'){
										$fy_filter = " AND bl_financial_year_id='$financial_year'";
									}

									$start_limit = 0;
									$end_limit = 50 ;

									if ($page != '' && floatval($page) > 1)
									{
										$start_limit = ($page - 1) * 50;
										$end_limit=($page)*50;
									}
                

									$csadded=$_SESSION['murgibhai'];
									//echo "SELECT * FROM tbl_login WHERE l_uid='$csadded'";	
									$getlog=f(q("SELECT * FROM tbl_login WHERE l_uid='$csadded'"));
									$ltype=$getlog['l_type'];
									$uidd=$getlog['user_id'];
									$lread=$_SESSION['lread'];
									$comid=$_SESSION['compids'];

									if($lread=='admin'){



									

									if($ltype=='2'){

										$query="SELECT * FROM cbill WHERE bl_user='$getlog[l_uid]' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
										$parrc = f(q("SELECT COUNT(*) AS total FROM `cbill` WHERE bl_user='$getlog[l_uid]' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter"));
									}elseif($ltype=='1'){

										if($allusr=='0'){

											$query="SELECT * FROM cbill WHERE bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
											$parrc = f(q("SELECT COUNT(*) AS total FROM `cbill` WHERE bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter"));
										}else{
											$usrv=md5($allusr);
											$query="SELECT * FROM cbill WHERE bl_usr='$usrv' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
											$parrc = f(q("SELECT COUNT(*) AS total FROM `cbill` WHERE bl_usr='$usrv' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter"));
										}


									}else{

										//$getu=f(q("SELECT * FROM adduser WHERE custid='$getlog[l_read]'"));
										$query="SELECT * FROM cbill WHERE bl_cid='$uidd'  AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
										// $getu=f(q("SELECT * FROM adduser WHERE custid=''"));
									}

								}else{

									if($ltype=='2'){

										$query="SELECT * FROM cbill WHERE bl_user='$getlog[l_uid]' AND bl_com='$comid' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
										$parrc = f(q("SELECT COUNT(*) AS total FROM `cbill` WHERE bl_user='$getlog[l_uid]' AND bl_com='$comid' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter"));
									}elseif($ltype=='1'){

										if($allusr=='0'){

											$query="SELECT * FROM cbill WHERE bl_com='$comid' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
											$parrc = f(q("SELECT COUNT(*) AS total FROM `cbill` WHERE bl_com='$comid' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter"));
										}else{
											$usrv=md5($allusr);
											$query="SELECT * FROM cbill WHERE bl_usr='$usrv' AND bl_com='$comid' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
											$parrc = f(q("SELECT COUNT(*) AS total FROM `cbill` WHERE bl_usr='$usrv' AND bl_com='$comid' AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter"));
										}


									}else{

										//$getu=f(q("SELECT * FROM adduser WHERE custid='$getlog[l_read]'"));
										$query="SELECT * FROM cbill WHERE bl_cid='$uidd' AND bl_com='$comid'  AND bl_dt BETWEEN '$stdt' AND '$enddt' $fy_filter ORDER BY blid DESC LIMIT $start_limit, $end_limit";
										// $getu=f(q("SELECT * FROM adduser WHERE custid=''"));
									}





								}
									//echo $query;


									$getc=mysqli_query($con,$query);
									while($arr=mysqli_fetch_array($getc)){
										//echo "SELECT * FROM tbl_area WHERE arid='$arr[area_id]'";
										$getar=f(q("SELECT * FROM adduser WHERE id='$arr[bl_cid]'"));
										$getarea=f(q("SELECT * FROM tbl_area WHERE arid='$getar[area_id]'"));
										$areaname=$getarea['arname'];





										if($arr['bl_attch']==''){   
                                                            $longurl="https://cable.biswascable.in/getpdf.php?bookids=".$arr['bl_trn'];
                                                            $timestamp = time();
                                                            // actual value: $time = 1628625734
                                                            $signature = md5( $timestamp . '268d2a5320' );
                                                            // actual value: $signature = "1d5710a81760ddf64f2a3d3941002798"
                                                                $username = 'admin';
                                                                $password = 'PaSs_$#@!56';
                                                                //$api_url =  'http://uss.e-marketing.ooo/yourls-api.php?timestamp=$timestamp&signature=$signature';

                                                                $api_url =  'http://uss.e-marketing.ooo/yourls-api.php';

                                                                // Init the CURL session
                                                                $ch = curl_init();
                                                                curl_setopt($ch, CURLOPT_URL, $api_url);
                                                                curl_setopt($ch, CURLOPT_HEADER, 0);            // No header in the result
                                                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
                                                                curl_setopt($ch, CURLOPT_POST, 1);              // This is a POST request
                                                                curl_setopt($ch, CURLOPT_POSTFIELDS, array(     // Data to POST
                                                                        'url' => $longurl,
                                                                        'format'   => 'json',
                                                                        'action'   => 'shorturl',
                                                                        'username' => $username,
                                                                        'password' => $password
                                                                    ));

                                                                // Fetch and return content
                                                                $data = curl_exec($ch);
                                                                curl_close($ch);

// Do something with the result. Here, we echo the long URL
$data = json_decode( $data );
$urls=$data->shorturl;  

$upurl=mysqli_query($con,"UPDATE cbill SET bl_attch='$urls' WHERE blid='$arr[blid]'");

}else{


    $urls=$arr['bl_attch'];
}

                                                            $textval=htmlentities("Your bill amount for the month ".$arr['bl_month']." is Rs.".$arr['bl_amt'].". Download bill from ".$urls);

                                                           


                                                            $wmsg="https://api.whatsapp.com/send?phone=91".$arr['bl_phone']."&text=".$textval;




								?>
								<tr>
									<td class="table-plus"><?=$arr['bl_no']?><br><br>
									<?php if($arr['bl_stat']==1){?> <small style="color:white;padding:5px;background-color: green;border-radius: 5px;">Paid </small> <?php }else{?> <small style="color:white;padding:5px;background-color: red;border-radius: 5px;">Not Paid</small> <?php } ?>
								
								</td>
									<td><?=date("d-m-Y", strtotime($arr['bl_dt']))?></td>
									<td>
										<b><?=$getar['name']?> </b><br>
						                  <? if($getar['is_cable']=='1'){ ?>
						                     <b>VC NO: </b><?=$getar['vc']?><br>
						                     <b>STB NO: </b><?=$getar['stb']?><br>
						                     <b>A/C No: </b><?=$getar['custid']?><br>
											 <b>Phone: </b><?=$getar['phone']?><br>
						                  <?}else{ ?>
						                  
						                     <b>IP: </b><?=$getar['vc']?><br>
						                     <b>Userid: </b><?=$getar['stb']?><br>


						                  <? } ?> 
																


									</td>
									<td><?php echo $areaname?></td>
									<td><?=floatval($arr['bl_amt'])?></td>
									<td><?=$arr['bl_payamt']?></td>
									<td>
										
										<div class="dropdown">
											<a class="btn btn-outline-primary dropdown-toggle" href="#" role="button" data-toggle="dropdown" style="color: black;">
												<i class="fa fa-ellipsis-h"></i>
											</a>
											<div class="dropdown-menu dropdown-menu-right">
												
												<a class="dropdown-item" href="getbills.php?bill_id=<?=$arr['blid']?>" target="_blank"><i class="fa fa-print"></i> Print A4</a>
												<a class="dropdown-item" href="print_bill.php?bill_id=<?=$arr['blid']?>" target="_blank"><i class="fa fa-print"></i> Print A5</a>
												<a class="dropdown-item" href="thermal_print.php?bill_id=<?=$arr['blid']?>" target="_blank"><i class="fa fa-print"></i> Thermal Print</a>
												<? if($ltype=='1'){?><a class="dropdown-item" href="<?=$_SERVER['PHP_SELF']?>?action=delete&cid=<?=$arr['blid']?>" onclick="return confirm('Are you sure you want to delete this item?');"><i class="fa fa-trash"></i> Delete</a>
												<?php if($arr['bl_stat']=='1'){?><a class="dropdown-item" href="<?=$_SERVER['PHP_SELF']?>?action=deletepay&cid=<?=$arr['blid']?>" onclick="return confirm('Are you sure you want to delete this item?');"><i class="fa fa-trash" style="color:red;"></i> Delete Payment</a> <?php } ?>
												<?php if($arr['bl_phone']!='0'){?>
												<a  target="_blank" href="<?php echo $wmsg?>" style="padding:5%;"  title="Whatsapp Report to <?php echo $arr['bl_cname'] ?>"><i class="fa fa-whatsapp" style="color:green;"></i> Whatsapp Bill</a>
											<?php } ?>
											<? } ?>
											<?php if($arr['bl_stat']==0){?>

											<!-- <a class="dropdown-item" href="payonline.php?blid=<?php echo $arr['bl_trn']?>"><i class="fa fa-check"></i> Add </a> -->


											<?php } ?>
											</div>
										</div>
										

									<!-- <a href="getpdf.php?bookids=<?=$arr['bl_trn']?>" target="_blank">Get PDF</a><br>
									<a href="<?=$_SERVER['PHP_SELF']?>?action=delete&cid=<?=$arr['blid']?>" onclick="return confirm('Are you sure you want to delete this item?');">DELETE</a><br> -->
									

									</td>
									<td>
										<?php
											$customerName = urlencode($getar['name']);
											$billAmount = urlencode(floatval($arr['bl_amt']));
											$billMonth = urlencode($arr['bl_month']);
											$predefinedMessage = urlencode("Hello " . $getar['name'] . ", your bill amount for the month " . $arr['bl_month'] . " is Rs." . floatval($arr['bl_amt']) . ". Please pay at your earliest convenience.");
											$waMeLink = "https://wa.me/91" . $arr['bl_phone'] . "?text=" . $predefinedMessage;
										?>
										<?php if($arr['bl_phone']!='0'){?>
											<?php if($arr['bl_stat']==0){?>
											<a target="_blank" href="<?php echo $waMeLink?>" title="Send predefined message to <?php echo $getar['name'] ?>"><i class="fa fa-whatsapp" style="color:green;"></i> Send Message</a>
											<?php }else{ echo "Bill Paid"; } ?>	
										<?php } ?>
									</td>
									<td>
										<?php if($arr['bl_phone']!='0'){?>
											<?php if($arr['bl_stat']==0){?>
											<button type="button" class="btn btn-sm btn-info" onclick="sendAutoSMS('<?php echo $arr['bl_phone']; ?>', 'Hello <?php echo $getar['name']; ?>, your bill amount for the month <?php echo $arr['bl_month']; ?> is Rs.<?php echo floatval($arr['bl_amt']); ?>. Please pay at your earliest convenience.')" title="Send SMS to <?php echo $getar['name']; ?>"><i class="fa fa-envelope"></i> Send SMS</button>
											<?php }else{ echo "Bill Paid"; } ?>	
										<?php } ?>
									</td>
								</tr>
								<? } ?>	
							</tbody>
						</table>
						<div class="col-md-12">
                        <div class="card">
                            <div class="card-body">
                                
                        <?php

                        $total_pages = $parrc['total'];
                        $total_pages = ceil($total_pages / 50);
                        
                        if ($page == "")
                        {
                            $page = 1;
                        }
                        
                        $prev_page = $page - 1;
                        $next_page = $page + 1;                     
                        
                        ?>
                        <p class="pagination">
                            <a href="billlists.php?page=<?php if($page == 1){ echo '1'; }else{ echo $prev_page; } ?>&stdt=<?php echo $stdt?>&enddt=<?php echo $enddt?>&logusers=<?php echo $allusr?>">&laquo;</a>
                        <?php 
                        
                        
                        for ($i = 1; $i <= $total_pages; $i++)
                        {
                            ?>
                            <a href="billlists.php?page=<?php echo  $i ?>&stdt=<?php echo $stdt?>&enddt=<?php echo $enddt?>&logusers=<?php echo $allusr?>" <?php if($page==$i){?> class="active" <?php } ?>><?php echo  $i ?></a>
                            <?php 
                        }
                        ?>
                            <a href="billlists.php?page=<?php if($page == $total_pages){ echo $total_pages; }else{ echo $next_page  ; } ?>&stdt=<?php echo $stdt?>&enddt=<?php echo $enddt?>&logusers=<?php echo $allusr?>">&raquo;</a>
                        </p>
                    


                             </div>
                        </div>
                    </div>
					</div>
				</div>
				

			</div>
			<?php include('include/footer.php'); ?>
		</div>
	</div>
	<?php include('include/script.php'); ?>

	<script src="src/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
	<script src="src/plugins/datatables/media/js/dataTables.bootstrap4.js"></script>
	<script src="src/plugins/datatables/media/js/dataTables.responsive.js"></script>
	<script src="src/plugins/datatables/media/js/responsive.bootstrap4.js"></script>
	<!-- buttons for Export datatable -->
	<script src="src/plugins/datatables/media/js/button/dataTables.buttons.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.bootstrap4.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.print.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.html5.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.flash.js"></script>
	<script src="src/plugins/datatables/media/js/button/pdfmake.min.js"></script>
	<script src="src/plugins/datatables/media/js/button/vfs_fonts.js"></script>
	<script>
		$('document').ready(function(){
			$('.data-table').DataTable({
				scrollCollapse: true,
				autoWidth: false,
				responsive: true,
				columnDefs: [{
					targets: "datatable-nosort",
					orderable: false,
				}],
				"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
				"language": {
					"info": "_START_-_END_ of _TOTAL_ entries",
					searchPlaceholder: "Search"
				},
			});
			$('.data-table-export').DataTable({
				scrollCollapse: true,
				autoWidth: false,
				responsive: true,
				paging: false,
				lengthchange: false,
				searching: true,
				ordering: false,
				columnDefs: [{
					targets: "datatable-nosort",
					orderable: false,
				}],
				"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
				"language": {
					"info": "_START_-_END_ of _TOTAL_ entries",
					searchPlaceholder: "Search"
				},
				dom: 'Bfrtip',
				buttons: [
				'copy', 'csv', 'pdf', 'print'
				]
			});
			var table = $('.select-row').DataTable();
			$('.select-row tbody').on('click', 'tr', function () {
				if ($(this).hasClass('selected')) {
					$(this).removeClass('selected');
				}
				else {
					table.$('tr.selected').removeClass('selected');
					$(this).addClass('selected');
				}
			});
			var multipletable = $('.multiple-select-row').DataTable();
			$('.multiple-select-row tbody').on('click', 'tr', function () {
				$(this).toggleClass('selected');
			});
		});
	</script>
	<script>
		function sendAutoSMS(phone, message) {
			console.log('sendAutoSMS called with phone:', phone, 'and message:', message);
			if (phone && message) {
				// Encode the message for URL safety
				var encodedMsg = btoa(unescape(encodeURIComponent(message)));

				// Make AJAX call to send-sms.php
				$.ajax({
					url: 'send-sms.php',
					type: 'POST',
					data: {
						action: 'sendsms',
						cphone: phone,
						msgs: encodedMsg
					},
					dataType: 'json',
					success: function (response) {
						console.log('SMS sent successfully to', phone);
						alert('SMS Sent');
						if (!response.success) {
							console.error('SMS sending failed:', response.error || 'Unknown error');
						}
					},
					error: function (xhr, status, error) {
						console.error('SMS sending failed:', error);
					}
				});
			} else {
				console.log('sendAutoSMS called but phone or message is missing');
			}
		}
	</script>
</body>
</html>