<?php
/**
 * Data Grid Page Example
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    18-08-2020
 * @edited_by
 * @last_edit_date
 * @todo           Nothing
 */
 
ob_start();
session_start();
$chain = "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad";
$dataTable=true;
include("validateLogin.php");
include("includeInformation.php");
include("header.php");
unset($_SESSION['userCatId']);
unset($_SESSION['userNumId']);
unset($_SESSION['GetCatZeyad']);
$_SESSION['GetCatZeyad']=array();
?>
<!-- start main-content -->
<script>
function fun2(varObjID2)
{
	if(document.getElementById(varObjID2).style.display=='none')
		document.getElementById(varObjID2).style.display='block';
	else
		document.getElementById(varObjID2).style.display='none';
}
function pageing(url,start)
{
	document.formUsersList.start.value=start;
	document.formUsersList.action =url;
	document.formUsersList.submit();
}
function fetchDate(id)
{
	$.post("fetchUserData.php",{ id:id,rand:Math.random() } ,function(res){
		data=res.split('#$#');
		$("#detailFullName").html(data[0]);
		$("#f1").html(data[0]);
		$("#f2").html(data[1]);
		$("#f3").html(data[2]);
		$("#f4").html(data[3]);
		$("#f5").html(data[4]);
		$("#f6").html(data[5]);
		$("#f7").html(data[6]);
		$("#f8").html(data[7]);
		$("#f9").html(data[8]);
	});
	$('#detailViewModal').modal('show');
}
function fetchDate2(id)
{
	$.post("fetchUserData.php",{ id:id,rand:Math.random() } ,function(res){
		data=res.split('#$#');
		
		$("#f11").val(data[0]);
		$("#editFullName").html(data[1]);
		$("#f12").html(data[1]);
		$("#f13").html(data[2]);
		$("#f14").val(data[3]);
		$("#f15").val(data[4]);
		$("#f16").val(data[5]);
		$("#f17").val(data[6]);
		$("#idUser").val(id);
	});
	$('#editModal').modal('show');
}
function fetchDate4(id)
{
	$("#chargeFalse28").hide();
	$("#chargeTrue28").hide();
	/*$("#allowChangeSender").prop('checked','');*/
	/*$("#specifyNumber").prop('checked','');*/			
	$("#number").val('');
	$("#sender").val('');
	
	$("#idUser28").val(id);
	$.post("fetchUserData3.php",{ id:id,rand:Math.random() } ,function(res){
		enabledDirectSend = true;
		data=res.split('#$#'); 
		if(data[1]==1)
			$("#allowChangeSender1").attr('checked','checked');
		else
			$("#allowChangeSender0").attr('checked','');
		
		if(data[2]==1)
			$("#specifyNumber1").attr('checked','checked');
		else
			$("#specifyNumber0").attr('checked','');
		 
		$("#sender").html(data[0]);
		$("#number").val(data[3]);

		
	});
	$('#settingsModal').modal('show');
}
function fetchDate22(id)
{
	$("#idUser2").val(id);
	$.post("fetchUserData.php",{ id:id,rand:Math.random() } ,function(res){
		data=res.split('#$#');
		$("#changePasswordFullName").html(data[0]);
	});
	$('#changePasswordModal').modal('show');
}
function checkDelete(url)
{
	var result = confirm("<?php echo $confirmAlert;?>");
	if (result==true) {
		self.location.href = url;
	}
}
</script>
<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 -->
        <?php
		$start = 0;
		if(!empty($_REQUEST['start']))
		$start=(int) $_REQUEST['start'];

		$numberResult = 25;
		$url="users.php";
		$queryNewUser = "SELECT id, fullName, userName, password, mobile, email,fatherId,account,accountOriginal,`date`,`block`";
		$queryNewUser.= " FROM `user_login` ";
		$queryNewUser.= " WHERE  power!='*'";
		$queryPagingAdd = "";
		
		if(!empty($_POST['searchType']) && !empty($_POST['searchValue'])) {
			$searchValue = trim($_POST['searchValue']);
			$searchType = trim($_POST['searchType']);
			$queryNewUser.= " AND $searchType LIKE ('$searchValue%')";
			$queryPagingAdd = " AND $searchType LIKE ('$searchValue%')";
		}
		$queryNewUser.= " ORDER BY `id` DESC";
		$queryNewUser.= " LIMIT $start, $numberResult";
		$resultNewUser = mysqli_query($conn, $queryNewUser);
		$numNewUser=mysqli_num_rows($resultNewUser);
		$numCounter=$numNewUser;
        ?>  
        <div class="page-content-wrapper">
            <div class="container-fluid">
                <div class="row justify-content-center align-items-center table-hover">
                    <div class="col-12">
                        <div class="card">
                        <?php
					if(!empty($_GET["res"]))
						echo result($_GET["res"]);
					?>
						<form  name="formUsersList" method="post" style="margin:0px">
                            <div class="card-body">
                               <div class="btn-collection-top">
                               		<button type="button" title="<?php echo $usersLBL["addUser"]; ?> " data-toggle="modal" data-target="#addModModal" class="btn bg-primary btn-sm btn-flat text-white m-1"><i class="fas fa-plus"></i> <?php echo $usersLBL["addUser"]; ?></button>
                               		<button type="button" title="<?php echo $usersLBL["searchUser"]; ?>" data-toggle="modal" data-target="#searchModal" class="btn bg-primary btn-sm btn-flat text-white m-1"><i class="fas fa-search"></i> <?php echo $usersLBL["searchUser"]; ?></button>
                                    <!--<button type="button" title="<?php echo $usersLBL["searchUserNumbers"]; ?>" data-toggle="modal" data-target="#searchModal" class="btn bg-primary btn-sm btn-flat text-white m-1"><i class="fas fa-search"></i> <?php echo $usersLBL["searchUserNumbers"]; ?></button>-->
                               </div>
                               <div class="table-responsive">
                                   <table class="table table-bordered">
                                   	<?php
									if(!empty($numNewUser)) {
									?>
                                      <thead>
                                         <tr>
                                            <th scope="col"><?php echo $usersLBL["fullname"];?></th>
                                            <th scope="col"><?php echo $usersLBL["userName"];?></th>
                                            <th scope="col"><?php echo $usersLBL["balanceDetail"];?></th>
                                            <th scope="col"><?php echo $usersLBL["regDate"];?></th>
                                            <th scope="col" style="text-align:center"><?php echo $dataGtidLBL["operations"];?></th>
                                         </tr>
                                      </thead>
                                      <tbody>
                                      <?php
                                            while($rowNewUser=mysqli_fetch_row($resultNewUser)) {
                                        ?>
                                         <tr>
                                            <td><?php echo $rowNewUser[1]?></td>
                                            <td><?php echo $rowNewUser[2]?></td>
                                            <td><?php echo $rowNewUser[7]."/".$rowNewUser[8]?></td>
                                            <td><?php if(!empty($rowNewUser[9])) echo date('d-m-Y',$rowNewUser[9])?></td>
                                            <td align="center">
                                            <a href="javascript:fetchDate('<?php echo $rowNewUser[0]?>');"><i class="fas fa-2x fa-file-alt" title="<?php echo $usersLBL["detailView"];?>"></i></a>&nbsp;
                                            <a href="javascript:fetchDate4('<?php echo $rowNewUser[0]?>');"><i class="fas fa-2x fa-tools" title="<?php echo $usersLBL["settings"];?>"></i></a>&nbsp;
                                            <a href="javascript:fetchDate3('<?php echo $rowNewUser[0]?>');"><i class="fas fa-2x fa-money-check-alt" title="<?php echo $usersLBL["balance"];?>"></i></a>&nbsp;
                                            <a href="javascript:fetchDate22('<?php echo $rowNewUser[0]?>');"><i class="fas fa-user-lock" title="<?php echo $usersLBL["changePassword"];?>"></i></a>&nbsp;
                                            <a href="javascript:fetchDate2('<?php echo $rowNewUser[0]?>');"><i class="fas fa-2x fa-edit" title="<?php echo $button["edit"];?>"></i></a> &nbsp;
                                            <?php
											if($rowNewUser[10]=='0') {
											?>
                                            <a href="javascript:checkDelete('userDelete.php?idUser=<?php echo $rowNewUser[0]?>');"> <i class="fas fa-2x fa-eye" title="<?php echo $usersLBL["clickToBlock"];?>"></i></a>&nbsp;
                                            <?php } else {
											?>
                                            <a href="#"><i class="fas fa-2x fa-eye-slash" title="<?php echo $usersLBL["clickToActive"];?>" onclick="checkDelete('userReactivate.php?idUser=<?php echo $rowNewUser[0]?>');" style="cursor:pointer"></i></a>&nbsp;
                                            <?php
											}
											?>
                                            
                                            </td>
                                         </tr>
                                         <?php
                                                }
                                            ?>
                                      </tbody>
                                      <?php
                                      } else {
                                        ?>
                                        <tr>
                                            <td colspan="12" style="text-align:center;font-weight:bold"><?php echo $tempMsgLBL["noData"];?></td>
                                            
                                         </tr>
                                        <?php
                                            }
                                        ?>
                                   </table>
                               </div>
                               
                               <div class="row">
                                  <div class="col-sm-12 col-md-12">
                                  <?php
									$select  =" SELECT count(id) from user_login where power!='*' $queryPagingAdd";	
									pagingView($select,$start,$numberResult);
									?> 
                                  </div>
                               </div>
                               <div class="btn-collection-top">
                               		<button type="button" title="<?php echo $usersLBL["addUser"]; ?> " data-toggle="modal" data-target="#addModModal" class="btn bg-primary btn-sm btn-flat text-white m-1"><i class="fas fa-plus"></i> <?php echo $usersLBL["addUser"]; ?></button>
                               		<button type="button" title="<?php echo $usersLBL["searchUser"]; ?>" data-toggle="modal" data-target="#searchModal" class="btn bg-primary btn-sm btn-flat text-white m-1"><i class="fas fa-search"></i> <?php echo $usersLBL["searchUser"]; ?></button>
                                    <!--<button type="button" title="<?php echo $usersLBL["searchUserNumbers"]; ?>" data-toggle="modal" data-target="#searchModal" class="btn bg-primary btn-sm btn-flat text-white m-1"><i class="fas fa-search"></i> <?php echo $usersLBL["searchUserNumbers"]; ?></button>-->
                               </div>
                            </div>
                              <input type=hidden name=start value='<?php echo $start?>'>
                                <input type=hidden name=counter value='<?php echo $numCounter?>'>
                                <input type=hidden name=idTemp value='<?php //echo $idTemp?>'>
                            </form>
                        </div>
                    </div> <!-- end col -->
                </div>
                <!-- end row -->
                </div>
                <!-- end container-fluid -->
            </div>
            <!-- end page-content-wrapper -->
        </div>
        <!-- End Page-content -->
    </div>
    <!-- end main content -->

