<?php defined( '_BIGNIGHT_EXEC' ) or die( 'Restricted access' );?>
<?php 
// Configuration
define(HOME,"http://146.245.250.215/~achikin/project/");

// database
define(DB_NAME,"achikin");
define(DB_HOST,"localhost");
define(DB_PORT,3306);
define(DB_USER,"achikin");
define(DB_PASS,"mycishw");

// website preferences
define(PER_PAGE,7);
define(HOT_COUNT,3);
define(READ_MORE,80);
define(DEFAULT_ZIP,10001);

?>
<?php

function View($mode = null){
	if ($mode == null || $mode == "") {
		require_once("view/default.php");
	} else {
		if (!file_exists("view/" . $mode . ".php")){
			header('Location: index.php');
		} else {
			require_once("view/" . $mode . ".php");
		}
	}
}

abstract class Database_Object
{
    protected static $DB_Name;
    protected static $DB_Open;
    protected static $DB_Conn;

    protected function __construct($database, $hostname, $hostport, $username, $password)
    {
        self::$DB_Name = $database;
        self::$DB_Conn = mysql_connect($hostname . ":" . $hostport, $username, $password);
        if (!self::$DB_Conn) { die('Critical Stop Error: Database Error<br />' . mysql_error()); }
        mysql_select_db(self::$DB_Name, self::$DB_Conn);
    }

    private function __clone() {}

    public function __destruct()
    {
           // mysql_close(self::$DB_Conn);  // <-- commented out due to current shared-link close 'feature'.  If left in, causes a warning that this is not a valid link resource.
    }
}

final class DB extends Database_Object
{
    public static function Open($database = DB_NAME, $hostname = DB_HOST, $hostport = DB_PORT, $username = DB_USER, $password = DB_PASS)
    {
        if (!self::$DB_Open)
        {
            self::$DB_Open = new self($database, $hostname, $hostport, $username, $password);
        }
        else
        {
            self::$DB_Open = null;
            self::$DB_Open = new self($database, $hostname, $hostport, $username, $password);
        }
        return self::$DB_Open;
    }

    public function qry($sql, $return_format = 0)
    {
        $query = mysql_query($sql, self::$DB_Conn) OR die(mysql_error());
		if ($query===false) self::$rows = 0;
		else if ($query===true) self::$rows = 1;
		else self::$rows = mysql_num_rows($query);
		
        switch ($return_format)
        {
            case 1:
                $query = mysql_fetch_row($query);
                return $query;
                break;
            case 2:
                $query = mysql_fetch_array($query);
                return $query;
                break;
            case 3:
                $query = mysql_fetch_row($query);
                $query = $query[0];
                return $query;
				break;
            case 4:
                $query = mysql_fetch_assoc($query);
                return $query;
				break;
			case 5:	// array of elements in first field
				$array = array();
				while($row = mysql_fetch_row($query)){
					$array[]=$row[0];
				}
				return $array;
				break;
            default:
				return $query;
        }
    }
	
	private static $rows=0;
	
	public function numrows(){
		return self::$rows;
	}
}

function get_events($add = -1){
	global $user;
	$blob = "<img src=\"images/icons/attending.png\"> <b>My events:</b><hr>";
	if($user === NULL){
		$blob .= "Please <a href=\"index.php?view=user\">log in</a> in order to add events.";
		return $blob;
	}
	global $DB;
	$result = $DB->qry("SELECT e.title,e.id,e.time FROM events e JOIN attending a ON e.id=a.event_id WHERE a.username='{$user["username"]}' AND time>" . (time()-48*3600) . " ORDER BY time ASC LIMIT 15;");

	if($DB->numrows()==0){
		$blob .= " Use 'attend' button in event details to join events.";
		return $blob;
	}
	while($row = mysql_fetch_assoc($result)){
		if(strlen($row["title"])>15){
			$title = substr_replace("{$row["title"]}","...",(strpos($row["title"]," ",15)==0 || strpos($row["title"]," ",15)>20 ? 15 : strpos($row["title"]," ",15)));
		} else $title = $row["title"];
		$blob .= "<div class=\"event_link\" id=\"el{$row["id"]}\" onMouseover=\"changeTo('el{$row["id"]}');\" onMouseout=\"changeBack('el{$row["id"]}')\"; " . ($_GET["view"]=="event" && $_GET["id"]==$row["id"] || $row["id"]==$add ? "style=\"background:#000000; color:#FFFFFF;\"" : "onclick=\"location.href='index.php?view=event&id={$row["id"]}'\" style=\"cursor: url('css/cursors/cd_pointer_blue.cur'),pointer;\"" ) . ">{$title}<br><div class=\"event_date\">" . gmdate("l, M j",$row["time"]) . "</div><hr></div>";
	}
	return $blob;
}

