<?php

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

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$usertype = $_SESSION["usertype_" . $dbname];
$dtcond = "";
$curdate = date("Y-m-d");
if ($usertype > 2) {
    $dtcond = "min='$curdate' ";
}

if ($_REQUEST["ctr"]) {
    $ctr = $_REQUEST["ctr"];
    $hide = $_REQUEST["hide"];

    $hide_var = "";

    if ($hide == 0) {
        $hide_var = 'style="display:none;"';
    }
    $mctr = $ctr;
    $mctr++;

    echo "<tr>";
    echo "<td style='text-align:center'><i class='fa fa-close remove' ></i></td>";
    echo "<td><input type='text' name='fsrno_$ctr' value='$mctr' class='form-control form'></td>";
    echo "<td><input type='date' $dtcond name='fcheckin_$ctr' value='' class='form-control form fcheckin'></td>";
    echo "<td><input type='date' $dtcond name='fcheckout_$ctr' value='' class='form-control form fcheckout'></td>";
    echo "<td>";
    echo "<select class='form-control form fhotel select2 fetchpart_$ctr' name='fhotel_$ctr' style='width:100%'  required>";
    echo "<option value=''></option>";
    $git = mysqli_query($conn, "SELECT `code`,`hotelnm` FROM `hotels` ORDER BY `hotelnm`") or die(mysqli_error($conn));
    while ($itm = mysqli_fetch_array($git)) {
        echo "<option value='$itm[code]'>$itm[hotelnm]</option>";
    }
    echo "</select>";
    echo "</td>";
    echo "<td>";
    echo "<select class='form-control form fmeal select2' name='fmeal_$ctr' style='width:100%'  >";
    echo "<option value=''></option>";
    $gmeal = mysqli_query($conn, "SELECT `code`,`name` FROM $zroot.`mealtype` ORDER BY `name`") or die(mysqli_error($conn));
    while ($fmeal = mysqli_fetch_array($gmeal)) {
        echo "<option value='$fmeal[code]'>$fmeal[name]</option>";
    }
    echo "</select>";
    echo "</td>";
    echo "<td><input type='number' name='fnonights_$ctr' value='0' class='form-control form fnonights text-right' readonly></td>";
    echo "<td><input type='number' name='fnopax_$ctr' value='0' class='form-control form fnopax text-right'></td>";
    echo "<td><input type='number' name='frate_$ctr' value='0' class='form-control form frate text-right'></td>";
    echo "<td><input type='number' name='famount_$ctr' value='0' class='form-control form famount text-right' readonly>"
    . "<input type='hidden' name='froe_$ctr' value='0' class='form-control form froe text-right'>"
    . "<input type='hidden' name='finramt_$ctr' value='0' class='form-control form finramt text-right'></td>";
    echo "</tr>";
    $ctr++;
} else {
    echo "ERROR";
}
