diff --git a/browse_downloadable.php b/browse_downloadable.php index f343a11..1e3d244 100644 --- a/browse_downloadable.php +++ b/browse_downloadable.php @@ -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 "\n"; +echo "Filter by license\n"; +$oVersion = new Version(); +echo $oVersion->makeLicenseList($sLicense); + echo " \n"; echo "\n
\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 "
No matches found
\n"; + echo html_frame_end(" "); + 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)) { diff --git a/include/version.php b/include/version.php index 4cedb6c..6cc3a2b 100644 --- a/include/version.php +++ b/include/version.php @@ -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; + } } ?>