Allow filtering by license when browsing downloadable apps

This commit is contained in:
Alexander Nicolaysen Sørnes
2007-01-27 22:58:12 +00:00
committed by WineHQ
parent 5bb8448821
commit 57c4b64986
2 changed files with 56 additions and 10 deletions

View File

@@ -9,6 +9,9 @@ require(BASE."include/incl.php");
apidb_header("Browse Downloadable Applications");
/* Match specific license? */
$sLicense = version::checkLicense($aClean['sLicense']);
/* Set default values */
if(!$aClean['iNumVersions'] || $aClean['iNumVersions'] > 200 || $aClean['iNumVersions'] < 0)
$aClean['iNumVersions'] = 25;
@@ -17,12 +20,19 @@ if(!$aClean['iPage'])
$aClean['iPage'] = 1;
/* Count the possible matches */
$hResult = query_parameters("SELECT DISTINCT appFamily.appName,
$sQuery = "SELECT DISTINCT appFamily.appName,
appVersion.versionName, appVersion.versionId, appFamily.description
FROM appFamily, appVersion, appData
WHERE appData.type = '?' AND appData.versionId = appVersion.versionId
AND appFamily.appId = appVersion.appId",
"downloadurl");
AND appFamily.appId = appVersion.appId";
if(!$sLicense)
$hResult = query_parameters($sQuery, "downloadurl");
else
{
$sQuery .= " AND license = '?'";
$hResult = query_parameters($sQuery, "downloadurl", $sLicense);
}
if($hResult && mysql_num_rows($hResult))
$num = mysql_num_rows($hResult);
@@ -58,16 +68,38 @@ foreach($numVersionsArray as $i)
echo "</select>\n";
echo "<b>Filter by license</b>\n";
$oVersion = new Version();
echo $oVersion->makeLicenseList($sLicense);
echo " <input type=\"submit\" value=\"Refresh\" />\n";
echo "</form></div>\n<br />\n";
$hResult = query_parameters("SELECT DISTINCT appFamily.appName,
appVersion.versionName, appVersion.versionId, appFamily.description
FROM appFamily, appVersion, appData
WHERE appData.type = '?' AND appData.versionId = appVersion.versionId
AND appFamily.appId = appVersion.appId
ORDER BY appFamily.appName LIMIT ?, ?",
"downloadurl", $iLimitLower, $aClean['iNumVersions']);
if(!$num)
{
echo "<div align=\"center\"><font color=\"red\">No matches found</font></div>\n";
echo html_frame_end("&nbsp;");
exit;
}
$sQuery = "SELECT DISTINCT appFamily.appName,
appVersion.versionName, appVersion.versionId, appFamily.description
FROM appFamily, appVersion, appData
WHERE appData.type = '?' AND appData.versionId = appVersion.versionId
AND appFamily.appId = appVersion.appId ";
if(!$sLicense)
{
$sQuery .= "ORDER BY appFamily.appName LIMIT ?, ?";
$hResult = query_parameters($sQuery, "downloadurl", $iLimitLower,
$aClean['iNumVersions']);
} else
{
$sQuery .= "AND license = '?' ORDER BY appFamily.appName LIMIT ?, ?";
$hResult = query_parameters($sQuery,
"downloadurl", $sLicense, $iLimitLower,
$aClean['iNumVersions']);
}
if($hResult && mysql_num_rows($hResult))
{

View File

@@ -1121,6 +1121,20 @@ class Version {
return $sReturn;
}
/* In order to prevent MySQL injections. Returns matched license */
function checkLicense($sLicense)
{
$aLicense = array(LICENSE_RETAIL, LICENSE_OPENSOURCE, LICENSE_FREEWARE,
LICENSE_DEMO, LICENSE_SHAREWARE);
foreach($aLicense as $sElement)
{
if($sLicense == $sElement)
return $sElement;
}
return FALSE;
}
}
?>