Browse code

reviews.php: Number of Likes - let one slip by...

Clarissa Walker authored on 2026/09/12 16:04:53
Showing 1 changed files
... ...
@@ -161,7 +161,7 @@ else if($action == "edit" || $action == "add") {
161 161
 				if($totalcount) $update = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
162 162
 				unset($totalcount);
163 163
 				if($ratings == 3) {
164
-					$count2 = dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
164
+					$count2 = dbquery("SELECT COUNT(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
165 165
 				} else {
166 166
 					$count2 = dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
167 167
 				}
Browse code

reviews.php: fix calculation for Number of Likes rating system for stories and chapters - avg -> count

Clarissa Walker authored on 2026/09/12 14:54:36
Showing 1 changed files
... ...
@@ -71,12 +71,22 @@ if($action == "delete") {
71 71
 				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = (reviews - 1) WHERE sid = '$item'");
72 72
 				dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = (reviews - 1) WHERE chapid = '$chapid'");
73 73
 			}
74
-			$count =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type='ST' AND rating != '-1'");
75
-			list($totalcount) = dbrow($count);
76
-			if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
77
-			$count2 =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
78
-			list($totalcount) = dbrow($count2);
79
-			if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($totalcount)."' WHERE chapid = '$chapid'");
74
+			if($ratings == 3) {
75
+				$count =  dbquery("SELECT COUNT(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type='ST' AND rating != '-1'");
76
+				list($totalcount) = dbrow($count);
77
+				if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
78
+				$count2 =  dbquery("SELECT COUNT(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
79
+				list($totalcount) = dbrow($count2);
80
+				if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($totalcount)."' WHERE chapid = '$chapid'");
81
+				}
82
+			else {
83
+				$count =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type='ST' AND rating != '-1'");
84
+				list($totalcount) = dbrow($count);
85
+				if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
86
+				$count2 =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
87
+				list($totalcount) = dbrow($count2);
88
+				if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($totalcount)."' WHERE chapid = '$chapid'");
89
+			}
80 90
 			$series = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_inseries WHERE sid = '$item'");
81 91
 			if(dbnumrows($series)) {
82 92
 				while($thisseries = dbassoc($series)) {
... ...
@@ -142,11 +152,19 @@ else if($action == "edit" || $action == "add") {
142 152
 			else if($type == "ST") {
143 153
 				if(isset($_POST['chapid']) && isNumber($_POST['chapid'])) $chapid = $_POST['chapid'];
144 154
 				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid, chapid) VALUES ('$item', 'ST', '$reviewer', '$review', '$rating', '" . time() . "', '".(USERUID && isNumber(USERUID) ? USERUID : 0)."', '$chapid')");
145
-				$count =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type = 'ST' AND rating != '-1'");
155
+				if($ratings == 3) {
156
+					$count =  dbquery("SELECT COUNT(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type = 'ST' AND rating != '-1'");
157
+				} else {
158
+					$count =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type = 'ST' AND rating != '-1'");
159
+				}
146 160
 				list($totalcount) = dbrow($count);
147 161
 				if($totalcount) $update = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
148 162
 				unset($totalcount);
149
-				$count2 = dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
163
+				if($ratings == 3) {
164
+					$count2 = dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
165
+				} else {
166
+					$count2 = dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
167
+				}
150 168
 				list($totalcount) = dbrow($count2);
151 169
 				if($totalcount) $update = dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($totalcount)."' WHERE chapid = '$chapid'");
152 170
 				if($review != "No Review") {
Browse code

forgotten date changes

Jimako authored on 2024/06/21 02:05:54
Showing 1 changed files
... ...
@@ -141,7 +141,7 @@ else if($action == "edit" || $action == "add") {
141 141
 			}
142 142
 			else if($type == "ST") {
143 143
 				if(isset($_POST['chapid']) && isNumber($_POST['chapid'])) $chapid = $_POST['chapid'];
144
-				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid, chapid) VALUES ('$item', 'ST', '$reviewer', '$review', '$rating', now(), '".(USERUID && isNumber(USERUID) ? USERUID : 0)."', '$chapid')");
144
+				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid, chapid) VALUES ('$item', 'ST', '$reviewer', '$review', '$rating', '" . time() . "', '".(USERUID && isNumber(USERUID) ? USERUID : 0)."', '$chapid')");
145 145
 				$count =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type = 'ST' AND rating != '-1'");
146 146
 				list($totalcount) = dbrow($count);
147 147
 				if($totalcount) $update = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
... ...
@@ -172,7 +172,7 @@ else if($action == "edit" || $action == "add") {
172 172
 				}
173 173
 			}
174 174
 			else if($type == "SE"){
175
-				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid) VALUES ('$item', 'SE', '$reviewer', '$review', '$rating', now(), '".(USERUID && isNumber(USERUID) ? USERUID : 0)."')");
175
+				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid) VALUES ('$item', 'SE', '$reviewer', '$review', '$rating', '" . time() . "', '".(USERUID && isNumber(USERUID) ? USERUID : 0)."')");
176 176
 				$thisseries = $item;
