oApp = new application($iAppId); /* If this is an existing application then there must be a version accompanying it */ if($iAppId) { /* Normal users do not get a aVersionsIds property, so we have to fetch the versionId manually. Normal users only have access to rejected applications */ if($_SESSION['current']->hasPriv("admin")) { $iVersionId = $this->oApp->aVersionsIds[0]; } else if($this->oApp->sQueued == "rejected") { $sQuery = "SELECT versionId FROM appVersion WHERE appId = '?' LIMIT 1"; $hResult = query_parameters($sQuery, $this->oApp->iAppId); if($hResult) { if($oRow = mysql_fetch_object($hResult)) $iVersionId = $oRow->versionId; } } $iVendorId = $this->oApp->iVendorId; } else { $iVersionId = null; $iVendorId = null; } $this->oVendor = new vendor($iVendorId); $this->oVersionQueue = new version_queue($iVersionId); } function create() { $bSuccess = TRUE; /* Create a new vendor if an existing one was not selected, and assign the application to it */ if(!$this->oApp->iVendorId) { $this->oVendor->create(); $this->oApp->iVendorId = $this->oVendor->iVendorId; } if(!$this->oApp->create()) $bSuccess = FALSE; /* Assign the version to the new application */ $this->oVersionQueue->oVersion->iAppId = $this->oApp->iAppId; if(!$this->oVersionQueue->create()) $bSuccess = FALSE; return $bSuccess; } function update() { $bSucess = TRUE; /* If the vendor was already un-queued then the edit vendor form would not have been displayed, and so the vendor name will not be set. Thus only update the vendor if the name is set */ if($this->oVendor->sName) $this->oVendor->update(); if(!$this->oApp->update()) $bSuccess = FALSE; if(!$this->oVersionQueue->update()) $bSuccess = FALSE; return $bSuccess; } function unQueue() { /* The vendor is not necessarily queued, as it could have existed on beforehand */ if($this->oVendor->sQueued != "false") $this->oVendor->unQueue(); $this->oApp->unQueue(); $this->oVersionQueue->unQueue(); } function reQueue() { $this->oApp->reQueue(); $this->oVersionQueue->reQueue(); } function reject() { $this->oVersionQueue->reject(); $this->oApp->reject(); } function delete() { $bSuccess = TRUE; if(!$this->oApp->delete()) $bSuccess = FALSE; /* When deleting a duplicate app in the application queue, the version is moved to another app and so when application_queue::delete() is called there is no version child to delete, so check if the versionId is valid */ if($this->oVersionQueue->oVersion->iVersionId) { if(!$this->oVersionQueue->delete()) $bSuccess = FALSE; } return $bSuccess; } function outputEditor() { /* We ask the user for the application name first so as to avoid duplicate submissons; a list of potential duplicates is displayed on the next page */ if(!$this->oApp->sName) { echo "
\n"; echo "
\n"; echo "Application name:\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "
\n"; } else { /* Show potential duplicates */ echo html_frame_start("Potential duplicate applications in the ". "database","90%","",0); $this->displayDuplicates(); echo html_frame_end(" "); $this->oApp->outputEditor(); /* We need to accept vendors submitted using the old keyword hack. This should be removed soon */ if(!$this->oVendor->sName && $this->oApp->iAppId) { $this->oVendor->sName = get_vendor_from_keywords( $this->oApp->sKeywords); } /* Display the new vendor form for new applications or if we are processing an application and the vendor is queued */ if(!$this->oApp->iAppId || $this->oVendor->sQueued != "false") { echo html_frame_start("New Vendor", "90%"); $this->oVendor->outputEditor(); echo html_frame_end(); } $this->oVersionQueue->oVersion->outputEditor(); global $aClean; echo $this->oVersionQueue->oDownloadUrl->outputEditorSingle( $this->oVersionQueue->Oversion->iVersionId, $aClean); $this->oVersionQueue->oTestDataQueue->outputEditor(); } } function getOutputEditorValues($aClean) { $this->oApp->getOutputEditorValues($aClean); $this->oVersionQueue->getOutputEditorValues($aClean); $this->oVendor->getOutputEditorValues($aClean); } function checkOutputEditorInput($aClean) { /* We want outputEditor() to be called again so we can display the main app form. No erros are displayed since we only return TRUE */ if($this->oApp->sName && !$aClean['bMainAppForm']) return TRUE; $sErrors = $this->oApp->checkOutputEditorInput($aClean); $sErrors .= $this->oVersionQueue->checkOutputEditorInput($aClean); return $sErrors; } function canEdit() { return $this->oApp->canEdit(); } function mustBeQueued() { return $this->oApp->mustBeQueued(); } function displayDuplicates() { echo "Like matches\n"; $this->displayDuplicateTable(searchForApplication($this->oApp->sName)); echo "
Fuzzy matches\n"; $this->displayDuplicateTable(searchForApplicationFuzzy($this->oApp->sName, 60)); } function displayDuplicateTable($hResult) { /* Exit if the MySQL handle is invalid */ if($hResult === FALSE) return FALSE; /* There's no point in displaying an empty table */ if($hResult === null ||mysql_num_rows($hResult) == 0) { echo "No matches.
\n"; return; } $aHeader = array( "Application name", "Description", "No. versions" ); /* We can only move data if the current application already exists, and we have admin privileges */ if($this->oApp->iAppId && $_SESSION['current']->hasPriv("admin")) { $bCanMove = TRUE; $aHeader[] = array("Move data", 'width="80"'); } else { $bCanMove = FALSE; } echo ""; echo html_tr($aHeader, "color4"); for($i = 0; $oRow = mysql_fetch_object($hResult); $i++) { $oApp = new application($oRow->appId); $aCells = array( $oApp->objectMakeLink(), util_trim_description($oApp->sDescription), sizeof($oApp->aVersionsIds) ); if($bCanMove) { $aCells[] = "oApp->iAppId."&iNewId=".$oApp->iAppId. "\">Move data"; } echo html_tr($aCells, ($i % 2) ? "color0" : "color1"); } echo "
"; } function display() { $this->oApp->display(); } function objectMakeUrl() { return TRUE; } function objectMakeLink() { return TRUE; } function objectGetEntries($bQueued, $bRejected) { return $this->oApp->objectGetEntries($bQueued, $bRejected); } function objectGetHeader() { return $this->oApp->objectGetHeader(); } function objectGetInstanceFromRow($oRow) { return application::objectGetInstanceFromRow($oRow); } function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) { return $this->oApp->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); } function objectMoveChildren($iNewId) { return $this->oApp->objectMoveChildren($iNewId); } function objectDisplayAddItemHelp() { $this->oApp->objectDisplayAddItemHelp(); } function allowAnonymousSubmissions() { return application::allowAnonymousSubmissions(); } } ?>