<?php

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

$zroot = $_SESSION["zdir"];
$zdb = $_SESSION["zdbyear_" . $dbname];
$society = $_SESSION["society_" . $dbname];
$username = $_SESSION["username_" . $dbname];
$keycond = "";


$querycomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
$fetcmpname = mysqli_fetch_object($querycomp)or die(mysqli_error($conn));
$mcmpname = mysqli_real_escape_string($conn, $fetcmpname->compname);
$mtel = mysqli_real_escape_string($conn, $fetcmpname->htel);

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

//$success = false;


if (isset($_REQUEST["mobile"])) {
    $mobile1 = $_REQUEST['mobile'];
    $amount = $_REQUEST['amount'];
    $flatno = $_REQUEST['flatno'];
    $para = $_REQUEST["para"];


    if ($para == "M") {
        $mgrpcode = "010";
        $te = "Maintenance";
    } else {
        $te = "Rent";
        $mgrpcode = "042";
    }

    $getparty1 = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `flatno` = '$flatno'");
    $gtpt1 = mysqli_fetch_array($getparty1);
    $bldg  = $gtpt1['wing'];

//    browse($mobile1);
    $mobnum = $mobile1;


//    $mobnum = '7718888446';

    if ($mobnum != '') {

        $msgtech = "Thanks for  payment of Rs $amount towards $te $mcmpname For BLD No. $bldg ROOM NO $flatno.Pl visit www.rapidconstruction.in RAPID RESIDENCY";

        $user = "RAPIDK";
        $password = "RAPIDK2022";
        $senderid = "RAPIDK";
//    $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&templateid=1207165639834439060");

        $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;
        }
        $succ = true;
    } else {
        $succ = false;
    }
    $rows = array();
    $rows = array('success' => $succ);
    header("Content-type: application\json");
    echo json_encode($rows);
//    }
}