<?php session_start();
    if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
        include ('../../../scripts/classes.php');
        //Prevent accessing the page withou POST METHOD
        if($_SERVER['REQUEST_METHOD'] != 'POST') exit('This page cannot be accessed directly');
        if ($_SESSION['lang']=="EN"){$lang="EN"; include ('../../../lang/en.php');}elseif ($_SESSION['lang']=="GR"){$lang="GR";include ('../../../lang/gr.php');}else {$lang="EN";include ('../../../en.php');}
        
        $objSmsBalance = SmsApi::GetSmsApiBalance();
        $sms_credits_balance = $objSmsBalance['credit_balance'];
              
        //echo $sms_credits_balance; //debugger
        
        ## Check if has not become zero
        if ($sms_credits_balance != 0){ //1
            //get post values and sanitize
            $phone_number = mysqli_real_escape_string($mysqli, $_POST['phone']);
            $sender_id = mysqli_real_escape_string($mysqli, $_POST['sender']);
            $sms_text = mysqli_real_escape_string($mysqli, $_POST['sms_text']);
            $delivery_datetime = isset($_POST['datetime']) ? mysqli_real_escape_string($mysqli, $_POST['datetime']) : '';  
                                    
            SmsApi::SendSmsApiSingle($phone_number, $sender_id, $sms_text);
            
        }else{
                echo '<div class="critical"><ul><li>'._ZERO_CREDITS_TEXT.'</li></ul></div>';
        }//end 1
} else {
    header('Location: login.php');
}
?>

