0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 13.59.250.115


Current Path : /var/www/oasis/Report_details/
Upload File :
Current File : /var/www/oasis/Report_details/room_allotment_datewise_stph.php

<?php
/*error_reporting(E_ALL);
ini_set('display_errors','on');*/
class room_allotment 
{
	function __construct($aobj_context)
	{
		session_start();
		$this->aobj_context=$aobj_context;
		$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
		$this->user_id = $_SESSION['user_id'];
		$this->funivcode = $_SESSION['FUNIVCODE'];			
		$this->collcode = $_SESSION['collcode'];	
		$this->log_name = $_SESSION['usr'];	
	}
 
	function DisplayRoomAllotmentDetatilsDatewiseStph()
	{
		session_start();
		$this->collcode=$_SESSION['collcode'];
		$frm_date = ($this->aobj_context->mobj_data["frm_date"]);
		$session = ($this->aobj_context->mobj_data["session"]);
		$ra_from = ($this->aobj_context->mobj_data["ra_from"]);
		$ra_to = ($this->aobj_context->mobj_data["ra_to"]);
		$alternative = ($this->aobj_context->mobj_data["alternative"]);
		$deggrp = ($this->aobj_context->mobj_data["deggrp"]);
		$romm = ($this->aobj_context->mobj_data["romm"]);
		// var_dump($romm);
		// die();

		if($_SESSION['fexamseparate'] == 'T')
		{
			$candsum = "examcandsum"; 
			$canddet = "examcanddet"; 

		}else
		{
			$candsum = "candsum"; 
			$canddet = "canddet"; 
		}	

		$roomarray = [];
		$roomalt = explode(",", $romm);
		
		foreach($roomalt as $key => $val){
			if($val == 'All'){
				$data = "ALL";
			}else{
				$roomarr .= "'".$val."',";
			}
		}
		$roomarray = substr_replace($roomarr ,"",-1);
		if($data == 'ALL'){
			$value = 'All';
		}else{
			$value = $roomarray;
		}
		
		if($value == 'All'){
			$cond="";
		}else{
			$cond="and froomno in ($value)";
		}

		if($session== 'both')
		{
			$sectionvalue = "";
		}
		else 
		{
			if($this->funivcode == '049'){
				$sectionvalue = "and s.fsession like '{$session}'";
			}else{
				$sectionvalue = "and s.fsession like '{$session}%'";
			}
		}
		
		$hall_no = '0';

		/*
		*	Updating Qpcode to canddet so that no need to link subject later
		*	also update hallno to null for pirticular session and college
		*/


		$query1 = "SELECT COUNT(DISTINCT cd.FREGNO) AS reg_cnt
					FROM $canddet cd INNER JOIN subject s ON s.fdegree = cd.fdegree 
					AND s.fexamno = cd.fexamno AND s.FSUBCODE=cd.FSUBCODE
					INNER JOIN $candsum cs ON  cd.fcollcode = cs.fcollcode and cd.FDEGREE=cs.FDEGREE 
					and cs.FREGNO=cd.FREGNO  and cd.fcollcode = cs.fcollcode
					inner join degree dd on cd.fdegree=dd.fdegree and dd.fexamno=cd.fexamno 
					WHERE  s.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
					AND IFNULL(cd.fpassmth,'') = '' AND cd.FPRESENT='P'  {$sectionvalue}
					AND IFNULL(cs.FRECPTDATE,'0000-00-00')<>'0000-00-00'  and cs.fcntrcode = '{$this->collcode}'
					and cs.fdegree in(select distinct fdegree from degree 
					where fdeggrp = '{$deggrp}') 
					GROUP BY s.fdoe";
						// var_dump($query1);die();


			$results1 = $this->aobj_context->mobj_db->GetRow($query1);
			$reg_cnt = $results1['reg_cnt'];
			
			$query1 = "select sum(fcapacity) as fcapacity from masroom where 
			 fcollcode = '{$this->collcode}' $cond";
			$results1 = $this->aobj_context->mobj_db->GetRow($query1);
			$fcapacity = $results1['fcapacity'];
			
			if($reg_cnt > $fcapacity)
			{
				$arr = "Insufficient Rooms for the allotment. Total Capacity : ".$fcapacity." Total Strength :".$reg_cnt;
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
				return;
			}



		$query = "update $canddet cd, subject s set cd.fqpcode1 = s.fqpcode, FHALLNO = NULL,fslno = NULL 
		where cd.fdegree = s.fdegree and cd.fexamno = s.fexamno 
		and ifnull(cd.fpassmth,'') = '' and cd.fpresent = 'P'
		and cd.fregno in (select fregno from $candsum where fcntrcode = '{$this->collcode}')
		and cd.fsubcode = s.fsubcode and s.fsession like '{$session}%'
		and cd.fdegree in(select distinct fdegree from degree where fdeggrp = '{$deggrp}')
		and s.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')";

		$rst1 = $this->aobj_context->mobj_db->Execute($query);	
		$rows_affected = $this->aobj_context->mobj_db->affected_rows();
		
		$query = "update masroom set fbalroomcnt = fcapacity where fcollcode = '{$this->collcode}'
		$cond";
		$rst1 = $this->aobj_context->mobj_db->Execute($query);	
		
		$cnd = "and ifnull(ab.fabstype,'') <> 'QpM'";
		if($this->funivcode == '049' || $this->funivcode == '052' || $this->funivcode == '021' || $this->funivcode == '055')
			$cnd = "";


		$query = "SELECT COUNT(DISTINCT cd.FREGNO) AS reg_cnt,s.FQPCODE,s.FDOE,s.fsubcode
				FROM $canddet cd INNER JOIN subject s ON s.fdegree = cd.fdegree 
				AND s.fexamno = cd.fexamno AND s.FSUBCODE = cd.FSUBCODE and cd.fqpcode1 = s.fqpcode
				INNER JOIN $candsum cs ON cs.FREGNO = cd.FREGNO AND cd.FDEGREE=cs.FDEGREE	
				left join absent  ab on   ab.fregno = cd.fregno
				WHERE s.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
				AND IFNULL(cd.fpassmth,'') = '' AND cd.FPRESENT='P'  {$sectionvalue}
				AND IFNULL(cs.FRECPTDATE,'0000-00-00')<>'0000-00-00'  
				and cs.fcntrcode = '{$this->collcode}' 
				{$cnd}
				 and ifnull(s.fqpcode,'') <> ''
				and cs.fdegree in(select distinct fdegree from degree where fdeggrp = '{$deggrp}')
				GROUP BY s.FQPCODE ORDER BY reg_cnt DESC,s.fsession,s.FQPCODE";
		
		$results = $this->aobj_context->mobj_db->GetAll($query); 
		$k = 1;
		foreach($results as $ak=>$value)
		{	
			$reg_cnt = $value['reg_cnt'];
			$qpcode = $value['FQPCODE'];			

			$query2 ="SELECT * FROM masroom
				WHERE fcollcode = '{$this->collcode}' $cond
				and fcapacity > 0
				order by froomno";	
			$restults = $this->aobj_context->mobj_db->GetAll($query2);

			foreach($restults as $key => $value)
			{
				
				if($value['fbalroomcnt'] <= 0)
					continue;

				if($value['fmaxqpcnt'] == 0)
				{
					$value['fmaxqpcnt'] = 1;
				}	
				
				$capacity     = $value['fcapacity']; 
				$studperqp    = round($value['fcapacity'] / $value['fmaxqpcnt']);
				$balroomcnt   = $value['fcapacity'] - $studperqp;	

				if($reg_cnt < $studperqp)
					$studperqp = $reg_cnt;

				if($value['fbalroomcnt'] <= $studperqp)
					$studperqp = $value['fbalroomcnt'];
				
				if($this->funivcode == '055')
					$regorder = "ifnull(cd.fsorder,'01'),cd.fdegree,cd.fregno";
				else
					$regorder = "cd.fregno";
				
				if($this->funivcode == '049')
				{	
					if($session == 'N1')
						$regorder = "cd.fdegree,cd.fregno";
					else
						$regorder = "cd.fregno";
				}

				$query1 = "SET SESSION group_concat_max_len=10000000";
				$res9 = $this->aobj_context->mobj_db->Execute($query1);

				$query = "select group_concat(distinct concat(\"'\",cd.FREGNO,\"'\") order by $regorder) as fregno 
				from $canddet cd inner join $candsum cs on cd.fregno = cs.fregno 
				inner join subject s ON s.fdegree = cd.fdegree 
				AND s.fexamno = cd.fexamno AND s.FSUBCODE=cd.FSUBCODE
				and s.fqpcode = cd.fqpcode1
				left join absent  ab on   ab.fregno = cd.fregno
				where cd.fqpcode1 = '{$qpcode}' 
				and cd.FPRESENT = 'P' and ifnull(cd.fpassmth,'') = '' 
				and ifnull(cd.FHALLNO,'') = '' 
				{$cnd}
				and cs.fcntrcode = '{$this->collcode}'
				order by {$regorder}
				limit {$studperqp}";						
				
				$rst3 = $this->aobj_context->mobj_db->GetRow($query);

				$regarr = explode(',',$rst3['fregno']);

				$regnoin = array_slice($regarr,0,$studperqp);
				$regnoin = implode(',',$regnoin);	
				
				$query = "update $canddet set FHALLNO = '{$value['froomno']}'
						where fregno in ({$regnoin}) and fqpcode1 = '{$qpcode}' 
						and FPRESENT = 'P' and ifnull(fpassmth,'') = ''";
				$rst1 = $this->aobj_context->mobj_db->Execute($query);
				$rows_affected = $this->aobj_context->mobj_db->affected_rows();

				if($rows_affected)
				{
					$query = "update masroom set fbalroomcnt = ({$value['fbalroomcnt']} - $rows_affected)
					where froomno = '{$value['froomno']}' 
					and fcollcode = '{$this->collcode}'";	
					
					$rst1 = $this->aobj_context->mobj_db->Execute($query);

					$insert = " insert into room_allotment(FCOLLCODE,FQPCODE,FHALLNO,FCAPACITY,FLOGNAME,FLOGDATE,FDOE,FSESSION,FORDER )
						values ('{$this->collcode}','{$qpcode}' ,'{$value['froomno']}','{$rows_affected}','{$this->log_name}',now(),{date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')},'{$session}','{$k}')";
					//$lobj_insert = $this->aobj_context->mobj_db->Execute($insert);
		
					$insert = " insert into room_allotment(FCOLLCODE,FQPCODE,FHALLNO,FCAPACITY,FLOGNAME,FLOGDATE,FDOE,FSESSION,FORDER )
							values ('{$this->collcode}','{$hall_arr[$k]->qpcode}' ,'{$hall_arr[$k]->hallno}','{$hall_arr[$k]->alloted}','{$this->log_name}',now(),'{$hall_arr[$k]->fdoe}','{$hall_arr[$k]->sestion}','{$k}')
							ON DUPLICATE KEY UPDATE 
							FCOLLCODE = '{$this->collcode}',
							FQPCODE = '{$hall_arr[$k]->qpcode}',
							FHALLNO = '{$hall_arr[$k]->hallno}',
							FCAPACITY = '{$hall_arr[$k]->alloted}',
							FLOGNAME = '{$this->log_name}',
							FLOGDATE = now(),
							FDOE = '{$hall_arr[$k]->fdoe}',
							FSESSION = '{$hall_arr[$k]->sestion}',
							FORDER = '{$k}'";
				$lobj_insert = $this->aobj_context->mobj_db->Execute($insert);
			
					
							
				}
				else
				{
					break;
				}

			}
			$k++;
		}
		
		if($alternative == 'T')
		{

		}else
		{

			if($this->funivcode == '033')
			{
				$teacharry = [];
				$query = "select distinct fteachcode from roominvig where fsession = '{$session}' and fdate = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')";
				$res1 = $this->aobj_context->mobj_db->GetAll($query);
			

				foreach($res1 as $val)
				{
					array_push($teacharry,$val['fteachcode']);
				}
				
			}
			

			$query = "SELECT distinct cd.fhallno
				FROM $canddet cd INNER JOIN subject s ON s.fdegree = cd.fdegree 
				AND s.fexamno = cd.fexamno AND s.FSUBCODE = cd.FSUBCODE and cd.fqpcode1 = s.fqpcode
				INNER JOIN $candsum cs ON cs.FREGNO = cd.FREGNO 			
				WHERE s.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
				AND IFNULL(cd.fpassmth,'') = '' AND cd.FPRESENT='P'  {$sectionvalue}
				AND IFNULL(cs.FRECPTDATE,'0000-00-00')<>'0000-00-00'  
				and cs.fcntrcode = '{$this->collcode}' 
				 and ifnull(s.fqpcode,'') <> ''
				 and cd.fdegree in(select distinct fdegree from degree where fdeggrp = '{$deggrp}')
				 order by cd.fhallno";
			
			$results = $this->aobj_context->mobj_db->GetAll($query);
			
			$roomprifxarry = ["A","B","C","D",'E',"F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","AA","AB",
			"AC","AD",'AE',"AF","AG","AH","AI","AJ","AK","AL","AM","AN","AO","AP","AQ","AR","AS","AT","AU","AV","AW","AX","AY","AZ"];

			$x = 0;
			foreach($results as $value)
			{

				$qrypre = "select fprefix,fcapacity from masroom where fcollcode = '{$this->collcode}'
				and froomno = '{$value['fhallno']}'";
				$resqrypre = $this->aobj_context->mobj_db->GetRow($qrypre);

	
				$teacode = $teacharry[$x];
				$roomprifix = $resqrypre['fprefix'];
				$fcapacity = ($resqrypre['fcapacity']/2);
				$lprix = 3;
				if($x >25)
					$lprix =2;
			
				if($this->funivcode == '033' || $this->funivcode == '052') 
				{

					$query1 = "SET SESSION group_concat_max_len=10000000";
					$res9 = $this->aobj_context->mobj_db->Execute($query1);

					$query =  "SELECT distinct s.fqpcode,cd.fdegree,cd.fqpcode1,cd.fcollcode,cd.fexamno, count(*) as cnt, 
					group_concat(cd.fregno order by {$regorder}) as reg
					FROM $canddet cd INNER JOIN subject s ON s.fdegree = cd.fdegree 
					AND s.fexamno = cd.fexamno AND s.FSUBCODE = cd.FSUBCODE and cd.fqpcode1 = s.fqpcode
					INNER JOIN $candsum cs ON cs.FREGNO = cd.FREGNO 			
					WHERE s.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
					AND IFNULL(cd.fpassmth,'') = '' AND cd.FPRESENT='P'  {$sectionvalue}
					AND IFNULL(cs.FRECPTDATE,'0000-00-00')<>'0000-00-00'  
					and cs.fcntrcode = '{$this->collcode}' 
					 and ifnull(s.fqpcode,'') <> ''
					 and cd.fhallno = '{$value['fhallno']}'
					 and cd.fdegree in(select distinct fdegree from degree where fdeggrp = '{$deggrp}')
					 group by fqpcode 
					 order by cnt desc,cd.fhallno";
					 $res = $this->aobj_context->mobj_db->GetAll($query);

					$a =1;
					$b =2;	 
					$i =1;
					$r = 1;
					$y =1;
					$x = 1;
					foreach($res as $val)
					{

						$fdegree   = $val['fdegree'];
						$fqpcode1  = $val['fqpcode1'];
						$fexamno   = $val['fexamno'];
						$reg       = $val['reg'];
						$regdet    = explode(",",$reg);
						
					
						foreach($regdet as $ereg)
						{
							$regno = $ereg;

							if($this->funivcode == '052')
							{
								if($x <= $fcapacity)
								{	
									$slno = 'A'.$x;
								}
								else
								{	
									$slno = 'B'.$y;	
									$y++;
									
								}

								$update = "update $canddet set fslno = '{$slno}'
								where fqpcode1 = '{$fqpcode1}'
								and fexamno = '{$fexamno}'
								and fregno = '{$regno}'";
								
								$res1 = $this->aobj_context->mobj_db->Execute($update);
								$x++;
							}
							else
							{
								
								if(( $i == 1 && $r <= $fcapacity ))
									$slno = $roomprifix.str_pad($a, $lprix, "0",STR_PAD_LEFT);
								else
									$slno = $roomprifix.str_pad($b, $lprix, "0",STR_PAD_LEFT);	

								$update = "update $canddet set fslno = '{$slno}'
								where fqpcode1 = '{$fqpcode1}'
								and fexamno = '{$fexamno}'
								and fregno = '{$regno}'";
								
								$res1 = $this->aobj_context->mobj_db->Execute($update);
								if($i==1  && $r <= $fcapacity)
									$a = $a+2;
								else
									$b = $b+2;	
								
								$r++;
							}
						}
						$i++;

					}
					//die();

				} 
				else
				{
					if($this->funivcode == '055')
					{
						$query = "update $canddet x, (select right(concat('000',@a:=@a+1),3) as fslno, fregno, fqpcode1, fhallno
						from (select cd.fdegree, cd.fcollcode, 
						cd.fregno,cd.fqpcode1, cd.fhallno from  $canddet cd, subject s, $candsum cs
						where s.fdegree = cd.fdegree 
						AND s.fexamno = cd.fexamno AND s.FSUBCODE = cd.FSUBCODE 
						and cd.fqpcode1 = s.fqpcode and cs.FREGNO = cd.FREGNO AND cd.FDEGREE=cs.FDEGREE
						and cd.fcollcode = cs.fcollcode 
						and s.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
						AND IFNULL(cd.fpassmth,'') = '' AND cd.FPRESENT='P'  {$sectionvalue}
						AND IFNULL(cs.FRECPTDATE,'0000-00-00')<>'0000-00-00'  and cd.fhallno = '{$value['fhallno']}'
						and cs.fcntrcode = '{$this->collcode}'
						and ifnull(s.fqpcode,'') <> ''
						order by cd.fqpcode1,RAND(),fregno) b, (SELECT @a:= '000') AS a) y
						set x.fslno = y.fslno 
						where x.fqpcode1 = y.fqpcode1
						and x.fhallno = y.fhallno
						and x.fregno = y.fregno";
					}else
					{
						$query = "update $canddet x, (select right(concat('000',@a:=@a+1),3) as fslno, fregno, fqpcode1, fhallno
						from (select cd.fdegree, cd.fcollcode, 
						cd.fregno,cd.fqpcode1, cd.fhallno from  $canddet cd, subject s, $candsum cs
						where s.fdegree = cd.fdegree 
						AND s.fexamno = cd.fexamno AND s.FSUBCODE = cd.FSUBCODE 
						and cd.fqpcode1 = s.fqpcode and cs.FREGNO = cd.FREGNO 
						and cd.fcollcode = cs.fcollcode 
						and s.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
						AND IFNULL(cd.fpassmth,'') = '' AND cd.FPRESENT='P'  {$sectionvalue}
						AND IFNULL(cs.FRECPTDATE,'0000-00-00')<>'0000-00-00'  and cd.fhallno = '{$value['fhallno']}'
						and cs.fcntrcode = '{$this->collcode}'
						and ifnull(s.fqpcode,'') <> ''
						order by cd.fqpcode1,fregno) b, (SELECT @a:= '000') AS a) y
						set x.fslno = y.fslno 
						where x.fqpcode1 = y.fqpcode1
						and x.fhallno = y.fhallno
						and x.fregno = y.fregno";
					}
					
					
					$lobj_insert = $this->aobj_context->mobj_db->Execute($query);
				}
				//$query = "";
				//var_dump($query); and cd.fregno in(select distinct fregno from student where fcollcode = '{$this->collcode}' order by fregno)
				
			
				$x++;
				
			}

			$query = "delete from anscapt where fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d') and fcntrcode = '{$this->collcode}'
			and ifnull(fansbookno,'') = ''";
			
			$lobj_update = $this->aobj_context->mobj_db->Execute($query);	
			
			$query = "insert ignore into anscapt(fregno, fdegree, fqpcode, fpresent, fyear, fexamtype, fdoe, fsession, fcntrcode, froomno)
			select a.fregno, a.fdegree, s.fqpcode, a.fpresent, a.fyear, a.fexamtype, s.fdoe, s.fsession, b.fcntrcode, 
			a.fhallno from $canddet a inner join $candsum b on a.fcollcode = b.fcollcode 
			and a.fregno = b.fregno inner join subject s on a.fdegree = s.fdegree and a.fexamno = s.fexamno
			and a.fsubcode = s.fsubcode
			and INSTR(b.fhtenable,a.fexamno) >0
			where ifnull(b.frecptdate,'') <> '' and ifnull(a.fpresent,'') = 'P' and ifnull(fpassmth,'') = ''
			and fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
			and b.fcntrcode = '{$this->collcode}'";
			
			$lobj_update = $this->aobj_context->mobj_db->Execute($query);

			$insert = " insert ignore into room_allotment(FCOLLCODE,FQPCODE,FHALLNO,FCAPACITY,FLOGNAME,FLOGDATE,FDOE,FSESSION )
					select b.fcntrcode, s.fqpcode,a.fhallno, '26','-',now(),s.fdoe, s.fsession 
					from $canddet a inner join $candsum b on a.fcollcode = b.fcollcode 
					and a.fregno = b.fregno inner join subject s on a.fdegree = s.fdegree and a.fexamno = s.fexamno
					and a.fsubcode = s.fsubcode
					and INSTR(b.fhtenable,a.fexamno) >0
					where ifnull(b.frecptdate,'') <> '' and ifnull(a.fpresent,'') = 'P' and ifnull(fpassmth,'') = ''
					and fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
					and b.fcntrcode = '{$this->collcode}'";
			$lobj_insert = $this->aobj_context->mobj_db->Execute($insert);

		}	



		echo $this->aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 	
	}
		
