<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zroot = $_SESSION["zdir"];
$zdb = $_SESSION["zdbyear_" . $dbname];
$compcd = $_SESSION["comp_" . $dbname];
$username = $_SESSION["username_" . $dbname];
//browse($compcd);
$querycomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
//print "SELECT `name` FROM $zroot.`company` WHERE code ='$compcd'";
$fetcmpname = mysqli_fetch_object($querycomp)or die(mysqli_error($conn));
$mcmpname = $fetcmpname->compname;
$mpcmpname = $fetcmpname->compname;
$apikey = $fetcmpname->whatapi;

//browse($mcmpname);
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];

$success = false;

$string = '0123456789';
//$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string_shuffled = str_shuffle($string);
$pass = substr($string_shuffled, 1, 6);


if (isset($_REQUEST["vouchno"])) {
    $vouchno = $_REQUEST['vouchno'];
    $para = $_REQUEST['para'];
    $vouchdt = date("d-m-Y", strtotime($_REQUEST['vouchdt']));
    $var = "";
    if ($para != "") {
        $var = " ( Tax Invoice )";
    }

    $cond = "";
    $rcond = "";
    $qcond = "";


//    $mobnum = '9820768444,9870004442,8108364186,9892372200';
    $mobnum = '8652372200';
//    $mobnum = '8108364186';
    $msgtech = "Request by staff  " . $username . " to edit $var Bill No. " . $vouchno . " Bill Date " . $vouchdt . " Enter this OTP " . $pass;




    $mobilenumbers = $mobnum;

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://app.rapbooster.com/api/sendMsg',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
//        CURLOPT_POSTFIELDS => array('apiAuthkey' => "$apikey", 'receiverMobile' => "971509786865", 'msg' => "$msgtech",
        CURLOPT_POSTFIELDS => array('apiAuthkey' => "$apikey", 'receiverMobile' => "91$mobnum", 'msg' => "$msgtech",
            'file' => '', 'caption' => '', 'fileType' => '', 'mimeType' => ''),
    ));

    $response = curl_exec($curl);
//    print $response;

    curl_close($curl);

//    if ($curlresponsetech != '') {
    $rows = array();
    $ctr = 0;
    $r = mysqli_fetch_assoc($result);
    $rows = array('success' => true);
    header("Content-type: application\json");
    echo json_encode($rows);
    $_SESSION["editotp"] = $pass;
//    }
}