<?php
require "commonincludefiles.php";

if ($_SESSION["VedantnrCollegeId"] != "" && isset($_SESSION["VedantnrCollegeId"])) {
	$objFeeshead = new FeesheadMgmt();
	$objStudentDetailMgmt =new StudentDetailMgmt();
	$objFeeshead->head_id = $_POST['head_id'];
	$objFeeshead->fees_type = $_POST['fees_type'];
	$objFeeshead->head_name = $_POST['head_name'];
	if ($objFeeshead->head_id == "0") {
		$objFeeshead->add();

		$head = $objFeeshead->head_name;
		$headName = $head . "_fee";
		$headNameMafi = $head . "_mafifee";


	
		$objStudentDetailMgmt->updateStudentFeesHeads($headName,$headNameMafi);
	/*	$query = "ALTER TABLE cms_studentdetail
				ADD COLUMN IF NOT EXISTS `$headName` INT(11),
				ADD COLUMN IF NOT EXISTS `$headNameMafi` INT(11)";
		dbQuery($query);*/


	} else {
		if ($_REQUEST['act'] == "del") {
			$objFeeshead->delete();

			$head = $objFeeshead->head_name;
			$headName = $head . "_fee";
			$headNameMafi = $head . "_mafifee";

			
			$objStudentDetailMgmt->updateStudentFeesHeadsDrop($headName,$headNameMafi);
			/*$query = "ALTER TABLE cms_studentdetail
						DROP COLUMN IF EXISTS `$headName`,
						DROP COLUMN IF EXISTS `$headNameMafi`";
			dbQuery($query);*/
		} else {

			$objFeeshead->edit();

			$head = $objFeeshead->head_name;
			$headName = $head . "_fee";
			$headNameMafi = $head . "_mafifee";

			$old_head_name = $_POST['old_head_name'];
			$oldHeadNameFee = $old_head_name . "_fee";
			$oldHeadNameMafi = $old_head_name . "_mafifee";

			$objStudentDetailMgmt->updateStudentFeesHeadschange($oldHeadNameFee,$oldHeadNameMafi,$headName,$headNameMafi);
			
			/*$query = "ALTER TABLE cms_studentdetail 
                          CHANGE `$oldHeadNameFee` `$headName` INT(11),
                          CHANGE `$oldHeadNameMafi` `$headNameMafi` INT(11)";
			dbQuery($query);*/
		}
	}
	echo '{"success":"true"}';
} else {
	echo '{"success":"false","msg":"session expiry"}';
}
?>