summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdocs/CHANGELOG2
-rw-r--r--lib/class/rating.class.php29
-rw-r--r--ratings.php4
-rw-r--r--templates/header.inc2
-rw-r--r--templates/show_object_rating.inc.php17
5 files changed, 42 insertions, 12 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index a680ab3e..3bdd75ed 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,8 @@
--------------------------------------------------------------------------
v.3.3.2-Alpha4
+ - Added Rating system, currently only non-flash works.
+ (Thx SoundOfEmotion for origional code)
- Added pop-up submenus to classic Theme (Thx Sigger)
- Fixed genre pulldown so it's a good bit faster (1/2 the sql calls)
- Updated Preferences (yet again) maybe it's better, maybe it's not
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index 4a513421..06344e1c 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -90,10 +90,15 @@ class Rating {
if ($total > 0) {
$average = floor($total/$i);
+ $this->rating = $average;
}
-
- $this->rating = $average;
-
+ elseif ($i >= '1' AND $total == '0') {
+ $this->rating = '-1';
+ }
+ else {
+ $this->rating = '0';
+ }
+
return $average;
} // get_average
@@ -104,9 +109,25 @@ class Rating {
* This uses the currently logged in user for the 'user' who is rating
* the object. Returns true on success, false on failure
*/
- function set_rating() {
+ function set_rating($score) {
+
+ $score = sql_escape($score);
+
+ /* Check if it exists */
+ $sql = "SELECT id FROM ratings WHERE object_id='$this->id' AND object_type='$this->type' AND `user`='" . sql_escape($GLOBALS['user']->username) . "'";
+ $db_results = mysql_query($sql, dbh());
+ if ($existing = mysql_fetch_assoc($db_results)) {
+ $sql = "UPDATE ratings SET user_rating='$score' WHERE id='" . $existing['id'] . "'";
+ $db_results = mysql_query($sql, dbh());
+ }
+ else {
+ $sql = "INSERT INTO ratings (`object_id`,`object_type`,`user_rating`,`user`) VALUES " .
+ " ('$this->id','$this->type','$score','" . sql_escape($GLOBALS['user']->username) . "')";
+ $db_results = mysql_query($sql, dbh());
+ }
+ return true;
} // set_rating
diff --git a/ratings.php b/ratings.php
index 3ae150b5..9ced9b95 100644
--- a/ratings.php
+++ b/ratings.php
@@ -28,7 +28,9 @@ $action = scrub_in($_REQUEST['action']);
switch ($action) {
case 'set_rating':
-
+ $rating = new Rating($_REQUEST['object_id'],$_REQUEST['rating_type']);
+ $rating->set_rating($_REQUEST['rating']);
+ show_confirmation(_("Rating Updated"),_("Your rating for this object has been updated"),"/index.php");
break;
default:
diff --git a/templates/header.inc b/templates/header.inc
index 635330d8..d69cee63 100644
--- a/templates/header.inc
+++ b/templates/header.inc
@@ -45,7 +45,7 @@ $location = get_location();
</div>
<div id="topbarright">
<a href="http://www.ampache.org/index.php">Ampache v.<?php echo conf('version'); ?></a><br />
- <b><?php echo _("You are currently logged in as") . " " . $GLOBALS['user']->username; ?></b>
+ <b><?php echo _("You are currently logged in as") . " " . $GLOBALS['user']->fullname; ?></b>
<br />
<?php echo _("Browse"); ?>:
<form method="post" action="<?php echo conf('web_path'); ?>/browse.php" enctype="multipart/form-data" style="Display:inline;">
diff --git a/templates/show_object_rating.inc.php b/templates/show_object_rating.inc.php
index 5b95868b..91df1f15 100644
--- a/templates/show_object_rating.inc.php
+++ b/templates/show_object_rating.inc.php
@@ -29,19 +29,24 @@ if ($type != 'song') {
$base_url = conf('web_path') . '/ratings.php?action=set_rating&mode=' . conf('flash') . '&rating_type=' . $rating->type . '&object_id=' . $rating->id . '&username=' . $GLOBALS['user']->username;
$score = '0';
+
/* count up to 6 */
while ($score < 6) {
/* Handle the "Not rated" possibility */
- if ($score == '0' AND $score === $rating->rating) {
+ if ($score == '0' AND $rating->rating == '-1') {
echo "<img src=\"" . conf('web_path') . "/images/ratings/x.gif\" border=\"0\" alt=\"" . get_rating_name($score) . "\">\n";
+ $found_on = true;
}
- elseif ($score == '0') {
- echo "<a href=\"" . $base_url . "&rating=$score\">\n";
- echo "\t<img src=\"" . conf('web_path') . "/images/ratings/x_off.gif\" border=\"0\" alt=\"" . get_rating_name($score) . "\">\n";
- echo "</a>";
+ elseif ($score == '0' AND $rating->rating == '0') {
+ echo "<img src=\"" . conf('web_path') . "/images/ratings/x_off.gif\" border=\"0\" alt=\"" . get_rating_name($score) . "\">\n";
+ $found_on = true;
}
- elseif ($score === $rating->rating) {
+ elseif ($score == $rating->rating) {
echo "<img src=\"" . conf('web_path') . "/images/ratings/star.gif\" border=\"0\" alt=\"" . get_rating_name($score) . "\">\n";
+ $found_on = true;
+ }
+ elseif (!$found_on) {
+ echo "<a href=\"" . $base_url . "&rating=$score\">\n\t<img src=\"" . conf('web_path') . "/images/ratings/star.gif\" border=\"0\" alt=\"" . get_rating_name($score) . "\">\n</a>\n";
}
else {
echo "<a href=\"" . $base_url . "&rating=$score\">\n\t<img src=\"" . conf('web_path') . "/images/ratings/star_off.gif\" border=\"0\" alt=\"" . get_rating_name($score) . "\">\n</a>\n";