<?php
   include_once("../include/main.inc.php");
   check_session('MyCpanel','index.php');
   
   ################ Paging Starts From Here ##################
   @extract($_REQUEST);
   if($parentID=="") {
   	$parentID=1;
   }
   $heading="Manage Sub Admin";
   $record_type="Sub Admin";
   $script_name="manage_user.php";
   $table_name="admin_details";
   
   if($id=="add_record") {
  
	$sql=db_query("insert into $table_name set name='$uname', user_id='$uid', pwd='$upass', email='$uemail', phone='$unum', user_type='user'");
   		
   $_SESSION['session_message']='
   <div class="btn btn-success">New '.$record_type.' has been added successfully</div>';
  header("Location: ".SITE_ADMIN_URL."/".$script_name);
  exit;
   	}
   	
   if($id=="update_record") {
 
	updateTable($table_name,"name='$uname', user_id='$uid', pwd='$upass', email='$uemail', phone='$unum' where slno='$recordID'");
   		
   		$_SESSION['session_message']='
   <div class="btn btn-success">'.$record_type.' has been updated successfully</div>';
   		header("Location: ".SITE_ADMIN_URL."/".$script_name);
   		exit;
   	}
	
   if($id=="status_record") {
	updateTable($table_name,"status='$status' where slno='$recordID'");
   	$_SESSION['session_message']='
   <div class="alert alert-danger" role="alert">'.$record_type.' has been deleted successfully</div>';
   	header("Location: ".SITE_ADMIN_URL."/".$script_name);
   	exit;
   }
   
   admin_header();
   ?> 
<div class="table-responsive">
   <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
      <tr>
         <td align="left" width="50%" class="myTitle"> <?=$heading;?> </td>
      </tr>
   </table>
</div>
<hr size="2" width="99%" color="#DA251C">
<?php
$qry= db_query("select * from $table_name where user_type!='admin' order by slno desc");
$reccnt = NumRows($qry);
   ?> 
<form name="formn" method="post" action="" enctype="multipart/form-data">
   <div class="table-responsive">
      <table class="lightBorder table table-bordered table-hover">
         <?php
            if($reccnt>0) {
                ?> 
         <thead>
		 <tr height="25" bgcolor="#EAEAEA">
	 <td width="5%" align="center"><strong>S.No.</strong></td>
	 <td width="20%" align="left"><strong>User Access</strong></td>
	 <td width="10%" align="left"><strong>Name</strong></td>
	 <td width="10%" align="left"><strong>Email</strong></td>
	 <td width="15%" align="center"><strong>Contact</strong></td>
	 <td width="10%" align="center"><strong>Status</strong></td>
	 <td width="20%" align="left"><strong>Options</strong></td>
         </thead>
         <tbody>
            <?php
               $sl=$start+1;
                   while($arr=mysqli_fetch_array($qry)) { 
                   ?> 
            <tr>
               <td><?=$sl;?></td>
			   <td><?php 
		  echo "User Id: ".$arr['user_id'];
		  echo "<br>User Pass: ".$arr['pwd'];
		  ?>
		  </td>
               <td> <?=$arr['name'];?></td>
               <td><?php  echo $arr['email']; ?> </td>
               <td>
                  <?php echo $arr['phone'];?>
               </td>
               <td> 
               <?php if($arr['status']=='Y'){
				echo "<i class='fa fa-circle' style='color:green'></i>";
			}else{
				echo "<i class='fa fa-circle' style='color:gray'></i>";
			}  ?> </td>
               <td>&nbsp; <a href="<?=$script_name;?>?id=edit_record&recordID=<?=$arr[slno];?>"><i class="fa fa-edit"></i></a>&nbsp; <a href="<?=$script_name;?>?id=status_record&recordID=<?=$arr['slno'];?>&status=<?php if($arr['status']=='Y'){ echo "N";} else { echo "Y";}?>" onClick="return confirm('Are you sure to Change Status...');"><?php if($arr['status']=='Y'){
			echo "In Active";
		}else{
			echo "Activate";
		}
		  ?></a>
               </td>
            </tr>
            <?php $sl++; }  ?> 
         </tbody>
         <?php } else { ?> 
         <tr>
            <td>
               <h5>Not Record Found ... </h5>
            </td>
         </tr>
         <?php } ?>
      </table>
   </div>
