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 : 52.14.223.136


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

<?php

//require_once("/Library/WebServer/Documents/oasis/aws/aws-autoloader.php");
require_once("/var/www/html/aws/aws-autoloader.php");
// require_once("C:/XAMPP/htdocs/aws/aws-autoloader.php");
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;


function saveuplcorrdoc($aobj_context){
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
  $type=$aobj_context->mobj_data["type"];
  $remarks=$aobj_context->mobj_data["remarks"];
  $univcode = $aobj_context->mobj_data['univcode'];

   $query="insert into corrdoc (ftype,fremarks,fdocpath,fdate)
   values ('{$type}','{$remarks}','',now())";
     $result = $aobj_context->pobj_db->Execute($query);
     $id = $aobj_context->pobj_db->Insert_ID();
  if($result){
      $qry = "select ifnull(fid,'') as fid,ifnull(ftype,'') as ftype,ifnull(fremarks,'') as fremarks
      from corrdoc where fid = '{$id}'";
      $res = $aobj_context->pobj_db->GetRow($qry);
    echo $aobj_context->mobj_output->ToJSONEnvelope($res, 0, "success");
  }
  else{
    $arr['msg']="Failed to Save";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
  }
}


function uploadcorrdoc  ($aobj_context){
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $univcode = $aobj_context->mobj_data['univcode'];
    $gfilename = $aobj_context->mobj_data['gfilename'];
    $remarks = $aobj_context->mobj_data['remarks'];
    $type = $aobj_context->mobj_data['type'];
    $fid = $aobj_context->mobj_data['fid'];


    // var_dump($gfilename);
    // die();

    if($gfilename){
        $s3 = S3Client::factory(
            array(
                'credentials' => array(
                    'key' => IAM_KEY,
                    'secret' => IAM_SECRET
                ),
                'version' => "latest",
                'region'  => 'ap-south-1'
            )
        );
        
        // $query = "select funivcode from control";
        // $results = $aobj_context->mobj_db->GetRow($query);
        // var_dump($results);
        // die();

        // $funivcode = $results['funivcode'];
        
        if($gfilename != '' && $gfilename != NULL)
        {
            $server_path = $aobj_context->main_src."upload/{$gfilename}";  
            
            $filename = explode(".", $gfilename);
          $ext = strtolower($filename[1]);
            
            $docpath = $univcode."/correction_doc/".$fid.'.'.$ext;

            if(file_exists($server_path)) 
            {
                try {
                    $s3->putObject(['Bucket' => CORRECTION_DOCUMENT, 'Key' => $docpath, 'SourceFile' => $server_path]);
                    $update="update corrdoc set fdocpath = '{$docpath}'
                    where fid = '{$fid}'";
                    $up_obj=$aobj_context->pobj_db->Execute($update); 
                    
                    unlink($server_path);
                }catch(S3Exception $e) {
                    $arr['message'] = 'Unable to upload Document';
                    echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
                    return;
                }
            }
        }
    }

    if($up_obj){
      $arr['msg'] = "Uploaded Successfully...!";
      echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
    }
    else{
      $arr['msg']="Failed to Upload";
      echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    }
    
  
}

function viewuplcorrdoc($aobj_context){
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $type=$aobj_context->mobj_data["type"];
    $univcode = $aobj_context->mobj_data['univcode'];
  
     $query="select ifnull(fid,'') as fid,ifnull(ftype,'') as ftype,ifnull(fremarks,'') as fremarks,
     ifnull(fdocpath,'') as fdocpath,ifnull(date_format(fdate,'%d/%m/%Y'),'') as fdate 
     from corrdoc where ftype = '{$type}'";

    //  var_dump($query);
    //  die();
       $result = $aobj_context->pobj_db->GetAll($query);
       
    if($result){
      echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "success");
    }
    else{
      $arr['msg']="Failed to View";
      echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    }
  }
  










?>