
<div>
    <ul class="breadcrumb">
    <li>
            <a href="index.php">home</a>
        </li>
        <li>
            <a href="index.php?page=voluntaryApp">Voluntary Application</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"></i> Voluntary Application</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">
                
                
                <!--start of search -->
                   <form method="post" id="search_vol">
                   <input type="hidden" value="search" name="opt" />
                <div class="well">
                
                
                
            
                   <div class="form-group"> <div class="row"><div class="col-md-12">Advance Search</div></div></div>
                   
                  
                 
                  <div class="form-group">
                        <div class="control-group"> 
                            <div class="row">
                   <?php 
				  
				   
				   if($_SESSION['admin_role']!=3){ ?>
          
                    <div class="col-md-1"><span>Branches</span></div>
                   
              <div class="col-md-3">
                  
                  <div class="controls">
                     <select name="branches" id="branches"  data-rel="chosen">
                      <option value="0">please choose branch</option>

                          <?php 
                           $query="select * from branches";
                           $res=mysqli_query($conn,$query);
                            if($res){
	                       while($row=mysqli_fetch_assoc($res)){
		                    ?>
	                   	<option value="<?php echo($row['branches_id']); ?>" ><?php echo($row['branches_name_en']); ?></option>
		
	                	<?php 
		
		                }
	
	                   }

                       ?>

                  </select>
                </div>
            </div><?php  }?>
        
                   
                   
             <div class="col-md-1">Status</div>
                   
                  <div class="col-md-3">
                   
                   <!---     role select            -->
                   
                   <div class="controls">
                   <select name="status" id="status"  data-rel="chosen">
                      <option value="0">please choose status</option>

                          <?php 
                           $query="select * from status";
                           $res=mysqli_query($conn,$query);
                            if($res){
	                       while($row=mysqli_fetch_assoc($res)){
		                    ?>
	                   	<option value="<?php echo($row['status_id']); ?>" ><?php echo($row['status_name_en']); ?></option>
		
	                	<?php 
		
		                }
	
	                   }

                       ?>

                  </select></div></div>
                  
                  
                  
                  
            
                    
                  <div class="col-md-1">Gender</div>
                  
                    <div class="col-md-3">
                   
                   <!---     role select            -->
                   
                   <div class="controls">
                   <select name="gender" id="gender"  data-rel="chosen" style="height:70px; line-height:70px;">
                      <option value="0">please choose gender</option>

                          <?php 
                           $query="select * from gender";
                           $res=mysqli_query($conn,$query);
                            if($res){
	                       while($row=mysqli_fetch_assoc($res)){
		                    ?>
	                   	<option value="<?php echo($row['gender_id']); ?>" ><?php echo($row['gender_name_en']); ?></option>
		
	                	<?php 
		
		                }
	
	                   }

                       ?>

                  </select></div></div>
                  
                   
                  
               </div><!-- row -->
                  </div><!-- group  -->
                  </div>
                  
                  
                  
                  
                  
                  
                    <div class="form-group">
                    <div class="control-group">
                  <div class="row">
                  
                  <div class="col-md-1">Period</div>
                     <div class="col-md-3">
                    <div class="controls">
                   <select name="period" id="period"  data-rel="chosen" >
                      <option value="0">please choose period</option>
                       <option value="1">open period</option>
                        <option value="2">specific period</option>

                          

                  </select></div>
                     
                     </div>
                  
                  
                  
                  <div class="col-md-1"><span>from</span></div>
                  <div class="col-md-3"> <input type="date" name="from_search" class="form-control"/>    </div>
                   <div class="col-md-1"><span>to</span></div>
                   <div class="col-md-3"><input type="date" name="to_search" class="form-control"/></div>
                   
                   
                   
                   
                   </div></div></div>
                    
                    
                     <div class="form-group">
                  <div class="row">
                    <div class="col-md-2"><span>ID number</span></div>
                   <div class="col-md-3"><input type="text" name="ID_search" id="ID_search"  class="form-control" placeholder="ID"/></div>
                  <div class="col-md-2">Passport Number</div>
                    
                    <div class="col-md-3"><input type="text" name="pass_search" id="pass_search"  class="form-control" placeholder="Passport number"/></div>
                  </div> 
                  </div>
                  
                  
                   <div class="form-group">
                    <div class="row">
                  <div class="col-md-10" align="right"><input type="submit" class="btn btn-info btn-sm" name="search_btn" value="Search" style="position:inherit; " /></div>
                  
                  </div> 
                   </div>
        
   </div><!-- well  -->
               
         </form>
                   
          <!-- end search  -->
                   
                  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                     <tr>
                       <td>#</td>
                       <td>Volunteer name</td>
                       <td>Fill Application date</td>
                       <td>branch</td>
                       <td>Status of application</td>
                       <td></td>
                     </tr>
                     
                     <?php 
					 $count=1;
					 $check=0;
					 $role=0;
					 $query="select * from voluntary 
                            inner join branches on branches_id=voluntary_branchid
                            inner join personal_info on personal_info_id=voluntary_personalInfoId
                            inner join status on status_id=voluntary_status ";
							
							if($_SESSION['admin_role']==3){
								$query=$query."where voluntary_branchid=".$_SESSION['admin_branchid'];
								$role=1;
							}

					 if($_REQUEST['opt']==search){
						 if($role==0){
						 $query=$query."where ";}
						 if($_REQUEST['ID_search']!='')
						 {
							 
							 $query=$query." personal_info_identity=".$_REQUEST['ID_search'];
							 
						 }//search 
						 
						 
						 
						 else if($_REQUEST['pass_search'] !=''){
							 
							  $query=$query." personal_info_passID=".$_REQUEST['pass_search'];
							
							 }//passport 
						
						
						
						///search by role dates,branch
						else{
							 
							 if($_REQUEST['branches'] !=0){
								 
								 if( $role==1 ){
								 $query=$query." and branches_id=".$_REQUEST['branches'];
								 }else{
									 $query=$query." branches_id=".$_REQUEST['branches'];
									 }
								 $check=1;
								 }//branch
							
								
								 if($_REQUEST['status'] !=0){
								       if($check==1 || $role==1 ){
								         $query=$query." and voluntary_status=".$_REQUEST['status'];
								        }else{$query=$query." voluntary_status=".$_REQUEST['status'];}
								 $check=1;
								 }//status
								 if($_REQUEST['period']!=1){
									 echo("goo");
								 if($_REQUEST['from_search'] !='' && $_REQUEST['to_search']!='' ){
								       if($check==1 || $role==1 ){
								         $query=$query." and voluntary_start >='".$_REQUEST['from_search']."' and voluntary_end <='".$_REQUEST['to_search']."'";
								        }else{$query=$query." voluntary_start >='".$_REQUEST['from_search']."' and voluntary_end <='".$_REQUEST['to_search']."'";}
								 $check=1;
								 }//dates
								 }
								 if($_REQUEST['period'] !=0){
								       if(($check==1 || $role==1) && $_REQUEST['period']==1){
								         $query=$query." and voluntary_start='0000-00-00 ' and voluntary_end='0000-00-00 '";
								        }
										if($check==0 && $_REQUEST['period']==1){$query=$query." voluntary_start='0000-00-00' and voluntary_end='0000-00-00 '";}
										if(($check==1 || $role==1 ) && $_REQUEST['period']==2){
								         $query=$query." and voluntary_start !='0000-00-00 ' and voluntary_end !='0000-00-00 '";
								        }
										if($check==0 && $_REQUEST['period']==2){$query=$query." voluntary_start !='0000-00-00 ' and voluntary_end !='0000-00-00 '";}
										
								 $check=1;
								 }//period
								 
								 
								 if($_REQUEST['gender'] !=0){
								       if($check==1 || $role==1){
								         $query=$query." and personal_info_genderid=".$_REQUEST['gender'];
								        }else{$query=$query." personal_info_genderid=".$_REQUEST['gender'];}
								 $check=1;
								 }//gender
								 
								 
								 
								
							}//else
								 
								 
							 
							 }//opt
							 
							 
						
					 echo($query);
					 $res=mysqli_query($conn,$query);
					 if($res){
					 while($row_res=mysqli_fetch_assoc($res)){
						 
					  ?>
                     
                     
                     <tr>
                       <td><?php  echo($count++); ?></td>
                       <td><?php  echo($row_res['personal_info_name']); ?></td>
                       <td><?php  echo($row_res['voluntary_app_date']); ?></td>
                       <td><?php  echo($row_res['branches_name_en']); ?></td>
                       <td><span <?php if($row_res['status_id']==1){?>class="label-warning label label-default"<?php } if($row_res['status_id']==3 || $row_res['status_id']==2){?> class="label-success label label-default"<?php }else{?>class="label-default label label-danger"  <?php } ?> ><?php  echo($row_res['status_name_en']); ?></span></td>
                       <td><a href="index.php?page=actionVol&Id=<?php  echo($row_res['voluntary_id']); ?>&PID=<?php  echo($row_res['personal_info_id']); ?>" class="btn btn-warning btn-xs"> <i class="glyphicon glyphicon-zoom-in icon-white"></i>View</a></td>
                     </tr>
                     <?php }
					 }
					   ?>
                     
                  </table>
                </div>
            </div>
        </div>
        <!--/span-->
    </div><!--/row-->
