<?php
require_once __DIR__ . '/../magic/auth.php';

$auth = bdr_require_privilege([20, 36, 30], '../logout.php');
$user = $auth['user_id'];
$father = $auth['user_id'];
$branch = $auth['branch'];
$conn = $auth['conn'];
$db = $auth['conn'];

require_once "../op/wanted.php";

//check if accountant of Oprearation manager
$role = 0;
$roleQuery = $conn->prepare('SELECT role FROM users WHERE user_id = ? LIMIT 1');
$roleQuery->execute([$father]);
if ($row = $roleQuery->fetch()) {
  $role = $row['role'];
}
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="robots" content="index,follow">
  <meta name="author" content="سامح دياب">
  <link rel="icon" href="../images/perfect.ico">
  <title>العقود السارية </title>
  <link rel="stylesheet" href="../dist/css/bootstrap.css" />
  <link rel="stylesheet" href="../css/font-awesome.min.css" />
  <link rel="stylesheet" href="myCar.css" />
  <script src="../js/jquery.js"></script>
  <script src="../dist/js/umd/popper.min.js"></script>
  <script src="../dist/js/bootstrap.js"></script>
</head>

<body style="background-color:#003300 ; color:#cce5ff;">
  <div class="navbar navbar-inverse bg-inverse bg-faded sticky-top">
    <div class="container-fluid">
      <div class="row">
        <div class="col">
          <div class="btn-group btn-group-lg" style="font-weight:bold;padding:5px;" role="group" aria-label="...">
            <button type="button" id="home" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-success">اليوم</button>
            <button type="button" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-info">ساري</button>
            <button type="button" id="debt_contracts" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-danger">مديون</button>
            <button type="button" id="car_search" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-secondary">بحث سيارة </button>
            <?php
            if ($role == 1) {
              echo '<button type="button" id="log" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-outline-success">سجلات</button>';
            }
            ?>
          </div>
        </div>
      </div>
    </div>
  </div>
  <br />
  <!-- <div class="container-fluid"> -->
  <?php $output = '';
  $sql = $conn->prepare("SELECT * from `log` WHERE 1 order by logid DESC LIMIT 50");
  $sql->execute();
  if ($sql->rowCount() > 0) {
    while ($row = $sql->fetch()) {
      $smart_com    = $row['smart_com'];
      $contract_id   = $row['contract_id'];
      $audate   = $row['audate'];
      $mmm = new DateTime($audate);
      $audate =  $mmm->format("Y-m-d");
      $output .= '<div class="card text-center card-inverse " style="background-color: #1a1a1a; border-color: #333;">
                <div class="card-header">
                    <h4 class="card-title" style="font-weight:bold;font-size:2rem;color:#cfd8dc"> ' . $contract_id . ' # # ' . $audate . '</h4>
                </div>
                 <div class="card-block" style="background-color: #333; border-color: #3d5c5c;">';
      $output .= '<p class="card-text" style="font-weight:bold;line-height:30px; font-size:1.9rem;color:#cfd8dc">' . $smart_com . '</p>';
      $output .= '</div></div><br />';
    }
  } else {
    $output .= '<p class="card-text" style="font-weight:bold; font-size:1.8rem;">لا توجد سجلات </p>';
  }
  echo $output; ?>
  <script>
    $(document).ready(function() {
      $("#home").click(function(event) {
        event.preventDefault();
        var myday = $("#myday").val();
        window.open("home.php", '_self');
      });

      $("#debt_contracts").click(function(event) {
        event.preventDefault();
        window.open("debt_contracts.php", '_self');
      });

      $("#car_search").click(function(event) {
        event.preventDefault();
        window.open("car_search.php", '_self');
      });
      $("#log").click(function(event) {
        event.preventDefault();
        window.open("log_manager.php", '_self');
      });

    });
  </script>
  <!-- </div> -->
</body>

</html
