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


Current Path : /proc/thread-self/root/var/www/html/univadmin_bkp/univadmin/Reports/
Upload File :
Current File : //proc/thread-self/root/var/www/html/univadmin_bkp/univadmin/Reports/timeTableClashReport.php

<?php
$main_src = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - 7);
$pdf_writer_class = $main_src . "/tcpdf/tcpdf.php";
require_once $pdf_writer_class;
// ini_set('memory_limit','900M');
// ini_set('max_execution_time',0);

class MYPDF extends TCPDF
{
    public $aobj_context;

    public function setData($aobj_context)
    {
        $this->aobj_context = $aobj_context;
        $this->doe = $aobj_context->mobj_data["fdatefrom"];
        $this->reportType = $aobj_context->mobj_data["rtype"];
        $this->qprngfrom = $aobj_context->mobj_data["qpfrm"];
        $this->qprngto = $aobj_context->mobj_data["qpto"];
        $fdeggrp = $aobj_context->mobj_data["dgp"];
    }
    public function Header()
    {
        // get the current page break margin
        $bMargin = $this->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $this->AutoPageBreak;
        // disable auto-page-break
        $this->SetAutoPageBreak(false, 0);
        $this->SetTitle("Time Table Error Report");
        // set bacground image
        $this->SetFillColor(248, 248, 255);
        $img_path = $this->aobj_context->main_src . "/img/logo.jpg";

        if (file_exists($img_path)) {
            $this->Image($img_path, 6, 6, 20, 20);
        }

        $this->SetFont('Times', 'B', 13);
        $this->SetY(5);
        $this->Cell(0, 4, $this->aobj_context->FUNIVNAME, 0, 1, 'C');
        //state
        $this->SetFont('Times', '', 11);
        $this->Cell(0, 4, $this->aobj_context->s_state, 0, 1, 'C');

        $this->SetFont('Times', 'BU', 12);
        $this->Ln(1);

        $this->Cell(0, 5, 'Time Table Error Report', '0', 1, 'C');
        $this->SetFont('Times', 'B', 12);

        $this->SetFont('Times', 'B', 11);
        $this->Cell(0, 4, $this->aobj_context->deggrp['fdeggrp'].' - '. 
                        $this->aobj_context->deggrp['fdescpn'], 0, 1, 'C');
        // var_dump($this->aobj_context->deggrp);
        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
    }

    public function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('helvetica', 'I', 8);
        if($this->CurOrientation == 'P')
        {
            $this->Cell(60, 10, 'IP : ' . $_SERVER["REMOTE_ADDR"], 0, 0, 'L');
            $this->Cell(60, 10, 'Date : ' . date("d-m-Y h:i:s A"), 0, 0, 'C');
            $this->Cell(60, 10, 'Page ' . $this->getPageNumGroupAlias() . '/' . $this->getPageGroupAlias(), 0, 1, 'R');
        }
        else {
            $this->Cell(90, 10, 'IP : ' . $_SERVER["REMOTE_ADDR"], 0, 0, 'L');
            $this->Cell(90, 10, 'Date : ' . date("d-m-Y h:i:s A"), 0, 0, 'C');
            $this->Cell(90, 10, 'Page ' . $this->getPageNumGroupAlias() . '/' . $this->getPageGroupAlias(), 0, 1, 'R');
        }
    }
}

class ReprtObject
{

    public function DefaultConstructor($aobj_context)
    {
        $this->aobj_context = $aobj_context;
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

        $this->ip = $_SERVER["REMOTE_ADDR"];
        $get_date = "select DATE_FORMAT(now(), '%d/%m/%Y') as now_date";
        $obj = $this->aobj_context->mobj_db->GetRow($get_date);
        $this->reportType = $aobj_context->mobj_data["rtype"];

        $get_coll_name = "select FUNIVNAME as 'FUNIVNAME',FUNIVCODE,
		FUNIVADD1 as 'state', pdf_logo_path,
		ifnull(FEXAMAPPREQ,'F') as FEXAMAPPREQ From control";
        $lobj_get_coll_name = $this->aobj_context->pobj_db->GetRow($get_coll_name);
// var_dump($get_coll_name);
        $aobj_context->FUNIVNAME = $lobj_get_coll_name['FUNIVNAME'];
        $aobj_context->s_state = $lobj_get_coll_name['state'];
        $aobj_context->pdf_logo_path = $lobj_get_coll_name['pdf_logo_path'];
        $aobj_context->FUNIVCODE = $lobj_get_coll_name['FUNIVCODE'];
        
        $aobj_context->deggrp = $this->deggrp;
        $this->current_date = $obj['now_date'];



        $this->pdf = new MYPDF('L');
        $this->pdf->setData($aobj_context);
    }

