 <?php  if(priv($_SESSION['role'],'view','Users',$connect)!=1){exit(); }?>
 <div>
    <ul class="breadcrumb">
        <li>
            <a href="index.php">Home</a>
        </li>
        <li>
            <a href="index.php?page=Users"> Add Users</a>
        </li>
    </ul>
</div>

<div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2><i class=" glyphicon glyphicon-th-list"></i> Users</h2>

                    <div class="box-icon">
                        <a href="#" class="btn btn-setting btn-round btn-default"><i
                                class="glyphicon glyphicon-cog"></i></a>
                        <a href="#" class="btn btn-minimize btn-round btn-default"><i
                                class="glyphicon glyphicon-chevron-up"></i></a>
                        <a href="#" class="btn btn-close btn-round btn-default"><i
                                class="glyphicon glyphicon-remove"></i></a>
                    </div>
                </div>
                <div class="box-content">
                
                <br />

                
              
                 
                  <?php  
				  if(priv($_SESSION['role'],'up','Users',$connect)==1)
				 if($_REQUEST['opt']==do_up){
					 
			$selectQuery=mysqli_query($connect,"select * from Users
			where Users_id='".post($connect,$_REQUEST['id'])."' ");
			$rowQuery=mysqli_fetch_array($selectQuery);
			
			$status=0;
 if($rowQuery['Users_status']==0){
	 $status=1;
	 }
 

 $Users_query="update users
set 
 Users_status='".$status."'
 where Users_id='".post($connect,$_REQUEST['id'])."'
 
 
 
 ";
 
 
 
 $situation=mysqli_query($connect,$Users_query);
 if($situation){ echo("<div>Users Updated SucessFully</div>");}
} 
				 ?>
                 
                 
                
                 
                 
                 
                
                  
                
                <?php 
				 if(priv($_SESSION['role'],'add','Users',$connect)==1)
			if($_REQUEST['opt']==do_add)
{
	
	if($_REQUEST['Users_name']==''
	|| $_REQUEST['Users_username']==''
	|| $_REQUEST['Users_passwords']==''
 
	|| $_REQUEST['Users_role']==0
	){
		
		echo("<div style='color:red'> Please Fill All Parameters </div>");
		}else{
 

 $Users_query="insert into users
set 
 Users_name='".post($connect,$_REQUEST['Users_name'])."'
,Users_date=now()
 ,Users_username='".post($connect,$_REQUEST['Users_username'])."'
,Users_passwords='".post($connect,$_REQUEST['Users_passwords'])."'
,Users_roleid='".post($connect,$_REQUEST['Users_role'])."'
,users_companyID='".post($connect,$_REQUEST['users_companyID'])."'
,Users_status=1


"; 
 
 
 
 $situation=mysqli_query($connect,$Users_query);
 if($situation){ echo("<div>Users Added SucessFully</div>");}
}}
			
			
			
				 ?>
                
                
                
                   <?php 
				   if(priv($_SESSION['role'],'add','Users',$connect)==1)
				   if($_REQUEST['opt']==add)
				   { 
				   ?>
                       <form method="post"  class="login_form" >
<input type="hidden" name="opt" value="do_add" />
<div class="form-group">
<div class="row ">
<div class="col-md-2">Name</div>
<div class="col-md-4"><input type="text" name="Users_name" id="Users_name" class="form-control" placeholder="Users name" /></div>
 
<div class="col-md-2">Username </div>
<div class="col-md-4"><input type="text" name="Users_username" id="Users_username" class="form-control" placeholder="Users username" /></div>
</div>
</div>

<div class="form-group">
<div class="row ">
<div class="col-md-2">Password</div>
<div class="col-md-4"><input type="text" name="Users_passwords" id="Users_passwords" class="form-control" placeholder="Users Password" /></div>
 
<div class="col-md-2">Role</div>
<div class="col-md-4"> 

<select name="Users_role" class="form-control" data-rel="chosen">
<option value="0">select Role</option>
<?php $selProvider=mysqli_query($connect,"select * from roles");

while($rowProv=mysqli_fetch_array($selProvider)){
	?>
	<option value="<?php echo($rowProv['roles_id']); ?>"><?php echo($rowProv['roles_name']); ?></option>
	<?php
	
	}
 ?>
</select>


</div>
</div>
</div>

<div class="form-group">
<div class="row ">
<div class="col-md-2">Company</div>
<div class="col-md-4"><?php  Select("users_companyID",$connect,"Please Select Company"," select * from Company",$Services_row['users_companyID']); ?></div>
  
</div>

<div class="form-group">
<div class="row ">

<div class="col-md-12"><input type="submit" name="Add_Users" value="Add Users" class="action-button"  style="width:120px"/></div>
</div>
</div>

</form>
<br>
<br>

 <!-----      end  add Users       -->
                       
                       <?php } ?>
                       
                       
                       <div class="row">
                       <div class="col-md-12">
                       <?php  if(priv($_SESSION['role'],'add','Users',$connect)==1){ ?>
                         <a href="index.php?page=Users&opt=add" ><i class="glyphicon glyphicon-plus icon-white"></i> Add new Users</a><br>
                         <?php }  ?>

                         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                                         
                         
                         
                           <tr>
                             <td>Name </td>
                             <td>Username</td>
                             <td align="center" valign="middle">Role</td>
                             <td align="center" valign="middle">Status</td>
                             <td align="center" valign="middle">Reset </td>
                             <td align="center" valign="middle">update </td>
                           </tr>
                           <?php  
						   
						   
						   
						  
						
			 
			 $query_Users="select * from users
inner join roles on roles_id=Users_roleid
where 1=1 

" ; 					   
							 
			 $Users_res=mysqli_query($connect,$query_Users);
			
			 if($Users_res){
				 while($row=mysqli_fetch_assoc($Users_res))
				 {
				
			  ?>
						
                           <tr>
                             <td><?php echo($row['Users_name']); ?></td>
                             <td><?php echo($row['Users_username']); ?></td>
                             <td align="center" valign="middle"><?php echo($row['roles_name']); ?></td>
                             <td align="center" valign="middle">
                             <?php  if($row['Users_status']==1){echo("Active");}
							 if($row['Users_status']==0){echo("Disabled");}
							  ?>
                             
                             </td>
                             <td align="center" valign="middle">&nbsp;</td>
                             <td align="center" valign="middle">
                             
                             
                             
                             
                             
                             <a href="index.php?page=Users&opt=do_up&id=<?php  echo($row['Users_id']); ?>"  > 
                             
                             <?php if($row['Users_status']==0){  ?>
                              <i class="glyphicon glyphicon-edit icon-white"></i> Activate This User
                  <?php }else{ ?> 
                  <i class="glyphicon glyphicon-trash icon-white"></i> Disable This User           
                       <?php }  ?>       
                              </a>
                              
                              
                               
                           
                               
                               
                               
                               
                               
                              </td>
                           </tr>
                           
                           
                           <?php  }}?>
                        
                  </table>
                  <br />


                 
                  </div></div>
                   
                </div>
            </div>
        </div>