<?php 
require 'dao/Admission.php';
require 'dao/Global.php';
require 'dao/Setup.php';
$success1 = "";
$success2 = "";
$success3 = "";
if (isset($_POST['admit'])) {
	$class = $_POST['class'];
	$form = $_POST['form'];
	$house = $_POST['house'];
	$track = $_POST['track'];

	$student_name = $_POST['student_name'];
	$postal_address = $_POST['postal_address'];
	$home_address = $_POST['home_address'];
	$district = $_POST['district'];
	$dob = $_POST['dob'];
	$jhs = $_POST['jhs'];
	$bece_index = $_POST['bece_index'];
	$religion = $_POST['religion'];

	$admission_year = date("Y-m-d");
	$generated_name_1 = '';
		if (isset($_FILES['student_picture'])&&$_FILES["student_picture"]["name"]!='') {
		
		  $ext_1 = explode('.', basename($_FILES["student_picture"]["name"])); //explode file name from dot(.) 
                $file_extension_1 = end($ext_1); //store extensions in the variable
                $generated_name_1 .= md5(uniqid()) . "." . $ext_1[count($ext_1) - 1];
                move_uploaded_file($_FILES["student_picture"]["tmp_name"], "../student_pics/".$generated_name_1);

                //  $image_data = array("student_picture"=>$generated_name_1);
                // if ($_FILES['student_picture']['name']!='') {
                // 	$success3 = $admission->add_doc($image_data,$student_id);
                // }
                
	}
	
	$student_data = array("student_name"=>$student_name,"class"=>$class,
						  "postal_address"=>$postal_address,"home_address"=>$home_address,
						  "district"=>$district,"dob"=>$dob,
						  "jhs"=>$jhs,"bece_index"=>$bece_index,
						  "religion"=>$religion,"student_picture"=>$generated_name_1,
						  "admission_year"=>$admission_year,"track"=>$track,"form_id"=>$form,
						  "house_id"=>$house);
	$success1 = $admission->add_student($student_data);

	$father_name = $_POST['father_name'];
	$mother_name = $_POST['mother_name'];
	$father_occupation = $_POST['father_occupation'];
	$mother_occupation = $_POST['mother_occupation'];
	$father_address = $_POST['father_address'];
	$mother_address = $_POST['mother_address'];
	$guardian = $_POST['guardian'];
	$guardian_phone = $_POST['guardian_phone'];
	$guardian_email = $_POST['guardian_email'];

	$student_id = $admission->get_student_id();
	$student_id = $student_id[0]['student_id'];

	if ($student_id) {
		 $parent_data = array("father_name"=>$father_name,"father_occupation"=>$father_occupation,
						  "father_address"=>$father_address,"mother_name"=>$mother_name,"mother_occupation"=>$mother_occupation,
						  "mother_address"=>$mother_address,"guardian_name"=>$guardian,"guardian_email"=>$guardian_email,
						  "guardian_phone"=>$guardian_phone);
              $success2 =   $admission->add_parent($parent_data,$student_id);
	

	}

	if ($success1&&$success2) {
		echo 0;
	}else{
		echo 1;
	}
	
}
$std_class_id = '';
$std_class_id = '';
$class_students = '';
if (isset($_GET['cid'])&&isset($_GET['sub'])) {
	$std_class_id = $_GET['cid'];
	$subject_id = $_GET['sub'];
	$class_students = $admission->get_all_class_students($std_class_id);
}
$form_students = "";
$std_form_id = "";
if (isset($_GET['fid'])) {
	$std_form_id = $_GET['fid'];
	$form_students = $admission->get_all_class_students($std_form_id);
}

$classes = $admission->get_all_classes();
$forms = $admission->get_all_forms();
$students = $admission->get_all_students();
// $service = $admission->get_all_service();
$session = $admission->get_all_session();

$vacation = $global->get_vacation();
$globals = $global->get_all_globals();
	$a_year_id = $globals[0]['a_year_id'];
	$semester_id = $globals[0]['semester_id'];
	$track_id = $globals[0]['track_id'];
	$no_of_days = $globals[0]['no_of_days'];

$houses = $setup->get_houses();

//Accidentals
if (isset($_GET['cid'])) {
	$std_class_id = $_GET['cid'];
	
	$fill_report = $admission->fill_report($std_class_id,$track_id,$semester_id,$a_year_id);
	
}
if (isset($_GET['fid'])) {
	$std_class_id = $_GET['fid'];
	//$fill_report = $admission->fill_report($std_class_id,$track_id,$semester_id,$a_year_id);
	
}

function position($position)
	 {
	 	if ($position == 1 || $position == 21 || $position == 31 || $position == 41 || $position == 51 || $position == 61 || $position == 71 || $position == 81 || $position == 91)
{
echo $sup = "st";
}
else if ($position == 2 || $position == 22 || $position ==32 || $position == 42 || $position == 52 || $position == 62 || $position == 72 || $position == 82 || $position == 92)
{
echo $sup = "nd";
}
else if ($position == 3 || $position == 23 || $position == 33 || $position == 43 || $position == 53 || $position == 63 || $position == 73 || $position == 83 || $position == 93)
{
echo $sup = "rd";
}
else
{
echo $sup = "th";
}
	 } 
$all_class_students = "";
$subjects = "";
	 if (isset($_GET['kid'])) {
	 	//$sub = $_GET['sub'];
	 	$kid =$_GET['kid'];
	 	$class_name = $admission->get_class_name($kid);
	$class_name = $class_name[0]['class_name'];
	 	$all_class_students = $admission->get_class($kid);
$subjects =$admission->get_student_subjects($kid);
	 }

$student_report = "";
$subjects = "";
	 if (isset($_GET['sid']) && isset($_GET['cid'])) {
	 	//$sub = $_GET['sub'];
	 	$kid =$_GET['cid'];
	 	$student_id = $_GET['sid'];
	 	$class_name = $admission->get_class_name($kid);
	$class_name = $class_name[0]['class_name'];
	 	$student_report = $admission->student_report($kid,$student_id);
$subjects =$admission->get_student_subjects($kid);
	 }



	 if (isset($_POST['set'])) {

	 	$attendance = $_POST['attendance'];
	 	$student_id = $_POST['student_id'];
	 	$class = $_POST['std_class'];
	 	$conduct = $_POST['conduct'];
	 	$attitude = $_POST['attitude'];
	 	$interest = $_POST['interest'];
	 	$attendance_id = $_POST['attendance_id'];
	 	$a_year_id;
	 	$semester_id;
	 	$isset = $admission->get_attendance($student_id,$class,$semester_id,$a_year_id);
	 	$data = array("attendance"=>$attendance,"student_id"=>$student_id,
	 				  "class"=>$class,"a_year_id"=>$a_year_id,
	 				  "semester_id"=>$semester_id,"interest"=>$interest,
	 				  "conduct"=>$conduct,"attitude"=>$attitude);
	 	if (!$isset) {
	 		$success = $admission->attendance($data);
	 	}else{
	 		$success = $admission->update_attendance($data,$attendance_id);
	 	}
	 	

	 }

if (isset($_GET['::'])) {
	$student_id = $_GET['::'];
	$success = $admission->remove_student($student_id);
	$students = $admission->get_all_students();
}


 ?>

   