<?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'];
$current_year = date("Y");
$admission_settings_cond = "YEAR(_create_date)='$current_year' AND _status='A'";
$admission_master_info = $obj->Details_By_Cond("_student_admission_master",$admission_settings_cond);
$_SESSION['ADMISSION_SESSION'] = $admission_master_info['_session'];

$table_name='_students_admission_mark_settings';
$where_cond="branch_id='".$branch_id."' limit 1";
$list=$obj->num_of_rows($table_name,$where_cond);

$total_mark = '';
$pass_mark = '';
$current_session = '';

if($list->num <= 0){
	$status ='insert';
	$current_session = $admission_master_info['_session'];
	$total_mark = '';
	$pass_mark = '';
	
}else{
		$status ='update';
		$column = 'total_mark,pass_mark,current_session';
		$can_list=$obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond);
		foreach ($can_list AS $index1 => $value1) {
			$current_session = $value1['current_session'];
			$total_mark = $value1['total_mark'];
			$pass_mark = $value1['pass_mark'];
		}
}
?>

<div class="row-fluid">
    <div class="span12">
        <div class="widget-header widget-header-large" style="border: 0;   background:none">
            <h3 class=" lighter pull-left position-relative" style="color: #2679B5;">
                <i class="icon-hand-right green"></i>
                Admission Settings
            </h3>
        </div>
        <div class="hr hr-18 hr-double dotted"></div>
        </div>
        <?php 
			if(($_SESSION['add']=='Y') || ($_SESSION['edit']=='Y')){
		?>    
		<div class="row-fluid">
            <div class="span3">
                <div class="control-group">
                    <label class="control-label form-label" for="form-field-1">Current Session <span style="color:red">*</span></label>
                    <div class="controls">
                        <input id="current_session" name="current_session" placeholder="On Going Session" type="text" value="<?php echo $current_session; ?>"> YYYY
                    </div>
                </div>
            </div>
			<div class="span3">
                <div class="control-group">
                    <label class="control-label form-label" for="form-field-1">Total Mark <span style="color:red">*</span></label>
                    <div class="controls">
                        <input id="total_mark" name="total_mark" placeholder="Total Mark" type="text" value="<?php echo $total_mark; ?>">
                    </div>
                </div>
            </div>
            <div class="span3"> 
                <div class="control-group">
                    <label class="control-label form-label" for="pass_mark">Pass Mark( Percentage) : <span style="color:red">*</span></label>
                    <div class="controls">
                        <input id="pass_mark" name="pass_mark" placeholder="Pass Mark" type="text" value="<?php echo $pass_mark; ?>" > %
                    </div>
                </div>
            </div>
		</div>
		<div class="row-fluid">
			<div class="span3">
				<br>
                <input type="hidden" name="branch_id" value="<?php echo $branch_id; ?>" id="branch_id"/>
				<button id="action-btn" type="button" class="btn btn-success <?php echo $status; ?>" >
					<i class="icon-save bigger-160"></i>
			  <?php if($status=='insert'){
						echo 'Save'; 
					}
					else{
					echo 'Update';} ?>  
				</button>
            </div>            
        </div>
<?php } ?> 
</div>

<div class="row-fluid" id="mark_settings_list">
</div>
<script> 
$(this).ready(function(){
    $("#mark_settings_list").load("module/admission/mark_settings_list_datatable.php");
});	
	$('#action-btn').click(function(){
//	$('.edit-admit').on('click', function(){
	
//$("#main_content_div").on("click", ".edit-admit", function(event){	
		$this = $(this) ;
		var branch_id = $("#branch_id").val();
		var total_mark = $("#total_mark").val();
		var pass_mark = $("#pass_mark").val();
		var current_session = $("#current_session").val();
		if($(this).hasClass('insert')){
			var operation = 'insert';	  
		}else{
			var operation = 'update';
			}
		
			
		var dataStr = "operation="+operation+"&branch_id="+branch_id+"&total_mark="+total_mark+"&pass_mark="+pass_mark+"&current_session="+current_session;
		if(!current_session){
			alert('oops!!! Current Session is required');
			$("#current_session").focus();
		}else if(!total_mark || !pass_mark){
			if(!total_mark){ $("#total_mark").focus(); } 
			if(!pass_mark){ $("#pass_mark").focus();  }
			
			alert('oops!!! Field Entry missing');
		}else if(!total_mark.match(/^\d+$/) || !pass_mark.match(/^\d+$/)  ) {
    		alert('Only Numaric Value Allowed')
			
		}
		else{
			$.ajax({
				type:"POST" ,
			  	url:"module/admission/save_mark_setings.php" ,
			  	data:dataStr ,
			  	success:function(st){
					alert('Success');
					$("#mark_settings_list").load("module/admission/mark_settings_list_datatable.php");
			  	}
			});
		}
		
		return false ;
	});						
</script>

    