<?php
	require "commonincludefiles.php";
	
	//subject allocation
	
	$sql = "select employee_id from cms_employeemaster where user_id ='".$_SESSION["VedantnrUserId"]."'";
	$sql_res = dbQuery($sql);
	$sql_rec = dbArray($sql_res);
	$faculty_id = $sql_rec[0];
	
	if($faculty_id != "")
	{
		$sql = "select GROUP_CONCAT(branch_id) as branch_id,GROUP_CONCAT(semester_id) as semester_id,
		count(div_id) as div_id,GROUP_CONCAT(batch_id) as batch_id,GROUP_CONCAT(lectype) as lectype			
		from cms_subject_allocation where employee_id = '".$faculty_id."'";
		$sql_res = dbQuery($sql);
		while($row = dbArray($sql_res))
		{
			$branch_id = $row['branch_id'];
			$semester_id = $row['semester_id'];
			$div_id = $row['div_id'];
			$lectype = $row['lectype'];
		}
		
	}
	//over
	
	/* Branch combo */
	$str1 = "";	
	$condition='';
	if($branch_id!=""){
	$condition = " And branch_id in(".$branch_id.")";}
	
	$order_field = " branch_id ";
	$order_type  = " ASC ";
	$objBranch = new BranchMgmt();
	$result = $objBranch->getAllRecords(0,0,$condition,$order_field,$order_type);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str1 .= "['".$record['branch_id']."','".$record['branch_name']."'],";	
		}
	}
	$str1 = substr($str1, 0, strlen($str1)-1);
	
	/* Branch combo */
	$str8 = "";	
	if($str1 != ""){
		$str8 .= "['All',':: All ::'],";	
		$str8 .= $str1;
	}
	
	/* Exam combo */
	$str9 = "";	
	$order_field = " exam_id ";
	$order_type  = " ASC ";
	$objExam = new ExamMgmt();
	$condition='';
	$result = $objExam->getAllRecords(0,0,$condition,$order_field,$order_type);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str9 .= "['".$record['exam_id']."','".$record['exam_name']."'],";	
		}
	}
	$str9 = substr($str9, 0, strlen($str9)-1);
	
	
	
	
	
	/* Semester combo */
	$str2 = "";	
	$order_field = " semester_id ";
	$order_type  = " ASC ";
	$objSemester = new SemesterMgmt();
	
	
	
	/*get all semester */
	
	$str22 = "";
	
	$result = $objSemester->getAllRecords(0,0,'','','');
		if(dbRows($result) > 0)
		{	
			while($record = dbArray($result))
			{
				$str22 .= "['".$record['branch_id']."','".$record['semester_id']."','".$record['semester_name']."'],";	
			}
		}
		$str22 = substr($str22, 0, strlen($str22)-1);
	
	
	
	
	
	/* for only odd sem seen in odd year */
	
	if(($_SESSION['aYearId'] % 2)==0)
	{
		$condition=" and (semester_id % 2)=0";
	}
	else
	{
		$condition=" and (semester_id % 2) != 0";
	}
	
	if($semester_id!="")
	{
		$condition = " And semester_id in(".$semester_id.")";}
		/* end */
		$result = $objSemester->getAllRecords(0,0,$condition,$order_field,$order_type);
		if(dbRows($result) > 0)
		{	
			while($record = dbArray($result))
			{
				$str2 .= "['".$record['branch_id']."','".$record['semester_id']."','".$record['semester_name']."'],";	
			}
		}
		$str2 = substr($str2, 0, strlen($str2)-1);
	
	
			if(($_SESSION['aYearId'] % 2)==0)
			{
				$condition=" and (semester_id % 2) != 0";
			
			}
			else
			{
				$condition=" and (semester_id % 2)=0";
			}
			
			/* end */
			$str12 = "";	
			$result = $objSemester->getAllRecords(0,0,$condition,$order_field,$order_type);
			if(dbRows($result) > 0)
			{	
				while($record = dbArray($result))
				{
					$str12 .= "['".$record['branch_id']."','".$record['semester_id']."','".$record['semester_name']."'],";	
				}
			}
			$str12 = substr($str12, 0, strlen($str12)-1);
	
			$str21 = "";
			$year_odd_even ='';	
			$result = $objSemester->getAllRecords(0,0,'','','');
			if(dbRows($result) > 0)
			{	
				while($record = dbArray($result))
				{
					if($record['semester_id'] %2 == 0)
					{
						$year_odd_even = 'even';	
					}
					else
					{
						$year_odd_even = 'odd';
					}
					$str21 .= "['".$record['branch_id']."','".$record['semester_id']."','".$record['semester_name']."','".$year_odd_even."'],";	
				}
			}
			
			$str21 = substr($str21, 0, strlen($str21)-1);
	
	/* Head combo */
	$str3 = "";	
	$condition = " AND head_active = 1 ";
	$order_field = " head_id ";
	$order_type  = " ASC ";
	$objHead = new FeesheadMgmt();
	$result = $objHead->getAllRecords(0,0,$condition,$order_field,$order_type);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str3 .= "['".$record['head_id']."','".$record['head_name']."'],";	
		}
	}
	$str3 = substr($str3, 0, strlen($str3)-1);
	
	/* Head combo with all option */
	$str7 = "['All','All'],";
	$condition = " AND head_active = 1 AND head_name != 'ACPDC Adm Fee' ";
	$order_field = " head_id ";
	$order_type  = " ASC ";
	$result = $objHead->getAllRecords(0,0,$condition,$order_field,$order_type);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str7 .= "['".$record['head_id']."','".$record['head_name']."'],";	
		}
	}
	$str7 = substr($str7, 0, strlen($str7)-1);
	
	/* Bankname combo */
	$str4 = "";	
	$sql = "SELECT DISTINCT bank_name FROM cms_feesreceivemaster WHERE bank_name != '' ORDER BY bank_name ASC";
	$result = dbQuery($sql);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str4 .= "['".$record['bank_name']."'],";	
		}
	}
	$str4 = substr($str4, 0, strlen($str4)-1);
	
	/* Group combo */
	$str5 = "['All'],";
	$sql = "SELECT DISTINCT group_name FROM cms_contact WHERE group_name != '' ORDER BY group_name ASC";
	$result = dbQuery($sql);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str5 .= "['".$record['group_name']."'],";	
		}
	}
	$str5 = substr($str5, 0, strlen($str5)-1);
	
	/* Message combo */
	$str6 = "";
	$sql = "SELECT message_title,message_content FROM cms_message";
	$result = dbQuery($sql);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str6 .= "['".$record['message_title']."','".$record['message_content']."'],";	
		}
	}
	$str6 = substr($str6, 0, strlen($str6)-1);
	/* lec combo */
	$str10 = "";	
	$order_field = " lec_id ";
	$order_type  = " ASC ";
	$objLec = new LecMgmt();
	$condition='';
	$result = $objLec->getAllRecords(0,0,$condition,$order_field,$order_type);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str10 .= "['".$record['lec_id']."','".$record['lec_name']."'],";	
		}
	}
	$str10 = substr($str10, 0, strlen($str10)-1);
	
	$str11="";
	
	//division new
	if($faculty_id!="")
	{
		
		$qry ="select distinct(div_id) as div_id,sa.* from cms_subject_allocation as sa where branch_id in($branch_id) and semester_id in($semester_id)";
		$result = dbQuery($qry);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str11 .= "['".$record['branch_id'].$record['semester_id']."','".$record['div_id']."'],";
		}
	}
	}
	else{$qry = "SELECT *
				FROM cms_branchsemester 
				WHERE college_id   = '".$_SESSION["VedantnrCollegeId"]."' ";
			
	
	$result = dbQuery($qry);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$div = $record['noofdiv'];
			
			for($i=0; $i<$div; $i++){
				$key = chr(65+$i);
				$str11 .= "['".$record['branch_id'].$record['semester_id']."','".$key."'],";
				}
			//echo 'div_id='.$div_id;
			/*if($div_id!=""){
				for($i=0; $i<$div_id; $i++){
				$key = chr(65+$i);
				$str11 .= "['".$record['branch_id'].$record['semester_id']."','".$key."'],";
				}
			}else{
				for($i=0; $i<$div; $i++){
				$key = chr(65+$i);
				$str11 .= "['".$record['branch_id'].$record['semester_id']."','".$key."'],";
				}
			}*/
		}
	}
	
	}
	//echo $str11;
	
	$str13 = "";	
	$order_field = " gtuhead_id ";
	$order_type  = " ASC ";
	$objcms_gtufeesheadMgmt = new cms_gtufeesheadMgmt();
	$condition='';
	$result = $objcms_gtufeesheadMgmt->getAllRecords(0,0,$condition,$order_field,$order_type);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str13 .= "['".$record['gtuhead_id']."','".$record['gtuhead_name']."','".$record['gtuhead_amount']."','".$record['max_amount']."','".$record['gtufee_type']."'],";	
		}
	}
	$str13 = substr($str13, 0, strlen($str13)-1);
	
	
	$str14 = "";
	$sql = "SELECT distinct gtufee_type FROM cms_gtufeeshead";
	$result = dbQuery($sql);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str14 .= "['".$record['gtufee_type']."'],";	
		}
	}
	$str14 = substr($str14, 0, strlen($str14)-1);
	
	
	
	$str15 = "";
	$sql = "SELECT distinct gtuhead_name FROM cms_gtufeeshead";
	$result = dbQuery($sql);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str15 .= "['".$record['gtuhead_name']."'],";	
		}
	}
	$str15 = substr($str15, 0, strlen($str15)-1);
	
	$str16 = "";
	$sql = "SELECT distinct employee_id,employee_name FROM sms_employeemaster where employee_designation = 23 "; // 23 for faculty only
	$result = dbQuery($sql);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
				$str16 .= "['".$record['employee_id']."','".$record['employee_name']."'],";	
		}
	}
	$str16 = substr($str16, 0, strlen($str16)-1);
	
	$str17 = "";	
	$sql = "SELECT * from cms_semestermaster";
	$result = dbQuery($sql);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str17 .= "['".$record['branch_id']."','".$record['semester_id']."','".$record['semester_name']."'],";	
		}
	}
	$str17 = substr($str17, 0, strlen($str17)-1);
	
	//year
	$str18 = "";
	
