host = $host; $this->username = $username; $this->password = $password; $this->table = $db; $this->connect(); } /** deletes a report by is id */ public function delete_thread($id){ mysql_query("DELETE FROM comments WHERE report = '$id'"); return mysql_query("DELETE FROM threads WHERE id = '$id'")or die(mysql_error()); } /** diplays a list of exception reports, this list will link to the indiviual reports */ public function display_report_list() { /* Instantiate class */ require_once("pager.php"); $p = new Pager; /* Show many results per page? */ $limit = 5; /* Find the start depending on $_GET['page'] (declared if it's null) */ $start = $p->findStart($limit); /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */ $count = mysql_num_rows(mysql_query("SELECT * FROM threads")); /* Find the number of pages based on $count and $limit */ $pages = $p->findPages($count, $limit); /* Now we use the LIMIT clause to grab a range of rows */ $r = mysql_query("SELECT * FROM threads ORDER BY id LIMIT ".$start.", ".$limit); /* Now get the page list and echo it */ $pagelist = $p->pageList($_GET['page'], $pages); /* get all the reports */ $entry_display = '
'; while($thread = mysql_fetch_assoc($r)) { $title = $thread['title']; $id = $thread['id']; $author = $thread['author']; $entry_display .= << #$id $title Started by: $author
ENTRY_DISPLAY; } $entry_display .= '
'.$pagelist.'
'; return $entry_display; } /** This will display the specified report */ public function display_thread($id) { $id = mysql_real_escape_string($id); /* get all the reports */ $r = mysql_query("SELECT * FROM threads WHERE id=".$id); if($thread = mysql_fetch_assoc($r)) { $title = $thread['title']; $author = $thread['author']; $time = $thread['time']; $entry_display = <<$title Started By: $author ~ $time THREAD; if($_SESSION['access'] == "admin" || $_SESSION['username'] == $author) echo <<Delete Thread DELETE; /* comments */ require_once('comments.php'); $comments = new comments("comments",DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE); $entry_display .= $comments->get_comments($id); $entry_display .= $comments->display_post($id);; } else return "No Thread Found: $id"; return $entry_display; } /* Files a new exception report into the database */ public function file_thread($title, $author, $time){ /* add escapes to the data */ $title = mysql_real_escape_string($title); /* insert the new report */ $insert = "INSERT INTO threads (title, author, time) VALUES ('$title', '$author', '$time')"; mysql_query($insert); return mysql_insert_id(); } /* Connects the the database */ public function connect() { mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error()); mysql_select_db($this->table) or die("Could not select database. " . mysql_error()); return $this->buildDB(); } /** Builds the database that will be used to for exception reports */ private function buildDB() { $sql = <<