<?php

include 'Hubtel/Api.php';

if(isset($_POST['send_sms'])){
    // print_r($_POST);

$em = '';
$id = "";

 $sms = $_POST['sms'];
    $father_no = $_POST['father_no'];
    $father_no = substr($father_no, 1);
    $mother_no = $_POST['mother_no'];
    $mother_no = substr($mother_no, 1);
$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);
try {
//     // Send a quick message
//     $a = 0;
//     for ($i = 0; $i<5; $i++) 
// {
//     $a .= mt_rand(0,9);
// }
    $messageResponse = $messagingApi->sendQuickMessage("OTSHS/OFFICE OF THE HOUSE MASTER", "+233".$father_no."", $sms);

    if ($messageResponse instanceof MessageResponse) {
        // echo $messageResponse->getStatus();
        echo 1;
        // $phone_code->insert(array("code"=>$a,"user_id"=>$id));
    } elseif ($messageResponse instanceof HttpResponse) {
        echo "\nServer Response Status : " . $messageResponse->getStatus();
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}

$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);
try {
//     // Send a quick message
//     $a = 0;
//     for ($i = 0; $i<5; $i++) 
// {
//     $a .= mt_rand(0,9);
// }
    $messageResponse = $messagingApi->sendQuickMessage("OTSHS/OFFICE OF THE HOUSE MASTER", "+233".$mother_no."", $sms);

    if ($messageResponse instanceof MessageResponse) {
        // echo $messageResponse->getStatus();
        echo 1;
        // $phone_code->insert(array("code"=>$a,"user_id"=>$id));
    } elseif ($messageResponse instanceof HttpResponse) {
        echo "\nServer Response Status : " . $messageResponse->getStatus();
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}

}

if(isset($_POST['bulk_sms'])){
    // print_r($_POST);

$em = '';
$id = "";
$form_id = $_POST['form'];
$getAllStudents = $student->get_form($form_id);
if ($getAllStudents) {
    foreach ($getAllStudents as $key) {
 $sms = $_POST['sms'];
 $mother_no = $key['mother_no'];
    $mother_no = substr($mother_no, 1);
$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);
try {
//     // Send a quick message
//     $a = 0;
//     for ($i = 0; $i<5; $i++) 
// {
//     $a .= mt_rand(0,9);
// }
    $messageResponse = $messagingApi->sendQuickMessage("OTSHS/OFFICE OF THE HOUSE MASTER", "+233".$mother_no."", $sms);

    if ($messageResponse instanceof MessageResponse) {
        // echo $messageResponse->getStatus();
        echo 1;
        // $phone_code->insert(array("code"=>$a,"user_id"=>$id));
    } elseif ($messageResponse instanceof HttpResponse) {
        echo "\nServer Response Status : " . $messageResponse->getStatus();
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}

}
}
if ($getStudents) {
    foreach ($getStudents as $key) {
 $sms = $_POST['sms'];
 $father_no = $key['guardian_phone'];
    $father_no = substr($father_no, 1);
$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);
try {
//     // Send a quick message
//     $a = 0;
//     for ($i = 0; $i<5; $i++) 
// {
//     $a .= mt_rand(0,9);
// }
    $messageResponse = $messagingApi->sendQuickMessage("OTSHS/OFFICE OF THE HOUSE MASTER", "+233".$father_no."", $sms);

    if ($messageResponse instanceof MessageResponse) {
        // echo $messageResponse->getStatus();
        echo 1;
        // $phone_code->insert(array("code"=>$a,"user_id"=>$id));
    } elseif ($messageResponse instanceof HttpResponse) {
        echo "\nServer Response Status : " . $messageResponse->getStatus();
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}

}
}

}