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

$father = bdr_current_user_id('logout.php');
$user = $father;
$_SESSION['LAST_ACTIVITY'] = time();
$branch = $_SESSION["branch"];
$conn = bdr_database();
$db = $conn;

$canViewAudit = bdr_user_has_privilege($conn, $father, [20, 30, 36]);

?>
<!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>بدر14 لخدمات السيارات</title>
	<link rel="stylesheet" href="css/bootstrap.css"/>
  <link rel="stylesheet" href="css/font-awesome.min.css"/>
	<link rel="stylesheet" href="hj2/humanity.calendars.picker.css">
	<link rel="stylesheet" href="css/myCar.css"/>
  <link rel="stylesheet" href="dist/css/dropzone.css"/>
	<script src="js/jquery.js"></script>
	<script src="js/jquery.autocomplete.js"></script>
	<script src="js/bootstrap.js"></script>
	<script src="hj2/jquery.plugin.js"></script>
	<script src="hj2/jquery.calendars.js"></script>
	<script src="hj2/jquery.calendars.plus.js"></script>
	<script src="hj2/jquery.calendars.picker.js"></script>
	<script src="hj2/jquery.calendars.ummalqura.js"></script>
  <script src="dist/js/dropzone.js"></script>
</head>
<body style="background-color:#000d1a;">
  <div class="container-fluid">
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
              <span class="glyphicon glyphicon-triangle-bottom"></span>
      </button>
				<a href="#" class="navbar-brand">Al-Wesam Cars Rental Company</a>
		</div>
      <div id="navbar" class="collapse navbar-collapse">
			<ul class="nav navbar-nav  navbar-right">
        <li><a href="./customers/customerFlow.php">عملاء<span class="glyphicon glyphicon-user" aria-hidden="true"></span></a></li>
        <li><a href="./customers/companyFlow.php">الشركات<span class="glyphicon glyphicon-modal-window" aria-hidden="true"></span></a></li>
				<li><a href="#">الرئيسية <span class="glyphicon glyphicon-home" aria-hidden="true"></span></a></li>
			</ul>
			<ul class="nav navbar-nav navbar-left">
				<li><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span><?php
        $currentUser = $_SESSION["realName"];
        echo " مرحبا : ".$currentUser.' '.$branch;
        ?></a>
        <ul class="dropdown-menu"style="background: transparent;">
          <div class="row" style="padding:3px;">
            <div class="col-xs-12 col-md-12">
              <button class="btn btn-danger btn-block" type="submit"><a href="logout.php" style="text-decoration:none; color:white">تسجيل خروج</a></button>
              </div>
            </div>
        <div class="row" style="padding:3px;">
          <div class="col-xs-12 col-md-12">
            <button type="button" class="btn btn-primary btn-block" data-toggle="modal" style="float:left;font-weight:bold;" data-backdrop="static" data-keyboard="false" data-target="#reset">كلمة السر</button>
            </div>
          </div>
        <?php if ($canViewAudit): ?>
        <div class="row" style="padding:3px;">
          <div class="col-xs-12 col-md-12">
            <button class="btn btn-info btn-block" type="button"><a href="audit/history.php" style="text-decoration:none; color:white">سجل التعديلات</a></button>
            </div>
          </div>
        <?php endif; ?>
        </ul>
					</li>
			</ul>
      </div><!--/.navbar-collapse -->
	</div>