$qry = "SELECT DISTINCT YEAR(`student_admdate`) as AYEAR FROM `cms_studentmaster` WHERE YEAR(`student_admdate`) != 0;";
	$result = dbQuery($qry);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str18 .= "['".$record['AYEAR']."'],";	
		}
	}
	$str18 = substr($str18, 0, strlen($str18)-1);
	
	//employee
	$str18 = "";
	
$qry = "SELECT * FROM `cms_employeemaster` WHERE `employee_designation` in(4,5,6,7)";
	$result = dbQuery($qry);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str19 .= "['".$record['employee_id']."','".$record['employee_name']."','".$record['branch_name']."'],";	
		}
	}
	//echo $str19;
	
	$str19 = substr($str19, 0, strlen($str19)-1);
	
	$str20="";
	$qry = "SELECT * FROM cms_lectype";
	if($lectype !=""){
		$qry.=" where lectype_id in (".$lectype.")";
	}
	$result = dbQuery($qry);
	if(dbRows($result) > 0){	
		while($record = dbArray($result)){
			$str20 .= "['".$record['lectype_id']."','".$record['lectype_name']."'],";	
		}
	}
	
	$str20 = substr($str20, 0, strlen($str20)-1);
?>
<script type="text/javascript" language="javascript">
	Ext.namespace('Ext.semester');
	Ext.namespace('Ext.contact');
	Ext.semester.branch = [<?php echo $str1; ?>];
	
	Ext.semester.head = [<?php echo $str3; ?>];
	Ext.semester.bankname = [<?php echo $str4; ?>];
	Ext.contact.group_name = [<?php echo $str5; ?>];
	Ext.contact.message = [<?php echo $str6; ?>];
	Ext.semester.headall = [<?php echo $str7; ?>];
	Ext.semester.exam = [<?php echo $str9; ?>];
	Ext.semester.branchall = [<?php echo $str8; ?>];
	Ext.semester.lec = [<?php echo $str10; ?>];
	Ext.semester.division = [<?php echo $str11; ?>];
	
	
	Ext.semester.semester = [<?php echo $str2; ?>];
	Ext.semester.semesterright = [<?php echo $str12; ?>];
	Ext.semester.semesterbyyear = [<?php echo $str21; ?>];
	Ext.semester.semesterall = [<?php echo $str22; ?>];
	
	
	Ext.semester.gtufeeshead = [<?php echo $str13; ?>];
	Ext.semester.gtufeestype = [<?php echo $str14; ?>];
	Ext.semester.gtuheadname = [<?php echo $str15; ?>];
	Ext.semester.faculty = [<?php echo $str16; ?>];
	Ext.semester.semesterAll = [<?php echo $str17; ?>];
	
	Ext.semester.admyear = [<?php echo $str18; ?>];
	Ext.semester.employee = [<?php echo $str19; ?>];
	Ext.semester.lectype = [<?php echo $str20; ?>];
	
</script>
