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 : 3.135.208.236


Current Path : /var/www/html/reva/src/
Upload File :
Current File : /var/www/html/reva/src/ia_room_allotment_datewise.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 DisplayIARoomAllotmentDetatilsDatewise()
	{
		session_start();
		ini_set('max_execution_time', '400');
		$this->collcode=$_SESSION['collcode'];
		$frm_date = ($this->aobj_context->mobj_data["frm_date"]);
		$session = ($this->aobj_context->mobj_data["session"]);

		$fexamno = stripslashes($this->aobj_context->mobj_data["degexam"]);
		$fdegree = stripslashes($this->aobj_context->mobj_data["degree"]);
		
		$ra_from = ($this->aobj_context->mobj_data["ra_from"]);
		$ra_to = ($this->aobj_context->mobj_data["ra_to"]);

		$canddet = "marks";
		$subject = "subject";
		$room_allotment = "room_allotment";

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

		$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.FCSUBCODE = cd.FSUBCODE
					inner join degree dd on cd.fdegree=dd.fdegree
					and dd.fexamno=cd.fexamno 
					inner join iatimetable t on 
					cd.fcollcode = t.fcollcode and cd.fexamno = t.fexamno 
					and cd.fsubcode = t.fsubcode
					and cd.fdegree = t.fdegree
					WHERE t.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
					and t.fsession = '{$session}'
					and cd.fdegree = '{$fdegree}'
					and cd.fexamno = '{$fexamno}'
					and cd.fcollcode = '{$this->collcode}' 
					GROUP BY t.fdoe";

			$results1 = $this->aobj_context->mobj_db->GetRow($query1);
			$reg_cnt = $results1['reg_cnt'];
			//var_dump($reg_cnt);
			$query1 = "select sum(fcapacity) as fcapacity from iamasroom where 
			froomno >= '0'
			AND froomno <='z' 
			and fcollcode = '{$this->collcode}'
			and fdegree = '{$fdegree}'
			and fexamno = '{$fexamno}'
			order by forder";
			$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, iatimetable t
        set cd.FHALLNO = NULL, cd.fslno = NULL
		where cd.fdegree = s.fdegree and cd.fexamno = s.fexamno
        and t.fcollcode = cd.fcollcode
		and t.fsubcode = cd.fsubcode
		and cd.fsubcode = s.fcsubcode
        and cd.fcollcode = '{$this->collcode}'
		and t.fsession = '{$session}'
		and cd.fdegree = '{$fdegree}'
		and cd.fexamno = '{$fexamno}'
		and t.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')";
		
		$rst1 = $this->aobj_context->mobj_db->Execute($query);	

		$query = "update iamasroom set fbalroomcnt = fcapacity where froomno >= '0'
				AND froomno <='z' AND fcollcode = '{$this->collcode}'
				and fdegree = '{$fdegree}'
				and fexamno = '{$fexamno}'";
		$rst1 = $this->aobj_context->mobj_db->Execute($query);	
	
		$query = "SELECT COUNT(DISTINCT cd.FREGNO) AS reg_cnt,t.fdoe,cd.fsubcode
				FROM {$canddet} cd INNER JOIN {$subject} s ON s.fdegree = cd.fdegree 
				AND s.fexamno = cd.fexamno AND s.FCSUBCODE = cd.FSUBCODE 
				inner join iatimetable t on cd.fcollcode = t.fcollcode 
				and cd.fexamno = t.fexamno 
				and cd.fdegree = t.fdegree
				and cd.fsubcode = t.fsubcode
				WHERE t.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
				and t.fsession = '{$session}'
				and cd.fdegree = '{$fdegree}'
				and cd.fexamno = '{$fexamno}'
				and cd.fcollcode = '{$this->collcode}' 
				GROUP BY cd.fsubcode
				ORDER BY reg_cnt DESC,s.fsession";

		$results = $this->aobj_context->mobj_db->GetAll($query); 
		
		$k = 1;
		foreach($results as $ak=>$value)
		{	
			$reg_cnt = $value['reg_cnt'];
			$fsubcode = $value['fsubcode'];	
			//var_dump($qpcode);
			$query2 ="SELECT * FROM iamasroom
				WHERE froomno >= '0'
				AND froomno <='z' 
				AND fcollcode = '{$this->collcode}'
				and fdegree = '{$fdegree}'
				and fexamno = '{$fexamno}'
				and fcapacity > 0
				order by forder,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'];
			
				$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 
				from {$canddet} cd inner join iatimetable t on cd.fcollcode = t.fcollcode
				and cd.fdegree = t.fdegree and cd.fexamno = t.fexamno
				and cd.fsubcode = t.fsubcode
				where cd.fsubcode = '{$fsubcode}' 
				and ifnull(cd.FHALLNO,'') = '' 
				and t.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
				and t.fsession = '{$session}'
				and cd.fcollcode = '{$this->collcode}'
				and cd.fdegree = '{$fdegree}'
				and cd.fexamno = '{$fexamno}'
				order by cd.fregno
				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 fsubcode = '{$fsubcode}'
						and fdegree = '{$fdegree}'
						and fexamno = '{$fexamno}'";
				
				$rst1 = $this->aobj_context->mobj_db->Execute($query);
				
				$rows_affected = $this->aobj_context->mobj_db->affected_rows();

				// var_dump($rows_affected,$qpcode,$value['froomno']);
				// var_dump($query);
				if($rows_affected)
				{
					$query = "update iamasroom set fbalroomcnt = ({$value['fbalroomcnt']} - $rows_affected)
					where froomno = '{$value['froomno']}' 
					and fcollcode = '{$this->collcode}'
					and fdegree = '{$fdegree}'
					and fexamno = '{$fexamno}'";	
					//var_dump($query);
					$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}','{$fsubcode}' ,'{$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,FBATCH )
							values ('{$this->collcode}','{$fsubcode}' ,'{$value['froomno']}','{$rows_affected}','{$this->log_name}',now(),date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d'),'{$session}','{$k}','{$fbatch}')
							ON DUPLICATE KEY UPDATE 
							FCOLLCODE = '{$this->collcode}',
							FQPCODE = '{$fsubcode}',
							FHALLNO = '{$value['froomno']}',
							FCAPACITY = '{$rows_affected}',
							FLOGNAME = '{$this->log_name}',
							FLOGDATE = now(),
							FDOE = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d'),
							FSESSION = '{$session}',
							FORDER = '{$k}',
							FBATCH = '{$fbatch}'";
							$lobj_insert = $this->aobj_context->mobj_db->Execute($insert);
					
				}
				else
				{
					break;
				}

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

		}else
		{
			$query = "SELECT distinct cd.fhallno
				FROM {$canddet} cd INNER JOIN {$subject} s ON s.fdegree = cd.fdegree 
				AND s.fexamno = cd.fexamno AND s.FCSUBCODE = cd.FSUBCODE 		
				inner join iatimetable t on  cd.fcollcode = t.fcollcode 
				and cd.fexamno = t.fexamno 
				and cd.fdegree = t.fdegree
				and cd.fsubcode = t.fsubcode
				WHERE t.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
				and cd.fcollcode = '{$this->collcode}' 
				and cd.fdegree = '{$fdegree}'
				and cd.fexamno = '{$fexamno}'
				and t.fsession = '{$session}'
				and ifnull(cd.fhallno,'') <> ''
				order by cd.fhallno";
			//var_dump($query);
			$results = $this->aobj_context->mobj_db->GetAll($query);

			foreach($results as $value)
			{

				$query = "update {$canddet} x, (select right(concat('000',@a:=@a+1),3) as fslno, fregno, fsubcode, fhallno
				from (select cd.fdegree, cd.fcollcode, 
				cd.fregno,cd.fsubcode, cd.fhallno from  {$canddet} cd, {$subject} s, iatimetable t
				where s.fdegree = cd.fdegree 
				AND s.fexamno = cd.fexamno AND s.FCSUBCODE = cd.FSUBCODE  
				and cd.fcollcode = t.fcollcode 
				and cd.fexamno = t.fexamno 
				and cd.fdegree = t.fdegree
				and cd.fsubcode = t.fsubcode
				and t.fdoe = date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d')
				and t.fsession = '{$session}'
				AND cd.fhallno = '{$value['fhallno']}'
				and cd.fdegree = '{$fdegree}'
				and cd.fexamno = '{$fexamno}'
				and cd.fcollcode = '{$this->collcode}'
				order by cd.fsubcode,fregno) b, (SELECT @a:= '000') AS a) y
				set x.fslno = y.fslno 
				where x.fsubcode = y.fsubcode
				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)

			}

		}	

		echo $this->aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 	
		return;
	}
		
 }
	
