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


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

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

$load_data = $_POST['load_data'];

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

if ($load_data == 'user_data') {
    $dept_code = $_POST["dept_code"];
    $mysql = "select dp.fdeptcode,dp.fdeptshrt,em.femplcode,em.femplname,em.fusercode from masempl em
    inner join masdept dp on em.fdeptcode = dp.fdeptcode
    where ifnull(fusercode,'')<>'' and ifnull(em.fdeleted,'F')<>'T' and ifnull(em.femplstat,'F')='T' 
    order by em.femplname";
    echo "<option value=0>--Select--</option>";
    $myres = mysqli_query($mycon, $mysql);
    while ($row = mysqli_fetch_assoc($myres)) {
        echo "<option value='$row[fusercode]'>$row[femplname] [$row[femplcode]] [$row[fdeptcode]] [$row[fdeptshrt]]</option>";
    }
}

if ($load_data == 'menu_data') {
    $mysql = "select * from sys_module where ifnull(fdeleted,'F')<>'T' order by fmodecode";
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) != 0) {
        while ($myrow = mysqli_fetch_assoc($myres)) {
            echo "<option value='$myrow[fmodecode]'>$myrow[fmodename]</option>";
        }
    }
}

if ($load_data == 'disp_data') {
    $dept_code = $_POST['dept_code'];
    $user_code = $_POST['user_code'];
    $mode_code = $_POST['mode_code'];

    echo "<table id='menu_grid' class=' table-bordered'>";
    echo "<tr>";
    echo "<th width='5%'>  # </th>";
    echo "<th width='50%'> Menu Name</th>";
    echo "<th width='40%'> Module</th>";
    echo "<th width='5%'>  <input type='checkbox' id='selectmenu' name='selectmenu' onClick='select_menu();'/></th>";
    // echo "<th width='5%'>  Add <input type='checkbox' id='selectaddn' name='selectaddn' onClick='select_addn();'/></th>";
    // echo "<th width='5%'>  Edit<input type='checkbox' id='selectedit' name='selectedit' onClick='select_edit();'/></th>";
    // echo "<th width='5%'>  Delete <input type='checkbox' id='selectdele' name='selectdele' onClick='select_dele();'/></th>";
    // echo "<th width='5%'>  View <input type='checkbox' id='selectview' name='selectview' onClick='select_view();'/></th>";
    echo "</tr>";

    if ($mode_code == '10') {
        $myqry1 = "";
    } else {
        $myqry1 = " and m.fmodecode='$mode_code'";
    }
    if ($type_id != 'ADMIN') {
        $myqry2 = " and m.fmenuadmn<>'T' ";
    }
    $mysql = "select m.fmodecode,m.fmainmenu,m.fmenucode,sm.fmodename,m.fmenuname,
    m.fmenuline,u.fusercode,u.flinkstat,u.flinkaddn,u.flinkedit,u.flinkdele,u.flinkview 
    from sys_menu m 
    left join sys_module sm on m.fmodecode = sm.fmodecode 
    left join sys_user_menu u on m.fmodecode=u.fmodecode and m.fmainmenu=u.fmainmenu and m.fmenucode=u.fmenucode and u.fusercode='$user_code'
    where fmenustat='T' " . $myqry1 . "and fmenuline='1' " . $myqry2 . " and ifnull(sm.fdeleted,'F')<>'T'
    order by m.fmodecode,m.fmainmenu,m.fmenucode";

    $myres = mysqli_query($mycon, $mysql);
    $i = 1;
    while ($myrow = mysqli_fetch_assoc($myres)) {
        $mode_code = $myrow['fmodecode'];
        $select_menu = "";
        $select_addn = "";
        $select_edit = "";
        $select_dele = "";
        $select_view = "";

        if ($myrow['flinkstat'] == 1) {
            $select_menu = 'checked="checked"';
        }
        if ($myrow['flinkaddn'] == 1) {
            $select_addn = 'checked="checked"';
        }
        if ($myrow['flinkedit'] == 1) {
            $select_edit = 'checked="checked"';
        }
        if ($myrow['flinkdele'] == 1) {
            $select_dele = 'checked="checked"';
        }
        if ($myrow['flinkview'] == 1) {
            $select_view = 'checked="checked"';
        }

        if ($myrow['fmenuline'] != 0) {
            echo "<tr>";
            echo "<input type=hidden name=txtmodecode[] id=txtmodecode[] value=$myrow[fmodecode]>";
            echo "<input type=hidden name=txtmaincode[] id=txtmaincode[] value=$myrow[fmainmenu]>";
            echo "<input type=hidden name=txtmenucode[] id=txtmenucode[] value=$myrow[fmenucode]>";
            echo "<td align=center>  $i</td>";
            echo "<td align='left'>$myrow[fmenuname]</td>";
            echo "<td align='center'>$myrow[fmodename]</td>";
            echo "<td align=center><input type=checkbox name=txtselemenu[] id=txtselemenu[] $select_menu></td>";
            // echo "<td align=center><input type=checkbox name=txtseleaddn[] id=txtseleaddn[] $select_addn></td>";
            // echo "<td align=center><input type=checkbox name=txtseleedit[] id=txtseleedit[] $select_edit></td>";
            // echo "<td align=center><input type=checkbox name=txtseledele[] id=txtseledele[] $select_dele></td>";
            // echo "<td align=center><input type=checkbox name=txtseleview[] id=txtseleview[] $select_view></td>";
            echo "</tr>";
        }
        $i++;
    }
    echo "</table>";
}