<!--  addMod Modal -->
<?php include("usersModalAdd.php");?>
<!--  addMod Modal -->

<!--  search Modal -->
<?php include("usersModalSearch.php");?>
<!--  search Modal -->

<!--  addMod Modal -->
<?php include("usersModalEdit.php");?>
<!--  addMod Modal -->

<!--  detailView Modal -->
<?php include("usersModalDetails.php");?>
<!--  detailView Modal -->

 <!--  settings Modal -->
<?php include("usersModalSettings.php");?>
 <!--  settings Modal -->

<!--  balance Modal -->
<?php include("usersModalBalance.php");?>
<!--  balance Modal -->

<!--  addMod Modal -->
<?php include("usersModalChangePassword.php");?>
<!--  addMod Modal -->


 <script>
function fetchDate3(id)
{
	$("#chargeFalse").hide();
	$("#chargeTrue").hide();
	$("#lastCharge").html("");
	$.post("fetchUserData2.php",{ id:id,rand:Math.random() } ,function(res){
		data=res.split('#$#');
		$("#fullName").html(data[0]);
		$("#userName").html(data[1]);
		$("#mobile").html(data[2]);
		$("#email").html(data[3]);
		$("#idUser22").val(id);
		$("#balanceFullName").html(data[0]);
		if(data[6] != ""){
			$("#lastCharge").html(data[6]);
			$("#lastChargeDiv").show();
		}
		
	});
	$('#balanceModal').modal('show');
}
 $(document).ready(function(){
	 $("#checkAll").click(function(){
		 if($("#checkAll").is(":checked")){
			$("#unCheckAll").prop('checked',false);
			$("input[name='categoryId[]']").prop('checked',true);	 
		 }else{
			 $("input[name='categoryId[]']").prop('checked',false);	 
		 }

	 });
	 $("#unCheckAll").click(function(){
		 if($("#unCheckAll").is(":checked")){
			 $("#checkAll").prop('checked',false);
			 $("input[name='categoryId[]']").prop('checked',false);
		 }else{
			 $("input[name='categoryId[]']").prop('checked',false);	 
		 }
	 });
 });
 </script>
<?php
include("footer.php");
ob_end_flush();
?>
