appdb/ ./objectManager.php include/objectManag ...

WineHQ wineowner at wine.codeweavers.com
Sun Mar 25 13:52:19 CDT 2007


ChangeSet ID:	31008
CVSROOT:	/opt/cvs-commit
Module name:	appdb
Changes by:	wineowner at winehq.org	2007/03/25 13:52:19

Modified files:
	.              : objectManager.php 
	include        : objectManager.php 

Log message:
	Alexander Nicolaysen Sørnes <alex at thehandofagony.com>
	objectManager: check editor values

Patch: http://cvs.winehq.org/patch.py?id=31008

Old revision  New revision  Changes     Path
 1.2           1.3           +8 -4       appdb/objectManager.php
 1.9           1.10          +52 -11     appdb/include/objectManager.php

Index: appdb/objectManager.php
diff -u -p appdb/objectManager.php:1.2 appdb/objectManager.php:1.3
--- appdb/objectManager.php:1.2	25 Mar 2007 18:52:19 -0000
+++ appdb/objectManager.php	25 Mar 2007 18:52:19 -0000
@@ -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
Index: appdb/include/objectManager.php
diff -u -p appdb/include/objectManager.php:1.9 appdb/include/objectManager.php:1.10
--- appdb/include/objectManager.php:1.9	25 Mar 2007 18:52:19 -0000
+++ appdb/include/objectManager.php	25 Mar 2007 18:52:19 -0000
@@ -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 '<form name="sQform" action="'.BASE.'objectManager.php?sClass='.
-             $this->sClass."&bIsQueue=".($this->bIsQueue ? "true" : "false").
-             ' method="post" enctype="multipart/form-data">',"\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 '<form name="sQform" action="'.$this->makeUrl("edit", $this->iId).
+                '" method="post" enctype="multipart/form-data">',"\n";
 
         echo '<input type="hidden" name="sClass" value="'.$this->sClass.'" />';
         echo '<input type="hidden" name="sTitle" value="'.$this->sTitle.'" />';
@@ -136,8 +144,6 @@ class ObjectManager
         echo '<input type="hidden" name="bIsRejected" '.
              'value='.($this->bIsRejected ? "true" : "false").' />';
 
-        $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 "<form method=\"post\">\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($sRedirectLink);
 
-        util_redirect_and_exit($this->makeUrl($sAction, false, "$this->sClass list"));
+        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 "<font color=\"red\">\n";
+            echo "The following errors were found<br />\n";
+            echo "<ul>$sErrors</ul>\n";
+            echo "</font><br />";
+        } else
+            return FALSE;
+    }
 }
 
 ?>



More information about the wine-cvs mailing list