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


$section_id;
$ct_id;
$subject_id;
$newDate = date("Y-m-d", strtotime($ct));
$exam_term;
$det_in = $obj->Details_By_Cond("_int_institute_setup_vw","section_id='$section_id'");
extract($det_in);
//$sub_id = $obj->Details_By_Cond("_ct_class_test_add","_br_id='$branchid' AND _id='$ct_id'");
//$subject_id=$sub_id['_sub_id'];

// =================================================
$exam_session;
$subject_det = $obj->Details_By_Cond("_int_subject","_id='$subject_id'");
$subject_type = $subject_det['_subject_type'];
$combined_id = $subject_det['_combined_sub_id'];

if($subject_id)
{

//foreach($obj->sub_wise_std_data($section_id,$exam_session,$subject_id) as $value){
foreach($obj->View_Student_List("sc._id='$section_id' AND bsf._session='$exam_session' AND pf_std._status='A'") as $value){
//extract($value);
//$sub_select_id = $value['_id'];
//$std_id = $value['_std_id'];

// if($subject_id){
// 	foreach($obj->View_Student_List("sc._id='$section_id' AND pf_std._status='A'") as $value){
		
		$form_data = array(
	        '_br_id'=>$_SESSION['LOGIN_BRANCH'],
			'_ct_id'=>$ct_id,
			'_subject_id'=>$subject_id,
			'_date'=>$newDate,
			'_exam_session'=>$exam_session,
			'_exam_term'=>$exam_term,
			'_section_id'=>$section_id,
			'_std_id'=>$value['_id'],
			'_atd_status'=>'P',
			'_status'=>'I',
			'_entry_by'=>$_SESSION['LOGIN_USERID'],
			'_entry_date'=>date("Y:m:d h:i:s")
		);

		$obj->Insert_Data_By_Cond("_ct_mark_sheet", $form_data,"_br_id='".$_SESSION['LOGIN_BRANCH']."' AND _ct_id='$ct_id' AND _subject_id='$subject_id' AND _exam_term='$exam_term' AND _std_id='".$value['_id']."'");
	}
}

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


$ct_dtls = $obj->Details_By_Cond("_ct_class_test_add","_br_id='$branchid' AND _id='$ct_id'");


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

$total_row = $obj->Total_Count_By_Cond("_ct_mark_sheet","_br_id='".$_SESSION['LOGIN_BRANCH']."' AND _ct_id='$ct_id'  AND _subject_id='$subject_id' AND _section_id='$section_id'");


$tch_id = $obj->Details_By_Cond("_r_class_routine","_section_id='$section_id' AND _teacher_type='ST' AND _subject_id='$subject_id' AND _teacher_id!='0' GROUP BY _teacher_type");
$teacher_id =  $tch_id['_teacher_id'];
$sub_tch_det = $obj->Details_By_Cond("_pf_emp_personal_info","_id='$teacher_id'");

?>

<script src="module/ct/js/ct_marks_entry.js" type="text/javascript"></script>
<div class="row-fluid"><div class="widget-box2">
		<div class="widget-header header-color-green2">
			<h4 class="smaller" >
				<small style="color:#fff;">Marks Entry Subject Selection </small>
			</h4>
			<button onclick="return_to_ct_sub_list()" class="btn btn-small btn-success" type="button" id="back_qz_sub_table" style="text-align:right; float:right;">
				<i class="icon-arrow-left icon-on-left"></i>
					BACK
			</button>
		</div>
		<div class="widget-body">
			<div class="widget-main">
				<p> 
					<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Shift:</b> '.$det_in['shift'];?></span> 
					<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Class:</b> '.$det_in['class']; ?></span> 
					<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Department:</b> '.$det_in['department'];?></span> 
					<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Student Type:</b> '.$det_in['student_type'];?></span>  
					<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Section:</b> '.$det_in['section']; ?> </span> 
					<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>CT Name:</b> '.$ct_dtls['_ct_name']; ?> </span> 
				</p>
				<p>
					<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Subject Name:</b> '.$subject_det['_subject_full_name']; ?> </span> 
				</p> 
			</div>
		</div>
</div></div>
<div class="row-fluid">
	<div class="span6" style="min-height: 20px;"><b>Subject Teacher Name:</b> <?php echo $sub_tch_det['_full_name']; if(!empty($sub_tch_det['_nick_name'])){ echo ' ('.$sub_tch_det['_nick_name'].')';} ?></div>
	<div class="span4" style="min-height: 20px;"><b>Contact No:</b> <?php echo $sub_tch_det['_contact_mobile_no']; ?></div>
	<div class="span2" style="min-height: 20px;"><b>Total Student:</b> <?php echo $total_row; ?></div>