177 177
 				seriesreview($item);
178 178
 				$uidquery = dbquery("SELECT uid as uid,title FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$item'");
Browse code

version 3.5.7

Jimako authored on 2024/04/08 12:21:57
Showing 1 changed files
... ...
@@ -219,8 +219,8 @@ else if($action == "edit" || $action == "add") {
219 219
 					}
220 220
 				}
221 221
 				$reviewname = $reviewer."(".$_SERVER['REMOTE_ADDR'].")";
222
-				if($action == "add") dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REVIEW, $reviewname, truncate_text($review), $title))."', '0', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
223
-				else dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_EDIT_REVIEW, USERPENNAME, USERUID, $title, $reviewid))."', '0', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
222
+				if($action == "add") dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REVIEW, $reviewname, truncate_text($review), $title)). "', '0', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
223
+				else dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_EDIT_REVIEW, USERPENNAME, USERUID, $title, $reviewid)). "', '0', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
224 224
 			}
225 225
 		}
226 226
 	}
... ...
@@ -418,4 +418,4 @@ else {
418 418
 }
419 419
 $tpl->assign("output", $output);
420 420
 $tpl->printToScreen( );
421
-?>
422 421
\ No newline at end of file
422
+?>
Browse code

3.5.6 efiction version

Jimako authored on 2024/03/09 16:09:42
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,421 @@
1
+<?php
2
+// ----------------------------------------------------------------------
3
+// Copyright (c) 2007 by Tammy Keefer
4
+// Based on eFiction 1.1
5
+// Copyright (C) 2003 by Rebecca Smallwood.
6
+// http://efiction.sourceforge.net/
7
+// ----------------------------------------------------------------------
8
+// LICENSE
9
+//
10
+// This program is free software; you can redistribute it and/or
11
+// modify it under the terms of the GNU General Public License (GPL)
12
+// as published by the Free Software Foundation; either version 2
13
+// of the License, or (at your option) any later version.
14
+//
15
+// This program is distributed in the hope that it will be useful,
16
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+// GNU General Public License for more details.
19
+//
20
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html
21
+// ----------------------------------------------------------------------
22
+
23
+//Begin basic page setup
24
+
25
+$current = "reviews";
26
+include ("header.php");
27
+
28
+//make a new TemplatePower object
29
+if(file_exists("$skindir/reviews.tpl")) $tpl = new TemplatePower( "$skindir/reviews.tpl" );
30
+else $tpl = new TemplatePower("default_tpls/reviews.tpl");
31
+if(file_exists("$skindir/reviewblock.tpl")) $tpl->assignInclude("reviewsblock", "$skindir/reviewblock.tpl" );
32
+else $tpl->assignInclude("reviewsblock", "default_tpls/reviewblock.tpl");
33
+$tpl->assignInclude( "header", "./$skindir/header.tpl" );
34
+$tpl->assignInclude( "footer", "./$skindir/footer.tpl" );
35
+
36
+//let TemplatePower do its thing, parsing etc.
37
+$tpl->prepare();
38
+
39
+include("includes/pagesetup.php");
40
+
41
+$reviewid = isset($_REQUEST['reviewid']) ? $_REQUEST['reviewid'] : false;
42
+if(!isNumber($reviewid)) unset($reviewid);
43
+$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false;
44
+$item = isset($_REQUEST['item']) ? $_REQUEST['item'] : false;
45
+if(!isNumber($item)) unset($item);
46
+
47
+if($action == "delete") {
48
+	if(isADMIN && uLEVEL <= 3) $notauthor = 1;
49
+	$query = dbquery("SELECT item, chapid, type, review, rating, uid FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '$reviewid' LIMIT 1");
50
+	list($item, $chapid, $type, $review, $rating, $reviewuid) = dbrow($query);
51
+	if($reviewuid == USERUID) $notauthor = 1;
52
+	if($type == "SE") $query2 = "SELECT uid FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$item' LIMIT 1";
53
+	if($type == "ST") $query2 = "SELECT uid FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$item' LIMIT 1";
54
+	else {
55
+		$revauthor = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'revauthor'");
56
+		while($code = dbassoc($revauthor)) {
57
+			eval($code['code_text']);
58
+		}
59
+	}
60
+	$authorquery = dbquery($query2);
61
+	list($author) = dbrow($authorquery);
62
+	if($author != USERUID && !$notauthor && ($revdelete < 2 || ($revdelete == 1 && $reviewuid))) accessDenied( );
63
+	$delete = isset($_GET['delete']) ? $_GET['delete'] : false;
64
+	$output .= "<div id=\"pagetitle\">"._DELETEREVIEW."</div>";
65
+	if($delete == "yes") {
66
+		if($type == "ST") {
67
+			$query = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = $item LIMIT 1");
68
+			
69
+			list($author) = dbrow($query);
70
+			if($review != "No Review") {
71
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = (reviews - 1) WHERE sid = '$item'");
72
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = (reviews - 1) WHERE chapid = '$chapid'");
73
+			}
74
+			$count =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type='ST' AND rating != '-1'");
75
+			list($totalcount) = dbrow($count);
76
+			if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
77
+			$count2 =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
78
+			list($totalcount) = dbrow($count2);
79
+			if($totalcount) dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($totalcount)."' WHERE chapid = '$chapid'");
80
+			$series = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_inseries WHERE sid = '$item'");
81
+			if(dbnumrows($series)) {
82
+				while($thisseries = dbassoc($series)) {
83
+					seriesreview($thisseries);
84
+				}
85
+			}
86
+		}
87
+		if($type == "SE") {
88
+			if($review != "No Review") dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET reviews = (reviews - 1) WHERE seriesid = '$item'");
89
+			seriesreview($item);
90
+		}
91
+		else {
92
+			$revdelete = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'revdelete'");
93
+			while($code = dbassoc($revdelete)) {
94
+				eval($code['code_text']);
95
+			}
96
+		}
97
+		if($review != "No Review") {
98
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET reviews = reviews - 1");
99
+			list($count) = dbrow(dbquery("SELECT COUNT(DISTINCT uid) FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review' AND uid != 0"));
100
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET reviewers = '$count'");
101
+		}
102
+		dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '$reviewid'");
103
+		
104
+		$output .= write_message(_ACTIONSUCCESSFUL.(isset($back) ? $back : ""));
105
+	}
106
+	else if ($delete == "no") {
107
+		$output .= write_message(_ACTIONCANCELLED);
108
+	}
109
+	else {
110
+		$output .= write_message(_CONFIRMDELETE."<BR><BR>
111
+			[ <a href=\"reviews.php?action=delete&amp;delete=yes&amp;reviewid=$reviewid\">"._YES."</a> | <a href=\"reviews.php?action=delete&amp;delete=no&amp;reviewid=$reviewid\">"._NO."</a> ]");
112
+	}
113
+}
114
+else if($action == "edit" || $action == "add") {
115
+	if(isset($_GET['next']) && isNumber($_GET['next'])) $nextchapter = $_GET['next'];
116
+	if(!isMEMBER && !$anonreviews) accessDenied( );
117
+	if(!isset($chapid) && $type == "ST") { 
118
+		$chapquery = dbquery("SELECT chapid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '$item' AND inorder = '1' LIMIT 1");
119
+		list($chapid) = dbrow($chapquery);
120
+	}
121
+	$tpl->assign("pagetitle", "<div id =\"pagetitle\">"._REVIEW."</div>");
122
+	if(isset($_POST['submit'])) {
123
+		$reviewer = isset($_POST['reviewer']) ? escapestring(descript(strip_tags($_POST['reviewer'], $allowed_tags))) : "";
124
+		$review = format_story(strip_tags(descript($_POST['review']), $allowed_tags));
125
+		$review = escapestring($review);
126
+		$rating = isset($_POST['rating']) && isNumber($_POST['rating']) ? $_POST['rating'] : -1;
127
+		if(!$review) $review = "No Review";
128
+		if(!$reviewer && $action != "edit") $reviewer = _ANONYMOUS;
129
+		if(isMEMBER) $reviewer = USERPENNAME;
130
+		if(!$rateonly && $review == "No Review") $output .= write_error(_MISSINGINFO2);
131
+		else if($captcha && !isMEMBER && !captcha_confirm()) $output .= write_error(_CAPTCHAFAIL);
132
+		else if($review == "No Review" && $_POST['rating'] == "-1") $output .= write_error(_MISSINGINFO);
133
+		else if(find_naughty($reviewer)) $output .= write_error(_NAUGHTYWORDS);
134
+		else if($action == "add" && (!$type || !$item)) $output .= write_error(_ERROR);
135
+		else {
136
+			$output .= write_message(_REVTHANKYOU);
137
+			if($action == "edit") {
138
+				$update = dbquery("UPDATE ".TABLEPREFIX."fanfiction_reviews SET review = '$review', rating = '$rating' WHERE reviewid = '$reviewid' LIMIT 1");
139
+				$info = dbquery("SELECT item, type, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '$reviewid' LIMIT 1");
140
+				list($item, $type, $chapid) = dbrow($info);
141
+			}
142
+			else if($type == "ST") {
143
+				if(isset($_POST['chapid']) && isNumber($_POST['chapid'])) $chapid = $_POST['chapid'];
144
+				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid, chapid) VALUES ('$item', 'ST', '$reviewer', '$review', '$rating', now(), '".(USERUID && isNumber(USERUID) ? USERUID : 0)."', '$chapid')");
145
+				$count =  dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type = 'ST' AND rating != '-1'");
146
+				list($totalcount) = dbrow($count);
147
+				if($totalcount) $update = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($totalcount)."' WHERE sid = '$item'");
148
+				unset($totalcount);
149
+				$count2 = dbquery("SELECT AVG(rating) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE chapid = '$chapid' AND rating != '-1'");
150
+				list($totalcount) = dbrow($count2);
151
+				if($totalcount) $update = dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($totalcount)."' WHERE chapid = '$chapid'");
152
+				if($review != "No Review") {
153
+					dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = (reviews + 1) WHERE sid = '$item'");
154
+					dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = (reviews + 1) WHERE chapid = '$chapid'");
155
+				}
156
+				$series = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_inseries WHERE sid = '$item'");
157
+				if(dbnumrows($series)) {
158
+					while($s = dbassoc($series)) {
159
+						seriesreview($s['seriesid']);
160
+					}
161
+				}
162
+				$output .= write_message("<a href=\"viewstory.php?sid=$item".(isset($_GET['next']) ? "&amp;chapter=".$_GET['next'] : "")."\">"._BACKTOSTORY."</a></center>");
163
+
164
+				$uidquery = dbquery("SELECT uid,title, coauthors FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$item'");
165
+				list($author, $title, $coauthors) = dbrow($uidquery);
166
+				if($coauthors) {
167
+					$array_coauthors = array( );
168
+					$coQuery = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$item'");
169
+					while($c = dbassoc($coQuery)) {
170
+						$array_coauthors[] = $c['uid'];
171
+					}
172
+				}
173
+			}
174
+			else if($type == "SE"){
175
+				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid) VALUES ('$item', 'SE', '$reviewer', '$review', '$rating', now(), '".(USERUID && isNumber(USERUID) ? USERUID : 0)."')");
176
+				$thisseries = $item;
177
+				seriesreview($item);
178
+				$uidquery = dbquery("SELECT uid as uid,title FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$item'");
179
+				list($author, $title) = dbrow($uidquery);
180
+
181
+			}
182
+			else {
183
+				$revadd = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'revadd'");
184
+				while($code = dbassoc($revadd)) {
185
+					eval($code['code_text']);
186
+				}
187
+			}
188
+			if($review != "No Review" && $action == "add") {
189
+				$mailquery= dbquery("SELECT ap.newreviews,"._EMAILFIELD." as email, "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." LEFT JOIN ".TABLEPREFIX."fanfiction_authorprefs as ap ON ap.uid = "._UIDFIELD." WHERE "._UIDFIELD." = '$author' ".(!empty($coauthors) ? " OR ".findclause(_UIDFIELD, $array_coauthors) : ""));
190
+				while($mail = dbassoc($mailquery)) {
191
+					if($mail['newreviews']) {
192
+						include_once("includes/emailer.php");
193
+						$subject = _REVEMAIL1.$title;
194
+						$mailtext = sprintf(_REVEMAIL2, "type=$type&amp;item=$item");
195
+						$result = sendemail($mail['penname'], $mail['email'], $sitename, $siteemail, $subject, $mailtext, "html");
196
+					}
197
+				}
198
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET reviews = reviews + 1");
199
+				list($count) = dbrow(dbquery("SELECT COUNT(DISTINCT uid) FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review' AND uid != 0"));
200
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET reviewers = '$count'");
201
+			}
202
+			if($logging && !USERUID) {
203
+				if($type == "ST") {
204
+					$storyquery = dbquery("SELECT s.title, s.uid, s.rid, s.sid FROM ".TABLEPREFIX."fanfiction_stories as s WHERE s.sid = '$item' LIMIT 1");
205
+					$story = dbassoc($storyquery);
206
+					$title = "<a href=\"viewstory.php?sid=$item\">".stripslashes($story['title'])."</a>";
207
+					$authoruid = $story['uid'];
208
+				}
209
+				else if($type == "SE") {
210
+					$storyquery = dbquery("SELECT title, uid FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$item' LIMIT 1");
211
+					list($title, $authoruid) = dbrow($storyquery);
212
+					$titletext = $title;
213
+					$title = "<a href=\"viewseries.php?seriesid=$item\">".stripslashes($title)."</a>";	
214
+				}
215
+				else { 
216
+					$titlequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'revtitle'");
217
+					while($code = dbassoc($titlequery)) {
218
+						eval($code['code_text']);
219
+					}
220
+				}
221
+				$reviewname = $reviewer."(".$_SERVER['REMOTE_ADDR'].")";
222
+				if($action == "add") dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REVIEW, $reviewname, truncate_text($review), $title))."', '0', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
223
+				else dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_EDIT_REVIEW, USERPENNAME, USERUID, $title, $reviewid))."', '0', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
224
+			}
225
+		}
226
+	}
227
+	else {
228
+		if(!$anonreviews && !USERPENNAME) accessDenied( );
229
+		else {
230
+			if($action == "edit") {
231
+				$result = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '$reviewid' LIMIT 1");
232
+				$review = dbassoc($result);
233
+			}
234
+			include("includes/reviewform.php");
235
+			$output .= $form;
236
+		}
237
+	}
238
+}
239
+else {
240
+	$query = "";
241
+	if(empty($reviewid) && empty($type)) accessDenied( );
242
+	if(!empty($reviewid) && empty($type)) {
243
+		list($type, $item) = dbrow(dbquery("SELECT type, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '$reviewid' LIMIT 1"));
244
+	}
245
+	if($type == "ST") {
246
+		$storyquery = dbquery("SELECT s.title, s.uid, s.rid, s.sid, s.coauthors FROM ".TABLEPREFIX."fanfiction_stories as s WHERE s.sid = '$item' LIMIT 1");
247
+		$story = dbassoc($storyquery);
248
+		$title = title_link($story);
249
+		$authoruid = $story['uid'];
250
+		$array_coauthors = array();
251
+		if(!empty($story['coauthors'])) {
252
+			$colist = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$item'");
253
+			while($c = dbassoc($colist)) {
254
+				$array_coauthors[] = $c['uid'];
255
+			}
256
+		}
257
+	}
258
+	else if($type == "SE") {
259
+		$storyquery = dbquery("SELECT title, uid FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$item' LIMIT 1");
260
+		list($title, $authoruid) = dbrow($storyquery);
261
+		$titletext = $title;
262
+		$title = "<a href=\"series.php?seriesid=$item\">".stripslashes($title)."</a>";
263
+	}
264
+	else { 
265
+		$titlequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'revtitle'");
266
+		while($code = dbassoc($titlequery)) {
267
+			eval($code['code_text']);
268
+		}
269
+	}
270
+	$tpl->assign("pagetitle", "<div id=\"pagetitle\">"._REVIEWSFOR." $title</div>");
271
+	if($type == "SE") {
272
+		$jumpmenu = "";
273
+		$stinseries = dbquery("SELECT sid, subseriesid, inorder FROM ".TABLEPREFIX."fanfiction_inseries WHERE seriesid = '$item'");
274
+		$scount = dbnumrows($stinseries);
275
+		if($scount) {
276
+			$subs = array( );
277
+			$stories = array( );
278
+			while($i = dbassoc($stinseries)) {
279
+				if($i['subseriesid']) {
280
+					$subs[$i['inorder']] = $i['subseriesid'];
281
+					$serieslist[] = $i['subseriesid'];
282
+				}
283
+				else {
284
+					$stories[$i['inorder']] = $i['sid'];
285
+					$storieslist[] = $i['sid'];
286
+				}
287
+			}
288
+			if(count($subs) > 0) {
289
+				$subsquery = dbquery(_SERIESQUERY." AND FIND_IN_SET(seriesid, '".implode(",", $subs)."') > 0");
290
+				while($sub = dbassoc($subsquery)) {
291
+					$inlist[array_search($sub['seriesid'], $subs)] = $sub;
292
+				}
293
+			}
294
+			if(count($stories)) {
295
+				$seriesstoryquery = dbquery(_STORYQUERY." AND FIND_IN_SET(sid, '".implode(",", $stories)."') > 0");
296
+				while($story = dbassoc($seriesstoryquery)) {
297
+					$inlist[array_search($story['sid'], $stories)] = $story;
298
+				}
299
+			}
300
+			if(is_array($inlist)) ksort($inlist);
301
+			$jumpmenu = "<form name=\"jump\" action=\"\">";
302
+			$jumpmenu .= "<select name=\"sid\" onChange=\"if (this.selectedIndex >0) window.location=this.options[this.selectedIndex].value\">";
303
+			$jumpmenu .= "<option value=\"reviews.php?type=SE&amp;item=$item\">"._VIEWALLREVIEWS."</option>";
304
+			foreach($inlist as $x => $st) {
305
+				$jumpmenu .= "<option value=\"reviews.php?type=".(isset($st['sid']) ? "ST&amp;item=".$st['sid'] : "SE&amp;item=".$st['seriesid'])."\">"._REVIEWSFOR." ".$st['title']."</option>";
306
+				if(!empty($st['sid'])) $storylist[] = $st['sid'];
307
+				else if(!empty($st['subseriesid'])) $serieslist[] = $st['subseriesid'];
308
+			}
309
+			$jumpmenu .= "</select></form>";
310
+		}
311
+		$tpl->assign("jumpmenu", $jumpmenu );
312
+		$query = "SELECT review.reviewid, review.respond, review.review, review.uid, review.reviewer, review.rating, review.date as date, series.title as seriestitle, stories.title as title FROM ".TABLEPREFIX."fanfiction_reviews as review LEFT JOIN ".TABLEPREFIX."fanfiction_series as series ON review.item = series.seriesid AND review.type = 'SE' LEFT JOIN ".TABLEPREFIX."fanfiction_stories as stories ON stories.sid = review.item AND review.type ='ST' WHERE 
313
+			((series.seriesid = '$item' AND series.seriesid = review.item AND review.type = 'SE')".
314
+			(isset($storylist) ? " OR (FIND_IN_SET(review.item, '".(implode(",", $storieslist))."') > 0 AND review.type = 'ST')" : "").
315
+			(isset($serieslist) ? " OR (FIND_IN_SET(item, '".(implode(",", $serieslist))."') > 0 AND type = 'SE')" : "").
316
+			") AND review.review != 'No Review'";
317
+		$count =  "SELECT count(reviewid) FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND type = 'SE' AND review != 'No Review'";
318
+
319
+	}
320
+	else if($type == "ST") {
321
+		if(isset($chapid))  {
322
+			$query = "SELECT review.reviewid, review.respond, review.review, review.uid, review.reviewer, review.rating, date as date, chapter.title as title, chapter.inorder as inorder FROM ".TABLEPREFIX."fanfiction_reviews as review, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.chapid = '$chapid' AND chapter.chapid = review.chapid AND review.review != 'No Review' ";
323
+			$count =  "SELECT count(reviewid) FROM ".TABLEPREFIX."fanfiction_reviews as review WHERE chapid = '$chapid' AND review != 'No Review'";
324
+		}
325
+		else  {
326
+			$query = "SELECT review.reviewid, review.respond, review.review, review.uid, review.reviewer, review.rating, review.date as date, chapter.title as title, chapter.inorder as inorder FROM ".TABLEPREFIX."fanfiction_reviews as review, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.sid = '$item' AND chapter.chapid = review.chapid AND review.review != 'No Review' AND review.type = 'ST'";
327
+			$count = "SELECT count(reviewid) FROM ".TABLEPREFIX."fanfiction_reviews as review WHERE item = '$item' AND review != 'No Review' AND type = 'ST'";
328
+		}
329
+		$jumpmenu = "<form name=\"jump\" action=\"\">";
330
+		$jumpmenu .= "<select name=\"sid\" onChange=\"window.location=this.options[this.selectedIndex].value\">";
331
+		$jumpmenu .= "<option value=\"reviews.php?type=ST&amp;item=".$story['sid'].(isset($_GET['unresponded']) ? "&amp;unresponded=1" : "")."\"";
332
+		if(!isset($chapid))
333
+			$jumpmenu .= " selected";
334
+		$jumpmenu .= ">"._VIEWALLREVIEWS."</option>";
335
+		$chapquery = dbquery("SELECT inorder, title, chapid, sid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".$story['sid']."' ORDER BY inorder ASC");
336
+		while($chapters = dbassoc($chapquery)) {
337
+			$jumpmenu .= "<option value=\"reviews.php?chapid=".$chapters['chapid'].(isset($_GET['unresponded']) ? "&amp;unresponded=1" : "")."&amp;type=ST&amp;item=$item\"";
338
+	
339
+			if(isset($chapid) && $chapid == $chapters['chapid'])
340
+				$jumpmenu .= " selected";
341
+
342
+			$jumpmenu .= ">"._REVIEWSFOR." ".$chapters['inorder'].". ".$chapters['title']."</option>\n";
343
+		}
344
+		$jumpmenu .= "</select></form>";
345
+
346
+		$tpl->assign("jumpmenu", $jumpmenu );
347
+	}
348
+	else {
349
+		$reviewquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'revqueries'");
350
+		while($code = dbassoc($reviewquery)) {
351
+			eval($code['code_text']);
352
+		}
353
+	}
354
+	if(isset($_GET['unresponded'])) {
355
+		$query .= "AND review.respond = '0' ";
356
+		$count .= "AND review.respond = '0' ";
357
+	}
358
+	if(!empty($reviewid)) {
359
+		$query .= " AND review.reviewid = '$reviewid' ";
360
+		$count .= " AND review.reviewid = '$reviewid' ";
361
+	}
362
+	$query .= "ORDER BY review.reviewid DESC LIMIT $offset,$itemsperpage";
363
+	$query = dbquery($query);
364
+	$count = dbquery($count);
365
+
366
+	list($numrows)= dbrow($count);
367
+	$counter = 0;
368
+	while($reviews = dbassoc($query))
369
+	{
370
+		$adminlink = "";
371
+		if(isADMIN && uLEVEL < 4) $adminlink = "<span class='label'>"._ADMINOPTIONS.": </span> [<a href=\"reviews.php?action=edit&amp;reviewid=".$reviews['reviewid']."\">"._EDIT."</a>]";
372
+		if( (isADMIN && uLEVEL < 4) || (USERUID && USERUID == $reviews['uid'])) $adminlink .= " [<a href=\"reviews.php?action=delete&amp;reviewid=".$reviews['reviewid']."\">"._DELETE."</a>]";
373
+		if($reviews['uid']) {
374
+			if(USERUID == $authoruid && $revdelete == 2 && !isADMIN) $adminlink .= " [<a href=\"reviews.php?action=delete&amp;reviewid=".$reviews['reviewid']."\">"._DELETE."</a>]";
375
+			$reviewer = "<a href=\"viewuser.php?uid=".$reviews['uid']."\">".$reviews['reviewer']."</a>";
376
+			$member = _SIGNED;
377
+		}
378
+		else {
379
+			if(USERUID == $authoruid && $revdelete && !isADMIN) $adminlink .= " [<a href=\"reviews.php?action=delete&amp;reviewid=".$reviews['reviewid']."\">"._DELETE."</a>]";
380
+			$reviewer = $reviews['reviewer'];
381
+			$member = _ANONYMOUS;
382
+		}
383
+		if(empty($reviews['respond']) && (USERUID == $authoruid || (isset($array_coauthors) && in_array(USERUID, $array_coauthors)))) $adminlink .= " [<a href=\"user.php?action=revres&amp;reviewid=".$reviews['reviewid']."\">"._RESPOND."</a>]";
384
+		$tpl->newBlock("reviewsblock");
385
+		$tpl->assign("reviewer"   , $reviewer );
386
+		$tpl->assign("reportthis", "[<a href=\""._BASEDIR."contact.php?action=report&amp;url=reviews.php?reviewid=".$reviews['reviewid']."\">"._REPORTTHIS."</a>]");
387
+		$tpl->assign("review"   , stripslashes($reviews['review']));
388
+		$tpl->assign("reviewdate", date("$dateformat $timeformat", $reviews['date']) );
389
+		$tpl->assign("rating", ratingpics($reviews['rating']) );
390
+		$tpl->assign("member", $member );
391
+		$tpl->assign("chapter", (!empty($reviews['title']) ? stripslashes($reviews['title']) : (!empty($reviews['seriestitle']) ? stripslashes($reviews['seriestitle']) : _NONE)) );
392
+		if(isset($reviews['inorder'])) $tpl->assign("chapternumber", $reviews['inorder'] );
393
+		if(!empty($adminlink)) $tpl->assign("adminoptions", "<div class=\"adminoptions\">$adminlink</div>");
394
+		$tpl->assign("oddeven", ($counter % 2 ? "odd" : "even"));
395
+		$counter++;
396
+	}
397
+	$tpl->gotoBlock( "_ROOT" );
398
+
399
+	if ($numrows > $itemsperpage) 
400
+		$tpl->assign("reviewpagelinks", build_pagelinks("reviews.php?type=$type&amp;item=$item&amp;".(!empty($chapid) ? "chapid=$chapid&amp;" : "").(isset($_GET['unresponded']) ? "unresponded=1&amp;" : ""), $numrows, $offset));
401
+	else if($numrows == 0) $tpl->assign("reviewpagelinks", write_message(_NORESULTS));
402
+	if(isMEMBER || $anonreviews)
403
+		$reviewslink = "<a href=\"reviews.php?action=add&amp;type=$type&amp;item=$item".(isset($chapid) ? "&amp;chapid=".$chapid : "")."\">"._SUBMITREVIEW."</a>";
404
+	else
405
+		$reviewslink = write_message(sprintf(_LOGINTOREVIEW, strtolower($pagelinks['login']['link']), strtolower($pagelinks['register']['link'])));
406
+	$tpl->assign("reviewslink", $reviewslink);
407
+	$form = "";
408
+	if($reviewsallowed) {
409
+		if(isMEMBER || $anonreviews) {
410
+			$item = $item;
411
+			$type = $type;
412
+			include("includes/reviewform.php");
413
+		}
414
+		else $form = write_message(sprintf(_LOGINTOREVIEW, strtolower($pagelinks['login']['link']), strtolower($pagelinks['register']['link'])));
415
+	}
416
+	$tpl->assign("reviewform", $form);
417
+
418
+}
419
+$tpl->assign("output", $output);
420
+$tpl->printToScreen( );
421
+?>
0 422
\ No newline at end of file