<?php 
require 'dao/Setup.php';
require 'dao/Admission.php';
$success = false;
$response = 0;
$msg = "";
$err = "";
$class_id = "";
$edit_class = "";

$sem_id = "";
$edit_sem = "";

$a_year_id = "";
$edit_a_year = "";

$track_id = "";
$edit_track = "";

$subject_id = "";
$edit_subject = "";

$house_id = "";
$edit_house = "";

$fee_type_id = "";
$edit_fee_type = "";

$set_fee_id = "";
$edit_set_fee = "";

$pay_fee_id = "";
$edit_pay_fee = "";
//
if (isset($_POST['add_class'])) {
	$class_name = $_POST['class_name'];
	$programme_id = $_POST['programme_id'];
	$data = array("class_name"=>$class_name,
				  "programme_id"=>$programme_id);
	$success = $setup->add_class($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}

if (isset($_POST['add_programme'])) {
	$programme_name = $_POST['programme_name'];
	$data = array("programme_name"=>$programme_name);
	$success = $setup->add_prog($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}



if (isset($_POST['add_house'])) {
	$house_name = $_POST['house_name'];
	$data = array("house_name"=>$house_name);
	$success = $setup->add_house($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}


if (isset($_POST['add_subject'])) {
	$subject_name = $_POST['subject_name'];
	$core_elective = $_POST['core_elective_id'];
	$data = array("subject_name"=>$subject_name,
				  "core_elective_id"=>$core_elective);
	$success = $setup->add_subject($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}

if (isset($_POST['add_sem'])) {
	$sem_name = $_POST['sem_name'];
	$data = array("sem_name"=>$sem_name);
	$success = $setup->add_semester($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}

if (isset($_POST['add_a_year'])) {
	$a_year_name = $_POST['a_year'];
	$data = array("a_year"=>$a_year_name);
	$success = $setup->add_a_year($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}


if (isset($_POST['add_track'])) {
	$track_name = $_POST['track_name'];
	$data = array("track_name"=>$track_name);
	$success = $setup->add_track($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}
//



// Start Class inc
if (isset($_GET['c::'])) {
	$class_id = $_GET['c::'];
	$edit_class = $setup->get_class($class_id);

}
if (isset($_POST['update_class'])) {
	$class_name = $_POST['class_name'];
	$programme_id = $_POST['programme_id'];
	$class_id = $_POST['class_id'];
	$data = array("class_name"=>$class_name,
				  "programme_id"=>$programme_id);
	$success = $setup->update_class($data,$class_id);
	if ($success) {
		echo $response = 2;
	}else{
		echo $response = 3;
	}
}

if (isset($_GET['c%%'])) {
	$class_id = $_GET['c%%'];
	$success = $setup->delete_class($class_id);
}
$registered_classes = $setup->get_classes();

// End Class inc

// Start semester inc
if (isset($_GET['s::'])) {
	$sem_id = $_GET['s::'];
	$edit_sem = $setup->get_semester($sem_id);

}
if (isset($_POST['update_sem'])) {
	$sem_name = $_POST['sem_name'];
	$sem_id = $_POST['sem_id'];
	$data = array("sem_name"=>$sem_name);
	$success = $setup->update_semester($data,$sem_id);
	if ($success) {
		echo $response = 2;
	}else{
		echo $response = 3;
	}
}

if (isset($_GET['s%%'])) {
	$sem_id = $_GET['s%%'];
	$success = $setup->delete_semester($sem_id);
}
$registered_sems = $setup->get_semesters();
//End semester in

// Start of Academic Year inc

if (isset($_GET['ayr::'])) {
	$a_year_id = $_GET['ayr::'];
	$edit_a_year = $setup->get_a_year($a_year_id);

}
if (isset($_POST['update_a_year'])) {
	$a_year_name = $_POST['a_year'];
	$a_year_id = $_POST['a_year_id'];
	$data = array("a_year"=>$a_year_name);
	$success = $setup->update_a_year($data,$a_year_id);
	if ($success) {
		echo $response = 2;
	}else{
		echo $response = 3;
	}
}

if (isset($_GET['ayr%%'])) {
	$a_year_id = $_GET['ayr%%'];
	$success = $setup->delete_a_year($a_year_id);
}
$registered_a_years = $setup->get_a_years();
// End of Academic Year inc

// Start of Track Inc

if (isset($_GET['t::'])) {
	$track_id = $_GET['t::'];
	$edit_track = $setup->get_track($track_id);

}
if (isset($_POST['update_track'])) {
	$track_name = $_POST['track_name'];
	$track_id = $_POST['track_id'];
	$data = array("track_name"=>$track_name);
	$success = $setup->update_track($data,$track_id);
	if ($success) {
		echo $response = 2;
	}else{
		echo $response = 3;
	}
}

if (isset($_GET['t%%'])) {
	$track_id = $_GET['t%%'];
	$success = $setup->delete_track($track_id);
}
$registered_tracks = $setup->get_tracks();

// End Track inc

// Start subject inc
if (isset($_GET['subj::'])) {
	$subject_id = $_GET['subj::'];
	$edit_subject = $setup->get_subject($subject_id);

}
if (isset($_POST['update_subject'])) {
	$subject_name = $_POST['subject_name'];
	$subject_id = $_POST['subject_id'];
	$core_elective = $_POST['core_elective_id'];
	$data = array("subject_name"=>$subject_name,
				  "core_elective_id"=>$core_elective);
	$success = $setup->update_subject($data,$subject_id);
	if ($success) {
		echo $response = 2;
	}else{
		echo $response = 3;
	}
}

if (isset($_GET['subj%%'])) {
	$subject_id = $_GET['subj%%'];
	$success = $setup->delete_subject($subject_id);
}
$registered_subjects = $setup->get_subjects();
$core_elective = $setup->get_core_elective();
// End subject inc

// Start house inc
if (isset($_GET['h::'])) {
	$house_id = $_GET['h::'];
	$edit_house = $setup->get_house($house_id);

}
if (isset($_POST['update_house'])) {
	$house_name = $_POST['house_name'];
	$house_id = $_POST['house_id'];
	$data = array("house_name"=>$house_name);
	$success = $setup->update_house($data,$house_id);
	if ($success) {
		echo $response = 2;
	}else{
		echo $response = 3;
	}
}

if (isset($_GET['h%%'])) {
	$house_id = $_GET['h%%'];
	$success = $setup->delete_house($house_id);
}
$edit_programme = '';
$programme_id  = '';
if (isset($_GET['p::'])) {
	$programme_id = $_GET['p::'];
	$edit_programme = $setup->get_programme($programme_id);

}
if (isset($_POST['update_programme'])) {
	$programme_name = $_POST['programme_name'];
	$programme_id = $_POST['programme_id'];
	$data = array("programme_name"=>$programme_name);
	$success = $setup->update_programme($data,$programme_id);
	if ($success) {
		echo $response = 2;
	}else{
		echo $response = 3;
	}
}

if (isset($_GET['p%%'])) {
	$programme_id = $_GET['p%%'];
	$success = $setup->delete_programme($programme_id);
}
$registered_houses = $setup->get_houses();
$programmes = $setup->get_programmes();
//End semester in

// Fees

if (isset($_POST['update_fee_type'])) {
	$fee_type_name = $_POST['fee_type_name'];
	$fee_type_id = $_POST['fee_type_id'];
	$data = array("fee_type_name"=>$fee_type_name);
	$success = $setup->update_fee_type($data,$fee_type_id);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}

if (isset($_GET['ft::'])) {
	$fee_type_id = $_GET['ft::'];
	$edit_fee_type = $setup->get_fee_type($fee_type_id);

}

if (isset($_GET['sf::'])) {
	$set_fee_id = $_GET['sf::'];
	$edit_set_fee = $setup->get_set_fee($set_fee_id);

}

if (isset($_GET['pf::'])) {
	$pay_fee_id = $_GET['pf::'];
	$edit_pay_fee = $setup->get_pay_fees($pay_fee_id);
}

if (isset($_GET['ft%%'])) {
	$fee_type_id = $_GET['ft%%'];
	$success = $setup->delete_fee_type($fee_type_id);
}

if (isset($_GET['sf%%'])) {
	$set_fee_id = $_GET['sf%%'];
	$success = $setup->delete_set_fee($set_fee_id);
}

if (isset($_POST['update_set_fee'])) {
	$set_fee_id = $_POST['set_fee_id'];
	$class_id = $_POST['class_id'];
	$fee_type_id = $_POST['fee_type_id'];
	$amount = $_POST['amount'];
	$data = array(
		"class_id"=>$class_id,
		"fee_type_id"=>$fee_type_id,
		"amount"=>$amount
	);
	$success = $setup->update_set_fee($data,$set_fee_id);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}

$fee_types = $setup->get_fee_types();
$set_fees = $setup->get_set_fees();
// 
$classes = $admission->get_all_classes();
$forms = $admission->get_all_forms();
$students = $admission->get_all_students();
$fees_payments = $setup->get_pay_fees();

