<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Administrator | Test by Position</title>
	<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
	<!-- bootstrap 3.0.2 -->
	<link href="<?php echo URL;?>public/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<!-- font Awesome -->
	<link href="<?php echo URL;?>public/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<!-- Ionicons -->
	<link href="<?php echo URL;?>public/css/ionicons.min.css" rel="stylesheet" type="text/css" />
   
	<!-- bootstrap wysihtml5 - text editor 
	<link href="<?php echo URL;?>public/css/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet" type="text/css" />
	 <!-- Theme style -->
	<link href="<?php echo URL;?>public/css/AdminLTE.css" rel="stylesheet" type="text/css" />
	
	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
	  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
	<![endif]-->
</head>
<body class="skin-blue fixed" ng-app="ubiapp"  ng-controller="testCtrl" ng-init="onFetchCategory();">
<!-- header logo: style can be found in header.less -->
<?php require VIEWS_PATH . '_templates/sidebar.php'; 
	topbar();
?>
<div class="wrapper row-offcanvas row-offcanvas-left">
	<!-- Left side column. contains the logo and sidebar -->
	<aside class="left-side sidebar-offcanvas">                
		<!-- sidebar: style can be found in sidebar.less -->
		<?php sidemenu(3.1);
		?>
		<!-- /.sidebar -->
	</aside>
	<!-- Right side column. Contains the navbar and content of the page -->
	<aside class="right-side">                
		<!-- Content Header (Page header) -->
        <section class="content-header">
			<h1>
				<span <?php   if(isset($this->settestid)){ ?>>Edit  Test by Position </span><?php } else { ?><span >Set  Test by Position </span><?php } ?>
				<br/><small>Set tests for different Positions and their levels.</small>
            </h1>
			<ol class="breadcrumb">
				<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
				
				<li>Tests</li>
				<li class="active" <?php   if(isset($this->settestid)){ ?>>Edit Test by Position</li><?php } else { ?><li >Set Test</li><?php } ?>
				
			</ol>
            <!-- Help start -->
            <div id="mySidenav" class="sidenav">
				<div class="helpHeader"><span >Help</span><a href="javascript:void(0)" class="closebtn text-right" onclick="closeNav()">×</a></div>
				<div id="sidenavData" class="sidenavData">
				</div>
			</div>
			<script>
				function openNav() {
					document.getElementById("mySidenav").style.width = "400PX";
					$('#sidenavData').load('<?=URL?>help/helpNav', {'page': 'set_test'});	
				}
				function closeNav() {
					document.getElementById("mySidenav").style.width = "0";
				}
			</script>
			<!-- help close -->
       </section>
		<!-- Main content -->
        <section class="content" >
			<div class="row">
				<div class="col-xs-12">
					<!-- /.box -->
                    <div class="box box-info">
						<div class="box-body table-responsive">
							<a data-toggle="tooltip" onclick="openNav()" title="Help" class="btn btn-primary btn-sm pull-right">
							<i class="fa fa-question"></i></a>
							<?php $this->renderFeedbackMessages(); ?>
                            <!-- form start -->   
                            <form id="frm" name="frm" action="<?php  if(isset($this->settestid)){?><?php echo URL;?>settest/editSave/<?php echo $this->settestid  ?><?php } else {?><?php echo URL;?>settest/create<?php } ?>" method="post" enctype="multipart/form-data">  
								<div class="box-body">
									<div class="row">			
										<label class="col-sm-1"></label>
										<div class="col-sm-10">
											<label class="col-sm-4 text-right">Position</label>
											<div class="col-sm-5">
												<div class="form-group">
													<select class="form-control" name="designation" onchange="onchangeposition(this.value,1)" <?php  if(isset($this->settestid)){?> disabled <?php }?> required/>
													<option value="">---SELECT--</option>
													<?php
													if(count($this->designations)==0)
														echo "<option value='addnew'>Add new  Position</option>";
													if ($this->designations) {
														foreach($this->designations as $key => $value){
															if($this->settest->designation_id==$value['designation_id']){
															echo '<option selected="selected" value="'.$value['designation_id'].'">'.$value['designation_name'].'</option>';
															}else{
																echo '<option value="'.$value["designation_id"].'">'.$value["designation_name"].'</option>';
															}
														}
													} 
													?>
													</select>
												</div><!-- /.form-group -->
											</div><!-- /.col-sm-5 -->
										</div><!-- /.col-sm-10-->
									</div><!-- /.row -->
									<div class="row">			
										<label class="col-sm-1"></label>
										<div class="col-sm-10">
											<label class="col-sm-4 text-right">Test level</label>
											<div class="col-sm-5">
												<div class="form-group">
													<select class="form-control" name="level" <?php  if(isset($this->settestid)){?> disabled <?php }?> required/>
													<option value="">---SELECT--</option>
													<?php
													if ($this->testlevel) {
														foreach($this->testlevel as $key => $value){
															if($this->settest->testlevel_id==$value['id']){
															echo '<option selected="selected" value="'.$value['id'].'">'.$value['level'].'</option>';
															}else{
																echo '<option value="'.$value["id"].'">'.$value["level"].'</option>';
															}
														}
													} 
													?>
													</select>
												</div><!-- /.form-group -->
											</div><!-- /.col-sm-5 -->
										</div><!-- /.col-sm-10-->
									</div><!-- /.row -->
									<div class="row">
									<div class="col-sm-3">
									<div class="block"   style="height:400px; overflow:auto; border:solid 1px;"  >
									<div ng-repeat="c in selectionCategory" my-post-repeat-directive>
								<div class="action-checkbox">
									<!--<label class="control-label"  for="{{employee.id}}"><input id="{{employee.id}}" type="checkbox" value="{{employee.id}}" ng-click="toggleSelection($index)" />{{employee.name}}</label>-->
									<label><input  type="checkbox"  ng-click="toggleCategory(c.test_id)"  />&nbsp;&nbsp;&nbsp;{{c.test_name}}</label>
									<!-- <label  ng-show="c.sts==0"><input type="checkbox"  ng-click="toggleCategory(c.test_id)"  />&nbsp;&nbsp;&nbsp;{{c.test_name}}</label> -->
								</div>
							</div>
									</div>
									</div>
									<div class="col-sm-6">
									<div class="block" style="height:400px; overflow:auto; border:solid 1px;"  >
									<div ng-repeat="t in selectionTestPaper" my-post-repeat-directive>
								<div class="action-checkbox">
									<!--<label class="control-label"  for="{{employee.id}}"><input id="{{employee.id}}" type="checkbox" value="{{employee.id}}" ng-click="toggleSelection($index)" />{{employee.name}}</label>-->
								<!-- 	<label ng-show="t.sts==1"><input checked="checked" type="checkbox"  ng-click="toggleSelection(t.id)"  />&nbsp;&nbsp;&nbsp;{{t.name}}</label> -->
									<label><input type="checkbox"  ng-click="toggleTests(t.cat_id)"  />&nbsp;&nbsp;&nbsp;{{t.cat_name}}</label>
								</div>
							</div>
													</div>
									</div>
										<div class="col-sm-3">
									<div class="block" style="height:400px; overflow:auto; border:solid 1px;"  >
									<div ng-repeat="t in selectedTests" my-post-repeat-directive>
								<div class="action-checkbox">
									<!--<label class="control-label"  for="{{employee.id}}"><input id="{{employee.id}}" type="checkbox" value="{{employee.id}}" ng-click="toggleSelection($index)" />{{employee.name}}</label>-->
									
									<label>&nbsp;&nbsp;&nbsp;{{t.cat_name}}</label>
								</div>
							</div>
													</div>
									</div>
									</div>
									<div class="text-center">
										<button type="submit" class="btn btn-primary">Submit</button>
										<a href="<?=URL?>settest/index/1" ><button type="button" class="btn btn-default">Cancel</button></a>
									</div>
								</div><!-- /.box-body -->
							</form>
						</div><!-- /.box-body -->
					</div><!-- /.box -->
				</div><!-- /.col-xs-12 -->
			</div><!-- /.row -->
		</section><!-- /.content -->
	</aside><!-- /.right-side -->
