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


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

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

function getQpTemplateDet($aobj_context){
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $univcode = $aobj_context->mobj_data["univcode"];
    
    $query = "select ftempcode, ftempname, ftempdesc 
    from tdvs_qptemphead 
    where ifnull(fdeleted,'') <> 'T'
    group by ftempcode";
    
    $result = $aobj_context->pobj_db->GetAll($query);

    if(count($result) > 0)
    {
        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 getTempQPData($aobj_context){
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $univcode = $aobj_context->mobj_data["univcode"];
    $ftempcode = $aobj_context->mobj_data["ftempcode"];
    
    $query = "select ifnull(ftempcode,'') as ftempcode,
    ifnull(ftempname,'') as ftempname,
    ifnull(ftempdesc,'') as ftempdesc,
    ifnull(ftempmax,'') as ftempmax,
    ifnull(ftotmandqn,'') as ftotmandqn,
    ifnull(fpartcode,'') as fpartcode,
    ifnull(fpartdesc,'') as fpartdesc,
    ifnull(fmaxqn,'') as fmaxqn,
    ifnull(fmandqn,'') as fmandqn,
    ifnull(fmaxmarks,'') as fmaxmarks,
    ifnull(fminqn,'') as fminqn
    from tdvs_qptemphead where ftempcode = '{$ftempcode}'";
    
    $result = $aobj_context->pobj_db->GetAll($query);

    $que = "select ifnull(ftempcode, '') as ftempcode,
    ifnull(fpartcode, '') as fpartcode,
    ifnull(fqncode, '') as fqncode,
    ifnull(fqnno, '') as fqnno,
    ifnull(fqndesc, '') as fqndesc,
    ifnull(fqnlevel, '') as fqnlevel,
    ifnull(fqnparent, '') as fqnparent,
    ifnull(fmaxmarks, '') as fmaxmarks,
    ifnull(fsubqp, '') as fsubqp,
    ifnull(fsubmaxqn, '') as fsubmaxqn,
    ifnull(fsubmandqn, '') as fsubmandqn,
    ifnull(fqnord, '') as fqnord 
    from tdvs_qptempdetl where ftempcode = '{$ftempcode}'
    order by fqnord";
    
    $res = $aobj_context->pobj_db->GetAll($que);
    
    $sumarr = array_map('transform', $result);

    $arr["ftempcode"] = $result[0]['ftempcode'];
    $arr["ftempname"] = $result[0]['ftempname'];
    $arr["ftempdesc"] = $result[0]['ftempdesc'];
    $arr["ftempmax"] = $result[0]['ftempmax'];
    $arr["ftotmandqn"] = $result[0]['ftotmandqn'];
    $arr["detlength"] = count($res) > 0 ? "T" : "F";
    $arr['sumarr'] = $result;
    $arr['sumarrdet']=$res;

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

function transform($el) {
    return [
        'partcode' => $el['fpartcode'],
        'partdescp' => $el['fpartdesc'],
        'maxqns' => $el['fmaxqn'],
        'mandqns' => $el['fmandqn'],
        'maxmarks' => $el['fmaxmarks'],
        'minqns' => $el['fminqn']
    ];
}

function check_tempcode($aobj_context){
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $univcode = $aobj_context->mobj_data["univcode"];
    $ftempcode = $aobj_context->mobj_data["ftempcode"];
    
    $query = "select * from tdvs_qptemphead where ftempcode = '{$ftempcode}'";
    
    $result = $aobj_context->pobj_db->GetAll($query);
    
    if(count($result) > 0)
    {
        $arr['msg'] = 'Template Code already present..!';
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
    }
    else
    {
        $arr['msg'] = 'Ok';
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
    }
}

function save_tempcode($aobj_context){
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $univcode = $aobj_context->mobj_data["univcode"];
    $tempcode = $aobj_context->mobj_data["tempcode"];
    $sumdata = json_decode($aobj_context->mobj_data["sumdata"], true);
    $delrows = json_decode($aobj_context->mobj_data["delrows"], true);
    $tempname = $aobj_context->mobj_data["tempname"];
    $tempdesc = $aobj_context->mobj_data["tempdesc"];
    $tempmaxmarks = $aobj_context->mobj_data["tempmaxmarks"];
    $tempmandqns = $aobj_context->mobj_data["tempmandqns"];
    $template_obj = '';

    foreach($delrows as $data){
        $deleteData = "delete from tdvs_qptemphead 
        where ftempcode = '${tempcode}' and fpartcode='{$data['partcode']}'";

        $res1 = $aobj_context->pobj_db->Execute($deleteData);
    }

    foreach($sumdata as $val){
        $template_obj .= "('{$tempcode}', '{$tempname}', '{$tempdesc}', '{$val['partcode']}', '{$val['partdescp']}', '{$val['maxqns']}', '{$val['mandqns']}',
        '{$val['maxmarks']}', '{$tempmaxmarks}', '{$tempmandqns}', '{$val['minqns']}'),";
    }
    $template_obj = rtrim($template_obj, ',');
    
    $sltQry = "insert into tdvs_qptemphead (ftempcode, ftempname,
    ftempdesc, fpartcode, fpartdesc,fmaxqn,fmandqn,
    fmaxmarks,ftempmax,ftotmandqn,fminqn) values
    {$template_obj}
    ON DUPLICATE KEY UPDATE
    fpartcode = VALUES(fpartcode), 
    fpartdesc = VALUES(fpartdesc),
    fmaxqn = VALUES(fmaxqn), 
    fmandqn = VALUES(fmandqn),
    fmaxmarks = VALUES(fmaxmarks)";
    
    $res = $aobj_context->pobj_db->Execute($sltQry);

    if($res){
        $arr['msg'] = 'Successfully Updated';
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
    } else {
        $arr['msg'] = 'Something Went wrong';
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    }
}

function saveTempQPDet($aobj_context){
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $univcode = $aobj_context->mobj_data["fusercode"];
    $tempcode = $aobj_context->mobj_data["ftempcode"];
    $ss = json_decode($aobj_context->mobj_data["ss"], true);
    $sumdata = json_decode($aobj_context->mobj_data["sumdata"], true);
    $tempname = $aobj_context->mobj_data["tempname"];
    $tempdesc = $aobj_context->mobj_data["tempdesc"];
    $tempmaxmarks = $aobj_context->mobj_data["tempmaxmarks"];
    $delrows = json_decode($aobj_context->mobj_data["del"],true);
    $template_obj = '';
    // var_dump($delrows,$ss);die();
    foreach($delrows as $data){
        foreach($data as $val){
            $deleteData = "delete from tdvs_qptempdetl 
            where ftempcode = '{$tempcode}' and fpartcode='{$val['partcode']}'
            and fqncode = '{$val['qpcode']}'";
            // var_dump($deleteData);
            $res1 = $aobj_context->pobj_db->Execute($deleteData);
        }
    }
// die();
    foreach ($sumdata as $sum) {
        foreach ($ss as $el) {
            if (isset($el[$sum['partcode']])) {
                foreach ($el[$sum['partcode']] as $item) {
                    $template_obj .= "('$tempcode', '{$sum['partcode']}', '{$item['qpcode']}', '{$item['qpno']}', NULL, '{$item['level']}', '{$item['parent']}', '{$item['maxmarks']}', '{$item['subqn']}', '{$item['maxqn']}', '{$item['mandqp']}', '{$item['order']}'),";
                }
            }
        }
    }
    $template_obj = rtrim($template_obj, ',');
    $sltQry = "INSERT INTO tdvs_qptempdetl (ftempcode, fpartcode, fqncode, fqnno, fqndesc, fqnlevel, fqnparent, fmaxmarks, fsubqp, fsubmaxqn, fsubmandqn, fqnord)
    values
    {$template_obj}
    ON DUPLICATE KEY UPDATE
      fqnno = VALUES(fqnno),
      fqndesc = VALUES(fqndesc),
      fqnlevel = VALUES(fqnlevel),
      fqnparent = VALUES(fqnparent),
      fmaxmarks = VALUES(fmaxmarks),
      fsubqp = VALUES(fsubqp),
      fsubmaxqn = VALUES(fsubmaxqn),
      fsubmandqn = VALUES(fsubmandqn),
      fqnord = VALUES(fqnord)";
    
    $res = $aobj_context->pobj_db->Execute($sltQry);

    if($res){
        $arr['msg'] = 'Successfully Updated';
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
    } else {
        $arr['msg'] = 'Something Went wrong';
        echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    }
}
?>