function get_subscriptions($add = ""){
	global $user;
	$blob = "<img src=\"images/icons/email.gif\"> <b>Subscriptions:</b><hr>";
	if($user === NULL){
		$blob .= "Please <a href=\"index.php?view=user\">log in</a> in order to subscribe.";
		return $blob;
	}
	global $DB;
	$result = $DB->qry("SELECT u.name,u.username FROM subscriptions s JOIN users u ON s.host=u.username WHERE s.subscriber='{$user["username"]}' ORDER BY IF(u.name='',u.username, u.name) ASC LIMIT 15;");

	if($DB->numrows()==0){
		$blob .= " Use 'subscribe' button in user details to receive e-mail notifications.";
		return $blob;
	}
	while($row = mysql_fetch_assoc($result)){
		$count = $DB->qry("SELECT COUNT(id) AS cnt FROM events WHERE username='{$row["username"]}' AND time>" . (time()-24*3600) . " AND time<" . (time()+14*24*3600) . ";",3);
		$blob .= "<div class=\"event_link\" id=\"el{$row["username"]}\" onMouseover=\"changeTo('el{$row["username"]}');\" onMouseout=\"changeBack('el{$row["username"]}')\"; " . ($_GET["view"]=="user" && $_GET["name"]==$row["username"] || $row["username"]==$add ? "style=\"background:#000000; color:#FFFFFF;\"" : "onclick=\"location.href='index.php?view=user&name={$row["username"]}'\" style=\"cursor: url('css/cursors/cd_pointer_blue.cur'),pointer;\"") . ">{$count} <img src=\"images/icons/calendar.gif\" title=\"Events within 2 weeks\"> " . (empty($row["name"])?$row["username"]:$row["name"]) . "<hr></div>";
	}
	return $blob;
}

function search_results($result,$pages = false,$search=""){
	if (mysql_num_rows($result)===0){
		echo "<div id=\"count\">No events found</div>";
	} else {
		$count = ($pages ? $pages : mysql_num_rows($result));
		
		global $DB;
		global $user;
			
		echo "<div id=\"count\">Found {$count} event" . ($count==1 ? "" : "s") . ".</div>";
		
		if($pages) display_pages($pages,$search);
			
		echo "<table width=100% class=\"tabless\">";
		while($row = mysql_fetch_assoc($result)){
			
			if(!empty($row["description"])){
				if(strlen($row["description"])>READ_MORE){
					$desc_str = substr_replace("{$row["description"]}","...",(strpos($row["description"]," ",READ_MORE)==0 || strpos($row["description"]," ",READ_MORE)>READ_MORE+10 ? READ_MORE : strpos($row["description"]," ",READ_MORE)));
				} else {
					$desc_str = $row["description"];
				}
			} else {
				$desc_str = "-- -- --";
			}
			
			if(file_exists("images/icons/" . $row["type"] . "-small.png")){
				$icon_str = "images/icons/" . $row["type"] . "-small.png";
			} else {
				$icon_str = "images/icons/Default-small.png";
			}
				
			echo "<tr id=\"A{$row["id"]}\" onMouseover=\"changeTo('A{$row["id"]}'); changeTo('B{$row["id"]}');\" onMouseout=\"changeBack('A{$row["id"]}'); changeBack('B{$row["id"]}');\" onclick=\"location.href='index.php?view=event&id={$row["id"]}'\">";
			echo "<th colspan=4><div style=\"display:inline;\"><img src=\"{$icon_str}\"> <b>{$row["title"]}</b></div><div class=\"row_info\">";
			
			$attending = $DB->qry("SELECT event_id AS attending FROM attending WHERE event_id={$row["id"]} AND username='{$user["username"]}';",3);
			$att_cnt = attend_count($row["id"]);
			if($att_cnt>=3) echo "<img src=\"images/icons/hot.png\" title=\"Hot!\"> ";
			if(is_subscribed($row["username"])) echo "<img src=\"images/icons/email.gif\" title=\"You are subscribed to {$row["name"]}'s events\"> ";
			if($attending!==NULL) echo "<img src=\"images/icons/attending.png\" title=\"You are attending\"> ";
			echo "<img src=\"images/icons/people.png\" title=\"People attending\">" . (!empty($att_cnt) ? $att_cnt : "0");
			if($user["username"]==$row["username"]) echo "<img src=\"images/icons/arrow.png\" title=\"You own this event\"> ";
			
			echo "</div></th></tr>";
			echo "<tr id=\"B{$row["id"]}\" onMouseover=\"changeTo('B{$row["id"]}'); changeTo('A{$row["id"]}');\" onMouseout=\"changeBack('B{$row["id"]}'); changeBack('A{$row["id"]}');\" colspan onclick=\"location.href='index.php?view=event&id={$row["id"]}'\">";
			echo "<td>{$row["address"]}, {$row["zip"]}</td><td>{$desc_str}</td><td>" . gmdate("m/d/y", $row["time"]) . "</br>" . gmdate("g:ia", $row["time"]) . "</td><td style=\"text-align:right;\"> \${$row["price"]}</td></tr>";
			
		}
		echo "<tr><th colspan=4></th></tr>";
		echo "</table>";
		
		if($pages) display_pages($pages,$search);
	}
}

