sClass = $sClass;
$this->sTitle = $sTitle;
$this->iId = $iId;
}
/* Check whether the associated class has the given method */
function checkMethod($sMethodName, $bEnableOutput)
{
// NOTE: we only 'new' here because php4 requires an instance
// of an object as the first argument to method_exists(), php5
// doesn't
if(!method_exists(new $this->sClass(), $sMethodName))
{
if($bEnableOutput) echo "class '".$this->sClass."' lacks method '".$sMethodName."'\n";
return false;
}
return true;
}
/* Check whether the specified methods are valid */
function checkMethods($aMethods, $bExit = true)
{
foreach($aMethods as $sMethod)
{
if(!$this->checkMethod($sMethod, false))
{
echo "Selected class does not support this operation ".
"(missing '$sMethod()')\n";
if($bExit)
exit;
else
return FALSE;
}
}
return TRUE;
}
/* displays the list of entries */
function display_table()
{
$this->checkMethods(array("ObjectGetEntries", "ObjectGetHeader",
"ObjectGetInstanceFromRow", "ObjectOutputTableRow", "canEdit"));
$oObject = new $this->sClass();
/* query the class for its entries */
/* We pass in $this->bIsQueue to tell the object */
/* if we are requesting a list of its queued objects or */
/* all of its objects */
$hResult = $oObject->objectGetEntries($this->bIsQueue, $this->bIsRejected);
/* did we get any entries? */
if(mysql_num_rows($hResult) == 0)
{
switch($this->getQueueString($this->bIsQueue, $this->bIsRejected))
{
case "true":
echo "
The queue for '$this->sClass' is empty
";
break;
case "false":
echo "
No entries of '$this->sClass' are present
";
break;
case "rejected":
echo "
No rejected entries of '$this->sClass' are ".
"present
";
$oObject = new $this->sClass();
if($oObject->canEdit())
{
echo "
makeUrl("add", false,
"Add $this->sClass")."\">Add entry\n";
}
}
/* display the entry for editing */
function display_entry_for_editing($sBackLink, $sErrors)
{
$this->checkMethods(array("outputEditor", "getOutputEditorValues",
"update", "create"));
// link back to the previous page
echo html_back_link(1, $sBackLink);
$oObject = new $this->sClass($this->iId);
/* Display errors, if any, and fetch form data */
if($this->displayErrors($sErrors))
{
global $aClean;
$oObject->getOutputEditorValues($aClean);
}
echo '';
}
/* Display help for queue processing */
function display_queue_processing_help()
{
/* No help text defined, so do nothing */
if(!method_exists(new $this->sClass(), "ObjectDisplayQueueProcessingHelp"))
return FALSE;
call_user_func(array($this->sClass,
"ObjectDisplayQueueProcessingHelp"));
}
/* Delete the object associated with the given id */
function delete_entry()
{
$this->checkMethods(array("delete", "canEdit"));
$oObject = new $this->sClass($this->iId);
if(!$oObject->canEdit())
return FALSE;
if($oObject->delete())
util_redirect_and_exit($this->makeUrl("view", false));
else
echo "Failure.\n";
}
/* Display screen for submitting a new entry of given type */
function add_entry($sBackLink, $sErrors = "")
{
$this->checkMethods(array("outputEditor", "getOutputEditorValues",
"update", "create"));
$oObject = new $this->sClass();
/* Display help if it is exists */
if(method_exists(new $this->sClass, "objectDisplayAddItemHelp"))
$oObject->objectDisplayAddItemHelp();
/* Display errors, if any, and fetch form data */
if($this->displayErrors($sErrors))
{
global $aClean;
$oObject->getOutputEditorValues($aClean);
}
echo "\n";
echo html_back_link(1, $sBackLink);
}
/* View an entry */
function view($sBackLink)
{
$this->checkMethods(array("display"));
$oObject = new $this->sClass($this->iId);
$oObject->display();
echo html_back_link(1, $sBackLink);
}
/* Process form data generated by adding or updating an entry */
function processForm($aClean)
{
if(!$aClean['sSubmit'])
return;
$this->checkMethods(array("getOutputEditorValues", "update", "create",
"canEdit"));
$this->iId = $this->getIdFromInput($aClean);
$oObject = new $this->sClass($this->iId);
/* If it isn't implemented, that means there is no default text */
if(method_exists(new $this->sClass, "getDefaultReply"))
{
/* Don't send the default reply text */
if($oObject->getDefaultReply() == $aClean['sReplyText'])
$aClean['sReplyText'] = "";
}
$oObject->getOutputEditorValues($aClean);
/* Check input, if necessary */
if(method_exists(new $this->sClass, "checkOutputEditorInput"))
{
$sErrors = $oObject->checkOutputEditorInput($aClean);
if($sErrors)
return $sErrors;
}
switch($aClean['sSubmit'])
{
case "Submit":
// if we have a valid iId then we are displaying an existing entry
// otherwise we should create the entry in the 'else' case
if($this->iId)
{
if(!$oObject->canEdit())
return FALSE;
if($this->bIsRejected)
$oObject->ReQueue();
if($this->bIsQueue && !$oObject->mustBeQueued())
$oObject->unQueue();
$oObject->update();
} else
{
$oObject->create();
}
break;
case "Reject":
if(!$oObject->canEdit())
return FALSE;
$oObject->reject();
break;
case "Delete":
$this->delete_entry();
}
/* Displaying the entire un-queued list for a class is not a good idea,
so only do so for queued data */
if($this->bIsQueue)
$sRedirectLink = $this->makeUrl("view", false, "$this->sClass list");
else
$sRedirectLink = APPDB_ROOT;
util_redirect_and_exit($sRedirectLink);
return TRUE;
}
/* Make an objectManager URL based on the object and optional parameters */
function makeUrl($sAction = false, $iId = false, $sTitle = false)
{
if($iId)
$sId = "&iId=$iId";
if($sAction)
$sAction = "&sAction=$sAction";
$sIsQueue = $this->bIsQueue ? "true" : "false";
$sIsRejected = $this->bIsRejected ? "true" : "false";
if(!$sTitle)
$sTitle = $this->sTitle;
$sTitle = urlencode($sTitle);
return APPDB_ROOT."objectManager.php?bIsQueue=$sIsQueue&sClass=$this->sClass".
"&sTitle=$sTitle$sId$sAction&bIsRejected=$sIsRejected";
}
/* Get id from form data */
function getIdFromInput($aClean)
{
$sId = "i".ucfirst($this->sClass)."Id";
$iId = $aClean['sId'];
if(!$iId)
$iId = $aClean['iId'];
return $iId;
}
/* Output headers for a table */
function outputHeader($sClass)
{
$oObject = new $this->sClass();
$aCells = $oObject->objectGetHeader();
/* Add an action column if the user can edit this class, or if it is a queue.
Even though a user annot process items, he can edit his queued submissions */
if($oObject->canEdit() || $this->bIsQueue)
$aCells[] = "Action";
echo html_tr($aCells, $sClass);
}
function getQueueString($bQueued, $bRejected)
{
if($bQueued)
{
if($bRejected)
$sQueueString = "rejected";
else
$sQueueString = "true";
} else
$sQueueString = "false";
return $sQueueString;
}
function displayErrors($sErrors)
{
if($sErrors)
{
echo "\n";
echo "The following errors were found \n";
echo "