<!-- begin:: Subheader -->
<div class="kt-subheader   kt-grid__item" id="kt_subheader">
<div class="kt-container  kt-container--fluid ">
    <div class="kt-subheader__main">
        <div class="kt-subheader__breadcrumbs">
            <a class="kt-subheader__breadcrumbs-link">
                Form Screening </a>
            <span class="kt-subheader__breadcrumbs-separator"></span>
            <a class="kt-subheader__breadcrumbs-link">
                All Form Screening List </a>
            <span class="kt-subheader__breadcrumbs-separator"></span>
            
        </div>
    </div>
    <div class="kt-subheader__toolbar">        
        <a href="<?=base_url();?>scripts/exportStudentData?center_name=0&year=<?=(isset($_GET['year']) && $_GET['year'] !=''? $_GET['year']:'C-20');?>" class="btn btn-label-brand btn-bold">
            <i class="flaticon-download"></i> Export to Excel</a>
    </div>                                        
</div>
</div>
<!-- end:: Subheader -->
<!-- begin:: Content -->
<div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid form-bg">
   <div class="kt-portlet">
      <div class="kt-portlet__body kt-portlet__body--fit">
        <div class="kt-portlet__body">        
        <form name="filter" method="get">          
            <div class="row justify-content-between">
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <input type="text" name="id" value="<?=(isset($_GET['id']) && $_GET['id']!='' ? $_GET['id']:'');?>" class="form-control" placeholder="Form No." aria-controls="kt_table_1" style="width: 100%;">
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <select name="session" aria-controls="kt_table_1" class="form-control input-height">
                        <option value="">Admission Session</option>
                        <option value="<?=CURRENT_SESSION;?>" <?=(isset($_GET['session']) && $_GET['session']==CURRENT_SESSION ?'selected':'');?>><?=CURRENT_SESSION;?></option>  
                    </select>
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <select name="course_id" id="course_id" class="form-control input-height">
                        <option value="">Choose Course</option>
                         <?php $courses = get_courses();?>  
                        <?php foreach($courses as $value){ ?>
                            <option value="<?=$value['id'];?>" <?=(isset($_GET['course_id']) && $_GET['course_id']==$value['id'] ?'selected':'');?>><?=$value['name'];?></option>
                        <?php } ?>                                  
                    </select>
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <select name="user_id" id="user_id" class="custom-select">
                        <option value="">Choose Uploaded By</option>
                        <?php $users = get_user_name_list(); ?>  
                        <?php foreach($users as $value){ ?>
                            <option value="<?=$value['uid'];?>" <?=(isset($_GET['user_id']) && $_GET['user_id']==$value['uid'] ?'selected':'');?>><?=$value['user_name'];?></option>
                        <?php } ?>                                   
                    </select>
                </div>
                <div class="col-sm-4" style="margin-bottom: 10px;">
                    <input type="text" name="cdate" class="form-control" placeholder="Created Date" aria-controls="kt_table_1" id="datepicker" value="<?=(isset($_GET['cdate']) && $_GET['cdate']!='' ? $_GET['cdate']:'');?>">
                </div>
                <div class="col-sm-4" style="margin-bottom: 10px;">
                    <select name="page" aria-controls="kt_table_1" class="custom-select form-control form-control-sm">
                        <option value="">Show Entries</option>
                        <option value="10" <?=(isset($_GET['page']) && $_GET['page']=='10' ?'selected':'');?>>10</option>
                        <option value="25" <?=(isset($_GET['page']) && $_GET['page']=='25' ?'selected':'');?>>25</option>
                        <option value="50" <?=(isset($_GET['page']) && $_GET['page']=='50' ?'selected':'');?>>50</option>
                        <option value="100" <?=(isset($_GET['page']) && $_GET['page']=='100' ?'selected':'');?>>100</option>
                    </select>
                </div>
                <div class="col-sm-4" style="margin-bottom: 10px;">
                    <button type="submit" class="btn btn-info" style="width: 100%;">Apply</button>
                </div>
            </div>
        </form>
            <div class="row">
                <div class="col-sm-12">
                <table class="table table-striped- table-bordered table-hover table-checkable" id="">
                        <thead>
                            <tr>                                                    
                                <th>Form No.</th>
                                <th>PIC</th>
                                <th>Enroll. No</th> 
                                <th>Name</th>
                                <th>Father Name</th>
                                <th>Mother Name</th>
                                <th>Admission Session</th>
                                <th>Admission Type</th>
                                <th>Course</th>
                                <th>Uploaded By</th>
                                <th> Form</th>
                                <th> Ack. Slip</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php $user_type = $this->session->userdata('user_type'); ?>
        				<?php 
                         if(empty($student_details)==FALSE){
                        $i=1; foreach ($student_details as $key):?>
        				<?php 
        					$center_details    = get_center_by_id($key->user_id);
        					$subCourse_details = get_sub_courses_by_id($key->sub_course_id);			
        		           
        					?>
                            <tr>
                                <td><?=ucfirst($key->id);?></td>
                                <td><?php if($key->image!=''){ ?>
                                <div class="kt-user-card-v2">
                                    <div class="kt-user-card-v2__pic">
                                        <img src="<?=base_url();?>uploads/<?=$key->image; ?>" class="m-img-rounded kt-marginless"/>
                                    </div>                                   
                                </div>
        	                    <?php } ?></td>                       
                                <td><?=$key->enroll_num;?></td>
                                 <td><?=ucfirst($key->name);?></td>
                                <td><?=ucfirst($key->father_name);?></td>
                                <td><?=ucfirst($key->mother_name);?></td>
                                <td><?=ucfirst($key->admission_session);?></td>
                                <td><?=ucfirst($key->admission_type);?></td>
                                <td><?=get_courses_by_id($key->course_id);?> </td>
                                <td><?=$center_details[0]['user_name'];?></td>
                                <td>
                                <span class="visited" id="loader_<?=$key->id; ?>">
                                <?php
                                if ($user_type == 1 || $user_type == 2) {
                                ?>
                                <input type="checkbox" name="form_status" value="1" id="checkstatus_<?=$key->id; ?>" onclick = "checkstatus('<?=$key->id; ?>')" <?php if(isset($key->form) && $key->form=='1'){ echo "checked"; } ?>>
                                <?php } ?>
                                </span><br/>
                                <?php if(isset($key->form) && $key->form=='1'){
                                    echo $key->form_submited_date; 
                                } ?>
                                </td>
                                <td><a href="<?=base_url();?>admin/print_ack/<?=$key->id; ?>" class="kt-badge kt-badge--brand kt-badge--inline kt-badge--pill" target="_blank">View</a></td>
                                <td>
                                	<a href="<?=base_url();?>admin/print_form/<?=$key->id; ?>" class="kt-badge kt-badge--brand kt-badge--inline kt-badge--pill" target="_blank">Print
        							</a>                             
        							<?php
        							if ($user_type == 1 || $user_type == 2) {
        							?>	
                                    <a href="<?=base_url();?>admin/edit_student/<?=$key->id; ?>" class="kt-badge  kt-badge--info kt-badge--inline kt-badge--pill">Edit</a>			
        							<a href="javascript:confirmDelete('<?=base_url();?>admin/delete_student/<?=$key->id; ?>')" class="kt-badge  kt-badge--danger kt-badge--inline kt-badge--pill">Delete</a>
        							<?php }else{ ?>
                                    <?php if($key->form !='1'){ ?>
                                    <a href="<?=base_url();?>admin/edit_student/<?=$key->id; ?>" class="kt-badge  kt-badge--info kt-badge--inline kt-badge--pill">Edit</a>
                                <?php }} ?>
                                </td>
                            </tr>
                            <?php $i++; endforeach ?>
                        <?php } else{ ?>
                            <tr class="odd"><td valign="top" colspan="13" style="color: #595d6e;text-align: center;">No matching records found.</td></tr>
                        <?php } ?>
                         </tbody>
                    </table>
                </div>               
            </div>
           <div class="row">
               <div class="col-sm-12 col-md-5">
                  <div class="dataTables_info" id="kt_table_1_info" role="status" aria-live="polite">
                    <?=$showing_result;?>

                  </div>
               </div>
               <div class="col-sm-12 col-md-7">
                  <div class="dataTables_paginate paging_full_numbers" id="kt_table_1_paginate">
                     <?=$paging;?>
                  </div>
               </div>
            </div>
        </div>
      </div>
   </div>
