Browse code

modules/challenges/challenges.php: layout now matches stories.php and is close to series.php

Clarissa Walker authored on 2026/11/15 13:59:02
Showing 1 changed files
... ...
@@ -160,7 +160,7 @@ else if($action == "add" || $action == "edit") {
160 160
 	$challenger = $action == "edit" ? $challenger : USERPENNAME;
161 161
 	$chaluid = $action == "edit" ? $chaluid : USERUID;
162 162
 	$output .= "<form METHOD=\"POST\" name=\"form\" action=\"challenges.php?action=$action".(isset($chalid) ? "&amp;chalid=$chalid" : "")."\">";
163
-	$output .= "<div class=\"tblborder\" style=\"width: 550px; margin: 0 auto; padding: 5px;\">";
163
+	$output .= "<div class=\"tblborder\" style=\"width: 75%; margin: 1em auto; padding: 10px;\">";
164 164
 	$output .= "<label for=\"challenger\">"._NAME.":</label> ";
165 165
 	if(isMEMBER) $output .= $challenger."<input type=\"hidden\" id=\"challenger\" name=\"challenger\" value=\"$challenger\"><input type=\"hidden\" name=\"challengeruid\" value=\"$chaluid\"><br />";
166 166
 	else $output .= "<input  type=\"text\" class=\"textbox=\" name=\"challenger\" maxlength=\"200\" size=\"30\"> <font color=\"red\">*</font><br />";
Browse code

modules/challenges/challenges.php: fix Undefined constant PHP 8.x error message due to the fact that it was missing the language file includes

Clarissa Walker authored on 2026/11/03 14:23:28
Showing 1 changed files
... ...
@@ -24,6 +24,8 @@
24 24
 $current = "challenges";
25 25
 if(isset($_GET['action']) && ($_GET['action'] == "add" || $_GET['action'] == "edit")) $displayform = 1;
26 26
 include ("../../header.php");
27
+if(file_exists(_BASEDIR."modules/challenges/languages/{$language}.php")) require_once (_BASEDIR."modules/challenges/languages/{$language}.php");
28
+else require_once (_BASEDIR."languages/en.php");
27 29
 
28 30
 //make a new TemplatePower object
29 31
 if(file_exists( "$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl" );
Browse code

modules/challenges/challenges.php: convert PHP 7+ only coalescing operator to ternary to support PHP 5+ - was unwittingly introduced in a security patch at some point

Clarissa Walker authored on 2026/11/03 11:51:10
Showing 1 changed files
... ...
@@ -47,7 +47,7 @@ if(isset($_GET['chalid']) && !$chalid) { unset($chalid); $action = false; }
47 47
 			$challenge = dbquery("SELECT uid, catid from ".TABLEPREFIX."fanfiction_challenges WHERE chalid='$chalid' LIMIT 1");
48 48
 			list($chaluid, $catid) = dbrow($challenge);
49 49
 			if(uLEVEL == 3 && $admincats != 0) {
50
-				$seriescats = explode(",", $catid ?? "");
50
+				$seriescats = explode(",", (isset($catid) ? $catid : ""));
51 51
 				$adcats = explode(",", $admincats);
52 52
 				foreach($seriescats as $cat) {
53 53
 					if(in_array($cat, $adcats)) $admin = 1;
... ...
@@ -83,13 +83,13 @@ if($action == "remove") {
83 83
 		if(isset($seriesid)) {
84 84
 			$chalinfo =dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$seriesid'");
85 85
 			list($challenges) = dbrow($chalinfo);
86
-			$challenges = explode(",", $challenges ?? "");
86
+			$challenges = explode(",", (isset($challenges) ? $challenges : ""));
87 87
 			$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET challenges = '".implode(",", array_diff($challenges, array((string)$chalid)))."' WHERE seriesid = '".(int)$seriesid."'");
88 88
 		}
89 89
 		else {
90 90
 			$chalinfo = dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$sid'");
91 91
 			list($challenges) = dbrow($chalinfo);
92
-			$challenges = explode(",", $challenges ?? "");
92
+			$challenges = explode(",", (isset($challenges) ? $challenges : ""));
93 93
 			$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET challenges = '".implode(",", array_diff($challenges, explode(",", $chalid)))."' WHERE sid = '$sid'");
94 94
 		}
95 95
 		if($result && $GLOBALS['dbconnect']->affected_rows > 0) dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET responses = GREATEST(responses - 1, 0) WHERE chalid = '".(int)$chalid."'");
... ...
@@ -105,9 +105,9 @@ else if($action == "add" || $action == "edit") {
105 105
 
106 106
 	$output .= "<div id=\"pagetitle\">".($action == "edit" ? _EDITCHALLENGE : _ADDCHALLENGE)."</div>";
107 107
 	if(isset($_POST['submit'])) {
108
-		$title = escapestring(descript($_POST['title'] ?? '', $allowed_tags));
109
-		$summary = escapestring(replace_naughty(strip_tags(descript($_POST['summary'] ?? ''), $allowed_tags)));
110
-		$challenger = escapestring(strip_tags(descript($_POST['challenger'] ?? ''), $allowed_tags));
108
+		$title = escapestring(descript((isset($_POST['title']) ? $_POST['title'] : ''), $allowed_tags));
109
+		$summary = escapestring(replace_naughty(strip_tags(descript((isset($_POST['summary']) ? $_POST['summary'] : '')), $allowed_tags)));
110
+		$challenger = escapestring(strip_tags(descript((isset($_POST['challenger']) ? $_POST['challenger'] : '')), $allowed_tags));
111 111
 		if(!$challenger) $challenger = _ANONYMOUS;
112 112
 		$challengeruid = isset($_POST['challengeruid']) && isNumber($_POST['challengeruid']) ? $_POST['challengeruid'] : 0;
113 113
 		$catid = isset($_POST['catid']) ? array_filter(is_array($_POST['catid']) ? $_POST['catid'] : explode(",", $_POST['catid']), "isNumber") : array( );
... ...
@@ -297,9 +297,9 @@ else {
297 297
 
298 298
 		$challenge = dbquery("SELECT * FROM  ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1");
299 299
 		list($chalid, $challenger, $uid, $title, $cat, $chars, $summary, $responses) = dbrow($challenge);
300
-		$challenger = stripslashes($challenger ?? "");
301
-		$title = stripslashes($title ?? "");
302
-		$summary= stripslashes($summary ?? "");
300
+		$challenger = stripslashes(isset($challenger) ? $challenger : "");
301
+		$title = stripslashes(isset($title) ? $title : "");
302
+		$summary= stripslashes(isset($summary) ? $summary : "");
303 303
 
304 304
 		$challenges->newBlock("titleblock");
305 305
 		if(isADMIN || USERUID == $uid) $challenges->assign("adminoptions", "<div class=\"adminoptions\">".($admin ? _ADMINOPTIONS : _OPTIONS).": [<a href=\"challenges.php?action=edit&amp;chalid=$chalid\">"._EDIT."</a>] [<a href=\"challenges.php?action=delete&amp;chalid=$chalid\">"._DELETE."</a>]</div>");
... ...
@@ -346,4 +346,4 @@ else {
346 346
 
347 347
 $tpl->assign("output", $output);
348 348
 $tpl->printToScreen( );
349
-?>
350 349
\ No newline at end of file
350
+?>
Browse code

Security patches from upstream - and general cleanup of old hacks

Clarissa Walker authored on 2026/10/31 20:10:45
Showing 1 changed files
... ...
@@ -34,8 +34,8 @@ $tpl->assignInclude( "header", "$skindir/header.tpl" );
34 34
 $tpl->assignInclude( "footer", "$skindir/footer.tpl" );
35 35
 include(_BASEDIR."includes/pagesetup.php");
36 36
 
37
-$chalid = isset($_GET['chalid']) ? $_GET['chalid'] : false;
38
-if($chalid && !isNumber($chalid)) unset($chalid, $action);
37
+$chalid = isset($_GET['chalid']) && is_string($_GET['chalid']) && isNumber($_GET['chalid']) ? (int)$_GET['chalid'] : false;
38
+if(isset($_GET['chalid']) && !$chalid) { unset($chalid); $action = false; }
39 39
 
40 40
 // security check
41 41
 	$admin = 0;
... ...
@@ -47,7 +47,7 @@ if($chalid && !isNumber($chalid)) unset($chalid, $action);
47 47
 			$challenge = dbquery("SELECT uid, catid from ".TABLEPREFIX."fanfiction_challenges WHERE chalid='$chalid' LIMIT 1");
48 48
 			list($chaluid, $catid) = dbrow($challenge);
49 49
 			if(uLEVEL == 3 && $admincats != 0) {
50
-				$seriescats = explode(",", $catid);
50
+				$seriescats = explode(",", $catid ?? "");
51 51
 				$adcats = explode(",", $admincats);
52 52
 				foreach($seriescats as $cat) {
53 53
 					if(in_array($cat, $adcats)) $admin = 1;
... ...
@@ -56,6 +56,21 @@ if($chalid && !isNumber($chalid)) unset($chalid, $action);
56 56
 			if($chaluid != USERUID &&  $admin != 1 && uLEVEL > 2) accessDenied( );
57 57
 		}
58 58
 	}
59
+	// Editing and deleting: only the challenge's owner or an admin. Removing a response:
60
+	// also the author of that story or series. (Before 3.5.78 the check above only
61
+	// covered level-3 admins, so any member could edit, delete or strip any challenge.)
62
+	if(in_array($action, array("edit", "delete", "remove"), true)) {
63
+		if(empty($chalid)) accessDenied( );
64
+		$ef_chal = dbrow(dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '".(int)$chalid."' LIMIT 1"));
65
+		if(!$ef_chal) accessDenied( );
66
+		$ef_ok = $admin || (USERUID && (int)$ef_chal[0] === (int)USERUID);
67
+		if(!$ef_ok && $action == "remove" && USERUID) {
68
+			// same order as the removal below: a series when one is named, otherwise the story
69
+			if(isset($seriesid)) $ef_ok = !empty($seriesid) && (bool)dbrow(dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '".(int)$seriesid."' AND uid = '".(int)USERUID."' LIMIT 1"));
70
+			else if(!empty($sid)) $ef_ok = (bool)dbrow(dbquery("SELECT s.sid FROM ".TABLEPREFIX."fanfiction_stories AS s LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors AS c ON c.sid = s.sid AND c.uid = '".(int)USERUID."' WHERE s.sid = '".(int)$sid."' AND (s.uid = '".(int)USERUID."' OR c.uid IS NOT NULL) LIMIT 1"));
71
+		}
72
+		if(!$ef_ok) accessDenied( );
73
+	}
59 74
 
60 75
 // end security check
61 76
 
... ...
@@ -68,16 +83,16 @@ if($action == "remove") {
68 83
 		if(isset($seriesid)) {
69 84
 			$chalinfo =dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$seriesid'");
70 85
 			list($challenges) = dbrow($chalinfo);
71
-			$challenges = explode(",", $challenges);
72
-			$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET challenges = '".array_diff($challenges, explode(",", $chalid))."' WHERE seriesid = '$seriesid'");
86
+			$challenges = explode(",", $challenges ?? "");
87
+			$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET challenges = '".implode(",", array_diff($challenges, array((string)$chalid)))."' WHERE seriesid = '".(int)$seriesid."'");
73 88
 		}
74 89
 		else {
75 90
 			$chalinfo = dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$sid'");
76 91
 			list($challenges) = dbrow($chalinfo);
77
-			$challenges = explode(",", $challenges);
92
+			$challenges = explode(",", $challenges ?? "");
78 93
 			$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET challenges = '".implode(",", array_diff($challenges, explode(",", $chalid)))."' WHERE sid = '$sid'");
79 94
 		}
80
-		if($result) dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET responses = responses - 1 WHERE chalid = '$chalid'");
95
+		if($result && $GLOBALS['dbconnect']->affected_rows > 0) dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET responses = GREATEST(responses - 1, 0) WHERE chalid = '".(int)$chalid."'");
81 96
 		$output .= write_message(_ACTIONSUCCESSFUL);
82 97
 	}
83 98
 }
... ...
@@ -90,15 +105,15 @@ else if($action == "add" || $action == "edit") {
90 105
 
91 106
 	$output .= "<div id=\"pagetitle\">".($action == "edit" ? _EDITCHALLENGE : _ADDCHALLENGE)."</div>";
92 107
 	if(isset($_POST['submit'])) {
93
-		$title = escapestring(descript($_POST['title'], $allowed_tags));
94
-		$summary = escapestring(replace_naughty(strip_tags(descript($_POST['summary']), $allowed_tags)));
95
-		$challenger = escapestring(strip_tags(descript($_POST['challenger']), $allowed_tags));
108
+		$title = escapestring(descript($_POST['title'] ?? '', $allowed_tags));
109
+		$summary = escapestring(replace_naughty(strip_tags(descript($_POST['summary'] ?? ''), $allowed_tags)));
110
+		$challenger = escapestring(strip_tags(descript($_POST['challenger'] ?? ''), $allowed_tags));
96 111
 		if(!$challenger) $challenger = _ANONYMOUS;
97 112
 		$challengeruid = isset($_POST['challengeruid']) && isNumber($_POST['challengeruid']) ? $_POST['challengeruid'] : 0;
98
-		$catid = isset($_POST['catid']) ? array_filter(explode(",", $_POST['catid']), "isNumber") : array( );
113
+		$catid = isset($_POST['catid']) ? array_filter(is_array($_POST['catid']) ? $_POST['catid'] : explode(",", $_POST['catid']), "isNumber") : array( );
99 114
 		$category = implode(",", $catid);
100 115
 		if(!$category) $category = -1;
101
-		$characters = isset($_POST['charid']) ? array_filter($_POST['charid'], "isNumber") : array( );
116
+		$characters = isset($_POST['charid']) ? array_filter((array)$_POST['charid'], "isNumber") : array( );
102 117
 		$charid = implode(",", $characters);
103 118
 		if(empty($title) || empty($summary)) {
104 119
 			$output .= write_error(_REQUIREDINFO);
... ...
@@ -188,10 +203,13 @@ else if($action == "delete") {
188 203
 			dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid'");
189 204
 			$responses = dbquery("SELECT challenges, sid FROM  ".TABLEPREFIX."fanfiction_stories WHERE FIND_IN_SET($chalid, challenges) > 0");
190 205
 			while($response = dbassoc($responses)) {
191
-				$challenges = explode(",", $response[challenges]);
192
-				if(is_array($challenges)) 
193
-					foreach($challenges as $key=>$value) { if($value == $chalid) unset($challenges[$key]); }
194
-				dbquery("UPDATE  ".TABLEPREFIX."fanfiction_stories SET challenges = '".implode(",", $challenges)."' WHERE sid = $response[sid] LIMIT 1");
206
+				$challenges = array_diff(explode(",", $response['challenges']), array((string)$chalid));
207
+				dbquery("UPDATE  ".TABLEPREFIX."fanfiction_stories SET challenges = '".escapestring(implode(",", $challenges))."' WHERE sid = '".(int)$response['sid']."' LIMIT 1");
208
+			}
209
+			$responses = dbquery("SELECT challenges, seriesid FROM  ".TABLEPREFIX."fanfiction_series WHERE FIND_IN_SET($chalid, challenges) > 0");
210
+			while($response = dbassoc($responses)) {
211
+				$challenges = array_diff(explode(",", $response['challenges']), array((string)$chalid));
212
+				dbquery("UPDATE  ".TABLEPREFIX."fanfiction_series SET challenges = '".escapestring(implode(",", $challenges))."' WHERE seriesid = '".(int)$response['seriesid']."' LIMIT 1");
195 213
 			}
196 214
 			$output .=  write_message(_ACTIONSUCCESSFUL."  <a href=\"challenges.php\">"._BACK2PREVIOUS."</a>");
197 215
 		}
... ...
@@ -279,9 +297,9 @@ else {
279 297
 
280 298
 		$challenge = dbquery("SELECT * FROM  ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1");
281 299
 		list($chalid, $challenger, $uid, $title, $cat, $chars, $summary, $responses) = dbrow($challenge);
282
-		$challenger = stripslashes($challenger);
283
-		$title = stripslashes($title);
284
-		$summary= stripslashes($summary);
300
+		$challenger = stripslashes($challenger ?? "");
301
+		$title = stripslashes($title ?? "");
302
+		$summary= stripslashes($summary ?? "");
285 303
 
286 304
 		$challenges->newBlock("titleblock");
287 305
 		if(isADMIN || USERUID == $uid) $challenges->assign("adminoptions", "<div class=\"adminoptions\">".($admin ? _ADMINOPTIONS : _OPTIONS).": [<a href=\"challenges.php?action=edit&amp;chalid=$chalid\">"._EDIT."</a>] [<a href=\"challenges.php?action=delete&amp;chalid=$chalid\">"._DELETE."</a>]</div>");
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,331 @@
1
+<?php
2
+// ----------------------------------------------------------------------
3
+// Copyright (c) 2007 by Tammy Keefer
4
+// Valid HTML 4.01 Transitional
5
+// Based on eFiction 1.1
6
+// Copyright (C) 2003 by Rebecca Smallwood.
7
+// http://efiction.sourceforge.net/
8
+// ----------------------------------------------------------------------
9
+// LICENSE
10
+//
11
+// This program is free software; you can redistribute it and/or
12
+// modify it under the terms of the GNU General Public License (GPL)
13
+// as published by the Free Software Foundation; either version 2
14
+// of the License, or (at your option) any later version.
15
+//
16
+// This program is distributed in the hope that it will be useful,
17
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+// GNU General Public License for more details.
20
+//
21
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html
22
+// ----------------------------------------------------------------------
23
+
24
+$current = "challenges";
25
+if(isset($_GET['action']) && ($_GET['action'] == "add" || $_GET['action'] == "edit")) $displayform = 1;
26
+include ("../../header.php");
27
+
28
+//make a new TemplatePower object
29
+if(file_exists( "$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl" );
30
+else $tpl = new TemplatePower(_BASEDIR."default_tpls/default.tpl");
31
+if(file_exists("$skindir/listings.tpl")) $tpl->assignInclude( "listings", "$skindir/listings.tpl" );
32
+else $tpl->assignInclude( "listings", _BASEDIR."default_tpls/listings.tpl" );
33
+$tpl->assignInclude( "header", "$skindir/header.tpl" );
34
+$tpl->assignInclude( "footer", "$skindir/footer.tpl" );
35
+include(_BASEDIR."includes/pagesetup.php");
36
+
37
+$chalid = isset($_GET['chalid']) ? $_GET['chalid'] : false;
38
+if($chalid && !isNumber($chalid)) unset($chalid, $action);
39
+
40
+// security check
41
+	$admin = 0;
42
+	if(!isset($anonchallenges)) accessDenied( );
43
+	if(($action && ($action != "add" || !$anonchallenges)) && !isMEMBER) accessDenied( );
44
+	if(isADMIN && uLEVEL < 3) $admin = 1;
45
+	if(isADMIN && uLEVEL == 3) {
46
+		if(isset($chalid)) {
47
+			$challenge = dbquery("SELECT uid, catid from ".TABLEPREFIX."fanfiction_challenges WHERE chalid='$chalid' LIMIT 1");
48
+			list($chaluid, $catid) = dbrow($challenge);
49
+			if(uLEVEL == 3 && $admincats != 0) {
50
+				$seriescats = explode(",", $catid);
51
+				$adcats = explode(",", $admincats);
52
+				foreach($seriescats as $cat) {
53
+					if(in_array($cat, $adcats)) $admin = 1;
54
+				}
55
+			}
56
+			if($chaluid != USERUID &&  $admin != 1 && uLEVEL > 2) accessDenied( );
57
+		}
58
+	}
59
+
60
+// end security check
61
+
62
+if($action == "remove") {
63
+	if(!$chalid || (empty($seriesid) && empty($sid))) {
64
+		$output .= write_error(_ERROR);
65
+	}
66
+	else {
67
+		$output .= "<div id='pagetitle'>"._CHALLENGES."</div>";
68
+		if(isset($seriesid)) {
69
+			$chalinfo =dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$seriesid'");
70
+			list($challenges) = dbrow($chalinfo);
71
+			$challenges = explode(",", $challenges);
72
+			$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET challenges = '".array_diff($challenges, explode(",", $chalid))."' WHERE seriesid = '$seriesid'");
73
+		}
74
+		else {
75
+			$chalinfo = dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$sid'");
76
+			list($challenges) = dbrow($chalinfo);
77
+			$challenges = explode(",", $challenges);
78
+			$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET challenges = '".implode(",", array_diff($challenges, explode(",", $chalid)))."' WHERE sid = '$sid'");
79
+		}
80
+		if($result) dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET responses = responses - 1 WHERE chalid = '$chalid'");
81
+		$output .= write_message(_ACTIONSUCCESSFUL);
82
+	}
83
+}
84
+
85
+else if($action == "add" || $action == "edit") {
86
+
87
+	if(!empty($_GET['cat']) && isNumber($_GET['cat'])) $cat = $_GET["cat"];
88
+	else $cat = -1;
89
+	$catid = isset($_POST['catid']) && isNumber($_POST['catid']) ? $_POST['catid'] : "";
90
+
91
+	$output .= "<div id=\"pagetitle\">".($action == "edit" ? _EDITCHALLENGE : _ADDCHALLENGE)."</div>";
92
+	if(isset($_POST['submit'])) {
93
+		$title = escapestring(descript($_POST['title'], $allowed_tags));
94
+		$summary = escapestring(replace_naughty(strip_tags(descript($_POST['summary']), $allowed_tags)));
95
+		$challenger = escapestring(strip_tags(descript($_POST['challenger']), $allowed_tags));
96
+		if(!$challenger) $challenger = _ANONYMOUS;
97
+		$challengeruid = isset($_POST['challengeruid']) && isNumber($_POST['challengeruid']) ? $_POST['challengeruid'] : 0;
98
+		$catid = isset($_POST['catid']) ? array_filter(explode(",", $_POST['catid']), "isNumber") : array( );
99
+		$category = implode(",", $catid);
100
+		if(!$category) $category = -1;
101
+		$characters = isset($_POST['charid']) ? array_filter($_POST['charid'], "isNumber") : array( );
102
+		$charid = implode(",", $characters);
103
+		if(empty($title) || empty($summary)) {
104
+			$output .= write_error(_REQUIREDINFO);
105
+		}
106
+		else if(find_naughty($title) || find_naughty($challenger)) {
107
+			$output .= write_error(_NAUGHTYWORDS);
108
+		}
109
+		else if(!isMEMBER && $captcha && !captcha_confirm()) {
110
+			$output .= write_error(_CAPTCHAFAIL);
111
+			$tpl->assign("output", $output);
112
+			$tpl->printToScreen( );
113
+			exit( );
114
+		}
115
+		else {
116
+			if($action != "edit") 
117
+				$insert = "INSERT INTO ".TABLEPREFIX."fanfiction_challenges (title, summary, catid, characters, challenger, uid) VALUES('$title', '$summary', '$category', '$charid', '$challenger', '$challengeruid')";
118
+			else 
119
+				$insert = "UPDATE ".TABLEPREFIX."fanfiction_challenges SET title = '$title', summary = '$summary', challenger = '$challenger', catid = '$category', characters = '$charid' WHERE chalid = '$chalid'";
120
+			dbquery($insert);
121
+			$codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'addchallenge'");
122
+			while($code = dbassoc($codequery)) {
123
+				eval($code['code_text']);
124
+			}
125
+			$output .= write_message(_ACTIONSUCCESSFUL."  <a href=\""._BASEDIR."browse.php?type=challenges\">"._BACK2PREVIOUS."</a>");
126
+			$tpl->assign("output", $output);
127
+			$tpl->printToScreen( );
128
+			exit( );
129
+		}		
130
+	}
131
+	if($action == "edit" && $chalid) {
132
+		$challenge = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid='$chalid' LIMIT 1");
133
+		list($chalid, $challenger, $chaluid, $chaltitle, $categories, $characters, $summary) = dbrow($challenge);
134
+		$cat = -1;
135
+		$catid = explode(",", $categories);
136
+		$charids = explode(",", $characters);
137
+	}
138
+	else {
139
+		$chaltitle = "";
140
+		$summary = "";
141
+		$categories = "";
142
+	}
143
+	$challenger = $action == "edit" ? $challenger : USERPENNAME;
144
+	$chaluid = $action == "edit" ? $chaluid : USERUID;
145
+	$output .= "<form METHOD=\"POST\" name=\"form\" action=\"challenges.php?action=$action".(isset($chalid) ? "&amp;chalid=$chalid" : "")."\">";
146
+	$output .= "<div class=\"tblborder\" style=\"width: 550px; margin: 0 auto; padding: 5px;\">";
147
+	$output .= "<label for=\"challenger\">"._NAME.":</label> ";
148
+	if(isMEMBER) $output .= $challenger."<input type=\"hidden\" id=\"challenger\" name=\"challenger\" value=\"$challenger\"><input type=\"hidden\" name=\"challengeruid\" value=\"$chaluid\"><br />";
149
+	else $output .= "<input  type=\"text\" class=\"textbox=\" name=\"challenger\" maxlength=\"200\" size=\"30\"> <font color=\"red\">*</font><br />";
150
+	$output .= "<label for=\"title\">"._TITLE.":</label> <span class=\"required\">*</span> <input  type=\"text\" class=\"textbox=\" name=\"title\" id=\"title\" maxlength=\"200\" value=\"".htmlentities(stripslashes($chaltitle))."\" size=\"50\"><br />
151
+		<label for=\"summary\">"._SUMMARY.":</label> <span class=\"required\">*</span><br /><textarea class=\"textbox\" rows=\"6\" id=\"summary\" name=\"summary\" cols=\"58\">".stripslashes($summary)."</textarea>";
152
+	if($tinyMCE) 
153
+		$output .= "<div class='tinytoggle'><input type='checkbox' name='toggle' onclick=\"toogleEditorMode('summary');\" checked><label for='toggle'>"._TINYMCETOGGLE."</label></div>";
154
+	if(!$multiplecats) $output .= "<input type=\"hidden\" name=\"catid\" id=\"catid\" value=\"1\">";
155
+	else {
156
+		include(_BASEDIR."includes/categories.php");
157
+		$output .= "<input type=\"hidden\" name=\"formname\" value=\"challenges\">";
158
+	}
159
+	$output .= "<label for=\"charid\">"._CHARACTERS.":</label> <br /><select class=\"textbox\" size=\"8\" style=\"width: 100%;\" name=\"charid[]\" id=\"charid\" multiple>";
160
+	foreach($charlist as $char => $info) {
161
+			if($info['catid'] == -1) $output .= "<option value=\"$char\"".(isset($charids) && in_array($char, $charids) ? " selected" : "").">".$info['name']."</option>";
162
+	}		
163
+	$output .= "</select>";
164
+	$codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'challengeform'");
165
+	while($code = dbassoc($codequery)) {
166
+		eval($code['code_text']);
167
+	}
168
+	if(!isMEMBER && $captcha) $output .= "<div><span class=\"label\">"._CAPTCHANOTE."</span><input MAXLENGTH=5 SIZE=5 name=\"userdigit\" type=\"text\" value=\"\"><br /><img width=120 height=30 src=\""._BASEDIR."includes/button.php\" style=\"border: 1px solid #111;\">";
169
+	$output .= "<div style=\"text-align: center; margin: 1em;\"><input type=\"submit\" class=\"button\" name=\"submit\" value=\""._SUBMIT."\"></div></div></form>";
170
+}
171
+
172
+else if($action == "delete") {
173
+
174
+	if($chalid)
175
+	{
176
+
177
+		$confirmed = isset($_GET["confirmed"]) ? $_GET["confirmed"] : false;
178
+	
179
+		$output .= "<div id=\"pagetitle\">"._DELETECHALLENGE."</div>";
180
+		if(!$admin) {
181
+			list($uid) = dbrow(dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1"));
182
+			if(USERUID != $uid) $output .=  write_error(_NOTAUTHORIZED);
183
+		}	
184
+		if($confirmed == "no") {
185
+			$output .= write_message(_ACTIONCANCELLED."  <a href=\""._BASEDIR."browse.php?type=challenges\">"._BACK2PREVIOUS."</a>");
186
+		}
187
+		else if($confirmed == "yes" && $chalid) {
188
+			dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid'");
189
+			$responses = dbquery("SELECT challenges, sid FROM  ".TABLEPREFIX."fanfiction_stories WHERE FIND_IN_SET($chalid, challenges) > 0");
190
+			while($response = dbassoc($responses)) {
191
+				$challenges = explode(",", $response[challenges]);
192
+				if(is_array($challenges)) 
193
+					foreach($challenges as $key=>$value) { if($value == $chalid) unset($challenges[$key]); }
194
+				dbquery("UPDATE  ".TABLEPREFIX."fanfiction_stories SET challenges = '".implode(",", $challenges)."' WHERE sid = $response[sid] LIMIT 1");
195
+			}
196
+			$output .=  write_message(_ACTIONSUCCESSFUL."  <a href=\"challenges.php\">"._BACK2PREVIOUS."</a>");
197
+		}
198
+		else {
199
+			$output .= write_message(_CONFIRMDELETE."<br /><br />[ <a href=\"challenges.php?action=delete&amp;confirmed=yes&amp;chalid=$chalid\">"._YES."</a> | 
200
+				<a href=\"challenges.php?action=delete&amp;confirmed=no\">"._NO."</a> ]");
201
+		}
202
+	}
203
+}
204
+
205
+else if($action == "respond") {
206
+
207
+	if(!isset($chalid)) {
208
+		$output .= write_error(_ERROR);
209
+	}
210
+	if(isset($_POST['submit'])) {
211
+		$count = 0;
212
+		if(isset($_POST["sid"]) && is_array($_POST["sid"])) {
213
+			foreach($_POST["sid"] as $story) {
214
+				if(isNumber($story))
215
+				{
216
+					$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET challenges = CONCAT('$chalid', ',', challenges) WHERE sid = '$story'");
217
+					$count++;
218
+				}
219
+			}
220
+		}
221
+		if(isset($_POST['seriesid']) && is_array($_POST["seriesid"])) {
222
+			foreach($_POST["seriesid"] as $series) {
223
+				if(isNumber($series))
224
+				{
225
+					$result2 = dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET challenges = CONCAT(challenges, ',' '$chalid') WHERE seriesid = '$series'");
226
+					$count++;
227
+				}
228
+			}
229
+		}
230
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET responses = responses + $count WHERE chalid = '$chalid'");
231
+		if($count) $output .= write_message(_ACTIONSUCCESSFUL." <a href='"._BASEDIR."browse.php?type=challenges'>"._BACK2CHALLENGES."</a>");
232
+	}
233
+	else {
234
+		$challenge = dbquery("SELECT title, challenger, uid FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1");
235
+		list($title, $challenger, $challengeruid) = dbrow($challenge);
236
+		$output .= "<div id=\"pagetitle\">$title "._BY." ".($challengeruid ? "<a href=\""._BASEDIR."viewuser.php?uid=$challengeruid\">$challenger</a>" : "$challenger")."</div>";
237
+		$output .= "<form METHOD=\"POST\" name=\"form\" action=\"challenges.php?action=respond&amp;chalid=$chalid\">";
238
+		$output .= "<input type=\"hidden\" name=\"chalid\" value=\"$chalid\">";
239
+		if(($admin) && isset($_GET['stories']) && $_GET['stories'] == "others") {
240
+			if($let == _OTHER) $letter = _PENNAMEFIELD." REGEXP '^[^a-z]'";	
241
+			else if($let) $letter = _PENNAMEFIELD." LIKE '$let%'";
242
+			$pagelink = _BASEDIR."modules/challenges/challenges.php?action=respond&amp;stories=others&amp;chalid=$chalid&amp;".($let ? "let=$let&amp;" : "");
243
+			$authorlink = "<a href=\""._BASEDIR."modules/challenges/challenges.php?action=respond&amp;chalid=$chalid&amp;stories=";
244
+			$countquery = "SELECT count(distinct uid) FROM ".TABLEPREFIX."fanfiction_authorprefs WHERE stories > 0 ".(isset($letter) ? " AND $letter" : "");
245
+			$authorquery = "SELECT ap.stories, "._PENNAMEFIELD." as penname, "._UIDFIELD." as uid FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_authorprefs as ap WHERE ap.uid = author.uid AND ap.stories > 0 ".(isset($letter) ? " AND $letter" : "");
246
+			include(_BASEDIR."includes/members_list.php");
247
+		}
248
+		else {
249
+			$authuid = isset($_GET["stories"]) && isNumber($_GET['stories']) ? $_GET["stories"] : USERUID;
250
+			$stories = dbquery("SELECT stories.title, stories.sid FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (stories.uid = '$authuid' OR coauth.uid = '$authuid')");
251
+
252
+			if($admin) $output .= "<div style=\"text-align: center; margin-bottom: 1em;\"><a href=\"challenges.php?action=respond&amp;stories=others&amp;chalid=$chalid\">"._CHOOSEAUTHOR."</a></div>";
253
+			$output .= "<table class=\"tblborder\" style=\"width: 500px; margin: 0 auto;\"><tr><th class=\"tblborder\">"._STORIES."</th></tr>";
254
+			$numstories = 0;
255
+			while($story = dbassoc($stories)) {
256
+				$output .= "<tr><td class=\"tblborder\"><input type=\"checkbox\" class=\"checkbox\" value=\"$story[sid]\" name=\"sid[]\">".stripslashes($story['title'])."</td></tr>";
257
+				$numstories++;
258
+			}
259
+			if($numstories == 0) $output .= "<tr><td align=\"center\">"._NORESULTS."</td></tr>";
260
+			$series2 = dbquery("SELECT title, seriesid FROM ".TABLEPREFIX."fanfiction_series WHERE uid = '$authuid' AND FIND_IN_SET($chalid, challenges) < 1 ORDER BY title ASC");
261
+			$output .= "<tr><th class=\"tblborder\">"._SERIES."</th></tr>";
262
+			$numseries = 0;
263
+			while($series = dbassoc($series2)) {
264
+				$output .= "<tr><td><input type=\"checkbox\" class=\"checkbox\" value=\"$series[seriesid]\" name=\"seriesid[]\">".stripslashes($series['title'])."</td></tr>";
265
+				$numseries++;
266
+			}
267
+			if($numseries < 1) $output .= "<tr><td align=\"center\">"._NORESULTS."</td></tr>";
268
+			$output .="</table><div style=\"text-align: center; margin: 1em;\"><input type=\"submit\" class=\"button\" name=\"submit\" value=\"submit\"></div></form>";
269
+		}
270
+	}
271
+}
272
+else {
273
+
274
+	$catid = isset($_GET['catid']) ? $_GET['catid'] : false;	
275
+	if($chalid) {
276
+		if(file_exists("./$skindir/challenges_title.tpl")) $challenges = new TemplatePower("./$skindir/challenges_title.tpl");
277
+		else $challenges = new TemplatePower(_BASEDIR."modules/challenges/default_tpls/challenges_title.tpl");
278
+		$challenges->prepare( );
279
+
280
+		$challenge = dbquery("SELECT * FROM  ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1");
281
+		list($chalid, $challenger, $uid, $title, $cat, $chars, $summary, $responses) = dbrow($challenge);
282
+		$challenger = stripslashes($challenger);
283
+		$title = stripslashes($title);
284
+		$summary= stripslashes($summary);
285
+
286
+		$challenges->newBlock("titleblock");
287
+		if(isADMIN || USERUID == $uid) $challenges->assign("adminoptions", "<div class=\"adminoptions\">".($admin ? _ADMINOPTIONS : _OPTIONS).": [<a href=\"challenges.php?action=edit&amp;chalid=$chalid\">"._EDIT."</a>] [<a href=\"challenges.php?action=delete&amp;chalid=$chalid\">"._DELETE."</a>]</div>");
288
+		$challenges->assign("author", ($uid ? "<a href=\""._BASEDIR."viewuser.php?uid=$uid\">$challenger</a>" : "$challenger"));
289
+		$challenges->assign("title", $title);
290
+		$challenges->assign("summary",$summary);
291
+		$challenges->assign("skindir", $skindir);
292
+		$challenges->assign("characters", $chars ? charlist($chars) : _NONE);
293
+		$challenges->assign("category", $cat > 0 ? catlist($cat) : _NONE);
294
+		$challenges->assign("respond", "<div class=\"respond\"><a href=\"challenges.php?action=respond&amp;chalid=$chalid\">"._RESPOND2CHALLENGE."</a></div>");
295
+		$challenges->assign("reportthis", "[<a href=\""._BASEDIR."contact.php?action=report&amp;url=modules/challenges/challenges.php?chalid=".$chalid."\">"._REPORTTHIS."</a>]");
296
+		$output .= $challenges->getOutputContent( );
297
+		$tpl->gotoBlock( "_ROOT" );
298
+		$tpl->newBlock("listings");
299
+		list($scount) = dbrow(dbquery(_SERIESCOUNT." WHERE FIND_IN_SET($chalid, challenges) > 0"));
300
+		$count = 0;
301
+		if($scount > $offset) {
302
+			$seriesquery = dbquery(_SERIESQUERY." AND FIND_IN_SET($chalid, series.challenges) > 0 LIMIT $offset, $itemsperpage");
303
+			while($stories = dbassoc($seriesquery)) {
304
+				include(_BASEDIR."includes/seriesblock.php");
305
+			}
306
+		}
307
+		if($scount - $offset < $itemsperpage) {
308
+			$storyoffset = $offset - $scount > 0 ? $offset - $scount : 0;
309
+			$remainder = $itemsperpage - $count;
310
+			list($scount2) = dbrow(dbquery(_STORYCOUNT." AND FIND_IN_SET($chalid, challenges) > 0"));
311
+			if($scount2 > 0) {
312
+				$storyquery = _STORYQUERY." AND FIND_IN_SET($chalid, stories.challenges) > 0";
313
+				$storyquery .= " LIMIT $offset, $remainder";
314
+				$storyresults = dbquery($storyquery);
315
+				while($stories = dbassoc($storyresults)) {
316
+					$tpl->newBlock("storyblock");
317
+					include(_BASEDIR."includes/storyblock.php"); 
318
+				}
319
+			}
320
+		}
321
+		if($scount + $scount2 > $itemsperpage) {
322
+			$tpl->gotoBlock( "listings" );
323
+			$tpl->assign( "pagelinks", build_pagelinks("challenges.php?chalid=$chalid&amp;", $scount + $scount2, $offset));
324
+		}
325
+		$tpl->gotoBlock( "_ROOT" );
326
+	}
327
+}
328
+
329
+$tpl->assign("output", $output);
330
+$tpl->printToScreen( );
331
+?>
0 332
\ No newline at end of file