    public function Header1($pdf)
    {
        $pdf->SetFont('Times', 'B', 10);
        $pdf->Cell(8, 4, "Sl.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Degree", "LRT", 0, "C");
        $pdf->Cell(13, 4, "Sem", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Sub.", "LRT", 0, "C");
        $pdf->Cell(100, 4, "Subject Name", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Max.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Stud.", "LRT", 1, "C");
        
        $pdf->Cell(8, 4, "No", "LRB", 0, "C");
        $pdf->Cell(15, 4, "", "LRB", 0, "C");
        $pdf->Cell(13, 4, "", "LRB", 0, "C"); //w h txt brd pos align
        $pdf->Cell(15, 4, "Code", "LBR", 0, "C");
        $pdf->Cell(100, 4, "", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Marks", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Count", "LBR", 1, "C");
        $pdf->SetFont('Times', '', 10);
    }

    public function WriteReport1($exattendancelist)
    {
        $pdf = $this->pdf;

        $pdf->SetMargins(15, 30);
        $pdf->startPageGroup();
        $pdf->AddPage("P");
        $pdf->SetFont('Times', 'B', 12);
        $pdf->Cell(0, 5, 'QP Codes not provided for below subjects', '0', 1, 'C');
        $pdf->SetFont('Times', '', 10);
        $pdf->Ln(5);
        $first = true;
        // var_dump($exattendancelist);
        $this->Header1($pdf);
        $sl_no = 1;
        foreach ($exattendancelist as $key => $value) {

            if ($pdf->getY() > 260) {
                $pdf->AddPage("P");
                $this->Header1($pdf);
            }
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            $pdf->SetX($x + 51);
            $pdf->MultiCell(100, 6, $value['fsubname'], 1, "L");
            $y1 = $pdf->GetY();
            $h = $y1 - $y;
            $pdf->SetXY($x, $y);
            $pdf->Cell(8, $h, $sl_no, "1", 0, "C");
            $pdf->cell(15, $h, $value['fdegree'], "1", 0, "C");
            $pdf->cell(13, $h, $value['fexamno'], "1", 0, "C");
            $pdf->cell(15, $h, $value['fsubcode'], "1", 0, "C");
            $pdf->SetXY($x + 151, $y);
            // $pdf->cell(79, $h, $value['fsubname'], "1", 0, "L");
            $pdf->cell(15, $h, $value['fmaxmarks'], "1", 0, "C");
            $pdf->cell(15, $h, $value['student_count'], "1", 1, "C");
            
        
            $sl_no++;
        }
    }

    public function Header2($pdf)
    {
        $pdf->SetFont('Times', 'B', 10);
        $pdf->Cell(8, 4, "Sl.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "QP Code", "LRT", 0, "C");
        $pdf->Cell(79, 4, "Subject Name", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Max.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Stud.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Temp", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Perm.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Session", "LRT", 1, "C");
        
        $pdf->Cell(8, 4, "No", "LRB", 0, "C");
        $pdf->Cell(15, 4, "", "LBR", 0, "C");
        $pdf->Cell(79, 4, "", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Marks", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Count", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Date", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Date", "LBR", 0, "C");
        $pdf->Cell(15, 4, "", "LBR", 1, "C");
        $pdf->SetFont('Times', '', 10);
    }

    public function WriteReport2($exattendancelist)
    {
        $pdf = $this->pdf;

        $pdf->SetMargins(15, 30);
        $pdf->startPageGroup();
        $pdf->AddPage("P");
        $pdf->SetFont('Times', 'B', 12);
        $pdf->Cell(0, 5, 'Time Table Not alloted for the below QP Codes', '0', 1, 'C');
        $pdf->SetFont('Times', '', 10);
        $pdf->Ln(5);
        $first = true;
        // var_dump($exattendancelist);
        $this->Header2($pdf);
        $sl_no = 1;
        foreach ($exattendancelist as $key => $value) {

            if ($pdf->getY() > 260) {
                $pdf->AddPage("P");
                $this->Header2($pdf);
            }
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            $pdf->SetX($x + 23);
            $pdf->MultiCell(79, 6, $value['fsubname'], 1, "L");
            $y1 = $pdf->GetY();
            $h = $y1 - $y;
            $pdf->SetXY($x, $y);
            $pdf->Cell(8, $h, $sl_no, "1", 0, "C");
            $pdf->cell(15, $h, $value['fqpcode'], "1", 0, "C");
            $pdf->SetXY($x + 102, $y);
            // $pdf->cell(79, $h, $value['fsubname'], "1", 0, "L");
            $pdf->cell(15, $h, $value['fmaxmarks'], "1", 0, "C");
            $pdf->cell(15, $h, $value['student_count'], "1", 0, "C");
            $pdf->cell(15, $h, $value['fdatecodet'], "1", 0, "C");
            $pdf->cell(15, $h, $value['fdatecodep'], "1", 0, "C");
            $pdf->cell(15, $h, $value['fsession'], "1", 1, "C");
            
            $sl_no++;
        }
    }

    public function Header3($pdf)
    {
        $pdf->SetFont('Times', 'B', 10);
        $pdf->Cell(8, 4, "Sl.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Date", "LRT", 0, "C");
        $pdf->Cell(79, 4, "QP Codes", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Stud.", "LRT", 1, "C");
        
        $pdf->Cell(8, 4, "No", "LRB", 0, "C");
        $pdf->Cell(15, 4, "Code", "LBR", 0, "C");
        $pdf->Cell(79, 4, "", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Count", "LBR", 1, "C");
        $pdf->SetFont('Times', '', 10);
    }

    public function Header4($pdf)
    {
        $pdf->SetFont('Times', 'B', 10);
        $pdf->Cell(8, 4, "Sl.", "LRT", 0, "C");
        $pdf->Cell(20, 4, "Reg. No.", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Date", "LRT", 0, "C");
        $pdf->Cell(15, 4, "Session", "LRT", 0, "C");
        $pdf->Cell(79, 4, "QP Codes", "LRT", 0, "C");
        $pdf->Cell(15, 4, "QP", "LRT", 1, "C");
        
        $pdf->Cell(8, 4, "No", "LRB", 0, "C");
        $pdf->Cell(20, 4, "", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Code", "LBR", 0, "C");
        $pdf->Cell(15, 4, "", "LBR", 0, "C");
        $pdf->Cell(79, 4, "", "LBR", 0, "C");
        $pdf->Cell(15, 4, "Count", "LBR", 1, "C");
        $pdf->SetFont('Times', '', 10);
    }

    public function WriteReport3($summary, $detailed)
    {
        $pdf = $this->pdf;

        $pdf->SetMargins(25, 30);
        $pdf->startPageGroup();
        $pdf->AddPage("P");
        $pdf->SetFont('Times', 'B', 12);
        $pdf->Cell(0, 5, 'Time table clashes Summary', '0', 1, 'C');
        $pdf->SetFont('Times', '', 10);
        $pdf->Ln(5);
        $first = true;
        // var_dump($exattendancelist);
        $this->Header3($pdf);
        $sl_no = 1;
        foreach ($summary as $key => $value) {

            if ($pdf->getY() > 260) {
                $pdf->AddPage("P");
                $this->Header3($pdf);
            }
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            $pdf->SetX($x + 23);
            $pdf->MultiCell(79, 6, $value['qpcode'], 1, "L");
            $y1 = $pdf->GetY();
            $h = $y1 - $y;
            $pdf->SetXY($x, $y);
            $pdf->Cell(8, $h, $sl_no, "1", 0, "C");
            $pdf->cell(15, $h, $value['fdatecodet'], "1", 0, "C");
            $pdf->SetXY($x + 102, $y);
            // $pdf->cell(79, $h, $value['fsubname'], "1", 0, "L");
            $pdf->cell(15, $h, $value['student_count'], "1", 1, "C");
            $sl_no++;
        }
        $pdf->Ln(5);
        $pdf->SetFont('Times', 'B', 12);
        $pdf->Cell(0, 5, 'Time table clashes Detailed', '0', 1, 'C');
        $pdf->SetFont('Times', '', 10);
        $pdf->Ln(5);
        $first = true;
        // var_dump($exattendancelist);
        $this->Header4($pdf);
        $sl_no = 1;
        foreach ($detailed as $key => $value) {

            if ($pdf->getY() > 260) {
                $pdf->AddPage("P");
                $this->Header4($pdf);
            }
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            $pdf->SetX($x + 58);
            $pdf->MultiCell(79, 6, $value['qpcode'], 1, "L");
            $y1 = $pdf->GetY();
            $h = $y1 - $y;
            $pdf->SetXY($x, $y);
            $pdf->Cell(8, $h, $sl_no, "1", 0, "C");
            $pdf->cell(20, $h, $value['fregno'], "1", 0, "C");
            $pdf->cell(15, $h, $value['fdatecodet'], "1", 0, "C");
            $pdf->cell(15, $h, $value['fsession'], "1", 0, "C");
            $pdf->SetXY($x + 137, $y);
            // $pdf->cell(79, $h, $value['fsubname'], "1", 0, "L");
            $pdf->cell(15, $h, $value['qpcount'], "1", 1, "C");
            $sl_no++;
        }
    }

    public function SendOutput()
    {
        // ob_end_clean();
        $this->pdf->Output("TimeTableClashes.pdf", "I");
    }
}

function GenerateExamTimetableError($aobj_context)
{
    ini_set('max_execution_time', '300');
    $univcode = $aobj_context->mobj_data["univcode"];
    $deggrp = $aobj_context->mobj_data["deggrp"];  

    $examnoStr = strtoupper($aobj_context->mobj_data["examrange"]);
    $splitexamno = str_split($examnoStr);
    
    $examno = implode("','", $splitexamno);

    $query = "select fdeggrp, fdescpn, fyear, fexamtype from deggrp where fdeggrp = '{$deggrp}'";
    $fdeggrp = $aobj_context->pobj_db->GetRow($query);

    $query = "CREATE TEMPORARY TABLE `tmpettcd` (
        `fregno` varchar(10) NOT NULL,
        `fdegree` varchar(5) NOT NULL,
        `fexamno` varchar(5) NOT NULL,
        `fsubcode` varchar(5) NOT NULL,
        PRIMARY KEY (`fregno`,`fdegree`,`fexamno`,`fsubcode`),
        KEY `fdegree` (`fdegree`,`fexamno`,`fsubcode`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1";
    $result = $aobj_context->pobj_db->Execute($query);

    $query = "CREATE TEMPORARY TABLE `tmpettsub` (
        `fdegree` varchar(5) NOT NULL,
        `fexamno` varchar(1) NOT NULL,
        `fsubcode` varchar(5) NOT NULL,
        `fsubname` varchar(100) DEFAULT NULL,
        `fqpcode` varchar(25) NOT NULL,
        `fdatecodep` varchar(4) DEFAULT NULL,
        `fdatecodet` varchar(4) DEFAULT NULL,
        `fsession` varchar(5) DEFAULT NULL,
        `fmaxmarks` int(3) DEFAULT NULL,
        PRIMARY KEY (`fdegree`,`fexamno`,`fsubcode`,`fqpcode`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1";
    
    $result = $aobj_context->pobj_db->Execute($query);

    $query = "insert into tmpettsub
    select fdegree, fexamno, fsubcode, fsubname, fqpcode, fdatecodep, fdatecodet, fsession, fsmaxmarks
     from subject where ifnull(ftheory,'') = 'T' and ifnull(fintass,'') = 'F' 
     and ifnull(fretain,'') = 'F' and ifnull(fsuspend,'') <> 'T' and ifnull(fsubsidary, '') <> 'T' 
     and fexamno in ( '{$examno}' )
    and fdegree in (select fdegree from degree where ifnull(fdeggrp,'') = '{$deggrp}') 
    order by fdegree, fexamno, fsubcode";
    $result = $aobj_context->pobj_db->Execute($query);

    $query = "insert into tmpettcd
    select fregno, fdegree, fexamno, fsubcode from canddet where ifnull(fpresent,'') = 'P'
    and ifnull(fpassmth,'') = '' and fyear = '{$fdeggrp['fyear']}' 
    and fexamtype= '{$fdeggrp['fexamtype']}'  and fexamno in ( '{$examno}')
    and fdegree in (select fdegree from degree where ifnull(fdeggrp,'') = '{$deggrp}')";
    $result = $aobj_context->pobj_db->Execute($query);

    $query = "select c.fdegree, c.fexamno, s.fsubcode, s.fsubname, fmaxmarks, 
    count(c.fregno) as student_count
    from tmpettcd c inner join tmpettsub s 
    on c.fdegree = s.fdegree and c.fexamno = s.fexamno
    and c.fsubcode = s.fsubcode 
    where ifnull(fqpcode,'') ='' 
    group by fdegree, fexamno, fsubcode
    order by fdegree, fexamno, fsubcode";
    
    $result1 = $aobj_context->pobj_db->GetAll($query);

    $query = "select s.fqpcode, s.fsubname, count(c.fregno) as student_count, 
    ifnull(s.fdatecodep, '') as fdatecodep, fmaxmarks,
    ifnull(s.fdatecodet, '') as fdatecodet, ifnull(fsession,'') as fsession
    from tmpettcd c inner join tmpettsub s 
    on c.fdegree = s.fdegree and c.fexamno = s.fexamno
    and c.fsubcode = s.fsubcode 
    where (ifnull(fdatecodep,'') ='' or ifnull(fdatecodet,'') = '' or ifnull(fsession,''))
    and ifnull(s.fqpcode,'') <> ''
    group by s.fqpcode
    order by s.fqpcode";

    $result2 = $aobj_context->pobj_db->GetAll($query);

    $query = "create temporary table ttclashes
    select fregno, fdatecodet, fsession, count(s.fqpcode) as qpcount, 
    group_concat(s.fqpcode order by s.fqpcode) as qpcode
    from tmpettcd c inner join tmpettsub s 
    on c.fdegree = s.fdegree and c.fexamno = s.fexamno
    and c.fsubcode = s.fsubcode 
    where ifnull(s.fqpcode,'') <> '' 
    group by fregno, fdatecodet, left(fsession,1)
    having count(s.fqpcode) > 1
    order by fregno";
    $result = $aobj_context->pobj_db->Execute($query);

    $query = "select distinct fdatecodet, qpcode,count(fregno) as student_count  from ttclashes
    group by fdatecodet, qpcode";

    $result3 = $aobj_context->pobj_db->GetAll($query);

    $query = "select fregno, fdatecodet, fsession, qpcount, qpcode from ttclashes";
    $result4 = $aobj_context->pobj_db->GetAll($query);


    $class_obj = new ReprtObject();
    $class_obj->univcode = $univcode;
    $class_obj->deggrp = $fdeggrp;
    $class_obj->DefaultConstructor($aobj_context);

    // If No data found Generate Blank Report
    if (count($result1) > 0) {
        $class_obj->WriteReport1($result1);
    }

    if (count($result2) > 0) {
        $class_obj->WriteReport2($result2);
    }

    if (count($result3) > 0) {
        $class_obj->WriteReport3($result3, $result4);
    }

    $query  = "drop table tmpettsub";
    $result = $aobj_context->pobj_db->Execute($query);

    $query  = "drop table tmpettcd";
    $result = $aobj_context->pobj_db->Execute($query);

    $query  = "drop table ttclashes";
    $result = $aobj_context->pobj_db->Execute($query);

    $class_obj->SendOutput();

}