</div><!-- ./wrapper -->


        <!-- jQuery 2.0.2 -->
        <script src="<?php echo URL;?>public/js/jquery.min.js"></script>
       
        <!-- Bootstrap -->
        <script src="<?php echo URL;?>public/js/bootstrap.min.js" type="text/javascript"></script>
        <script src="//code.jquery.com/ui/1.11.1/jquery-ui.min.js" type="text/javascript"></script>
        <script src="<?php echo URL;?>public/js/angular.min.js"></script>
        <!-- AdminLTE App -->
        <script src="<?php echo URL;?>public/js/AdminLTE/app.js" type="text/javascript"></script>
        
        <!-- Bootstrap WYSIHTML5 -->
        <script src="<?php echo URL;?>public/js/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js" type="text/javascript"></script>
         <script src="<?php echo URL;?>public/js/plugins/iCheck/icheck.min.js" type="text/javascript"></script>
       
        <script type="text/javascript">
			
             //jQuery UI sortable for the todo list
			
			function onchangeposition($val,$id)
			{
				if($val=="addnew"){
					$link="designation/addnew";
					if($id == 2)
						$link="testcategory/addnew";
					if($id == 3)
						$link="quiz/addnew";
					window.open("<?= URL ?>"+$link, "_self");
				}
			}

		$(document).ready(function(){
			$('#category').on('change',function() {
				var categoryID=$(this).val();
				//alert(categoryID);
				if(categoryID)
				{
					$.ajax({
						type:'POST',
						url:'<?= URL ?>'+'settest/addnew',
						data:'category_id=' +categoryID,
						success:function(html)
						{
							$('#testcategory').html(html);
							//alert(html)//console.log(html)
						}
					});
				}
				//console.log($(this).val());
			});
		});
		 $('body').tooltip({
		selector: '[rel=tooltip]'
	});
        </script>
        
		
		
