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


Current Path : /var/www/html/univadmin/
Upload File :
Current File : /var/www/html/univadmin/upload-study-material.php

<?php

require_once(__DIR__."/../aws/aws-autoloader.php");
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
header("Access-Control-Allow-Origin: *");
header('Content-Type: multipart/form-data');
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, x-auth-origin, x-auth-token, x-auth-type");
$ds = DIRECTORY_SEPARATOR;
$date = date("dmYhis");
$file_resp = "";

if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { 
    die();
}
$req_body = file_get_contents('php://input');
$req_body = json_decode($req_body, true);
$body =$req_body;
$data  = $body["img64"];
$name  = $body["name"];
$univcode  = $body["univcode"];
$college  = $body["college"];
$fdegree  = $body["fdegree"];
$sem  = $body["sem"];
$subject  = $body["subject"];
$lesson  = $body["lesson"];
$tech  = $body["tech"];
$dept  = $body["dept"];

if($data=="" || $name == "" || $univcode == "") {
    $arr['msg'] = "Invalid Params";
    $arr['error_code'] = -1;
    echo json_encode($arr);
    die();
}


if (preg_match('/^data:image\/(\w+);base64,/', $data, $type)) {
    $file_name = $name;
    $data = substr($data, strpos($data, ',') + 1);
    $type = strtolower($type[1]); // jpg, png, gif

    if (!in_array($type, [ 'jpg', 'jpeg', 'png', 'pdf' ])) {
        $arr['msg'] = "Invalid Image formats";
        $arr['error_code'] = -1;
        echo json_encode($arr);
        die();
    }

    $data = base64_decode($data);

    if ($data === false) {
        $arr['msg'] = "base64_decode failed";
        $arr['error_code'] = -1;
        echo json_encode($arr);
        die();
    }

    $S3filepath = $univcode.'/'.$collcode.'_'.date('Y-m-d-H:i:s', time()).'-'.$file_name;
    $path = $collcode.'_'.date('Y-m-d-H:i:s', time()).'-'.$file_name;

    $s3 = S3Client::factory(
		array(
			'credentials' => array(
				'key' => IAM_KEY,
				'secret' => IAM_SECRET
			),
			'version' => "latest",
			'region'  => 'ap-south-1'
		)
    );

    $result = $s3->putObject([
        'Bucket' => STUDY_MATERIAL, 
        'Key' => $S3filepath, 
        'Body' => $data,
        'ContentType' => 'image/' . $type, 
    ]);

    $query = "insert into osmmain(fcollcode,FDEGREE,FEXAMNO,FSUBCODE,FCHAPTER,FPATH,FCREATEDATE,FUPDDEPT,FUPDTEACH,FAPPRSTATUS,FAPPRDATE)
         values('{$college}','{$fdegree}','{$sem}','{$subject}','{$lesson}','{$path}',now(),'{$dept}','{$tech}','approved',now())";

	$studresults = $aobj_context->mobj_db->Execute($query);


    $query = "select distinct d.fdescpn,s.fsubname,d.fexamname from degree d 
		inner join subject s on d.fdegree = s.fdegree
		and d.fexamno = s.fexamno
		where d.fdegree ='{$fdegree}' and d.fexamno = '{$sem}' and s.fsubcode = '{$subject}'";
		$res_sub = $aobj_context->mobj_db->GetRow($query);
		
		$degree_name = $res_sub['fdescpn'];
		$sub_name = $res_sub['fsubname'];
		$exam_name = $res_sub['fexamname'];

		$query = "insert ignore into logisys3_comexam.pushnotif(funivcode,fmobileno,fmobappid, fcollcode, fregno, fdegree, fenttype, fsubcode, ftitle, fbody, fstatus, fyear, fexamtype, fpushdate)
		select distinct '{$univcode}',m.fmobileno,m.FAPPMOBID,s.fcollcode, m.fregno, s.fdegree, '{$ID}', '{$ID}',  
					'Online Study Material Upload' as ftitle,
		concat('Dear Student, Study Material Upload for the Degree : ','$degree_name','; Semester : ', '$exam_name','; Subject : ','$sub_name','; chapter / lesson : ','$lesson','. visit Student Portal for more details') AS fmessage,
					'F', '2020', '1',NOW()
		 FROM student s 
						INNER JOIN logisys3_comexam.masuser m ON s.fregno = m.fregno 
		AND m.funivcode = '{$univcode}' and ifnull(fappmobid,'') <> ''
		where s.fcollcode = '{$college}' and s.fdegree = '{$fdegree}'";
		$res = $aobj_context->mobj_db->Execute($query);


    $arr['filename'] = $S3filepath;
    $arr['error_code'] = 0;
    $arr['msg'] = 'Uploaded Successfully';
    echo json_encode($arr);
    die();



} else {

    $bin = base64_decode($data, true);
    // var_dump($bin);
    $file_name = $name;
    if (strpos($bin, '%PDF') !== 0) {
        $arr['msg'] = "did not match data URI with image data";
        $arr['error_code'] = -1;
        echo json_encode($arr);
        die();
    }

    // $S3filepath = $univcode.'/'.date('Y-m-d-H:i:s', time()).'-'.$file_name;
    $S3filepath = $univcode.'/'.$collcode.'_'.date('Y-m-d-H:i:s', time()).'-'.$file_name;



    $s3 = S3Client::factory(
		array(
			'credentials' => array(
				'key' => IAM_KEY,
				'secret' => IAM_SECRET
			),
			'version' => "latest",
			'region'  => 'ap-south-1'
		)
    );

    $result = $s3->putObject([
        'Bucket' => STUDY_MATERIAL, 
        'Key' => $S3filepath, 
        'Body' => $bin,
        'ContentType' => 'application/pdf', 
    ]);

    $query = "insert into osmmain(fcollcode,FDEGREE,FEXAMNO,FSUBCODE,FCHAPTER,FPATH,FCREATEDATE,FUPDDEPT,FUPDTEACH,FAPPRSTATUS,FAPPRDATE)
         values('{$college}','{$fdegree}','{$sem}','{$subject}','{$lesson}','{$path}',now(),'{$dept}','{$tech}','approved',now())";

	$studresults = $aobj_context->mobj_db->Execute($query);


    $query = "select distinct d.fdescpn,s.fsubname,d.fexamname from degree d 
    inner join subject s on d.fdegree = s.fdegree
    and d.fexamno = s.fexamno
    where d.fdegree ='{$fdegree}' and d.fexamno = '{$sem}' and s.fsubcode = '{$subject}'";
    $res_sub = $aobj_context->mobj_db->GetRow($query);
    
    $degree_name = $res_sub['fdescpn'];
    $sub_name = $res_sub['fsubname'];
    $exam_name = $res_sub['fexamname'];

    $query = "insert ignore into logisys3_comexam.pushnotif(funivcode,fmobileno,fmobappid, fcollcode, fregno, fdegree, fenttype, fsubcode, ftitle, fbody, fstatus, fyear, fexamtype, fpushdate)
    select distinct '{$univcode}',m.fmobileno,m.FAPPMOBID,s.fcollcode, m.fregno, s.fdegree, '{$ID}', '{$ID}',  
                'Online Study Material Upload' as ftitle,
    concat('Dear Student, Study Material Upload for the Degree : ','$degree_name','; Semester : ', '$exam_name','; Subject : ','$sub_name','; chapter / lesson : ','$lesson','. visit Student Portal for more details') AS fmessage,
                'F', '2020', '1',NOW()
        FROM student s 
                    INNER JOIN logisys3_comexam.masuser m ON s.fregno = m.fregno 
    AND m.funivcode = '{$univcode}' and ifnull(fappmobid,'') <> ''
    where s.fcollcode = '{$college}' and s.fdegree = '{$fdegree}'";
    $res = $aobj_context->mobj_db->Execute($query);
    

    $arr['filename'] = $S3filepath;
    $arr['error_code'] = 0;
    echo json_encode($arr);
    die();
}