<?php 
require '../dao/Setup.php';
require '../dao/Global.php';
$success = false;
$response = 0;
$msg = "";
$err = "";
// Start of Class Code
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;
	}
}


$registered_classes = $setup->get_classes();

// End of Class Code

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;
	}
}
$registered_sems = $setup->get_semesters();

// End of Sem Code

// Start of academic code

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;
	}
}
$registered_a_years = $setup->get_a_years();

// End of Academic Code

//Start of Track Code

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;
	}
}

$registered_tracks = $setup->get_tracks();

//End Track Code

// Start Subject Code

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;
	}
}
$registered_subjects = $setup->get_subjects();
//

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;
	}
}
$registered_houses = $setup->get_houses();

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;
	}
}

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

if (isset($_POST['set_fee'])) {
	$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->set_class_fee($data);
	if ($success) {
		echo $response = 0;
	}else{
		echo $response = 1;
	}
}


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


if (isset($_GET['load_class'])) {
	?>

							<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">Class ID</th>
									<th data-class="expand">Class</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($registered_classes) {
									$i = 0;
									foreach ($registered_classes as $key) {
										$i++;
									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['class_id'] ?></td>
									<td><?php echo $key['class_name'] ?></td>
									<td><a href="index.php#ajax/class_setup.php?c::=<?php echo $key['class_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/class_setup.php?c%%=<?php echo $key['class_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
								</tr>
									<?php
									}
								}
								 ?>
								
							</tbody>
							<?php
}
if (isset($_GET['load_semester'])) {
	?>

							<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">sem ID</th>
									<th data-class="expand">sem</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($registered_sems) {
									$i = 0;
									foreach ($registered_sems as $key) {
										$i++;
									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['sem_id'] ?></td>
									<td><?php echo $key['sem_name'] ?></td>
									<td><a href="index.php#ajax/semester_setup.php?s::=<?php echo $key['sem_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/semester_setup.php?s%%=<?php echo $key['sem_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
								</tr>
									<?php
									}
								}
								 ?>
								
							</tbody>
							<?php
}
if (isset($_GET['load_a_yr'])) {
	?>

							<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">Academic Year ID</th>
									<th data-class="expand">Academic Year</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($registered_a_years) {
									$i = 0;
									foreach ($registered_a_years as $key) {
										$i++;
									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['a_year_id'] ?></td>
									<td><?php echo $key['a_year'] ?></td>
									<td><a href="index.php#ajax/a_year_setup.php?ayr::=<?php echo $key['sem_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/a_year_setup.php?ayr%%=<?php echo $key['sem_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
								</tr>
									<?php
									}
								}
								 ?>
								
							</tbody>
							<?php
}
if (isset($_GET['load_track'])) {
	?>

							<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">Track ID</th>
									<th data-class="expand">Track</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($registered_tracks) {
									$i = 0;
									foreach ($registered_tracks as $key) {
										$i++;
									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['track_id'] ?></td>
									<td><?php echo $key['track_name'] ?></td>
									<td><a href="index.php#ajax/track_setup.php?t::=<?php echo $key['track_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/track_setup.php?t%%=<?php echo $key['track_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
								</tr>
									<?php
									}
								}
								 ?>
								
							</tbody>
							<?php
}

if (isset($_GET['load_sub'])) {
	?>

							<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">Subject ID</th>
									<th data-class="expand">Subject</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($registered_subjects) {
									$i = 0;
									foreach ($registered_subjects as $key) {
										$i++;
									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['subject_id'] ?></td>
									<td><?php echo $key['subject_name'] ?></td>
									<td><a href="index.php#ajax/subject_setup.php?subj::=<?php echo $key['subject_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/subject_setup.php?subj%%=<?php echo $key['subject_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
								</tr>
									<?php
									}
								}
								 ?>
								
							</tbody>
							<?php
}
if (isset($_GET['load_house'])) {
	?>
<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">House ID</th>
									<th data-class="expand">House</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($registered_houses) {
									$i = 0;
									foreach ($registered_houses as $key) {
										$i++;
									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['house_id'] ?></td>
									<td><?php echo $key['house_name'] ?></td>
									<td><a href="index.php#ajax/house_setup.php?h::=<?php echo $key['house_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/class_setup.php?h%%=<?php echo $key['house_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
								</tr>
									<?php
									}
								}
								 ?>
								
							</tbody>
							
		<?php
}
if (isset($_GET['load_prog'])) {
	$programmes = $setup->get_programmes();
	?>
<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">Programme ID</th>
									<th data-class="expand">Programme</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($programmes) {
									$i = 0;
									foreach ($programmes as $key) {
										$i++;
									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['programme_id'] ?></td>
									<td><?php echo $key['programme_name'] ?></td>
									<td><a href="index.php#ajax/prog_setup.php?p::=<?php echo $key['programme_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/prog_setup.php?p%%=<?php echo $key['programme_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
								</tr>
									<?php
									}
								}
								 ?>
								
							</tbody>
							
		<?php
}

if (isset($_GET['load_fee_type'])) {
	$fee_types = $setup->get_fee_types();
	$i = 0;
	foreach ($fee_types as $key) {
		$i++;
	?>
	<tr>
		<td><?php echo $i; ?></td>
		<td><?php echo $key['fee_type_id'] ?></td>
		<td><?php echo $key['fee_type_name'] ?></td>
		<td><a href="index.php#ajax/add_fees_type.php?ft::=<?php echo $key['fee_type_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/add_fees_type.php?t%%=<?php echo $key['fee_type_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
	</tr>
							
	<?php
	}
}

if (isset($_GET['load_set_fee'])) {
	$set_fees = $setup->get_set_fees();
	$i = 0;
	foreach ($set_fees as $key) {
		$i++;
	?>
	<tr>
		<td><?php echo $i; ?></td>
		<td><?php echo $key['set_fee_id'] ?></td>
		<td><?php echo $key['class_name'] ?></td>
		<td><?php echo $key['fee_type_name'] ?></td>
		<td><?php echo $key['amount'] ?></td>
		<td><a href="index.php#ajax/set_class_fee.php?sf::=<?php echo $key['set_fee_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/set_class_fee.php?sf%%=<?php echo $key['set_fee_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
	</tr>
							
	<?php
	}
}


if (isset($_GET['load_fee_payment'])) {
	$fees_payments = $setup->get_pay_fees();
	$i = 0;
	if ($fees_payments) {
		$i = 0;
		foreach ($fees_payments as $key) {
			$i++;
		?>
		<tr>
		<td><?php echo $i; ?></td>
		<td><?php echo $key['pay_fee_id'] ?></td>
		<td><?php echo $key['student_name'] ?></td>
		<td><?php echo $key['class_name'].' '.$key['fee_type_name'].' | '.$key['date_created']; ?></td>
		<td><?php echo $key['amount'] ?></td>
		<td><?php echo $key['amount_paid'] ?></td>
		<td><a href="index.php#ajax/pay_fee.php?pf::=<?php echo $key['set_fee_id'] ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a> <a href="index.php#ajax/pay_fee.php?pf%%=<?php echo $key['set_fee_id'] ?>" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td>
	</tr>
							
	<?php
	}
}
}

$globals = array();
if(isset($_GET['get_global'])){
	$globals = $global->get_all_globals();
	echo json_encode($globals);
}