<script>
	<!----- Start Number validation------->
	var app = angular.module('ubiapp', []);
	app.controller('testCtrl', function($scope, $http, $timeout) {
		$scope.hastrue=false;
		$scope.position='';
		$scope.tests='';
		$scope.candidateid=0;
		$scope.scheduledatetime="";
		$scope.testlevel=0;
		$scope.leftdisable=true;
		$scope.rightdisable=true;
		$scope.selectedcolumnsarr = [];	
		$scope.location="";
		$scope.filterCandidate="";
		$scope.startdate="";
		$scope.enddate="";
		$scope.currentlevel="";
		$scope.point="";
		$scope.minscore=0;
		$scope.maxscore=100;
		$scope.searchcandidate="";
		$scope.selectionCategory=[];
		$scope.selectionTestPaper=[];
		$scope.TestPaper=[];
		$scope.selectedTests=[];
		
		
		$scope.toggleCategory = function($x) {

		for(var i=0; i<$scope.selectionCategory.length; i++) {
			
			if($scope.selectionCategory[i].test_id==$x){
				if($scope.selectionCategory[i].sts){		
			$scope.selectionCategory[i].sts=0;
			var len=$scope.selectionTestPaper.length;
				for(var i=0; i<len; i++) {
					if($x==$scope.selectionTestPaper[i].category_id)
					{
							$scope.selectionTestPaper.remove(i);	
							i=-1;
							len=$scope.selectionTestPaper.length;
					}	
							
				}
			//$scope.selectionCategory.remove(i);	
			}else{
				
				$scope.selectionCategory[i].sts=1;
				$http({
				url: path+'settest/gettestpaper',
				method: "POST",
				data:'category_id=' +$scope.selectionCategory[i].test_id,
				//data: xsrf,
				headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
			}).success(function (data, status, headers, config) {
				
				$scope.TestPaper=data;
						for(var i=0; i<$scope.TestPaper.length; i++) {
							
							$scope.selectionTestPaper.insert($scope.selectionTestPaper.length,$scope.TestPaper[i]);
							
						}
				
				$scope.hastrue=false;
			}).error(function (data, status, headers, config) {
				errorMessage("error: "+$scope.status);//$scope.status = status + ' ' + headers;
				$scope.hastrue=false;
			});
				//$scope.selection.insert($scope.selection.length,$scope.filtercandidatearr[i]);
			}
			}
			
		}
		
			/* if($scope.filtercandidatearr[$x].sts){		
			$scope.filtercandidatearr[$x].sts=false;
			$scope.selection.remove($x);	
			}else{
				$scope.filtercandidatearr[$x].sts=true;
				$scope.selection.insert($scope.selection.length,$scope.filtercandidatearr[$x]);
			} */
			
		};
		
		$scope.toggleTests = function($x) {

		for(var i=0; i<$scope.selectionTestPaper.length; i++) {
			
			if($scope.selectionTestPaper[i].cat_id==$x){
				if($scope.selectionTestPaper[i].sts){		
				$scope.selectionTestPaper[i].sts=0;
				for(var j=0; j<$scope.selectedTests.length; j++)
				{
					if($scope.selectedTests[j].cat_id==$x){
						$scope.selectedTests.remove(j);
					}
				}
				
				//$scope.selectionCategory.remove(i);	
			}else{
				
				$scope.selectionTestPaper[i].sts=1;
				$scope.selectedTests.insert($scope.selectedTests.length,$scope.selectionTestPaper[i]);
					
			
					
			
				//$scope.selection.insert($scope.selection.length,$scope.filtercandidatearr[i]);
			}
			}
			
		}
		
			/* if($scope.filtercandidatearr[$x].sts){		
			$scope.filtercandidatearr[$x].sts=false;
			$scope.selection.remove($x);	
			}else{
				$scope.filtercandidatearr[$x].sts=true;
				$scope.selection.insert($scope.selection.length,$scope.filtercandidatearr[$x]);
			} */
			
		};
		
		$scope.toggleSelectionall = function() {
			$scope.hastrue=true;
			for(var i=0; i<$scope.filtercandidatearr.length; i++) {
				//console.log($scope.candidatearr[i].vsts);
		
					
					if($scope.filtercandidatearr[i].sts){
						$scope.filtercandidatearr[i].sts=false;
						$scope.selection.remove(i);	
						$scope.hastrue=false;
					}
					else{
					$scope.filtercandidatearr[i].sts=true;
						$scope.selection.insert($scope.selection.length,$scope.filtercandidatearr[i]);
						$scope.hastrue=false;
				}
				$scope.hastrue=false;
			
				/* if($scope.candidatearr[i].vsts){
					$scope.candidatearr[i].vsts=false;
				} */
				
			}
		};
		
		
			///////inset and remove function///////
		Array.prototype.insert = function (index, item) {
			this.splice(index, 0, item);
		};	
		Array.prototype.remove = function (index) {
		  this.splice(index,1);
		};
	 
	 
	$scope.onFetchCategory =function(){
		
			$scope.hastrue=true;
			//var xsrf = $.param({scheduleid: $scheduleid});
			$http({
				url: path+'settest/getallcategory',
				method: "POST",
				//data: xsrf,
				headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
			}).success(function (data, status, headers, config) {
				
				$scope.selectionCategory=data;
					
				$scope.hastrue=false;
			}).error(function (data, status, headers, config) {
				errorMessage("error: "+$scope.status);//$scope.status = status + ' ' + headers;
				$scope.hastrue=false;
			});
		};
	 

	});
	</script>
	

		
		
		
    </body>
</html>
