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.141.21.106
<?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 uploadbackup($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
session_start();
$univcode = $aobj_context->mobj_data["univcode"];
$date = $aobj_context->mobj_data["date"];
$type = $aobj_context->mobj_data["type"];
$title = $aobj_context->mobj_data["title"];
$desc = $aobj_context->mobj_data["desc"];
$user = $aobj_context->mobj_data["user"];
$filename = $aobj_context->mobj_data["gfilename"];
if($filename){
$s3 = S3Client::factory(
array(
'credentials' => array(
'key' => IAM_KEY,
'secret' => IAM_SECRET
),
'version' => "latest",
'region' => 'ap-south-1'
)
);
if($filename != '' && $filename != NULL)
{
$fpath = $aobj_context->main_src."upload_backup/{$filename}";
$file = $univcode."/Backup/".$filename;
if(file_exists($fpath))
{
try {
$s3->putObject(['Bucket' => "takshila-backup", 'Key' => $file, 'SourceFile' => $fpath]);
$insert = "insert into logisys3_comexam.backups(fdate, ftype, ftitle, ffilepath, fdescription,fupddate,fupduser,funivcode,fdeleted) values
(date_format(str_to_date('{$date}','%d/%m/%Y'),'%Y-%m-%d'),'{$type}', '{$title}','{$file}','{$desc}',now(),'{$user}','{$univcode}','F')";
$up_obj=$aobj_context->pobj_db->Execute($insert);
if($up_obj){
$arr['msg']="Uploaded Successfully";
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
unlink($fpath);
return;
}
}catch(S3Exception $e) {
$arr['message'] = 'Unable to upload file';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
}
}
}
}
function viewBackup($aobj_context){
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$univcode = $aobj_context->mobj_data["univcode"];
$datefrm = $aobj_context->mobj_data["datefrm"];
$dateto = $aobj_context->mobj_data["dateto"];
$type = $aobj_context->mobj_data["type"];
$university = $aobj_context->mobj_data["university"];
if($type == 'all'){
$cnd = "";
}else{
$cnd = "and ftype = '{$type}'";
}
$query = "select ifnull(date_format(fdate,'%d/%m/%Y'),'') as fdate,
ifnull(ftype,'')as ftype, ifnull(fdescription,'')as fdesc,
ifnull(ftitle,'')as ftitle, ifnull(fupduser,'')as fuser,
ifnull(ffilepath,'')as filepath, ifnull(funivcode, '')as funivcode,
ifnull(fid,'')as fid from logisys3_comexam.backups where
fdate between DATE_FORMAT(STR_TO_DATE('{$datefrm}', '%d/%m/%Y'),'%Y-%m-%d')
and DATE_FORMAT(STR_TO_DATE('{$dateto}', '%d/%m/%Y'),'%Y-%m-%d')
and funivcode = '{$university}' and fdeleted <> 'T'
$cnd";
$result = $aobj_context->pobj_db->GetAll($query);
if($result){
$arr['data']=$result;
$arr['error_code']=0;
$arr['msg']='success';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
return;
}else{
$arr['msg'] = "No data found";
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
}
function deleteFile($aobj_context){
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$univcode = $aobj_context->mobj_data["univcode"];
$file = $aobj_context->mobj_data["file"];
$university = $aobj_context->mobj_data["university"];
$id = $aobj_context->mobj_data["id"];
$query = "update logisys3_comexam.backups set fdeleted = 'T' where fid = '{$id}' and funivcode = '{$university}'";
$result = $aobj_context->pobj_db->Execute($query);
if($result){
echo $aobj_context->mobj_output->ToJSONEnvelope($result,0,"success");
return;
}else{
$arr['msg'] = "Failed to delete";
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
}
function getUploadUnivs($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$univcode = $aobj_context->mobj_data["univcode"];
$query ="select distinct funivcode ,funivname
from logisys3_empty.masuniv";
$result=$aobj_context->pobj_db->GetAll($query);
if($result && count($result)>1){
echo $aobj_context->mobj_output->TOJSONEnvelope($result,0,"success");
}
else{
$arr['msg']="Please try later";
echo $aobj_context->mobj_output->TOJSONEnvelope($arr,-1,"failed");
}
}
?>
|