host = $host; $this->username = $username; $this->password = $password; $this->table = $db; $this->connect(); } /** Generates and sends a email to notify users of their email */ function sendEmail($userEmail, $title, $body){ mail( $userEmail , $title , $body); } public function email_guests($title, $body){ $r = mysql_query("SELECT * FROM guests"); if ( $r !== false && mysql_num_rows($r) > 0 ) while ( $a = mysql_fetch_assoc($r) ) $this->sendEmail($a['email'], $title, $body); } /** Display all users as links that remove them */ public function display_guest_list() { $entry_display .= '

Guest List:

'; /* Instantiate class */ require_once("pager.php"); $p = new Pager; /* Show many results per page? */ $limit = 10; /* 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 guests")); /* 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 guests ORDER BY f_name LIMIT ".$start.", ".$limit); /* Now get the page list and echo it */ $pagelist = $p->pageList($_GET['page'], $pages); if ( $r !== false && mysql_num_rows($r) > 0 ) { while ( $a = mysql_fetch_assoc($r) ) { $address = $a['address']; $email = $a['email']; $name = $a['f_name'].' '.$a['l_name']; $plus_one = $a['plus_one_f_name'].' '.$a['plus_one_l_name']; $entry_display .= <<$name & $plus_one
$address
$email

GUEST; } $entry_display .= '
'.$pagelist.'
'; } else $entry_display .= '

No entries have been made on this page.

'; return $entry_display; } public function get_guest_count(){ $sql="select * from guests"; $result=mysql_query($sql); return mysql_num_rows($result); } /** inserts a new user into the database @author ricky barrette */ public function new_guest($f_name, $l_name, $address, $email, $plus_one_f_name, $plus_one_l_name) { $sql="select * from guests where email='$email'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) // If there is a match. die("User/Email already exists"); $email = mysql_real_escape_string(strip_tags($email)); $f_name = mysql_real_escape_string(strip_tags($f_name)); $l_name = mysql_real_escape_string(strip_tags($l_name)); $address = mysql_real_escape_string(strip_tags($address)); $hash=md5($email); $sql = "INSERT INTO guests (f_name, l_name, address, email, hash, plus_one_f_name, plus_one_l_name) VALUES('$f_name','$l_name','$address','$email','$hash','$plus_one_f_name','$plus_one_l_name')"; return mysql_query($sql) or die("Could not insert. " . mysql_error()); } /** Connects to the database @author ricky barrette */ public function connect() { $connection = 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 users table @author ricky barrette */ private function buildDB() { $sql = <<