diff --git a/distributionView.php b/distributionView.php
index 8466192..ed7084b 100644
--- a/distributionView.php
+++ b/distributionView.php
@@ -25,46 +25,25 @@ if ($aClean['sSub'])
}
$oDistribution = new distribution($aClean['iDistributionId']);
-//exit with error if no distribution
+/* Display distribution list if no id given */
if(!$oDistribution->iDistributionId)
{
apidb_header("View Distributions");
//get available Distributions
- $hResult = query_parameters("SELECT distributionId FROM distributions ORDER BY name, distributionId;");
+ $hResult = distribution::ObjectGetEntries(false);
// show Distribution list
echo html_frame_start("","90%","",0);
echo "
\n\n";
- echo "\n";
- echo " | Distribution name | \n";
- echo " Distribution url | \n";
- echo " Linked Tests | \n";
- if ($_SESSION['current']->hasPriv("admin"))
- echo " Action | \n";
- echo "
\n\n";
-
- $c = 1;
- while($oRow = mysql_fetch_object($hResult))
+ distribution::ObjectOutputHeader("color4");
+
+ for($c = 1; $oRow = mysql_fetch_object($hResult); $c++)
{
- if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; }
- $oDistribution = new distribution($oRow->distributionId);
- echo "\n";
- echo " | iDistributionId."\">","\n";
- echo $oDistribution->sName." | \n";
- echo " sUrl."\">".$oDistribution->sUrl." | \n";
- echo " ".sizeof($oDistribution->aTestingIds)." | \n";
- if ($_SESSION['current']->hasPriv("admin"))
- {
- echo " ";
- echo "[edit]";
- if(!sizeof($oDistribution->aTestingIds))
- echo " [iDistributionId."'>delete]";
- echo " | \n";
- }
- echo "
\n";
- $c++;
+ $oDistribution = distribution::ObjectGetInstanceFromRow($oRow);
+
+ $oDistribution->display(($c % 2) ? "color0" : "color1");
}
echo "
\n\n";
echo html_frame_end(" ");
diff --git a/include/distribution.php b/include/distribution.php
index 5dac91a..c5d34d6 100644
--- a/include/distribution.php
+++ b/include/distribution.php
@@ -7,7 +7,7 @@ require_once(BASE."include/util.php");
// Test class for handling Distributions.
-class distribution{
+class distribution {
var $iDistributionId;
var $sName;
var $sDescription;
@@ -422,6 +422,76 @@ class distribution{
}
echo "\n";
}
+
+ function ObjectOutputHeader($sClass = "")
+ {
+ $aCells = array(
+ "Distribution name",
+ "Distribution url",
+ array("Linked Tests", "align=\"right\""));
+
+ if(distribution::canEdit())
+ $aCells[3] = array("Action", "align=\"center\"");
+
+ echo html_tr($aCells, $sClass);
+ }
+
+ function ObjectGetEntries($bQueued)
+ {
+ if($bQueued)
+ {
+ if(distribution::canEdit())
+ {
+ /* Only users with edit privileges are allowed to view queued
+ items, so return NULL in that case */
+ $sQuery = "SELECT distributionId FROM distributions
+ WHERE queued = '?' ORDER BY name";
+ return query_parameters($sQuery, $bQueued ? "true" : "false");
+ } else
+ return NULL;
+ } else
+ {
+ $sQuery = "SELECT distributionId FROM distributions
+ WHERE queued = '?' ORDER BY name";
+ return query_parameters($sQuery, "false");
+ }
+ }
+
+ function ObjectGetInstanceFromRow($oRow)
+ {
+ return new distribution($oRow->distributionId);
+ }
+
+ function display($sClass = "")
+ {
+ $aCells = array(
+ "iDistributionId."\">$this->sName.",
+ "sUrl\">$this->sUrl",
+ array(sizeof($this->aTestingIds), "align=\"right\""));
+
+ if($this->canEdit())
+ {
+ $aCells[3] = array(
+ "[edit]".
+ (!sizeof($this->aTestingIds)) ?
+ " [iDistributionId'>delete]" : "",
+ "align=\"center\"");
+ }
+
+ echo html_tr($aCells, $sClass);
+ }
+
+ // Whether the user has permission to edit distributions
+ function canEdit()
+ {
+ if($_SESSION['current']->hasPriv("admin"))
+ return TRUE;
+
+ return FALSE;
+ }
}
?>