<?php
/**
 * HTML Change Password Form
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    17-08-2020
 * @edited_by
 * @last_edit_date
 * @todo           Nothing
 */
ob_start();
session_start();
$chain = "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad";
include("validateLogin.php");
include("includeInformation.php");
include("header.php");
?>
<link rel="stylesheet" type="text/css" href="../JScalendar/jquery-ui-timepicker-addon.css" />
<link rel="stylesheet" media="all" href="../JScalendar/jquery-ui.css" />
<?php if($_SESSION["language"]==1){
    ?>
    <script type="text/javascript" src="../JScalendar/jquery-ui.min.Ar.js"></script>
    <script type="text/javascript" src="../JScalendar/jquery-ui-timepicker-addon-Ar.js"></script>
    <?php
}else{
    ?>
    <script type="text/javascript" src="../JScalendar/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../JScalendar/jquery-ui-timepicker-addon.js"></script>
    <?php
}
?>

<!-- Start Dashboard page -->
    <!-- start main-content -->
    <div class="main-content">
        <!-- Start Page-content -->
        <div class="page-content">
        <!-- Page-Title -->
        <div class="page-title-box">
            <div class="container-fluid">
                <div class="row align-items-center">
                    <?php echo breadcrumbs(basename($_SERVER['PHP_SELF']));?>
                </div>
            </div>
        </div>
        <!-- end page title end breadcrumb -->
        <div class="page-content-wrapper">
            <div class="container-fluid">
                <div class="row justify-content-center align-items-center">
                    <div class="col-sm-12 col-lg-4 ">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="mb-5 text-center"><?php echo $archivesDataLBL["sendSearch"];?></h5>
       							 <form action="" name="pageEditForm" id="pageEditForm" method="POST" class="formAlign" >
                                    <div class="row">
                                        <?php
                                        if(!empty($_GET["res"]))
                                            echo result($_GET["res"]);
                                        ?>
                                        <div class="col-md-12">
                                        
                                             <div class="form-group form-group-custom mb-2">
                                            	 <span style="color:#46becf;font-weight:500;padding-bottom:10px;font-size:12px"><?php echo $archivesDataLBL["searchFrom"];?>: </span><br>
                                                <input type="text" class="form-control" name="searchFrom" id="searchFrom" value=<?php if(isset($_POST["searchFrom"])) echo $_POST['searchFrom']; else echo date("m/d/Y")?> onchange="this.setAttribute('value', this.value);">
                                            </div>
                                            <div class="form-group form-group-custom mb-4">
                                            	 <span style="color:#46becf;font-weight:500;padding-bottom:10px;font-size:12px"><?php echo $archivesDataLBL["searchTo"];?>: </span><br>
                                                <input type="text" class="form-control" name="searchTo" id="searchTo" value=<?php if(isset($_POST["searchTo"])) echo $_POST['searchTo']; else echo date("m/d/Y")?> onchange="this.setAttribute('value', this.value);">
                                            </div>
                                            
                                            <div class="form-group form-group-custom mb-2">
                                                <select name="user_Id" id="user_Id"  class="form-control"  style="padding:0px">
                                                <option value=""><?php echo $categoryLBL['select']?></option>
                                                    <?php
													$queryFirstSender = "SELECT `id`,userName FROM `user_login` WHERE id!='1' ORDER BY `id` ASC";
                									$resultFirstSender = mysqli_query($conn, $queryFirstSender);
               										 $senderNum=mysqli_num_rows($resultFirstSender);
													while ($rowsFirstSender = mysqli_fetch_assoc($resultFirstSender)) {
													?>
														<option value="<?php echo $rowsFirstSender['id']; ?>"><?php echo $rowsFirstSender['userName']?></option>
													<?php }?>
                                                </select>
                                             <label for="timeId"><?php echo $archivesDataLBL["userName"]?></label>
                                           </div>
                                           
                                            <div class="mt-4">
                                                <button class="btn btn-success btn-block waves-effect waves-light" type="submit"><?php echo $button["search"]?></button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <br />
                                <?php
								 $dateFirst="";
								if(!empty($_POST['searchFrom'])){
									$dateFirstArr = explode('/',$_POST['searchFrom']);
									$dateFirst=@mktime(0,0,0,$dateFirstArr[0],$dateFirstArr[1],$dateFirstArr[2]);
								}
								$dateLast="";
								if(!empty($_POST['searchTo'])){
									$dateLastArr = explode('/',$_POST['searchTo']);
									$dateLast=@mktime(23,59,59,$dateLastArr[0],$dateLastArr[1],$dateLastArr[2]);	
								}
								$user_Id="";
								$and = "";
								if(!empty($_POST['user_Id'])){
									$user_Id = $_POST['user_Id'];
									$and = "AND id=".$user_Id;
								}
								if(!empty($dateLast) && !empty($dateFirst))
								{
									$query = "select distinct idUser,userName,SUM(`countNumbers`) as sumNumbers,SUM(`points`) as sumPoints from history WHERE `date` >$dateFirst AND `date`<$dateLast $and GROUP BY idUser";
									$result = mysqli_query($conn, $query);
									$num = mysqli_num_rows($result);
								?>
                                <div class="table-responsive">
                                   <table class="table table-bordered">
                                      <thead>
                                         <tr>
                                            <th scope="col"><?php echo $archivesDataLBL["userName"];?></th>
                                            <th scope="col"><?php echo $archivesDataLBL["countNumbers"];?></th>
                                            <th scope="col"><?php echo $archivesDataLBL["countPoints"];?></th>
                                         </tr>
                                      </thead>
                                      <tbody>
                                      <?php
                                        if(!empty($num)) {
                                            while($row=mysqli_fetch_assoc($result))
	  										{
                                        ?>
                                         <tr>
                                            <td><?php echo $row['userName']?></td>
                                            <td><?php echo $row['sumNumbers']?></td>
                                            <td><?php echo $row['sumPoints']?></td>
                                         </tr>
                                         <?php
                                                }
                                            } else {
                                        ?>
                                        <tr>
                                            <td colspan="3" style="text-align:center;font-weight:bold"><?php echo $msgBoxListLBL["noData"];?></td>
                                         </tr>
                                        <?php
                                            }
                                        ?>
                                      </tbody>
                                   </table>
                               </div>
                                <?php
								}?>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end row -->
            </div>
            <!-- end container-fluid -->
        </div>
        <!-- end page-content-wrapper -->
    </div>
        <!-- End Page-content -->
</div>
    <!-- end main content -->
<!-- End Dashboard page -->
<script>
$(document).ready(function() {
	$('#searchFrom').datetimepicker({
		showTimePicker: false,
		showHour: false,
		showMinute: false,
		showSecond: false,
		showTime:false,
		timeFormat: ''
	});
	$('#searchTo').datetimepicker({
		showTimePicker: false,
		showHour: false,
		showMinute: false,
		showSecond: false,
		showTime:false,
		timeFormat: ''
	});
});

</script>
<?php
include("footer.php");
ob_end_flush();
?>
