<?php 
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
//include("../../php_crud/my_class_for_web.php");
include("../../php_crud/my_class.php");
$obj = new my_class();
$branch_id = $_SESSION['LOGIN_BRANCH'];

$selected_session = $_SESSION['ADMISSION_SESSION'];
$selected_admission_details=addslashes(trim($_GET['admission_details_id']));

$table_name="_students_admission_form";
$column="admission_form_id,_candidate_name,_invoice_number,_mobile_number,_email,_approve_status,_candidate_status";
$where_cond="_class=".$selected_admission_details." ORDER BY admission_form_id ASC";
$can_list=$obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond);
?>
<style type="text/css">
i{
	cursor:pointer;
}

</style>
<div class="row-fluid">
<?php if(count($can_list)>0){?> 
    <button class="btn btn-small btn-primary " id="print-candidate-list" style="float:right; margin-bottom:15px" onclick="create_pdf_candidate_list(<?php echo $selected_admission_details;?>)">
		<i class="icon-print "></i>
		Print
	</button>
</div> 
<?php } ?>  
<div class="row-fluid" >
<table id="sample-table-22" class="table table-striped table-bordered table-hover">
    <thead>
		<th>Sl</th>
        <th>Form No</th>
        <th>Name</th>
        <th>Invoice</th>
		<th>Mobile Number</th>
		<!--<th>Email</th>-->
        <th>Approved Status</th>
        <th>Candidate Status</th>
        <th>Action</th>
    </thead>
    <tbody>
    <?php
        $sl = 1;
		foreach ($can_list AS $index1 => $value1) {
			echo "<tr>";
            echo "<td>" . $sl . "</td>";
            $sl++;
    ?>  
            <td><?php $selected_admission_form_id = $value1['admission_form_id']; 
					echo $selected_admission_form_id;
				?> 
			</td>
            <td><?php echo $value1['_candidate_name']; ?> </td>
            <td><?php echo $value1['_invoice_number']; ?> </td>
            <td><?php echo $value1['_mobile_number']; ?></td>
          <!--  <td><?php echo $value1['_email']; ?></td>  -->         
			<?php   $unpaid_select='';
					$paid_select='';
					$accepted_select='';
					$rejected_select='';
					$merit_list_select = '';
					$waiting_list_select = '';
					//$pending_select ='';
					//$success_select ='';
 					
					if ($value1['_approve_status'] == 'A') { 
						echo '<td><span class="label label-success">Approved</span></td>';
						//$approve_select ='selected="selected"';
                    }else if($value1['_approve_status']=='R')  {
						echo '<td><span class="label label-important arrowed-in">Rejected</span></td>';
						//$reject_select ='selected="selected"';
                    } else if($value1['_approve_status']=='P')	{ 
						echo '<td><span class="label label-warning">Pending</span></td>';
						//$pending_select ='selected="selected"'; 
					} else if($value1['_approve_status']=='S')	{ 
						echo '<td><span class="label label-info arrowed arrowed-right">Success</span></td>';
						//$success_select ='selected="selected"';  
					}
                        
					$selected_candidate_status = $value1['_candidate_status'];
					if($selected_candidate_status=='UP'){
						echo '<td><span class="label label-warning">Pending</span></td>';
						$unpaid_select='selected="selected"';
					}else if($selected_candidate_status=='RE'){
						echo '<td><span class="label label-important">Disapproved</span></td>';
						$rejected_select='selected="selected"';
					}else if($selected_candidate_status=='PA'){
						echo '<td><span class="label label-info">Approved</span></td>';
						$paid_select='selected="selected"';
					}else if($selected_candidate_status=='ME'){
						echo '<td><span class="label label-success">Merit List</span></td>';
						$merit_list_select ='selected="selected"';
					}else if($selected_candidate_status=='WA'){
						echo '<td><span class="label label-warning">Waiting List</span></td>';
						$waiting_list_select ='selected="selected"';
					}?>
					<td>
                    <?php 
						if($_SESSION['add']=='Y'){
							if($selected_candidate_status=='UP' || $selected_candidate_status=='RE'){
								$appro_status = 'Approve';
								$approve_class = 'btn-success tooltip-success btn-single-approve';
								$data_title = 'Click to Approve';
							}else{
								$appro_status = 'Disapprove';
								$approve_class = 'btn-danger tooltip-info  btn-single-unapprove';
								$data_title = 'Click to Unapprove';
							}
						echo '<span data-original-title="'.$data_title.'" class="btn  btn-small  icon-ok '.$approve_class.'" data-rel="tooltip" data-placement="top" title="">'.$appro_status.'</span>';
						
						}?>
						<i class="icon-edit bigger-170" style="hover:cursor; margin-left:10px;"></i>
                        </td>
						<input type="hidden" name="admission_form_id" value="<?php echo $value1['admission_form_id']; ?>" class="admission_form_id"  /> 
							<?php echo "</tr>";}?>
    </tbody>
