diff --git a/admin/editDistribution.php b/admin/editDistribution.php
deleted file mode 100644
index 5068e99..0000000
--- a/admin/editDistribution.php
+++ /dev/null
@@ -1,42 +0,0 @@
-hasPriv("admin"))
- util_show_error_page_and_exit("Insufficient privileges.");
-
-$oDistribution = new distribution($aClean['iDistributionId']);
-if($aClean['sSubmit'])
-{
- $oDistribution->GetOutputEditorValues($aClean);
-
- if($oDistribution->iDistributionId)
- $oDistribution->update();
- else
- {
- $oDistribution->create();
- }
-
- util_redirect_and_exit(apidb_fullurl("distributionView.php"));
-}
-else
-{
- if ($oDistribution->iDistributionId)
- apidb_header("Edit Distribution");
- else
- apidb_header("Add Distribution");
-
- echo '
";
- echo html_frame_end(" ");
- apidb_footer();
-}
-?>
diff --git a/admin/editVendor.php b/admin/editVendor.php
deleted file mode 100644
index 7c76c62..0000000
--- a/admin/editVendor.php
+++ /dev/null
@@ -1,37 +0,0 @@
-hasPriv("admin"))
- util_show_error_page_and_exit();
-
-$oVendor = new Vendor($aClean['iVendorId']);
-if($aClean['sSubmit'])
-{
- $oVendor->getOutputEditorValues($aClean);
- $oVendor->update();
- util_redirect_and_exit(apidb_fullurl("vendorview.php"));
-}
-else
-{
- if($oVendor->iVendorId)
- apidb_header("Edit Vendor");
- else
- apidb_header("Add Vendor");
-
- // Show the form
- echo '";
- echo html_frame_end(" ");
- apidb_footer();
-
-}
-?>
diff --git a/include/distribution.php b/include/distribution.php
index a8b90a5..241b377 100644
--- a/include/distribution.php
+++ b/include/distribution.php
@@ -363,7 +363,6 @@ class distribution {
function outputEditor()
{
- echo html_frame_start("Distribution Form", "90%", "", 0);
echo "\n";
// Name
@@ -376,7 +375,6 @@ class distribution {
echo '',"\n";
echo "
\n";
- echo html_frame_end();
}
/* retrieves values from $_REQUEST that were output by outputEditor() */
@@ -459,11 +457,11 @@ class distribution {
return new distribution($oRow->distributionId, $oRow);
}
- function objectOutputTableRow($sClass = "")
+ function objectOutputTableRow($oManager, $sClass)
{
$aCells = array(
- "iDistributionId."\">$this->sName.",
+ "makeUrl("view", $this->iDistributionId,
+ "View distribution")."\">$this->sName.",
"sUrl\">$this->sUrl",
array(sizeof($this->aTestingIds), "align=\"right\""));
@@ -471,12 +469,12 @@ class distribution {
{
if(!sizeof($this->aTestingIds))
{
- $sDelete = " [iDistributionId'>delete]";
+ $sDelete = " [delete]";
}
$aCells[3] = array(
- "[edit]$sDelete",
+ "[edit]$sDelete",
"align=\"center\"");
}
diff --git a/include/objectManager.php b/include/objectManager.php
new file mode 100644
index 0000000..2879009
--- /dev/null
+++ b/include/objectManager.php
@@ -0,0 +1,288 @@
+sClass = $sClass;
+ $this->sTitle = $sTitle;
+ $this->iId = $iId;
+ }
+
+ /* Check whether the associated class has the given method */
+ function checkMethod($sMethodName, $bEnableOutput)
+ {
+ if(!method_exists($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", "ObjectOutputHeader",
+ "ObjectGetInstanceFromRow", "ObjectOutputTableRow"));
+
+
+ /* 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 = call_user_func(array($this->sClass,
+ "objectGetEntries"), $this->bIsQueue);
+
+ /* did we get any entries? */
+ if(mysql_num_rows($hResult) == 0)
+ {
+ $sIsQueue = $this->bIsQueue ? "true" : "false";
+
+ if($this->bIsQueue)
+ echo "The queue for '$this->sClass' is empty";
+ else
+ echo "No entries of '$this->sClass' are present";
+
+ echo "
sClass&bIsQueue=$sIsQueue&sTitle=".
+ urlencode($this->sTitle)."&sAction=add\">Add an entry?";
+ return;
+ }
+
+ /* output the header */
+ echo '';
+
+ call_user_func(array($this->sClass,
+ "objectOutputHeader"), "color4");
+
+
+ /* output each entry */
+ for($iCount = 0; $oRow = mysql_fetch_object($hResult); $iCount++)
+ {
+ $oObject = call_user_func(array($this->sClass,
+ "objectGetInstanceFromRow"), $oRow);
+
+ $oObject->objectOutputTableRow($this,
+ ($iCount % 2) ? "color0" : "color1");
+ }
+
+ echo "
";
+
+ $oObject = new $this->sClass();
+ if($oObject->canEdit())
+ {
+ echo "
sClass&sAction=add&sTitle=Add\">".
+ "Add entry\n";
+ }
+ }
+
+ /* display the entry for editing */
+ function display_entry_for_editing($sBackLink)
+ {
+ $this->checkMethods(array("outputEditor", "getOutputEditorValues",
+ "update", "create"));
+
+ // link back to the previous page
+ echo html_back_link(1, $sBackLink);
+
+ echo '';
+
+ }
+
+ /* Display help for queue processing */
+ function display_queue_processing_help()
+ {
+ /* No help text defined, so do nothing */
+ if(!method_exists($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)
+ {
+ $this->checkMethods(array("outputEditor", "getOutputEditorValues",
+ "update", "create"));
+
+ $oObject = new $this->sClass();
+
+ 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);
+
+ $oObject->getOutputEditorValues($aClean);
+
+ if($this->iId)
+ {
+ if(!$oObject->canEdit())
+ return FALSE;
+
+ $oObject->update();
+ }
+ else
+ $oObject->create();
+
+ $sIsQueue = $tihs->bIsQueue ? "true" : "false";
+
+ util_redirect_and_exit($this->makeUrl("view", false, "$this->sClass list"));
+ }
+
+ /* 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";
+
+ if(!$sTitle)
+ $sTitle = $this->sTitle;
+
+ $sTitle = urlencode($sTitle);
+
+ return $_SERVER['PHP_SELF']."?bIsQueue=$sIsQueue&sClass=$this->sClass".
+ "&sTitle=$sTitle$sId$sAction";
+ }
+
+ /* Get id from form data */
+ function getIdFromInput($aClean)
+ {
+ $sId = "i".ucfirst($this->sClass)."Id";
+ return $aClean[$sId];
+ }
+}
+
+?>
diff --git a/include/sidebar.php b/include/sidebar.php
index 82723cd..59939f0 100644
--- a/include/sidebar.php
+++ b/include/sidebar.php
@@ -28,9 +28,8 @@ function global_sidebar_menu()
$g->add("Submit Application", BASE."appsubmit.php?sSub=view&sAppType=application");
$g->add("Help & Documentation", BASE."help/");
$g->add("AppDB Stats", BASE."appdbStats.php");
- $g->add("View Distributions (".distribution::getNumberOfDistributions(false).")", BASE."distributionView.php");
- $g->add("View Vendors (".getNumberOfvendors().")", BASE."vendorview.php");
-
+ $g->add("View Distributions (".distribution::getNumberOfDistributions(false).")", BASE."objectManager.php?sClass=distribution&bIsQueue=false&sTitle=View%20Distributions");
+ $g->add("View Vendors (".getNumberOfvendors().")", BASE."objectManager.php?sClass=vendor&bIsQueue=false&sTitle=View%20Vendors");
$g->add("Email your suggestions for improving the AppDB", "mailto:appdb@winehq.org");
$g->done();
diff --git a/include/vendor.php b/include/vendor.php
index 8aa5aae..bc618ea 100644
--- a/include/vendor.php
+++ b/include/vendor.php
@@ -61,6 +61,9 @@ class Vendor {
*/
function create()
{
+ if(!$this->canEdit())
+ return FALSE;
+
$hResult = query_parameters("INSERT INTO vendor (vendorName, vendorURL) ".
"VALUES ('?', '?')",
$this->sName, $this->sWebpage);
@@ -182,23 +185,23 @@ class Vendor {
return new vendor($oRow->vendorId, $oRow);
}
- function objectOutputTableRow($sClass = "")
+ function objectOutputTableRow($oObject, $sClass = "")
{
$aCells = array(
- "iVendorId\">".
- "$this->sName",
+ "makeUrl("view", $this->iVendorId,
+ "View Vendor")."\">$this->sName",
"sWebpage\">$this->sWebpage",
array(sizeof($this->aApplicationsIds), "align=\"right\""));
if($this->canEdit())
{
if(!sizeof($this->aApplicationsIds))
- $sDelete = " [iVendorId\">".
+ $sDelete = " [makeUrl("delete",
+ $this->iVendorId, "View Vendors")."\">".
"delete]";
- $aCells[sizeof($aCells)] = "[iVendorId\">edit]$sDelete";
+ $aCells[sizeof($aCells)] = "[makeUrl("edit",
+ $this->iVendorId, "Edit Vendor")."\">edit]$sDelete";
}
echo html_tr($aCells, $sClass);
@@ -223,7 +226,8 @@ class Vendor {
echo 'Vendor Name: '.$this->sName,"\n";
if($this->canEdit())
{
- echo "[iVendorId\">edit]";
+ echo "[iVendorId&sTitle=Edit%20Vendor\">edit]";
}
echo '
',"\n";
diff --git a/objectManager.php b/objectManager.php
new file mode 100644
index 0000000..c18970f
--- /dev/null
+++ b/objectManager.php
@@ -0,0 +1,70 @@
+bIsQueue = true;
+else $oObject->bIsQueue = false;
+
+
+$oOtherObject = new $oObject->sClass($oObject->iId);
+
+/* Certain actions must be performed before the header is set */
+$oObject->processForm($aClean);
+
+if($oObject->iId && $aClean['sAction'] == "delete")
+ $oObject->delete_entry();
+
+apidb_header($oObject->sTitle);
+
+/* display a particular element */
+if($oObject->iId)
+{
+ switch($aClean['sAction'])
+ {
+ case "cancel":
+ $oObject->display_table(); /* go back to the queue */
+ break;
+
+ case "edit":
+ $oObject->display_entry_for_editing($REQUEST_URI);
+ break;
+
+ default:
+ $oObject->view($REQUEST_URI);
+ break;
+ }
+} else if ($aClean['sAction'] == "add")
+ $oObject->add_entry($REQUEST_URI);
+else
+{
+ // if displaying a queue display the help for the given queue
+ if($oObject->bIsQueue)
+ $oObject->display_queue_processing_help();
+
+ $oObject->display_table();
+}
+
+?>
diff --git a/unit_test/run_tests.php b/unit_test/run_tests.php
index 1ab140f..8b681bc 100644
--- a/unit_test/run_tests.php
+++ b/unit_test/run_tests.php
@@ -24,4 +24,6 @@ echo "\n";
include_once("test_filter.php");
echo "\n";
include_once("test_url.php");
+echo "\n";
+include_once("test_om_objects.php");
?>
diff --git a/unit_test/test_om_objects.php b/unit_test/test_om_objects.php
new file mode 100644
index 0000000..9e1ed66
--- /dev/null
+++ b/unit_test/test_om_objects.php
@@ -0,0 +1,115 @@
+hasValidMethods(true))
+ {
+ return false;
+ }
+
+ return true;
+}
+
+function test_object_methods()
+{
+ test_start(__FUNCTION__);
+
+/* $sClassName = 'application';
+ if(!test_class($sClassName))
+ {
+ echo $sClassName." class does not have valid methods for use with the object manager\n";
+ return false;
+ } else
+ {
+ echo "PASSED:\t\t".$sClassName."\n";
+ }
+
+ $sClassName = 'application_queue';
+ if(!test_class($sClassName))
+ {
+ echo $sClassName." class does not have valid methods for use with the object manager\n";
+ return false;
+ } else
+ {
+ echo "PASSED:\t\t".$sClassName."\n";
+ }
+
+ $sClassName = 'version';
+ if(!test_class($sClassName))
+ {
+ echo $sClassName." class does not have valid methods for use with the object manager\n";
+ return false;
+ } else
+ {
+ echo "PASSED:\t\t".$sClassName."\n";
+ }
+
+ $sClassName = 'version_queue';
+ if(!test_class($sClassName))
+ {
+ echo $sClassName." class does not have valid methods for use with the object manager\n";
+ return false;
+ } else
+ {
+ echo "PASSED:\t\t".$sClassName."\n";
+ }
+
+ $sClassName = 'maintainer';
+ if(!test_class($sClassName))
+ {
+ echo $sClassName." class does not have valid methods for use with the object manager\n";
+ return false;
+ } else
+ {
+ echo "PASSED:\t\t".$sClassName."\n";
+ } */
+
+ $aTestMethods = array("objectOutputHeader", "objectOutputTableRow",
+ "objectGetEntries", "display",
+ "objectGetInstanceFromRow", "outputEditor", "canEdit");
+
+ $oObject = new ObjectManager("");
+ $oObject->sClass = 'distribution';
+ if(!$oObject->checkMethods($aTestMethods, false))
+ {
+ echo $oObject->sClass." class does not have valid methods for use with".
+ " the object manager\n";
+ return false;
+ } else
+ {
+ echo "PASSED:\t\t".$oObject->sClass."\n";
+ }
+
+ $oObject->sClass = 'vendor';
+ if(!$oObject->checkMethods($aTestMethods, false))
+ {
+ echo $oObject->sClass." class does not have valid methods for use with".
+ " the object manager\n";
+ return false;
+ } else
+ {
+ echo "PASSED:\t\t".$oObject->sClass."\n";
+ }
+
+ return true;
+}
+
+if(!test_object_methods())
+ echo "test_object_methods() failed!\n";
+else
+ echo "test_object_methods() passed\n";
+
+?>