header('Content-type: text/html');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('X-Content-Type-Options: nosniff');
?>
//////////////////////////////////////////////
// towninfo.php
// Author: Derek Myska
//
// -- description --
// handles all left hand navigation links
//////////////////////////////////////////////
include_once("/mnt/cluster/www6/readysetgov/includes/common.php");
include_once('include/config.php');
include_once('include/lib.php');
clean_params();
// globals
$town = $_REQUEST['t'];
$page = $_REQUEST['p'];
$errors = array();
$errorMessage = '';
$leftNav = '';
$townName = '';
$townLink = '';
$pageTitle = '';
$output = '';
// run script
main();
//////////////////////////////////////////////
// script controller
//////////////////////////////////////////////
function main() {
if (validate()) {
$output = build_page();
}
else {
error();
}
}
//////////////////////////////////////////////
// validate input
//////////////////////////////////////////////
function validate() {
global $dbh, $errors, $town, $page, $leftNav, $townName, $townLink;
if (!preg_match('/^\d+$/', $town)) {
array_push($errors, "The town selected does not exist.");
}
else {
$query = @mysql_query(
"SELECT COUNT(*) as total
FROM towns
WHERE town_id='".$town."'"
);
$row = mysql_fetch_assoc($query);
if (!$row['total'] > 0) {
array_push($errors, "The town selected does not exist.");
}
else {
$name = get_town_name($town);
$townLink = "Town of ".ucwords($name)."";
$leftNav = build_left_nav($town, $townName, $page);
if (!preg_match('/^\d+$/', $page)) {
array_push($errors, "The page you selected to view does not exist.");
}
else {
$query = @mysql_query(
"SELECT COUNT(*) as total
FROM pages
WHERE page_town_id='$town'
AND page_id='".$page."'"
);
$row = mysql_fetch_assoc($query);
if (!$row['total'] > 0) {
array_push($errors, "This section is not available for the selected town.");
}
if (!preg_match('/^\s*$/', $_REQUEST['nid']) and !preg_match('/^\d+$/', $_REQUEST['nid'])) {
array_push($errors, "The headline you selected does not exist.");
}
else {
$query = @mysql_query(
"SELECT COUNT(*) as total
FROM news
WHERE news_town_id='$town'
AND news_id='".$_REQUEST['nid']."'"
);
if (!$row['total'] > 0) {
array_push($errors, "This headline is not available for the selected town.");
}
}
if (!preg_match('/^\s*$/', $_REQUEST['mid']) and !preg_match('/^\d+$/', $_REQUEST['mid'])) {
array_push($errors, "The meeting you selected does not exist.");
}
else {
$query = @mysql_query(
"SELECT COUNT(*) as total
FROM town_meeting
WHERE town_meeting_town_id='$town'
AND town_meeting_id='".$_REQUEST['mid']."'"
);
if (!$row['total'] > 0) {
array_push($errors, "This meeting is not available for the selected town.");
}
}
}
}
}
if (count($errors) > 0) {
return false;
}
else {
return true;
}
}
//////////////////////////////////////////////
// if there are errors, handle them
//////////////////////////////////////////////
function error() {
global $errors, $errorMessage;
foreach ($errors as $key => $value) {
$errorMessage .= $value . "
";
}
}
//////////////////////////////////////////////
// everything worked
//////////////////////////////////////////////
function build_page() {
global $town, $page, $pageTitle, $dbh;
$query = @mysql_query(
"SELECT page_title
FROM pages
WHERE page_town_id='$town'
AND page_id='".$page."'"
);
$row = mysql_fetch_assoc($query);
$pageTitle = $row['page_title'];
}
//////////////////////////////////////////////
// comment form
//////////////////////////////////////////////
function get_comment_form() {
global $page, $dbh;
$query = @mysql_query(
"SELECT page_value_module_option_id, page_value_data
FROM published_page_values
WHERE page_value_page_id='$page'"
);
$info = array();
while ($row = mysql_fetch_assoc($query)) {
$info[$row['page_value_module_option_id']] = $row['page_value_data'];
}
$form = "