2007-02-03 19:03:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/* class for managing objects */
|
|
|
|
|
/* - handles processing of queued objects */
|
|
|
|
|
/* - handles the display and editing of unqueued objects */
|
|
|
|
|
class ObjectManager
|
|
|
|
|
{
|
|
|
|
|
var $sClass;
|
|
|
|
|
var $bIsQueue;
|
|
|
|
|
var $sTitle;
|
|
|
|
|
var $iId;
|
2007-03-24 18:30:16 +00:00
|
|
|
var $bIsRejected;
|
2007-02-03 19:03:42 +00:00
|
|
|
|
|
|
|
|
function ObjectManager($sClass, $sTitle = "list", $iId = false)
|
|
|
|
|
{
|
|
|
|
|
$this->sClass = $sClass;
|
|
|
|
|
$this->sTitle = $sTitle;
|
|
|
|
|
$this->iId = $iId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check whether the associated class has the given method */
|
|
|
|
|
function checkMethod($sMethodName, $bEnableOutput)
|
|
|
|
|
{
|
2007-02-03 19:33:20 +00:00
|
|
|
// 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))
|
2007-02-03 19:03:42 +00:00
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
2007-03-17 21:04:43 +00:00
|
|
|
$this->checkMethods(array("ObjectGetEntries", "ObjectGetHeader",
|
2007-03-04 23:22:57 +00:00
|
|
|
"ObjectGetInstanceFromRow", "ObjectOutputTableRow", "canEdit"));
|
2007-02-03 19:03:42 +00:00
|
|
|
|
2007-03-24 18:30:16 +00:00
|
|
|
$oObject = new $this->sClass();
|
2007-02-03 19:03:42 +00:00
|
|
|
/* 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 */
|
2007-03-25 03:56:20 +00:00
|
|
|
$hResult = $oObject->objectGetEntries($this->bIsQueue, $this->bIsRejected);
|
2007-02-03 19:03:42 +00:00
|
|
|
|
|
|
|
|
/* did we get any entries? */
|
|
|
|
|
if(mysql_num_rows($hResult) == 0)
|
|
|
|
|
{
|
2007-03-25 03:56:20 +00:00
|
|
|
switch($this->getQueueString($this->bIsQueue, $this->bIsRejected))
|
|
|
|
|
{
|
|
|
|
|
case "true":
|
|
|
|
|
echo "<center>The queue for '$this->sClass' is empty</center>";
|
|
|
|
|
break;
|
|
|
|
|
case "false":
|
|
|
|
|
echo "<center>No entries of '$this->sClass' are present</center>";
|
|
|
|
|
break;
|
|
|
|
|
case "rejected":
|
|
|
|
|
echo "<center>No rejected entries of '$this->sClass' are ".
|
|
|
|
|
"present</center>";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-02-03 19:03:42 +00:00
|
|
|
|
2007-03-24 18:30:16 +00:00
|
|
|
echo "<br /><center><a href=\"".$this->makeUrl("add", false,
|
|
|
|
|
"Add $this->sClass entry")."\">Add an entry?</a></center>";
|
2007-02-03 19:03:42 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* output the header */
|
|
|
|
|
echo '<table width="100%" border="0" cellpadding="3" cellspacing="0">';
|
|
|
|
|
|
2007-03-17 21:04:43 +00:00
|
|
|
/* Output header cells */
|
|
|
|
|
$this->outputHeader("color4");
|
2007-02-03 19:03:42 +00:00
|
|
|
|
|
|
|
|
/* output each entry */
|
|
|
|
|
for($iCount = 0; $oRow = mysql_fetch_object($hResult); $iCount++)
|
|
|
|
|
{
|
|
|
|
|
$oObject = call_user_func(array($this->sClass,
|
|
|
|
|
"objectGetInstanceFromRow"), $oRow);
|
|
|
|
|
|
2007-03-13 21:08:39 +00:00
|
|
|
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */
|
|
|
|
|
$oObject->objectOutputTableRow($this, ($iCount % 2) ? "color0" : "color1",
|
|
|
|
|
$this->bIsQueue ? "process" : "edit");
|
2007-02-03 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
|
|
|
|
|
|
$oObject = new $this->sClass();
|
|
|
|
|
if($oObject->canEdit())
|
|
|
|
|
{
|
2007-03-24 18:30:16 +00:00
|
|
|
echo "<br /><br /><a href=\"".$this->makeUrl("add", false,
|
|
|
|
|
"Add $this->sClass")."\">Add entry</a>\n";
|
2007-02-03 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* display the entry for editing */
|
2007-03-25 18:52:19 +00:00
|
|
|
function display_entry_for_editing($sBackLink, $sErrors)
|
2007-02-03 19:03:42 +00:00
|
|
|
{
|
|
|
|
|
$this->checkMethods(array("outputEditor", "getOutputEditorValues",
|
|
|
|
|
"update", "create"));
|
|
|
|
|
|
|
|
|
|
// link back to the previous page
|
|
|
|
|
echo html_back_link(1, $sBackLink);
|
|
|
|
|
|
2007-03-25 18:52:19 +00:00
|
|
|
$oObject = new $this->sClass($this->iId);
|
|
|
|
|
|
|
|
|
|
/* Display errors, if any, and fetch form data */
|
|
|
|
|
if($this->displayErrors($sErrors))
|
|
|
|
|
{
|
|
|
|
|
global $aClean;
|
|
|
|
|
$oObject->getOutputEditorValues($aClean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo '<form name="sQform" action="'.$this->makeUrl("edit", $this->iId).
|
|
|
|
|
'" method="post" enctype="multipart/form-data">',"\n";
|
2007-02-03 19:03:42 +00:00
|
|
|
|
|
|
|
|
echo '<input type="hidden" name="sClass" value="'.$this->sClass.'" />';
|
|
|
|
|
echo '<input type="hidden" name="sTitle" value="'.$this->sTitle.'" />';
|
|
|
|
|
echo '<input type="hidden" name="iId" value="'.$this->iId.'" />';
|
|
|
|
|
echo '<input type="hidden" name="bIsQueue" '.
|
2007-03-24 18:30:16 +00:00
|
|
|
'value='.($this->bIsQueue ? "true" : "false").' />';
|
2007-03-25 03:56:20 +00:00
|
|
|
echo '<input type="hidden" name="bIsRejected" '.
|
2007-03-24 18:30:16 +00:00
|
|
|
'value='.($this->bIsRejected ? "true" : "false").' />';
|
2007-02-03 19:03:42 +00:00
|
|
|
|
|
|
|
|
$oObject->outputEditor();
|
|
|
|
|
|
|
|
|
|
/* if this is a queue add a dialog for replying to the submitter of the
|
|
|
|
|
queued entry */
|
|
|
|
|
if($this->bIsQueue)
|
|
|
|
|
{
|
2007-03-04 23:22:57 +00:00
|
|
|
/* If it isn't implemented, that means there is no default text */
|
|
|
|
|
if(method_exists(new $this->sClass, "getDefaultReply"))
|
|
|
|
|
$sDefaultReply = $oObject->getDefaultReply();
|
|
|
|
|
|
2007-02-03 19:03:42 +00:00
|
|
|
echo html_frame_start("Reply text", "90%", "", 0);
|
|
|
|
|
echo "<table width='100%' border=0 cellpadding=2 cellspacing=0>\n";
|
|
|
|
|
echo '<tr valign=top><td class="color0"><b>email Text</b></td>',"\n";
|
|
|
|
|
echo '<td><textarea name="sReplyText" style="width: 100%" cols="80" '.
|
2007-03-04 23:22:57 +00:00
|
|
|
'rows="10">'.$sDefaultReply.'</textarea></td></tr>',"\n";
|
2007-02-03 19:03:42 +00:00
|
|
|
|
|
|
|
|
/* buttons for operations we can perform on this entry */
|
|
|
|
|
echo '<tr valign=top><td class=color3 align=center colspan=2>' ,"\n";
|
2007-03-04 23:22:57 +00:00
|
|
|
echo '<input name="sSubmit" type="submit" value="Submit" class="button" '.
|
2007-02-03 19:03:42 +00:00
|
|
|
'/>',"\n";
|
2007-03-04 23:22:57 +00:00
|
|
|
if(!method_exists(new $this->sClass, "objectHideDelete"))
|
|
|
|
|
{
|
|
|
|
|
echo '<input name="sSubmit" type="submit" value="Delete" '.
|
|
|
|
|
'class="button" />',"\n";
|
|
|
|
|
}
|
2007-03-25 03:56:20 +00:00
|
|
|
|
|
|
|
|
if(!$this->bIsRejected)
|
|
|
|
|
{
|
|
|
|
|
echo '<input name="sSubmit" type="submit" value="Reject" class="button" '.
|
|
|
|
|
'/>',"\n";
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-04 23:22:57 +00:00
|
|
|
echo '<input name="sSubmit" type="submit" value="Cancel" class="button" '.
|
2007-02-03 19:03:42 +00:00
|
|
|
'/>',"\n";
|
|
|
|
|
echo '</td></tr>',"\n";
|
|
|
|
|
echo '</table>';
|
|
|
|
|
echo html_frame_end();
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
echo '<tr valign=top><td class=color3 align=center colspan=2>',"\n";
|
2007-03-04 23:22:57 +00:00
|
|
|
echo '<input name="sSubmit" type="submit" value="Submit" class="button">'.
|
2007-02-03 19:03:42 +00:00
|
|
|
' ',"\n";
|
|
|
|
|
echo "</td></tr>\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Display help for queue processing */
|
|
|
|
|
function display_queue_processing_help()
|
|
|
|
|
{
|
|
|
|
|
/* No help text defined, so do nothing */
|
2007-02-03 19:55:15 +00:00
|
|
|
if(!method_exists(new $this->sClass(), "ObjectDisplayQueueProcessingHelp"))
|
2007-02-03 19:03:42 +00:00
|
|
|
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 */
|
2007-03-25 18:52:19 +00:00
|
|
|
function add_entry($sBackLink, $sErrors = "")
|
2007-02-03 19:03:42 +00:00
|
|
|
{
|
|
|
|
|
$this->checkMethods(array("outputEditor", "getOutputEditorValues",
|
|
|
|
|
"update", "create"));
|
|
|
|
|
|
2007-03-25 18:52:19 +00:00
|
|
|
|
2007-02-03 19:03:42 +00:00
|
|
|
$oObject = new $this->sClass();
|
|
|
|
|
|
2007-03-25 18:52:19 +00:00
|
|
|
/* 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);
|
|
|
|
|
}
|
2007-02-03 19:03:42 +00:00
|
|
|
echo "<form method=\"post\">\n";
|
|
|
|
|
|
|
|
|
|
$oObject->outputEditor();
|
|
|
|
|
|
|
|
|
|
echo "<input type=\"hidden\" name=\"sClass=\"distribution\" />\n";
|
|
|
|
|
echo "<input type=\"hidden\" name=\"sTitle\" value=\"$this->sTitle\" />\n";
|
|
|
|
|
|
|
|
|
|
echo "<div align=\"center\">";
|
|
|
|
|
echo "<input type=\"submit\" class=\"button\" value=\"Submit\" ".
|
|
|
|
|
"name=\"sSubmit\" />\n";
|
|
|
|
|
echo "</div></form>\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);
|
|
|
|
|
|
2007-03-04 23:22:57 +00:00
|
|
|
/* 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'] = "";
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-03 19:03:42 +00:00
|
|
|
$oObject->getOutputEditorValues($aClean);
|
|
|
|
|
|
2007-03-25 18:52:19 +00:00
|
|
|
/* Check input, if necessary */
|
|
|
|
|
if(method_exists(new $this->sClass, "checkOutputEditorInput"))
|
|
|
|
|
{
|
|
|
|
|
$sErrors = $oObject->checkOutputEditorInput($aClean);
|
|
|
|
|
if($sErrors)
|
|
|
|
|
return $sErrors;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-04 23:22:57 +00:00
|
|
|
switch($aClean['sSubmit'])
|
2007-02-03 19:03:42 +00:00
|
|
|
{
|
2007-03-04 23:22:57 +00:00
|
|
|
case "Submit":
|
|
|
|
|
if($this->iId)
|
|
|
|
|
{
|
|
|
|
|
if(!$oObject->canEdit())
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2007-04-21 01:02:10 +00:00
|
|
|
if($this->bIsRejected)
|
|
|
|
|
$oObject->ReQueue();
|
|
|
|
|
|
2007-03-04 23:22:57 +00:00
|
|
|
if($this->bIsQueue)
|
|
|
|
|
$oObject->unQueue();
|
2007-02-03 19:03:42 +00:00
|
|
|
|
2007-03-04 23:22:57 +00:00
|
|
|
$oObject->update();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$oObject->create();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Reject":
|
|
|
|
|
if(!$oObject->canEdit())
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
$oObject->reject();
|
|
|
|
|
break;
|
|
|
|
|
case "Delete":
|
|
|
|
|
$this->delete_entry();
|
2007-02-03 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-25 18:52:19 +00:00
|
|
|
/* 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");
|
2007-03-04 23:22:57 +00:00
|
|
|
else
|
2007-03-25 18:52:19 +00:00
|
|
|
$sRedirectLink = APPDB_ROOT;
|
2007-03-04 23:22:57 +00:00
|
|
|
|
2007-03-25 18:52:19 +00:00
|
|
|
util_redirect_and_exit($sRedirectLink);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2007-02-03 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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";
|
2007-03-24 18:30:16 +00:00
|
|
|
$sIsRejected = $this->bIsRejected ? "true" : "false";
|
2007-02-03 19:03:42 +00:00
|
|
|
|
|
|
|
|
if(!$sTitle)
|
|
|
|
|
$sTitle = $this->sTitle;
|
|
|
|
|
|
|
|
|
|
$sTitle = urlencode($sTitle);
|
|
|
|
|
|
2007-03-18 00:47:14 +00:00
|
|
|
return APPDB_ROOT."objectManager.php?bIsQueue=$sIsQueue&sClass=$this->sClass".
|
2007-03-24 18:30:16 +00:00
|
|
|
"&sTitle=$sTitle$sId$sAction&bIsRejected=$sIsRejected";
|
2007-02-03 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get id from form data */
|
|
|
|
|
function getIdFromInput($aClean)
|
|
|
|
|
{
|
|
|
|
|
$sId = "i".ucfirst($this->sClass)."Id";
|
2007-04-19 23:45:15 +00:00
|
|
|
$iId = $aClean['sId'];
|
|
|
|
|
|
|
|
|
|
if(!$iId)
|
|
|
|
|
$iId = $aClean['iId'];
|
|
|
|
|
|
|
|
|
|
return $iId;
|
2007-02-03 19:03:42 +00:00
|
|
|
}
|
2007-03-17 21:04:43 +00:00
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
}
|
2007-03-24 18:30:16 +00:00
|
|
|
|
|
|
|
|
function getQueueString($bQueued, $bRejected)
|
|
|
|
|
{
|
|
|
|
|
if($bQueued)
|
|
|
|
|
{
|
|
|
|
|
if($bRejected)
|
|
|
|
|
$sQueueString = "rejected";
|
|
|
|
|
else
|
|
|
|
|
$sQueueString = "true";
|
|
|
|
|
} else
|
|
|
|
|
$sQueueString = "false";
|
|
|
|
|
|
|
|
|
|
return $sQueueString;
|
|
|
|
|
}
|
2007-03-25 18:52:19 +00:00
|
|
|
|
|
|
|
|
function displayErrors($sErrors)
|
|
|
|
|
{
|
|
|
|
|
if($sErrors)
|
|
|
|
|
{
|
|
|
|
|
echo "<font color=\"red\">\n";
|
|
|
|
|
echo "The following errors were found<br />\n";
|
|
|
|
|
echo "<ul>$sErrors</ul>\n";
|
|
|
|
|
echo "</font><br />";
|
2007-04-04 00:32:43 +00:00
|
|
|
return TRUE;
|
2007-03-25 18:52:19 +00:00
|
|
|
} else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2007-02-03 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|