</div>



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

<style type="text/css">
	.text_style {
		text-align: center !important;
		font-size: 11px;
		padding: 4px;
	}

	.text_style2 {
		font-size: 11px;
		padding: 4px;
	}
	.input_custom{
		width: 40px;
		height: 15px !important;
		padding: 4px !important;
		margin-bottom: 0px !important;
		text-align: center !important;
	}
</style>

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

<form class="form-vertical" >
	<input type="hidden" name="br_id" value="<?php echo $_SESSION['LOGIN_BRANCH'];?>"/>
	<input name="total_row" id="total_row" type="hidden" value="<?php echo $total_row; ?>">
	<input name="asin_mrk" id="asin_mrk" value="<?php echo $subject_det['_ct_asign_mark']; ?>" type="hidden">
	<input name="pass_mrk" id="pass_mrk" value="<?php echo $subject_det['_ct_pass_mark']; ?>" type="hidden">
	<input name="" id="subject_id" value="<?php echo $subject_id; ?>" type="hidden">
	
	<div class="row-fluid" style="margin-top: 15px;">										
		<table id="sample-table-121" class="table table-striped table-bordered table-hover">
			<tr>
				<th>Sl</th>
				<th>Student ID</th>
				<th>Name</th>
				<th>Roll</th>
				<th>
					Mark (Assign=<?php echo $subject_det['_ct_asign_mark'].', Pass='.$subject_det['_ct_pass_mark'].'%'; ?>)
				</th>
				<th>Comments</th>
				<th>
					Present / Absent
				</th>
			</tr>

			<?php
			$table_name = "_ct_mark_sheet b LEFT JOIN _pf_std_personal_info a ON a._id=b._std_id";
			$column = "b._id as idd,a._uniq_id,a._full_name,a._section_roll,b._mark,b._comments,b._atd_status";
			$where_cond = "b._exam_session='$exam_session' AND b._section_id=$section_id AND b._ct_id=$ct_id AND b._subject_id=$subject_id AND b._exam_term='$exam_term' ORDER BY _section_roll ASC"; 
			$i=0;
			foreach($obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond) as $v1){
			$i++;

			if($v1['_atd_status']=='P'){
				$checked = 'checked';
				$status_val = 'A';
				}
				else{
					$checked = '';	
					$status_val = 'P';
				}

			?>
			<tr>
				<input name="mark_id_<?php echo $i; ?>" id="mark_id_<?php echo $i; ?>" value="<?php echo $v1['idd']; ?>" type="hidden">
				<td><?php echo $i; ?></td>
				<td><?php echo $v1['_uniq_id']; ?></td>
				<td><?php echo $v1['_full_name']; ?></td>
				<td><?php echo $v1['_section_roll']; ?></td>
				<td class="text_style">
					<input onkeyup="mark_check(<?php echo $i ?>)" class="input_custom" name="mark_<?php echo $i; ?>" id="mark_<?php echo $i; ?>" value="<?php echo $v1['_mark']; ?>">
				</td>
				<td class="text_style">
					<input name="comments_<?php echo $i; ?>" id="comments_<?php echo $i; ?>" value="<?php echo $v1['_comments']; ?>">
				</td>
				<td style="text-align: center;">
					<div class="controls">
						<label>
							<?php if($_SESSION['edit']=='Y' OR $_SESSION['add']=='Y'){ ?>
							<input <?php echo $checked; ?> onclick="quize_atd_status('<?php echo $v1['idd'] ?>','<?php echo $status_val;?>')" type="checkbox"/>
							<span class="lbl"></span>
							<?php
							}
							else{
							?>
							<input <?php echo $checked; ?> type="checkbox" readonly="readonly" />
							<span class="lbl"></span>
							<?php } ?>								
						</label>
					</div>
				</td>
			</tr>
			<?php
			}
			?>

		</table>
		
	</div>

	<div class="row-fluid">
		<div class="span6">
			<div class="controls">
				<?php if($_SESSION['edit']=='Y' OR $_SESSION['add']=='Y'){ ?>
				<button class="btn btn-small btn-success" type="button" id="save_marks_sheet">
					<i class="icon-ok bigger-100"></i>
					Save
				</button>
				<?php } ?>
			</div>
		</div>
	</div>

</form>