link = mysql_connect($host, $user, $pass); mysql_select_db($db); register_shutdown_function(array(&$this, 'close')); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; return mysql_query($query, $this->link); } //*** Function: fetchArray, Purpose: Get array of query results *** function fetchArray($result) { return mysql_fetch_array($result); } //*** Function: close, Purpose: Close the connection *** function close() { mysql_close($this->link); } function getConnector() { return new DBConnector(); } } ?>setmnu_ID($mnu_ID); $this->setmnu_Type($mnu_Type); $this->setmnu_Title($mnu_Title); $this->setmnu_ParentID($mnu_ParentID); $this->setmnu_Order($mnu_Order); $this->setmnu_Link($mnu_Link); $this->setmnu_Published($mnu_Published); $this->setmnu_CID($mnu_CID); $this->setmnu_Locked($mnu_Locked); } function setmnu_ID($newmnu_ID) { $this->mnu_ID = $newmnu_ID; } function getmnu_ID() { return $this->mnu_ID; } function setmnu_Type($newmnu_Type) { $this->mnu_Type = $newmnu_Type; } function getmnu_Type() { return $this->mnu_Type; } function setmnu_Title($newmnu_Title) { $this->mnu_Title = $newmnu_Title; } function getmnu_Title() { return $this->mnu_Title; } function setmnu_ParentID($newmnu_ParentID) { $this->mnu_ParentID = $newmnu_ParentID; } function getmnu_ParentID() { return $this->mnu_ParentID; } function setmnu_Order($newmnu_Order) { $this->mnu_Order = $newmnu_Order; } function getmnu_Order() { return $this->mnu_Order; } function setmnu_Link($newmnu_Link) { $this->mnu_Link = $newmnu_Link; } function getmnu_Link() { return $this->mnu_Link; } function setmnu_Published($newmnu_Published) { $this->mnu_Published = $newmnu_Published; } function getmnu_Published() { return $this->mnu_Published; } function setmnu_CID($newmnu_CID) { $this->mnu_CID = $newmnu_CID; } function getmnu_CID() { return $this->mnu_CID; } function setmnu_Locked($newmnu_Locked) { $this->mnu_Locked = $newmnu_Locked; } function getmnu_Locked() { return $this->mnu_Locked; } function getBean() { return get_object_vars($this); } function loadMenuByID() { if ($this->getmnu_ID() > 0){ // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve locations $sqlresult = $connector->query("SELECT * FROM sitemenu WHERE mnu_ID = ".$this->getmnu_ID().""); while ($row = mysql_fetch_array($sqlresult)){ $this->setmnu_ID($row["mnu_ID"]); $this->setmnu_Type($row["mnu_Type"]); $this->setmnu_Title($row["mnu_Title"]); $this->setmnu_ParentID($row["mnu_ParentID"]); $this->setmnu_Order($row["mnu_Order"]); $this->setmnu_Link($row["mnu_Link"]); $this->setmnu_CID($row["mnu_CID"]); $this->setmnu_Locked($row["mnu_Locked"]); } } } function getMenuByID() { $connector = new DbConnector(); if ($this->mnu_ID == 0){ $sqlresult = $connector->query("SELECT sitemenu.*, COUNT(B.mnu_ID) AS mnu_Count, sitemenu_types.type_Title, component.com_Link AS mnu_ComponentLink, C.mnu_Link AS mnu_ParentLink FROM sitemenu INNER JOIN sitemenu_types ON sitemenu.mnu_Type = sitemenu_types.type_ID LEFT JOIN sitemenu AS B ON sitemenu.mnu_Type=B.mnu_type LEFT JOIN component ON sitemenu.mnu_CID = component.com_ID LEFT JOIN sitemenu C ON sitemenu.mnu_ParentID = C.mnu_ID GROUP BY sitemenu.mnu_ID ORDER BY mnu_Type, mnu_Order"); } else { $sqlresult = $connector->query("SELECT sitemenu.*, COUNT(B.mnu_ID) AS mnu_Count, sitemenu_types.type_Title, component.com_Link AS mnu_ComponentLink, C.mnu_Link AS mnu_ParentLink FROM sitemenu INNER JOIN sitemenu_types ON sitemenu.mnu_Type = sitemenu_types.type_ID LEFT JOIN sitemenu AS B ON sitemenu.mnu_Type=B.mnu_type LEFT JOIN component ON sitemenu.mnu_CID = component.com_ID LEFT JOIN sitemenu C ON sitemenu.mnu_ParentID = C.mnu_ID WHERE mnu_ID = ".$this->mnu_ID." ORDER BY mnu_Type, mnu_Order"); } return $sqlresult; } function getMenusWithLinks() { $connector = new DbConnector(); $sqlresult = $connector->query("SELECT sitemenu.*, sitemenu_types.type_Title FROM sitemenu INNER JOIN sitemenu_types ON sitemenu.mnu_Type = sitemenu_types.type_ID WHERE mnu_CID = 0 AND mnu_ParentID = 0 ORDER BY mnu_Type, mnu_Order"); return $sqlresult; } function getMenuArticles() { $connector = new DbConnector(); $sqlresult = $connector->query("SELECT * FROM article WHERE art_menuID = ".$this->mnu_ID." AND art_Published='Y' ORDER BY art_Order") or die('Query failed: ' . mysql_error()); return $sqlresult; } function getDefaultArticle() { $connector = new DbConnector(); $sqlresult = $connector->query("SELECT * FROM article WHERE art_Default = 'Y' AND art_Published='Y' ORDER BY art_Order"); return $sqlresult; } function flushMenuToDatabase() { $connector = new DbConnector(); if ($this->getmnu_ID() == 0){ $newOrder = $this->countMenusByTypeID($this->getmnu_Type()); $newOrder++; $sqlresult = $connector->query("INSERT INTO sitemenu (mnu_Type,mnu_Title,mnu_ParentID,mnu_Order,mnu_Link,mnu_Published,mnu_CID,mnu_Locked) VALUES ( ".$this->getmnu_Type().", '".$this->getmnu_Title()."', ".$this->getmnu_ParentID().", ".$newOrder.", '".$this->getmnu_Link()."', '".$this->getmnu_Published()."', ".$this->getmnu_CID().", ".$this->getmnu_Locked()." )") or die('Query failed: ' . mysql_error()); } else { $oldMenu=$this->getMenuByID(); $oldRow = mysql_fetch_array($oldMenu); if ($this->getmnu_Type() != $oldRow['mnu_Type']){ $newOrder = $this->countMenusByTypeID($this->getmnu_Type()); $newOrder++; $this->reorderUpper($this->getmnu_Order(),$oldRow['mnu_Type']); $this->setmnu_Type($newOrder); } $sqlresult = $connector->query("UPDATE sitemenu SET mnu_Type = ".$this->getmnu_Type().", mnu_Title = '".$this->getmnu_Title()."', mnu_ParentID = ".$this->getmnu_ParentID().", mnu_Order = '".$this->getmnu_Order()."', mnu_Link = '".$this->getmnu_Link()."', mnu_Published = ".$this->getmnu_Published().", mnu_CID = ".$this->getmnu_CID().", mnu_Locked = '".$this->getmnu_Locked()."' WHERE mnu_ID = ".$this->getmnu_ID()."") or die('Query failed: ' . mysql_error()); // or die('Query failed: ' . mysql_error()) } if (mysql_affected_rows() > 0){ return true; } else { return false; } } function reorderUpper($Order,$typeID) { $connector = new DbConnector(); $checkOrder = true; while ($checkOrder){ $Order2 = $Order+1; $sqlresult2 = $connector->query("UPDATE sitemenu SET mnu_Order = ".$Order." WHERE mnu_Order = ".$Order2." AND mnu_Type = ".$typeID.""); if (mysql_affected_rows() == 0){ $checkOrder = false; } else { $Order++; } } } function countMenusByTypeID($Type=0) { // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve locations $artOrder = $connector->query("SELECT * FROM sitemenu WHERE mnu_Type = ".$Type.""); $rowCount = mysql_num_rows($artOrder); return $rowCount; } function getMenuByType($Type=0) { $connector = new DbConnector(); $sqlresult = $connector->query("SELECT sitemenu.*, sitemenu_types.type_Title, component.com_Link AS mnu_ComponentLink, B.mnu_Link AS mnu_ParentLink FROM sitemenu INNER JOIN sitemenu_types ON sitemenu.mnu_Type = sitemenu_types.type_ID LEFT JOIN component ON sitemenu.mnu_CID = component.com_ID LEFT JOIN sitemenu B ON sitemenu.mnu_ParentID = B.mnu_ID WHERE sitemenu.mnu_Type = ".$Type." AND sitemenu.mnu_Published = 'Y' ORDER BY mnu_Type, mnu_Order") or die('Query failed: ' . mysql_error()); return $sqlresult; } function getMenuTypeByID() { $connector = new DbConnector(); $sqlresult = $connector->query("SELECT * FROM sitemenu WHERE mnu_ID = ".$this->getmnu_ID().""); $row = mysql_fetch_array($sqlresult); $retval = $row["mnu_Type"]; return $retval; } function deleteMenuByID() { // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve locations $artInfo = $this->loadMenuByID(); $currentOrder = $this->getmnu_Order(); $checkOrder = true; $sqlresult = $connector->query("DELETE FROM sitemenu WHERE mnu_ID = ".$this->getmnu_ID()." AND mnu_Type = ".$this->getmnu_Type().""); if (mysql_affected_rows() > 0){ $mnuDeleted = true; } else { $mnuDeleted = false; } while ($checkOrder){ $currentOrder2 = $currentOrder+1; $sqlresult2 = $connector->query("UPDATE sitemenu SET mnu_Order = ".$currentOrder." WHERE mnu_Order = ".$currentOrder2." AND mnu_Type = ".$this->getmnu_Type().""); if (mysql_affected_rows() == 0){ $checkOrder = false; } else { $currentOrder++; } } return $mnuDeleted; } function publishMenuByID() { // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve locations $sqlresult = $connector->query("UPDATE sitemenu SET mnu_Published = 'Y' WHERE mnu_ID = ".$this->getmnu_ID().""); if (mysql_affected_rows() > 0){ return true; } else { return false; } } function unpublishMenuByID() { // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve locations $sqlresult = $connector->query("UPDATE sitemenu SET mnu_Published = '' WHERE mnu_ID = ".$this->getmnu_ID().""); if (mysql_affected_rows() > 0){ return true; } else { return false; } } function getMenuOrderByID() { // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve locations $mnuOrder = $connector->query("SELECT mnu_Order FROM sitemenu WHERE mnu_ID = ".$this->getmnu_ID().""); $row = mysql_fetch_array($mnuOrder); $retval = $row["mnu_Order"]; return $retval; } function reorderMenuByID($direction) { if ($direction == "up"){ $mnuInfo = $this->loadMenuByID(); $old_mnu_Order = $this->getMenuOrderByID(); $new_mnu_Order = $old_mnu_Order - 1; $connector = new DbConnector(); $connector->query("UPDATE sitemenu SET mnu_Order=".$new_mnu_Order." WHERE mnu_ID = ".$this->getmnu_ID()." AND mnu_Type = ".$this->getmnu_Type().""); $connector->query("UPDATE sitemenu SET mnu_Order=".$old_mnu_Order." WHERE mnu_Order = ".$new_mnu_Order." AND mnu_ID <> ".$this->getmnu_ID()." AND mnu_Type = ".$this->getmnu_Type().""); } else { $mnuInfo = $this->loadMenuByID(); $old_mnu_Order = $this->getMenuOrderByID(); $new_mnu_Order = $old_mnu_Order + 1; $connector = new DbConnector(); $connector->query("UPDATE sitemenu SET mnu_Order=".$new_mnu_Order." WHERE mnu_ID = ".$this->getmnu_ID()." AND mnu_Type = ".$this->getmnu_Type().""); $connector->query("UPDATE sitemenu SET mnu_Order=".$old_mnu_Order." WHERE mnu_Order = ".$new_mnu_Order." AND mnu_ID <> ".$this->getmnu_ID()." AND mnu_Type = ".$this->getmnu_Type().""); } if (mysql_affected_rows() > 0){ return true; } else { return false; } } function makeCrumbs($ref='') { $bcrumb = ''; if(strlen(trim($ref)) > 0){ } else { $bcrumb = "Home"; } return $bcrumb; } } ?>