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


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/admsummmaryexcel.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);

    // 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_clean();
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
}


function admsummmaryexcel($aobj_context)
{

    $objPHPExcel = new PHPExcel();
    $fileName = 'admsummmaryexcel';
    $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);
    
    /*$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);
    $univcode = $aobj_context->mobj_data["univcode"]; 
    $deggrp = $aobj_context->mobj_data["deggrp"];
    $fdegfrom =$aobj_context->mobj_data["fdegfrom"];     
    $fdegto =$aobj_context->mobj_data["fdegto"];  
   // $fcollfrom =$aobj_context->mobj_data["fcollfrom"];
   // $fcollto =$aobj_context->mobj_data["fcollto"]; 
    $query = "select degree.fdegree ,degree.fdescpn  ,
    sum(case when fcaste='GM'  and fgender='M' then 1 else 0 end) as GM_male, 
    sum(case when fcaste='GM'  and fgender='F' then 1 else 0 end) as GM_female, 
    sum(case when fcaste='IIA' and fgender='M' then 1 else 0 end) as IIA_male, 
    sum(case when fcaste='IIA' and fgender='F' then 1 else 0 end) as IIA_female, 
    sum(case when fcaste='IIB' and fgender='M' then 1 else 0 end) as IIB_male, 
    sum(case when fcaste='IIB' and fgender='F' then 1 else 0 end) as IIB_female, 
    sum(case when fcaste='IIIA' and fgender='M' then 1 else 0 end) as IIIA_male, 
    sum(case when fcaste='IIIA' and fgender='F' then 1 else 0 end) as IIIA_female, 
    sum(case when fcaste='IIIB' and fgender='M' then 1 else 0 end) as IIIB_male, 
    sum(case when fcaste='IIIB' and fgender='F' then 1 else 0 end) as IIIB_female, 
    sum(case when fcaste='SC' and fgender='M' then 1 else 0 end) as SC_male, 
    sum(case when fcaste='SC' and fgender='F' then 1 else 0 end) as SC_female, 
    sum(case when fcaste='ST' and fgender='M' then 1 else 0 end) as ST_male, 
    sum(case when fcaste='ST' and fgender='F' then 1 else 0 end) as ST_female, 
    sum(case when fcaste='CAT-I' and fgender='M' then 1 else 0 end) as `CAT-I_male`, 
    sum(case when fcaste='CAT-I' and fgender='F' then 1 else 0 end) as `CAT-I_female`, 
    count(*) as totadm
    from studadm, degree where studadm.fdegree = degree.fdegree and 
    ifnull(studadm.fdeleted,'')<>'T' and studadm.fexamno='a' and 
    degree.fdeggrp='{$deggrp}' 
    and studadm.fdegree between '{$fdegfrom}' and '{$fdegto}'
    group by studadm.fdegree";
    $results = $aobj_context->pobj_db->GetAll($query);
/*var_dump($query);
var_dump($results);
die();*/
    /*$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'];

    $deggrp = $aobj_context->mobj_data["dgp"] . ' - ' . $results['fexamdate'];

    $objPHPExcel->getActiveSheet()->getHeaderFooter()
    ->setOddHeader('&C&H&"-,Bold"&16' . $aobj_context->FUNIVNAME . "\n" . '&12' . 
    ' - ' . $deggrp);

    $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'),
            ),
        ),
    );

  $cat = ['CAT-I', 'GM', 'IIA', 'IIB', 'IIIA', 'IIIB', 'SC', 'ST'];

    $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()->getStyle('1:2')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('1:2')->getFont()->setSize(13);
    $objPHPExcel->getActiveSheet()->freezePane('D3');

    $objPHPExcel->getActiveSheet()->mergeCells('A1:A2')->setCellValue('A1', 'Sl. No.');
    $objPHPExcel->getActiveSheet()->mergeCells('B1:B2')
        ->setCellValue('B1', 'Degree');
    $objPHPExcel->getActiveSheet()->mergeCells('C1:C2')
        ->setCellValue('C1', 'Description');


    $j = 3;
    for($i = 0; $i < count($cat);$i++) {
        $objPHPExcel->getActiveSheet()->mergeCells($alpha[$j].'1:'.$alpha[$j+2].'1')
        ->setCellValue($alpha[$j].'1', $cat[$i]);
        $j += 3;
    }
    $objPHPExcel->getActiveSheet()->mergeCells($alpha[$j].'1:'.$alpha[$j+2].'1')
        ->setCellValue($alpha[$j].'1', "Total");
    $j = 3;
    for($i = 0; $i < count($cat);$i++) {
        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$j].'2', "Male");
        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$j+1].'2', "Female");
        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$j+2].'2', "Total");
        $j += 3;
    }

    $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$j].'2', "Male");
        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$j+1].'2', "Female");
        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$j+2].'2', "Total");
    // die();
    
    $objPHPExcel->getActiveSheet()->getStyle('A1:AD2')->applyFromArray($styleArray);
    // $objPHPExcel->getActiveSheet()->getColumnDimension('G1')->setAutoSize(true);
    $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);
    $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
    $objPHPExcel->getActiveSheet()->getStyle('A1:AD2')->getAlignment()->setWrapText(true);
    $objPHPExcel->getActiveSheet()->getStyle('A1:AD2')->getAlignment()
                ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('A1:AD2')->getAlignment()
                ->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    $j = 3;
    $slNo = 1;
    $sum = array();

    foreach ($results as $key => $value) {
        
        $objPHPExcel->getActiveSheet()->setCellValue('A' .$j, $slNo)
        ->getColumnDimension('A')->setwidth(5);

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

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

        $i = 3;
        $mc = 0;
        $fc = 0;
        $tc = 0;
        
        foreach($cat as $v) {
            $objPHPExcel->getActiveSheet()
            ->setCellValue($alpha[$i].$j, $value[$v.'_male']);

            $objPHPExcel->getActiveSheet()
            ->setCellValue($alpha[$i+1].$j, $value[$v.'_female']);

            $objPHPExcel->getActiveSheet()
            ->setCellValue($alpha[$i+2].$j, $value[$v.'_male']+ $value[$v.'_female']);

            $mc += $value[$v.'_male'];
            $fc += $value[$v.'_female'];
            $tc += $value[$v.'_female'] + $value[$v.'_male'];

            $sum[$v.'_male'] += $value[$v.'_male'];
            $sum[$v.'_female'] += $value[$v.'_female'];
            $sum['totadm'.$v] += $value[$v.'_female'] + $value[$v.'_male'];
            $i += 3;
        }

        $objPHPExcel->getActiveSheet()->getStyle($alpha[$i].$j.':'.$alpha[$i+2].$j)->getFont()->setBold(true);
        
        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$i].$j, $mc);

        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$i+1].$j, $fc);

        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$i+2].$j, $tc);
        
        $objPHPExcel->getActiveSheet()->getRowDimension($j)->setRowHeight(26);
        $j++;$slNo++;
    }

    $objPHPExcel->getActiveSheet()->getRowDimension($j)->setRowHeight(26);
    $objPHPExcel->getActiveSheet()->getStyle($j)->getFont()->setBold(true);
    
    $objPHPExcel->getActiveSheet()->mergeCells('A'.$j.':C'.$j)
        ->setCellValue('A'.$j, "Total");

    $i = 3;

    $mc = 0;
    $fc = 0;
    $tc = 0;
    
    foreach($cat as $v) {
        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$i].$j, $sum[$v.'_male']);

        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$i+1].$j, $sum[$v.'_female']);

        $objPHPExcel->getActiveSheet()
        ->setCellValue($alpha[$i+2].$j, $sum[$v.'_female']+ $sum[$v.'_male']);

        $mc += $sum[$v.'_male'];
        $fc += $sum[$v.'_female'];
        $tc += $sum[$v.'_female'] + $sum[$v.'_male'];   
        $i += 3;
    }

    $objPHPExcel->getActiveSheet()
    ->setCellValue($alpha[$i].$j, $mc);

    $objPHPExcel->getActiveSheet()
    ->setCellValue($alpha[$i+1].$j, $fc);
    
    $objPHPExcel->getActiveSheet()
    ->setCellValue($alpha[$i+2].$j, $tc);


    $objPHPExcel->getActiveSheet()->getStyle('A3' . ':AD' . $j)->applyFromArray($styleArray);

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

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

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

    $objPHPExcel->getActiveSheet()->getStyle('A3' . ':AD' . $j)->getAlignment()
    ->setWrapText(true);


    getheaders($objPHPExcel, $fileName);
}