function attend_count($event_id){
	global $DB;
	return $DB->qry("SELECT COUNT(username) FROM attending WHERE event_id={$event_id};",3);
}

function get_people($event_id){
	global $DB;
	$people = $DB->qry("SELECT a.username, u.name FROM attending a JOIN users u ON a.username=u.username WHERE event_id={$event_id} ORDER BY IF(u.name='',a.username, u.name) ASC LIMIT 50;");
	$count = $DB->numrows();
	if($count===0) return " none";
	$blob = "";
	$i=0;
	while($person = mysql_fetch_assoc($people)){
		$blob .= " <a href=\"index.php?view=user&name={$person["username"]}\">" . (empty($person["name"])?$person["username"]:$person["name"]) . "</a>" . ($count==++$i?"":",");
	}
	if($count==50) $blob .= " ...";
	return $blob;
}

function is_subscribed($host){
	global $user;
	global $DB;
	$host = str_replace("'","''",$host);
	$subscribed = $DB->qry("SELECT * FROM subscriptions WHERE subscriber='{$user["username"]}' AND host='{$host}';",3);
	return ($subscribed === NULL ? false : true);
}

function get_user_by_name($name,$check_block=false){
	global $DB;
	$username_search = str_replace("'","''",$name);
	$result = $DB->qry("SELECT u.*,z.city,z.state_prefix AS state,z.lat,z.lon,r.rank,r.id AS rank_id FROM users u LEFT JOIN zip_code z ON u.zip=z.zip_code LEFT JOIN ranks r ON u.permissions=r.id WHERE username='$username_search'" . ($check_block?" AND blocked=0;":";"),4);
	if($DB->numrows()===0) return null;
	return $result;
}

function get_ranks(){
	global $DB;
	$result = $DB->qry("SELECT rank FROM ranks ORDER BY id ASC;",5);
	if($DB->numrows()===0) return null;
	return $result;
}

function get_page_limit($per_page=PER_PAGE){
	if (isset($_GET["page"])) $current = intval($_GET["page"]);
	else $current = 1;
	if($current<1) $current = 1;
	
	return " LIMIT " . (($current-1)*$per_page) . ", {$per_page}";
}

function display_pages($count, $search="", $per_page=PER_PAGE){
	if($count<2) return;
	if (isset($_GET["page"])) $current = intval($_GET["page"]);
	else $current = 1;
	if($current<1) $current = 1;
	
	$pages = ceil($count/$per_page);
	$dots = false;
	echo "<center>";
	echo ($current==1 ? "Prev" : "<a href=\"index.php?{$search}page=" . ($current-1) . "\">Prev</a>") . " ";
	if($search!=="") $search .= "&";
	for($i=1;$i<=$pages;$i++)
		if(abs($current-$i)<=2 || $i==1 || $i==$pages) {
			echo ($i==$current ? "[ $i ]" : "<a href=\"index.php?{$search}page=" . ($i) . "\">[ {$i} ]</a>") . " ";
			$dots = false;
		} else if(!$dots) {
			echo " ... ";
			$dots = true;
		}
	echo ($current==$pages ? "Next" : "<a href=\"index.php?{$search}page=" . ($current+1) . "\">Next</a>");
	echo "</center>";
}


