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


if (isset($_POST['pta_tea_sms'])) {
  $sms = $_POST['msg'];
  print_r($_POST);
 
$get_all_staff = $profile->get_all_staff();

$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 ($get_all_staff as $staff) {
try {
    // Send a quick message
    
    
    $phone = $staff['phone'];
    $phone = substr($phone, 1,9);
    
    $messageResponse = $messagingApi->sendQuickMessage("OTSHS", "+233".$phone."", $sms);
    
    if ($messageResponse instanceof MessageResponse) {
        if ($messageResponse->getStatus()==0) {
         echo $staff['first_name']." Notified successfully <br>";
        }
    } elseif ($messageResponse instanceof HttpResponse) {
      if ($messageResponse->getStatus()==502) {
        echo $staff['staff_name']." Phone Not Found! <br>";
      }
        
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}
}
}