<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============

extract($_GET);
$today_date;
$medium_id;
$atd_status_id;
$atd_session;
?>

<style type="text/css">
	.input-append, .input-prepend {
		margin-bottom: 0px !important;
	}
	.table td {
		padding: 3px !important;
	}
</style>


<?php
$det_in = $obj->Details_By_Cond("_int_institute_setup_vw","section_id='$section_id'");

$tch_id = $obj->Details_By_Cond("_r_class_routine","_section_id='$section_id' AND _teacher_type='CT' AND _teacher_id!='0' GROUP BY _teacher_type");
$teacher_id =  $tch_id['_teacher_id'];

$tch_det = $obj->Details_By_Cond("_pf_emp_personal_info","_id='$teacher_id'");

$class_name 		= $det_in['class'];
$department_name 	= $det_in['department'];
$student_type 		= $det_in['student_type'];
$section_name 		= $det_in['section'];
?>

<div class="row-fluid">
<legend>
<div class="widget-header header-color-green2">
<h4 class="lighter smaller" style="font-weight:bold;">Daily Class Wise Attendance Sheet</h4>
<div class="span12 label label-danger arrowed-in arrowed-in-right" style="margin:10px 0px 0px 20px;width:220px;font-size:13px;">
                <b>Attendance Date : <?php echo $today_date; ?></b>
                </div>
				<div class="span12 label label-danger arrowed-in arrowed-in-right" style="margin:10px 0px 0px 20px;width:220px;font-size:13px;">
                <b>Session: <?php echo $atd_session; ?></b>
                </div>
<a href="#" id="back_att" style="float:right;">
	<!--<img src="asset/custom/back.png" id="back" >-->
    <span class="label btn-mini btn-warning no-border" style="padding: 8px 24px 3px; height:28px; margin-top:0px; display:block;font-size:16px">
    <i class="icon-arrow-left"></i>
    Back
</span>
</a>
</div>

</legend>
</div>
<div class="row-fluid" style="background-color:#f5f5f5;-webkit-box-shadow: 0 8px 6px -6px black; -moz-box-shadow: 0 8px 6px -6px black; box-shadow: 0 8px 6px -6px black; margin-top:-15px; display:block;">
	<div class="span3">
		<div class="control-group" >
			<div class="span12 label label-info arrowed-in arrowed-in-right" style="margin:5px 0px 0px 10px;width:150px;font-size:13px;">
            <b>Class : <?php echo $class_name; ?></b>
            </div>
		</div>
	</div>	
	
	<div class="span3">
		<div class="control-group" >
				<div class="span12 label label-success arrowed-in arrowed-in-right" style="margin:5px 0px 0px 10px;width:150px;font-size:13px;">
                <b>Department : <?php echo $department_name; ?></b>
                </div>
			</div>
	</div>
    <div class="span3">
		<div class="control-group" >
				<div class="span12 label label-warning arrowed-in arrowed-in-right" style="margin:5px 0px 0px 10px;width:200px;font-size:13px;">
                <b>Student Type : <?php echo $student_type; ?></b>
                </div>
                
			</div>
	</div>
    <div class="span3">
		<div class="control-group" >
				<div class="span12 label label-danger arrowed-in arrowed-in-right" style="margin:5px 0px 0px 10px;width:150px;font-size:13px;">
                <b>Section : <?php echo $section_name; ?></b>
                </div>
                
			</div>
	</div>
	 <div class="span3">
		<div class="control-group" >
				<div class="span12 label label-danger arrowed-in arrowed-in-right" style="margin:5px 0px 0px 10px;width:150px;font-size:13px;">
                <b>Section : <?php echo $section_name; ?></b>
                </div>
                
			</div>
</div>
<br />

<!-- ==================================== -->
<form class="form-vertical" id="attendance_sheet">

