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

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$zroot = $_SESSION["zdbroot"];
$success = false;

if (isset($_REQUEST["tour"])) {
    $tour = $_REQUEST["tour"];

    $gen1 = mysqli_query($conn, "SELECT regnno AS maxreg FROM `tourquot` WHERE  regnno != '' AND tourno = '$tour' order by regnno desc LIMIT 0,1 ") or die(mysqli_error($conn));
    if (mysqli_num_rows($gen1) > 0) {
        $vvouch = mysqli_fetch_assoc($gen1);
        $rvouch = $vvouch["maxreg"] + 1;
    } else {
        $gen11 = mysqli_query($conn, "SELECT startreg FROM `tour` WHERE code = '$tour' ") or die(mysqli_error($conn));
        if (mysqli_num_rows($gen11) > 0) {
            $fet11 = mysqli_fetch_array($gen11);
            $rvouch = $fet11['startreg'];
        } else {
            $rvouch = '1';
        }
    }

    $rows = array('success' => true,
           'regvouch' => "$rvouch");

    header("Content-type: application\json");
    echo json_encode($rows);
}
?>

