<?php 
    header('Access-Control-Allow-Origin: *');
    
    require_once './Mobile_Api/connection.php';
    
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }
     print_r($_SESSION);
    echo "username ".$_SESSION['username'];
    if (!isset($_SESSION['username'])) {
        // header("Location: ./login.php");
        // exit;
    }
?>


<html lang="en" class=" js flexbox flexboxlegacy canvas canvastext webgl no-touch geolocation postmessage websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers no-applicationcache svg inlinesvg smil svgclippaths"><head>
        <title>Canal Monitoring </title>


        <!--[if lt IE 10]>
              <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
              <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
              <![endif]-->

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="description" content="#">
        <meta name="keywords" content="Admin , Responsive, Landing, Bootstrap, App, Template, Mobile, iOS, Android, apple, creative app">
        <meta name="author" content="#">

        <link rel="icon" href="./files/assets/images/favicon.ico" type="image/x-icon">

        <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

        <link rel="stylesheet" type="text/css" href="./files/bower_components/bootstrap/dist/css/bootstrap.min.css">

        <link rel="stylesheet" type="text/css" href="./files/assets/icon/feather/css/feather.css">

        <link rel="stylesheet" type="text/css" href="./files/assets/css/style.css">
        <link rel="stylesheet" type="text/css" href="./files/assets/css/jquery.mCustomScrollbar.css">
        <style type="text/css">/* Chart.js */
            /*
             * DOM element rendering detection
             * https://davidwalsh.name/detect-node-insertion
             */
            @keyframes chartjs-render-animation {
                from {
                    opacity: 0.99;
                }
                to {
                    opacity: 1;
                }
            }

            .chartjs-render-monitor {
                animation: chartjs-render-animation 0.001s;
            }

            /*
             * DOM element resizing detection
             * https://github.com/marcj/css-element-queries
             */
            .chartjs-size-monitor,
            .chartjs-size-monitor-expand,
            .chartjs-size-monitor-shrink {
                position: absolute;
                direction: ltr;
                left: 0;
                top: 0;
                right: 0;
                bottom: 0;
                overflow: hidden;
                pointer-events: none;
                visibility: hidden;
                z-index: -1;
            }

            .chartjs-size-monitor-expand > div {
                position: absolute;
                width: 1000000px;
                height: 1000000px;
                left: 0;
                top: 0;
            }

            .chartjs-size-monitor-shrink > div {
                position: absolute;
                width: 200%;
                height: 200%;
                left: 0;
                top: 0;
            }
        </style>

        <script>
            // setInterval(function () {
//                window.location.reload();
            // }, 10000);