function get_param($key){
	if(!empty($_POST[$key])) return $_POST[$key];
	else if(!empty($_GET[$key])) return $_GET[$key];
	else return "";
}

function make_get_url(){
	$params = $_GET;
	unset($params["page"]);
	foreach($_POST as $key=>$value){
		if(!empty($_POST[$key]))
			$params[$key]=$value;
	}
	return http_build_query($params);
}

function display_avatar($user,$edit=false,$admin=false){
	echo "<div class=\"avatars\">";
	if($edit) echo "<a href=\"index.php?view=avatar\">";
	if($admin) echo "<img src=\"../images/avatars/";
	else echo "<img src=\"images/avatars/";
	if ($user["avatar"] == 0){
		// custom
		if(file_exists("images/avatars/" . $user["username"] . ".jpg") || file_exists("../images/avatars/" . $user["username"] . ".jpg"))
			echo $user["username"];
		else
			echo "1";	// default
	} else {
		// from list
		if(file_exists("images/avatars/" . $user["avatar"] . ".jpg") || file_exists("../images/avatars/" . $user["avatar"] . ".jpg"))
			echo $user["avatar"];
		else
			echo "1";	// default
	}
	echo ".jpg\" alt=\"Avatar\">";
	if($edit) echo "</a>";
	echo "</div>";
}

/*
function featured_events($zip){
	$parser=xml_parser_create();
	
	function start($parser,$element_name,$element_attrs){
		switch($element_name){
			case "EVENT":
			echo "<font color=\"#BB3333\">-- event --</font><br />";
			break;
			case "TITLE":
			echo "<font color=\"#3333BB\">title:</font> ";
			default;
		}
	}
	
	function stop($parser,$element_name){
		echo "<br />";
	}
	
	function char($parser,$data){
		echo $data;
	}
	
	xml_set_element_handler($parser,"start","stop");
	xml_set_character_data_handler($parser,"char");
//	$url = "http://api.eventful.com/rest/events/search?app_key=rqvfvQBTxm3SxT4k&location={$zip}&within=15&units=mi&sort_order=relevance&date=This%20Week";

	$url = "xml/eventful_{$zip}.xml";
	$fp=fopen($url,"r");
	while ($data=fread($fp,4096)){
		xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error!"));
	}
	xml_parser_free($parser);	
}
*/

function featured_events($zip=DEFAULT_ZIP){
	$filename = "xml/eventful_" . DEFAULT_ZIP . ".xml";
	if(!file_exists($filename)) return;
	$fh = fopen($filename, "r");
	$temp = fread($fh, filesize($filename));
	$xml = new SimpleXMLElement($temp);

	// generate 3 random numbers
	$count = count($xml->events->event);
	for ($i = 0; $i < 3; $i++)
		$random[] = rand(0, $count - 1);
	while ($random[1] == $random[0])
		$random[1] = rand(0, $count - 1);
	while ($random[2] == $random[0] || $random[2] == $random[1])
		$random[2] = rand(0, $count - 1);

	echo '<hr><center><b>Featured Events:</b></center><table
	cellspacing=15 cellpadding=11><tr>';
	for ($i = 0; $i < 3; $i++){
		$title = $xml->events->event[$random[$i]]->title;
		$title = (strlen($title)>45 ? substr_replace($title,"...",(strpos($title," ",45)==0 || strpos($title," ",45)>45+10 ? 45 : strpos($title," ",45))) : $title);
		$url = $xml->events->event[$random[$i]]->attributes();
		$start_time = $xml->events->event[$random[$i]]->start_time;
		$description = $xml->events->event[$random[$i]]->description;
		$description = (strlen($description)>READ_MORE ? substr_replace($description,"...",(strpos($description," ",READ_MORE)==0 || strpos($description," ",READ_MORE)>READ_MORE+10 ? READ_MORE : strpos($description," ",READ_MORE))) : $description);
		$image = $xml->events->event[$random[$i]]->image->medium->url;
		$td = '<font face="arial" color="#ffffff"><a target=\"_blank\"
		href="http://eventful.com/' . $url . '"><b><div
		style="line-height:18px">' . $title . '</div></b></a>';
		$td .= $start_time . '</font></p>';
		$td .= "<center><a target=\"_blank\" href=\"http://eventful.com/{$url}\"><img src=\"{$image}\"></a></center>";
		$td .= '<font face="arial" color="#ffffff" size=2><div
		style="line-height:16px">' . $description . '</div></font>';
		echo '<td width=222 style="background:url(images/trans-bg.png);" valign="top">' . $td . '</td>';
	}
	echo '</tr></table>';
}

