<?php 
    session_start();
    include "../modules/Class/autoload.php";  
    $url = '217.11.177.108:9907/Fines/api/rbdaapi/index.php';
    $secret = 'shohinnewkey';
    $inputdate = date('ymdHis');                        
    $data = [
        "action"=>"getlogins",
        "inputdate"=>$inputdate,
        "sign"=>md5('getlogins'.$plate.$inputdate.$secret)
    ];
    $jsondata = json_encode($data);
    $sendcurl = sendcurl($jsondata,$url);
    $loginarray = customjsondecode($sendcurl);     
   
?>

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>РБДА</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="РБДА" name="description" />
    <meta content="Themesdesign" name="author" />
    <!-- App favicon -->
    <link rel="shortcut icon" href="../assets/images/nerufavicon.png">
    <!-- Bootstrap Css -->
    <link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Icons Css -->
    <link href="../assets/css/icons.min.css" rel="stylesheet" type="text/css" />
    <!-- App Css-->
    <link href="../assets/css/app.min.css" rel="stylesheet" type="text/css" />

</head>

<body data-sidebar="dark">

    <!-- Begin page -->
    <div id="layout-wrapper">        
        <?php include "header.php";?>
        <!-- ========== Left Sidebar Start ========== -->
        <?php include "menu.php"?>
        <!-- Left Sidebar End -->

        <!-- ============================================================== -->
        <!-- Start right Content here -->
        <!-- ============================================================== -->
        <div class="main-content">
            <div class="page-content">
                <div class="container-fluid">
                    <!-- start page title -->
                    <div class="row">
                        <div class="col-12">
                            <div class="page-title-box d-flex align-items-center justify-content-between">
                                <h4 class="mb-0 font-size-18">Поиск штрафов</h4>
                            </div>
                        </div>
                    </div>
                    <!-- end page title -->
                    <div class="card">
                        <div class="card-body">
                            <div class="p-lg-3">
                                <div class="col-md-12">
                                <form method="post" action="report_spravka.php">
                                    <div class="row">
                                    <?php if (isset($_REQUEST['login'])){$login = $_REQUEST['login']; }else{$login='';}?>
                                    <?php if (isset($_REQUEST['from'])){$from = $_REQUEST['from']; }else{$from='';}?>
                                    <?php if (isset($_REQUEST['to'])){$to = $_REQUEST['to']; }else{$to='';}?>
                                        <div class="col-4">
                                            <div class="form-group">
                                                <label for="my-select">Выберите логин</label>
                                                <select id="my-select" class="form-control" name="login">
                                                    <option value="*">Выберите логин</option>
                                                    <?php foreach ($loginarray as $item){ ?>
                                                        <option value="<?=$item['login']?>"><?=$item['fio']?></option>
                                                    <?php }?>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-4">
                                            <div class="form-group">
                                                <label for="my-input">Дата от</label>
                                                <input value="<?=$from?>" id="my-input" class="form-control" type="date" name="from">
                                            </div>
                                            
                                        </div>
                                        <div class="col-4">
                                            <div class="form-group">
                                                <label for="my-input">Дата до</label>
                                                <input value="<?=$to?>" id="my-input" class="form-control" type="date" name="to">
                                            </div>
                                        </div>
                                        
                                        
                                    </div>
                                    <div class="form-group">
                                        <button name="srchfines" class="btn btn-success" type="submit">Сформировать</button>
                                    </div>
                                    
                                    
                                </form> 
                                </div>
                                             
                            </div>
                        <!--end card body-->
                    </div> <!-- end card-->
                </div> <!-- container-fluid -->
                
                <?php 
                
                    if(isset($_REQUEST['srchfines'])){                        
                        $login = filterdb($_REQUEST['login']);
                        $from = substr(str_replace('-','',$_REQUEST['from']),2,6);
                        $to = substr(str_replace('-','',$_REQUEST['to']),2,6);
                        if($from == '' or $to==''){
                            echo '
                            <div class="alert alert-info" role="alert">
                                Введите дату начала и  окончания
                            </div>
                            ';
                            return;
                        }
                        if($login=='*'){
                            echo '
                            <div class="alert alert-info" role="alert">
                                Не выбран логин.
                            </div>
                            ';
                            return;
                        }
                        
                        $url = '217.11.177.108:9907/Fines/api/rbdaapi/index.php';
                        $secret = 'shohinnewkey';
                        $inputdate = date('ymdHis');                        
                        $data = [
                            "action"=>"report_spravka",
                            "inputdate"=>$inputdate,
                            "login"=>$login,
                            "from"=>$from,
                            "to"=>$to,
                            "sign"=>md5('report_spravka'.$plate.$inputdate.$secret)
                        ];
                        $jsondata = json_encode($data);
                        $sendcurl = sendcurl($jsondata,$url);
                        $arraydata = customjsondecode($sendcurl);     
                        // dd($arraydata);                      
                        // return;
                        if(@$arraydata['code']=='103'){
                            echo '
                            <div class="alert alert-primary" role="alert">
                                У сотрудника <u>'.$arraydata[0]['fioname'].'</u> не обнаружены выданные справки за период.
                            </div>
                            ';
                            return;
                        }
                ?>
                
                <div class="card">
                        <div class="card-body">
                            <div class="p-lg-3">
                                <div class="col-md-6">
                                    <div class="alert alert-primary" role="alert">
                                        Выдал справку: <u> <?=$arraydata[0]['fioname']?></u><br>
                                        Кол-во: <u> <?=$arraydata[0]['kolvo']?></u><br>
        
                                    </div>
                                    <hr>
                                </div>
                                <div class="col" style="overflow-x:auto ;">
                                <table class="table table-light">
                                        <thead class="thead-light">
                                            <tr>
                                                <th>№</th>
                                                <th>Номер автомобиля</th>
                                                <th>Дата</th>
                                                <th>Выдал справку</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $i=1; foreach ($arraydata as $value) { ?>
                                                <tr>
                                                    <td><?=$i ?></td>
                                                    <td><?=strtoupper($value['plate']) ?></td>
                                                    <td><?=SanaTime($value['inputdate'])?></td>
                                                    <td><?=$value['fioname']?></td>                                                    
                                                </tr>
                                            <?php $i++; } ?>
                                        </tbody>
                                       
                                    </table>
                                </div>
                                
                                    
                                                                             
                            </div>
                        <!--end card body-->
                    </div> <!-- end card-->
                </div> <!-- container-fluid -->
                <?php } ?>


            </div>
            <!-- End Page-content -->
        </div>
        <!-- end main content-->

    </div>
    <!-- END layout-wrapper -->

    <!-- JAVASCRIPT -->
    <script src="../assets/libs/jquery/jquery.min.js"></script>
    <script src="../assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="../assets/libs/metismenu/metisMenu.min.js"></script>
    <script src="../assets/libs/simplebar/simplebar.min.js"></script>
    <script src="../assets/libs/node-waves/waves.min.js"></script>

    <script src="../assets/js/app.js"></script>
    <script src="../assets/js/myjs.js"></script>

</body>

</html>