From 52a155588c7eb0b7eb335993e79b8ed35c4ce4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Fri, 5 Jan 2007 05:20:05 +0000 Subject: [PATCH] Add the ability to add download URLs to application versions. They are displayed in the version view marked as 'free downloads'. The links will later be used to allow browsing of downloadable applications. --- admin/editAppVersion.php | 4 + include/appData.php | 19 ++++ include/downloadurl.php | 222 +++++++++++++++++++++++++++++++++++++++ include/version.php | 4 + tables/appdb_tables.sql | 2 +- 5 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 include/downloadurl.php diff --git a/admin/editAppVersion.php b/admin/editAppVersion.php index 39b0a01..bfad083 100644 --- a/admin/editAppVersion.php +++ b/admin/editAppVersion.php @@ -16,6 +16,7 @@ if(!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintaine if(!empty($aClean['sSubmit'])) { process_app_version_changes(true); + downloadurl::processForm($_REQUEST); util_redirect_and_exit(apidb_fullurl("appview.php?iVersionId=".$aClean['iVersionId'])); } else /* or display the webform for making changes */ { @@ -85,6 +86,9 @@ if(!empty($aClean['sSubmit'])) echo html_frame_end(); echo ""; + /* Download URL editor */ + echo downloadurl::editor($oVersion, "editAppVersion.php"); + /* only admins can move versions */ if($_SESSION['current']->hasPriv("admin")) { diff --git a/include/appData.php b/include/appData.php index 3861a8e..95bbc5d 100644 --- a/include/appData.php +++ b/include/appData.php @@ -51,6 +51,25 @@ class appData return $sReturn; } + + /* Get appData for a given version/application, optionally filter by type */ + function getData($iId, $sType, $bIsVersion = TRUE) + { + $iAppId = 0; + $iVersionId = 0; + + if($bIsVersion) + $iVersionId = $iId; + else + $iAppId = $iId; + + $hResult = query_parameters("SELECT * FROM appData WHERE appId = '?' AND versionId = '?' AND TYPE = '?'", $iAppId, $iVersionId, $sType); + + if(!$hResult || !mysql_num_rows($hResult)) + return FALSE; + + return $hResult; + } } ?> diff --git a/include/downloadurl.php b/include/downloadurl.php new file mode 100644 index 0000000..b626085 --- /dev/null +++ b/include/downloadurl.php @@ -0,0 +1,222 @@ +iId); + + if($hResult && mysql_num_rows($hResult)) + { + $oRow = mysql_fetch_object($hResult); + if($oRow) + { + $this->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->queued == "true") ? TRUE : FALSE; + } + } + } + + /* Display download links for a given version */ + function display($iVersionId) + { + if(!($hResult = appData::getData($iVersionId, "downloadurl"))) + return FALSE; + + for($i = 0; $oRow = mysql_fetch_object($hResult); $i++) + { + $sReturn .= html_tr(array( + "Free Download", + "url\">$oRow->description"), + "color1"); + } + + return $sReturn; + } + + /* Output an editor for Download URL fields */ + function editor($oVersion, $sFormAction) + { + /* 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_table_begin("width=100%"); + $sReturn .= html_tr(array( + array("Remove", "width=\"90\""), + "Description", + "URL" + ), + "color0"); + + $sReturn .= html_tr(array( + " ", + "", + ""), + "color4"); + + if($hResult) + { + for($i = 1; $oRow = mysql_fetch_object($hResult); $i++) + { + $sReturn .= html_tr(array( + "id\" />", + "id\" value=\"$oRow->description\" />", + "id\" ". + "value=\"$oRow->url\" />"), + ($i % 2) ? "color0" : "color4"); + } + } + + $sReturn .= html_table_end(); + $sReturn .= "
\n"; + $sReturn .= "iVersionId\" />\n"; + $sReturn .= "iAppId\" />\n"; + $sReturn .= "
\n"; + $sReturn .= html_frame_end(" "); + + return $sReturn; + } + + /* 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 = '?'", + "downloadurl", $aValues["iVersionId"]))) + return FALSE; + + if(!($oRow = mysql_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 = mysql_fetch_object($hResult)) + { + /* Remove URL */ + if($aValues["bRemove$oRow->id"]) + { + if(!query_parameters("DELETE FROM appData WHERE id = '?'", + $oRow->id)) + 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"]) + { + if(!query_parameters("UPDATE appData SET description = '?', + url = '?' WHERE id = '?'", + $aValues["sDescription$oRow->id"], + $aValues["sURL$oRow->id"], $oRow->id)) + return FALSE; + + $sWhatChangedModify .= "Modified\nOld URL: $oRow->url\nOld ". + "Description: $oRow->description\nNew URL: ". + $aValues["sUrl$oRow->id"]." New Description: ". + $aValues["sDescription$oRow->id"]."\n\n"; + } + } + } + + /* Insert new URL */ + if($aValues["sDescriptionNew"] && $aValues["sUrlNew"]) + { + if(!query_parameters("INSERT INTO appData (versionId, TYPE, + description, url, submitterId, queued) + VALUES('?', '?', '?', '?', '?', '?')", + $aValues["iVersionId"], "downloadurl", + $aValues["sDescriptionNew"], $aValues["sUrlNew"], + $_SESSION["current"]->iUserId, "false")) + 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['iAppId'])) + { + $oApp = new Application($aValues["iAppId"]); + + $sSubject = "Download URLs for $oApp->sName updated by ". + $_SESSION['current']->sRealname; + + $sMsg = APPDB_ROOT."appview.php?iVersionId=".$aValues['iVersionId']; + $sMsg .= "\n\n"; + $sMsg .= "The following changed were made\n\n"; + $sMsg .= "$sWhatChanged\n\n"; + + mail_appdb("$sEmail, $sSubject, $sMsg"); + } + + return TRUE; + } + + function canEdit($iVersionId) + { + $oUser = new User($_SESSION['current']->iUserId); + + if($oUser->hasPriv("admin") || maintainer::isUserMaintainer($oUser, + $iVersionId)) + { + return TRUE; + } else + { + return FALSE; + } + } +} + +?> diff --git a/include/version.php b/include/version.php index 6e6aea2..4e48b11 100644 --- a/include/version.php +++ b/include/version.php @@ -10,6 +10,7 @@ require_once(BASE."include/screenshot.php"); require_once(BASE."include/bugs.php"); require_once(BASE."include/util.php"); require_once(BASE."include/testData.php"); +require_once(BASE."include/downloadurl.php"); /** * Version class for handling versions. @@ -667,6 +668,9 @@ class Version { echo "Maintainer’s Rating".$this->sTestedRating."\n"; echo "Maintainer’s Version".$this->sTestedRelease."\n"; + if($sDownloadurls = downloadurl::display($this->iVersionId)) + echo $sDownloadurls; + // image $img = Screenshot::get_random_screenshot_img($oApp->iAppId, $this->iVersionId, false); echo "$img\n"; diff --git a/tables/appdb_tables.sql b/tables/appdb_tables.sql index fbbeed2..8111cb7 100644 --- a/tables/appdb_tables.sql +++ b/tables/appdb_tables.sql @@ -133,7 +133,7 @@ create table appData ( id int not null auto_increment, appId int not null, versionId int default 0, - type enum('image', 'url', 'bug'), + type enum('image', 'url', 'bug','downloadurl'), description text, url varchar(255) default NULL, submitTime timestamp(14) NOT NULL,