<!DOCTYPE html> 
<html lang="en"> 

<head>
<?php ob_start(); ?>
<?php   require_once 'head_link.php'; ?> 

</head>

<body> 

<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

  // Ensure that the necessary variables are set
  if (isset($_POST['smssend'])) {
    
    $Number = $_POST['StuId'];
    $Text = $_POST['Text'];  

    $Message = "$Text";

    // Initialize curl
    $curl = curl_init();

    // Set the necessary curl options
     curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://api.sms.net.bd/sendsms',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_POSTFIELDS => http_build_query(array('api_key' => 'LvpiximdpLedV8UDt5TCZvrY090wBCUeZg6J7j62', 'msg' => $Message, 'to' => $Number)),
    ));

    // Execute curl request
    $response = curl_exec($curl);

    // Check for errors
    if ($response === false) {
      echo '<script>alert("Error: ' . curl_error($curl) . '")</script>';
    } else {
      // Close curl
      curl_close($curl);

      echo '<script>alert("SMS sent successfully."); window.location.href=("student-wise-sms");</script>';
      exit;
    }
  } else {
    echo '<script>alert("Error: Required fields are missing.")</script>';
  }
}

?>
 
<?php   require_once 'header1.php'; ?> 

<?php  require_once 'sidebar.php'; ?>


  <main id="main" class="main">

    <div class="pagetitle bg-light rounded p-2">
      <h1><i class="bi bi-person-bounding-box"></i>  Student Wise SMS <i class="bi bi-chat-left-dots"></i></h1>
       
    </div> 

<section class="section">
      <div class="row">
	  
        <div class="col-lg-6">

          <div class="card">
            <div class="card-body p-5">
				
				<form class="form-horizontal" enctype="multipart/form-data" method="post">
				
				<div class="row mb-3 mt-5">
                  <label for="CustId1" class="col-sm-3 control-label">Student Name</label>
                  <div class="col-sm-9">
        <select style="width:100%;" class="form-control chosen-select" Id="StuId" name="StuId" >
							<option value="#">Select Student</option>

							<?php
							$sql = "SELECT contact_info,customer_name,batch_name FROM customer 
							left join batch on batch.id = customer.batch_no
							where member_id='".$_SESSION['id']."'  order by customer_id desc ";
							$result = $con->query($sql);

							while ($row = $result->fetch_array()) {
								echo "<option value='" . $row[0] . "'>" . $row[1] . " - " . $row[1] . " - " . $row[0] . "</option>";
							}
							?>
						</select> 
				  </div>
                </div>
			    
				<div class="row mb-3">
                  <label for="Text" class="col-sm-3 col-form-label">Text / SMS </label>
                  <div class="col-sm-9">
				   <textarea class="form-control" id="Text" name="Text"   rows="5"></textarea> 
                  </div>
                </div>
				  
				  <div class="text-center mt-5">
				  <button type="submit" name="smssend" class="btn btn-primary">  Send SMS <i class="bi bi-send"></i></button>
                  </div>
				  
				  
				</form>

		
			</div>
          </div>

        </div>

	
	
	  
	  </div>
    </section>

 
	
	 </main>
	
 

<?php  require_once 'footer1.php'; ?>


<script src="custom/js/report.js"></script>
<script src = "js/chosen.js"></script>
<script type = "text/javascript">
	$('.chosen-select').chosen({width: "100%"});
</script>
 