<div class="row-fluid">	
	<input type="hidden" name="atd_status_id" value="<?php echo $atd_status_id; ?>">
	<input type="hidden" name="medium_id" value="<?php echo $medium_id; ?>">
	<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
    <input type="hidden" name="today_date" value="<?php echo $today_date; ?>">					
	<input type="hidden" name="atd_session" value="<?php echo $atd_session; ?>">
	<table class="table table-striped table-bordered table-hover">
		<thead>
			<th>Sl</th>
			<th>Student ID</th>
			<th>Name</th>
			<th>Roll</th>
			<th style="text-align: center;">Present</th>
			<th style="text-align: center;">Absent</th>
			<th style="text-align: center;">Late</th>
			<th style="text-align: center;">Late Time</th>
			<th style="text-align: center;">Leave</th>
            <th style="text-align: center;">In Time</th>
            <th style="text-align: center;">Out Time</th>
			<th style="text-align: center;">Comments</th>
			<th style="text-align: center;">Contact No</th>
            
		</thead>
		<tbody>
			<?php
			$i=0;
			foreach($obj->View_Student_List("sc._id='$section_id' AND pf_std._status='A' AND bsf._session='$atd_session' ORDER BY _section_roll ASC") as $value){
			extract($value);
			$i++;	
			?>	
			<tr>
				<td class="td_pad">
					<input type="hidden" name="std_id_<?php echo $i; ?>" value="<?php echo $value['_id']; ?>">
					<?php echo $i; ?>
				</td>
				<td class="td_pad"><?php echo $value['_uniq_id']; ?></td>
				<td class="td_pad"><?php echo $value['_full_name']; if(!empty($value['_nick_name'])){echo ' ('.$value['_nick_name'].')'; } ?></td>
				<td class="td_pad"><?php echo $value['_section_roll']; ?></td>
				<td class="td_pad" style="text-align: center;"><label><input type="radio" id="atd_status_<?php echo $i; ?>" name="atd_status_<?php echo $i; ?>" value="P" checked><span class="lbl"></span></label></td>
				<td class="td_pad" style="text-align: center;"><label><input type="radio" id="atd_status_<?php echo $i; ?>" name="atd_status_<?php echo $i; ?>" value="A"><span class="lbl"></span></label></td>
				<td class="td_pad" style="text-align: center;"><label><input type="radio" id="atd_status_<?php echo $i; ?>" name="atd_status_<?php echo $i; ?>" value="LA"><span class="lbl"></span></label></td>
				<td class="td_pad" style="text-align: center;">
					<input name="late_time_<?php echo $i; ?>" type="text" class="input-mini spinner1"/>
				</td>
				<td class="td_pad" style="text-align: center;"><label><input type="radio" name="atd_status_<?php echo $i; ?>" value="LE"><span class="lbl"></span></label></td>
                 <td class="td_pad"><input name="in_time_<?php echo $i; ?>" type="text" class="input-mini "/></td>
                <td class="td_pad"><input name="out_time_<?php echo $i; ?>" type="text" class="input-mini "/></td>
				<td class="td_pad" style="text-align: center;"><input name="comments_<?php echo $i; ?>" class="input-small" type="text" placeholder="Comments"></td>
				<td class="td_pad"><?php echo $value['_contact_mobile']; ?></td>
               
			</tr>	
			<?php
			}
			$total_row = $obj->View_Student_List_rows("sc._id='$section_id' AND pf_std._status='A' AND bsf._session='$atd_session'");
			?>
			<tr>
				<input type="hidden" name="total_row" value="<?php echo $total_row; ?>">
			</tr>
		</tbody>	

	</table>
</div>

<!-- ========================== -->

<div class="row-fluid">	
	<div class="span5"><b>Class Teacher name:</b> <?php echo $tch_det['_full_name']; if(!empty($tch_det['_nick_name'])){ echo ' ('.$tch_det['_nick_name'].')';} ?></div>

	<div class="span3"><b>Mobile No:</b> <?php echo $tch_det['_contact_mobile_no']; ?></div>
</div>

<!-- ========================= -->

<div class="row-fluid">	
	<div class="span3">Attendance Time
		<div class="controls">
			<div class="input-append bootstrap-timepicker">
				<input name="atd_time" type="text" class="input-small timepicker1" />
				<span class="add-on">
					<i class="icon-time"></i>
				</span>
			</div>
		</div>
	</div>

	<div class="span3">Comments
		<div class="controls">
			<input name="remarks" class="input-large" type="text" placeholder="Comments">
		</div>
	</div>
</div>


<!-- =========================== -->

<div class="row-fluid">									
	<div class="span12">			
		<div class="control-group">
			<label class="control-label" for="form-field-1">&nbsp;</label>
			<div class="loading"></div>
			<div class="controls">
				<?php if($total_row){ ?>
				<button class="btn btn-small btn-success" type="button" id="btn_save_atdsheet">
					<i class="icon-ok bigger-100"></i>Save
				</button>
				<?php
				}
				else{
				?>
				<button class="btn btn-small btn-success" type="button" id="btn_save_atd">
					<i class="icon-ok bigger-100"></i>Save
				</button>
				<?php } ?>

				&nbsp; &nbsp; &nbsp;
				<button class="btn btn-small btn-danger" type="reset" id="btn_reset">
					<i class="icon-undo bigger-100"></i>
					Reset
				</button>
			</div>
		</div>
	</div>
	
</div>


</form>


<script type="text/javascript">
$('.spinner1').ace_spinner({value:0,min:0,max:80,step:1, btn_up_class:'btn-info' , btn_down_class:'btn-info'})
.on('change', function(){
});



