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_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 "