iId = $oRow->id; $this->iVersionId = $oRow->versionId; $this->sDescription = $oRow->description; $this->sUrl = $oRow->url; $this->sSubmitTime = $oRow->submitTime; $this->iSubmitterId = $oRow->submitterId; $this->bQueued = ($oRow->state == 'queued') ? TRUE : FALSE; } } /* Display download links for a given version */ function display($iVersionId) { if(!($hResult = appData::getData($iVersionId, "downloadurl"))) return FALSE; // we're appending, so initialize it $sReturn = ''; for($i = 0; $oRow = query_fetch_object($hResult); $i++) { $sReturn .= html_tr(array( "Free Download", "url\">$oRow->description"), "color1"); } return $sReturn; } public function objectGetParent($sClass = '') { $oAppData = new appData($this->iId, null, $this); return $oAppData->objectGetParent(); } public function objectSetParent($iNewId, $sClass = '') { if($this->iVersionId || !$this->iAppId) $this->iVersionId = $iNewId; else $this->iAppId = $iNewId; } function objectGetChildren($bIncludeDeleted = false) { /* We have none */ return array(); } /* Output an editor for Download URL fields */ function outputEditor($oVersion = null, $sFormAction = null) { /* If we do not get any parameters we try to behave like a proper objectManager object, by only showing an editor for one entry instead of several. This code is sort of hacky, and should be fixed once the rest of the downloadurl code is fully adapted to the objectManager */ if(!$oVersion && !$sFormAction) { global $aClean; echo downloadurl::outputEditorSingle($this->iVersionId); } if(!$oVersion || !$sFormAction) return FALSE; /* Check for correct permissions */ if(!downloadurl::canEdit($oVersion->iVersionId)) return FALSE; $hResult = appData::getData($oVersion->iVersionId, "downloadurl"); $sReturn .= html_frame_start("Download URL", "90%", "", 0); $sReturn .= "
\n"; $sReturn .= html_frame_end(" "); return $sReturn; } function objectGetSubmitterId() { return $this->iSubmitterId; } function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) { return new mailOptions(); } function objectGetMail($sAction, $bMailSubmitter, $bParentAction) { /* We don't do this at the moment */ return array(null, null, null); } /* Process data from a Download URL form */ function ProcessForm($aValues) { /* Check that we are processing a Download URL form */ if($aValues["sSubmit"] != "Update Download URLs") return FALSE; /* Check permissions */ if(!downloadurl::canEdit($aValues["iVersionId"])) return FALSE; if(!($hResult = query_parameters("SELECT COUNT(*) as num FROM appData WHERE TYPE = '?' AND versionId = '?' AND state = 'accepted'", "downloadurl", $aValues["iVersionId"]))) return FALSE; if(!($oRow = query_fetch_object($hResult))) return FALSE; $num = $oRow->num; /* Update URLs. Nothing to do if none are present in the database */ if($num) { if(!$hResult = appData::getData($aValues["iVersionId"], "downloadurl")) return FALSE; while($oRow = query_fetch_object($hResult)) { $oDownloadurl = new downloadurl($oRow->id); /* Remove URL */ if($aValues["bRemove$oRow->id"]) { if(!$oDownloadurl->delete()) return FALSE; $sWhatChangedRemove .= "Removed\nURL: $oRow->url\n". "Description: $oRow->description\n\n"; } /* Change description/URL */ if(($aValues["sDescription$oRow->id"] != $oRow->description or $aValues["sUrl$oRow->id"] != $oRow->url) && $aValues["sDescription$oRow->id"] && $aValues["sUrl$oRow->id"]) { $oDownloadurl->sDescription = $aValues["sDescription$oRow->id"]; $oDownloadurl->sUrl = $aValues["sUrl$oRow->id"]; if(!$oDownloadurl->update()) return FALSE; $sWhatChangedModify .= "Modified\nOld URL: $oRow->url\nOld ". "Description: $oRow->description\nNew URL: ". $aValues["sUrl$oRow->id"]."\nNew Description: ". $aValues["sDescription$oRow->id"]."\n\n"; } } } /* Insert new URL */ if($aValues["sDescriptionNew"] && $aValues["sUrlNew"]) { $oDownloadurl = new downloadurl(); $oDownloadurl->iVersionId = $aValues["iVersionId"]; $oDownloadurl->sUrl = $aValues["sUrlNew"]; $oDownloadurl->sDescription = $aValues["sDescriptionNew"]; if(!$oDownloadurl->create()) return FALSE; $sWhatChanged = "Added\nURL: ".$aValues["sUrlNew"]."\nDescription: ". $aValues["sDescriptionNew"]."\n\n"; } $sWhatChanged .= "$sWhatChangedRemove$sWhatChangedModify"; if($sWhatChanged && $sEmail = User::get_notify_email_address_list($aValues['iVersionId'])) { $oVersion = new Version($aValues["iVersionId"]); $sSubject = "Download URLs for ".version::fullName($oVersion->iVersionId). " updated by ".$_SESSION['current']->sRealname; $sMsg = $oVersion->objectMakeUrl(); $sMsg .= "\n\n"; $sMsg .= "The following changed were made\n\n"; $sMsg .= "$sWhatChanged\n\n"; mail_appdb($sEmail, $sSubject, $sMsg); } return TRUE; } function objectGetState() { return ($this->bQueued) ? 'queued' : 'accepted'; } function canEdit($iVersionId = NULL) { if($_SESSION['current']->hasPriv("admin") || ($iVersionId && maintainer::isUserMaintainer($_SESSION['current'], $iVersionId))) { return TRUE; } else { $oVersion = new version($this->iVersionId); return $oVersion->canEdit(); } } /* Output an editor for a single new URL */ function outputEditorSingle($iVersionId = NULL, $aValues = NULL) { if($aValues["sDownloadUrlUrl"] && $aValues["sDownloadUrlDescription"]) { $sDownloadUrlUrl = $aValues["sDownloadUrlUrl"]; $sDownloadUrlDescription = $aValues["sDownloadUrlDescription"]; } else if($iVersionId) { /* This illustrates the importance of converting downloadurl completely to the objectManager model. If we don't get a match searching for a queued entry, try finding a rejected one. */ if(($hResult = appData::getData($iVersionId, "downloadurl", TRUE, TRUE, FALSE)) || $hResult = appData::getData($iVersionId, "downloadurl", TRUE, TRUE, TRUE)) { $oRow = query_fetch_object($hResult); $sDownloadUrlUrl = $oRow->url; $sDownloadUrlDescription = $oRow->description; } } $sReturn .= html_frame_start("Download URL","90%"); $sReturn .= html_table_begin("width='100%' border=0 cellpadding=2 cellspacing=0"); $sReturn .= "A place where this version can be downloaded for free". " (if applicable). You can add more links later.