<?php

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

$zdb = $_SESSION["zdbyear_" . $dbname];
$admin = $_SESSION["admin_" . $dbname];
mysqli_select_db($conn, $zdb);
$tourcode = $_SESSION['tourcode'];
$tourcond = "AND tourno = '$tourcode'";
$success = false;
$compcd = $_SESSION["comp_" . $dbname];

if (isset($_REQUEST['regnno'])) {
    $regnno = $_REQUEST['regnno'];
    $recpagnst = $_REQUEST['recpagnst'];

    if ($recpagnst != "F") {
        $getm = mysqli_query($conn, "SELECT haji, surname,agent FROM bookform WHERE `regnno`='$regnno' $tourcond") or die(mysqli_error($conn));
        $fetm = mysqli_fetch_array($getm);

        $fname = $fetm["haji"] . " " . $fetm["surname"];
        if ($compcd != 51) {
            if ($fetm['agent']) {
                $fname = $fetm['agent'];
                $prnme = $fetm["haji"] . " " . $fetm["surname"];
            }
        }


        if ($fname != " ") {
            $getname = mysqli_query($conn, "SELECT `accode` FROM accmast WHERE `name` = '$fname' ") or die(mysqli_error($conn));
            $fetname = mysqli_fetch_array($getname);
            $accode = $fetname['accode'];
        }


    } else {
        $getm = mysqli_query($conn, "SELECT surname,name,midname,agent,mobile FROM pax WHERE `vouchno`='$regnno' ") or die(mysqli_error($conn));
        $fetm = mysqli_fetch_array($getm);
        $fname = $fetm["surname"] . ' ' . $fetm["name"] . ' ' . $fetm["midname"];
        $fmobile = $fetm["mobile"];
        if ($fetm['agent'] > 0) {
            $accode = $fetm["agent"];
        } else {
            $getname = mysqli_query($conn, "SELECT `accode` FROM accmast WHERE `name` = '$fname' AND `mobile`='$fmobile' ") or die(mysqli_error($conn));
            $fetname = mysqli_fetch_array($getname);
            $accode = $fetname['accode'];
        }

    }

    $rows = array();
    $ctr = 0;
    $rows = array(
        'success' => true,
        'prname' => "$prnme",
        'accode' => "$accode"
    );
    header("Content-type: application\json");
    echo json_encode($rows);
}