iDistributionId = $iDistributionId; $this->sName = $oRow->name; $this->sUrl = $oRow->url; $this->sSubmitTime = $oRow->submitTime; $this->iSubmitterId = $oRow->submitterId; $this->sQueued = $oRow->queued; } /* * We fetch Test Result Ids. */ if($_SESSION['current']->hasPriv("admin")) { $sQuery = "SELECT testingId FROM testResults WHERE distributionId = '?' ORDER BY testedRating;" ; } else /* only let users view test results that aren't queued and for apps that */ /* aren't queued or versions that aren't queued */ { $sQuery = "SELECT testingId FROM testResults, appFamily, appVersion WHERE testResults.queued = 'false' AND testResults.versionId = appVersion.versionId AND appFamily.appId = appVersion.appId AND appFamily.queued = 'false' AND appVersion.queued = 'false' AND distributionId = '?' ORDER BY testedRating;"; } if($hResult = query_parameters($sQuery, $iDistributionId)) { 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 '?'"; $hDuplicate = query_parameters($sQuery, $this->sName); 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; } $hResult = query_parameters("INSERT INTO distributions (name, url, submitterId, queued) ". "VALUES ('?', '?', '?', '?')", $this->sName, $this->sUrl, $_SESSION['current']->iUserId, $this->mustBeQueued() ? "true" : "false"); if($hResult) { $this->iDistributionId = mysql_insert_id(); $this->distribution($this->iDistributionId); $this->SendNotificationMail(); return true; } else { addmsg("Error while creating Distribution.", "red"); 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; } if(query_parameters("UPDATE distributions SET name = '?', url = '?' WHERE distributionId = '?'", $this->sName, $this->sUrl, $this->iDistributionId)) { $this->SendNotificationMail("edit"); return true; } else { addmsg("Error while updating Distribution", "red"); return false; } } // Delete Distributution. function delete($bSilent=false) { /* Is the current user allowed to delete this distribution? We allow everyone to delete a queued, empty distribution, because it should be deleted along with the last testData associated with it */ if(!($this->canEdit() || (!sizeof($this->aTestingIds) && $this->sQueued != "false"))) return; /* Check for associated test results */ if(sizeof($this->aTestingIds)) { addmsg("This distribution still has associated test results", "red"); return FALSE; } // now delete the Distribution $sQuery = "DELETE FROM distributions WHERE distributionId = '?' LIMIT 1"; if(!($hResult = query_parameters($sQuery, $this->iDistributionId))) { addmsg("Error removing the Distribution!", "red"); } if(!$bSilent) $this->SendNotificationMail("delete"); $this->mailSubmitter("delete"); return true; } // Move Distribution out of the queue. function unQueue() { /* Check permissions */ if($this->mustBeQueued()) return FALSE; // If we are not in the queue, we can't move the Distribution out of the queue. if(!$this->sQueued == 'true') return false; if(query_parameters("UPDATE distributions SET queued = '?' WHERE distributionId = '?'", "false", $this->iDistributionId)) { $this->sQueued = 'false'; // we send an e-mail to interested people $this->mailSubmitter("unQueue"); $this->SendNotificationMail(); return true; } else { addmsg("Error while unqueueing Distribution", "red"); return false; } } function Reject($bSilent=false) { // is the current user allowed to reject this Distribution? if(!$_SESSION['current']->hasPriv("admin")) { return false; } // If we are not in the queue, we can't move the Distribution out of the queue. if(!$this->sQueued == 'true') return false; return $this->delete(); } function ReQueue() { // is the current user allowed to requeue this data if(!$_SESSION['current']->hasPriv("admin") && !($_SESSION['current']->iUserId == $this->iSubmitterId)) { return false; } if(query_parameters("UPDATE testResults SET queued = '?' WHERE testingId = '?'", "true", $this->iTestingId)) { if(query_parameters("UPDATE distribution SET queued = '?' WHERE distributionId = '?'", "true", $this->iDistributionId)) { $this->sQueued = 'true'; // we send an e-mail to interested people $this->SendNotificationMail(); // the test data has been resubmitted addmsg("The Distribution has been resubmitted", "green"); return true; } } /* something has failed if we fell through to this point without */ /* returning */ addmsg("Error requeueing Distribution", "red"); return false; } function mailSubmitter($sAction="add") { global $aClean; 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 "delete": { $sSubject = "Submitted Distribution deleted"; $sMsg = "The Distribution you submitted (".$this->sName.") has been deleted."; $sMsg .= "Reason given:\n"; $sMsg .= $aClean['sReplyText']."\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) { global $aClean; switch($sAction) { case "add": if($this->sQueued == "false") { $sSubject = "Distribution ".$this->sName." added by ". $_SESSION['current']->sRealname; $sMsg = $this->objectMakeUrl()."\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 .= $aClean['sReplyText']."\n"; // append the reply text, if there is any } addmsg("The Distribution was successfully added into the database.", "green"); } else // test data queued. { $sSubject = "Distribution ".$this->sName." submitted by ".$_SESSION['current']->sRealname; $sMsg .= "This test 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 = $this->objectMakeUrl()."\n"; addmsg("Distribution modified.", "green"); break; case "delete": $sSubject = "Distribution ".$this->sName." has been deleted by ".$_SESSION['current']->sRealname; // if sReplyText is set we should report the reason the data was deleted if($aClean['sReplyText']) { $sMsg .= "Reason given:\n"; $sMsg .= $aClean['sReplyText']."\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 = $this->objectMakeUrl()."\n"; // if sReplyText is set we should report the reason the data was rejected if($aClean['sReplyText']) { $sMsg .= "Reason given:\n"; $sMsg .= $aClean['sReplyText']."\n"; // append the reply text, if there is any } addmsg("Distribution rejected.", "green"); break; } $sEmail = User::get_notify_email_address_list(null, null); if($sEmail) mail_appdb($sEmail, $sSubject ,$sMsg); } function outputEditor() { echo "\n"; $this->sName = str_replace('"', '"', $this->sName); // Name echo html_tr(array( array("Distribution Name", 'class="color1"'), array('', 'class="color0"') )); // URL echo html_tr(array( array("Distribution URL", 'class="color1"'), array('', 'class="color0"') )); echo "
\n"; if($this->iDistributionId) { echo '',"\n"; } } /* retrieves values from $_REQUEST that were output by outputEditor() */ /* $aValues can be $_REQUEST or any array with the values from outputEditor() */ function GetOutputEditorValues($aValues) { $this->iDistributionId = $aValues['iDistributionId']; $this->sName = $aValues['sDistribution']; $this->sUrl = $aValues['sUrl']; } /* Get the total number of Distributions in the database */ function objectGetEntriesCount($bQueued, $bRejected) { /* Not implemented */ if($bRejected) return FALSE; $hResult = query_parameters("SELECT count(distributionId) as num_dists FROM distributions WHERE queued='?'", $bQueued ? "true" : "false"); if($hResult) { $oRow = mysql_fetch_object($hResult); return $oRow->num_dists; } return 0; } /* Make a dropdown list of distributions */ function make_distribution_list($varname, $cvalue) { $sQuery = "SELECT name, distributionId FROM distributions WHERE queued = 'false' ORDER BY name"; $hResult = query_parameters($sQuery); if(!$hResult) return; echo "\n"; } function objectGetHeader() { $aCells = array( "Distribution name", "Distribution url", array("Linked Tests", "align=\"right\"")); return $aCells; } function objectGetEntries($bQueued, $bRejected, $iRows = 0, $iStart = 0) { /* Not implemented */ if($bRejected) return FALSE; /* Only users with edit privileges are allowed to view queued items, so return NULL in that case */ if($bQueued && !distribution::canEdit()) return NULL; /* If row limit is 0 we want to fetch all rows */ if(!$iRows) $iRows = distribution::objectGetEntriesCount($bQueued, $bRejected); $sQuery = "SELECT * FROM distributions WHERE queued = '?' ORDER BY name LIMIT ?,?"; return query_parameters($sQuery, $bQueued ? "true" : "false", $iStart, $iRows); } function objectGetInstanceFromRow($oRow) { return new distribution($oRow->distributionId, $oRow); } /* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectOutputTableRow($oManager, $sClass, $sEditLinkLabel) { $aCells = array( "makeUrl("view", $this->iDistributionId, "View distribution")."\">$this->sName.", "sUrl\">$this->sUrl", array(sizeof($this->aTestingIds), "align=\"right\"")); if($this->canEdit()) { if(!sizeof($this->aTestingIds)) $shDeleteLink = "   [delete]"; $aCells[] = array( "[$sEditLinkLabel]$shDeleteLink", "align=\"center\""); } echo html_tr($aCells, $sClass); } // Whether the user has permission to edit distributions function canEdit() { if($_SESSION['current']->hasPriv("admin")) return TRUE; /* Maintainers are allowed to process queued test results and therefore also queued distributions */ if(is_object($this) && $this->sQueued != "false" && maintainer::isUserMaintainer($_SESSION['current'])) return TRUE; return FALSE; } function mustBeQueued() { if($_SESSION['current']->hasPriv("admin") || maintainer::isUserMaintainer($_SESSION['current'])) return FALSE; else return TRUE; } function objectHideDelete() { return TRUE; } function display() { echo "Distribution Name:"; if($this->sUrl) echo ""; echo $this->sName; if ($this->sUrl) { echo " (".$this->sUrl.")"; echo "
\n"; } else { echo "
\n"; } if($this->aTestingIds) { echo '

Testing Results for '.$this->sName.'
',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; foreach($this->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; /* make sure the user can view the versions we list in the table */ /* otherwise skip over displaying the entries in this table */ if(!$_SESSION[current]->canViewApplication($oApp)) continue; if(!$_SESSION[current]->canViewVersion($oVersion)) continue; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; if ($_SESSION['current']->hasAppVersionModifyPermission($oVersion)) { echo '',"\n"; } echo '',"\n"; } echo '
Application VersionSubmitterDate SubmittedWine versionInstalls?Runs?Rating
',"\n"; echo version::fullName($oVersion->iVersionId).'',"\n"; if($_SESSION['current']->isLoggedIn()) { echo $oSubmitter->sEmail ? "sEmail."\">":""; echo $oSubmitter->sRealname; echo $oSubmitter->sEmail ? "":""; } else echo $oSubmitter->sRealname; echo ''.date("M d Y", mysqltimestamp_to_unixtimestamp($oTest->sSubmitTime)).''.$oTest->sTestedRelease.' '.$oTest->sInstalls.' '.$oTest->sRuns.' '.$oTest->sTestedRating.' ',"\n"; echo 'Edit
',"\n"; } } /* Make a URL for viewing the specified distribution */ function objectMakeUrl() { $oObject = new objectManager("distribution", "View Distribution"); return $oObject->makeUrl("view", $this->iDistributionId); } /* Make an HTML link for viewing the specified distirbution */ function objectMakeLink() { return "objectMakeUrl()."\">$this->sName"; } function objectMoveChildren($iNewId) { /* Keep track of how many children we modified */ $iCount = 0; foreach($this->aTestingIds as $iTestId) { $oTest = new testData($iTestId); $oTest->iDistributionId = $iNewId; if($oTest->update(TRUE)) $iCount++; else return FALSE; } return $iCount; } function objectGetid() { return $this->iDistributionId; } } ?>