$('.timepicker1').timepicker({
	minuteStep: 1,
	showSeconds: false,
	showMeridian: false
})



$("#btn_save_atdsheet").click(function(){

	var atd_status_id = $('input[name="atd_status_id"]').val();	
	var medium_id = $('input[name="medium_id"]').val();
	var section_id = $('input[name="section_id"]').val();
	var today_date = $('input[name="today_date"]').val();
	var atd_session = $('input[name="atd_session"]').val();
	var remarks = $('input[name="remarks"]').val();
	var atd_time = $('input[name="atd_time"]').val();
	var total_row = $('input[name="total_row"]').val();
	var operation = 'save_atd';
	var operation2 = 'up_status';

	//var rs = false;
	//alert(today_date);
	$(".loading").show();
	$('.loading').html("<span style='color:#2e8965;font-size:16px;font-weight:bold;'>Data Generating.... Please Wait.  <img src='php_crud/img/preloader.gif' /></span>");
	
	for (i = 1; i <= total_row; i++) {

		var std_id = $('input[name="std_id_'+i+'"]').val();
		var atd_status = $('input:radio[name="atd_status_'+i+'"]:checked').val();
		var late_time = $('input[name="late_time_'+i+'"]').val();
		var comments = $('input[name="comments_'+i+'"]').val();

		
		var dataStr="operation="+operation+"&section_id="+section_id+"&std_id="+std_id+"&atd_status="+atd_status+"&late_time="+late_time+"&comments="+comments+"&today_date="+today_date;
		
		var dataStr2="operation2="+operation2+"&atd_status_id="+atd_status_id+"&atd_time="+atd_time+"&remarks="+remarks+"&today_date="+today_date;

		var dataStr3="medium_id="+medium_id+"&atd_session="+atd_session;

		//alert(late_time);

		$.ajax({
			type:"post",
			url:"module/attendance/save_atd_data_class.php",
			data:dataStr ,
			success:function(result){
			
			}
		});
	}

	$.ajax({
		type:"post",
		url:"module/attendance/save_atd_data_class.php",
		data:dataStr2 ,
		success:function(st){
			//alert(st);
			if(st==1){
			alert('Data Saved Successfully. ');
			$('#btn_save_atdsheet').css("display","none");
			$(".loading").hide();
			}
			//$(".data_to_show_atd").load("module/attendance/daily_attendance_class_status_view.php",dataStr3);

			//$('#first_part').remove();
			//$('#second_part').css("display","block");
		}
	});

});



// =================================



$("#btn_save_atd").click(function(){

	var atd_status_id = $('input[name="atd_status_id"]').val();
	var medium_id = $('input[name="medium_id"]').val();
	var remarks = $('input[name="remarks"]').val();
	var atd_time = $('input[name="atd_time"]').val();
	var atd_session = $('input[name="atd_session"]').val();
	var operation2 = 'up_status';

	var dataStr4="operation2="+operation2+"&atd_status_id="+atd_status_id+"&atd_time="+atd_time+"&remarks="+remarks;

	var dataStr5="medium_id="+medium_id+"&atd_session="+atd_session;


	$.ajax({
		type:"post",
		url:"module/attendance/save_atd_data_class.php",
		data:dataStr4 ,
		success:function(st){
			//alert(st);
			$(".data_to_show_atd").load("module/attendance/daily_attendance_class_status_view.php",dataStr5);

			$('#first_part').remove();
			$('#second_part').css("display","block");
		}
	});

});
</script>


<script type="text/javascript">
    $('#back_att').click(function(){
	var medium_id  = $('input[name="medium_id"]').val();
	var section_id = $('input[name="section_id"]').val();
	var today_date = $('input[name="today_date"]').val();
	var atd_session = $('input[name="atd_session"]').val();
	var dataStr1="medium_id="+medium_id+"&section_id="+section_id+"&today_date="+today_date+"&atd_session="+atd_session;
	//alert(dataStr1);
    $(".data_to_show_atd").load("module/attendance/daily_attendance_class_status_view.php",dataStr1);
    });
</script>


<script type="text/javascript">
	$('.date-picker').datepicker().next().on(ace.click_event, function(){
     $(this).prev().focus();
    });
	
	$("#btn_search").click(function(){
   	var date = $('#date').val();
	var datast_mfs ="date="+date;
	$("#data_to_show").show();
	$('#data_to_show').html("<span style='color:#2e8965;font-size:16px;font-weight:bold;text-align:center;'>Data Generating.... Please Wait.  <img src='php_crud/img/preloader.gif' /></span>");
	if(date==""){
		alert("Select Date");
		$('#date').focus();
		return false;
	}
	$('#data_to_show').load('module/fees/fee_collection_datatable.php',{'date':date},function(data){
			//alert(data);
		}); 
   });
</script>