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