function display_comments($id,$edit=true){
	echo "<hr>";

	global $DB;
	global $user;
	
	$limit = get_page_limit();
	$result = $DB->qry("SELECT SQL_CALC_FOUND_ROWS c.*,u.name FROM comments c JOIN users u ON u.username=c.username WHERE event_id={$id} ORDER BY time DESC {$limit};");
	$total = $DB->qry("SELECT FOUND_ROWS();",3);
	
	echo "<center><div id=\"comments_error\" style=\"color:#FF9900; font-weight:bold;\"></div>";
	if($user!==NULL){	// comment form
		echo "<a href=\"javascript:void(0)\" onclick=\"javascript:expand('post')\">post a comment </a><a id=\"expand_link\" href=\"javascript:void(0)\" onclick=\"javascript:expand('post')\">[ " . ($total==0?"-":"+") . " ]</a></center>";
		echo "<div class=\"comment\" id=\"post\" " . ($total==0?"":"style=\"display:none\"") . "><div class=\"avatar_area\"><a href=\"index.php?view=user\">";
		echo (empty($user["name"])?$user["username"]:$user["name"]);
		display_avatar($user);
		echo "</a></div>";
		echo "<div class=\"comment_area\">enter text:<br>";
		echo "<textarea id=\"new_comment\" rows=\"2\" cols=\"60\" name=\"comment\" onKeyPress=\"enter(event,{$id});\"></textarea>";
		echo "&nbsp;&nbsp;&nbsp;<input type=\"submit\" id=\"post_comment\" onclick=\"javascript:comment({$id})\" name=\"submit\" value=\"Submit\"></div></div>";
	} else {
		echo "Please <a href=\"index.php?view=user\">log in</a> in order to post comments</center>";
	}

	while($row = mysql_fetch_assoc($result)){
		echo "<div class=\"comment\"><div class=\"avatar_area\"><a href=\"index.php?view=user&name={$row["username"]}\">";
		echo (empty($row["name"])?$row["username"]:$row["name"]);
		display_avatar(get_user_by_name($row["username"]));
		echo "</a></div>";
		echo "<div class=\"comment_area\"><small>" . gmdate("g:i a, F j, Y",$row["time"]) . "</small><br>";
		echo $row["comment"];
		echo "</div>" . ($user["username"]==$row["username"] ? "<a class=\"delete_comment\" href=\"javascript:void(0);\" onclick=\"javascript:delete_comment({$id},{$row["id"]})\"><img title=\"Delete\" src=\"images/icons/delete.gif\"></a>" : "") . "</div>";
	}
	display_pages($total,"view=event&id={$id}");
}

function getIP() {
	$ip;
	if (getenv("HTTP_CLIENT_IP"))
		$ip = getenv("HTTP_CLIENT_IP");
	else if(getenv("HTTP_X_FORWARDED_FOR"))
		$ip = getenv("HTTP_X_FORWARDED_FOR");
	else if(getenv("REMOTE_ADDR"))
		$ip = getenv("REMOTE_ADDR");
	else
		$ip = "UNKNOWN";
	return $ip;
}

function getZipByIP($ip){
	global $DB;
	$zip = $DB->qry("SELECT zip FROM ip_db WHERE ip={$ip};",3);
	return $zip;
}

function get_zip_pos($zip){
	$zip = intval($zip);
	global $DB;
	$result = $DB->qry("SELECT zip_code AS zip,city,state_prefix AS state,lat,lon FROM zip_code WHERE zip_code={$zip};",4);
	return $result;
}

