mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
This commit is contained in:
parent
1eea2951fb
commit
c2b65f2b7b
2 changed files with 48 additions and 24 deletions
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue