<?php
	require "../commonincludefiles.php";
	
		$objSubjectMgmt= new SubjectMgmt();
	$objStudentMgmt= new StudentMgmt();
	$objexamsetupMgmt =new examsetupMgmt();

	if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"]))
	{	
 		if($_REQUEST['action'] == "branch")
 		{
			$branch_id 	= Escape($_REQUEST['branch_id']);
			$branch_name  = Escape($_REQUEST['branch_name']);
			$college_id = $_SESSION["VedantnrCollegeId"];

			$objBranchMgmt= new BranchMgmt();
			$RES_BRANCH=$objBranchMgmt->getbranch($branch_name,$branch_id);
			//$SQL_BRANCH = "SELECT * FROM cms_branchmaster WHERE branch_name = '$branch_name' AND branch_id != $branch_id";
			//$RES_BRANCH = dbQuery($SQL_BRANCH);
			$NOREC_BRANCH = dbRows($RES_BRANCH);
				
	 		if($NOREC_BRANCH > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "subject")
 		{
			$branch_id 	= Escape($_REQUEST['branch_id']);
			$year_id  = Escape($_REQUEST['year_id']);
			$branchyear_id  = Escape($_REQUEST['branchyear_id']);
			$semester_id  = Escape($_REQUEST['semester_id']);
			$subject_id   = Escape($_REQUEST['subject_id']);
			$subject_name = Escape($_REQUEST['subject_name']);
			$subject_code = Escape($_REQUEST['subject_code']);
			
			$condition ="";

			if($branch_id !=""){
				$condition .="and branch_id = '$branch_id' ";					
			}
			if($year_id !=""){
				$condition .=" and year_id = '$year_id' ";
			}
			if($branchyear_id !=""){
				$condition .=" and branchyear_id = '$branchyear_id' ";
			}
			if($semester_id !=""){
				$condition .=" and semester_id = '$semester_id'  ";
			}
			$condition .="and subject_name = '$subject_name' AND 
								subject_id != $subject_id AND
								subject_code != $subject_code";
			
			$RES_SUBJECT=$objSubjectMgmt->getsubject($condition);
			/*$SQL_SUBJECT = "SELECT * FROM cms_subjectmaster WHERE 
								subject_name = '$subject_name' AND 
								subject_id != $subject_id AND
								subject_code != $subject_code";
			$RES_SUBJECT = dbQuery($SQL_SUBJECT);*/
			$NOREC_SUBJECT = dbRows($RES_SUBJECT);
				
	 		if($NOREC_SUBJECT > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "exam")
 		{
			$exam_id 	= Escape($_REQUEST['exam_id']);
			$exam_name  = Escape($_REQUEST['exam_name']);
			
			$objExamMgmt= new ExamMgmt();
			$RES_EXAM=$objExamMgmt->getexam($exam_name,$exam_id);
			//$SQL_EXAM = "SELECT * FROM cms_exammaster WHERE exam_name = '$exam_name' AND exam_id != $exam_id";
			//$RES_EXAM = dbQuery($SQL_EXAM);
			$NOREC_EXAM = dbRows($RES_EXAM);
				
	 		if($NOREC_SUBJECT > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "semester")
 		{
			$semester_id 	= Escape($_REQUEST['semester_id']);
			$semester_name  = Escape($_REQUEST['semester_name']);
			$branch_id  = Escape($_REQUEST['branch_id']);
			

			$objSemesterMgmt= new SemesterMgmt();
			$RES_SEMESTER=$objSemesterMgmt->getsemester($semester_name,$semester_id,$branch_id);
			//$SQL_SEMESTER = "SELECT * FROM cms_semestermaster WHERE semester_name = '$semester_name' AND semester_id != $semester_id AND branch_id = '$branch_id'";
			//$RES_SEMESTER = dbQuery($SQL_SEMESTER);
			$NOREC_SEMESTER = dbRows($RES_SEMESTER);
				
	 		if($NOREC_SEMESTER > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
			else if($_REQUEST['action'] == "timetable")
 		{
			$employee_id 	= Escape($_REQUEST['employee_id']);
			$day_name  = Escape($_REQUEST['day_name']);
			$time_id  = Escape($_REQUEST['time_id']);
			$condition ="";
			$condition .="WHERE day_name = '$day_name' AND employee_id = $employee_id
			and time_id='$time_id'";
			
			$RES_SEMESTER=$objSubjectMgmt->getworksubject($condition);
			//$SQL_TIME = "SELECT * FROM work_allotment_subject WHERE day_name = '$day_name' AND employee_id = $employee_idand time_id='$time_id'";
			//$RES_SEMESTER = dbQuery($SQL_TIME);
			$NOREC_SEMESTER = dbRows($RES_SEMESTER);
				
	 		if($NOREC_SEMESTER > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}		

			else if($_REQUEST['action'] == "timetable1")
 		{
			$time_id 	= Escape($_REQUEST['time_id']);
			$day_name  = Escape($_REQUEST['day_name']);
			$room_id  = Escape($_REQUEST['room_id']);
			
			
			$condition ="";
			$condition .="WHERE day_name = '$day_name' AND time_id = $time_id
			and room_id='$room_id'";
			$RES_SEMESTER=$objSubjectMgmt->getworksubject($condition);
		
			/*$SQL_TIME = "SELECT * FROM work_allotment_subject WHERE day_name = '$day_name' AND time_id = $time_id
			and room_id='$room_id'
			";
			$RES_SEMESTER = dbQuery($SQL_TIME);*/
			$NOREC_SEMESTER = dbRows($RES_SEMESTER);
				
	 		if($NOREC_SEMESTER > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}


		else if($_REQUEST['action'] == "gtuno")
 		{
			$student_id 		= Escape($_REQUEST['student_id']);
			$student_gturegno  = Escape($_REQUEST['student_gturegno']);
			
			$RES_GTU=$objstudentMgmt->getgturegno($student_gturegno,$student_id);
			//$SQL_GTU = "SELECT * FROM cms_studentmaster WHERE student_gturegno = '$student_gturegno' AND student_id != '$student_id' ";
			//$RES_GTU = dbQuery($SQL_GTU);
			$NOREC_GTU = dbRows($RES_GTU);
				
	 		if($NOREC_GTU > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "student_examseatno")
 		{
			$student_id 		= Escape($_REQUEST['student_id']);
			$student_examseatno  = Escape($_REQUEST['student_examseatno']);
			$RES_GTU=$objstudentMgmt->getexamseatno($student_examseatno,$student_id);
			//$SQL_GTU = "SELECT * FROM cms_studentmaster WHERE student_examseatno = '$student_examseatno' AND student_id != '$student_id' ";
			//$RES_GTU = dbQuery($SQL_GTU);
			$NOREC_GTU = dbRows($RES_GTU);
				
	 		if($NOREC_GTU > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "head")
 		{
			$head_id 	= Escape($_REQUEST['head_id']);
			$head_name  = Escape($_REQUEST['head_name']);
			
			$objFeesheadMgmt =new FeesheadMgmt();
			$RES_HEAD=$objFeesheadMgmt->getfeeshead($head_name,$head_id);
		
			//$SQL_HEAD = "SELECT * FROM cms_feeshead WHERE head_name = '$head_name' AND head_id != '$head_id' and college_id = '$college_id' ";
			//$RES_HEAD = dbQuery($SQL_HEAD);
			$NOREC_HEAD = dbRows($RES_HEAD);
				
	 		if($NOREC_HEAD > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "setup")
 		{
			$semester_name 	= Escape($_REQUEST['semester_name']);
			$head_name 		= Escape($_REQUEST['head_name']);
			$setup_id 		 = Escape($_REQUEST['setup_id']);
			$objFeessetupMgmt =new FeessetupMgmt();
			$RES_SETUP=$objFeessetupMgmt->getfeessetup($head_name,$semester_name,$setup_id);
			/*$SQL_SETUP = "SELECT * FROM cms_feessetup WHERE semester_id = '$semester_name' AND 
			              head_id = '$head_name' AND year_id = ".$_SESSION["VedantnrYearId"]." AND setup_id != '$setup_id' ";
			$RES_SETUP = dbQuery($SQL_SETUP);*/
			$NOREC_SETUP = dbRows($RES_SETUP);
				
	 		if($NOREC_SETUP > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		
		else if($_REQUEST['action'] == "semester_setup")
 		{
			$semester_name 	 = Escape($_REQUEST['semester_name']);
			$term_month 		= Escape($_REQUEST['term_month']);
			$semester_setup_id = Escape($_REQUEST['semester_setup_id']);
			
			$objcms_semester_setupMgmt =new cms_semester_setupMgmt();
			$RES_SETUP=$objcms_semester_setupMgmt->getsemestersetup($term_month,$semester_name,$semester_setup_id);
			/*$SQL_SETUP = "SELECT * FROM cms_semester_setup WHERE semester_id = '$semester_name' AND 
					 term_month = '$term_month' AND year_id = ".$_SESSION["VedantnrYearId"]." AND semester_setup_id != '$semester_setup_id' ";
			$RES_SETUP = dbQuery($SQL_SETUP);*/
			$NOREC_SETUP = dbRows($RES_SETUP);
				
	 		if($NOREC_SETUP > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		
		else if($_REQUEST['action'] == "examsetup")
 		{
			$branch_id	  = Escape($_REQUEST['branch_name']);
			$semester_id 	= Escape($_REQUEST['semester_name']);
			$exam_id 		= Escape($_REQUEST['exam_name']);
			$subject_id 	 = Escape($_REQUEST['subject_name']);
			$setup_id 	   = Escape($_REQUEST['setup_id']);
			$condition ="";
			$condition ."and branch_id = '$branch_id' AND 
							semester_id = '$semester_id' AND 
							exam_id = '$exam_id' AND 
							subject_id = '$subject_id' AND 
							setup_id != '$setup_id'";
			
			$RES_SETUP=$objexamsetupMgmt->getexamsetup($condition);
			/*$SQL_SETUP = "SELECT * FROM cms_examsetup WHERE 
							branch_id = '$branch_id' AND 
							semester_id = '$semester_id' AND 
							exam_id = '$exam_id' AND 
							subject_id = '$subject_id' AND 
							setup_id != '$setup_id' AND
							year_id = ".$_SESSION["VedantnrYearId"];
			$RES_SETUP = dbQuery($SQL_SETUP);*/
			$NOREC_SETUP = dbRows($RES_SETUP);
				
	 		if($NOREC_SETUP > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "result")
 		{
			$branch_id   = Escape($_REQUEST['branch_name']);
			$semester_id = Escape($_REQUEST['semester_name']);
			$exam_id 	 = Escape($_REQUEST['exam_name']);
			$subject_id  = Escape($_REQUEST['subject_name']);

			$condition ="";
			$condition ."and branch_id = '$branch_id' AND 
							semester_id = '$semester_id' AND 
							exam_id = '$exam_id' AND 
							subject_id = '$subject_id'";
			$RES_SETUP=$objexamsetupMgmt->getexamsetup($condition);
			/*$SQL_RESULT = "SELECT * FROM cms_examsetup WHERE 
							branch_id = '$branch_id' AND 
							semester_id = '$semester_id' AND 
							exam_id = '$exam_id' AND 
							subject_id = '$subject_id' AND 
							year_id = ".$_SESSION["VedantnrYearId"];
			$RES_RESULT = dbQuery($SQL_RESULT);*/
			$NOREC_RESULT = dbRows($RES_RESULT);
				
	 		if($NOREC_RESULT > 0)
				echo "{success:'false'}"; 
			else
				echo "{success:'true'}";
		}
		else if($_REQUEST['action'] == "atkt")
 		{
			$branch_id   = Escape($_REQUEST['branch_name']);
			$semester_id = Escape($_REQUEST['semester_name']);

			$RES_RESULT=$objStudent->getstudentbranchsemester($branch_id,$semester_id);
			/*$SQL_RESULT = "
				SELECT * FROM cms_studentmaster sm,cms_studentdetail sd WHERE
					sm.student_id = sd.student_id AND 
					sd.cur_branchid = '$branch_id' AND
					sd.cur_semesterid = '$semester_id' AND 
					sm.student_active = 1 AND
					sd.year_id = ".$_SESSION["VedantnrYearId"];
			$RES_RESULT = dbQuery($SQL_RESULT);*/
			$NOREC_RESULT = dbRows($RES_RESULT);
	 		if($NOREC_RESULT > 0)
				echo "{success:'true'}"; 
			else
				echo "{success:'false'}";
		}
	 	else
	 	{
	     	echo "{success:'false'}";
	 	}
	}
?>