<?php
require '../dao/Admission.php';
require '../dao/Global.php';
// Let us test the SDK
require './vendor/autoload.php';


if (isset($_POST['pta_sms'])) {
  $form = $_POST['form'];
  $sms = $_POST['msg'];
 $array = array();
$all_class_students = $admission->get_all_students_by_from($form);
foreach ($all_class_students as $key) {
  $get_first_letter = substr($key['class_name'], 0,1);
  if ($get_first_letter =='2') {
    array_push($array, $key['student_id']);
  }
}
$auth = new BasicAuth("rwkelkwk", "giscmswq");

// instance of ApiHost
$apiHost = new ApiHost($auth);

// instance of AccountApi
$accountApi = new AccountApi($apiHost);

// set web console logging to false
$disableConsoleLogging = false;

// Let us try to send some message

$messagingApi = new MessagingApi($apiHost, $disableConsoleLogging);
 foreach ($array as $key => $value) {
try {
    // Send a quick message
    
    
    $guardians = $admission->get_guardian($value);

    $guardian = $guardians[0]['guardian_phone'];
    $messageResponse = $messagingApi->sendQuickMessage("OTSHS", "+233".$guardian."", $sms);
    
    if ($messageResponse instanceof MessageResponse) {
        if ($messageResponse->getStatus()==0) {
         echo $student['student_name']." Parent Notified successfully <br>";
        }
    } elseif ($messageResponse instanceof HttpResponse) {
      if ($messageResponse->getStatus()==502) {
        echo $student['student_name']." Parent not found! <br>";
      }
        
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}
}
}