<?
//setup constants
$now_date = formatDate();
$now_timestamp = strtotime($now_date);
/****** INITIAL DATABASE FUNCTIONS ******/
function openDatabase() {
global $db_sock, $db_hostname, $db_username, $db_pass, $db_select, $database_down;
//open the database
if($db_sock = @mysql_connect($db_hostname, $db_username, $db_pass)) {
if(!mysql_select_db($db_select))
$database_down = 1;
} else {
$database_down = 1;
}
}
function closeDatabase() {
global $db_sock, $database_down;
mysql_close($db_sock);
$database_down = 1;
}
//open the database on init
openDatabase();
function getPage($page) {
global $database_down, $pages_table_name;
if(!$database_down) {
$result = mysql_query("SELECT * FROM $pages_table_name WHERE name=\"$page\"");
if($row = mysql_fetch_array($result)) {
$page_title = $row['page_title'];
$info = $row['info'];
} else {
$info = "<h1>404 Page Not Found</h1><p>The page you have requested could not be found.</p>";
$page_title = "Page Not Found";
}
} else {
$info = "<h1>Database Error</h1><p>The database is offline or inaccessible. Please try again later.</p>";
$page_title = "Database Error";
}
return array("page_title" => $page_title, "info" => $info);
}
/****** REGULAR USE FUNCTIONS ******/
function FormatDate() {
//creates dates in the format "yyyy-mm-dd hh:mm:ss"
global $time_offset;
if(!isset($time_offset))
$time_offset = 0;
return date("Y-m-d H:i:s", (time() + ($time_offset * 60 * 60)));
}
function validateEmail($email) {
//quick script to validate an email address
if(ereg("^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$", strtolower($email)))
return true;
}
?>