<?php
/************************************************************************/
/*     PROGRAMMER     :  SMA                                            */
/*     SCRIPT NAME    :  adminuser_edit.php                             */
/*     CREATED ON     :  10/JULY/2006                                   */
/*     MODERNIZED     :  20/AUG/2025                                     */
/*     PURPOSE        :  Set Privileges to Selected Admin User         */
/************************************************************************/

$adminobj = new adminuser();

$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$adminobj->GetAdimUserDetails($id);

$note = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : '';
?>

<form name="frm_users" method="post" action="adminuser_privilege_manage.php">
    <table border="0" cellpadding="0" cellspacing="0" class="tablebdr" width="65%" align="center">
        <tr>
            <td align="center" colspan="2" class="tdhead"><b>Admin User Privileges</b></td>
        </tr>
        <tr><td height="10"></td></tr>
        <?php if ($note) { ?>
            <tr><td colspan="2" align="center" class="textred"><?php echo htmlspecialchars($note); ?></td></tr>
        <?php } ?>
        <tr>
            <td width="100%" align="center" colspan="2">
                <table cellpadding="0" cellspacing="0" align="center">
                    <tr>
                        <td height="30">Privileges for the user: &nbsp;<b><?php echo htmlspecialchars($adminobj->username); ?></b></td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td width="90%" align="left" height="30" class="tdhead"><b>Links</b></td>
            <td width="10%" align="center" height="30" class="tdhead"><b>Privilege</b></td>
        </tr>

        <?php  
        $adminobj->GetAdminLiks(0);
        for ($i = 0; $i < count($adminobj->linkid); $i++) {
            $mainLinkUsers = explode(",", $adminobj->linkusers[$i]);
            $checked = in_array($id, $mainLinkUsers) ? "checked='checked'" : "";
        ?> 
            <tr>
                <td width="90%" align="left" height="30"><b><?php echo htmlspecialchars($adminobj->linktitle[$i]); ?></b></td>
                <td width="10%" align="right" height="30">
                    <input type="checkbox" <?php echo $checked; ?> name="chk_<?php echo intval($adminobj->linkid[$i]); ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
                </td>
            </tr>

            <?php
            $userobj = new adminuser();
            $childResult = $userobj->GetAdminLiks($adminobj->linkid[$i]);
            if ($childResult) {
                for ($j = 0; $j < count($userobj->linkid); $j++) {
                    $childLinkUsers = explode(",", $userobj->linkusers[$j]);
                    $childChecked = in_array($id, $childLinkUsers) ? "checked='checked'" : "";
            ?>
                <tr>
                    <td colspan="2" width="100%">
                        <table cellpadding="0" cellspacing="0" align="center" width="100%">
                            <tr>
                                <td align="left" width="10%">&nbsp;</td>
                                <td align="left" width="80%"><?php echo htmlspecialchars($userobj->linktitle[$j]); ?></td>
                                <td width="10%" align="right" height="30">
                                    <input type="checkbox" <?php echo $childChecked; ?> name="chk_<?php echo intval($userobj->linkid[$j]); ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            <?php
                }
            }
        }
        ?>
        <tr>
            <td colspan="2" align="center" height="40">
                <input type="submit" name="Update" value="Update" />
                <input type="hidden" name="id" value="<?php echo $id; ?>" />
            </td>
        </tr>
        <tr><td colspan="2">&nbsp;</td></tr>
    </table>
</form>