function DisplayIARoomAllotmentDetatilsDatewise($aobj_context)
{
    $class_obj=new room_allotment($aobj_context);
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$class_obj->DisplayIARoomAllotmentDetatilsDatewise();
}

function getIARoomdetails($aobj_context)
{
	session_start();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$collcode = $_SESSION['collcode'];
	
	$degexam = stripslashes($aobj_context->mobj_data["degexam"]);
	$degree = stripslashes($aobj_context->mobj_data["degree"]);

	$query = "select froomno as id, froomname as value from iamasroom 
			where fcollcode = '{$collcode}' 
			and fdegree = '{$degree}'
			and fexamno = '{$degexam}'
			and fcapacity > 0 order by froomno ";
	$rst1 = $aobj_context->mobj_db->getAll($query);	
	
	
	$rst['rooms'] = $rst1;
	echo $aobj_context->mobj_output->ToJSONEnvelope($rst,0,"success"); 
	return;
}	

function getIAExamDates($aobj_context)
{
	session_start();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$collcode = $_SESSION['collcode'];
	
	$degexam = stripslashes($aobj_context->mobj_data["degexam"]);
	$degree = stripslashes($aobj_context->mobj_data["degree"]);

	$query = "select distinct date_format(fdoe,'%d/%m/%Y') as internal_code,
	 date_format(fdoe,'%d/%m/%Y') as VALUE 
	from iatimetable 
			where fcollcode = '{$collcode}' 
			and fdegree = '{$degree}'
			and fexamno = '{$degexam}'";
	$rst1 = $aobj_context->mobj_db->getAll($query);	
	
	$rst['iadoe'] = $rst1;
	echo $aobj_context->mobj_output->ToJSONEnvelope($rst,0,"success"); 
	return;

}


function getIASession($aobj_context)
{
	session_start();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$collcode = $_SESSION['collcode'];
	
	$degexam = stripslashes($aobj_context->mobj_data["degexam"]);
	$degree = stripslashes($aobj_context->mobj_data["degree"]);
	$frm_date = stripslashes($aobj_context->mobj_data["frm_date"]);

	$query = "select fsession as internal_code, fsession as VALUE 
	from iatimetable 
			where fcollcode = '{$collcode}' 
			and fdegree = '{$degree}'
			and fexamno = '{$degexam}'
			and fdoe = date_format(str_to_date('{$frm_date}','%d/%m/%Y'),'%Y-%m-%d')";
	$rst1 = $aobj_context->mobj_db->getAll($query);	

	$rst['iasession'] = $rst1;
	echo $aobj_context->mobj_output->ToJSONEnvelope($rst,0,"success"); 
	return;

}

?>