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


Current Path : /var/www/html/collportal/custom_src/
Upload File :
Current File : //var/www/html/collportal/custom_src/modupdqp.php

<?php
    require_once(_DIR_."/../../aws/aws-autoloader.php");
    use Aws\S3\S3Client;
    use Aws\S3\Exception\S3Exception;

    function getModQpDetails($aobj_context){
        $teachcode = $aobj_context->mobj_data["teachcode"];
        $fstatus = $aobj_context->mobj_data["fstatus"];

        if($fstatus == "Pending"){
            $cond = "and ifnull(q.fmodqpdate,'') = ''";
        }else if($fstatus == "Uploaded"){
            $cond = "and ifnull(q.fmodqpdate,'') <> ''";
        }

        // $query = "select q.fqpcode, concat(s.fsubname, ' - ', s.fsubshort)as fsubname, q.fset, q.fteachcode, s.fqpsyllabus,
        //         q.fexamtype,q.fyear,ifnull(q.fmodqpdate,'') as fmodqpdate, q.ftype,ifnull(q.fmodstatus,'')as fmodstatus,
        //         DATE_FORMAT(m.ftodate,'%d/%m/%Y')as ftodate,
        //         CASE 
        //         WHEN DATE(flastdate) < CURDATE() THEN 'T' 
        //         ELSE 'F'
        //         END AS flastdate_status
        //         from qpseterdet q inner join 
        //         (select distinct fqpcode, fsubname, fqpsyllabus, fsubshort from subject where ifnull(fqpcode, '') <> '') s on 
        //         s.fqpcode = q.fqpcode 
        //         inner join moderator m on m.fqpcode = q.fqpcode 
        //         where m.fteachcode = '{$teachcode}' and ifnull(q.fqpfilepath, '') <> ''
        //         and m.flogin = 'T' 
        //         $cond
        //         group by q.fteachcode,q.fqpcode, q.fset, q.fyear, q.fexamtype
        //         order by q.fqpcode, q.fset";

        $query = "select q.fqpcode, concat(s.fsubname, ' - ', s.fsubshort)as fsubname, q.fset, q.fteachcode, s.fqpsyllabus,
        ifnull(q.ffinalpaper, '')as ffinalpaper,
        q.fexamtype,q.fyear,ifnull(q.fmodqpdate,'') as fmodqpdate, q.ftype,ifnull(q.fmodstatus,'F')as fmodstatus,
        DATE_FORMAT(m.ftodate,'%d/%m/%Y')as ftodate, 
        CASE WHEN m.ftodate < CURDATE() THEN 'T' ELSE 'F' END AS flastdate_status
        from qpseterdet q inner join 
        (select distinct fqpcode, fsubname, fqpsyllabus, fsubshort from subject where ifnull(fqpcode, '') <> '') s on 
        s.fqpcode = q.fqpcode 
        inner join moderator m on m.fqpcode = q.fqpcode 
        where m.fteachcode = '{$teachcode}' and ifnull(q.fqpfilepath, '') <> ''
        and m.flogin = 'T' 
        $cond
        group by q.fteachcode,q.fqpcode, q.fset, q.fyear, q.fexamtype
        order by ifnull(q.fmodqpdate,''), q.fqpcode, q.fset";
               
        $result = $aobj_context->mobj_db->GetAll($query);

        if($result){
            echo $aobj_context->mobj_output->ToJSONEnvelope($result,0,"success");  
        }else{
            $arr['msg'] = 'No data found';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
        }
    }

    function getModUpdData($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $univcode = $aobj_context->mobj_data["univcode"];
        $user = $aobj_context->mobj_data["userid"];
        $data = json_decode($aobj_context->mobj_data["data"], true);
        $qpcode = $data["fqpcode"];
        $teachcode = $data["fteachcode"];
        $fset = $data["fset"];
        $fyear = $data["fyear"];
        $fexamtype = $data["fexamtype"];
        $ftype = $data["ftype"];
        
        $query = "select * from moderator where fteachcode = '{$user}' and flogin = 'T' and fqpcode = '{$qpcode}'";
        $res = $aobj_context->mobj_db->GetRow($query);


        $query = "select count(*) as cnt from moderator where fteachcode = '{$user}'
        and fqpcode = '{$qpcode}' 
        and date_format(now(),'%Y-%m-%d') between date_format(ffromdate,'%Y-%m-%d') and date_format(ftodate,'%Y-%m-%d')
        and fyear = '{$fyear}' and fexamtype = '{$fexamtype}'";
        $res = $aobj_context->mobj_db->GetRow($query);

        if($univcode == '030'){
            if($res['cnt'] > 0){

            } else {
                $arr['msg'] = 'Last Date is over. Kindly contact admin';
                echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
                return;
            }
        }

        if($res){
            $query = "select q.fset, ifnull(q.fqpfilepath,'')as fqpfilepath, 
            ifnull(q.fanskeypath, '') as fanskeypath,
            ifnull(q.fmodqppath, '') as fmodqppath,
            ifnull(q.fmodqpupd, '') as fmodqpupd, 
            ifnull(q.fmodanskey, '') as fmodanskey, 
            ifnull(q.fmodform, '') as fmodform,
            ifnull(q.fteachcode,'') as fteachcode,
            q.fyear,q.fexamtype,ifnull(q.fmodremfile, '')as fmodremfile
            from qpseterdet q inner join moderator m on m.fqpcode = q.fqpcode 
            where q.fqpcode = '{$qpcode}' and m.fteachcode = '{$user}' and
            ifnull(q.fqpfilepath, '') <> ''
            and m.flogin = 'T' and q.fteachcode = '{$teachcode}' and q.fset = '{$fset}'
            and q.fyear = '{$fyear}' and q.fexamtype = '{$fexamtype}'
            and q.ftype='{$ftype}'";
            $result = $aobj_context->mobj_db->GetAll($query);

            if($result){
                echo $aobj_context->mobj_output->ToJSONEnvelope($result,0,"success");  
                return;
            } else {
                $arr['msg'] = 'No data found';
                echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
                return;
            }

        } else {
            $arr['msg'] = 'Login Disabled. Kindly contact admin';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
            return;
        }
    }

    function uploadModQpData($aobj_context){
        $data = json_decode($aobj_context->mobj_data["data"], true);
        $userid = $data['userid'];
        $univcode = $data["univcode"];
        $qpcode = $data["fqpcode"];
        $teachcode = $data["fteachcode"];
        $fset = $data["fset"];
        $fyear = $data["fyear"];
        $fexamtype = $data["fexamtype"];
        $ftype = $data["ftype"];
        $qpstatus = $aobj_context->mobj_data["qpstatus"];
        $ansstatus = $aobj_context->mobj_data["ansstatus"];
        $modstatus = $aobj_context->mobj_data["modstatus"];
        $remstatus = $aobj_context->mobj_data["remstatus"];

        $qpfile = $_FILES['qpfile'];
        $anskeyfile = $_FILES['anskeyfile'];
        $modFromFile = $_FILES['modFromFile'];
        $remfile = $_FILES['remfile'];

        $yearmode = $fyear.'-'.$fexamtype;
        $length = 30; 
        $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    
        $s3 = S3Client::factory(
            array(
                'credentials' => array(
                    'key' => IAM_KEY,
                    'secret' => IAM_SECRET
                ),
            'version' => "latest",
            'region'  => 'ap-south-1'
        ));

        try {
            if($qpstatus === "Yes"){
                for ($i = 0; $i < $length; $i++) {
                    $randomString .= $characters[rand(0, strlen($characters) - 1)];
                }
                $ext = pathinfo($qpfile['name'], PATHINFO_EXTENSION);
                $file_name = $qpcode."_qp_".$randomString.".".$ext;
                $key = $univcode."/".$yearmode."/".$qpcode."/".$file_name;

                
                $s3->putObject(['Bucket' => "moderator-upd", 'Key' => $key, 'SourceFile' => $qpfile['tmp_name']]);

                $query = "update qpseterdet set fmodqpupd='{$key}', fmodqpdate=now(), fmodteach = '{$userid}',
                        fmodstatus = 'T'
                        where fqpcode = '{$qpcode}'
                        and fset='{$fset}' and fteachcode = '{$teachcode}' and fyear = '{$fyear}'
                        and fexamtype = '{$fexamtype}' and ftype='{$ftype}'";
                $result = $aobj_context->mobj_db->Execute($query);

                // $remarks = "Moderator QP Details - uploaded QPFILE against QP CODE: ".$qpcode. " ,set: ".$fset. " and Moderator: ".$teachcode;
                // $res = error_logs($aobj_context, $univcode, $remarks, $collcode, "Moderator QP Details", $teachcode, $teachcode);
            }
            if($ansstatus === "Yes"){
                for ($i = 0; $i < $length; $i++) {
                    $randomString .= $characters[rand(0, strlen($characters) - 1)];
                }
                $ext = pathinfo($anskeyfile['name'], PATHINFO_EXTENSION);
                $file_name = $qpcode."_ans_".$randomString.".".$ext;
                $key = $univcode."/".$yearmode."/".$qpcode."/".$file_name;

                $s3->putObject(['Bucket' => "moderator-upd", 'Key' => $key, 'SourceFile' => $anskeyfile['tmp_name']]);

                $query = "update qpseterdet set fmodanskey='{$key}', fmodansdate=now(), fmodteach = '{$userid}'
                        where fqpcode = '{$qpcode}'
                        and fset='{$fset}' and fteachcode = '{$teachcode}' and fyear = '{$fyear}'
                        and fexamtype = '{$fexamtype}' and ftype='{$ftype}'";
                $result = $aobj_context->mobj_db->Execute($query);

                // $remarks = "Moderator QP Details - uploaded ANSFILE against QP CODE: ".$qpcode. " ,set: ".$fset. " and Moderator: ".$teachcode;
                // $res = error_logs($aobj_context, $univcode, $remarks, $collcode, "Moderator QP Details", $teachcode, $teachcode);
            }
            if($modstatus === "Yes"){
                for ($i = 0; $i < $length; $i++) {
                    $randomString .= $characters[rand(0, strlen($characters) - 1)];
                }
                $ext = pathinfo($modFromFile['name'], PATHINFO_EXTENSION);
                $file_name = $qpcode."_mod_".$randomString.".".$ext;
                $key = $univcode."/".$yearmode."/".$qpcode."/".$file_name;

           
                $s3->putObject(['Bucket' => "moderator-upd", 'Key' => $key, 'SourceFile' => $modFromFile['tmp_name']]);

                $query = "update qpseterdet set fmodform='{$key}', fmodformdate=now(), fmodteach = '{$userid}'
                        where fqpcode = '{$qpcode}'
                        and fset='{$fset}' and fteachcode = '{$teachcode}' and fyear = '{$fyear}'
                        and fexamtype = '{$fexamtype}' and ftype='{$ftype}'";
                $result = $aobj_context->mobj_db->Execute($query);

                // $remarks = "Moderator QP Details - uploaded MODFORM against QP CODE: ".$qpcode. " ,set: ".$fset. " and Moderator: ".$teachcode;
                // $res = error_logs($aobj_context, $univcode, $remarks, $collcode, "Moderator QP Details", $teachcode, $teachcode);                
            }

            if($remstatus === "Yes"){
                for ($i = 0; $i < $length; $i++) {
                    $randomString .= $characters[rand(0, strlen($characters) - 1)];
                }
                $ext = pathinfo($remfile['name'], PATHINFO_EXTENSION);
                $file_name = $qpcode."_rem_".$randomString.".".$ext;
                $key = $univcode."/".$yearmode."/".$qpcode."/".$file_name;

           
                $s3->putObject(['Bucket' => "moderator-upd", 'Key' => $key, 'SourceFile' => $remfile['tmp_name']]);

                $query = "update qpseterdet set fmodremfile='{$key}', fmodremupdate=now(), fmodteach = '{$userid}'
                        where fqpcode = '{$qpcode}'
                        and fset='{$fset}' and fteachcode = '{$teachcode}' and fyear = '{$fyear}'
                        and fexamtype = '{$fexamtype}' and ftype='{$ftype}'";
                $result = $aobj_context->mobj_db->Execute($query);

                // $remarks = "Moderator QP Details - uploaded MODFORM against QP CODE: ".$qpcode. " ,set: ".$fset. " and Moderator: ".$teachcode;
                // $res = error_logs($aobj_context, $univcode, $remarks, $collcode, "Moderator QP Details", $teachcode, $teachcode);                
            }

            if($result){
                $arr['msg'] = "File Uploaded";
                echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
             }else{
                 $arr['msg'] = "Failed to upload data";
                 echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
                 return;
             }
        }catch(S3Exception $e) {
            $arr['msg'] = 'Failed to upload';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
            return;
        }
    }
?>