</table>
</div>
<script>
	var oTable2 = $('#sample-table-22').dataTable({
                "aoColumns": [
                    {"bSortable": true},
                    null,null,null, null,null,null,
                    {"bSortable": true}
                ]});
	/*$("#print-candidate-list" ).click(function() {	
		var branch_id = $( "#branch_id" ).val();
		var class_name = $( "#class_name" ).val();
		var dpt_num = $( "#dpt_num" ).val();
		var dataStr = "branch_id=" + branch_id+"&class_name=" + class_name+"&dpt_num=" + dpt_num; 
			
		$.ajax({
            type: 'post',
            url: "module/admission/pdf_generator_exam_candidate_list.php",
            data: dataStr,
            success: function (response)
            {
               window.open('<?php echo $bs_url; ?>');
			   
			   
            }
        });
		return false;
	});	 */
$("table").on("click", ".btn-single-approve", function(event){		
	$this = $(this);
	$paent = $this.parent();
	var selected_admission_form_id = '';
	selected_admission_form_id = $( this ).parent().parent().find( ".admission_form_id" ).val();
	var approved_status='A';
	var candidate_status='PA';
	var operation = "update_candidate_status";
	var dataStr = "selected_admission_form_id="+selected_admission_form_id+
				  "&approved_status="+approved_status+"&candidate_status="+candidate_status+
				  "&operation="+operation; 
	//alert(dataStr);	
	$.ajax({
        type: 'post',
        url: "module/admission/candidate_list_ajax.php",
        data: dataStr,
        success: function (response)
        {
            $this.parent().empty();
			$paent.html('<span data-original-title="Click to Unapprove" class="btn  btn-small  icon-ok btn-danger tooltip-info  btn-single-unapprove" data-rel="tooltip" data-placement="top" title="">Disapprove</span><i class="icon-edit bigger-170" style="hover:cursor; margin-left:10px;"></i>');
			//alert(response);
			if(response==0){
				alert(response);
			}
			else{
				var admission_details_id="admission_details_id="+response;
				$("#show_candidate_list").load("module/admission/temp_candidate_list_datatable.php",admission_details_id);
			}
        }
    });
	return false;
});
	
//	$( ".btn-single-unapprove" ).click(function() {
//	$(".btn-single-unapprove").on("click", function(event){
$("table").on("click", ".btn-single-unapprove", function(event){		
	$this = $(this);
	$paent = $this.parent();
	var selected_admission_form_id = '';
	selected_admission_form_id = $( this ).parent().parent().find( ".admission_form_id" ).val();
	var approved_status='R';
	var candidate_status='RE';
	var operation = "update_candidate_status";
	var dataStr = "selected_admission_form_id="+selected_admission_form_id+
				  "&approved_status="+approved_status+"&candidate_status="+candidate_status+
				  "&operation="+operation; 
	//alert(dataStr);	
	$.ajax({
        type: 'post',
        url: "module/admission/candidate_list_ajax.php",
        data: dataStr,
        success: function (response)
        {
            $this.parent().empty();
			$paent.html('<span data-original-title="Click to Approve" class="btn  btn-small  icon-ok btn-success tooltip-success btn-single-approve" data-rel="tooltip" data-placement="top" title="">Approve</span><i class="icon-edit bigger-170" style="hover:cursor; margin-left:10px;"></i>');
			//alert(response);
			if(response==0){
				alert(response);
			}
			else{
				var admission_details_id="admission_details_id="+response;
				$("#show_candidate_list").load("module/admission/temp_candidate_list_datatable.php",admission_details_id);
			}
        }
    });
	return false;
});
$("table").on("click", ".icon-edit", function(event){
	var selected_admission_form_id = $( this ).parent().parent().find( ".admission_form_id" ).val();
	var datastr="admission_form_id="+selected_admission_form_id;
	document.getElementById("candidate_list_view_holder").style.display = "none";
	document.getElementById("candidate_list_edit_holder").style.display = "block";
	$("#candidate_list_edit_holder").load('module/admission/edit_selected_admission_form.php?'+datastr);
});
</script>

    