<?php
include '../includes/session.php';

$msg = isset($_GET['msg']) ? htmlspecialchars($_GET['msg']) : '';
$userobj = new adminuser();
$adminUserId = $_SESSION['ADMINUSERID'];

// Load error page content
$errorContent = '';
$errorFile = 'error.htm';
if (file_exists($errorFile) && is_readable($errorFile)) {
    $errorContent = file_get_contents($errorFile);
}
?>

<div align="center">
    <center>
        <?php if ($msg): ?>
            <p class="textred" style="text-align:center;">
                <small><?= $msg ?></small>
            </p>
        <?php endif; ?>

        <table border="0" cellpadding="2" cellspacing="1" width="90%" class="tablebdr">
            <!-- Change Email -->
            <tr><td colspan="4" class="tdhead"><b>Change the Administrator Email Address</b></td></tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr>
                <td width="18%">&nbsp;</td>
                <td width="82%" colspan="3">
                    <form name="mailupdate" action="admin_options_manage.php" method="post">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="30%" align="right">Email Address</td>
                                <td width="3%">&nbsp;</td>
                                <td width="41%">
                                    <input type="email" name="mail" size="26" value="<?= htmlspecialchars($_SESSION['MAIL']) ?>" tabindex="1" required />
                                </td>
                                <td width="26%" align="center">
                                    <input type="submit" value="Modify Mail" name="action" tabindex="2" />
                                </td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>

            <!-- Change Admin Login -->
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr><td colspan="4" class="tdhead"><b>Change the Administrator Login</b></td></tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr>
                <td>&nbsp;</td>
                <td colspan="3">
                    <form name="loginupdate" action="admin_options_manage.php" method="post">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="30%" align="right">Admin Login</td>
                                <td width="3%">&nbsp;</td>
                                <td width="41%">
                                    <input type="text" name="login" size="26" value="<?= htmlspecialchars($_SESSION['ADMIN']) ?>" tabindex="3" required />
                                </td>
                                <td width="26%" align="center">
                                    <input type="submit" value="Modify Login" name="action" tabindex="4" />
                                </td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>

            <!-- Change Password -->
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr><td colspan="4" class="tdhead"><b>Change Administrator Password</b></td></tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr>
                <td>&nbsp;</td>
                <td colspan="3">
                    <form name="passwordupdate" action="admin_options_manage.php" method="post">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="30%" align="right">Current Password</td>
                                <td width="3%">&nbsp;</td>
                                <td width="41%">
                                    <input type="password" name="pass1" size="26" tabindex="5" required />
                                </td>
                                <td width="26%" rowspan="3" align="center">
                                    <input type="submit" value="Modify Password" name="action" tabindex="8" />
                                </td>
                            </tr>
                            <tr><td colspan="3" height="3"></td></tr>
                            <tr>
                                <td align="right">New Password</td>
                                <td>&nbsp;</td>
                                <td><input type="password" name="pass2" size="26" tabindex="6" required /></td>
                            </tr>
                            <tr><td colspan="3" height="3"></td></tr>
                            <tr>
                                <td align="right">Confirm New Password</td>
                                <td>&nbsp;</td>
                                <td><input type="password" name="pass3" size="26" tabindex="7" required /></td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>

            <!-- Change Site Title and Lines Per Page -->
            <?php if ($userobj->GetAdminUserLink('Administrator Settings', $adminUserId, 6)): ?>
                <tr><td colspan="4">&nbsp;</td></tr>
                <tr><td colspan="4" class="tdhead"><b>Change Page Settings</b></td></tr>
                <tr><td colspan="4">&nbsp;</td></tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <form action="admin_options_manage.php" method="post">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="30%" align="right">Site Title</td>
                                    <td width="3%">&nbsp;</td>
                                    <td width="44%">
                                        <input type="text" name="new_title" size="26" tabindex="9" value="<?= htmlspecialchars(stripslashes($title)) ?>" />
                                    </td>
                                    <td width="23%" align="center">
                                        <input type="submit" value="Change Title" name="action" tabindex="10" />
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <form action="admin_options_manage.php" method="post">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="30%" align="right">Number of Records per Page</td>
                                    <td width="3%">&nbsp;</td>
                                    <td width="41%">
                                        <input type="number" name="number" size="10" value="<?= htmlspecialchars($lines) ?>" tabindex="11" required />
                                    </td>
                                    <td width="26%" align="center">
                                        <input type="submit" value="Change Lines/Page" name="action" tabindex="12" />
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </td>
                </tr>

                <!-- Error Page Settings -->
                <tr><td colspan="4">&nbsp;</td></tr>
                <tr><td colspan="4" class="tdhead"><b>Error Page Settings</b></td></tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <form name="error_page" action="admin_options_manage.php" method="post">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="30%" align="right" valign="top">Set Error Page</td>
                                    <td width="3%">&nbsp;</td>
                                    <td width="48%">
                                        <textarea name="error" rows="6" cols="50"><?= htmlspecialchars($errorContent) ?></textarea>
                                    </td>
                                    <td width="19%" align="center">
                                        <input type="submit" value="Error Page Setting" name="action" tabindex="13" />
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </td>
                </tr>
            <?php endif; ?>
        </table>
    </center>
</div>
<br />
