<div class="workplace">
	<div class="page-header">
		<h1>List <small>: All System Users</small></h1>
    </div>
    
    						
     <div class="row-fluid" style="margin-bottom: 20px">

                    <div class="span12">                    
                        <div class="head clearfix">
                            <div class="isw-grid"></div>  
                            <h1>Filter Results</h1>                    
                        </div>
                        
                        <div class="block-fluid table-sorting clearfix"  style="clear: both; padding: 10px">                
                
                    
<div class="pull-left" style="margin-right:10px">
    	<?php
    	
    	if($this->UserDetails['UnionType'] < 4){
    	?>
							
							<div class="pull-left" style="margin-left: 10px; width:150px">
    		
    	
									Organisation Type<br/>
									<select id="OrganisationType" onchange="OrganisationTypeChange(this)"  style="width: 150px">
										
										<?php
										
										if(count($this->UnionTypes)>0){
											
										 foreach($this->UnionTypes as $IntuitutionType){
										 	
											
											
												echo '<option value="'.$IntuitutionType["type_id"].'"' ;
											 	if($this->TYPE == $IntuitutionType["type_id"]){ echo "selected"; }
											 	echo '>'.$IntuitutionType["Text"].'</option>';
											
												
                                    	 
                                                                                 }
										 	
										 }
                    ?>  
									</select>
									
							</div>
							<?php
    	
    	if($this->UserDetails['UnionType'] < 3){
    	?>
							<div class="pull-left" style="margin-left: 10px; width:150px">
                                                            Organisations<br/>
									<select id="getOrganisation"  style="width: 150px">
										 <option value="">All Organisations</option>
									</select>
									
							</div>	
							
							<?php }} ?>
    <div class="pull-left" style="margin-left: 10px; width:150px">
    		Role Category<br/>
                                                                        <select id="getTitle"  style="width: 150px" onchange="loadTitleTypes(this)">
										 <option value="">All Category</option>
                                                                                 <?php
                                                                                 if(count($this->TitleType)>0){
                                                                                 foreach($this->TitleType as $TitleType){
                                                                                     if($TitleType["parent"]==0){
                                                                                    echo '<option value="'.$TitleType["TypeID"].'">'.$TitleType["TypeName"].'</option>'; 
                                                                                     }
                                                                                 }
                                                                                 }
                                                                                 ?>
									</select>
									
							</div>
    <div class="pull-left" style="margin-left: 10px; width:150px">
    		
    	
									Roles<br/>
									<select id="getRoles"  style="width: 150px">
                                                                            <option value="">All Roles</option>
									</select>
                                                                        
                                                                        
									
							</div>
    
                                                                        <div class="pull-left" style="margin-left: 10px; width:220px">
                                                                            Search<br/>
                                                                        <input type="text" id="tableSearchBox" placeholder="Search ..">
                                                                        </div>
    
							<div class="pull-left" style="margin-left: 10px;padding-top: 22px;">
								<input type="button" value="Show Results" class="btn" onclick="submitGetResults()" />
							</div>
									
</div> 
  </div>
  </div>
  </div>  
  
    
    <div class="row-fluid">
    	
    	
    	
    	<div class="head clearfix">
		 	<div class="isw-grid"></div>
		 	<h1>Personnel</h1>
		 		
				<ul class="buttons">
					
																			
					
					
				
                                <li>
                                    <a href="#" class="isw-settings"></a>
                                    <ul class="dd-list">
                                        <li><a href="#" id="PrintCurrentPageBtn"><span class="isw-attachment"></span> Download PDF</a></li>
                                        <li><a href="#" id="ExcelCurrentPageBtn"><span class="isw-attachment"></span> Download Excel</a></li>
                                    </ul>
                                </li>
                                <?php
                                if(isset($this->AccessRoles[$this->getControllerName]["Actions"]["add"])){
                                ?>
                                <li>
                                    <a href="/members/add/" class="isw-plus tipb" title="Add Personnel"></a>
                                </li>
                                <?php } ?>
                            </ul> 
				
		</div>
		 
		
		<div class="block-fluid table-sorting clearfix">
			
	<table id="ajaxLoadingTable" class="display table"  width="100%" cellspacing="0">
        <thead>
            <tr>
            	<th  width="1%" >#</th>
                                        <th  width="15%">Full Name</th>
                                        <th width="15%">Organisation</th>
                                        <th width="13%">E-mail</th>
                                        <th width="14%">Job Title</th>
                                        <th width="8%">Mobile</th> 
                                        <th width="10%" class="nosort">Last Login</th> 
                                        <th  class="nosort" width="12%">Actions</th>                                     
                                    </tr>
        </thead>
 
        <tfoot>
          
        </tfoot>
    </table>
		</div>
	</div>                
              
</div>





<div id="DeleteRowConfirm" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close DoNotCraeteGrant"   data-dismiss="modal"   aria-hidden="true">×</button>
		<h3 id="myModalLabel">Confirm Delete</h3>
	</div>
							<div class="modal-body">
								 <p style="margin: 30px; 10px">Are you sure you want to delete this account</p>
								 <input type="hidden" id="id_input" />
							</div>
	<div class="modal-footer">
		<button class="btn btn-danger DoNotCraeteGrant"  data-dismiss="modal"  aria-hidden="true">Cancel</button>
		<button class="btn " type="submit" onclick="RemoveUser(this)" >Confirm</button>
	</div>