function email_comment_subs($comment_id){

	global $DB;
	$id = intval($comment_id);
	$comment = $DB->qry("SELECT * FROM comments WHERE id={$id};",4);
	if($DB->numrows()===0) return;
	
	$event = $DB->qry("SELECT id,username,title FROM events WHERE id={$comment["event_id"]};",4);
	if($DB->numrows()===0) return;
	
	$subs = array();
	// creator of event
	$subs[] = $event["username"];
	// get people who commented on this post
	$commented = $DB->qry("SELECT DISTINCT username FROM comments WHERE event_id={$event["id"]};",5);
	foreach($commented as $sub) if(!in_array($sub,$subs)) $subs[]=$sub;
	// get people who are attending the event
	$subscribers = $DB->qry("SELECT username FROM attending WHERE event_id={$event["id"]};",5);
	foreach($subscribers as $sub) if(!in_array($sub,$subs)) $subs[]=$sub;
	
	$headers = 'From: Big Night Out Admin' . "\r\n" . 'Reply-To: admin@paindealers.org';
	$message = "\n\nYou are subscribed to an event '{$event["title"]}' at Big Night Out website.\n" . get_name($comment["username"]) . " has left a comment:\n\n\t{$comment["comment"]}\n\nFollow the link to see this event:\n" . HOME . "index.php?view=event&id={$event["id"]}\n\nThis e-mail was generated automatically, please do not reply. You will not receive any more e-mails before you log on.\nIn order to unsubscribe from e-mail notifications go to your profile and uncheck 'Receive subscriptions':\n" . HOME . "index.php?view=user&details=1\n\nBest regards,\nAdministrator";
	$subject = "Big Night Out - Subscription";
	foreach($subs as $sub){	// email subscribers
		if(subs_status($sub) && $sub!=$comment["username"]){ // check if subs enabled and if it's the user himself
			$email = $DB->qry("SELECT email FROM users WHERE username='{$sub}';",3);
			$sent = mail($email, $subject, "Hello, " . get_name($sub) . $message, $headers);
			if($sent) $DB->qry("UPDATE users SET got_email=1 WHERE username='{$sub}';");
		}
	}
}

function email_user_subs($event_id){
	global $DB;
	$id = intval($event_id);
	$event = $DB->qry("SELECT * FROM events WHERE id={$id};",4);
	$subs = $DB->qry("SELECT subscriber AS username FROM subscriptions WHERE host='{$event["username"]}';");
	
	$headers = 'From: Big Night Out Admin' . "\r\n" . 'Reply-To: admin@paindealers.org';
	$message = "\n\nYou are subscribed to events by '" . get_name($event["username"]) . "' at Big Night Out website.\n" . get_name($event["username"]) . " has created an event:\n\n\t{$event["title"]}:\n\t{$event["description"]}\n\nFollow the link to see this event:\n" . HOME . "index.php?view=event&id={$id}\n\nThis e-mail was generated automatically, please do not reply. You will not receive any more e-mails before you log on.\nIn order to unsubscribe from e-mail notifications go to your profile and uncheck 'Receive subscriptions':\n" . HOME . "index.php?view=user&details=1\n\nBest regards,\nAdministrator";
	$subject = "Big Night Out - Subscription";
	foreach($subs as $sub){	// email subscribers
		if(subs_status($sub) && $sub!=$event["username"]){ // check if subs enabled and if it's the user himself
			$email = $DB->qry("SELECT email FROM users WHERE username='{$sub}';",3);
			$sent = mail($email, $subject, "Hello, " . get_name($sub) . $message, $headers);
			if($sent) $DB->qry("UPDATE users SET got_email=1 WHERE username='{$sub}';");
		}
	}
}

function subs_status($username){
	global $DB;	// check if user has subs enabled and if he already received sub after last time he logged on
	$user = $DB->qry("SELECT subs,got_email FROM users WHERE username='{$username}';",4);
	return ($user["subs"] && !$user["got_email"]);
	
}

function get_name($username){
	global $DB;
	$name = $DB->qry("SELECT name FROM users WHERE username='{$username}';",3);
	return (empty($name)?$username:$name);
}

function delete_event($event_id){
	global $DB;
	$id = intval($event_id);
	$DB->qry("DELETE FROM attending WHERE event_id={$id}");
	$DB->qry("DELETE FROM comments WHERE event_id={$id}");
	$DB->qry("DELETE FROM events WHERE id={$id}");
}

?>