diff --git a/help/voting.help b/help/voting.help index 50510ff..c574065 100644 --- a/help/voting.help +++ b/help/voting.help @@ -3,18 +3,18 @@

Application Voting System Help

-The Application Database features a voting system that allows you to pick which 3 applications +The Application Database features a voting system that allows you to pick which 3 application verions you would MOST like to see running in Wine.

-

Step by Step help on Voting

+

Step by Step Help on Voting

  1. Log into the Application Database.
  2. -

  3. Browse to the Application you wish to add to your vote list.
  4. +

  5. Browse to the application version you wish to add to your vote list.
  6. -

  7. In the sidebar, Click one of the 3 available slots, and click Vote.
  8. +

  9. In the sidebar, click one of the 3 available slots, and click Vote.
  10. Done!
  11. @@ -25,14 +25,12 @@ you would MOST like to see running in Wine. diff --git a/include/application.php b/include/application.php index 44c7b16..2520e99 100644 --- a/include/application.php +++ b/include/application.php @@ -613,10 +613,6 @@ class Application { if(!$_SESSION['current']->canViewApplication($this)) util_show_error_page_and_exit("Something went wrong with the application or version id"); - // show Vote Menu - if($_SESSION['current']->isLoggedIn()) - apidb_sidebar_add("vote_menu"); - // header apidb_header("Viewing App - ".$this->sName); @@ -640,12 +636,10 @@ class Application { echo " Name ".$this->sName." \n"; echo " Vendor ". " ".$oVendor->sName."  \n"; - echo " Votes "; - echo vote_count_app_total($this->iAppId); echo " \n"; // main URL - echo " URL".$appLinkURL."\n"; + echo " URL".$appLinkURL."\n"; // optional links if($sUrls = url::display(NULL, $this->iAppId)) diff --git a/include/util.php b/include/util.php index b3f451b..a30b81d 100644 --- a/include/util.php +++ b/include/util.php @@ -279,11 +279,11 @@ function outputTopXRowAppsFromRating($rating, $iNum_apps) /* them again when filling in any empty spots in the list */ $appIdArray = array(); - $sQuery = "SELECT appVotes.appId AS appId, appVersion.versionId, COUNT( appVotes.appId ) AS c + $sQuery = "SELECT appVotes.versionId, COUNT( appVotes.versionId ) AS c FROM appVotes, appVersion WHERE appVersion.maintainer_rating = '?' - AND appVersion.appId = appVotes.appId - GROUP BY appVotes.appId + AND appVersion.versionId = appVotes.versionId + GROUP BY appVotes.versionId ORDER BY c DESC LIMIT ?"; $hResult = query_parameters($sQuery, $rating, $iNum_apps); @@ -298,7 +298,7 @@ function outputTopXRowAppsFromRating($rating, $iNum_apps) if(!$iNum_apps) return; /* if we have any empty spots in the list, get these from applications with images */ - $sQuery = "SELECT DISTINCT appVersion.appId as appId, appVersion.versionId + $sQuery = "SELECT DISTINCT appVersion.versionId FROM appVersion, appData WHERE appVersion.maintainer_rating = '$rating' AND appVersion.versionId = appData.versionId @@ -307,7 +307,7 @@ function outputTopXRowAppsFromRating($rating, $iNum_apps) /* make sure we exclude any apps we've already output */ foreach($appIdArray as $key=>$value) - $sQuery.="AND appVersion.appId != '".$value."' "; + $sQuery.="AND appVersion.versionId != '".$value."' "; $sQuery.=" LIMIT $iNum_apps"; diff --git a/include/version.php b/include/version.php index f419ac8..7b4f7fb 100644 --- a/include/version.php +++ b/include/version.php @@ -668,8 +668,8 @@ class Version { return $errors; } - /* retrieves values from $aValues that were output by OutputEditor() */ - /* $aValues can be $_REQUEST or any array with the values from OutputEditor() */ + /* retrieves values from $aValues that were output by outputEditor() */ + /* $aValues can be $_REQUEST or any array with the values from outputEditor() */ function GetOutputEditorValues($aValues) { $this->iAppId = $aValues['iAppId']; @@ -930,6 +930,24 @@ class Version { return $ob->versionName; } + function fullName($iVersionId) + { + if(!$iVersionId) + return FALSE; + + $hResult = query_parameters( + "SELECT appFamily.appName, appVersion.versionName + FROM appVersion, appFamily WHERE appVersion.appId = appFamily.appId + AND versionId = '?'", + $iVersionId); + + if(!$hResult || !mysql_num_rows($hResult)) + return FALSE; + + $oRow = mysql_fetch_object($hResult); + return "$oRow->appName $oRow->versionName"; +} + function showList($hResult) { //show applist diff --git a/include/vote.php b/include/vote.php index 6b3c108..ed5c68c 100644 --- a/include/vote.php +++ b/include/vote.php @@ -3,11 +3,10 @@ require_once(BASE."include/util.php"); /* max votes per user */ define('MAX_VOTES',3); - /** * count the number of votes for appId by userId */ -function vote_count($iAppId, $iUserId = null) +function vote_count($iVersionId, $iUserId = null) { if(!$iUserId) { @@ -16,8 +15,8 @@ function vote_count($iAppId, $iUserId = null) else return 0; } - $hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?' AND userId = '?'", - $iAppId, $iUserId); + $hResult = query_parameters("SELECT * FROM appVotes WHERE versionId = '?' AND userId = '?'", + $iVersionId, $iUserId); return mysql_num_rows($hResult); } @@ -40,11 +39,12 @@ function vote_count_user_total($iUserId = null) /* - * total votes for appId + * total votes for versionId */ -function vote_count_app_total($iAppId) +function vote_count_version_total($iVersionId) { - $hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?'", $iAppId); + $hResult = query_parameters("SELECT * FROM appVotes WHERE versionId = '?'", + $iVersionId); return mysql_num_rows($hResult); } @@ -52,7 +52,7 @@ function vote_count_app_total($iAppId) /** * add a vote for appId */ -function vote_add($iAppId, $iSlot, $iUserId = null) +function vote_add($iVersionId, $iSlot, $iUserId = null) { if(!$iUserId) { @@ -67,8 +67,9 @@ function vote_add($iAppId, $iSlot, $iUserId = null) vote_remove($iSlot, $iUserId); - query_parameters("INSERT INTO appVotes (id, time, appId, userId, slot) - VALUES (?, ?, '?', '?', '?')", "null", "null", $iAppId, $iUserId, $iSlot); + query_parameters("INSERT INTO appVotes (id, time, versionId, userId, slot) + VALUES (?, ?, '?', '?', '?')", "null", "null", + $iVersionId, $iUserId, $iSlot); } @@ -115,19 +116,21 @@ function vote_menu() global $aClean; $m = new htmlmenu("Votes","updatevote.php"); - + $votes = vote_get_user_votes(); for($i = 1;$i <= MAX_VOTES; $i++) { if(isset($votes[$i])) { - $sAppName = Application::lookup_name($votes[$i]->appId); - $str = " $sAppName"; - $m->add(" ".$str); + $sName = Version::fullName($votes[$i]->versionId); + $str = "". + "$sName"; } else - $m->add(" No App Selected"); + $str = "No App Selected"; + + $m->add(" $str"); } $m->addmisc(" "); @@ -135,7 +138,7 @@ function vote_menu() $m->add(""); $m->add(""); - $m->addmisc(""); + $m->addmisc(""); $m->add("View Results", BASE."votestats.php"); $m->add("Voting Help", BASE."help/?sTopic=voting"); @@ -149,10 +152,11 @@ function vote_update($vars) if(!$_SESSION['current']->isLoggedIn()) util_show_error_page_and_exit("You must be logged in to vote"); - if( !is_numeric($vars['iAppId']) OR !is_numeric($vars['iSlot'])) + if( !is_numeric($vars['iVersionId']) OR !is_numeric($vars['iSlot'])) { - if(is_numeric($vars['iAppId'])) - util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars['iAppId'])); + if(is_numeric($vars['iVersionId'])) + util_redirect_and_exit(apidb_fullurl( + "appview.php?iVersionId=".$vars['iVersionId'])); else util_redirect_and_exit(apidb_fullurl("index.php")); @@ -161,8 +165,8 @@ function vote_update($vars) if($vars["sVote"]) { - addmsg("Registered vote for App #".$vars['iAppId'], "green"); - vote_add($vars['iAppId'], $vars['iSlot']); + addmsg("Registered vote for App #".$vars['iVersionId'], "green"); + vote_add($vars['iVersionId'], $vars['iSlot']); } else if($vars['sClear']) { /* see if we have a vote in this slot, if we don't there is */ @@ -170,11 +174,12 @@ function vote_update($vars) if(is_vote_in_slot($vars['iSlot'])) { vote_remove($vars['iSlot']); - addmsg("Removed vote for App #".$vars['iAppId'], "green"); + addmsg("Removed vote for App #".$vars['iVersionId'], "green"); } } - util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars['iAppId'])); + util_redirect_and_exit(apidb_fullurl( + "appview.php?iVersionId=".$vars['iVersionId'])); } // tell us if there is a vote in a given slot so we don't diff --git a/index.php b/index.php index 4f469a8..795c29c 100644 --- a/index.php +++ b/index.php @@ -59,21 +59,20 @@ If you have screenshots or links to contribute, please browse the database and u $numApps = getNumberOfVersions(); - $voteQuery = "SELECT appVotes.appId, appName, count(userId) as count ". - "FROM appVotes, appFamily ". - "WHERE appVotes.appId = appFamily.appId ". - "GROUP BY appId ORDER BY count DESC LIMIT 1"; + $voteQuery = "SELECT appVotes.versionId, count(userId) as count ". + "FROM appVotes ". + "GROUP BY versionId ORDER BY count DESC LIMIT 1"; $hResult = query_parameters($voteQuery); $oRow = mysql_fetch_object($hResult); - $voteAppId = $oRow->appId; - $voteAppName = $oRow->appName; + $sVoteVersionId = $oRow->versionId; + $sVoteAppName = version::fullName($oRow->versionId); // don't mention the top application if there are no votes yet - if($voteAppId != "") + if($sVoteVersionId != "") { echo "There are $numApps applications currently in the database with\n"; - echo "$voteAppName being the\n"; + echo "$sVoteAppName being the\n"; echo "top voted application.\n"; } else { diff --git a/tables/appdb_tables.sql b/tables/appdb_tables.sql index 0605785..299cdc0 100644 --- a/tables/appdb_tables.sql +++ b/tables/appdb_tables.sql @@ -152,11 +152,11 @@ create table appData ( create table appVotes ( id int not null auto_increment, time timestamp, - appId int not null, + versionId int not null, userId int not null, slot int not null, key(id), - index(appId), + index(versionId), index(userId) ); diff --git a/votestats.php b/votestats.php index 8e23fd7..051168f 100644 --- a/votestats.php +++ b/votestats.php @@ -125,10 +125,13 @@ echo '
    '; if(empty($aClean['iCategoryId'])) { /* leave out the appFamily.catId = '$aClean['iCategoryId']' */ - $hResult = query_parameters("SELECT appVotes.appId, appName, count(userId) as count ". - "FROM appVotes, appFamily ". - "WHERE appVotes.appId = appFamily.appId ". - "GROUP BY appId ORDER BY count DESC LIMIT ?", $aClean['iTopNumber']); + $hResult = query_parameters("SELECT appVotes.versionId, appName, count(userId) as + count + FROM appVotes, appFamily, appVersion + WHERE appVotes.versionId = appVersion.versionId AND + appFamily.appId = appVersion.appId + GROUP BY appVotes.versionId ORDER BY count DESC LIMIT ?", + $aClean['iTopNumber']); } else { /* Display all application for a given category (including sub categories) @@ -139,15 +142,16 @@ if(empty($aClean['iCategoryId'])) c.catId =29 OR c.catParent =29)*/ - $hResult = query_parameters("SELECT v.appId, f.appName, count( v.appId ) AS count - FROM appFamily AS f, appCategory AS c, appVotes AS v - WHERE v.appId = f.appId + $hResult = query_parameters("SELECT v.versionId, f.appName, count( v.versionId ) AS count + FROM appFamily AS f, appCategory AS c, appVotes AS v, appVersion + WHERE appVersion.appId = f.appId + AND appVersion.versionId = v.versionId AND f.catId = c.catId AND ( c.catId = '?' OR c.catParent = '?' ) - GROUP BY appId + GROUP BY v.versionId ORDER BY count DESC LIMIT ?", $aClean['iCategoryId'], $aClean['iCategoryId'], $aClean['iTopNumber']); } @@ -162,7 +166,7 @@ if($hResult) while($row = mysql_fetch_object($hResult)) { $bgcolor = ($c % 2) ? "color0" : "color1"; - $link = "$row->appName"; + $link = "$row->appName"; echo "$c. $link $row->count \n"; $c++; }