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


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

<?php

$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);
ini_set('max_execution_time', 300);
    ini_set('memory_limit', '512M');
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(true);

    // Redirect output to a client’s web browser (Excel5)
    

    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="' . $fileName . '.CSV"');
    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_clean();
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
    $objWriter->save('php://output');
}


function MPEXCEL($aobj_context)
{

    $objPHPExcel = new PHPExcel();
    $univcode = $aobj_context->mobj_data["univcode"];
    $fileName = 'MAL-PRACTICE';
    $objPHPExcel->getProperties()->setCreator("Me")
        ->setLastModifiedBy("Me")->setTitle("My Excel Sheet")
        ->setSubject("My Excel Sheet")->setDescription("Excel Sheet")
        ->setKeywords("Excel Sheet")->setCategory("Me");

    // 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_LANDSCAPE);

    $alpha = [
        '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', 'AF', 'AE', 'AF', 'AG', 'AH'
    ];


    $objPHPExcel->getActiveSheet()
        ->setCellValue('A1', 'EXAM DATE')
        ->setCellValue('B1', 'EXAM SESSION')
        ->setCellValue('C1', 'School Code')
        ->setCellValue('D1', 'School Name')
        ->setCellValue('E1', 'Program Code')
        ->setCellValue('F1', 'USN')
        ->setCellValue('G1', 'Student Name')
        ->setCellValue('H1', 'QPCODE')
        ->setCellValue('I1', 'COURSE NAME')
        ->setCellValue('J1', 'ENTERED BY');

    $j = 3;
    $slNo = 1;
    $sum = array();
    
    $fdatefrom = $aobj_context->mobj_data["vdatefrom"];
    $fdateto = $aobj_context->mobj_data["vdateto"];
    $clgfrom = $aobj_context->mobj_data["clgfrom"];
    $clgto = $aobj_context->mobj_data["clgto"];
    $qpfrom = $aobj_context->mobj_data["qpfrom"];
    $qpto = $aobj_context->mobj_data["qpto"];

if($univcode == '051'){

    $query = "SELECT a.fcollcode AS COLLCODE, c.fcollname AS COLLNAME,s.fdegree AS DEGREE, a.fregno AS USN, s.fname AS STUDNAME, 
    DATE_FORMAT(a.fdoe, '%d/%m/%Y') AS fdoe  , a.fqpcode AS QP, 
    concat('Sem' ,' : ' , sb.fexamno ,' - ', sb.fsubname,' ( ', sb.fsubshort, ' )')  AS SUBNAME , a.fsession AS SESSION, a.flogname AS LOGNAME  
    FROM absent a 
    INNER JOIN college c ON a.fcollcode = c.fcollcode
    INNER JOIN student s ON a.fregno = s.fregno AND a.fcollcode = s.fcollcode
    INNER JOIN subject sb ON s.fdegree = sb.fdegree AND sb.fqpcode = a.fqpcode 
    WHERE a.fabstype = 'QpM' 
    AND a.fcollcode BETWEEN '{$clgfrom}' AND '{$clgto}'
    AND a.fqpcode BETWEEN '{$qpfrom}' AND '{$qpto}'
    AND a.fdoe BETWEEN DATE_FORMAT(STR_TO_DATE('{$fdatefrom}','%d/%m/%Y'),'%Y-%m-%d') AND
    DATE_FORMAT(STR_TO_DATE('{$fdateto}','%d/%m/%Y'),'%Y-%m-%d')
    union 
    SELECT a.fcollcode AS COLLCODE, c.fcollname AS COLLNAME,s.fdegree AS DEGREE, a.fregno AS USN, s.fname AS STUDNAME, 
    DATE_FORMAT(a.fdoe, '%d/%m/%Y') AS fdoe  , a.fqpcode AS QP, 
    concat('Sem' ,' : ' , sb.fexamno ,' - ', sb.fsubname,' ( ', sb.fsubshort, ' )')  AS SUBNAME, a.fsession AS SESSION, a.flogname AS LOGNAME  
    FROM logisys3_dypatil_bkp.absent a 
    INNER JOIN college c ON a.fcollcode = c.fcollcode
    INNER JOIN student s ON a.fregno = s.fregno AND a.fcollcode = s.fcollcode
    INNER JOIN subject sb ON s.fdegree = sb.fdegree AND sb.fqpcode = a.fqpcode 
    WHERE a.fabstype = 'QpM' 
    AND a.fcollcode BETWEEN '{$clgfrom}' AND '{$clgto}'
    AND a.fqpcode BETWEEN '{$qpfrom}' AND '{$qpto}'
    AND a.fdoe BETWEEN DATE_FORMAT(STR_TO_DATE('{$fdatefrom}','%d/%m/%Y'),'%Y-%m-%d') AND
    DATE_FORMAT(STR_TO_DATE('{$fdateto}','%d/%m/%Y'),'%Y-%m-%d')
    ORDER BY fdoe";

  }  
  else if($univcode == '030')
  {
    $query = "SELECT a.fcollcode AS COLLCODE, c.fcollname AS COLLNAME,s.fdegree AS DEGREE, a.fregno AS USN, s.fname AS STUDNAME, 
    DATE_FORMAT(a.fdoe, '%d/%m/%Y') AS fdoe  , a.fqpcode AS QP, 
    concat('Sem' ,' : ' , sb.fexamno ,' - ', sb.fsubname,' ( ', sb.fsubshort, ' )')  AS SUBNAME , a.fsession AS SESSION, a.flogname AS LOGNAME  
    FROM absent a 
    INNER JOIN college c ON a.fcollcode = c.fcollcode
    INNER JOIN student s ON a.fregno = s.fregno AND a.fcollcode = s.fcollcode
    INNER JOIN subject sb ON s.fdegree = sb.fdegree AND sb.fqpcode = a.fqpcode
    INNER JOIN timetable tb ON  tb.fqpcode = a.fqpcode  
    WHERE a.fabstype = 'QpM' 
    AND a.fcollcode BETWEEN '{$clgfrom}' AND '{$clgto}'
    AND a.fqpcode BETWEEN '{$qpfrom}' AND '{$qpto}'
    AND a.fdoe BETWEEN DATE_FORMAT(STR_TO_DATE('{$fdatefrom}','%d/%m/%Y'),'%Y-%m-%d') AND
    DATE_FORMAT(STR_TO_DATE('{$fdateto}','%d/%m/%Y'),'%Y-%m-%d')
    union 
    SELECT a.fcollcode AS COLLCODE, c.fcollname AS COLLNAME,s.fdegree AS DEGREE, a.fregno AS USN, s.fname AS STUDNAME, 
    DATE_FORMAT(a.fdoe, '%d/%m/%Y') AS fdoe  , a.fqpcode AS QP, 
    concat('Sem' ,' : ' , sb.fexamno ,' - ', sb.fsubname,' ( ', sb.fsubshort, ' )')  AS SUBNAME, a.fsession AS SESSION, a.flogname AS LOGNAME  
    FROM logisys3_reva_bkp.absent a 
    INNER JOIN college c ON a.fcollcode = c.fcollcode
    INNER JOIN student s ON a.fregno = s.fregno AND a.fcollcode = s.fcollcode
    INNER JOIN subject sb ON s.fdegree = sb.fdegree AND sb.fqpcode = a.fqpcode 
    INNER JOIN timetable tb ON  tb.fqpcode = a.fqpcode 
    WHERE a.fabstype = 'QpM' 
    AND a.fcollcode BETWEEN '{$clgfrom}' AND '{$clgto}'
    AND a.fqpcode BETWEEN '{$qpfrom}' AND '{$qpto}'
    AND a.fdoe BETWEEN DATE_FORMAT(STR_TO_DATE('{$fdatefrom}','%d/%m/%Y'),'%Y-%m-%d') AND
    DATE_FORMAT(STR_TO_DATE('{$fdateto}','%d/%m/%Y'),'%Y-%m-%d')
    ORDER BY fdoe";
    
}

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

    $i = 2;
	$totamt=0;
    foreach ($result as $key => $value) {
        

        $objPHPExcel->getActiveSheet()
            ->setCellValue('A' . $i, $value["fdoe"]);
        $objPHPExcel->getActiveSheet()
             ->setCellValue('B' . $i, $value["SESSION"]);
        $objPHPExcel->getActiveSheet()
           ->setCellValue('C' . $i, $value["COLLCODE"]);
        $objPHPExcel->getActiveSheet()
            ->setCellValue('D' . $i, $value["COLLNAME"]);
        $objPHPExcel->getActiveSheet()
            ->setCellValue('E' . $i, $value["DEGREE"]);
        $objPHPExcel->getActiveSheet()
            ->setCellValue('F' . $i, $value["USN"]);
        $objPHPExcel->getActiveSheet()
            ->setCellValue('G' . $i, $value['STUDNAME']);
        $objPHPExcel->getActiveSheet()
            ->setCellValue('H' . $i, $value["QP"]);
        $objPHPExcel->getActiveSheet()
            ->setCellValue('I' . $i, $value["SUBNAME"]);
        $objPHPExcel->getActiveSheet()
            ->setCellValue('J' . $i, $value["LOGNAME"]);
        $i++;
    }

    getheaders($objPHPExcel, $fileName);
}