</div>  



<div id="QuickView" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close DoNotCraeteGrant"   data-dismiss="modal"   aria-hidden="true">×</button>
		<h3 id="myModalLabel">Profile</h3>
	</div>
	<div id="Content_Area">
		
	</div>
</div>

<div id="PrintOption" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close DoNotCraeteGrant"   data-dismiss="modal"   aria-hidden="true">×</button>
		<h3 id="myModalLabel">Print Options</h3>
	</div>
							<div class="modal-body">
								<div >
									
									<table width="100%">
										<tr>
											
											<td valign="top">
												<h4 style="margin: 10px;color: #ccc">Option Select</h4>
												
												
												<div class="block-fluid ucard" style="border-top: 1px solid #ccc;width:100%">

                                        <div class="info">                                                                
                                            <ul class="rows">
                                                
                                                <li>
                                                    <div class="title">Print:</div>
                                                    <div class="text"><select   id="PrintCurrent">
																										<option value="1"> Current Page</option>
																										<option value="2">All Pages</option>
																									</select></div>
                                                </li>
                                                <li>
                                                    <div class="title">Orientation:</div>
                                                    <div class="text">
                                                    	<select  id="PrintOrientation">
																												<option value="Landscape">Landscape</option>
																												<option value="Portrait">Portrait</option>
																											</select>
                                                    </div>
                                                </li>
                                                                              
                                            </ul>                                                      
                                        </div>                        
                                </div>
												
											
											</td>
										</tr>
									</table>
									
								</div>
								
							</div>
	<div class="modal-footer">
		<button class="btn btn-danger DoNotCraeteGrant"  data-dismiss="modal"  aria-hidden="true"   >Cancel</button>
		<button class="btn " type="submit" onclick="printPage()" >Download</button>
	</div>
</div>


<div id="ExcelOption" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close DoNotCraeteGrant"   data-dismiss="modal"   aria-hidden="true">×</button>
		<h3 id="myModalLabel">Excel Options</h3>
	</div>
							<div class="modal-body">
								<div >
									
									<table width="100%">
										<tr>
											
											<td valign="top">
												<h4 style="margin: 10px;color: #ccc">Option Select</h4>
												
												
												<div class="block-fluid ucard" style="border-top: 1px solid #ccc;width:100%">

                                        <div class="info">                                                                
                                            <ul class="rows">
                                                
                                                <li>
                                                    <div class="title">Print:</div>
                                                    <div class="text"><select   id="ExcelCurrent">
																										<option value="1"> Current Page</option>
																										<option value="2">All Pages</option>
																									</select></div>
                                                </li>
                                                                              
                                            </ul>                                                      
                                        </div>                        
                                </div>
												
											
											</td>
										</tr>
									</table>
									
								</div>
								
							</div>
	<div class="modal-footer">
		<button class="btn btn-danger DoNotCraeteGrant"  data-dismiss="modal"  aria-hidden="true"   >Cancel</button>
		<button class="btn " type="submit" onclick="ExcelPage()" >Download</button>
	</div>
</div>

<script>
    var GetData =0;
function OrganisationTypeChange(e){
		 	var v = $(e).val();
		 	loadOrganisations(v)
		 }	

    function loadOrganisations(type){
			var jsonClass = <?=  str_replace("'","\'",json_encode($this->Unions->toArray()))?>;
		
			var unionid = 0;
			if(type ==0){
      		$("#getOrganisation").html('<option value="0">All Organisations</option>');
      	}else{
      				var option1 ='<option value="0">All Organisations</option>';
      				$.each(jsonClass,function(i,v){
      					
            			if(v.un_type == type){
            					option1+='<option value="'+v.un_id+'" ';
            					if(v.un_id == unionid){
            						option1+=' selected="true" ';
            					}
            					option1+='>'+v.un_name+'</option>';
            			}
            			
            		})
            		
            		$("#getOrganisation").html(option1);
      	}
			    
	}	
function loadTitleTypes(e){
    var type =$(e).val();
			var jsonClass = <?=  str_replace("'","\'",json_encode($this->TitleType->toArray()))?>;
		var option1 ='<option value="0">All Roles</option>';
			if(type ==2 ){
      		option1 ='<option value="0">All Roles</option>';
      	}else {
      				$.each(jsonClass,function(i,v){
      					
            			if(v.parent == type && type !=0 && type !=""){
            					option1+='<option value="'+v.TypeID+'" ';
            					option1+='>'+v.TypeName+'</option>';
            			}
            			
            		})
            		
            		$("#getRoles").html(option1);
      	}
			    
	}	
	var table;
