<?php include("homeheader.php");?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap -->
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="../vendors/iCheck/skins/flat/green.css" rel="stylesheet">
    <!-- Datatables -->
    <link href="../vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="../vendors/datatables.net-buttons-bs/css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="../vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="../vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="../vendors/datatables.net-scroller-bs/css/scroller.bootstrap.min.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="../css/custom.css" rel="stylesheet">
  </head>
  <body>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
	  
	    <?php 
			$user = $dat['company'];
			$qry=mysql_query("select * from airtime_admin where username='$user' and account='Mobisky' ");
			
			if(mysql_num_rows($qry)> 0){
				?>
	    <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            <!--div class="navbar nav_title" style="border: 0;">
              <a href="index.html" class="site_title">
			    <div class="profile_pic" style="margin-top:-10px;">
					<img src="../images/mlogo.png" alt="" class="img-circle profile_img" />
			    </div>
			        <span>Instant Airtime </span>
            </div>
            <div class="clearfix"></div-->
            
            <!-- menu profile quick info -->
            <div class="profile">
              <div class="profile_pic">
			    <?php 
			  if($img == ""){
				  ?>
				   <img src="../profileimages/noimage.gif" alt="..." class="img-circle profile_img">
				  <?php
			  }else{
				?>
				 <img src="<?php echo $photo ?>" alt="..." class="img-circle profile_img" width="40px;" height="60px;">
            <?php				
			  }
			  ?>
              </div>
              <div class="profile_info">
                <span>Mobisky Admin </span>
				<h2> <?php $fname = $dat['fname']; $lname = $dat['lname']; echo $fname." ".$lname ?> </h2>
             <!--   <h2>John Doe</h2> -->
              </div>
            </div>
            <!-- /menu profile quick info -->
            <br/>	
				  <!-- sidebar menu -->
            <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
              <div class="menu_section">
			  
     
            	 <?php include("sidebar.php"); ?>
              </div>
            </div>
			<!--end side menubar -->
			</div>
        </div>
		
		 <?php include("admintopmenubar.php"); ?>
		 
			 <!-- page content -->
        <div class="right_col" role="main">
		  <!-- /top navigation -->
		     <div class="row">
          <!-- top tiles -->
          <div class="row tile_count">
            <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
              <p>Airtime Portal </p>
            </div>
            
          </div>
		  </div>
          <!-- /top tiles -->
		 
		 <div class="row">
		 
		 <!-- users table -->
		 
		       <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>System Admins List  </h2>
					<a href="addnewadmin.php"> <button class="btn btn-success pull-right" > Add New Admin </button>  </a>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                     <table id="datatable" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>Account For</th>
                          <th>Company</th>
                          <th>Contact</th>
                          <th>Email</th>
						  <th>Status</th>
                        </tr>
                      </thead>
                      <tbody>
                      <?php
					  $sql = "select * from airtime_customer where user_type='Admin' and customer_id !='$session_id' ";
					  $result = mysql_query($sql);
					   while($row = mysql_fetch_array($result)) {
						   $id= $row['customer_id'];
						   $Fname= $row['fname'];
						   $Lname= $row['lname'];
						   $name=$Fname." ".$Lname;
						   $pne= $row['phone'];
						   $em= $row['email'];
						   $comp= $row['company'];
						   $sts= $row['status'];
						   
							
                       echo "<tr>";
				        echo '<td>' . $name . '</td>';
				        echo '<td>' . $row['company']. '</td>';
                        echo '<td>' . $row['phone']. '</td>';
				       echo '<td>' .  $row['email'] . '</td>';
					   ?> 
					   <td>

	<!--<a href="viewuserlogs.php">  <button class=" pull-left " style="margin-left:20px;" ><i class="fa fa-th"> </i> </button> </a>-->

<a rel="facebox" class = "btn btn-primary" href="viewuserlogs.php?customer_id=<?php echo $row['customer_id']; ?>">
                                                <i class="fa fa-pencil">Activity Logs</i>  
                                            </a>  

					   <button class="btn btn-primary" > <?php echo $sts ?> </button> </td>
					   <?php
				
				       }  
                       echo "</table>";
					  
					  ?>  
                       
                       
                        
                      </tbody>
                    </table>
                  </div>
                </div>
				
				<form method="post"	>
				<div class="x_panel">
                  <div class="x_title">
				   <label class="control-label col-md-3 col-sm-3 col-xs-12">Block or Unblock Admin</label>
				      <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Select Admin:</label>
                        <div class="col-md-3 col-sm-3 col-xs-3">
                          <select class="form-control"  name="user" required>
                            <option value="">Choose Admin</option>
							<?php
									 $sql = "select * from airtime_customer where user_type='Admin' and customer_id !='$session_id' order by fname desc";
								  $s=mysql_query($sql);
								  	while ($grp = mysql_fetch_array($s)){
													echo ' <option value="'.$grp['customer_id'].'">'.$grp['fname']." ".$grp['lname'].'</option>';
												}
							
							?>
                          </select>
                        </div>
                      </div>
				  <br/>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
				    <div class="col-md-3 col-sm-3 col-xs-3">
                          <button type="submit" style="margin-top:20px;" class="btn btn-primary " name="blockuser">Block Admin</button>  
                    </div>
						<div class="col-md-3 col-sm-3 col-xs-3">
							<button type="submit" style="margin-top:20px;" class="btn btn-primary " name="unblockUser">Unblock Admin</button>  
					  </div>
				  </div>
				</div>
		    </form>
		  
		  <?php 
		      if(isset($_POST['blockuser'])){
				 $cid=$_POST['user'];
				 
				 if(!empty($_POST['user']) ){
					 
					$s=mysql_query("select * from airtime_customer where customer_id='$cid' ");
					$cdt=mysql_fetch_array($s);
					$fname = $cdt['fname'];
					$lname = $cdt['lname'];
					$name = $fname." ".$lname;
					
					if($cdt['status'] == "Blocked"){
						?>
						<script>
							alert("Admin is already Blocked. Do you want to unblock this Admin?");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						$query = mysql_query("update airtime_customer set status='Blocked' where customer_id='$cid'");
						if($query){
							 $qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
							$sdata=mysql_fetch_array($qry2);				
							$actions = $sdata['user_actions'];
							mysql_query("update airtime_logs set user_actions='$actions Blocked Admin id - $cid, Name - $name.' where id='$session_lid'  ");
						?>
						<script>
							alert("Admin Blocked Successfully.");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						?>
						<script>
							alert("Error Blocking this Admin! Please try again.");
							window.location="viewadmins.php";
						</script>
					<?php
					}
					
					}	
		
				}else{
					?>
					<script>
					alert("Error! Select Admin to block.");
					</script>
					<?php
				}
				  
			 }
			 
			 if(isset($_POST['unblockUser'])){
				 $cid=$_POST['user'];
				 
				 if(!empty($_POST['user']) ){
					 
					$s=mysql_query("select * from airtime_customer where customer_id='$cid' ");
					$cdt=mysql_fetch_array($s);
					$fname = $cdt['fname'];
					$lname = $cdt['lname'];
					$name = $fname." ".$lname;
					
					if($cdt['status'] == "Active"){
						?>
						<script>
							alert("This Admin is already Active. Do you want to block this Admin?");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						$query = mysql_query("update airtime_customer set status='Active' where customer_id='$cid'");
						if($query){
							 $qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
							$sdata=mysql_fetch_array($qry2);				
							$actions = $sdata['user_actions'];
							mysql_query("update airtime_logs set user_actions='$actions Activated Admin id - $cid, Name - $name.' where id='$session_lid'  ");
						?>
						<script>
							alert("Admin Activated Successfully.");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						?>
						<script>
							alert("Error Activating this Admin! Please try again.");
							window.location="viewadmins.php";
						</script>
					<?php
					}
					
					}	
		
				}else{
					?>
					<script>
					alert("Error! Select Admin to block.");
					</script>
					<?php
				}
				 
				 
			 }
		  ?>
				
				
              </div>
		 <!-- end admins table -->
		  </div>
		  </div>
		 
		 
		
			<?php	
			}
			else{
				?>
				 <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            <!--div class="navbar nav_title" style="border: 0;">
              <a href="index.html" class="site_title">
			  <div class="profile_pic" style="margin-top:-10px;">
			  <img src="../images/mlogo.png" alt="" class="img-circle profile_img" />
			    </div>
		            <span>Instant Airtime </span>
            </div>

            <div class="clearfix"></div-->

			
            <!-- menu profile quick info -->
            <div class="profile">
              <div class="profile_pic">
			     <?php 
			  if($img == ""){
				  ?>
				   <img src="../profileimages/noimage.gif" alt="..." class="img-circle profile_img">
				  <?php
			  }else{
				?>
				 <img src="<?php echo $photo ?>" alt="..." class="img-circle profile_img" width="40px;" height="60px;">
            <?php				
			  }
			  ?>
              </div>
             <div class="profile_info">

                <span>Admin </span>
				<h2> <?php $fname = $dat['fname']; $lname = $dat['lname']; echo $fname." ".$lname ?> </h2>
             <!--   <h2>John Doe</h2> -->
              </div>
            </div>
            <!-- /menu profile quick info -->

            <br />

            <!-- sidebar menu -->
          <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
              <div class="menu_section">
			  
                <h3>General</h3>
                <ul class="nav side-menu">
                  <li ><a  href="adminpage.php" ><i class="fa fa-home"></i>  Home <span class="fa fa-chevron-right"></span></a> </li>
                   <li><a href="#">  Users <span class="fa fa-chevron-down"></span></a> 
				  <ul class="nav child_menu">
					    <li><a  href="adduser.php" ><i class="fa fa-bug"></i>Create User<span class="fa fa-chevron-right"></span></a> </li>
						<li class="active"><a  href="viewuser.php" ><i class="fa fa-edit"></i>View Users<span class="fa fa-chevron-down"></span></a> </li>
					   </ul>
				  </li>
                  <li><a href="contacts.php">  View Contacts <span class="fa fa-chevron-right"></span> </a> </li>
                  <li><a href="groups.php"> View Groups  <span class="fa fa-chevron-right"></span> </a>   </li>
                  <!--li><a href="requests.php">Topup Requests  <span class="fa fa-chevron-right"></span> </a>   </li>
                 <li><a href="topupaccount.php">Topup My account <span class="fa fa-chevron-right"></span> </a>   </li>
				 <li><a> Reports <span class="fa fa-chevron-down"></span></a>  
					   <ul class="nav child_menu">
					    <li><a  href="buyinghistory.php" > Purchase History <span class="fa fa-chevron-right"></span> </a> </li>
						<li><a  href="sendinghistory.php" > Sending History <span class="fa fa-chevron-right"></span> </a></li>
					   </ul>
				   </li-->
                </ul>
              </div>

            </div>
			 </div>
        </div>
		 <?php include("topmenubar.php");   ?>
		 
			 <!-- page content -->
        <div class="right_col" role="main">
		  <!-- /top navigation -->
		     <div class="row">
          <!-- top tiles -->
          <div class="row tile_count">
            <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
              <p>Airtime Portal </p>
            </div>
            
          </div>
		  </div>
          <!-- /top tiles -->
		 
		 <div class="row">
		 
		 <!-- users table -->
		 
		       <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Account Admins List  </h2>
					<a href="newadmin.php"> <button class="btn btn-success pull-right" > Add New Admin </button>  </a>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                     <table id="datatable" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>First Name</th>
                          <th>Last Name</th>
                          <th>Username</th>
                          <th>Contact</th>
                          <th>Email</th>
						  <th> No. of Groups </th>
						  <th> Status </th>
                        </tr>
                      </thead>
                      <tbody>
                      <?php
					   $frm  = $dat['company'];
					  $sql = "select * from airtime_customer where user_type='Admin' and company='$frm' ";
					  $result = mysql_query($sql);
					   while($row = mysql_fetch_array($result)) {
						   $id= $row['customer_id'];
						  
						   $Fname= $row['fname'];
						   $Lname= $row['lname'];
						   $pne= $row['phone'];
						   $em= $row['email'];
						   $gr= $row['username'];
						   $sts= $row['status'];
						   
						   $s = mysql_query("select * from airtime_groups where customer_id='$id'  ");
						   $rst = mysql_fetch_assoc($s);
						    $gid =  $rst['group_id'];
							$numrows = mysql_num_rows($s);
							$name =  $rst['name'];
							$cid = $rst['customer_id'];
							
                       echo "<tr>";
				        echo '<td>' . $row['fname'] . '</td>';
				        echo '<td>' . $row['lname'] . '</td>';
                        echo '<td>' . $row['username'] . '</td>';
				       echo '<td>' .  $row['phone'] . '</td>';
				       echo '<td>' .  $row['email'] . '</td>';
					   ?>
					   <td> <?php echo $numrows  ?>
					       <a rel="tooltip" title="View Users" id="<?php echo  $gid ?>" href="#view<?php echo  $gid ?>" data-toggle="modal" ><i class='fa fa-eye fa-lg'></i>  </a>
					     <?php include('users.php'); ?>
						 </td> 
						   
					   <td> <button class="btn btn-primary" > <?php echo $sts ?> </button> </td>
					   <?php
				
				       }  
                       echo "</table>";
					  
					  ?>  
                       
                       
                        
                      </tbody>
                    </table>
                  </div>
                </div>
				
				<form method="post"	>
				<div class="x_panel">
                  <div class="x_title">
				   <label class="control-label col-md-3 col-sm-3 col-xs-12">Block or Unblock Admin</label>
				      <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Select Admin:</label>
                        <div class="col-md-3 col-sm-3 col-xs-3">
                          <select class="form-control"  name="user" required>
                            <option value="">Choose Admin</option>
							<?php
							 $frm  = $dat['company'];
									 $sql = "select * from airtime_customer where company='$frm' and user_type='Admin' order by fname desc";
								  $s=mysql_query($sql);
								  	while ($grp = mysql_fetch_array($s)){
													echo ' <option value="'.$grp['customer_id'].'">'.$grp['fname']." ".$grp['lname'].'</option>';
												}
							
							?>
                          </select>
                        </div>
                      </div>
				  <br/>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
				    <div class="col-md-3 col-sm-3 col-xs-3">
                          <button type="submit" style="margin-top:20px;" class="btn btn-primary " name="blockuser">Block Admin</button>  
                    </div>
						<div class="col-md-3 col-sm-3 col-xs-3">
							<button type="submit" style="margin-top:20px;" class="btn btn-primary " name="unblockUser">Unblock Admin</button>  
					  </div>
				  </div>
				</div>
		    </form>
		  
		  <?php 
		      if(isset($_POST['blockuser'])){
				 $cid=$_POST['user'];
				 
				 if(!empty($_POST['user']) ){
					 
					$s=mysql_query("select * from airtime_customer where customer_id='$cid' ");
					$cdt=mysql_fetch_array($s);
					$fname = $cdt['fname'];
					$lname = $cdt['lname'];
					$name = $fname." ".$lname;
					
					if($cdt['status'] == "Blocked"){
						?>
						<script>
							alert("Admin is already Blocked. Do you want to unblock this Admin?");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						$query = mysql_query("update airtime_customer set status='Blocked' where customer_id='$cid'");
						if($query){
							 $qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
							$sdata=mysql_fetch_array($qry2);				
							$actions = $sdata['user_actions'];
							mysql_query("update airtime_logs set user_actions='$actions Blocked Admin id - $cid, Name - $name.' where id='$session_lid'  ");
						?>
						<script>
							alert("Admin Blocked Successfully.");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						?>
						<script>
							alert("Error Blocking this Admin! Please try again.");
							window.location="viewadmins.php";
						</script>
					<?php
					}
					
					}	
		
				}else{
					?>
					<script>
					alert("Error! Select Admin to block.");
					</script>
					<?php
				}
				  
			 }
			 
			 if(isset($_POST['unblockUser'])){
				 $cid=$_POST['user'];
				 
				 if(!empty($_POST['user']) ){
					 
					$s=mysql_query("select * from airtime_customer where customer_id='$cid' ");
					$cdt=mysql_fetch_array($s);
					$fname = $cdt['fname'];
					$lname = $cdt['lname'];
					$name = $fname." ".$lname;
					
					if($cdt['status'] == "Active"){
						?>
						<script>
							alert("This Admin is already Active. Do you want to block this Admin?");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						$query = mysql_query("update airtime_customer set status='Active' where customer_id='$cid'");
						if($query){
							 $qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
							$sdata=mysql_fetch_array($qry2);				
							$actions = $sdata['user_actions'];
							mysql_query("update airtime_logs set user_actions='$actions Activated Admin id - $cid, Name - $name.' where id='$session_lid'  ");
						?>
						<script>
							alert("Admin Activated Successfully.");
							window.location="viewadmins.php";
						</script>
					<?php
					}else{
						?>
						<script>
							alert("Error Activating this Admin! Please try again.");
							window.location="viewadmins.php";
						</script>
					<?php
					}
					
					}	
		
				}else{
					?>
					<script>
					alert("Error! Select Admin to block.");
					</script>
					<?php
				}
				 
				 
			 }
		  ?>
				
				
              </div>
		 <!-- end admins table -->
		  </div>
		  </div>
		 
		 
		
			<?php	
			}
	?>
	  
       
		
		
		
		  
		 </div>
		  </div>  
		          <!-- /page content. End of main -->

     <?php include("footerlinks.php"); ?>
	 
	   <!-- jQuery -->
    <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="../vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="../vendors/nprogress/nprogress.js"></script>
    <!-- Datatables -->
    <script src="../vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="../vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="../vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="../vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="../vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="../vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="../vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="../vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    <script src="../vendors/jszip/dist/jszip.min.js"></script>
    <script src="../vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="../vendors/pdfmake/build/vfs_fonts.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="../js/custom.js"></script>

    <!-- Datatables -->
    <script>
      $(document).ready(function() {
        var handleDataTableButtons = function() {
          if ($("#datatable-buttons").length) {
            $("#datatable-buttons").DataTable({
              dom: "Bfrtip",
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
          }
        };

        TableManageButtons = function() {
          "use strict";
          return {
            init: function() {
              handleDataTableButtons();
            }
          };
        }();

        $('#datatable').dataTable();
        $('#datatable-keytable').DataTable({
          keys: true
        });

        $('#datatable-responsive').DataTable();

        $('#datatable-scroller').DataTable({
          ajax: "js/datatables/json/scroller-demo.json",
          deferRender: true,
          scrollY: 380,
          scrollCollapse: true,
          scroller: true
        });

        var table = $('#datatable-fixed-header').DataTable({
          fixedHeader: true
        });

        TableManageButtons.init();
      });
    </script>
    <!-- /Datatables -->
  </body>
</html>