There are no exits in the second class. Thats what I find so strange. Here is the code :
Flat file:
<?php
require_once ("../../smarty/Smarty.class.php");
require_once ("../../classes/class.categories.php");
require_once ("../../classes/class.modifiedcategory.php");
require_once ("../../config/config.php");
$smarty = new Smarty;
$categories_obj = new categories;
//$modifiedcategory_obj = new modifiedcategory;
print_r($_POST);
if ($_POST[Action] == "Save")
{
if (!$_POST[IsDisplay]) { $IsDisplay = "N"; } else { $IsDisplay = "Y"; }
if (!$_POST[IsTopLevel]) { $IsTopLevel = "N"; } else { $IsTopLevel = "Y"; }
if (!$_POST[SpecialCase]) { $SpecialCase = "N"; } else { $SpecialCase = "Y"; }
$categories_obj->saveCategory($parentID, $name, $userID, $display, $topLevel, $specialCase, $specialDescription);
}
elseif ($_POST[Action] == "Update")
{
if (!$_POST[IsDisplay]) { $IsDisplay = "N"; } else { $IsDisplay = "Y"; }
if (!$_POST[IsTopLevel]) { $IsTopLevel = "N"; } else { $IsTopLevel = "Y"; }
if (!$_POST[SpecialCase]) { $SpecialCase = "N"; } else { $SpecialCase = "Y"; }
$categories_obj->updateCategory($_POST[CategoryId], $_POST[CategoryName], $IsDisplay, $IsTopLevel, $SpecialCase, $_POST[SpecialDescription]);
//if ($categories_obj->updateCategory($_POST[CategoryId], $_POST[CategoryName], $IsDisplay, $IsTopLevel, $SpecialCase, $_POST[SpecialDescription]))
//$modifiedcategory_obj->saveModifiedCategory($_POST[CategoryId], $_POST[CategoryName], $IsDisplay, $IsTopLevel, $SpecialCase, $_POST[SpecialDescription])
}
...
$smarty->display('categories.tpl');
?>
Categories Class:
<?php
include_once ("class.mysqldb.php");
class categories
{
// Object Attributes
var $CategoryID;
var $ParentID;
var $lvalue;
var $rvalue;
var $Name;
var $UserID;
var $DateCreated;
var $HierarchyID;
var $Display;
var $TopLevel;
var $SpecialCase;
var $SpecialDescription;
var $db;
// Object Constructor
function categories()
{
$this->init();
}
// Object Methods
function init()
{
$this->CategoryID = "";
$this->ParentID = "";
$this->lvalue = "";
$this->rvalue = "";
$this->Name = "";
$this->UserID = "";
$this->DateCreated = "";
$this->HierarchyID = "";
$this->Display = "";
$this->TopLevel = "";
$this->SpecialCase = "";
$this->SpecialDescription = "";
$this->db = new mysqldb;
}
function saveCategory($parentID, $name, $userID, $display, $topLevel, $specialCase, $specialDescription)
{
// check to see if the category already exists
if (!$this->alreadyExists($name, $parentID))
{
// to save a new node in the table we first have to get the left and right values of the parent node
$sql = "SELECT lvalue, rvalue FROM Categories WHERE CategoryID = $parentID";
$this->db->query($sql);
$row = $this->db->getRows();
$lft = $row[lvalue];
$rgt = $row[rvalue];
// Update the rvalue value of all nodes to the right of the inserted node
$sql = "UPDATE Categories SET rvalue = rvalue + 2 WHERE rvalue >= '$rgt'";
$this->db->query($sql);
// Update the lvalue value of all nodes to the right of the inserted node
$sql = "UPDATE Categories SET lvalue = lvalue + 2 WHERE lvalue > '$rgt'";
$this->db->query($sql);
// default level for a new Category is level 1 as level 0 of the tree is the root with a value of "Gotcha"
// Now we can insert the new node using the right value and right value + 1
$sql = "INSERT INTO Categories VALUES(NULL, $parentID, $rgt, $rgt+1, '$name', $userID, now(), '$display', '$topLevel', '$specialCase', '$specialDescription')";
$this->db->query($sql);
if ($this->db->getaffectedrows())
{
$verifyinsert = 1;
}
else
{
echo "class.categories.php - function SaveCategory() : Problem inserting new node.<br />";
}
}
else
{
$verifyinsert = 2;
}
return $verifyinsert;
}
function updateCategory($categoryID, $name, $display, $topLevel, $specialCase, $specialDescription)
{
// update the entry in the Categories Table
$sql = "Update Categories set Name = '$name', Display = '$display', TopLevel = '$topLevel', SpecialCase = '$specialCase', SpecialDescription = '$specialDescription' where CategoryID = '$categoryID'";
echo $sql."<br />";
$this->db->query($sql);
if ($this->db->getaffectedrows())
{
return 1;
}
else
return -1;
}
// Other Object Functions set and get etc
}
database class:
<?php
class mysqldb
{
// Object Attributes
var $dbhost;
var $db;
var $dbuser;
var $dbpassword;
var $sql;
var $numberrows;
var $affectedrows;
var $dbopenstatus;
var $dbconnection;
var $result;
// Object Constructor
function mysqldb()
{
$this->init();
}
function init()
{
$this->setdbhost(DBSERVER);
$this->setdb(DBNAME);
$this->setdbuser(DBUSERNAME);
$this->setdbpassword(DBPASSWORD);
$this->setdbconnection(false);
$this->opendbconnection();
}
// Object Methods
function opendbconnection()
{
$link = mysql_connect($this->getdbhost(), $this->getdbuser(), $this->getdbpassword());
if ($link)
{
mysql_select_db($this->getdb());
$this->setdbconnection($link);
}
else
{
$this->setdbconnection($link);
return false;
}
return true;
}
function closedbconnection()
{
if ($this->dbconnection = $TRUE)
{
mysql_close($this->dbconnection);
}
}
function query($sql)
{
if ($this->getdbconnection())
{
$this->opendbconnection();
}
//echo $sql."<br />";
$this->qry = mysql_query($sql);
if (!$this->qry)
{
die("Invalid query: " . mysql_error());
return false;
}
else
{
if (preg_match("/\bselect\b/i", $sql))
$this->setnumberrows(mysql_num_rows($this->qry));
elseif (preg_match("/\binsert\b/i", $sql) || preg_match("/\bupdate\b/i", $sql) || preg_match("/\bdelete\b/i", $sql))
$this->setaffectedrows(mysql_affected_rows());
else
{
echo("[Error:] Querrying Database<br />");
return false;
}
}
}
// get and set functions, etc
}
Modified Category Class:
<?php
include_once ("class.mysqldb.php");
class modifiedcategory
{
// Object Attributes
var $ModifiedID;
var $CategoryID;
var $Modification;
var $UserID;
var $Date;
// Object Constructor
function modifiedcategory()
{
$this->init();
}
// Object Methods
function init()
{
$this->ModifiedID = "";
$this->CategoryID = "";
$this->Modification = "";
$this->UserID = "";
$this->Date = "";
$this->db = new mysqldb;
}
function saveModifiedCategory($categoryID, $name, $display, $topLevel, $specialCase, $specialDescription)
{
$tempName = null;
$tempDisplay = null;
$tempTopLevel = null;
$tempSpecialCase = null;
$tempSpecialDescription = null;
$mod = null;
$sql = "SELECT Name, Display, TopLevel, SpecialCase, SpecialDescription FROM Categories WHERE CategoryID = $CategoryId";
$this->db->query($sql);
while ($row = $this->db->getRows();)
{
$tempName = $row[Name];
$tempDisplay = $row[Display];
$tempTopLevel = $row[TopLevel];
$tempSpecialCase = $row[SpecialCase];
$tempSpecialDescription = $row[SpecialDescription];
}
if ($tempName != $CategoryName)
$mod .= "Changed Name to : ".$CategoryName." from ".$tempName.".";
if ($tempDisplay != $IsDisplay)
$mod .= "Changed Display to : ".$IsDisplay." from ".$tempDisplay.".";
if ($tempTopLevel != $IsTopLevel)
$mod .= "Changed TopLevel to : ".$IsTopLevel." from ".$tempTopLevel.".";
if ($tempSpecialCase != $SpecialCase)
$mod .= "Changed SpecialCase to : ".$SpecialCase." from ".$tempSpecialCase.".";
if ($tempSpecialDescription != $SpecialDescription)
$mod .= "Changed SpecialDescription to : ".$SpecialDescription." from ".$tempSpecialDescription.".";
echo $mod."<br />";
//mysql_query ("INSERT INTO ModifiedCategory VALUES (Null, '$CategoryId', '$mod', '$USER_ID', now())")
}
// etc etc
}
if I uncomment in the flat file at the line :
$modifiedcategory_obj = new modifiedcategory;
Thats when I get the blank output
Hope this helps