</div>
	<div class="modal fade" id="modal-id">
    <div class="modal-dialog">
        <div class="modal-content"> 
		<form>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Add Enrollment</h4>
            </div>
			 <input type="hidden" name="students_id" id="students_id" value="" />
            <div class="modal-body">                
                     <div class="form-group">
                        <label for="">Enrollment No</label>
                        <input type="text" name = "enroll_no"  id = "enroll_no" maxlength="14" class="form-control" placeholder="Insert Student Enrollment No.">
                    </div>                                  
               
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" id="btn_add_inroll" onclick = "addEnrollemt()">Submit</button>
            </div> 
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->  
<div class="modal fade" id="modal-Pendency">
    <div class="modal-dialog">
        <div class="modal-content"> 
		<form>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Add Pendency</h4>
            </div>
			  <input type="hidden" name="student_id" id="student_id" value="" />
            <div class="modal-body" style="left: 50;">                
                    <div class="form-group">
                       <input type="checkbox" class="pendency" name="pendency[]" value="10th DMC" />
						<label for="">10th DMC</label>						
                    </div> 
                    <div class="form-group">
                       <input type="checkbox" class="pendency" name="pendency[]" value="12th DMC" />
						<label for="">12th DMC</label>						
                    </div> 
					 <div class="form-group">
                       <input type="checkbox" class="pendency" name="pendency[]" value="Graduation DMC" />
						<label for="">Graduation DMC</label>						
                    </div> 
                     <div class="form-group">
                       <input type="checkbox" class="pendency" name="pendency[]" value="PG DMC" />
						<label for="">PG DMC</label>						
                    </div> 
					 <div class="form-group">
                       <input type="checkbox" class="pendency" name="pendency[]" value="Degree/Provisional" />
						<label for="">Degree/Provisional </label>						
                    </div> 
					 <div class="form-group">
                       <input type="checkbox" class="pendency" name="pendency[]" value="Photo" />
						<label for="">Photo</label>						
                    </div>
                    <div class="form-group">
                       <input type="text" class="form-control" name="pendency_other" id="pendency_other" value="" placeholder="Others" />
											
                    </div> 					
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" id="btn_add_pendency" onclick = "addPendency()">Submit</button>
            </div> 
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->  	
<script type="text/javascript">
function openPendency(id){
	if(id!=''){		
		$('#student_id').val(id);
		var $modal = $('#modal-Pendency');        
        $('#modal-Pendency input[type=checkbox]').each(function() 
		{ 
				this.checked = false; 
		}); 	
		$modal.modal('show');
	}
}

