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


Current Path : /proc/thread-self/root/var/www/html/admission/src/
Upload File :
Current File : //proc/thread-self/root/var/www/html/admission/src/qpupload_240621.php

<?php

function uploadScriptStats($aobj_context)
{
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	session_start();
	require_once dirname(__FILE__) . '/../PHPExcel/Classes/PHPExcel/IOFactory.php';
    
    $univcode = $aobj_context->mobj_data["univcode"];
    $deggrp = $aobj_context->mobj_data["deggrp"];
    $filename = $aobj_context->mobj_data["gfilename"];

    $date = date("dmYhis");
    $folderpath = $aobj_context->main_src."/upload/"; 
    $temp_path = $aobj_context->main_src."/upload/".$filename;
    
	if(!file_exists($temp_path))
	{
		$data = "File is not uploaded and try again";
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
		return;
	}
	// var_dump($temp_path);
    $inputFileName = $temp_path;
    $inputFileType = 'Excel2007';
    
    ///////////////////// Code To convert xlsx to csv \\\\\\\\\\\\\
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcelReader = $objReader->load($inputFileName);

    $loadedSheetNames = $objPHPExcelReader->getSheetNames();

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');
    $i = 0;
    // var_dump($loadedSheetNames);
    foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) 
    {
        if($i != 0)
            break;
        $objWriter->setSheetIndex($sheetIndex);
        $csvFile = $folderpath.$date.$loadedSheetName.'.csv';
        $objWriter->setUseBOM(true);
        $objWriter->save($csvFile);

        $table_name = "masqp_{$univcode}";

        $drop_query = "DROP TABLE IF EXISTS {$table_name}";
        // var_dump($drop_query);
        $results = $aobj_context->mobj_db->Execute($drop_query);
        // var_dump($results);
        $create_query = "CREATE TABLE {$table_name} (
            `FQPCODE` varchar(5) NOT NULL,
            `FSUBNAME` varchar(100) DEFAULT NULL,
            `FMAXMARKS` int(3) DEFAULT NULL,
            `FDOE` date DEFAULT NULL,
            `FSESSION` varchar(2) DEFAULT NULL,
            `FENTTYPE` varchar(1) DEFAULT NULL,
            `FDEVMARK` int(3) DEFAULT NULL,
            `FNOVAL` int(3) DEFAULT NULL,
            `FDELETED` varchar(1) DEFAULT NULL,
            `fboard` varchar(5) DEFAULT NULL,
            `fspresent` int(5) DEFAULT NULL,
            `fapresent` int(5) DEFAULT NULL,
            `ftotpkt1` int(5) DEFAULT NULL,
            `fvalpkt1` int(5) DEFAULT NULL,
            `ftotpkt2` int(5) DEFAULT NULL,
            `fvalpkt2` int(5) DEFAULT NULL,
            `fcodecount` int(5) DEFAULT NULL,
            `fdeggrp` varchar(5) DEFAULT NULL,
            PRIMARY KEY (`FQPCODE`)
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1";
        
        $results = $aobj_context->mobj_db->Execute($create_query);
        
        //return;

        if($univcode == '027')
        {
        
            $query = "LOAD DATA LOCAL INFILE '{$csvFile}'
            INTO TABLE {$table_name}
            FIELDS TERMINATED BY \",\"
            OPTIONALLY ENCLOSED BY '\"' 
            LINES TERMINATED BY \"\n\" 
            IGNORE 1 LINES
            (fqpcode,fdoe,fsession,fsubname, @dummy, @dummy, @dummy, @dummy, 
            @dummy, @dummy, @dummy, fboard, @dummy, @dummy, @dummy, fspresent, 
            fapresent, fcodecount, @dummy, ftotpkt1, @dummy, @dummy, fvalpkt1,ftotpkt2, @dummy, 
            @dummy,fvalpkt2, @dummy, @dummy, @dummy, @dummy,@dummy, fdeggrp)";

        }else
        {
            $query = "LOAD DATA LOCAL INFILE '{$csvFile}'
            INTO TABLE {$table_name}
            FIELDS TERMINATED BY \",\"
            OPTIONALLY ENCLOSED BY '\"' 
            LINES TERMINATED BY \"\n\" 
            IGNORE 1 LINES
            (fqpcode,fdoe,fsession,fsubname, @dummy, @dummy, @dummy, @dummy, 
            @dummy, @dummy, @dummy, @dummy, @dummy, @dummy, fboard, @dummy, fspresent, 
            fapresent, fcodecount, ftotpkt1, @dummy, @dummy, fvalpkt1,ftotpkt2, @dummy, 
            @dummy,fvalpkt2, @dummy, @dummy, @dummy, @dummy,@dummy, fdeggrp)";
        }
        
        // var_dump($query);    
        $results = $aobj_context->mobj_db->Execute($query);
        
        // var_dump($results);
        $rows_affected = $aobj_context->mobj_db->affected_rows();
        
        // var_dump($rows_affected);
        // return;
        if(!$results)
        {
            $data = "Upload failure. Error while loading excel data to database";
            echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
            return;
        }
        // Delete All the blank values from table
        $query = "delete from {$table_name} where fqpcode = ''";
        $results = $aobj_context->mobj_db->Execute($query);
        
        $query = "select fdbname from dbname where funivcode = '{$univcode}'";
        $results = $aobj_context->mobj_db->GetRow($query);

        $db = $results['fdbname'];
        // var_dump($db);
        $query = "insert ignore into {$db}.masqp(fqpcode, fsubname, fboard, fspresent, fapresent, 
        ftotpkt1, fvalpkt1, fcodecount, fdeggrp,ftotpkt2,fvalpkt2)
        select fqpcode, fsubname, fboard, fspresent, fapresent, ftotpkt1, fvalpkt1, 
        fcodecount, fdeggrp,ftotpkt2,fvalpkt2 from {$table_name} where
        fcodecount >0 and ifnull(fcodecount,'') <> '' and fcodecount <> ''";
        
        $results = $aobj_context->mobj_db->Execute($query);
        // var_dump($results);
        $rows_affectedi = $aobj_context->mobj_db->affected_rows();
        $update_query = "update {$db}.masqp a, {$table_name} b
        set a.fboard = b.fboard,
        a.fspresent = b.fspresent,
        a.fapresent = b.fapresent,
        a.ftotpkt1 = b.ftotpkt1,
        a.fvalpkt1 = b.fvalpkt1,
        a.ftotpkt2 = b.ftotpkt2,
        a.fvalpkt2 = b.fvalpkt2,
        a.fcodecount = b.fcodecount,
        a.fdeggrp = b.fdeggrp
        where a.fqpcode = b.fqpcode and
        b.fcodecount >0
        and ifnull(b.fcodecount,'') <> '' and b.fcodecount <> ''";
        
        $results = $aobj_context->mobj_db->Execute($update_query);
        $rows_affectedu = $aobj_context->mobj_db->affected_rows();

        $query = "insert ignore into {$db}.masboard(fboardcode, fboardname)
        select distinct fboard,fboard from {$db}.masqp where ifnull(fboard,'') <> ''";
        $res = $aobj_context->mobj_db->Execute($query);
     
    }
    if($results)
    {
        $arr['msg'] = "Uploaded Successfully.";
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 
        return;	
    }
    else
    {
        $arr['msg'] = "Error while updating";
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"error"); 
        return;
    }
	
	
}