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


Current Path : /proc/thread-self/root/proc/thread-self/root/var/www/oasis/src/
Upload File :
Current File : //proc/thread-self/root/proc/thread-self/root/var/www/oasis/src/uploadcopo.php

<?php
    function getElementWiseDegree($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $collcode = $_SESSION['collcode'];
        $element = $aobj_context->mobj_data["element"];

        if($element==='theroy'){
            $cond="and ifnull(fintass, '')<>'T' and ifnull(fretain, '')<>'T'";
        }else{
            $cond="and ifnull(fintass, '')='T' and ifnull(fretain, '')='T'";
        }

        $query = "select distinct ifnull(d.fdegree , '') as fdegree, 
                  concat(d.fdegree,' - ',ifnull(d.fdescpn , '')) as fdescpn 
                  from degree d
                  inner join subject s on d.fdegree = s.fdegree
                  and d.fexamno = s.fexamno 
                  inner join colldeg c on c.fdegree = d.fdegree
                  where ifnull(d.FDEGREE , '') <> '' and c.fcollcode='{$collcode}'
                  {$cond}";
        $result = $aobj_context->mobj_db->GetAll($query);

        if($result){
            echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "success");
        }else{
            $arr['msg']='Something Went Wrong..!';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
        }
    }

    function getDegreeWiseExamno($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $collcode = $_SESSION['collcode'];
        $degree = $aobj_context->mobj_data["degree"];

        $query = "select distinct ifnull(FEXAMNO , '') as fexamno,ifnull(FEXAMNAME , '') as fexamname from degree
                  where FDEGREE = '{$degree}'";
        $result = $aobj_context->mobj_db->GetAll($query);

        if($result){
            echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "success");
        }else{
            $arr['msg']='Something Went Wrong..!';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
        }
    }

    function getDegreeExamWiseSubject($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $collcode = $_SESSION['collcode'];
        $element = $aobj_context->mobj_data["element"];
        $degree = $aobj_context->mobj_data["degree"];
        $examno = $aobj_context->mobj_data["examno"];

         if($element === 'theory'){
           $cond = "ifnull(FQPCODE , '') as fqpcode,concat(s.fqpcode,' - ',ifnull(s.FSUBNAME, '')) as fsubname";
           $condEle = "and FQPCODE <> ''";
        }else {
            $cond = "ifnull(FCSUBCODE , '') as fqpcode,  concat(ifnull(FSUBNAME, ''),' - ',fssubname) as fsubname";
            $condEle = "and fretain = 'T'";
        }

        $query = "select distinct {$cond} from subject s
                  where FDEGREE = '{$degree}' and FEXAMNO = '{$examno}' 
                  {$condEle}";
        $result = $aobj_context->mobj_db->GetAll($query);

        if($result){
            echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "success");
        }else{
            $arr['msg']='Something Went Wrong..!';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
        }
    }

    function uploadcopodoc($aobj_context){
        require_once dirname(__FILE__) . '/../PHPExcel/Classes/PHPExcel/IOFactory.php';
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $collcode = $_SESSION['collcode'];
        $element = $aobj_context->mobj_data["element"];
        $degree = $aobj_context->mobj_data["degree"];
        $examno = $aobj_context->mobj_data["examno"];
        $subject = $aobj_context->mobj_data["subject"];
        $file = $_FILES['file']['tmp_name'];
        $file_name = $_FILES['file']['name'];
        $ext = pathinfo($file_name, PATHINFO_EXTENSION);
        $date = date("dmYhis");

        $folderpath = $aobj_context->main_src."copodoc/";
        $temp_path = $aobj_context->main_src."copodoc/";

        if(!file_exists($temp_path)){
		    mkdir($temp_path);
	    }

        if($collcode == ''){
            $data = "Please login and try again";
            echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
            return;
	    }

        if($ext != 'xlsx'){
			$data="Please Upload file xlsx format only";
			echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
			return;
		}
        
        $filename = $collcode."_".$element."_".$degree."_".$examno."_".$subject.".".$ext;
        
        if($_FILES['file']['name'] !== NULL){
            move_uploaded_file($file, 'copodoc/'. $filename);  
            $file = $aobj_context->main_src.'copodoc/'.$filename;

            if(!file_exists($file)){
                $data = "Upload failure. Upload file does not exist";
				echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
				return;
            }else{
                $inputFileName = $file;
			    $inputFileType = 'Excel2007';

                $objReader = PHPExcel_IOFactory::createReader($inputFileType);
			    $objPHPExcelReader = $objReader->load($inputFileName);
                $loadedSheetNames = $objPHPExcelReader->getSheetNames();
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');
                $i = 0;
                foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
                    $objWriter->setSheetIndex($sheetIndex);
                    $csvFile = $folderpath.$date.$loadedSheetName.'.csv';
                    $objWriter->setUseBOM(true);
                    $objWriter->save($csvFile);
                    $query = "LOAD DATA LOCAL INFILE '{$csvFile}'
                              INTO TABLE tdvs_copomarks
                              FIELDS TERMINATED BY \",\"
                              OPTIONALLY ENCLOSED BY '\"' 
                              LINES TERMINATED BY \"\n\" 
                              IGNORE 1 LINES
                              (@col1,@col2,@col3,@col4,@col5,@col6,@col7,@col8,@col9,@col10,
                               @col11,@col12,@col13,@col14,@col15,@col16,@col17,@col18,@col19,@col20,
                               @col21,@col22,@col23,@col24,@col25,@col26,@col27,@col28,@col29,@col30,
                               @col31,@col32,@col33,@col34,@col35,@col36,@col37,@col38,@col39,@col40,
                               @col41,@col42,@col43,@col44,@col45,@col46,@col47,@col48,@col49,@col50,
                               @col51) set
                              fregno=@col1,fteachcode=@col2,fvalno=@col3,fcollcode='{$collcode}',fdegree='{$degree}',
                              fexamno='{$examno}',fsubcode='{$subject}',fyear=@col4,fexamtype=@col5, 
                              ftotmarks=@col6,fq1a=@col7,fq1b=@col8,fq1c=@col9,fq1d=@col10,fq1e=@col11,
                              fq2a=@col12,fq2b=@col13,fq2c=@col14,fq2d=@col15,fq2e=@col16,
                              fq3a=@col17,fq3b=@col18,fq3c=@col19,fq3d=@col20,fq3e=@col21,
                              fq4a=@col22,fq4b=@col23,fq4c=@col24,fq4d=@col25,fq4e=@col26,	
                              fq5a=@col27,fq5b=@col28,fq5c=@col29,fq5d=@col30,fq5e=@col31,
                              fq6a=@col32,fq6b=@col33,fq6c=@col34,fq6d=@col35,fq6e=@col36,
                              fq7a=@col37,fq7b=@col38,fq7c=@col39,fq7d=@col40,fq7e=@col41,
                              fq8a=@col42,fq8b=@col43,fq8c=@col44,fq8d=@col45,fq8e=@col46,	
                              fq9a=@col47,fq9b=@col48,fq9c=@col49,fq9d=@col50,fq9e=@col51";
                    $result = $aobj_context->mobj_db->Execute($query);
                    if(!$result){
						$data = "Upload failure. Error while loading excel data to database";
						echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
						return;
					}else{
                        unlink($file);
                        unlink($csvFile);
                        $data = "Upload success";
						echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success"); 
						return;
                    }
                    
                }
            }
            
        }    
    }



?>