<?php
	require "../commonincludefiles.php";
 	$arr = array();
 	$total = 0;
	
	
	//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 != "" && $_SESSION["VedantnrUserRole"] !='Hod'  && $_SESSION["VedantnrUserRole"] !='PowerUser')
	{
		$sql = "select GROUP_CONCAT(subject_id) as subject_id 
		from cms_subject_allocation where employee_id = '".$faculty_id."'";
		$sql_res = dbQuery($sql);
		while($row = dbArray($sql_res))
		{
			$subject_id = $row['subject_id'];

		}
		
	}
	//over
	
	
	if($_REQUEST['branch_name']!="" && $_REQUEST['semester_name']!=""){
		
		$sql = "SELECT * FROM cms_subjectmaster WHERE subject_active = 1 
				and branch_id = '".Escape($_REQUEST['branch_name'])."' 
		        AND semester_id = '".Escape($_REQUEST['semester_name'])."' ";
				
		if($subject_id!=""){
		$sql.=" AND subject_id in (".$subject_id.")";
		}
		
	//	echo $sql;
		$sql = $sql."Order By subject_name ASC";
		$rs = dbQuery($sql);		
				
		$total=dbRows($rs);
		$i = 0;
		$SubjectData = array("count" => $total, "data" => array());
		if(dbRows($rs) > 0){
			while($row = dbArray($rs)){
				$temparray["subject_id"]  	= $row["subject_id"];
				$temparray["subject_name"]	= stripcslashes($row["subject_name"]);
				$SubjectData["data"][$i] 	= $temparray;   
				$i++;
			}
		}
	}
	else if($_REQUEST['task']=="getall")
	  {  
		
		$sql = "SELECT * FROM cms_subjectmaster where  subject_active = 1 ";
		
		if($subject_id!=""){
		$sql.=" and subject_id in ('".$subject_id."') ";
		}
		
		
		$sql = $sql."Order By subject_name ASC";
		
		
		
		$rs = dbQuery($sql);		
				
		$total=dbRows($rs);
		$i = 0;
		$SubjectData = array("count" => $total, "data" => array());
		if(dbRows($rs) > 0){
			while($row = dbArray($rs)){
				$temparray["subject_id"]  	= $row["subject_id"];
				$temparray["subject_name"]	= $row["subject_name"];
				$SubjectData["data"][$i] 	= $temparray;   
				$i++;
			}
		}
	
	  }
	
	echo json_encode($SubjectData);	
?>
