<?php
/************************************************************************/
/*     PROGRAMMER     :  SMA                                            */
/*     SCRIPT NAME    :  adminuser_edit.php                             */
/*     CREATED ON     :  10/JULY/2006                                   */
/*     MODERNIZED     :  20/AUG/2025                                     */
/*	Page to edit admin user. 											*/
/************************************************************************/

$adminobj = new adminuser();

$note     = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : '';
$username = isset($_REQUEST['username']) ? $_REQUEST['username'] : '';
$password = ''; // Do not prefill hashed password
$email    = isset($_REQUEST['email']) ? $_REQUEST['email'] : '';
$id       = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;

if ($id) {
    if ($adminobj->GetAdimUserDetails($id)) {
        $username = $adminobj->username;
        $email    = $adminobj->email;
        // $password is left blank to avoid showing hash
    }
}
?>

<form name="frm_users" method="post" action="adminusers_manage.php?mode=edit" onsubmit="return Validate();">
    <table border="0" cellpadding="0" cellspacing="0" class="tablebdr" width="65%" align="center">
        <tr>
            <td align="center" colspan="2" class="tdhead"><b>Edit Admin User</b></td>
        </tr>
        <tr><td height="10"></td></tr>
        <?php if ($note) { ?>
            <tr><td colspan="2" align="center" class="textred"><?= htmlspecialchars($note) ?></td></tr>
        <?php } ?>
        <tr>
            <td height="30" align="right" width="50%">Username&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td height="30" align="left" width="50%">
                <input type="text" name="txt_username" maxlength="25" value="<?= htmlspecialchars($username) ?>" />
            </td>
        </tr>
        <tr>
            <td height="30" align="right" width="50%">Password&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td height="30" align="left" width="50%">
                <input type="password" name="txt_password" maxlength="25" placeholder="Leave blank to keep existing" />
            </td>
        </tr>
        <tr>
            <td height="30" align="right" width="50%">Email&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td height="30" align="left" width="50%">
                <input type="email" name="txt_email" value="<?= htmlspecialchars($email) ?>" />
            </td>
        </tr>
        <tr>
            <td height="30" align="center" colspan="2">
                Send Mail to Admin User&nbsp;
                <input type="checkbox" name="chk_mail" />
            </td>
        </tr>
        <tr>
            <td height="30" align="center" colspan="2">
                <input type="submit" name="btn_update" value="Update" />
                <input type="hidden" name="id" value="<?= $id ?>" />
            </td>
        </tr>
    </table>
</form>

<script>
function Validate() {
    if (document.frm_users.txt_username.value.trim() === '') {
        alert('Please enter the username');
        document.frm_users.txt_username.focus();
        return false;
    }
    if (document.frm_users.txt_email.value.trim() === '') {
        alert('Please enter the Email Address');
        document.frm_users.txt_email.focus();
        return false;
    }
    return true;
}
</script>