</nav>
	<p><br/></p>
	<p><br/></p>
		<div class="row" style="padding:1; margin:1;">
      <div class="col-md-2 hidden-print" style='float:right;padding:1; margin:1;'>
					<?php
					$bar_qury = $conn->prepare( 'SELECT arabic , comm , bar_id FROM bar_priv WHERE bar_id in(SELECT bar_id from site_element WHERE element_id in
					 (SELECT element_id from privileges where user_id =?))');
           $bar_qury->bindParam(1,$father);
					 $bar_qury->execute();
					 if($bar_qury->rowCount()>0){?>
						 <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
						 <?php
						 $sam = 'true';
						 $tam = 'One';
						 $i=1;
						 $site_array= array();
					 while($row = $bar_qury->fetch()){
						 $bar_id   = $row["bar_id"];
			       $arabic   = $row["arabic"];
						 $comm     = $row["comm"];
						 switch ($i) {
							 case '1':$tam = 'One';break;
							 case '2':$tam = 'Two';break;
							 case '3':$tam = 'Three';break;
							 case '4':$tam = 'Four';break;
							 case '5':$tam = 'Five';break;
							 case '6':$tam = 'Six';break;
							 case '7':$tam = 'Seven';break;
							 case '8':$tam = 'Eight';break;
							 case '9':$tam = 'Nine';break;
						 }
						 echo "<div class='panel panel-primary'>
               <div class='panel-heading' role='tab' id='heading$tam'>
                 <h6 class='panel-title'>
                   <a role='button' data-toggle='collapse' data-parent='#accordion'
 									href='#collapse$tam' aria-expanded = '$sam' aria-controls='collapse$tam'>
                     <b>$arabic</b>
                   </a>
                 </h6>
               </div>
               <div id='collapse$tam' class='panel-collapse collapse in' role='tabpanel'
 							 aria-labelledby='heading$tam'>
                 <div class='panel-body'style='background-color:#161616;'>
                   <ul class='list-unstyled' style='float:right; padding:0; font-weight:bold;'>
									 ";
									 $item_qury = $conn->prepare( 'SELECT arb_name , element_id, link_ref from site_element WHERE bar_id ='.$bar_id.' AND element_id in
			 						 (select element_id from privileges where yes_no =1 AND user_id = '.$father.')');
									 $item_qury->execute();
							if($item_qury->rowCount()>0){
							while($row = $item_qury->fetch()){
			 						 $element_id   = $row["element_id"];
			 			       $arb_name  = $row["arb_name"];
			 						 $link_ref  = $row["link_ref"];
									$site_array[$element_id]=$link_ref;
						echo "<li style='line-height:1.9em; height: auto;'><a href='#'style='color:#DFECF0;' onclick='myPage($element_id)'>$arb_name</a></li>";
								 }}
								 if($tam === 'Nine' && $canViewAudit){
						echo "<li style='line-height:1.9em; height: auto;'><a href='audit/history.php' style='color:#DFECF0;'>سجل التعديلات</a></li>";
								 }
								 echo "</ul>
                 </div>
               </div>
             </div>";
						 $sam = 'false';
						 $tam = 'Two';
						 $i++;
						 }
						 }
					 ?>
</div>
			</div>
<div class="col-md-10" style="float:right;font-size:0.8em; padding:0px; margin:0;">
  <div class="row">
			<div class="col-md-12" id="signup_msg">
				<!--Alert from signup form-->
			</div>
		</div>
		<div id="site">
<!-- my current site -->
<!-- <iframe id="iframe3" style="background:transparent; border: 0px solid rgb(238, 238, 238); width: 100%; overflow: hidden;font-weight: bold;height: 170px;" src="https://timesprayer.today/widget_frame.php?frame=3&amp;id=23&amp;changecity=false&amp;sound=true&amp;theme=w3-teal"></iframe> -->
<?php
// include "includes/bdr.php";
 ?> 
			<!-- <div class="panel-footer" >stop end</div> -->
			</div>
		</div>
	</div>
</div>
  <!-- <center> -->
  <footer class="footer" >
     <div class="container text-center">
       <h6 class="text-muted">Sameh Deyab &copy;<a href="http://www.BDR14.com/"> www.BDR14.com</a></h6>
     </div>
   </footer>
<!-- </center> -->
<!-- invoice modal -->
<div class="modal fade" id="reset" tabindex="-1" role="dialog" aria-labelledby="exLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header"style="background-color:teal ;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" style="font-weight:bold;color:#FFFAF0; " id="exLabel">تغيير كلمة السر</h4>
      </div>
      <div class="modal-body">
        <form method="post" class="form-horizontal" id="modal_reset" style="float:center;">
          <div id="reset_msg"></div>
            <div class="row" style="padding:4px;">
              <input type="hidden"  class="form-control" id="id2" name="id2" />
              <input type="hidden" id="in_id" name="in_id"/>
                <div class="col-xs-4 col-md-4"style="float:right;">
                  <label for="pass" class="control-label"style="float:left;">كلمة السر الحالية <span class="text-danger">*</span></label>
                </div>
                <div class="col-xs-3 col-md-3"style="float:right;">
                  <input type="password" class="form-control" style="float:right;" id="pass" name="pass"/>
                  <div id="pass_msg" class="text-danger" style="font-size:10px;"></div>
                </div>
            </div>
            <div class="row" style="padding:4px;">
                    <div class="col-xs-4 col-md-4"style="float:right;">
                    <label for="new_pass" class="control-label"style="float:left;">كلمة السر الجديدة</label>
                    </div>
                    <div class="col-xs-3 col-md-3"style="float:right;">
                    <input type="password" class="form-control" style="float:right;" id="new_pass" name="new_pass"/>
                    <div id="new_pass_msg" class="text-danger" style="font-size:12px;"></div>
                    </div>
                    <div class="col-xs-1 col-md-1"style="float:right;">
                      <label for="new_pass2" class="control-label"style="float:left;">تأكيد</label>
                    </div>
                    <div class="col-xs-3 col-md-3"style="float:right;">
                      <input type="password" style="float:right;" class="form-control" id="new_pass2" name="new_pass2" placeholder="تأكيد كلمة السر" />
                      <div id="new_pass2_msg" class="text-danger" style="font-size:12px;"></div>
                    </div>
              </div>
          </form><!-- end of sanad_in form -->
    </div>
      <div class="modal-footer form-group">
        <button type="button" class="btn btn-default" data-dismiss="modal">خروج</button>
        <input type="button" id="save_new" name="save_new" class="btn btn-primary" value="حفظ "/>
        </div>
    </div>
    </div><!-- end of sanad_in modal -->
</div>
 <!-- modal invoice end -->
 <script>
  $(document).ready(function() {
    var s = window.matchMedia("(min-width:0px) and (max-width:550px)");
      isMobile(s);
     s.addListener(isMobile);
  });

  function isMobile(mq) {
  if (mq.matches) {
    window.location.href = 'mobile/home.php';
  }
}
</script>
</body>
</html>
<script>
$("#save_new").click(function(event){
        event.preventDefault();
        $("#reset_msg").html("");
        $("#pass_msg").html("");
        $("#new_pass_msg").html("");
        $("#new_pass2_msg").html("");
    $.ajax({
    url     	: "actions/reset.php",
    method  	: "POST",
    data    	:	$("#modal_reset").serialize(),
    dataType	:	"json",
    success 	: function(data){
      if(data.error){
    $("#reset_msg").html(data.error.reset);
    $("#pass_msg").html(data.error.pass);
    $("#new_pass_msg").html(data.error.new_pass);
    $("#new_pass2_msg").html(data.error.new_pass2);
    }else{
  $("#reset_msg").html(data.reset);
  $("#reset_msg").delay(3000).slideUp(function(){  $("#reset_msg").html(''); });
}}
  });
});
function myPage(pg){
			var book = <?php echo json_encode($site_array) ?>;
		$('#site').load(book[pg]);
		}

</script>
