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.147.126.199


Current Path : /var/www/html/univadmin/Reports/
Upload File :
Current File : /var/www/html/univadmin/Reports/examTimeTableQPWiseExcel.php

<?php
ini_set('max_execution_time', 60);
$main_src = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - 7);

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('GMT+5:30');
// PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

/** Include PHPExcel */
$pdf_writer_class = $main_src . '/PHPExcel/Classes/PHPExcel.php';
require_once($pdf_writer_class);


function getheaders($objPHPExcel, $fileName)
{
    //To Fit To Page while printing
    $objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(0);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);
    
    ob_end_clean();
    // ob_start();
    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="' . $fileName . '.xls"');
    header('Cache-Control: max-age=0');
    // If you're serving to IE 9, then the following may be needed
    header('Cache-Control: max-age=1');

    // If you're serving to IE over SSL, then the following may be needed
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
    header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header('Pragma: public'); // HTTP/1.0
    ob_end_clean();
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    
    $objWriter->save('php://output');
}


function reportExamTimeTable($result, $aobj_context)
{

    $objPHPExcel = new PHPExcel();
    $fileName = 'Exam Time Table';
    $objPHPExcel->getProperties()->setCreator("Me")
    ->setLastModifiedBy("Me")->setTitle("My Excel Sheet")
    ->setSubject("My Excel Sheet")->setDescription("Excel Sheet")
    ->setKeywords("Excel Sheet")->setCategory("Me");
    // $objPHPExcel->setOutputEncoding('UTF-8');
    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    $objPHPExcel->getActiveSheet()->setTitle($fileName);
    $objPHPExcel->getActiveSheet()->getPageSetup()
    ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
    
    $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 = $aobj_context->pobj_db->GetRow($get_coll_name);

    $objPHPExcel->getActiveSheet()->getHeaderFooter()
    ->setOddHeader('&C&H&"-,Bold"&16' . $lobj_get_coll_name['FUNIVNAME']);

    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&RPage &P of &N');


    // Add column headers and make them bold
    $styleArray = array(
        'borders' => array(
            'allborders' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN,
                'color' => array('argb' => '000000'),
            ),
        ),
    );

    
    $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setSize(12);
    $objPHPExcel->getActiveSheet()->freezePane('A1');

    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Sl. No.');
    $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Date');
    $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Time');
    $objPHPExcel->getActiveSheet()->setCellValue('D1', 'QP Code');
    $objPHPExcel->getActiveSheet()->setCellValue('E1', 'Subject Name');
    
    
    $objPHPExcel->getActiveSheet()->getStyle('A1:E1')->applyFromArray($styleArray);
    // $objPHPExcel->getActiveSheet()->getColumnDimension('G1')->setAutoSize(true);
    $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);

    $objPHPExcel->getActiveSheet()->getStyle('A1:E1')->getAlignment()->setWrapText(true);
    $objPHPExcel->getActiveSheet()->getStyle('A1:E1')->getAlignment()
                ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('A1:E1')->getAlignment()
                ->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    $j = 2;
    $slNo = 1;
    // setlocale(LC_ALL, 'hi_IN');

    foreach ($result as $key => $value) {

        $objPHPExcel->getActiveSheet()->setCellValue('A' . $j, $slNo)
        ->getColumnDimension('A')->setwidth(5);

        $objPHPExcel->getActiveSheet()->setCellValue('B' . $j, $value['fdate'])
        ->getColumnDimension('B')->setwidth(10.43);

        $objPHPExcel->getActiveSheet()->setCellValue('C' . $j, $value['ftime'])
        ->getColumnDimension('C')->setwidth(25);

        $objPHPExcel->getActiveSheet()->setCellValue('D' . $j, $value['fqpcode'])
        ->getColumnDimension('D')->setwidth(12);

        $objPHPExcel->getActiveSheet()->setCellValue('E' . $j, $value['fsubname'])
        ->getColumnDimension('E')->setwidth(40);

        $objPHPExcel->getActiveSheet()->getRowDimension($j)->setRowHeight(30);
        $j++;$slNo++;
    }
    // var_dump($totamt);die();


    $objPHPExcel->getActiveSheet()->getStyle('A2' . ':E' . $j)->applyFromArray($styleArray);

    $objPHPExcel->getActiveSheet()->getStyle('A2'.':E' . $j)->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

    $objPHPExcel->getActiveSheet()->getStyle('A2'.':E' . $j)->getAlignment()
    ->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    // $objPHPExcel->getActiveSheet()->getStyle('C2'.':C' . $j)->getAlignment()
    // ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

    $objPHPExcel->getActiveSheet()->getStyle('E2'.':E' . $j)->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

    getheaders($objPHPExcel, $fileName);
}


