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.146.37.242
<?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 DisplayRoomAllotmentDetatilsDatewise()
{
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"]);
$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"]);
if($session== 'both')
{
$sectionvalue = "";
}
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}'
GROUP BY s.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 masroom where
froomno >= '{$ra_from}'
AND froomno <='{$ra_to}'
and fcollcode = '{$this->collcode}'";
$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,candsum cs
set cd.fqpcode1 = s.fqpcode, cd.FHALLNO = NULL, cd.fslno = NULL
where cd.fdegree = s.fdegree and cd.fexamno = s.fexamno
and cs.fdegree = cd.fdegree and cs.fcollcode = cd.fcollcode
and cs.fregno = cd.fregno and cs.fcntrcode = '{$this->collcode}'
and ifnull(cd.fpassmth,'') = '' and cd.fpresent = 'P'
and cd.fsubcode = s.fsubcode and s.fsession like '{$session}'
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();
// var_dump($rows_affected);
$query = "update masroom set fbalroomcnt = fcapacity where froomno >= '0'
AND froomno <='z' AND fcollcode = '{$this->collcode}'";
$rst1 = $this->aobj_context->mobj_db->Execute($query);
$query = "SELECT COUNT(DISTINCT cd.FREGNO) AS reg_cnt,s.FQPCODE,s.FDOE,s.fsubcode,cd.forder
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
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,'') <> ''
GROUP BY s.FQPCODE,cd.forder ORDER BY cd.forder,reg_cnt DESC,s.fsession,s.FQPCODE";
$results = $this->aobj_context->mobj_db->GetAll($query);
//var_dump($query);
$k = 1;
foreach($results as $ak=>$value)
{
$reg_cnt = $value['reg_cnt'];
$qpcode = $value['FQPCODE'];
$forder = $value['forder'];
//var_dump($qpcode);
$query2 ="SELECT * FROM masroom
WHERE froomno >= '{$ra_from}'
AND froomno <='{$ra_to}'
AND fcollcode = '{$this->collcode}'
and fcapacity > 0
order by forder,froomno";
$restults = $this->aobj_context->mobj_db->GetAll($query2);
//var_dump($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'];
// $query = "select group_concat(distinct concat(\"'\",FREGNO,\"'\") order by forder,fregno) as fregno from canddet
// where fqpcode1 = '{$qpcode}' and forder = '{$forder}'
// and FPRESENT = 'P' and ifnull(fpassmth,'') = ''
// and ifnull(FHALLNO,'') = '' and fcollcode = '{$this->collcode}'
// order by forder,fregno desc
// limit {$studperqp}";
$query = "select group_concat(distinct concat(\"'\",cd.FREGNO,\"'\") order by cd.forder,cd.fregno) as fregno from canddet cd
inner join candsum cs on cd.fdegree = cs.fdegree and cd.fcollcode = cs.fcollcode and cd.fregno = cs.fregno
where cd.fqpcode1 = '{$qpcode}'
and cd.FPRESENT = 'P' and ifnull(cd.fpassmth,'') = ''
and ifnull(cd.FHALLNO,'') = '' and cs.fcntrcode = '{$this->collcode}'
order by cd.forder,cd.fregno desc
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();
//var_dump($rows_affected,$qpcode,$value['froomno']);
if($rows_affected)
{
$query = "update masroom set fbalroomcnt = ({$value['fbalroomcnt']} - $rows_affected)
where froomno = '{$value['froomno']}'
and fcollcode = '{$this->collcode}'";
// 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}','{$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}','{$qpcode}' ,'{$value['froomno']}','{$rows_affected}','{$this->log_name}',now(),date_format(STR_TO_DATE('{$frm_date}', '%d/%m/%Y'),'%Y-%m-%d'),'{$session}','{$k}')
ON DUPLICATE KEY UPDATE
FCOLLCODE = '{$this->collcode}',
FQPCODE = '{$qpcode}',
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}'";
$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.FSUBCODE = cd.FSUBCODE and cd.fqpcode1 = s.fqpcode
INNER JOIN candsum cs ON cs.FREGNO = cd.FREGNO AND cd.FDEGREE=cs.FDEGREE
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,'') <> ''
order by cd.fhallno";
//var_dump($query);
$results = $this->aobj_context->mobj_db->GetAll($query);
foreach($results as $value)
{
// $query = "
// CREATE TABLE tmp_{$this->collcode}
// select distinct st.fregno from candsum st inner join subject su on st.fdegree = su.fdegree and ifnull(su.fqpcode,'') <> '' and
// su.fdoe = date_format(STR_TO_DATE('14/10/2019', '%d/%m/%Y'),'%Y-%m-%d')
// and su.fsession like '{$session}'
// inner join canddet t on st.fcollcode = t.fcollcode and st.fdegree = t.fdegree
// and t.fsubcode = su.fsubcode and t.fregno = st.fregno
// where st.fcntrcode = '{$this->collcode}' and t.fhallno = '{$value['fhallno']}'
// and t.fpresent = 'P'
// and ifnull(su.fqpcode,'') <> '' order by st.fregno";
// $lobj_insert = $this->aobj_context->mobj_db->Execute($query);
// $query = "update canddet cd, subject s,(SELECT @a:= 0) AS a, candsum cs
// set cd.fslno = right(concat('000',@a:=@a+1),3)
// 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,'') <> ''
// and cd.fregno in(select distinct fregno from tmp_{$this->collcode} order by fregno)";
$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 forder,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)
}
}
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);
//var_dump($hall_arr);
$i = 0;
$oldqp = '';
$newqp = '';
$j = 0;
$mpcnd = "and ifnull(ab.fabstype,'') <> 'QpM'";
if($this->funivcode == '027')
$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";
// var_dump($query);
$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);
//var_dump($insert);
$fregno = explode(',',$results['fregno']);
//var_dump($fregno);
$FSUBCODE = $results['FSUBCODE'];
$regnoin = array_slice($fregno,$i,$hall_arr[$k]->capacity);
$regnoin = implode(',',$regnoin);
//var_dump($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);
//var_dump($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 DisplayRoomAllotmentDetatilsDatewise($aobj_context)
{
$class_obj=new room_allotment($aobj_context);
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$class_obj->DisplayRoomAllotmentDetatilsDatewise();
}
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 ";
//var_dump($query);die();
$rst = $aobj_context->mobj_db->getAll($query); //forder,
echo $aobj_context->mobj_output->ToJSONEnvelope($rst,0,"success");
}
?>
|