<?php
include_once "../../../tools/inc.php";
$page = include("../../common.php");
include("../tools/function.string.php");
include("../tools/function.sql.php");
$n=$settings["rec_count"];
$table="pages".$config["table_prefix"];
$access=check_level("Subscribe Page");
$name="subscribe_page";

$message_list=array(
	1 => "{rs:MSG_SUBSCRIPTION_PAGE} {rs:MSG_UPDATED}",
);

$mail_mode_list=array(
	0 => "{rs:MAIL_MODE_0}",
	1 => "{rs:MAIL_MODE_1}",
);

$message=new Message();
$error=new Message("error");
if (isset($_r)) $message->add($message_list[$_r]);

$sql="select * from $table where name='$name'";
$rs=$db->select($sql);
$data=$rs[0];
$edit=isset($data["name"]);
if (isset($save) and (isset($access["edit"]) or isset($access["admin"]))) {
	$r=check_array($r, "description");
	$r["name"]=$name;
	if ($save) {
		$fields="description";
		$sql=($edit ? get_sql_update($table, $fields, $r, "where name='$name'") : get_sql_insert($table, $fields.", name", $r));
		$db->execute($sql);
		$db->close();
		$link->add("_r", "1");
		header("Location: ".$link->get());
		exit;
	} else $data=html_string($r, true);
	$page->section("SUBSCRIBE_PAGE");
        $page->assign($data);
} elseif (isset($access["view"]) or isset($access["admin"])) {
        if (!isset($data["name"])) {
		$data=array("description" => "%form%");
	}
	$data=html_string($data);
	$page->section("SUBSCRIBE_PAGE");
        $page->assign($data);
} else {
	$page->section("ACCESS_DENIED");
	$error->add("{rs:ERROR_ACCESS_RESTRICTED}");
}
add_to_tree("{rs:TITLE_DESIGN}", "design/");
add_to_tree("{rs:TITLE_SUBSCRIPTION_PAGE}", "design/subscribe_page/");
$db->close();
$page->assign(array(
	"TITLE"			=> "{rs:TITLE_SUBSCRIPTION_PAGE}",
	"ERROR"			=> ($error->count ? $error->get() : ""),
	"MESSAGE"		=> ($message->count ? $message->get() : ""),
	"LINK"			=> $link->get(),
	"is_design"		=> 1,
	"IMG"			=> "subscription_page.gif",
	"BACK_LINK"		=> $PATH,
	"BACK_TITLE"		=> "{rs:TITLE_MAIN_MENU}",
	"WINDOW_TITLE"		=> "{rs:EDIT_SUBSCRIPTION_PAGE}",
));
print $page->evaluate();
?>