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


Current Path : /var/www/html/admission/src/
Upload File :
Current File : /var/www/html/admission/src/uploadSSPData.php

<?php

function uploadSSPData($aobj_context){

    ini_set('max_execution_time', 600);
  
      $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"];
    $filename = $aobj_context->mobj_data["gfilename"];
  
    $date = date("dmYhis");
    $folderpath = $aobj_context->main_src."SSPData/".$univcode.'/'; 
//   var_dump($folderpath);
    $temp_path = $aobj_context->main_src."upload/".$filename;
  
    
  
      if(!file_exists($temp_path))
      {
          $data = "Please login and try again";
          echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
          return;
      }
    // var_dump($temp_path);
    if(!file_exists($folderpath))
    {
        mkdir($folderpath , 0777, true);
    }
    $inputFileName = $temp_path;
    $inputFileType = 'Excel2007';

    ///////////////////// Code To convert xlsx to csv \\\\\\\\\\\\\
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcelReader = $objReader->load($inputFileName);
  
    $loadedSheetNames = $objPHPExcelReader->getSheetNames();
  // var_dump($loadedSheetNames);
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');
  
    $i = 0;
    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 = "sspdata_{$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} (
          `University_Code` varchar(13) NOT NULL,
          `University_Name` varchar(100) DEFAULT NULL,
          `Registration_Number` varchar(100) DEFAULT NULL,
          `Academic_Year` varchar(200) DEFAULT NULL,
          `Student_Name` varchar(200) DEFAULT NULL,
          `UG_PG` varchar(200) DEFAULT NULL,
          PRIMARY KEY (`Registration_Number`)
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1";
      //var_dump($create_query);
      // var_dump($csvfile);
  
      $results = $aobj_context->mobj_db->Execute($create_query);
      //return;
      $query = "LOAD DATA LOCAL INFILE '{$csvFile}'
      INTO TABLE {$table_name}
      FIELDS TERMINATED BY \",\"
      OPTIONALLY ENCLOSED BY '\"' 
      LINES TERMINATED BY '\n' 
      (University_Code,University_Name,Registration_Number, Academic_Year,Student_Name,UG_PG)";
      // 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);
      
      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 Registration_Number IN ('','Registration_Number')";
      
      $results = $aobj_context->mobj_db->Execute($query);
      
      $query = "select fdbname,ffolder from dbname where funivcode = '{$univcode}'";
      $results = $aobj_context->mobj_db->GetRow($query);
  
      $db = $results['fdbname'];
      $univshort = $results['ffolder'];
      // var_dump($db);
      $qpdelt = "delete from ssp_admdata where funivcode = '{$univcode}' and ifnull(finserted,'') <> 'T'";
      $res = $aobj_context->mobj_db->Execute($qpdelt);

      $query = "INSERT IGNORE INTO ssp_admdata(Academic_Year_code,University_Name,University_SSP_Code,University_Registration_Number,STUDENT_NAME,fdeggrp,funivcode)
      SELECT Academic_Year,University_Name,University_Code,Registration_Number,Student_Name,UG_PG ,'{$univcode}'
      FROM {$table_name}";
     
// var_dump($query);

      $results = $aobj_context->mobj_db->Execute($query);
      
      $rows_affectedi = $aobj_context->mobj_db->affected_rows();
  
    }
  
    if($results)
    {
      $data = "Uploaded Pushed";
      echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success"); 
      return;	
    }
    else
    {
      $data = "Error while updating";
      echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"error"); 
      return;
    }
  }





function loadsspadmpush($aobj_context){

  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
  

  $univcode = $aobj_context->mobj_data["univcode"];
  //var_dump($univcode);
  //die();
  $query = "select distinct FSSPCODE,FSSPKEY  
  from logisys3_comexam.dbname
  where funivcode  = '{$univcode}'";
  $result3 = $aobj_context->mobj_db->GetRow($query);
  $univsspcode = $result3['FSSPCODE'];
  
  if($result3)
  {
    
  }
  else
  {
    $data = "SSP Uni. Code not found contact admin";
    echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"error"); 
    return;
  }


  $query = "select distinct University_Name, University_SSP_Code, 
  sum(if(ifnull(finserted,'F') = 'F',1,0)) as not_pushed,
  sum(if(ifnull(finserted,'F') = 'T',1,0)) as pushed,
  count(*) as tot
      from logisys3_comexam.ssp_admdata
      where University_SSP_Code  = '{$univsspcode}'";
  // var_dump($query);
  // die();
  $result = $aobj_context->mobj_db->GetRow($query);
  
  if($result)
  {
    $data = "Uploaded Pushed";
      echo $aobj_context->mobj_output->ToJSONEnvelope($result,0,"success"); 
      return;	
  }
  else
  {
    $data = "No Details uploaded.";
    echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"error"); 
    return;
  }

}


?>