<?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];

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["party"])) {
    $party = $_REQUEST['party'];




    $mobnum = '7718888446';
//    $mobnum = '7718888446';

    $msgtech = 'MSP Req. From ' . $mcmpname . ' ' . $username . "  BN-" . $vouchno .
            " IT " . $mitname . " MRP " . $mmrp . " MSP " . $mmsp . " Qty. " .
            $mrowqty . " RATE " . $mrowrate . " Salesman " . $salename . " OTP " . $pass . "CEPHEI";



//    $user = "ABDRAS";
//    $password = "ABDRAS2017";
//    $senderid = "ABDRAS";
    $user = "CEPHEI";
    $password = "Cephei@2021";
    $senderid = "CEPHEI";
//    $url = "144.76.39.175/api.php?";
    $url = "http://vas.mobilogi.com/api.php?";




    $mobilenumbers = $mobnum;

    $messagetech = urlencode($msgtech);
//    browse($messagetech);
    $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&templateid=1207162322374846347");
    $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);
        $success = true;

//        echo $curlresponsetech;
    }

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