<?php
//############################################################################//
// Created             : 19/Oct/2004
// Last Modified       : Updated to modern PHP in 2025
// Script Name         : admin_terms.php
//============================================================================//
// Admin can set the terms and conditions through this section
//############################################################################//

include '../includes/session.php';
include '../includes/constants.php';
include '../includes/functions.php';
include_once '../includes/allstripslashes.php';

// Added by SMA on 14-July-2006 for Admin Users
$userobj = new adminuser();
$adminUserId = isset($_SESSION['ADMINUSERID']) ? (int)$_SESSION['ADMINUSERID'] : 0;
// End Add on 14-July-2006

$proceed = 0;
$type = isset($_GET['type']) ? trim($_GET['type']) : '';

if ($type === "merchant") {
    if ($userobj->GetAdminUserLink('Merchant Generic Terms & Conditions', $adminUserId, 6)) {
        $proceed = 1;
    } else {
        include('permission_denied.php');
    }
} else {
    if ($userobj->GetAdminUserLink('Affiliates Generic Terms & Conditions', $adminUserId, 6)) {
        $proceed = 1;
    } else {
        include('permission_denied.php');
    }
}

if ($proceed === 1) {
    if ($type === "merchant") {
        $filename = "mer_terms.htm";
        $caption = "Change Merchant Terms And Conditions";
    } else {
        $filename = "terms.htm";
        $caption = "Change Affiliate Terms And Conditions";
    }

    $contents = '';
    if (file_exists($filename) && is_readable($filename)) {
        $fp = fopen($filename, 'r');
        if ($fp) {
            $contents = fread($fp, filesize($filename));
            fclose($fp);
        }
    }

    $msg = isset($_GET['msg']) ? htmlspecialchars($_GET['msg']) : '';
    ?>

    <form name="terms_page" action="terms_validate.php?type=<?= htmlspecialchars($type) ?>" method="post">
    <table border="0" cellpadding="2" cellspacing="1" width="90%" class="tablebdr">
        <tr>
            <td colspan="4" class="tdhead"><b><?= htmlspecialchars($caption) ?></b></td>
        </tr>
        <tr>
            <td colspan="4" class="textred" align="center"><?= $msg ?></td>
        </tr>
        <tr>
            <td width="20%">&nbsp;</td>
            <td width="28%"><b>Set Terms &amp; Conditions</b></td>
            <td width="31%">
                <textarea rows="10" name="error" cols="60"><?= htmlspecialchars($contents) ?></textarea>
            </td>
            <td width="23%" align="center">
                <input type="submit" value="Change" name="action" />
            </td>
        </tr>
        <tr>
            <td colspan="4"></td>
        </tr>
    </table>
    </form>

<?php
} // end if $proceed
?>
<br />