//            $(document).ready(function () {
//                feather.replace()
//            })

        </script>

        <!--<script src="https://kit.fontawesome.com/2bc8cc4aed.js" crossorigin="anonymous"></script>-->

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


    </head>
    <body themebg-pattern="pattern4">

        <div id="pcoded" class="pcoded iscollapsed" nav-type="st6" theme-layout="vertical" vertical-placement="left" vertical-layout="wide" pcoded-device-type="desktop" vertical-nav-type="expanded" vertical-effect="shrink" vnavigation-view="view1" fream-type="theme1" sidebar-img="false" sidebar-img-type="img1" layout-type="light">
            <div class="pcoded-overlay-box"></div>
            <div class="pcoded-container navbar-wrapper">
                <nav class="navbar header-navbar pcoded-header iscollapsed" header-theme="theme1" pcoded-header-position="fixed">
                    <div class="navbar-wrapper">
                        <div class="navbar-logo" logo-theme="theme1">
                            <a class="mobile-menu" id="mobile-collapse" href="#!">
                                <i class="fa fa-sliders"></i>
                            </a>
                            <a href="index.php">
                                <img class="img-fluid" src="./files/assets/img/bridge.png" height="50px" width="50px" alt="Theme-Logo"> Canal Monitoring
                            </a>
                            <a class="mobile-options">
                                <i class="feather icon-more-horizontal"></i>
                            </a>
                        </div>

                        <?php
                        $notification = 0;

                        $query = 'SELECT MAX(id) as id FROM `tbl_flow_meter_data` WHERE flag=1 GROUP BY user_id ORDER by id asc';
                        mysqli_set_charset($con, 'utf8');
                        $result = mysqli_query($con, $query);
                        if (mysqli_num_rows($result) > 0) {
                            $i = 1;
                            while ($row = mysqli_fetch_assoc($result)) {

                                $id = $row["id"];

                                $query1 = 'SELECT tfmd.*,DATE_FORMAT(tfmd.created_date,"%d-%m-%Y %H:%i:%s") AS created_date_new,DATE_FORMAT(tfmd.created_date,"%Y-%m-%d") AS days_date,tfm.meter_name,tfm.address FROM `tbl_flow_meter_data` as tfmd LEFT join tbl_flow_meter as tfm on tfm.user_id=tfmd.user_id WHERE tfmd.id=' . $id . ' and tfmd.flag=1 ORDER by tfmd.id DESC LIMIT 0,1';
//                                $query1 = 'SELECT twts.id,twts.user_id,twts.freez_temperature,twts.freez_humidity,twts.comment,DATE_FORMAT(twts.created_date,"%d-%m-%Y %H:%i:%s") AS created_date,DATE_FORMAT(twts.created_date,"%Y-%m-%d") AS days_date,tsu.full_name,tsu.mobile_no,ts.school_name,tv.village,tv.village_hindi,tv.village_guj FROM `tbl_freez_status` as twts LEFT join tbl_school_user as tsu on twts.user_id=tsu.id left join tbl_school as ts on tsu.school_id=ts.id left join tbl_village as tv on ts.village_id=tv.id where twts.flag=1 and twts.id=' . $id . ' order by twts.id DESC LIMIT 0,1';
//                                echo '$query1 ' . $query1;
                                mysqli_set_charset($con, 'utf8');
                                $result1 = mysqli_query($con, $query1);
                                if (mysqli_num_rows($result) > 0) {
                                    $i = 1;
                                    while ($row1 = mysqli_fetch_assoc($result1)) {

                                        $now = time(); // or your date as well
                                        $your_date = strtotime($row1["days_date"]);
                                        $datediff = $now - $your_date;

//                                                                                            echo round($datediff / (60 * 60 * 24));
                                        $Days = round($datediff / (60 * 60 * 24));

                                        if ($Days > 3) {
                                            $notification = $notification + 1;
                                        }


                                        if ($row1['water_level'] < 0) {
                                            $notification = $notification + 1;
                                        }
//                                        else if ($row1['water_level'] < - 20) {
//                                            $notification = $notification + 1;
//                                        }
                                    }
                                }
                            }
                        }
                        ?>

                        <div class="navbar-container">
                            <ul class="nav-right">
                                <li class="header-notification">
                                    <div class="dropdown-primary dropdown">
                                        <div class="dropdown-toggle" data-toggle="dropdown">
                                            <i class="fa fa-bell"></i>
                                            <span class="badge bg-c-pink"><?php echo $notification; ?></span>
                                        </div>
                                        <ul class="show-notification notification-view dropdown-menu" data-dropdown-in="fadeIn" data-dropdown-out="fadeOut" style="max-height: 550px;background: #b4cee7;overflow: auto">
                                            <li>


                                                <?php
                                                if ($_SESSION['User_language'] == 'ENGLISH') {
                                                    ?>
                                                    <h6>Notifications</h6>
                                                    <label class="label label-danger">New</label>
                                                    <?php
                                                }

                                                if ($_SESSION['User_language'] == 'GUJARATI') {
                                                    ?>
                                                    <h6>સૂચનાઓ</h6>
                                                    <label class="label label-danger">નવી</label>
                                                    <?php
                                                }
                                                ?>

                                            </li>

                                            <?php
                                            $offline = 0;
                                            $online = 0;

                                            $query = 'SELECT MAX(id) as id FROM `tbl_flow_meter_data` WHERE flag=1 GROUP BY user_id ORDER by id asc';
                                            mysqli_set_charset($con, 'utf8');
                                            $result = mysqli_query($con, $query);
                                            if (mysqli_num_rows($result) > 0) {
                                                $i = 1;
                                                while ($row = mysqli_fetch_assoc($result)) {

                                                    $id = $row["id"];

                                                    $query1 = 'SELECT tfmd.*,DATE_FORMAT(tfmd.created_date,"%d-%m-%Y %H:%i:%s") AS created_date_new,DATE_FORMAT(tfmd.created_date,"%Y-%m-%d") AS days_date,tfm.meter_name,tfm.address FROM `tbl_flow_meter_data` as tfmd LEFT join tbl_flow_meter as tfm on tfm.user_id=tfmd.user_id WHERE tfmd.id=' . $id . ' and tfmd.flag=1 ORDER by tfmd.id DESC LIMIT 0,1';
                                                    mysqli_set_charset($con, 'utf8');
                                                    $result1 = mysqli_query($con, $query1);
                                                    if (mysqli_num_rows($result) > 0) {
                                                        $i = 1;
                                                        while ($row1 = mysqli_fetch_assoc($result1)) {

                                                            $now = time(); // or your date as well
                                                            $your_date = strtotime($row1["days_date"]);
                                                            $datediff = $now - $your_date;

//                                                                                            echo round($datediff / (60 * 60 * 24));
                                                            $Days = round($datediff / (60 * 60 * 24));

                                                            if ($Days > 3) {
                                                                $offline = $offline + 1;
                                                                ?>

                                                                <li style="padding: 10px">
                                                                    <div class="media view_school_tank_status" id="<?php echo $row1["user_id"]; ?>">
                                                                        <img class="d-flex align-self-center img-radius" src="./files/assets/img/freezerlogo.png" alt="Generic placeholder image">
                                                                        <div class="media-body">
                                                                            <h5 class="notification-user"><?php echo $row1["school_name"]; ?></h5>


                                                                            <?php
                                                                            if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                                ?>
                                                                                <p class="notification-msg view_school_tank_status" id="<?php echo $row1["user_id"]; ?>"><?php echo $row1["school_name"]; ?> stop working last <?php echo $Days . " Days."; ?>
                                                                                </p>
                                                                                <?php
                                                                            }

                                                                            if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                                ?>
                                                                                <p class="notification-msg view_school_tank_status" id="<?php echo $row1["user_id"]; ?>"><?php echo $row1["school_name"]; ?> નું ફ્રિઝર છેલ્લા <?php echo $Days; ?> દિવસથી બંધ છે.
                                                                                </p>
                                                                                <?php
                                                                            }
                                                                            ?>

                                                                                                                                                                                                                        <!--<span class="notification-time">30 minutes ago</span>-->
                                                                        </div>
                                                                    </div>
                                                                </li>

                                                                <?php
                                                            } else {
                                                                $online = $online + 1;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            ?>
                                        </ul>
                                    </div>
                                </li>

                                <li class="header-notification">
                                    <div class="dropdown-primary dropdown">
                                        <div class="dropdown-toggle" data-toggle="dropdown">
                                            <i class="icon text-primary fa fa-language" style="font-size:26px;"></i>

                                            <?php
                                            if ($_SESSION['User_language'] == 'ENGLISH') {
                                                ?>
                                                <span>Change Language</span>
                                                <?php
                                            }
                                            if ($_SESSION['User_language'] == 'GUJARATI') {
                                                ?>
                                                <span>ભાષા બદલો</span>
                                                <?php
                                            }
                                            ?>
                                        </div>

                                        <ul class="show-notification notification-view dropdown-menu" data-dropdown-in="fadeIn" data-dropdown-out="fadeOut">
                                            <li>

                                                <?php
                                                if ($_SESSION['User_language'] == 'ENGLISH') {
                                                    ?>
                                                    <h6>Choose Language </h6>
                                                    <?php
                                                }

                                                if ($_SESSION['User_language'] == 'GUJARATI') {
                                                    ?>
                                                    <h6>ભાષા પસંદ કરો</h6>
                                                    <?php
                                                }
                                                ?>
                                                <label class="icon text-primary fa fa-language"></label>
                                            </li>
                                            <li>
                                                <div class="media">
                                                    <button onclick="btn_english()" type="button" tabindex="0" class="dropdown-item">
                                                        <span class="mr-3 opacity-8 flag large IND"></span><b> English </b>
                                                    </button>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="media">
                                                    <button onclick="btn_gujarati()" type="button" tabindex="0" class="dropdown-item" id="btn-gujarati">
                                                        <span class="mr-3 opacity-8 flag large CH"></span><b> GUJARATI </b>
                                                    </button>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                </li>

                                <!--                                <div class="dropdown show">
                                                                    <button type="button" data-toggle="dropdown" class="p-0 mr-2 btn btn-link" aria-expanded="true">
                                                                        <span class="icon-wrapper icon-wrapper-alt rounded-circle">
                                                                            <span class="icon-wrapper-bg bg-focus"></span>
                                                                            <i class="icon text-primary fa fa-language"></i>
                                                                            <span class="language-icon opacity-8 large fa fa-globe"></span>
                                                                        </span>
                                                                    </button>
                                                                    <div tabindex="-1" role="menu" aria-hidden="true" class="rm-pointers dropdown-menu dropdown-menu-right show" x-placement="bottom-end" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(-198px, 46px, 0px);">
                                                                        <div class="dropdown-menu-header">
                                                                            <div class="dropdown-menu-header-inner pt-4 pb-4 bg-focus">
                                                                                <div class="menu-header-image opacity-05"></div>
                                                                                <div class="menu-header-content text-center text-white">
                                
                                
                                                                                    <h6 class="menu-header-subtitle mt-0"> Choose Language</h6>
                                
                                
                                
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                        <h6 tabindex="-1" class="dropdown-header"> Popular Languages</h6>
                                                                                                            <a onclick="btn_english()" class="nav-link">
                                                                                                                English 1
                                                                                                            </a>
                                                                        <a  class="nav-link">
                                                                        <button onclick="btn_english()" type="button" tabindex="0" class="dropdown-item">
                                                                            <span class="mr-3 opacity-8 flag large IND"></span> English
                                                                        </button>
                                                                        </a>
                                                                        <button onclick="btn_gujarati()" type="button" tabindex="0" class="dropdown-item" id="btn-gujarati">
                                                                            <span class="mr-3 opacity-8 flag large CH"></span> ગુજરાતી
                                                                        </button>
                                                                                                                <button onclick="btn_hindi()" type="button" tabindex="0" class="dropdown-item" id="btn-hindi">
                                                                                                                    <span class="mr-3 opacity-8 flag large FR"></span> हिन्दी
                                                                                                                </button>
                                                                    </div>
                                                                </div>-->

                                <li class="user-profile header-notification">
                                    <div class="dropdown-primary dropdown">
                                        <div class="dropdown-toggle" data-toggle="dropdown">
                                            <img src="./files/assets/images/avatar-4.jpg" class="img-radius" alt="User-Profile-Image">
                                            <span>Admin</span>
                                            <i class="fa fa-chevron-down"></i>
                                        </div>
                                        <ul class="show-notification profile-notification dropdown-menu" data-dropdown-in="fadeIn" data-dropdown-out="fadeOut">


                                            <?php
                                            if ($_SESSION['User_language'] == 'ENGLISH') {
                                                ?>
                                                <li>
                                                    <a href="javascript:void(0)" id="btn-logout">
                                                        <i class="fa fa-lock"></i> Logout
                                                    </a>
                                                </li>
                                                <?php
                                            }
                                            if ($_SESSION['User_language'] == 'GUJARATI') {
                                                ?>
                                                <li>
                                                    <a href="javascript:void(0)" id="btn-logout">
                                                        <i class="fa fa-lock"></i> લૉગઆઉટ
                                                    </a>
                                                </li>
                                                <?php
                                            }
                                            ?>

                                        </ul>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </nav>

                <div class="pcoded-main-container" style="margin-top: 56px;">
                    <div class="pcoded-wrapper">
                        <nav class="pcoded-navbar" navbar-theme="theme1" active-item-theme="theme1" sub-item-theme="theme2" active-item-style="style0" pcoded-navbar-position="fixed">
                            <div class="pcoded-inner-navbar main-menu mCustomScrollbar _mCS_1" id="" style="height: calc(100% - 80px);"><div id="mCSB_1" class="mCustomScrollBox mCS-light mCSB_vertical_horizontal mCSB_inside" style="max-height: none;" tabindex="0"><div id="mCSB_1_container_wrapper" class="mCSB_container_wrapper mCS_x_hidden mCS_no_scrollbar_x"><div id="mCSB_1_container" class="mCSB_container" style="position: relative; top: -10px; left: 0px; width: 100%;" dir="ltr">
                                            <div class="pcoded-navigatio-lavel" menu-title-theme="theme5">Navigation</div>
                                            <ul class="pcoded-item pcoded-left-item" item-border="true" item-border-style="none" subitem-border="true">                                                
                                                <li class="">
                                                    <a href="./index.php">
                                                        <span class="pcoded-micon"><i class="fa fa-home"></i></span>


                                                        <?php
                                                        if ($_SESSION['User_language'] == 'ENGLISH') {
                                                            ?>
                                                            <span class="pcoded-mtext">Dashboard</span>
                                                            <?php
                                                        }

                                                        if ($_SESSION['User_language'] == 'GUJARATI') {
                                                            ?>
                                                            <span class="pcoded-mtext">ડેશબોર્ડ</span>
                                                            <?php
                                                        }
                                                        ?>

                                                    </a>
                                                </li>
                                            </ul>
                                        </div></div><div id="mCSB_1_scrollbar_vertical" class="mCSB_scrollTools mCSB_1_scrollbar mCS-light mCSB_scrollTools_vertical" style="display: block;"><div class="mCSB_draggerContainer"><div id="mCSB_1_dragger_vertical" class="mCSB_dragger" style="position: absolute; min-height: 30px; display: block; height: 167px; max-height: 667px; top: 2px;"><div class="mCSB_dragger_bar" style="line-height: 30px;"></div></div><div class="mCSB_draggerRail"></div></div></div><div id="mCSB_1_scrollbar_horizontal" class="mCSB_scrollTools mCSB_1_scrollbar mCS-light mCSB_scrollTools_horizontal" style="display: none;"><div class="mCSB_draggerContainer"><div id="mCSB_1_dragger_horizontal" class="mCSB_dragger" style="position: absolute; min-width: 30px; width: 0px; left: 0px;"><div class="mCSB_dragger_bar"></div></div><div class="mCSB_draggerRail"></div></div></div></div></div>
                        </nav>
                        <div class="pcoded-content">
                            <div class="pcoded-inner-content">
                                <div class="main-body">
                                    <div class="page-wrapper">
                                        <div class="page-body">
                                            <div class="row">


                                                <div class="col-xl-3 col-md-6">
                                                    <div class="card bg-c-yellow update-card">
                                                        <div class="card-block">
                                                            <div class="row align-items-end">

                                                                <?php
                                                                $query = 'SELECT count(id) as id FROM `tbl_flow_meter` WHERE flag=1';
                                                                mysqli_set_charset($con, 'utf8');
                                                                $result = mysqli_query($con, $query);
                                                                if (mysqli_num_rows($result) > 0) {
                                                                    $i = 1;
                                                                    while ($row = mysqli_fetch_assoc($result)) {

                                                                        $id = $row["id"];
                                                                        ?>

                                                                        <div class="col-8">
                                                                            <h4 class="text-white"><?php echo $row["id"]; ?></h4>

                                                                            <?php
                                                                            if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                                ?>
                                                                                <h6 class="text-white m-b-0">All Canal </h6>
                                                                                <?php
                                                                            }

                                                                            if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                                ?>
                                                                                <h6 class="text-white m-b-0">કુલ નહેર</h6>
                                                                                <?php
                                                                            }
                                                                            ?>

                                                                        </div>
                                                                        <div class="col-4 text-right"><div class="chartjs-size-monitor"><div class="chartjs-size-monitor-expand"><div class=""></div></div><div class="chartjs-size-monitor-shrink"><div class=""></div></div></div>
                                                                            <canvas id="update-chart-2" height="50" width="65" style="display: block; width: 65px; height: 50px;" class="chartjs-render-monitor"></canvas>
                                                                        </div>

                                                                        <?php
                                                                    }
                                                                }
                                                                ?>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                                <?php
                                                $offline = 0;
                                                $online = 0;

                                                $query = 'SELECT MAX(id) as id FROM `tbl_flow_meter_data` WHERE flag=1 GROUP BY user_id ORDER by id asc';
                                                mysqli_set_charset($con, 'utf8');
                                                $result = mysqli_query($con, $query);
                                                if (mysqli_num_rows($result) > 0) {
                                                    $i = 1;
                                                    while ($row = mysqli_fetch_assoc($result)) {

                                                        $id = $row["id"];

                                                        $query1 = 'SELECT tfmd.*,DATE_FORMAT(tfmd.created_date,"%d-%m-%Y %H:%i:%s") AS created_date_new,DATE_FORMAT(tfmd.created_date,"%Y-%m-%d") AS days_date,tfm.meter_name,tfm.address FROM `tbl_flow_meter_data` as tfmd LEFT join tbl_flow_meter as tfm on tfm.user_id=tfmd.user_id WHERE tfmd.id=' . $id . ' and tfmd.flag=1 ORDER by tfmd.id DESC LIMIT 0,1';
                                                        mysqli_set_charset($con, 'utf8');
                                                        $result1 = mysqli_query($con, $query1);
                                                        if (mysqli_num_rows($result) > 0) {
                                                            $i = 1;
                                                            while ($row1 = mysqli_fetch_assoc($result1)) {

                                                                $now = time(); // or your date as well
                                                                $your_date = strtotime($row1["days_date"]);
                                                                $datediff = $now - $your_date;

//                                                                                            echo round($datediff / (60 * 60 * 24));
                                                                $Days = round($datediff / (60 * 60 * 24));

                                                                if ($Days > 3) {
                                                                    $offline = $offline + 1;
                                                                } else {
                                                                    $online = $online + 1;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                ?>

                                                <div class="col-xl-3 col-md-6">
                                                    <div class="card bg-c-green update-card">
                                                        <div class="card-block">
                                                            <div class="row align-items-end">
                                                                <div class="col-8">
                                                                    <h4 class="text-white"><?php echo $online; ?></h4>


                                                                    <?php
                                                                    if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                        ?>
                                                                        <h6 class="text-white m-b-0">Online</h6>
                                                                        <?php
                                                                    }

                                                                    if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                        ?>
                                                                        <h6 class="text-white m-b-0">ઓનલાઈન</h6>
                                                                        <?php
                                                                    }
                                                                    ?>

                                                                </div>
                                                                <div class="col-4 text-right"><div class="chartjs-size-monitor"><div class="chartjs-size-monitor-expand"><div class=""></div></div><div class="chartjs-size-monitor-shrink"><div class=""></div></div></div>
                                                                    <canvas id="update-chart-3" height="50" width="65" style="display: block; width: 65px; height: 50px;" class="chartjs-render-monitor"></canvas>
                                                                </div>

                                                            </div>
                                                        </div>

                                                    </div>
                                                </div>
                                                <div class="col-xl-3 col-md-6">
                                                    <div class="card bg-c-pink update-card">
                                                        <div class="card-block">
                                                            <div class="row align-items-end">
                                                                <div class="col-8">
                                                                    <h4 class="text-white"><?php echo $offline; ?></h4>

                                                                    <?php
                                                                    if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                        ?>
                                                                        <h6 class="text-white m-b-0">Offline</h6>
                                                                        <?php
                                                                    }

                                                                    if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                        ?>
                                                                        <h6 class="text-white m-b-0">ઑફલાઇન</h6>
                                                                        <?php
                                                                    }
                                                                    ?>

                                                                </div>
                                                                <div class="col-4 text-right"><div class="chartjs-size-monitor"><div class="chartjs-size-monitor-expand"><div class=""></div></div><div class="chartjs-size-monitor-shrink"><div class=""></div></div></div>
                                                                    <canvas id="update-chart-4" height="50" width="65" style="display: block; width: 65px; height: 50px;" class="chartjs-render-monitor"></canvas>
                                                                </div>
                                                            </div>
                                                        </div>

                                                    </div>
                                                </div>

                                                <div class="col-xl-12 col-md-12">
                                                    <div class="card table-card">
                                                        <div class="row">
                                                            <div class="card-header col-md-3" >

                                                                <?php
                                                                if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                    ?>
                                                                    <h5>Canal List</h5>
                                                                    <?php
                                                                }

                                                                if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                    ?>
                                                                    <h5>નહેરની યાદી</h5>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </div>

                                                        </div>
                                                        <hr style="margin-bottom: 0px;margin-top: 0px">
                                                        <div class="card-block">
                                                            <div class="table-responsive">
                                                                <table class="table table-hover  table-borderless">
                                                                    <thead>
                                                                        <tr>
                                                                            <?php
                                                                            if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                                ?>
                                                                                <th>No.</th>
                                                                                <th>
                                                                                    Canal Name
                                                                                </th>
                                                                                <th>Water Level</th>
                                                                                <th>Water Flow</th>
                                                                                <th>Accumulative Water</th>
                                                                                <th>Last Update</th>
                                                                                <th>Status</th>
                                                                                <?php
                                                                            }

                                                                            if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                                ?>
                                                                                <th>નં.</th>
                                                                                <th>
                                                                                    નહેરનું નામ
                                                                                </th>
                                                                                <th>વોટર લેવલ</th>
                                                                                <th>પાણીનો પ્રવાહ</th>
                                                                                <th>સંચિત પાણી</th>
                                                                                <th>છેલ્લું અપડેટ</th>
                                                                                <th>સ્થિતિ</th>
                                                                                <?php
                                                                            }
                                                                            ?>

                                                                        </tr>
                                                                    </thead>
                                                                    <tbody id="school_list">

                                                                        <?php
                                                                        $query = 'SELECT MAX(id) as id FROM `tbl_flow_meter_data` WHERE flag=1 GROUP BY user_id ORDER by id asc';
                                                                        mysqli_set_charset($con, 'utf8');
                                                                        $result = mysqli_query($con, $query);
                                                                        if (mysqli_num_rows($result) > 0) {
                                                                            $i = 1;
                                                                            while ($row = mysqli_fetch_assoc($result)) {

                                                                                $id = $row["id"];

                                                                                $query1 = 'SELECT tfmd.*,DATE_FORMAT(tfmd.created_date,"%d-%m-%Y %H:%i:%s") AS created_date_new,DATE_FORMAT(tfmd.created_date,"%Y-%m-%d") AS days_date,tfm.meter_name,tfm.address FROM `tbl_flow_meter_data` as tfmd LEFT join tbl_flow_meter as tfm on tfm.user_id=tfmd.user_id WHERE tfmd.id=' . $id . ' and tfmd.flag=1 ORDER by tfmd.id DESC LIMIT 0,1';
                                                                                mysqli_set_charset($con, 'utf8');
                                                                                $result1 = mysqli_query($con, $query1);
                                                                                if (mysqli_num_rows($result) > 0) {
                                                                                    while ($row1 = mysqli_fetch_assoc($result1)) {
                                                                                        ?>
                                                                                        <tr id="<?php echo $row1["user_id"]; ?>" class="view_school_tank_status">
                                                                                            <td><?php echo $i; ?></td>
                                                                                            <td>

                                                                                                <div class="d-inline-block align-middle">
                                                                                                    <h6><?php echo $row1["meter_name"]; ?></h6>
                                                                                                    <p class="text-muted m-b-0"><?php echo $row1["address"]; ?></p>
                                                                                                </div>
                                                                                            </td>
                                                                                            <td><?php echo $row1["water_level"].' Meter'; ?></td>
                                                                                            <!--<td><?php // echo $row1["water_flow"].' m3/h'; ?></td>-->
                                                                                            <td><?php echo $row1["water_flow"] * 0.00981 .' Cusec/Hour'; ?></td>
                                                                                            <td><?php echo $row1["accumulative_water"].' m3'; ?></td>
                                                                                            <!--<td><?php // echo $row1["accumulative_water"]/0.0010000.' m3'; ?></td>-->
                                                                                            <td><?php echo $row1["created_date_new"]; ?></td>

                                                                                            <?php
                                                                                            $now = time(); // or your date as well
                                                                                            $your_date = strtotime($row1["days_date"]);
                                                                                            $datediff = $now - $your_date;

//                                                                                            echo round($datediff / (60 * 60 * 24));
                                                                                            $Days = round($datediff / (60 * 60 * 24));
                                                                                            ?>

                                                                                            <td class="text-c-blue">
                                                                                                <!--<div class="btn-group " role="group" data-toggle="tooltip" data-placement="top" data-original-title=".btn-xlg">-->
                                                                                                <?php
                                                                                                if ($Days > 3) {
                                                                                                    ?>


                                                                                                    <?php
                                                                                                    if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                                                        ?>
                                                                                                        <label class="btn-danger btn-sm">Offline</label>
                                                                                                        <?php
                                                                                                    }

                                                                                                    if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                                                        ?>
                                                                                                        <label class="btn-danger btn-sm">ઑફલાઇન</label>
                                                                                                        <?php
                                                                                                    }
                                                                                                    ?>

                                                                                                    <?php
                                                                                                } else {
                                                                                                    ?>


                                                                                                    <?php
                                                                                                    if ($_SESSION['User_language'] == 'ENGLISH') {
                                                                                                        ?>
                                                                                                        <label class=" btn-success btn-sm">Online</label>
                                                                                                        <?php
                                                                                                    }

                                                                                                    if ($_SESSION['User_language'] == 'GUJARATI') {
                                                                                                        ?>
                                                                                                        <label class=" btn-success btn-sm">ઓનલાઈન</label>
                                                                                                        <?php
                                                                                                    }
                                                                                                    ?>
                                                                                                    <?php
                                                                                                }
                                                                                                ?>



                                                                                                <!--</div>-->
                                                                                            </td>
                                                                                        </tr>
                                                                                        <?php
                                                                                    }
                                                                                }
                                                                                $i = $i + 1;
                                                                            }
                                                                        }
                                                                        ?>

                                                                    </tbody>
                                                                </table>
                                                                <!--                                                                <div class="text-center">
                                                                                                                                    <a href="#!" class=" b-b-primary text-primary">View all
                                                                                                                                        Projects</a>
                                                                                                                                </div>-->
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <!--[if lt IE 10]>
        <div class="ie-warning">
            <h1>Warning!!</h1>
            <p>You are using an outdated version of Internet Explorer, please upgrade <br/>to any of the following web browsers to access this website.</p>
            <div class="iew-container">
                <ul class="iew-download">
                    <li>
                        <a href="http://www.google.com/chrome/">
                            <img src="./files/assets/images/browser/chrome.png" alt="Chrome">
                            <div>Chrome</div>
                        </a>
                    </li>
                    <li>
                        <a href="https://www.mozilla.org/en-US/firefox/new/">
                            <img src="./files/assets/images/browser/firefox.png" alt="Firefox">
                            <div>Firefox</div>
                        </a>
                    </li>
                    <li>
                        <a href="http://www.opera.com">
                            <img src="./files/assets/images/browser/opera.png" alt="Opera">
                            <div>Opera</div>
                        </a>
                    </li>
                    <li>
                        <a href="https://www.apple.com/safari/">
                            <img src="./files/assets/images/browser/safari.png" alt="Safari">
                            <div>Safari</div>
                        </a>
                    </li>
                    <li>
                        <a href="http://windows.microsoft.com/en-us/internet-explorer/download-ie">
                            <img src="./files/assets/images/browser/ie.png" alt="">
                            <div>IE (9 & above)</div>
                        </a>
                    </li>
                </ul>
            </div>
            <p>Sorry for the inconvenience!</p>
        </div>
        <![endif]-->





        <script type="text/javascript" src="./files/bower_components/jquery/dist/jquery.min.js"></script>
        <script type="text/javascript" src="./files/bower_components/jquery-ui/jquery-ui.min.js"></script>
        <script type="text/javascript" src="./files/bower_components/popper.js/dist/umd/popper.min.js"></script>
        <script type="text/javascript" src="./files/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

        <script type="text/javascript" src="./files/bower_components/jquery-slimscroll/jquery.slimscroll.js"></script>

        <script type="text/javascript" src="./files/bower_components/modernizr/modernizr.js"></script>

        <script type="text/javascript" src="./files/bower_components/chart.js/dist/Chart.js"></script>

        <script src="./files/assets/pages/widget/amchart/amcharts.js"></script>
        <script src="./files/assets/pages/widget/amchart/serial.js"></script>
        <script src="./files/assets/pages/widget/amchart/light.js"></script>
        <script src="./files/assets/js/jquery.mCustomScrollbar.concat.min.js"></script>
        <script type="text/javascript" src="./files/assets/js/SmoothScroll.js"></script>
        <script src="./files/assets/js/pcoded.min.js"></script>

        <script src="./files/assets/js/vartical-layout.min.js"></script>
        <!--<script type="text/javascript" src="./files/assets/pages/dashboard/custom-dashboard.min.js"></script>-->
        <script type="text/javascript" src="./files/assets/js/script.js"></script>

        <!-- jQuery library -->
        <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>-->

        <script type="text/javascript">

                                                        var User_lang;
                                                        function btn_english() {
//                        alert('function btn-english');
                                                            User_lang = "ENGLISH";
                                                            $.myjQuery(User_lang);
                                                        }

                                                        function btn_gujarati() {
//                        alert('function btn_gujarati');
                                                            User_lang = "GUJARATI";
                                                            $.myjQuery(User_lang);
                                                        }
                                                        function btn_hindi() {
//                        alert('function btn_hindi');
                                                            User_lang = "HINDI";
                                                            $.myjQuery(User_lang);
                                                        }

                                                        $(document).ready(function () {

                                                            $.myjQuery = function (User_lang) {
//                                                    alert("jQuery " + User_lang);
                                                                if (User_lang == " ") {
//                                alert('Project Id Not Found! ');
                                                                } else {
                                                                    debugger;
                                                                    var send = {'Language_User': User_lang};
                                                                    $.ajax({
                                                                        type: 'POST',
                                                                        data: send,
                                                                        url: './PHP_Code/set_session_user_language.php',
                                                                        success: function (data) {
                                                                            debugger;
//                                                                alert('data ' + data);
                                                                            location.reload();
//                                        window.location.href = "/project_progress/project_detail";
                                                                        }, error: function (xhr, err) {
                                                                            alert('Error ' + err.message);
                                                                        }
                                                                    });
                                                                }
                                                            };
                                                        });



                                                        $(document).ready(function () {

                                                            $(document.body).on('change', '#select_taluka', function () {
                                                                debugger;
                                                                if ($("#select_taluka").val() == "Select")
                                                                {
//                                                                    $("#msg_select_milk_type").fadeIn(500);
//                                                                    $("#msg_select_milk_type").html("* Milk Type Not Selected").css({'color': 'red'});
//                                                                    $("#msg_select_milk_type").focusin();
                                                                } else
                                                                {
//                                                                    $("#msg_select_milk_type").fadeOut(1000);
                                                                    debugger;
                                                                    var taluka_id = $('#select_taluka').find('option:selected').attr('id');
//                                                                    var a = $("#select_taluka").val();

                                                                    var data = {};
                                                                    data.taluka_id = taluka_id;
                                                                    $.ajax({
                                                                        type: 'POST',
                                                                        data: data,
                                                                        url: './PHP_Code/select_school_list.php',
                                                                        success: function (data) {
//                        alert('data '+data);
                                                                            debugger;
                                                                            $('#school_list').html('');
                                                                            $('#school_list').html(data);
                                                                            $("#school_list").val('Select');
                                                                        }, error: function (xhr, err) {
                                                                            alert('Error ' + err.message);
                                                                        }
                                                                    });

                                                                }
                                                            });

                                                            $(document.body).on('click', '.view_school_tank_status', function (e) {

                                                                //            alert('id is ' + $(this).attr('id'));
                                                                var user_id = $(this).attr('id');
                                                                if (user_id == " ") {
                                                                    alert('User Id Not Found! ');
                                                                } else {
                                                                    debugger;
                                                                    var data = {};
                                                                    var data = {'user_id': user_id};
//                                                        data.user_id = user_id;
                                                                    $.ajax({
                                                                        type: 'POST',
                                                                        data: data,
                                                                        url: './PHP_Code/select_water_tank_detail.php',
                                                                        success: function (data) {
                                                                            debugger;
//                                                                                        alert('data '+data);
                                                                            window.location.href = "./view_freezer_detail.php";

                                                                        }, error: function (xhr, err) {
                                                                            alert('Error ' + err.message);
                                                                        }
                                                                    });
                                                                }

                                                            });

                                                            $('#btn-logout').click(function () {
//                alert('logout');
                                                                var send = {'logout': 'logout'};
                                                                $.ajax({
                                                                    url: './PHP_Code/session_destroy.php',
                                                                    type: 'POST',
                                                                    data: send,
                                                                    success: function (data)
                                                                    {
                                                                        debugger;
//                        alert('data ' + data);
                                                                        window.location.href = "./index.php";

                                                                    },
                                                                    error: function (err) {
                                                                        alert('error ' + err);
                                                                    }
                                                                });
                                                            });

                                                        });
        </script>

       
    </body></html>