PHP Support Class (For a commerce site)
This is my take on a php support class. Enjoy its not truely complete but it can be finished with a little time
If u wish to use it feel free to but credit me and send me a mail telling me where you are using it
You will need my take on a mysql class also posted on my blog or make your own and edit the code.
Plus where you see the constants bit either make your own constants class or fill it in with your own constants.
<? /** * Class:support * + Handles the support section of the website. * -------- * @author mdalke * @copyright 2007 mdalke * @todo + Constants from constants class. * + Add class to add a ticket * + Security * + Add Stuff* + Proper Labeling of what everything does */
class support{ // + Generally Needed variables var $db; var $constants; var $debugStack = array(); // + Table Variables var $support_table; var $userstbl; var $managerstbl; var $base_cat_tbl; var $base_topics_tbl; var $assignedtbl; // + Knowledge Base Items var $title; var $content; var $subject; var $sub_subject; var $priority; var $assigned; var $user_id;/** * Void support * + Construct (PHP4) * ----------------- * @param string $title * @param string $content * @param int $subject * @param int $sub_subject * @param int $priority * @param int $assigned * @param int $user_id * @param string $support_table * @return support */ function support($title=null,$content=null,$subject=null,$sub_subject=null,$priority=null,$assigned=null,$user_id=null,$support_table=null){ $this->__construct($title,$content,$subject,$sub_subject,$priority,$assigned,$user_id,$support_table); }/** * Void __construct * + Construct (PHP5 Fix) * ----------------- * @param string $title * @param string $content * @param int $subject * @param int $sub_subject * @param int $priority * @param int $assigned * @param int $user_id * @param string $support_table * @return __construct */ function __construct($title=null,$content=null,$subject=null,$sub_subject=null,$priority=null,$assigned=null,$user_id=null,$support_table=null){if(!$this->db = new sql()){ throw new Exception("Error opening class sql"); } $this->debug("Opened SQL Class"); if(!$this->constants = new constants()){ throw new Exception("Error opening class constants"); } $this->debug("Opened Constants");$this->title = ($title)?$title:$this->title; $this->content = ($content)?$content:$this->content; $this->subject = ($subject)?$subject:$this->subject; $this->sub_subject = ($sub_subject)?$sub_subject:$this->sub_subject; $this->priority = ($priority)?$priority:$this->priority; $this->assigned = ($assigned)?$assigned:$this->assigned; $this->user_id = ($user_id)?$user_id:$this->user_id; $this->support_table = ($support_table)?$support_table:$this->support_table; $this->debug("Constructed Variables");$this->base_topics_tbl = $this->constants->getconst("kb_topics_tbl"); $this->managerstbl = $this->constants->getconst("managers_tbl"); $this->userstbl = $this->constants->getconst("users_tbl"); $this->assignedtbl = $this->constants->getconst("assigned_tbl"); $this->base_cat_tbl = $this->constants->getconst("kb_cat_tbl"); $this->debug("Added Some Constants");}function view_kb_topic($id){$sql = "SELECT * FROM '".$this->base_topics_tbl."' WHERE id='".$id."'"; $query = $this->db->query($sql);if(!$base = $this->db->fetch_array($query)){ throw new Exception("Error Fetching The Knowledge Base Item ".mysql_error()."<br>".$sqlb); } $this->debug("Retrived the Knowledge Base Topic"); return $base;}function view_kb_cats($id){$sql = "SELECT * FROM '".$this->base_cat_tbl."' WHERE id='".$id."'"; $query = $this->db->query($sql);if(!$base = $this->db->fetch_array($query)){ throw new Exception("Error Fetching The Knowledge Base Catergory ".mysql_error()."<br>".$sqlb); } $this->debug("Retrieved the Knowledge Base Category"); return $base;}function view_kb_cat_from_topic($id){$sql = "SELECT * FROM '".$this->base_topics_tbl."' INNER JOIN '".$this->base_cat_tbl."' ON '".$this->base_topics_tbl."'.cid='".$this->base_cat_tbl."'.id"; $query = $this->db->query($sql);if(!$base = $this->db->fetch_array($query)){ throw new Exception("Error getting the knowledge base item in query ".mysql_error()."<br>".$sqlb); } $this->debug("Retrieved the Category from the Topic"); return $base;}function assign_manager($tid){$sql = "SELECT * FROM '".$this->managerstbl."' INNER JOIN '".$this->usertbl."' ON '".$this->managerstbl."'.user_id='".$this->usertbl."'.user_id";$query = $this->db->query($sql); if(!$max = $this->db->num_rows($query)){ throw new Exception("Error Executive Query ".mysql_error()."<br>".$sqlb); } $this->debug("Accessed the managers table"); $figure = rand(0,$max); $this->debug("Created a random figure from the managers id"); while($base = mysql_fetch_array($query)){if($base["id"] == $figure){ $sqlb = "INSERT INTO '".$this->assignedtbl."' (tid,mid) VALUES('".$tid."','".$base["id"]."')"; if(!$sql_q = mysql_query($sqlb)){ throw new Exception("Error with Assigning A Manager: ".mysql_error()."<br>".$sqlb); }else{ $this->debug("Assigned manager to topic"); return true; } }}}function get_manager_info($mid){$sql = "SELECT * FROM '".$this->managerstbl."' INNER JOIN '".$this->usertbl."' ON '".$this->managerstbl."'.user_id='".$this->usertbl."'.user_id WHERE '".$this->managerstbl."'.mid = '".$mid."'"; $query = $this->db->query($sql);if(!$base = $this->db->fetch_array($query)){ throw new Exception("Error Getting Manager's Info".mysql_error()."<br>".$sqlb); } $this->debug("Retrived The Managers Information"); return $base; }function add_ticket($title,$content,$subject,$sub_subject,$priority,$assigned,$user_id){$this->title = stripslashes($title); $this->content = stripslashes($content); $this->subject = $subject; $this->sub_subject = $sub_subject; $this->priority = $priority; $this->assigned = $assigned; $this->user_id = $user_id; $this->debug("Assigned Values For Ticket");$this->support_table = $this->constants->getconst("kb_topics_tbl"); $this->debug("Support Table Assigned From Constants"); $sql = "INSERT INTO '".$this->support_table."' (title,content,subject,sub_subject,priority,assigned,user_id) VALUES('".$this->title."','".$this->content."','".$this->subject."','".$this->sub_subject."', '".$this->priority."','".$this->assigned."','".$this->user_id."')";if(!$sql_q = mysql_query($sql)){ throw new Exception("Error with Adding A Ticket: ".mysql_error()."<br>".$sql); }else{ $this->debug("Inserted Ticket into DB"); return true; }}/** * Void debug * + Creates a set of debug instructions * ----------------- * @param string $msg */function debug($msg){ $this->debugStack .= $msg."<br>\n"; }/** * String returnDebug * + Returns the debugstack. * ----------------- * @return string $debugStack */ function returnDebug(){ return $this->debugStack; }}?>

does PHP4 support the usage of ___construct
In PHP 4 you call the class initializer the same as the class name.
Note this version is for php 5 as it has exceptions included. If you wish to use on php4 just remove this and put your own error handler or just die() there instead.