function examTimeTableQPWiseReportExcel($aobj_context) {
    $univcode = $aobj_context->mobj_data["univcode"];
    $deggrp = $aobj_context->mobj_data["deggrp"];
    $examrange = $aobj_context->mobj_data["examrange"];

    $exam = str_split($examrange);

    $examrange = implode("','", $exam);

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

    if($univcode != "021"){

        $query =  "select s.fqpcode, s.fsubname, group_concat(distinct s.fdegree SEPARATOR ', ')  as fdegree,
        ifnull(s.fdatecodet,'') as fdatecode, ifnull(r.freasoncd,'') as ftimecode,d.fexamdate, 
        ifnull(date_format(ifnull(md.fdate, ''),'%d/%m/%Y'),'') as fdate, 
        ifnull(r.fdescpn,'') as ftime
        from subject s inner join degree d on s.fdegree = d.fdegree and s.fexamno = d.fexamno 
        inner join masdate md on s.fdatecodet = md.fdatecode and md.fdeggrp = '{$deggrp}'
        and md.fyear = d.fmeyear and d.fmeexamtyp = md.fexamtype
        inner join reason r on s.fsessiont = r.freasoncd
        where d.fdeggrp = '{$deggrp}' and s.fexamno in('{$examrange}')
        and s.ftheory = 'T' and s.fintass <> 'T' and ifnull(s.fqpcode,'') <>''
        group by s.fqpcode
        order by s.fdatecodet, s.fqpcode";
    }else{
        $query = "select s.fqpcode,s.fsubshort, s.fsubname, group_concat(distinct s.fdegree SEPARATOR ', ')  as fdegree,
        ifnull(t.fdatecodet,'') as fdatecode, ifnull(r.freasoncd,'') as ftimecode,d.fexamdate, 
        ifnull(date_format(ifnull(md.fdate, ''),'%d/%m/%Y'),'') as fdate, 
        ifnull(r.fdescpn,'') as ftime
        from subject s inner join degree d on s.fdegree = d.fdegree 
        and s.fexamno = d.fexamno 
        inner join timetable t on s.fqpcode = t.fqpcode 
        and t.fyear = d.fmeyear and d.fmeexamtyp = t.fexamtype
        inner join masdate md on t.fdatecodet = md.fdatecode 
        and md.fyear = d.fmeyear and d.fmeexamtyp = md.fexamtype
        and md.fyear = t.fyear and t.fexamtype = md.fexamtype
        and md.fdeggrp = t.fdeggrp
        left join reason r on t.fsessiont = r.freasoncd
        where d.fdeggrp = '{$deggrp}' 
        and	t.fdeggrp = '{$deggrp}'
        and md.fdeggrp ='{$deggrp}'
        and s.fexamno in('{$examrange}')
        and t.fyear = '{$fyear}' and t.fexamtype = '{$fexamtype}'
        and s.ftheory = 'T' and s.fintass <> 'T' and ifnull(s.fqpcode,'') <>''
        and ifnull(t.fdatecodet,'') <> ''
        group by s.fqpcode
        order by s.fdatecodet, s.fqpcode";
    }

    // var_dump($query);die();

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

    reportExamTimeTable($result, $aobj_context);


}