diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 40 | ||||
-rw-r--r-- | web/template/actions_form.php | 32 |
2 files changed, 48 insertions, 24 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 5696321f..2265c767 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 * diff --git a/web/template/actions_form.php b/web/template/actions_form.php index 59a6e7aa..e5ab7c2e 100644 --- a/web/template/actions_form.php +++ b/web/template/actions_form.php @@ -3,33 +3,17 @@ <fieldset> <input type="hidden" name="IDs[<?php echo $row['ID'] ?>]" value="1" /> <input type="hidden" name="ID" value="<?php echo $row['ID'] ?>" /> - <?php - # Voting Button - # - $q = "SELECT * FROM PackageVotes WHERE UsersID = ". $uid; - $q.= " AND PackageID = ".$row["ID"]; - $result = db_query($q, $dbh); - if ($result): - if (!mysql_num_rows($result)): - ?> - <input type="submit" class="button" name="do_Vote" value="<?php echo __("Vote") ?>" /> - <?php else: ?> + + <?php if (user_voted($uid, $row['ID'])): ?> <input type="submit" class="button" name="do_UnVote" value="<?php echo __("UnVote") ?>" /> - <?php endif; ?> + <?php else: ?> + <input type="submit" class="button" name="do_Vote" value="<?php echo __("Vote") ?>" /> <?php endif; ?> - <?php - # Comment Notify Button - # - $q = "SELECT * FROM CommentNotify WHERE UserID = ". $uid; - $q.= " AND PkgID = ".$row["ID"]; - $result = db_query($q, $dbh); - if ($result): - if (!mysql_num_rows($result)): - ?> - <input type="submit" class="button" name="do_Notify" value="<?php echo __("Notify") ?>" title="<?php echo __("New Comment Notification") ?>" /> - <?php else: ?> + + <?php if (user_notify($uid, $row['ID'])): ?> <input type="submit" class="button" name="do_UnNotify" value="<?php echo __("UnNotify") ?>" title="<?php echo __("No New Comment Notification") ?>" /> - <?php endif; ?> + <?php else: ?> + <input type="submit" class="button" name="do_Notify" value="<?php echo __("Notify") ?>" title="<?php echo __("New Comment Notification") ?>" /> <?php endif; ?> <?php if ($row["OutOfDateTS"] === NULL): ?> |