diff --git a/include/objectManager.php b/include/objectManager.php index 53ea3be..8fd09e1 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -116,7 +116,7 @@ class ObjectManager } /* display the entry for editing */ - function display_entry_for_editing($sBackLink) + function display_entry_for_editing($sBackLink, $sErrors) { $this->checkMethods(array("outputEditor", "getOutputEditorValues", "update", "create")); @@ -124,9 +124,17 @@ class ObjectManager // link back to the previous page echo html_back_link(1, $sBackLink); - echo '
',"\n"; + $oObject = new $this->sClass($this->iId); + + /* Display errors, if any, and fetch form data */ + if($this->displayErrors($sErrors)) + { + global $aClean; + $oObject->getOutputEditorValues($aClean); + } + + echo 'iId). + '" method="post" enctype="multipart/form-data">',"\n"; echo ''; echo ''; @@ -136,8 +144,6 @@ class ObjectManager echo ''; - $oObject = new $this->sClass($this->iId); - $oObject->outputEditor(); /* if this is a queue add a dialog for replying to the submitter of the @@ -215,13 +221,24 @@ class ObjectManager } /* Display screen for submitting a new entry of given type */ - function add_entry($sBackLink) + 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"; $oObject->outputEditor(); @@ -272,6 +289,14 @@ class ObjectManager $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": @@ -299,12 +324,16 @@ class ObjectManager $this->delete_entry(); } - if(!$this->bIsQueue) - $sAction = "view"; + /* 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 - $sAction = false; + $sRedirectLink = APPDB_ROOT; - util_redirect_and_exit($this->makeUrl($sAction, false, "$this->sClass list")); + util_redirect_and_exit($sRedirectLink); + + return TRUE; } /* Make an objectManager URL based on the object and optional parameters */ @@ -362,6 +391,18 @@ class ObjectManager return $sQueueString; } + + function displayErrors($sErrors) + { + if($sErrors) + { + echo "\n"; + echo "The following errors were found
\n"; + echo "\n"; + echo "

"; + } else + return FALSE; + } } ?> diff --git a/objectManager.php b/objectManager.php index 89415d9..e57035d 100644 --- a/objectManager.php +++ b/objectManager.php @@ -40,8 +40,12 @@ if($aClean['bIsRejected'] == 'true') $oOtherObject = new $oObject->sClass($oObject->iId); -/* Certain actions must be performed before the header is set */ -$oObject->processForm($aClean); +/* Certain actions must be performed before the header is set + processForm return TRUE on success, or a user-readable list of errors + on failure */ +$sErrors = $oObject->processForm($aClean); +if($sErrors === TRUE) + $sErrors = ""; if($oObject->iId && $aClean['sAction'] == "delete") $oObject->delete_entry(); @@ -58,7 +62,7 @@ if($oObject->iId) break; case "edit": - $oObject->display_entry_for_editing($REQUEST_URI); + $oObject->display_entry_for_editing($REQUEST_URI, $sErrors); break; default: @@ -66,7 +70,7 @@ if($oObject->iId) break; } } else if ($aClean['sAction'] == "add") - $oObject->add_entry($REQUEST_URI); + $oObject->add_entry($REQUEST_URI, $sErrors); else { // if displaying a queue display the help for the given queue