function openEnroll(id){
	if(id!=''){
		$('#students_id').val(id);
		var $modal = $('#modal-id');		
		$modal.modal('show');
		$(".modal-body input").val("");
	}
}
function addEnrollemt(){
	var id = $('#students_id').val().trim();
	var enroll_no = $('#enroll_no').val().trim();
	if(id!='' && enroll_no!=""){
		var NORMALSERVER = "";
		 $("#btn_add_inroll").text("");	 
		 $("#btn_add_inroll").append("<img src='/images/btn-loader.gif'/>");
		  $.ajax({
            type: "POST",
            url: NORMALSERVER+"add_enrollment",
            data: {student_id:id,enroll_no:enroll_no},
            dataType: "JSON",
            success: function(data) {			
			if(data.success!=null && data.success!=''){	
                $('#openEnroll_'+id).empty();			
				$('#openEnroll_'+id).append(enroll_no);
				$("#btn_add_inroll").text("Submit");	
				var $modal = $('#modal-id');
		        $modal.modal('toggle');		
			}
            },
            error: function(err) {
			$("#btn_add_inroll").text("Submit");		 
            console.log(err);
            }
        });
		
	}
}
function deleteEnroll(id){
	if(id!=''){
		var NORMALSERVER = "";
		  $("#openEnroll_"+id).text("");	 
		  $("#openEnroll_"+id).append("<img src='/images/btn-loader.gif'/>");
		  $.ajax({
            type: "POST",
            url: NORMALSERVER+"delete_enrollment",
            data: {student_id:id},
            dataType: "JSON",
            success: function(data) {			
			if(data.success!=null && data.success!=''){	
                $('#openEnroll_'+id).empty();			
				$('#openEnroll_'+id).append(data.message);			
			}
            },
            error: function(err) {				 
            console.log(err);
            }
        });
		
	}
}
function deletePendency(id){
	if(id!=''){
		var NORMALSERVER = "";
		  $("#openPendency_"+id).text("");	 
		  $("#openPendency_"+id).append("<img src='/images/btn-loader.gif'/>");
		  $.ajax({
            type: "POST",
            url: NORMALSERVER+"delete_pendency",
            data: {student_id:id},
            dataType: "JSON",
            success: function(data) {			
			if(data.success!=null && data.success!=''){	
                $('#openPendency_'+id).empty();			
				$('#openPendency_'+id).append(data.message);			
			}
            },
            error: function(err) {				 
            console.log(err);
            }
        });
		
	}
}
function checkstatus(id){
	if(id!=''){
		var form_status = '0';	
		if($("#checkstatus_"+id).prop('checked')==true){ 
			form_status = '1';
		}
		if($("#checkstatus_"+id).not(':checked').length){
			form_status = '0';
        }
		var NORMALSERVER = "";		
		 $("#loader_"+id).append("<img src='/assets/media/icons/btn-loader.gif'/>");
		  $.ajax({
            type: "POST",
            url: NORMALSERVER+"admin/submit_form",
            data: {student_id:id,form_status:form_status},
            dataType: "JSON",
            success: function(data) {			
			if(data.success!=null && data.success!=''){	               
				$("#loader_"+id+"> img").remove();
			}
            },
            error: function(err) {
			$("#loader_"+id+"> img").remove();		 
            console.log(err);
            }
        });
		
	}
}
function addPendency(){
	var id = $('#student_id').val().trim();
	  var pendency = '';  
       $('.pendency:checked').each(function (i,e) {
        var comma = pendency.length===0?'':',';
        pendency += (comma+e.value);
       });
     var pendency_other = $('#pendency_other').val().trim();	   
	if(id!='' && (pendency!="" || pendency_other!="")){
		var NORMALSERVER = "";
		 $("#btn_add_pendency").text("");	 
		 $("#btn_add_pendency").append("<img src='/images/btn-loader.gif'/>");
		  $.ajax({
            type: "POST",
            url: NORMALSERVER+"add_pendency",
            data: {student_id:id,pendency:pendency,pendency_other:pendency_other},
            dataType: "JSON",
            success: function(data) {			
			if(data.success!=null && data.success!=''){	
                $('#openPendency_'+id).empty();			
				$('#openPendency_'+id).append(pendency);
				$("#btn_add_pendency").text("Submit");	
				var $modal = $('#modal-Pendency');
		        $modal.modal('toggle');		
			}
            },
            error: function(err) {
			$("#btn_add_pendency").text("Submit");		 
            console.log(err);
            }
        });
		
	}
}
</script>			