<?php
session_start();
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj = new my_class();
$branchid = $_SESSION['LOGIN_BRANCH'];
extract($_GET);
// print_r($_GET);
// print_r($date);
$newDate = date("Y-m-d", strtotime($date));
//echo $newDate;
$from_date_input = $newDate;
$days_to_fetch = $day;
$from_date_ts = strtotime($from_date_input);
$to_date_ts = strtotime("-$days_to_fetch  days", $from_date_ts);
$to_date_ts = strtotime("+1 day", $to_date_ts);
$nto_date = date('Y-m-d', $to_date_ts);

$from_date = date('d-M-Y', strtotime($from_date_input));
$from2_date = strtoupper($from_date);
$to_date = date('d-M-Y', strtotime($nto_date));
$to2_date = strtoupper($to_date);

$key_id = strtolower($key_id);
$table = "FFWC.DATA_TBL";
$column = "PK_ID,TO_CHAR(M_DATE,'DD-MM-YYYY HH24:MI') AS READ_DATE,DATA_VALUE,D_TYPE";

$where_cond = "LOWER(STATION_CODE)='" . $key_id . "' and TO_DATE(M_DATE,'DD-MON-RRRR') BETWEEN '" . $to2_date . "' and '" . $from2_date . "' and D_TYPE='W' ORDER BY M_DATE DESC ";
$where_cond_pk = "LOWER(STATION_CODE)='" . $key_id . "' and TO_DATE(M_DATE,'DD-MON-RRRR ') BETWEEN '" . $to2_date . "' and '" . $from2_date . "' and D_TYPE='W' ORDER BY M_DATE DESC ";

$row_count = $obj->Total_Count_By_Cond($table, $where_cond);
$value = $obj->View_column_details_By_Cond($table, $column, $where_cond_pk);
$pk = $value['PK_ID'];
// echo $pk;
?>

<style>
    select,
    textarea,
    input[type="text"],
    input[type="password"],
    input[type="datetime"],
    input[type="datetime-local"],
    input[type="date"],
    input[type="month"],
    input[type="time"],
    input[type="week"],
    input[type="number"],
    input[type="email"],
    input[type="url"],
    input[type="search"],
    input[type="tel"],
    input[type="color"],
    .uneditable-input {
        display: inline-block;
        height: 1px !important;
        padding: 8px 3px !important;
        margin-bottom: 2px !important;
        font-size: 13px !important;
        line-height: 23px !important;
        color: #555;
        vertical-align: middle;
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px;
    }

    .table th,
    .table td {
        padding: 2px !important;
        line-height: 20px;
        text-align: left;
        vertical-align: top;
        border-top: 1px solid #ddd;
    }

    .tbl_border {
        border: 1px solid #ddd;
    }
</style>
<h4 style="margin-top: -3px;">
    Water Level Data for 
    <b><font color="#0040ff"><?php echo "$stationName ($key_id)"; ?></font></b>
    &nbsp;&nbsp;
    <a data-toggle='modal' href='#modal_ffwc_wl_add' onclick="ffwc_load_station_add_modal('<?php echo $key_id; ?>')" title="Add New Entry" 
       style="display: inline-block; width: 37px; height: 38px; line-height: 38px; text-align: center; background-color: #28a745; color: white; font-size: 24px; font-weight: bold; text-decoration: none; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">
        +
    </a>
</h4>


<div style="height:650px; overflow:auto;">
    <table id="wl_data_table" class="table table-bordered table-hover" style="width: 100%;" align="center">
        <thead>
            <tr style="font-family: 'Open Sans'; height: 5px;">
                <td style="text-align: center;  border: 1px solid #ddd;" class="table-header">Date</td>
                <td style="text-align: center;  border: 1px solid #ddd;" class="table-header">WL(m)</td>
            </tr>
        </thead>
        <tbody class="tbl_border">
            <?php
            $tblone = 'FFWC.DATA_TBL';
            $colone = "PK_ID,TO_CHAR(M_DATE,'DD-MM-YYYY HH24:MI') AS READ_DATE,DATA_VALUE,D_TYPE";
            $where_cond_one = "LOWER(STATION_CODE)='" . $key_id . "' and TO_DATE(M_DATE,'DD-MON-RRRR ') BETWEEN '" . $to2_date . "' and '" . $from2_date . "' and D_TYPE='W' ORDER BY M_DATE DESC ";
        


            foreach ($obj->View_colmn_By_Cond($tblone, $colone, $where_cond_one) as $value) {
                // print_r($value);
                $pk = $value['PK_ID'];
                $date = $value['READ_DATE'];
                $water_level = $value['DATA_VALUE'];
                $stat_name = $stationName;

                echo "<tr  height='5px'>";
                echo "<td width='17%' style='text-align: center; border: 1px solid #ddd;'>$date</td>";
                echo "<td width='12%' style='text-align: center; border: 1px solid #ddd;'>
                    <button type='button' data-toggle='modal' href='#modal_ffwc_wl_edit' onclick='ffwc_load_station_edit_modal(" . $pk . ")'>$water_level</button></td>";
                echo "</tr>";
            }

            ?>
        </tbody>
    </table>
</div>