</form>
<br>
<form name="bannerFrm" method=post action="" enctype="multipart/form-data" onsubmit="return validate('bannerFrm') && chk_valid_date();">
   <?php
      if($_GET['recordID']=="" || $id!="edit_record") {
       ?> 
   <div class="form-group">
      <h3>Add New <?=$record_type;?> </h3>
   </div>
   <?php
      }
      else {
       ?> 
   <div class="form-group">
      <h3>Edit <?=$record_type;?> </h3>
   </div>
   <div class="form-group text-right">
      <a href="
         <?=$script_name;?>" class="btn btn-primary text-white">
      <b>Add New <?=$record_type;?> </b>
      </a>
   </div>
   <?php
      }
      $res=getResult($table_name," where slno='$_GET[recordID]'");
      ?> 
   <div class="form-group">
      <label for="cate">User Name <font color="red">*</font>
      </label> <?php
         if($_GET['recordID']=="" || $id!="edit_record") {
          ?> <input type="text" name="uname" class="form-control" value="" placeholder="User Name" Required> <?php
         }
         else { ?> <input type="text" name="uname" class="form-control" value="<?=$res['name']?>" placeholder="User Name " require> <?php } ?>
   </div>
   <div class="form-group">
      <label for="cate">User Id <font color="red">*</font>
      </label> <?php
         if($_GET['recordID']=="" || $id!="edit_record") {
          ?> <input type="text" name="uid" class="form-control" value="" placeholder="User Id" Required> <?php
         }
         else { ?> <input type="text" name="uid" class="form-control" value="<?=$res['user_id']?>" placeholder="User Id " Required> <?php } ?>
   </div>
   <div class="form-group">
      <label for="cate">User Password <font color="red">*</font>
      </label> <?php
         if($_GET['recordID']=="" || $id!="edit_record") {
          ?> <input type="text" name="upass" class="form-control" value="" placeholder="User Password" Required> <?php
         }
         else { ?> <input type="text" name="upass" class="form-control" value="<?=$res['pwd']?>" placeholder="User Password" Required> <?php } ?>
   </div>

   <div class="form-group">
      <label for="cate">Email <font color="red">*</font>
      </label> <?php
         if($_GET['recordID']=="" || $id!="edit_record") {
          ?> 
      <input type="email" name="uemail" class="form-control" value="" placeholder="Email" Required>
      <?php
         }
         else { ?> 
     <input type="text" name="uemail" class="form-control" value="<?=$res['email']?>" placeholder="Email" Required>
      <?php } ?>
   </div>
   <div class="form-group">
      <label for="cate">Contact Number <font color="red">*</font>
      </label> <?php
         if($_GET['recordID']=="" || $id!="edit_record") {
          ?> 
      <input type="tel" name="unum" class="form-control" value="" placeholder="Contact Number" Required>
      <?php
         }
         else { ?> 
     <input type="tel" name="unum" class="form-control" value="<?=$res['phone']?>" maxlength="12" placeholder="Contact Number" Required>
      <?php } ?>
   </div>
   <div class="form-group"> <?php
      if($recordID !="") {
       ?> <input type="submit" class="btn btn-primary" name="submit" value="Update 
      <?=$record_type;?>" class="button">
      <input type="hidden" name="recordID" value="
         <?=$res['slno'];?>">
      <input type="hidden" name="id" value="update_record"> <?php	   
         }
         else{
          ?> <input type="submit" class="btn btn-primary" name="submit" value="Add New 
         <?=$record_type;?>" class="button">
      <input type="hidden" name="id" value="add_record"> <?php
         }
         ?> <input type="hidden" name="start" value="
         <?=$start;?>">
      <input type="hidden" name="pagesize" value="
         <?=$pagesize;?>">
   </div>
</form>
<script src="jquery.min.js"></script>
<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="
   <?=SITE_URL_PATH;?>/js/calendar/themes/Normal/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe> <?php
   admin_footer();
   exit;
   ?>