$(document).ready(function() {
	
	

	

	
	
   
    
    
    
   $("#changeOrg li a").click(function(){
		var v = $(this).text();
		var id = $(this).attr("id");
		$("#selectedOrg span").html(v);
		$("#getOrganisation").val(id);
		var t = $("#OrganisationType").val();
		table.ajax.url( "/members/getmembers/unionid/"+id+"/type/"+t ).load();
			});
	 
	$("#PrintOrientation").change(function(){
		var r =$(this).val();
		if(r =="Portrait"){
			$("#PrintOrientationDiv").css({"width":170,"height":270});
		}else{
			$("#PrintOrientationDiv").css({"width":270,"height":170});
		}
		
	});
	
	$("#PrintCurrentPageBtn").click(function(){
		$("#PrintOption").modal("show");
		return false;
	});
	
	$("#ExcelCurrentPageBtn").click(function(){
		$("#ExcelOption").modal("show");
		return false;
	});
	

	
	
	
   
    
    $( document ).ajaxComplete(function(event,request, settings) {
    	var u = $("#getOrganisation").val();
    	var t = $("#OrganisationType").val();
    	var tl = $("#getTitle").val();
    	var r = $("#getRoles").val();
    	$("#PrintCurrentPageBtn").attr("href","/members/pdf/page/"+request.responseJSON.page
    	+"/start/"+request.responseJSON.start+
    	"/length/20"+
    	"/search/"+request.responseJSON.search+
    	"/column/"+request.responseJSON.column+
    	"/unionid/"+u+
    	"/type/"+t+
    	"/title/"+tl+
    	"/role/"+r+
    	"/dir/"+request.responseJSON.dir
    	);
    	$("#ExcelCurrentPageBtn").attr("href","/pdf/excel"
    	+"/start/"+request.responseJSON.start+
    	"/length/20"+
    	"/search/"+request.responseJSON.search+
    	"/column/"+request.responseJSON.column+
    	"/unionid/"+u+
    	"/type/"+t+
    	"/title/"+tl+
    	"/role/"+r+
    	"/dir/"+request.responseJSON.dir
    	);
			//alert(request.responseJSON.column);
		});
    
} );


function submitGetResults(){
    
    var search = $("#tableSearchBox").val();
    
     var u = $("#getOrganisation").val();
		var t = $("#OrganisationType").val();
                var title = $("#getTitle").val();
                var R = $("#getRoles").val();
                if(search.length==0){
        var link = "/members/getmembers/unionid/"+u+"/type/"+t+"/title/"+title+"/role/"+R+"/search//";
    }else{
        var link = "/members/getmembers/unionid/"+u+"/type/"+t+"/title/"+title+"/role/"+R+"/search/"+search;
    }
    	if(GetData>0){
           
		table.ajax.url(link).load();
            }else{
                GetData =1;
                
                table = $('#ajaxLoadingTable').DataTable( {
    	"processing": true,
        "serverSide": true,
        "bLengthChange": false,"iDisplayLength":20,
        "ajax": link,
        "aoColumns": [ 
                   { "bSortable": false },
                   { "bSortable": true },
                   { "bSortable": true },
                   { "bSortable": true },
                   { "bSortable": true },
                   { "bSortable": true },
                   { "bSortable": true },
                   { "bSortable": false } ]
    } );
            }
    }

function delete_acc(e){
	var id = $(e).attr("id");
	$("#id_input").val(id);
	$("#DeleteRowConfirm").modal('show');
	
}
 

 function Quickview(e){
 	var id = $(e).attr("id");
	$("#id_input").val(id);
	$("#QuickView").modal('show');
	$("#QuickView #Content_Area").html('<div class="modal-body"><div  style="height: 200px; color:#ccc; line-height: 200px; font-size: 20px; text-align: center">Processing ....</div></div>');
	$.post("/members/getmember/id/"+id,function(r){
		$("#QuickView #Content_Area").html(r);
	
	});
 }
 
 function gotoProfile(){
 	var id = $("#QuickView #getUserID").val();
 	window.location.href ="/members/profile/id/"+id;
 	
 }
 function deleteUser(){
		var id = $("#QuickView #getUserID").val();
	$("#id_input").val(id);
	$("#QuickView").modal('hide');
	$("#DeleteRowConfirm").modal('show');
	
}
function RemoveUser(e){
 	var id =$("#id_input").val();
 	$(e).text("Deleting ..");
 	$.post("/members/delete/id/"+id,function(){
 		submitGetResults();
 		$(e).text("Confirm");
 		$("#DeleteRowConfirm").modal('hide');
 	});
 	
 }
function printPage(){
	var PrintCurrent = $("#PrintCurrent").val();
	var PrintOrientation = $("#PrintOrientation").val();
	var Url = $("#PrintCurrentPageBtn").attr("href");
	$("#PrintOption").modal("hide");
	window.location.href =Url+"/current/"+PrintCurrent+"/orientation/"+PrintOrientation;
	  
}
function ExcelPage(){
	
	
	var ExcelCurrent = $("#ExcelCurrent").val();
	var Url = $("#ExcelCurrentPageBtn").attr("href");
	$("#ExcelOption").modal("hide");
	window.location.href =Url+"/current/"+ExcelCurrent;
	//alert(Url+"/current/"+ExcelCurrent);
}
</script>