<?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` WHERE code ='$compcd'") 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->pname;
$mpcmpname = $fetcmpname->name;
//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'];
    $vouchdt = $_REQUEST['vouchdt'];



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


$mobnum = '9222111555,9892372200,9167531562,8108364186';//    $mobnum = '9320094672';

    $msgtech = 'Request From  Company' . $mpcmpname . "( " . $mcmpname . " ) " . " By Staff  " . $username . " To Delete Bill No. " . $vouchno . " to Delete the Bill Enter this OTP " . $pass;


    $user = "BENHUR";
    $password = "BENHUR2017";
    $senderid = "BENHUR";
//    $url = "144.76.39.175/api.php?";
    $url = "http://vas.mobilogi.com/api.php?";




    $mobilenumbers = $mobnum;

    $messagetech = urlencode($msgtech);

    $chtech = curl_init();
    if (!$chtech) {
        die("Couldn't initialize a cURL handle");
    }
    $rettech = curl_setopt($chtech, CURLOPT_URL, $url);
    curl_setopt($chtech, CURLOPT_POST, 1);
    curl_setopt($chtech, CURLOPT_POSTFIELDS, "username=$user&password=$password&route=1&sender=$senderid&mobile[]=$mobilenumbers&message[]=$messagetech");

    $rettech = curl_setopt($chtech, CURLOPT_RETURNTRANSFER, true);

    $curlresponsetech = curl_exec($chtech);
    if (curl_errno($chtech)) {
//        echo 'curl error : ' . curl_error($chtech);
    }
    if (empty($rettech)) {

        die(curl_error($chtech));
        curl_close($chtech);
    } else {
        $infotech = curl_getinfo($chtech);
        curl_close($chtech);

//        echo $curlresponsetech;
    }


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