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


Current Path : /var/www/html/oums/api/
Upload File :
Current File : /var/www/html/oums/api/taskreminder.php

<?php
    include("sys_connect.php");
    include("../src/api_sendsms.php");
    include("../src/sys_mainphp.php");
    
    $type = $_GET['type'];
    $u_type = $_GET['usrtype'];
    $empid = $_GET['empid'];

    if($type == "get_task_assigner"){
        if($u_type == "ADMIN"){
            $myqry = " where femplcode in (select ftaskasby from taskreminder) ";
            $myqry2 = " where femplcode in (select ftaskasto from taskreminder) ";
        }else{
            $myqry = " where femplcode in (select ftaskasby from taskreminder where ftaskasto='{$empid}')";
            $myqry2 = " where femplcode in (select ftaskasto from taskreminder where ftaskasby='{$empid}') ";
        } 
        $mysql = "select distinct femplcode,femplname from masempl ". $myqry ." order by femplname;";
        $mysql2 = "select distinct femplcode,femplname from masempl ". $myqry2 ." order by femplname;";

        $res = mysqli_query($mycon, $mysql);
        $res2 = mysqli_query($mycon, $mysql2);
        $count = mysqli_num_rows($res);
        $count2 = mysqli_num_rows($res2);
        if($count>0){
            $data = [];
            $i=0;
            while($fetch = mysqli_fetch_assoc($res)){
                $data[$i]=$fetch;
                $i++;
            }
            $arr['data1'] = $data;
            
        }

        if($count2>0){
            $data2 = [];
            $j = 0;
            while($fetch2 = mysqli_fetch_assoc($res2)){
                $data2[$j] = $fetch2;
                $j++;
            }
            $arr['data2'] = $data2;
        }
        echo json_encode(array("error_code"=>0, "data"=>$arr));
    }

    if($type == "getdata"){
        $stat = $_GET['stat'];
        $query = "select ftaskcode,date_format(ftaskdate,'%d/%m/%Y') as ftaskdate, 
                  ftaskname, ftaskasby, e1.femplname as fasbyname, ftaskasto, 
                  e2.femplname as fastoname, ftaskstat, ftaskdetl,
                  date_format(flastdate,'%d/%m/%Y')as flastdate from taskreminder tk 
                  left join masempl e1 on tk.ftaskasby = e1.femplcode 
                  left join masempl e2 on tk.ftaskasto = e2.femplcode 
                  where ifnull(tk.fdeleted,'F')='F' and ftaskstat = '{$stat}'
                  order by ftaskcode desc, ftaskdate desc";

        $res = mysqli_query($mycon, $query);
        $count = mysqli_num_rows($res);
        if($count > 0){
            $data = [];
            $i = 0;
            while($fetch = mysqli_fetch_assoc($res)){
                $data[$i] = $fetch;
                $i++;
            }
        echo json_encode(array("error_code"=>0, "data"=>$data));
        return;
        }
    }

    if($type == "savetask"){   
        $task = $_POST['taskname'];
        $taskDetails = $_POST['taskDetails'];
        $assignedto = $_POST['assignedto'];
        $assignedtomob = $_POST['assignedtomob'];
        $requiredate = $_POST['requiredate'];
        $status = $_POST['status'];
        $taskby = $_POST['taskassignedby'];
        $usr = $_POST['upduser'];
        $assignedtoname = $_POST['assignedToName'];

        $query = "insert into taskreminder(ftaskdate, ftaskname, ftaskasby, 
                  ftaskasto, ftaskstat, fstrtdate, flastdate, fupdtuser, fupdttime, ftaskdetl ) 
                  values(now(), '{$task}', '{$taskby}', '{$assignedto}', '{$status}', now(), 
                  date_format(str_to_date('{$requiredate}','%d/%m/%Y'),'%Y-%m-%d'), '{$usr}', now(), '{$taskDetails}')";
        $res = mysqli_query($mycon, $query);
        $crtd_code = str_pad(mysqli_insert_id($mycon), 6, '0', STR_PAD_LEFT);
        
        if($res){
            if(strlen($assignedtomob) == 10){
                $asto_mesg = "Task Created [" . $crtd_code . "] " . chr(10) . "Task Name : " . $task . chr(10) . "Task From : " . $usr . chr(10) . "Start Date : " . date("d/m/Y") . chr(10) . "Due Date : " . $requiredate . " - Uniclare";
                send_sms($assignedtomob, $asto_mesg);
                $asto_qry = "insert ignore into logisys3_comexam.sendsms(funivcode,fregno,fmobileno,fenttype,fsubcode,fmessage,fstatus,fdeleted,fyear,fexamtype,fupdate) values('999','$assignedto','$assignedtomob','oums',concat(date_format(current_date,'%d/%m/%Y'),'_nt_','$crtd_code'),'$asto_mesg','T','F',year(current_date),'1',now())";
                $asto_res = mysqli_query($mycon, $asto_qry);
            }
            echo json_encode(array("error_code"=>0, "msg"=>"Task Added"));
            return;
        }else{
            echo json_encode(array("error_code"=>-1, "msg"=>"Try Again Later"));
            return;
        }
    }

    if($type == "getTask"){
        $taskcode = $_GET['taskcode'];
        $query = "select  ftaskcode, date_format(ftaskdate,'%d/%m/%Y')as ftaskdate,
                  ftaskname, ftaskdetl, ftaskasby, ftaskasto, ftaskstat, femplname,
                  date_format(fstrtdate,'%d/%m/%Y')as fstrtdate,
                  date_format(flastdate,'%d/%m/%Y')as flastdate, ftaskasby
                  from taskreminder tr inner join masempl m on tr.ftaskasto = m.femplcode
                  where ftaskcode = '{$taskcode}'";
        $res = mysqli_query($mycon, $query);
        $count = mysqli_num_rows($res);
        if($count>0){
            $fetch = mysqli_fetch_assoc($res);
            echo json_encode(array("error_code"=>0, "data"=>$fetch));
            return;
        }else{
            echo json_encode(array("error_code"=>-1, "data"=>"no data found"));
            return;
        }
    }

    if($type == "updTask"){
        $task = $_POST['taskname'];
        $taskDetails = $_POST['taskDetails'];
        $taskto = $_POST['assignedto'];
        $tasktoname = $_POST['assignedToName'];
        $requiredate = $_POST['requiredate'];
        $status = $_POST['status'];
        $usr = $_POST['upduser'];
        $taskcode = $_POST['taskcode'];
        $assignedtomob = $_POST['assignedtomob'];
        $assignedBy = $_POST['taskassignedby'];
        $currdate = $_POST['startdate'];

        $getempl = "select femplname from masempl where femplcode = '{$assignedBy}'";
        $res=mysqli_query($mycon, $getempl);
        $fecth = mysqli_fetch_assoc($res);
        $empl = $fecth['femplname'];
        
        $query = "update taskreminder set  
                  ftaskname='{$task}', ftaskdetl='{$taskDetails}', ftaskasto='{$taskto}',
                  ftaskstat='{$status}', 
                  flastdate = date_format(str_to_date('{$requiredate}','%d/%m/%Y'),'%Y-%m-%d'),
                  fupdtuser = '{$usr}', fupdttime=now() 
                  where ftaskcode='{$taskcode}' and ftaskasby = '{$assignedBy}'";          
        $res=mysqli_query($mycon, $query);
        $crtd_code = $taskcode;
        
        if($res){
            if($status == "COMPLETED"){
                if(strlen($assignedtomob) == 10){
                    $asto_mesg = "Task CreatedCode [" . $crtd_code . "] " . chr(10) . "Task Name : " . $task . chr(10) . "Task From : " . $empl . chr(10) . "Completed On : " . date("d/m/Y") . chr(10) . "Start Date : " . $currdate . chr(10) . "Due Date : " . $requiredate . chr(10) . "Status : " . $status . chr(10) ." - Uniclare";
                    send_sms($assignedtomob, $asto_mesg);
                }
            }else{
                if(strlen($assignedtomob) == 10){
                    $asto_mesg = "Task Created [" . $crtd_code . "] " . chr(10) . "Task Name : " . $task . chr(10) . "Task From : " . $empl . chr(10) . "Start Date : " . date("d/m/Y") . chr(10) . "Due Date : " . $requiredate . chr(10) ." - Uniclare";
                    send_sms($assignedtomob, $asto_mesg);
                    $asto_qry = "insert ignore into logisys3_comexam.sendsms(funivcode,fregno,fmobileno,fenttype,fsubcode,fmessage,fstatus,fdeleted,fyear,fexamtype,fupdate) values('999','$assignedto','$assignedtomob','oums',concat(date_format(current_date,'%d/%m/%Y'),'_nt_','$crtd_code'),'$asto_mesg','T','F',year(current_date),'1',now())";
                    $asto_res = mysqli_query($mycon, $asto_qry);
                }
            };
            echo json_encode(array("error_code"=>0, "msg"=>"Task Updated"));
            return;
        }else{
            echo json_encode(array("error_code"=>-1, "msg"=>"Try Again Later"));
            return;
        }

    }

    if($type == "mobno"){
        $emplcode = $_GET['empcode'];
        $query = "select femplcode, femplname, femplmobl from masempl where femplcode = '{$emplcode}'";
        $result = mysqli_query($mycon, $query);
        $count = mysqli_num_rows($result);
        if($count>0){
            $fetch = mysqli_fetch_assoc($result);
            echo json_encode(array("error_code"=>0, "data"=>$fetch));
            return;
        }else{
            echo json_encode(array("error_code"=>-1, "data"=>"Something Went Wrong"));
            return;
        }
    }

    
    
?>