diff options
author | canyonknight <canyonknight@gmail.com> | 2012-05-23 15:22:51 -0400 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2012-07-06 11:26:53 +0200 |
commit | c2b65f2b7bffeed46a2981f4eeb04e063c379ac0 (patch) | |
tree | af11ae83d59eacbad45fc78b8b37b89a98a4daa3 /web/lib | |
parent | 1eea2951fbebb5bb4dfc0c09ad7622f03e4a6471 (diff) | |
download | aurweb-c2b65f2b7bffeed46a2981f4eeb04e063c379ac0.tar.xz |
action_form.php: Pull out DB code
* Create new functions in pkgfuncs.inc.php with SQL queries from
action_form.php
* Centralization of DB code important in a future transition to PDO interface
* Flip logic of vote and notify XHTML button to use function return rather
than a more confusing NOT (!) logical operator statement
Signed-off-by: canyonknight <canyonknight@gmail.com>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 5696321..2265c76 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -973,6 +973,46 @@ function getvotes($pkgid, $dbh=NULL) { return $votes; } +# Determine if a user has already voted for a specific package +function user_voted($uid, $pkgid, $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } + + $uid = db_escape_string($uid); + $pkgid = db_escape_string($pkgid); + + $q = "SELECT * FROM PackageVotes WHERE UsersID = ". $uid; + $q.= " AND PackageID = ".$pkgid; + $result = db_query($q, $dbh); + if (mysql_num_rows($result)) { + return true; + } + else { + return false; + } +} + +# Determine if a user wants notifications for a specific package +function user_notify($uid, $pkgid, $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } + + $uid = db_escape_string($uid); + $pkgid = db_escape_string($pkgid); + + $q = "SELECT * FROM CommentNotify WHERE UserID = ". $uid; + $q.= " AND PkgID = ".$pkgid; + $result = db_query($q, $dbh); + if (mysql_num_rows($result)) { + return true; + } + else { + return false; + } +} + /** * Toggle notification of packages * |