	function SaveRoomAllotmentDatewise()
	{
		ini_set('memory_limit','900M');
		ini_set('max_execution_time',0);
		include_once($this->aobj_context->main_src."/src/json.php"); 
		$json = new Services_JSON();
		$hall_arr = stripslashes($this->aobj_context->mobj_data["hall_arr"]);
		
		$mobj_jsondata = $json->decode($hall_arr);
		$hall_arr = get_object_vars($mobj_jsondata);

		$i = 0;
		$oldqp = '';
		$newqp = '';
		$j = 0;
		$mpcnd = "and ifnull(ab.fabstype,'') <> 'QpM'";
		if($this->funivcode == '027' || $this->funivcode == '052')
			$mpcnd = "";
		for($k=1;$k<=count($hall_arr);$k++)
		{		
	
			$newqp = $hall_arr[$k]->qpcode;
			if($newqp != $oldqp)
			{
				$i = 0;
				
				$query1 = "SET SESSION group_concat_max_len=100000";
				$results1 = $this->aobj_context->mobj_db->Execute($query1);

				$query = "SELECT group_concat(distinct concat(\"'\",cd.FREGNO,\"'\") order by cd.fregno) as fregno,cd.FEXAMNO,cd.FDEGREE,cd.FSUBCODE
				FROM canddet cd INNER JOIN subject s ON s.fdegree = cd.fdegree 
				AND s.fexamno = cd.fexamno AND s.FSUBCODE=cd.FSUBCODE
				INNER JOIN candsum cs ON cs.FCOLLCODE = cd.FCOLLCODE and cs.fdegree = cd.fdegree and cs.FREGNO=cd.FREGNO 
				left join attshort a on  a.fdegree = cd.fdegree and cd.fexamno = a.fexamno and a.fregno = cd.fregno and left(a.fsubcode,4) = cd.fsubcode
				left join absent  ab on  ab.fregno = cd.fregno 
				WHERE cs.FCNTRCODE='{$this->collcode}' AND TRIM(s.FQPCODE)='{$hall_arr[$k]->qpcode}' 
				AND FPRESENT='P' AND IFNULL(cd.fpassmth,'') = '' 
				and ifnull(a.fregno,'') = '' 
				{$mpcnd}
				AND IFNULL(cs.FRECPTDATE,'0000-00-00')<>'0000-00-00' 
				group by s.fqpcode
				ORDER BY cd.FREGNO";

				$results = $this->aobj_context->mobj_db->GetRow($query);

			}

			if($hall_arr[$j]->remaing > 0)
			{
				$hall_arr[$k]->capacity = $hall_arr[$j]->remaing;
			}
			
			$insert = " insert into room_allotment(FCOLLCODE,FQPCODE,FHALLNO,FCAPACITY,FLOGNAME,FLOGDATE,FDOE,FSESSION,FORDER )
						values ('{$this->collcode}','{$hall_arr[$k]->qpcode}' ,'{$hall_arr[$k]->hallno}','{$hall_arr[$k]->alloted}','{$this->log_name}',now(),'{$hall_arr[$k]->fdoe}','{$hall_arr[$k]->sestion}','{$k}')";
			$lobj_insert = $this->aobj_context->mobj_db->Execute($insert);
		
			$fregno = explode(',',$results['fregno']);
			$FSUBCODE = $results['FSUBCODE'];
			$regnoin = array_slice($fregno,$i,$hall_arr[$k]->capacity);
			$regnoin = implode(',',$regnoin);
		
			$update = "update $canddet,candsum,subject
			set canddet.FHALLNO='{$hall_arr[$k]->hallno}'
			where
			canddet.FCOLLCODE = candsum.FCOLLCODE
			and canddet.FDEGREE = candsum.FDEGREE
			and canddet.FREGNO = candsum.FREGNO
			and canddet.fdegree = subject.fdegree
			and canddet.fexamno = subject.fexamno
			and canddet.fsubcode = subject.fsubcode
			and candsum.FCNTRCODE = '{$this->collcode}'
			and subject.fqpcode = '{$hall_arr[$k]->qpcode}'
			and canddet.fregno in({$regnoin})";
			$lobj_update = $this->aobj_context->mobj_db->Execute($update);	
			
			$i = $i+$hall_arr[$k]->capacity; 
			$oldqp = $hall_arr[$k]->qpcode;
			$j++;
		}

		if($lobj_update)
		{
			$data="Update Successfully.";
			echo $this->aobj_context->mobj_output->ToJSONEnvelope($data,0,"success"); 				
		}
		else
		{
			$data="Failed";
			echo $this->aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 		
		}
	}	 
 }
	
function DisplayRoomAllotmentDetatilsDatewiseStph($aobj_context)
{
    $class_obj=new room_allotment($aobj_context);
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$class_obj->DisplayRoomAllotmentDetatilsDatewiseStph();
}

function SaveRoomAllotmentDatewise($aobj_context)
{
    $class_obj=new room_allotment($aobj_context);
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$class_obj->SaveRoomAllotmentDatewise();
} 

function getRoomdetails($aobj_context)
{
	session_start();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$collcode = $_SESSION['collcode'];
	
	$query = "select froomno as id, froomname as value from masroom 
			where ifnull(fdeleted,'') <>'T' 
			and  fcollcode = '{$collcode}' and fcapacity <> 0 order by froomno ";
	
$rst = 	$aobj_context->mobj_db->getAll($query);	//forder,
	
	echo $aobj_context->mobj_output->ToJSONEnvelope($rst,0,"success"); 
}	
?>