<?php 
    session_start();
    include "../modules/Class/autoload.php";   
?>

<!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-3">
                                    <p class="lead" >Роль : <b>Администратор</b></p>
                                </div>
                                             
                            </div>
                            <hr>
                        <!--end card body-->
                    </div> <!-- end card-->
                    
                </div> <!-- container-fluid -->
                <?php 
                        $url = '217.11.177.108:9907/Fines/api/rbdaapi/index.php';
                        $secret = 'shohinnewkey';
                        $inputdate = date('ymdHis');
                        $plate = filterdb($_REQUEST['plate']);
                        $data = [
                            "action"=>"access",
                            "inputdate"=>$inputdate,
                            "id"=>filterdb($_REQUEST['login']),
                            "sign"=>md5('access'.$inputdate.$secret)
                        ];
                        $jsondata = json_encode($data);
                        $sendcurl = sendcurl($jsondata,$url);
                        $arraydata = customjsondecode($sendcurl);  
                        // dd($arraydata);
                        $dataproceed = $arraydata[0]['result'];
                                             
                        if(@$arraydata['code']=='103'){
                            echo '
                            <div class="alert alert-primary" role="alert">
                               Не удалось найти код роли 
                            </div>
                            ';
                            return;
                        }
                ?>
                
                <div class="card">
                        <div class="card-body">
                            <div class="p-lg-3">
                                <div class="col" style="overflow-x:auto ;">
                                <p class="lead">Доступы</p>
                                <hr>
                                <form method="post" action="../modules/crud.php?act=access">                                
                                    <table class="table table-light">
                                        <thead class="thead-light">
                                            <tr>
                                                <th>№</th>
                                                <th>Наименование доступа</th>
                                                <th>Наличие доступа</th>
                                         
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $i=1; foreach ($dataproceed as $value) { 
                                                if ($value['Check']=='1'){$checked = 'checked';}else{$checked='';}    
                                            ?>
                                                <tr>
                                                    <td><?=$i ?></td>
                                                    <td><?=$value['Name'] ?></td>
                                                    <td>
                                                        <div class="form-check">
                                                        <input value="<?=$value['Letter']?>"  id="my-input" class="form-check-input" type="checkbox" name="access[]"  <?php echo $checked;?>   >
                                                        </div>
                                                        <input type="hidden" name="id" value="<?=$_REQUEST['login']?>">
                                                    </td>                                                                                                   
                                                </tr>
                                            <?php $i++; } ?>
                                        </tbody>                                       
                                    </table>

                                    <button class="btn btn-primary" type="submit">Выдать/Убрать доступы</button>

                                    </form>
                                </div>
                                
                                    
                                                                             
                            </div>
                        <!--end card body-->
                    </div> <!-- end card-->
                </div> <!-- container-fluid -->
            </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>