if ($load_data == 'save_data') {
    $user_code = $_POST['user_code'];
    $mode_code = $_POST['mode_code'];
    $main_code = $_POST['main_code'];
    $menu_code = $_POST['menu_code'];

    $sele_menu = $_POST['sele_menu'];
    $sele_addn = $_POST['sele_addn'];
    $sele_edit = $_POST['sele_edit'];
    $sele_dele = $_POST['sele_dele'];
    $sele_view = $_POST['sele_view'];

    for ($i = 0; $i < sizeof($menu_code); $i++) {
        $mysql = "select * from sys_user_menu where fusercode='$user_code' and fmodecode='$mode_code[$i]' and fmainmenu='$main_code[$i]' and fmenucode='$menu_code[$i]'";
        $myres = mysqli_query($mycon, $mysql);
        if (mysqli_num_rows($myres) == 0) {
            $mysql1 = "insert into sys_user_menu (fusercode, fmodecode, fmainmenu, fmenucode, flinkstat, flinkaddn, flinkedit, flinkdele, flinkview) values('$user_code', '$mode_code[$i]', '$main_code[$i]', '$menu_code[$i]', $sele_menu[$i], $sele_addn[$i], $sele_edit[$i], $sele_dele[$i], $sele_view[$i])";
            $myres1 = mysqli_query($mycon, $mysql1);
        } else {
            $mysql1 = "update sys_user_menu set flinkstat=$sele_menu[$i], flinkaddn=$sele_addn[$i], flinkedit=$sele_edit[$i], flinkdele=$sele_dele[$i], flinkview=$sele_view[$i] where fusercode='$user_code' and fmodecode='$mode_code[$i]' and fmainmenu='$main_code[$i]' and fmenucode='$menu_code[$i]'";
            $myres1 = mysqli_query($mycon, $mysql1);
        }
    }

    set_user_logs($dept_id, $user_id, 'UACC', 'USER RIGHTS UPDATED - ' . $user_code);

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

if ($load_data == 'save_defa') {
    $user_code = $_POST['user_code'];

    $mysql = "delete from sys_user_menu where fusercode='$user_code'";
    $myres = mysqli_query($mycon, $mysql);

    $mysql = "select * from sys_menu where fmenuuser regexp (select fusertype from masempl where fusercode='$user_code')";
    $myres = mysqli_query($mycon, $mysql);
    while ($myrow = mysqli_fetch_assoc($myres)) {
        $mysql1 = "insert into sys_user_menu (fusercode, fmodecode, fmainmenu, fmenucode, flinkstat) ";
        $mysql1 .= "values('$user_code','$myrow[fmodecode]','$myrow[fmainmenu]','$myrow[fmenucode]',1)";
        $myres1 = mysqli_query($mycon, $mysql1);
    }

    $resp_mesg = "Default user rights updated!";
    echo json_encode(array("mesg" => $resp_mesg, "stat" => $resp_stat, "file" => $resp_file));
}