[AppDB] Let users submit the results of testing their application with wine.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[AppDB] Let users submit the results of testing their application with wine.

Tony Lambregts
This (Big) patch is big step towards getting the AppDB ready for Wine
0.9. It Lets users submit the results of testing their application with
wine.

You will need to run the sql files in order for this patch to work.

Still to do.

* Integrate test results form into pages where users submit Applications
and Versions.
* Allow Maintainers a way of administrating the test results.
* Pages that would be usefull for developers.

Change Log: Let users submit the results of testing their application
with wine.

Files Changed: application.css appview.php admin/adminAppQueue.php
include/sidebar_admin.php  include/util.php

Files Added:  testResults.php distributionView.php
admin/adminTestResults.php admin/adminDistributions.php
admin/editDistribution.php admin/adminDistributions.php
include/distributions.php include/testResults.php
tables/distributions.sql tables/testResults.sql


Index: application.css
===================================================================
RCS file: /home/wine/appdb/application.css,v
retrieving revision 1.4
diff -u -r1.4 application.css
--- application.css 15 Oct 2005 15:18:19 -0000 1.4
+++ application.css 16 Oct 2005 21:04:35 -0000
@@ -21,5 +21,9 @@
 td.gold { background-color: #fff600; }
 td.silver { background-color: silver; }
 td.bronze { background-color: #fcba0a; }
-td.garbage { background-color: #5c4f2a; }
+td.garbage { background-color: #999966; }
 
+tr.gold { background-color: #fff600; }
+tr.silver { background-color: silver; }
+tr.bronze { background-color: #fcba0a; }
+tr.Garbage { background-color: #999966; }
Index: appview.php
===================================================================
RCS file: /home/wine/appdb/appview.php,v
retrieving revision 1.73
diff -u -r1.73 appview.php
--- appview.php 30 Sep 2005 01:55:51 -0000 1.73
+++ appview.php 16 Oct 2005 21:04:35 -0000
@@ -15,6 +15,7 @@
 require(BASE."include/maintainer.php");
 require(BASE."include/mail.php");
 require(BASE."include/monitor.php");
+require_once(BASE."include/testResults.php");
 
 
 $oApp = new Application($_REQUEST['appId']);
@@ -503,8 +504,19 @@
     // description
     echo "<table width='100%' border=0><tr><td width='100%' valign=top> <b>Description</b><br />\n";
     echo $oVersion->sDescription;
-    echo "</td></tr>";
 
+    // Show testing data
+    $oTest = new TestData($_REQUEST['iTestingId']);
+    $iCurrentTest = $oTest->ShowTestResult($oTest->iTestingId,$oVersion->iVersionId);
+    if($iCurrentTest)
+        $oTest->ShowVersionsTestingTable($oVersion->iVersionId,$iCurrentTest,$_SERVER['PHP_SELF']."?versionId=".$oVersion->iVersionId."&iTestingId=");
+    echo '<form method=post name=message action=testResults.php?sub=view&iVersionId='.$oVersion->iVersionId.'>';
+    echo '<input type=submit value="Add Testing Data" class="button" />';
+    echo '</form>';
+    
+
+    echo "</td></tr>";
+    
     /* close the table */
     echo "</table>\n";
 
Index: include/sidebar_admin.php
===================================================================
RCS file: /home/wine/appdb/include/sidebar_admin.php,v
retrieving revision 1.17
diff -u -r1.17 sidebar_admin.php
--- include/sidebar_admin.php 5 Aug 2005 22:07:41 -0000 1.17
+++ include/sidebar_admin.php 16 Oct 2005 21:04:36 -0000
@@ -2,6 +2,8 @@
 /*****************/
 /* sidebar_admin */
 /*****************/
+require_once(BASE."include/testResults.php");
+require_once(BASE."include/distributions.php");
 
 function global_admin_menu() {
 
@@ -9,6 +11,7 @@
     
     $g->add("Add Category", BASE."admin/addCategory.php");
     $g->add("Add Vendor", BASE."admin/addVendor.php");
+    $g->add("Add Distribution", BASE."admin/editDistribution.php");
     
     $g->addmisc("&nbsp;");
     $g->add("View App Queue (".$_SESSION['current']->getQueuedAppCount()."/".$_SESSION['current']->getQueuedVersionCount().")", BASE."admin/adminAppQueue.php");
@@ -17,11 +20,14 @@
     $g->add("View Maintainer Entries (".getMaintainerCount().")", BASE."admin/adminMaintainers.php");
     $g->add("View Vendors (".getVendorCount().")", BASE."admin/adminVendors.php");
     $g->add("View Bug Links (".getNumberOfQueuedBugLinks()."/".getNumberOfBugLinks().")", BASE."admin/adminBugs.php");
+    $g->add("View TestResults (".getNumberOfQueuedTests().")", BASE."admin/adminTestResults.php");
+    $g->add("View Distributions (".getNumberOfDistributions().")", BASE."admin/adminDistributions.php");
 
     $g->addmisc("&nbsp;");
     $g->add("Users Management", BASE."admin/adminUsers.php");
     $g->add("Comments Management", BASE."admin/adminCommentView.php");
     $g->add("Screenshots Management", BASE."admin/adminScreenshots.php");
+
     $g->done();
 }
 
Index: include/util.php
===================================================================
RCS file: /home/wine/appdb/include/util.php,v
retrieving revision 1.48
diff -u -r1.48 util.php
--- include/util.php 11 Oct 2005 01:06:54 -0000 1.48
+++ include/util.php 16 Oct 2005 21:04:37 -0000
@@ -117,7 +117,7 @@
     if(!$result) return;
 
     echo "<select name='$varname'>\n";
-    echo "<option value=\" \">Choose ...</option>\n";
+    echo "<option value=\"\">Choose ...</option>\n";
     while(list($value) = mysql_fetch_row($result))
     {
         if($value == $cvalue)
@@ -132,7 +132,7 @@
 {
     
     echo "<select name='$varname'>\n";
-    echo "<option value=\" \">Choose ...</option>\n";
+    echo "<option value=\"\">Choose ...</option>\n";
     $aRating = array("Gold", "Silver", "Bronze", "Garbage");
     $iMax = count($aRating);
 
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ testResults.php 2005-10-15 22:50:21.000000000 -0600
@@ -0,0 +1,223 @@
+<?php
+/**************************************************/
+/* code to submit, view and resubmit Test Results */
+/**************************************************/
+
+include("path.php");
+require(BASE."include/incl.php");
+require(BASE."include/tableve.php");
+require(BASE."include/application.php");
+require(BASE."include/mail.php");
+require_once(BASE."include/testResults.php");
+require_once(BASE."include/distributions.php");
+
+
+
+if ($_REQUEST['sub'])
+{
+    $oTest = new testData($_REQUEST['iTestingId']);
+    if($_REQUEST['iVersionId'])
+        $oTest->iVersionId = $_REQUEST['iVersionId'];
+    $errors = "";
+// $errors .= "<li>:".$_REQUEST['iVersionId'].":</li>\n";
+// $errors .= "<li>:".$oTest->iVersionId.":</li>\n";
+    // Submit the new testing results
+    if ($_REQUEST['sub'] == 'Submit')
+    {
+        $errors = $oTest->CheckOutputEditorInput();
+        $oTest->GetOutputEditorValues(); // retrieve the values from the current $_REQUEST
+        if(empty($errors) && is_numeric($_REQUEST['iVersionId']))
+        {
+            $sDistribution = trim($_REQUEST['sDistribution']);
+            if(!empty($sDistribution))
+            {
+                $oDistribution = new distribution();
+                $oDistribution->sName = $sDistribution;
+                $oDistribution->create();
+                $oTest->iDistributionId = $oDistribution->iDistributionId;
+            }
+            $oTest->create();
+            redirect($_SERVER['PHP_SELF']);
+        } else
+        {
+            $_REQUEST['sub'] = 'view';
+        }
+    }
+    // Resubmit testing results
+    if ($_REQUEST['sub'] == 'Resubmit')
+    {
+        $oTest->GetOutputEditorValues(); // retrieve the values from the current $_REQUEST
+        $errors = $oTest->CheckOutputEditorInput();
+        if(empty($errors))
+        {
+            $sDistribution = trim($_REQUEST['sDistribution']);
+            if(!empty($sDistribution))
+            {
+                $oDistribution = new distribution();
+                $oDistribution->sName = $sDistribution;
+                $oDistribution->create();
+                $oTest->iDistributionId = $oDistribution->iDistributionId;
+            }
+            $oTest->update(true);
+            $oTest->ReQueue();
+            redirect($_SERVER['PHP_SELF']);
+        } else
+        {
+            $_REQUEST['sub'] = 'view';
+        }
+    }
+
+    // Delete testing results
+    if ($_REQUEST['sub'] == 'Delete')
+    {
+        if(is_numeric($_REQUEST['iTestingId']))
+        {
+            $oTest = new testData($_REQUEST['iTestingId']);
+            $oTest->delete();
+        }
+        
+        redirect($_SERVER['PHP_SELF']);
+    }
+
+    // is this an old test?
+    if(is_numeric($_REQUEST['iTestingId']))
+    {
+        // make sure the user has permission to view this testing result
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !$_SESSION['current']->hasAppVersionModifyPermission($oTest->iVersionId)&&
+           !(($_SESSION['current']->iUserId == $oTest->iSubmitterId) && !($oTest->sQueued == 'false')))
+        {
+            errorpage("Insufficient privileges.");
+            exit;
+        } else
+        $oVersion = new version($oTest->iVersionId);
+    } else
+    {
+        $oTest->iVersionId = $_REQUEST['iVersionId'];
+        $oVersion = new version($_REQUEST['iVersionId']);      
+        $oTest->sQueued = "new";
+    }
+    if ($_REQUEST['sub'] == 'view')
+    {
+        $oApp = new application($oVersion->iAppId);
+        $sVersionInfo = $oApp->sName." ".$oVersion->sName;
+
+        switch($oTest->sQueued)
+        {
+        case "new":
+            apidb_header("Submit new testing results for ".$sVersionInfo);
+            $oTest->sTestedDate = date('Y-m-d H:i:s');
+            break;
+        case "true":
+            apidb_header("Edit new testing results for ".$sVersionInfo);
+            break;
+        case "rejected":
+            apidb_header("Resubmit testing results for ".$sVersionInfo);
+            break;
+        case "False":
+            apidb_header("Edit testing results for ".$sVersionInfo);
+            break;
+        default:
+            apidb_header("Edit testing results for ");
+        }
+        echo '<form name="qform" action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">',"\n";
+
+
+        //help
+        echo "<p>This is the Screen for imputting testing information so that others looking at the database will know \n";
+        echo "what was working or a particular release of Wine.</p>\n";
+        echo "<p>Please be as detailed as you can.</p>\n";
+        echo "<p>If you can not find your distribution on the list of existing Distributions please add it add it in the \n";
+        echo "field provided.</p>\n\n";        
+
+        if(!empty($errors))
+        {
+            echo '<font color="red">',"\n";
+            echo '<p class="red"> We found the following errors:</p><ul>'.$errors.'</ul>Please correct them.';
+            echo '</font><br />',"\n";
+            echo '<p></p>',"\n";
+        }
+  
+        // View Testing Details
+        $oTest->OutputEditor($_REQUEST['sDistribution'],true);
+
+        echo '<a href="'.BASE."appview.php?versionId=".$oTest->iVersionId.'">Back to Version</a>';
+
+        echo '<tr valign=top><td class=color3 align=center colspan=2>',"\n";
+
+
+        // Submit Buttons
+        switch($oTest->sQueued)
+        {
+        case "new":
+            echo '<input name="sub" type="submit" value="Submit" class="button" >&nbsp',"\n";
+            break;
+        case "true":
+        case "rejected":
+        case "False":
+             echo '<input name="sub" type="submit" value="Resubmit" class="button" >&nbsp',"\n";
+             echo '<input name="sub" type="submit" value="Delete" class="button" >',"\n";
+             break;
+        }
+        echo '</td></tr>',"\n";    
+        echo "</form>";
+
+        echo html_frame_end("&nbsp;");
+    }
+    else
+    {
+        // error no sub!
+        addmsg("Internal Routine Not Found!!", "red");
+        redirect($_SERVER['PHP_SELF']);
+    }
+}
+else // if ($_REQUEST['sub']) is not defined, display the Testing results queue page
+{
+    apidb_header("Testing Results");
+
+    // Get queued testing results.
+    $oTest = new TestData();
+    $hResult = $oTest->getTestingQueue("true");
+
+    if(!$hResult)
+    {
+        // no Tests in queue
+        echo html_frame_start("Submitted Testing Results","90%");
+        echo '<p><b>The Submitted Testng Results Queue is empty.</b></p>',"\n";
+        echo html_frame_end("&nbsp;");        
+    }
+    else
+    {
+        // help
+        echo "<div align=center><table width='90%' border=0 cellpadding=3 cellspacing=0><tr><td>\n\n";
+        echo "<p>This is the list of Test Results waiting for submition, or to be deleted.</p>\n";
+        echo "<p>To view a submission, click on its name. From that page you can delete or edit and\n";
+        echo "re-submit it into the AppDB .<br>\n";
+        echo "</td></tr></table></div>\n\n";
+
+        $oTest->ShowListofTests($hResult,"Submitted Testing Results");
+    }
+    // Get rejected testing results.
+    $hResult = $oTest->getTestingQueue("rejected");
+
+    if(!$hResult || !mysql_num_rows($hResult))
+    {
+        //no Test Results in queue
+        echo html_frame_start("Rejected Testing Results","90%");
+        echo '<p><b>The Rejected Testng Results Queue is empty.</b></p>',"\n";
+        echo html_frame_end("&nbsp;");        
+    }
+    else
+    {
+        //help
+        echo "<div align=center><table width='90%' border=0 cellpadding=3 cellspacing=0><tr><td>\n\n";
+        echo "<p>This is the list of Rejected Test Results waiting for re-submition or deletion.</p>\n";
+        echo "<p>To view a submission, click on its name. From that page you can delete or edit and re-submit it into \n";
+        echo "the AppDB .<br>\n";
+        echo "</td></tr></table></div>\n\n";
+
+        $oTest->ShowListofTests($hResult,"Rejected Testing Results");
+    }
+}
+apidb_footer();      
+?>
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ distributionView.php 2005-10-09 22:55:05.000000000 -0600
@@ -0,0 +1,79 @@
+<?php
+/*************************************/
+/* code to view vendors & their apps */
+/*************************************/
+
+/*
+ * application environment
+ */
+include("path.php");
+require(BASE."include/incl.php");
+require(BASE."include/distributions.php");
+require(BASE."include/testResults.php");
+//require(BASE."include/application.php");
+//require(BASE."include/version.php");
+
+$oDistribution = new distribution($_REQUEST['iDistributionId']);
+
+//exit with error if no vendor
+if(!$oDistribution->iDistributionId)
+{
+    errorpage("No Distribution ID specified!");
+    exit;
+}
+else
+{
+    //display page
+    apidb_header("View Distribution");
+    echo html_frame_start("Distribution Information",500);
+    echo "Distribution Name: ".$oDistribution->sName." <br />\n";
+
+    if ($oDistribution->sUrl)
+        echo "<a href='".$oDistribution->sUrl."'>Distribution Page</a> <br />\n";
+
+
+    if($oDistribution->aTestingIds)
+    {
+        echo "<br />Testing results for ".$oDistribution->sName."<br /><ol>\n";
+        echo '<p><span class="title">Testing Results</span><br />',"\n";
+        echo '<table width="100%" border="0">',"\n";
+        echo '<thead class="historyHeader">',"\n";
+        echo '<tr>',"\n";
+        echo '<td>Submitter</td>',"\n";
+        echo '<td>Date Submitted</td>',"\n";
+        echo '<td>Wine version</td>',"\n";
+        echo '<td>Installs?</td>',"\n";
+        echo '<td>Runs?</td>',"\n";
+        echo '<td>Rating</td>',"\n";
+        echo '</tr></thead>',"\n";
+        foreach($oDistribution->aTestingIds as $iTestingId)
+        {
+            $oTest = new testData($iTestingId);
+            $oVersion = new version($oTest->iVersionId);
+            $oApp  = new application($oVersion->iAppId);
+            $oSubmitter = new User($oTest->iSubmitterId);
+            $bgcolor = $oTest->sTestedRating;
+            echo '<tr class='.$bgcolor.'>',"\n";
+            echo '    <td>',"\n";
+            echo $oSubmitter->sEmail ? "<a href=\"mailto:".$oSubmitter->sEmail."\">":"";
+            echo $oSubmitter->sRealname;
+            echo $oSubmitter->sEmail ? "</a>":"";
+            echo '    </td>',"\n";
+            echo '    <td>'.date("M d Y", mysqldatetime_to_unixtimestamp($oTest->sSubmitTime)).'</td>',"\n";
+            echo '    <td>'.$oTest->sTestedRelease.'&nbsp</td>',"\n";
+            echo '    <td>'.$oTest->sInstalls.'&nbsp</td>',"\n";
+            echo '    <td>'.$oTest->sRuns.'&nbsp</td>',"\n";
+            echo '    <td>'.$oTest->sTestedRating.'&nbsp</td>',"\n";
+            echo '</tr>',"\n";
+        }
+        echo '</table>',"\n";
+    }
+
+
+    echo html_frame_end();
+    echo html_back_link(1);
+    apidb_footer();
+
+}
+
+?>
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ admin/adminTestResults.php 2005-10-15 22:49:39.000000000 -0600
@@ -0,0 +1,191 @@
+<?php
+/*************************************/
+/* code to View and resubmit Apps    */
+/*************************************/
+
+include("path.php");
+require(BASE."include/incl.php");
+require(BASE."include/tableve.php");
+require(BASE."include/application.php");
+require(BASE."include/mail.php");
+require_once(BASE."include/testResults.php");
+require_once(BASE."include/distributions.php");
+
+
+
+if ($_REQUEST['sub'])
+{
+    if (!($_SESSION['current']->hasPriv("admin")) &&
+        !($_SESSION['current']->hasAppVersionModifyPermission($_REQUEST['iVersionId'])))
+    {
+        errorpage("Insufficient privileges.");
+        exit;
+    }
+    // submit the testing results
+    if ($_REQUEST['sub'] == 'Submit')
+    {
+
+        if(is_numeric($_REQUEST['iTestingId']))
+        {
+            $oTest = new testData($_REQUEST['iTestingId']);
+            $oTest->GetOutputEditorValues();
+            $oTest->update(true);
+            $oTest->unQueue();
+            redirect($_SERVER['PHP_SELF']);
+        }
+    }
+    // submit the testing results
+    if ($_REQUEST['sub'] == 'Save')
+    {
+
+        if(is_numeric($_REQUEST['iTestingId']))
+        {
+            $oTest = new testData($_REQUEST['iTestingId']);
+            $oTest->GetOutputEditorValues();
+            $oTest->update();
+            redirect($_SERVER['PHP_SELF']);
+        }
+    }
+    if ($_REQUEST['sub'] == 'Reject')
+    {
+        if(is_numeric($_REQUEST['iTestingId']))
+        {
+
+            $oTest = new testData($_REQUEST['iTestingId']);
+            $oTest->GetOutputEditorValues();
+            $oTest->update(true);
+            $oTest->Reject();
+            redirect($_SERVER['PHP_SELF']);
+        }
+    }
+    // Delete testing results
+    if ($_REQUEST['sub'] == 'Delete')
+    {
+        if(is_numeric($_REQUEST['iTestingId']))
+        {
+            $oTest = new testData($_REQUEST['iTestingId']);
+            $oTest->delete();
+        }
+        
+        redirect($_SERVER['PHP_SELF']);
+    }
+
+    if(is_numeric($_REQUEST['iTestingId']))
+    {
+        $oTest = new testData($_REQUEST['iTestingId']);
+    }
+    if ($_REQUEST['sub'] == 'view')
+    {
+        switch($oTest->sQueued)
+        {
+        case "new":
+            apidb_header("Submit new testing results");
+            $_REQUEST['sTestedDate'] = date('Y-m-d H:i:s');
+            break;
+        case "true":
+        case "rejected":
+            apidb_header("Edit new testing results");
+            break;
+        case "False":
+            apidb_header("Edit testing results");
+            break;
+        }
+        echo '<form name="qform" action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">',"\n";
+        // View Testing Details
+        echo "<table width='100%' border=0 cellpadding=2 cellspacing=0>\n";
+/*
+            //help
+            echo "<div align=center><table width='90%' border=0 cellpadding=3 cellspacing=0><tr><td>\n\n";
+            echo "<p>This is the full view of the rejected application. \n";
+            echo "You need to pick a category before submitting \n";
+            echo "it into the database.\n";
+            echo "<p>Click delete to remove the selected item from the queue. An email will automatically be sent to the\n";
+            echo "submitter to let them know the item was deleted.</p>\n\n";        
+            echo "</td></tr></table></div>\n\n";    
+*/    
+        $oTest->OutputEditor();
+
+        echo '<a href="'.$_SERVER['PHP_SELF'].'">Back</a>';
+
+        echo '<tr valign=top><td class=color3 align=center colspan=2>' ,"\n";
+
+        // Submit Buttons
+        switch($oTest->sQueued)
+        {
+        case "false":
+            echo '<input name="sub" type="submit" value="Submit" class="button" >&nbsp',"\n";
+            echo '<input name="sub" type="submit" value="Delete" class="button" >',"\n";
+            break;
+        case "true":
+            echo '<input name="sub" type="submit" value="Submit" class="button" >&nbsp',"\n";
+            echo '<input name="sub" type="submit" value="Reject" class="button" >&nbsp',"\n";
+            echo '<input name="sub" type="submit" value="Delete" class="button" >',"\n";
+            break;
+        case "rejected":
+            echo '<input name="sub" type="submit" value="Submit" class="button" >&nbsp',"\n";
+            echo '<input name="sub" type="submit" value="Save" class="button" >&nbsp',"\n";
+            echo '<input name="sub" type="submit" value="Delete" class="button" >',"\n";
+            break;
+        }
+        echo '</td></tr>',"\n";
+        echo '</form>',"\n";
+
+        echo html_frame_end("&nbsp;");
+    }
+    else
+    {
+        // error no sub!
+        addmsg("Internal Routine Not Found!!", "red");
+        redirect($_SERVER['PHP_SELF']);
+    }
+}
+else // if ($_REQUEST['sub']) is not defined, display the Testing results queue page
+{
+    $oTest = new TestData();
+    apidb_header("Testing Results");
+
+    // Get queued testing results.
+
+    $hResult = $oTest->getTestingQueue("true");
+    if(!$hResult)
+    {
+         //no apps in queue
+        echo html_frame_start("Submitted Testing Results","90%");
+        echo '<p><b>The Submitted Testng Results Queue is empty.</b></p>',"\n";
+        echo html_frame_end("&nbsp;");        
+    }
+    else
+    {
+        //help
+        echo "<div align=center><table width='90%' border=0 cellpadding=3 cellspacing=0><tr><td>\n\n";
+        echo "<p>This is the list of test results waiting for submition, rejection or deletion.</p>\n";
+        echo "<p>To view a submission, click on its name. From that page you can Submit it into \n";
+        echo "the AppDB reject it or delete it.<br>\n";
+        echo "</td></tr></table></div>\n\n";
+
+        $oTest->ShowListofTests($hResult,"Submitted Testing Results");
+    }
+
+    // Get rejected testing results.
+    $hResult = $oTest->getTestingQueue("rejected");
+    if(!$hResult || !mysql_num_rows($hResult))
+    {
+        //no rejected test results in queue
+        echo html_frame_start("Rejected Testing Results","90%");
+        echo '<p><b>The Rejected Testng Results Queue is empty.</b></p>',"\n";
+        echo html_frame_end("&nbsp;");        
+    }
+    else
+    {
+        //help
+        echo "<div align=center><table width='90%' border=0 cellpadding=3 cellspacing=0><tr><td>\n\n";
+        echo "<p>This is the list of test results that have been rejected for some reason.</p>\n";
+        echo "<p>To view a submission, click on its name. From that page you can Submit it into \n";
+        echo "the AppDB, edit and save it or delete it.<br>\n";
+        echo "</td></tr></table></div>\n\n";
+
+        $oTest->ShowListofTests($hResult,"Rejected Testing Results");
+    }
+}
+apidb_footer();      
+?>
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ admin/adminDistributions.php 2005-10-15 08:58:42.000000000 -0600
@@ -0,0 +1,69 @@
+<?php
+/*******************************************************/
+/* code to view and maintain the list of Distributions */
+/*******************************************************/
+
+/*
+ * application environment
+ */
+include("path.php");
+require(BASE."include/incl.php");
+require_once(BASE."include/distributions.php");
+
+if(!$_SESSION['current']->hasPriv("admin"))
+{
+    errorpage("Insufficient privileges.");
+    exit;
+}
+if ($_REQUEST['sub'])
+{
+    if($_REQUEST['sub'] == 'delete')
+    {
+        $oDistribution = new distribution($_REQUEST['iDistributionId']);
+        $oDistribution->delete();
+        redirect(apidb_fullurl("admin/adminDistributions.php"));
+    }
+} else
+{
+    apidb_header("Admin Distributions");
+
+    //get available Distributions
+    $sQuery = "SELECT distributionId FROM distributions ORDER BY name, distributionId;";
+    $hResult = query_appdb($sQuery);
+
+    // show Distribution list
+    echo html_frame_start("","90%","",0);
+    echo "<table width='100%' border=0 cellpadding=3 cellspacing=0>\n\n";
+
+    echo "<tr class=color4>\n";
+    echo "    <td>Distribution name</td>\n";
+    echo "    <td>Distribution url</td>\n";
+    echo "    <td>Linked Tests</td>\n";
+    echo "    <td align=\"center\">Action</td>\n";
+    echo "</tr>\n\n";
+      
+    $c = 1;
+    while($ob = mysql_fetch_object($hResult))
+    {
+        if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; }
+        $oDistribution = new distribution($ob->distributionId);
+        echo "<tr class=\"$bgcolor\">\n";
+        echo "    <td><a href=\"".BASE."distributionView.php?iDistributionId=".$oDistribution->iDistributionId."\">","\n";
+        echo $oDistribution->sName."</a></td>\n";
+        echo "    <td><a href=\"".$oDistribution->sUrl."\">".$oDistribution->sUrl."</a></td>\n";
+        echo "    <td>".sizeof($oDistribution->aTestingIds)."</td>\n";
+        echo "    <td align=\"center\">";
+        echo "[<a href='editDistribution.php?iDistributionId=".$oDistribution->iDistributionId."'>edit</a>]";
+        if(!sizeof($oDistribution->aTestingIds))
+            echo " &nbsp; [<a href='adminDistributions.php?sub=delete&iDistributionId=".$oDistribution->iDistributionId."'>delete</a>]";
+        echo "        </td>\n";
+        echo "</tr>\n\n";
+        $c++;
+    }
+    echo "</table>\n\n";
+    echo html_frame_end("&nbsp;");
+
+}
+
+apidb_footer();
+?>
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ admin/editDistribution.php 2005-10-16 13:30:25.000000000 -0600
@@ -0,0 +1,51 @@
+<?php
+include("path.php");
+require(BASE."include/incl.php");
+require(BASE."include/distributions.php");
+
+if(!$_SESSION['current']->hasPriv("admin"))
+{
+    errorpage();
+    exit;
+}
+
+
+$oDistribution = new distribution($_REQUEST['iDistributionId']);
+if($_REQUEST['Submit'])
+{
+        addmsg('i am here');
+
+    $oDistribution->GetOutputEditorValues();
+        addmsg('i am here as well');
+
+    if($oDistribution->iDistributionId)
+        $oDistribution->update();
+    else
+    {
+       $oDistribution->create();
+    }
+        addmsg('i am here too');
+  
+    redirect(apidb_fullurl("admin/adminDistributions.php"));
+    exit;
+}
+else
+{
+    if ($oDistribution->iDistributionId)
+        apidb_header("Edit Distribution");
+    else
+        apidb_header("Add Distribution");
+
+    echo '<form name="qform" action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">',"\n";
+
+    $oDistribution->OutputEditor();
+
+    echo '<tr valign=top><td class=color3 align=center colspan=2>',"\n";
+    echo '<input name="Submit" type="submit" value="Submit" class="button" >&nbsp',"\n";
+    echo '</td></tr>',"\n";
+
+    echo "</form>";
+    echo html_frame_end("&nbsp;");
+    apidb_footer();
+}
+?>
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ admin/adminDistributions.php 2005-10-15 08:58:42.000000000 -0600
@@ -0,0 +1,69 @@
+<?php
+/*******************************************************/
+/* code to view and maintain the list of Distributions */
+/*******************************************************/
+
+/*
+ * application environment
+ */
+include("path.php");
+require(BASE."include/incl.php");
+require_once(BASE."include/distributions.php");
+
+if(!$_SESSION['current']->hasPriv("admin"))
+{
+    errorpage("Insufficient privileges.");
+    exit;
+}
+if ($_REQUEST['sub'])
+{
+    if($_REQUEST['sub'] == 'delete')
+    {
+        $oDistribution = new distribution($_REQUEST['iDistributionId']);
+        $oDistribution->delete();
+        redirect(apidb_fullurl("admin/adminDistributions.php"));
+    }
+} else
+{
+    apidb_header("Admin Distributions");
+
+    //get available Distributions
+    $sQuery = "SELECT distributionId FROM distributions ORDER BY name, distributionId;";
+    $hResult = query_appdb($sQuery);
+
+    // show Distribution list
+    echo html_frame_start("","90%","",0);
+    echo "<table width='100%' border=0 cellpadding=3 cellspacing=0>\n\n";
+
+    echo "<tr class=color4>\n";
+    echo "    <td>Distribution name</td>\n";
+    echo "    <td>Distribution url</td>\n";
+    echo "    <td>Linked Tests</td>\n";
+    echo "    <td align=\"center\">Action</td>\n";
+    echo "</tr>\n\n";
+      
+    $c = 1;
+    while($ob = mysql_fetch_object($hResult))
+    {
+        if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; }
+        $oDistribution = new distribution($ob->distributionId);
+        echo "<tr class=\"$bgcolor\">\n";
+        echo "    <td><a href=\"".BASE."distributionView.php?iDistributionId=".$oDistribution->iDistributionId."\">","\n";
+        echo $oDistribution->sName."</a></td>\n";
+        echo "    <td><a href=\"".$oDistribution->sUrl."\">".$oDistribution->sUrl."</a></td>\n";
+        echo "    <td>".sizeof($oDistribution->aTestingIds)."</td>\n";
+        echo "    <td align=\"center\">";
+        echo "[<a href='editDistribution.php?iDistributionId=".$oDistribution->iDistributionId."'>edit</a>]";
+        if(!sizeof($oDistribution->aTestingIds))
+            echo " &nbsp; [<a href='adminDistributions.php?sub=delete&iDistributionId=".$oDistribution->iDistributionId."'>delete</a>]";
+        echo "        </td>\n";
+        echo "</tr>\n\n";
+        $c++;
+    }
+    echo "</table>\n\n";
+    echo html_frame_end("&nbsp;");
+
+}
+
+apidb_footer();
+?>
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ include/distributions.php 2005-10-16 14:27:16.000000000 -0600
@@ -0,0 +1,396 @@
+<?php
+/***************************************/
+/* this class represents Distributions */
+/***************************************/
+require_once(BASE."include/mail.php");
+
+// Testing class for handling Distributions.
+
+class distribution{
+    var $iDistributionId;
+    var $sName;
+    var $sDescription;
+    var $sUrl;
+    var $sSubmitTime;
+    var $iSubmitterId;
+    var $sQueued;
+    var $aTestingIds;
+
+     // constructor, fetches the data.
+    function distribution($iDistributionId = null)
+    {
+        // we are working on an existing distribution.
+        if(is_numeric($iDistributionId))
+        {
+            // We fetch the data related to this distribution.
+            if(!$this->$iDistributionId)
+            {
+                $sQuery = "SELECT *
+                           FROM distributions
+                           WHERE distributionId = ".$iDistributionId;
+                if($hResult = query_appdb($sQuery))
+                {
+                    $oRow = mysql_fetch_object($hResult);
+                    $this->iDistributionId = $iDistributionId;
+                    $this->sName = $oRow->name;
+                    $this->sDescription = $oRow->description;
+                    $this->sUrl = $oRow->url;
+                    $this->sSubmitTime = $oRow->submitTime;
+                    $this->iSubmitterId = $oRow->submitterId;
+                    $this->sQueued = $oRow->queued;
+                }
+            }
+
+            /*
+             * We fetch Test Result Ids.
+             */
+            $sQuery = "SELECT testingId
+                       FROM testResults
+                       WHERE distributionId = ".$iDistributionId;
+            if($hResult = query_appdb($sQuery))
+            {
+                while($oRow = mysql_fetch_object($hResult))
+                {
+                    $this->aTestingIds[] = $oRow->testingId;
+                }
+            }
+        }
+    }
+
+    // Creates a new distribution.
+    function create()
+    {
+        //Let's not create a duplicate
+        $sQuery = "SELECT *
+                   FROM distributions
+                   WHERE name LIKE '".$this->sName."'";
+        $hDuplicate = query_appdb($sQuery, "checking distributions");
+        if(!mysql_num_rows($hDuplicate) == 0)
+        {
+            addmsg("There was an existing Distribution called ".$this->sName.".", "red");
+            $oRow = mysql_fetch_object($hDuplicate);
+            $this->iDistributionId = $oRow->distributionId;
+            return false;
+        }
+
+        // Security, if we are not an administrator the Distributions must be queued.
+        if(!$_SESSION['current']->hasPriv("admin"))
+            $this->sQueued = 'true';
+        else
+            $this->sQueued = 'false';
+
+        $aInsert = compile_insert_string(array( 'name'              => $this->sName,
+                                                'url'               => $this->sUrl,
+                                                'submitterId'       => $_SESSION['current']->iUserId,
+                                                'queued'            => $this->sQueued ));
+        $sFields = "({$aInsert['FIELDS']})";
+        $sValues = "({$aInsert['VALUES']})";
+
+        if(query_appdb("INSERT INTO distributions $sFields VALUES $sValues", "Error while creating Distribution."))
+        {
+            $this->iDistributionId = mysql_insert_id();
+            $this->distribution($this->iDistributionId);
+            $this->SendNotificationMail();
+            return true;
+        }
+        else
+            return false;
+    }
+
+    // Update Distribution.
+    function update()
+    {
+        // is the current user allowed to update this Distribution?
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !($_SESSION['current']->iUserId == $this->iSubmitterId))
+        {
+            return;
+        }
+        $sUpdate = compile_update_string(array( 'name'              => $this->sName,
+                                                'url'               => $this->sUrl ));
+        if(query_appdb("UPDATE distributions SET ".$sUpdate." WHERE distributionId = ".$this->iDistributionId, "Error while updating Distribution."))
+        {
+            $this->SendNotificationMail("edit");
+            return true;
+        }
+        else
+            return false;
+    }
+    
+    // Delete Distributution.
+    function delete($bSilent=false)
+    {
+        // is the current user allowed to delete this Distribution?
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !($_SESSION['current']->iUserId == $this->iSubmitterId))
+        {
+            return;
+        }
+        // now delete the Distribution
+        $sQuery = "DELETE FROM distributions
+                   WHERE distributionId = ".$this->iDistributionId."
+                   LIMIT 1";
+        if(!($hResult = query_appdb($sQuery)))
+        {
+            addmsg("Error removing the Distribution!", "red");
+        }
+
+        if(!$bSilent)
+            $this->SendNotificationMail("delete");
+
+        $this->mailSubmitter("delete");
+    }
+
+
+    // Move Distribution out of the queue.
+    function unQueue()
+    {
+        // is the current user allowed to move this Distribution?
+        if(!$_SESSION['current']->hasPriv("admin"))
+        {
+            return;
+        }
+
+        // If we are not in the queue, we can't move the Distribution out of the queue.
+        if(!$this->sQueued == 'true')
+            return false;
+
+        $sUpdate = compile_update_string(array('queued'    => "false"));
+        if(query_appdb("UPDATE distribution SET ".$sUpdate." WHERE distributionId = ".$this->iDistributionId, "Error while unqueuing Distribution."))
+        {
+            $this->sQueued = 'false';
+            // we send an e-mail to intersted people
+            $this->mailSubmitter("unQueue");
+            $this->SendNotificationMail();
+        }
+    }
+
+    function Reject($bSilent=false)
+    {
+        // is the current user allowed to reject this Distribution?
+        if(!$_SESSION['current']->hasPriv("admin"))
+        {
+            return;
+        }
+
+        // If we are not in the queue, we can't move the Distribution out of the queue.
+        if(!$this->sQueued == 'true')
+            return false;
+
+        $sUpdate = compile_update_string(array('queued'    => "rejected"));
+        if(query_appdb("UPDATE distribution SET ".$sUpdate." WHERE distributionId = ".$this->iDistributionId, "Error while rejecting Distribution."))
+        {
+            $this->sQueued = 'rejected';
+            // we send an e-mail to intersted people
+            if(!$bSilent)
+            {
+                $this->mailSubmitter("reject");
+                $this->SendNotificationMail("reject");
+            }
+            // the Distribution data has been rejected
+        }
+    }
+
+    function ReQueue()
+    {
+        // is the current user allowed to requeue this data
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !($_SESSION['current']->iUserId == $this->iSubmitterId))
+        {
+            return;
+        }
+
+        $sUpdate = compile_update_string(array('queued'    => "true"));
+        if(query_appdb("UPDATE testResults SET ".$sUpdate." WHERE testingId = ".$this->iTestingId))
+        if(query_appdb("UPDATE distribution SET ".$sUpdate." WHERE distributionId = ".$this->iDistributionId, "Error while requeueing Distribution."))
+        {
+            $this->sQueued = 'true';
+            // we send an e-mail to intersted people
+            $this->SendNotificationMail();
+
+            // the testing data has been resubmitted
+            addmsg("The Distribution has been resubmitted", "green");
+        }
+    }
+
+    function mailSubmitter($sAction="add")
+    {
+        if($this->iSubmitterId)
+        {
+            $oSubmitter = new User($this->iSubmitterId);
+            switch($sAction)
+            {
+            case "add":
+               {
+                   $sSubject =  "Submitted Distribution accepted";
+                   $sMsg  = "The Distribution you submitted (".$this->sName.") has been accepted.";
+               }
+            break;
+            case "reject":
+                {
+                    $sSubject =  "Distribution rejected";
+                    $sMsg  = "The Distribution you submitted (".$this->sName.") has been rejected.";
+                    $sMsg .= APPDB_ROOT."testingData.php?sub=view&versionId=".$this->iVersionId."\n";
+                    $sMsg .= "Reason given:\n";
+                    $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                }
+
+            break;
+            case "delete":
+                {
+                    $sSubject =  "Submitted Distribution deleted";
+                    $sMsg  = "The Distribution you submitted (".$this->sName.") has been deleted.";
+                    $sMsg .= "Reason given:\n";
+                    $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                }
+            break;
+            }
+            $sMsg .= "We appreciate your help in making the Application Database better for all users.";
+        
+            mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg);
+        }
+    }
+
+
+    function SendNotificationMail($sAction="add",$sMsg=null)
+    {
+        switch($sAction)
+        {
+            case "add":
+                if($this->sQueued == "false")
+                {
+                    $sSubject = "Distribution ".$this->sName." added by ".$_SESSION['current']->sRealname;
+                    $sMsg  = APPDB_ROOT."distributionView.php?iDistributionId=".$this->iDistributionId."\n";
+                    if($this->iSubmitterId)
+                    {
+                        $oSubmitter = new User($this->iSubmitterId);
+                        $sMsg .= "This Distribution has been submitted by ".$oSubmitter->sRealname.".";
+                        $sMsg .= "\n";
+                        $sMsg .= "Appdb admin reply text:\n";
+                        $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                    }
+                    addmsg("The Distribution was successfully added into the database.", "green");
+                } else // testing data queued.
+                {
+                    $sSubject = "Distribution ".$this->sName." submitted by ".$_SESSION['current']->sRealname;
+                    $sMsg .= "This testing data has been queued.";
+                    $sMsg .= "\n";
+                    addmsg("The Distribution you submitted will be added to the database after being reviewed.", "green");
+                }
+            break;
+            case "edit":
+                $sSubject =  "Distribution ".$this->sName." has been modified by ".$_SESSION['current']->sRealname;
+                $sMsg  = APPDB_ROOT."distributionView.php?iDistributionId=".$this->iDistributionId."\n";
+                addmsg("Distribution modified.", "green");
+            break;
+            case "delete":
+                $sSubject = "Distribution ".$this->sName." has been deleted by ".$_SESSION['current']->sRealname;
+
+                // if replyText is set we should report the reason the data was deleted
+                if($_REQUEST['replyText'])
+                {
+                    $sMsg .= "Reason given:\n";
+                    $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                }
+
+                addmsg("Distribution deleted.", "green");
+            break;
+            case "reject":
+                $sSubject = "Distribution '".$this->sName." has been rejected by ".$_SESSION['current']->sRealname;
+                $sMsg  = APPDB_ROOT."distributionView.php?iDistributionId=".$this->iDistributionId."\n";
+
+                 // if replyText is set we should report the reason the data was rejected
+                if($_REQUEST['replyText'])
+                {
+                    $sMsg .= "Reason given:\n";
+                    $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                }
+
+                addmsg("Distribution rejected.", "green");
+            break;
+        }
+        $sEmail = get_notify_email_address_list(null, null);
+        if($sEmail)
+            mail_appdb($sEmail, $sSubject ,$sMsg);
+    }
+
+    function OutputEditor()
+    {
+        echo html_frame_start("Distribution Form", "90%", "", 0);
+        echo "<table width='100%' border=0 cellpadding=2 cellspacing=0>\n";
+
+        // Name
+        echo '<tr valign=top><td class="color1" width="20%"><b>Distribution Name</b></td>',"\n";
+        echo '<td class="color0"><input type=text name="sName" value="'.$this->sName.'" size="50"></td></tr>',"\n";
+        // Url
+        echo '<tr valign=top><td class="color1"><b>Distribution Url</b></td>',"\n";
+        echo '<td class="color0"><input type=text name="sUrl" value="'.$this->sUrl.'" size="50"></td></tr>',"\n";
+
+        echo  '<input type="hidden" name="iDistributionId" value="'.$this->iDistributionId.'">',"\n";
+
+        echo "</table>\n";
+        echo html_frame_end();
+    }
+
+    /* retrieves values from $_REQUEST that were output by OutputEditor() */
+    function GetOutputEditorValues()
+    {
+        if(get_magic_quotes_gpc())
+        {
+            $this->iDistributionId = stripslashes($_REQUEST['iDistributionId']);
+            $this->sName = stripslashes($_REQUEST['sName']);
+            $this->sUrl = stripslashes($_REQUEST['sUrl']);
+        } else
+        {
+            $this->iDistributionId = $_REQUEST['iDistributionId'];
+            $this->sName = $_REQUEST['sName'];
+            $this->sUrl = $_REQUEST['sUrl'];
+        }
+    }
+
+}
+
+/* Make a dropdown list of distributions */
+function make_distribution_list($varname, $cvalue)
+{
+    $query = "SELECT name, distributionId FROM distributions ORDER BY name";
+
+    $result = query_appdb($query);
+    if(!$result) return;
+
+    echo "<select name='$varname'>\n";
+    echo "<option value=\"\">Choose ...</option>\n";
+    while(list($name, $value) = mysql_fetch_row($result))
+    {
+        if($value == $cvalue)
+            echo "<option value=$value selected>$name\n";
+        else
+            echo "<option value=$value>$name\n";
+    }
+    echo "</select>\n";
+}
+/* Get the total number of Distributions in the database */
+function getNumberOfDistributions()
+{
+    $hResult = query_appdb("SELECT count(*) as num_dists FROM distributions");
+    if($hResult)
+    {
+      $row = mysql_fetch_object($hResult);
+      return $row->num_dists;
+    }
+    return 0;
+}
+
+/* Get the number of Queued Distributions in the database */
+function getNumberOfQueuedDistributions()
+{
+    $hResult = query_appdb("SELECT count(*) as num_dists FROM distributions WHERE queued='true';");
+    if($hResult)
+    {
+      $row = mysql_fetch_object($hResult);
+      return $row->num_dists;
+    }
+    return 0;
+}
+
+?>
--- /dev/null 2005-10-07 12:32:22.621430296 -0600
+++ include/testResults.php 2005-10-16 08:55:52.000000000 -0600
@@ -0,0 +1,643 @@
+<?php
+/*****************************************/
+/* this class represents Testing results */
+/*****************************************/
+require_once(BASE."include/distributions.php");
+
+// Testing class for handling Testing History.
+
+class testData{
+    var $iTestingId;
+    var $iVersionId;
+    var $sWhatWorks;
+    var $sWhatDoesnt;
+    var $sWhatNotTested;
+    var $sTestedRelease;
+    var $iDistributionId;
+    var $sTestedDate;
+    var $sTestedRelease;
+    var $sInstalls;
+    var $sRuns;
+    var $sTestedRating;
+    var $sComments;
+    var $sSubmitTime;
+    var $iSubmitterId;
+    var $sQueued;
+
+     // constructor, fetches the data.
+    function testData($iTestingId = null)
+    {
+        // we are working on an existing test
+        if(is_numeric($iTestingId))
+        {
+            // We fetch the data related to this test.
+            if(!$this->iTestingId)
+            {
+                $sQuery = "SELECT *
+                           FROM testResults
+                           WHERE testingId = ".$iTestingId;
+                if($hResult = query_appdb($sQuery))
+                {
+                    $oRow = mysql_fetch_object($hResult);
+                    $this->iTestingId = $iTestingId;
+                    $this->iVersionId = $oRow->versionId;
+                    $this->sWhatWorks = $oRow->whatWorks;
+                    $this->sWhatDoesnt = $oRow->whatDoesnt;
+                    $this->sWhatNotTested = $oRow->whatNotTested;
+                    $this->sTestedDate = $oRow->testedDate;
+                    $this->iDistributionId = $oRow->distributionId;
+                    $this->sTestedRelease = $oRow->testedRelease;
+                    $this->sInstalls = $oRow->installs;
+                    $this->sRuns = $oRow->runs;
+                    $this->sTestedRating = $oRow->testedRating;
+                    $this->sComments = $oRow->comments;
+                    $this->sSubmitTime = $oRow->submitTime;
+                    $this->iSubmitterId = $oRow->submitterId;
+                    $this->sQueued = $oRow->queued;
+                }
+            }
+        }
+    }
+
+    // Creates a new Test Results.
+    function create()
+    {
+        // Security, if we are not an administrator or an maintainer the test result must be queued.
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !$_SESSION['current']->hasAppVersionModifyPermission($oTest->iVersionId))
+            $this->sQueued = 'true';
+        else
+            $this->sQueued = 'false';
+
+        $aInsert = compile_insert_string(array( 'versionId'         => $this->iVersionId,
+                                                'whatWorks'         => $this->sWhatWorks,
+                                                'whatDoesnt'        => $this->sWhatDoesnt,
+                                                'whatNotTested'     => $this->sWhatNotTested,
+                                                'testedDate'        => $this->sTestedDate,
+                                                'distributionId'    => $this->iDistributionId,
+                                                'testedRelease'     => $this->sTestedRelease,
+                                                'installs'          => $this->sInstalls,
+                                                'runs'              => $this->sRuns,
+                                                'testedRating'      => $this->sTestedRating,
+                                                'comments'          => $this->sComments,
+                                                'submitterId'       => $_SESSION['current']->iUserId,
+                                                'queued'            => $this->sQueued ));
+        $sFields = "({$aInsert['FIELDS']})";
+        $sValues = "({$aInsert['VALUES']})";
+
+        if(query_appdb("INSERT INTO testResults $sFields VALUES $sValues", "Error while creating test results."))
+        {
+            $this->iTestingId = mysql_insert_id();
+            $this->testData($this->iTestingId);
+            $this->SendNotificationMail();
+            return true;
+        }
+        else
+            return false;
+    }
+
+    // Update Test Results.
+    function update($bSilent=false)
+    {
+        // is the current user allowed to update this testing result?
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !$_SESSION['current']->hasAppVersionModifyPermission($this->iVersionId) &&
+           !(($_SESSION['current']->iUserId == $this->iSubmitterId) && !($this->sQueued == 'false')))
+        {
+            return;
+        }
+
+        $sUpdate = compile_update_string(array( 'versionId'         => $this->iVersionId,
+                                                'whatWorks'         => $this->sWhatWorks,
+                                                'whatDoesnt'        => $this->sWhatDoesnt,
+                                                'whatNotTested'     => $this->sWhatNotTested,
+                                                'testedDate'        => $this->sTestedDate,
+                                                'distributionId'    => $this->iDistributionId,
+                                                'testedRelease'     => $this->sTestedRelease,
+                                                'installs'          => $this->sInstalls,
+                                                'runs'              => $this->sRuns,
+                                                'testedRating'      => $this->sTestedRating,
+                                                'comments'          => $this->sComments));
+
+        if(query_appdb("UPDATE testResults SET ".$sUpdate." WHERE testingId = ".$this->iTestingId, "Error while updating test results."))
+        {
+            if(!$bSilent)
+                $this->SendNotificationMail();
+            return true;
+        }
+        else
+            return false;
+    }
+    
+    // Delete testing results.
+    function delete($bSilent=false)
+    {
+        // is the current user allowed to delete this testing result?
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !$_SESSION['current']->hasAppVersionModifyPermission($this->iVersionId) &&
+           !(($_SESSION['current']->iUserId == $this->iSubmitterId) && !($this->sQueued == 'false')))
+        {
+            return;
+        }
+        // now delete the testing data
+        $sQuery = "DELETE FROM testResults
+                   WHERE testingId = ".$this->iTestingId."
+                   LIMIT 1";
+        if(!($hResult = query_appdb($sQuery)))
+        {
+            addmsg("Error removing the deleted testing data!", "red");
+        }
+
+        if(!$bSilent)
+            $this->SendNotificationMail("delete");
+
+        $this->mailSubmitter("delete");
+    }
+
+
+    // Move Testing Data out of the queue.
+    function unQueue()
+    {
+        // is the current user allowed to delete this testing data?
+        if(!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->hasAppVersionModifyPermission($this->iVersionId))
+        {
+            return;
+        }
+
+        // If we are not in the queue, we can't move the testing data out of the queue.
+        if(!$this->sQueued == 'true')
+            return false;
+
+        $sUpdate = compile_update_string(array('queued'    => "false"));
+        if(query_appdb("UPDATE testResults SET ".$sUpdate." WHERE testingId = ".$this->iTestingId))
+        {
+            $this->sQueued = 'false';
+            // we send an e-mail to intersted people
+            $this->mailSubmitter("unQueue");
+            $this->SendNotificationMail();
+        }
+    }
+
+    function Reject()
+    {
+        // is the current user allowed to delete this testing data?
+        if(!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->hasAppVersionModifyPermission($this->iVersionId))
+        {
+            return;
+        }
+
+        // If we are not in the queue, we can't move the version out of the queue.
+        if(!$this->sQueued == 'true')
+            return false;
+
+        $sUpdate = compile_update_string(array('queued'    => "rejected"));
+        if(query_appdb("UPDATE testResults SET ".$sUpdate." WHERE testingId = ".$this->iTestingId))
+        {
+            $this->sQueued = 'rejected';
+            // we send an e-mail to intersted people
+            $this->mailSubmitter("reject");
+            $this->SendNotificationMail("reject");
+        }
+    }
+
+    function ReQueue()
+    {
+        // is the current user allowed to requeue this data
+        if(!$_SESSION['current']->hasPriv("admin") &&
+           !$_SESSION['current']->hasAppVersionModifyPermission($this->iVersionId) &&
+           !$_SESSION['current']->iUserId == $this->iSubmitterId)
+        {
+            return;
+        }
+
+        $sUpdate = compile_update_string(array('queued'    => "true"));
+        if(query_appdb("UPDATE testResults SET ".$sUpdate." WHERE testingId = ".$this->iTestingId))
+        {
+            $this->sQueued = 'true';
+            // we send an e-mail to intersted people
+            $this->SendNotificationMail();
+        }
+    }
+
+    function mailSubmitter($sAction="add")
+    {
+        if($this->iSubmitterId)
+        {
+            $oSubmitter = new User($this->iSubmitterId);
+            switch($sAction)
+            {
+            case "add":
+                $sSubject =  "Submitted testing data accepted";
+                $sMsg  = "The testing data you submitted (".$oApp->sName." ".$this->sName.") has been accepted.";
+                $sMsg .= APPDB_ROOT."appview.php?versionId=".$this->iVersionId."&iTestingId=".$this->iTestingId."\n";
+                break;
+            case "reject":
+                $sSubject =  "Submitted testing data rejected";
+                $sMsg  = "The testing data you submitted (".$oApp->sName." ".$this->sName.") has been rejected.";
+                $sMsg .= APPDB_ROOT."testResults.php?sub=view&iTestingId=".$this->iTestingId."\n";
+                $sMsg .= "Reason given:\n";
+                $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                break;
+            case "delete":
+                $sSubject =  "Submitted testing data deleted";
+                $sMsg  = "The testing data you submitted (".$oApp->sName." ".$this->sName.") has been deleted.";
+                $sMsg .= "Reason given:\n";
+                $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+            break;
+            }
+            $sMsg .= $_REQUEST['replyText']."\n";
+            $sMsg .= "We appreciate your help in making the Application Database better for all users.";
+        
+            mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg);
+        }
+    }
+
+
+    function SendNotificationMail($sAction="add",$sMsg=null)
+    {
+        $oVersion = new Version($this->iVersionId);
+        $oApp = new Application($oVersion->iAppId);
+        switch($sAction)
+        {
+            case "add":
+                if($this->sQueued == "false")
+                {
+                    $sSubject = "Test Results added to version ".$oVersion->sName." of ".$oApp->sName." submitted by ".$_SESSION['current']->sRealname;
+                    $sMsg  = $sMsg .= APPDB_ROOT."appview.php?versionId=".$this->iVersionId."&iTestingId=".$this->iTestingId."\n";
+                    if($this->iSubmitterId)
+                    {
+                        $oSubmitter = new User($this->iSubmitterId);
+                        $sMsg .= "This Testing data has been submitted by ".$oSubmitter->sRealname.".";
+                        $sMsg .= "\n";
+                        $sMsg .= "Appdb admin reply text:\n";
+                        $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                    }
+                    addmsg("The testing data was successfully added into the database.", "green");
+                } else // testing data queued.
+                {
+                    $sSubject = "Test Results submitted for version ".$oVersion->sName." of ".$oApp->sName." submitted by ".$_SESSION['current']->sRealname;
+                    $sMsg .= APPDB_ROOT."admin/adminTestResults.php?sub=view&iTestingId=".$this->iTestingId."\n";
+                    $sMsg .= "This testing data has been queued.";
+                    $sMsg .= "\n";
+                    addmsg("The testing data you submitted will be added to the database after being reviewed.", "green");
+                }
+            break;
+            case "edit":
+                $sSubject = "Test Results modified for version ".$oVersion->sName." of ".$oApp->sName." submitted by ".$_SESSION['current']->sRealname;
+                $sMsg .= APPDB_ROOT."admin/adminTestResults.php?sub=view&iTestingId=".$this->iTestingId."\n";
+                addmsg("testing data modified.", "green");
+            break;
+            case "delete":
+                $sSubject = "Test Results deleted for version ".$oVersion->sName." of ".$oApp->sName." submitted by ".$_SESSION['current']->sRealname;
+                // if replyText is set we should report the reason the data was deleted
+                if($_REQUEST['replyText'])
+                {
+                    $sMsg .= "Reason given:\n";
+                    $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                }
+
+                addmsg("testing data deleted.", "green");
+            break;
+            case "reject":
+                $sSubject = "Test Results rejected for version ".$oVersion->sName." of ".$oApp->sName." submitted by ".$_SESSION['current']->sRealname;
+                $sMsg .= APPDB_ROOT."admin/adminTestResults.php?sub=view&iTestingId=".$this->iTestingId."\n";
+                 // if replyText is set we should report the reason the data was rejected
+                if($_REQUEST['replyText'])
+                {
+                    $sMsg .= "Reason given:\n";
+                    $sMsg .= $_REQUEST['replyText']."\n"; // append the reply text, if there is any
+                }
+                addmsg("testing data rejected.", "green");
+            break;
+        }
+        $sEmail = get_notify_email_address_list(null, $this->iVersionId);
+        if($sEmail)
+            mail_appdb($sEmail, $sSubject ,$sMsg);
+    }
+
+    function ShowTestResult($iCurrentTest,$iVersionId)
+    {
+        $hResult = query_appdb("SELECT *
+                                F