assignInclude( "listings", "$skindir/listings.tpl" ); else $tpl->assignInclude( "listings", _BASEDIR."default_tpls/listings.tpl" ); $tpl->assignInclude( "header", "$skindir/header.tpl" ); $tpl->assignInclude( "footer", "$skindir/footer.tpl" ); include(_BASEDIR."includes/pagesetup.php"); $chalid = isset($_GET['chalid']) ? $_GET['chalid'] : false; if($chalid && !isNumber($chalid)) unset($chalid, $action); // security check $admin = 0; if(!isset($anonchallenges)) accessDenied( ); if(($action && ($action != "add" || !$anonchallenges)) && !isMEMBER) accessDenied( ); if(isADMIN && uLEVEL < 3) $admin = 1; if(isADMIN && uLEVEL == 3) { if(isset($chalid)) { $challenge = dbquery("SELECT uid, catid from ".TABLEPREFIX."fanfiction_challenges WHERE chalid='$chalid' LIMIT 1"); list($chaluid, $catid) = dbrow($challenge); if(uLEVEL == 3 && $admincats != 0) { $seriescats = explode(",", $catid); $adcats = explode(",", $admincats); foreach($seriescats as $cat) { if(in_array($cat, $adcats)) $admin = 1; } } if($chaluid != USERUID && $admin != 1 && uLEVEL > 2) accessDenied( ); } } // end security check if($action == "remove") { if(!$chalid || (empty($seriesid) && empty($sid))) { $output .= write_error(_ERROR); } else { $output .= "
"._CHALLENGES."
"; if(isset($seriesid)) { $chalinfo =dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$seriesid'"); list($challenges) = dbrow($chalinfo); $challenges = explode(",", $challenges); $result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET challenges = '".array_diff($challenges, explode(",", $chalid))."' WHERE seriesid = '$seriesid'"); } else { $chalinfo = dbquery("SELECT challenges FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$sid'"); list($challenges) = dbrow($chalinfo); $challenges = explode(",", $challenges); $result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET challenges = '".implode(",", array_diff($challenges, explode(",", $chalid)))."' WHERE sid = '$sid'"); } if($result) dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET responses = responses - 1 WHERE chalid = '$chalid'"); $output .= write_message(_ACTIONSUCCESSFUL); } } else if($action == "add" || $action == "edit") { if(!empty($_GET['cat']) && isNumber($_GET['cat'])) $cat = $_GET["cat"]; else $cat = -1; $catid = isset($_POST['catid']) && isNumber($_POST['catid']) ? $_POST['catid'] : ""; $output .= "
".($action == "edit" ? _EDITCHALLENGE : _ADDCHALLENGE)."
"; if(isset($_POST['submit'])) { $title = escapestring(descript($_POST['title'], $allowed_tags)); $summary = escapestring(replace_naughty(strip_tags(descript($_POST['summary']), $allowed_tags))); $challenger = escapestring(strip_tags(descript($_POST['challenger']), $allowed_tags)); if(!$challenger) $challenger = _ANONYMOUS; $challengeruid = isset($_POST['challengeruid']) && isNumber($_POST['challengeruid']) ? $_POST['challengeruid'] : 0; $catid = isset($_POST['catid']) ? array_filter(explode(",", $_POST['catid']), "isNumber") : array( ); $category = implode(",", $catid); if(!$category) $category = -1; $characters = isset($_POST['charid']) ? array_filter($_POST['charid'], "isNumber") : array( ); $charid = implode(",", $characters); if(empty($title) || empty($summary)) { $output .= write_error(_REQUIREDINFO); } else if(find_naughty($title) || find_naughty($challenger)) { $output .= write_error(_NAUGHTYWORDS); } else if(!isMEMBER && $captcha && !captcha_confirm()) { $output .= write_error(_CAPTCHAFAIL); $tpl->assign("output", $output); $tpl->printToScreen( ); exit( ); } else { if($action != "edit") $insert = "INSERT INTO ".TABLEPREFIX."fanfiction_challenges (title, summary, catid, characters, challenger, uid) VALUES('$title', '$summary', '$category', '$charid', '$challenger', '$challengeruid')"; else $insert = "UPDATE ".TABLEPREFIX."fanfiction_challenges SET title = '$title', summary = '$summary', challenger = '$challenger', catid = '$category', characters = '$charid' WHERE chalid = '$chalid'"; dbquery($insert); $codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'addchallenge'"); while($code = dbassoc($codequery)) { eval($code['code_text']); } $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2PREVIOUS.""); $tpl->assign("output", $output); $tpl->printToScreen( ); exit( ); } } if($action == "edit" && $chalid) { $challenge = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid='$chalid' LIMIT 1"); list($chalid, $challenger, $chaluid, $chaltitle, $categories, $characters, $summary) = dbrow($challenge); $cat = -1; $catid = explode(",", $categories); $charids = explode(",", $characters); } else { $chaltitle = ""; $summary = ""; $categories = ""; } $challenger = $action == "edit" ? $challenger : USERPENNAME; $chaluid = $action == "edit" ? $chaluid : USERUID; $output .= "
"; $output .= "
"; $output .= " "; if(isMEMBER) $output .= $challenger."
"; else $output .= " *
"; $output .= " *
*
"; if($tinyMCE) $output .= "
"; if(!$multiplecats) $output .= ""; else { include(_BASEDIR."includes/categories.php"); $output .= ""; } $output .= "
"; $codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'challengeform'"); while($code = dbassoc($codequery)) { eval($code['code_text']); } if(!isMEMBER && $captcha) $output .= "
"._CAPTCHANOTE."
"; $output .= "
"; } else if($action == "delete") { if($chalid) { $confirmed = isset($_GET["confirmed"]) ? $_GET["confirmed"] : false; $output .= "
"._DELETECHALLENGE."
"; if(!$admin) { list($uid) = dbrow(dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1")); if(USERUID != $uid) $output .= write_error(_NOTAUTHORIZED); } if($confirmed == "no") { $output .= write_message(_ACTIONCANCELLED." "._BACK2PREVIOUS.""); } else if($confirmed == "yes" && $chalid) { dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid'"); $responses = dbquery("SELECT challenges, sid FROM ".TABLEPREFIX."fanfiction_stories WHERE FIND_IN_SET($chalid, challenges) > 0"); while($response = dbassoc($responses)) { $challenges = explode(",", $response[challenges]); if(is_array($challenges)) foreach($challenges as $key=>$value) { if($value == $chalid) unset($challenges[$key]); } dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET challenges = '".implode(",", $challenges)."' WHERE sid = $response[sid] LIMIT 1"); } $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2PREVIOUS.""); } else { $output .= write_message(_CONFIRMDELETE."

[ "._YES." | "._NO." ]"); } } } else if($action == "respond") { if(!isset($chalid)) { $output .= write_error(_ERROR); } if(isset($_POST['submit'])) { $count = 0; if(isset($_POST["sid"]) && is_array($_POST["sid"])) { foreach($_POST["sid"] as $story) { if(isNumber($story)) { $result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET challenges = CONCAT('$chalid', ',', challenges) WHERE sid = '$story'"); $count++; } } } if(isset($_POST['seriesid']) && is_array($_POST["seriesid"])) { foreach($_POST["seriesid"] as $series) { if(isNumber($series)) { $result2 = dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET challenges = CONCAT(challenges, ',' '$chalid') WHERE seriesid = '$series'"); $count++; } } } dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET responses = responses + $count WHERE chalid = '$chalid'"); if($count) $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2CHALLENGES.""); } else { $challenge = dbquery("SELECT title, challenger, uid FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1"); list($title, $challenger, $challengeruid) = dbrow($challenge); $output .= "
$title "._BY." ".($challengeruid ? "$challenger" : "$challenger")."
"; $output .= "
"; $output .= ""; if(($admin) && isset($_GET['stories']) && $_GET['stories'] == "others") { if($let == _OTHER) $letter = _PENNAMEFIELD." REGEXP '^[^a-z]'"; else if($let) $letter = _PENNAMEFIELD." LIKE '$let%'"; $pagelink = _BASEDIR."modules/challenges/challenges.php?action=respond&stories=others&chalid=$chalid&".($let ? "let=$let&" : ""); $authorlink = " 0 ".(isset($letter) ? " AND $letter" : ""); $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" : ""); include(_BASEDIR."includes/members_list.php"); } else { $authuid = isset($_GET["stories"]) && isNumber($_GET['stories']) ? $_GET["stories"] : USERUID; $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')"); if($admin) $output .= "
"._CHOOSEAUTHOR."
"; $output .= ""; $numstories = 0; while($story = dbassoc($stories)) { $output .= ""; $numstories++; } if($numstories == 0) $output .= ""; $series2 = dbquery("SELECT title, seriesid FROM ".TABLEPREFIX."fanfiction_series WHERE uid = '$authuid' AND FIND_IN_SET($chalid, challenges) < 1 ORDER BY title ASC"); $output .= ""; $numseries = 0; while($series = dbassoc($series2)) { $output .= ""; $numseries++; } if($numseries < 1) $output .= ""; $output .="
"._STORIES."
".stripslashes($story['title'])."
"._NORESULTS."
"._SERIES."
".stripslashes($series['title'])."
"._NORESULTS."
"; } } } else { $catid = isset($_GET['catid']) ? $_GET['catid'] : false; if($chalid) { if(file_exists("./$skindir/challenges_title.tpl")) $challenges = new TemplatePower("./$skindir/challenges_title.tpl"); else $challenges = new TemplatePower(_BASEDIR."modules/challenges/default_tpls/challenges_title.tpl"); $challenges->prepare( ); $challenge = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_challenges WHERE chalid = '$chalid' LIMIT 1"); list($chalid, $challenger, $uid, $title, $cat, $chars, $summary, $responses) = dbrow($challenge); $challenger = stripslashes($challenger); $title = stripslashes($title); $summary= stripslashes($summary); $challenges->newBlock("titleblock"); if(isADMIN || USERUID == $uid) $challenges->assign("adminoptions", "
".($admin ? _ADMINOPTIONS : _OPTIONS).": ["._EDIT."] ["._DELETE."]
"); $challenges->assign("author", ($uid ? "$challenger" : "$challenger")); $challenges->assign("title", $title); $challenges->assign("summary",$summary); $challenges->assign("skindir", $skindir); $challenges->assign("characters", $chars ? charlist($chars) : _NONE); $challenges->assign("category", $cat > 0 ? catlist($cat) : _NONE); $challenges->assign("respond", ""); $challenges->assign("reportthis", "["._REPORTTHIS."]"); $output .= $challenges->getOutputContent( ); $tpl->gotoBlock( "_ROOT" ); $tpl->newBlock("listings"); list($scount) = dbrow(dbquery(_SERIESCOUNT." WHERE FIND_IN_SET($chalid, challenges) > 0")); $count = 0; if($scount > $offset) { $seriesquery = dbquery(_SERIESQUERY." AND FIND_IN_SET($chalid, series.challenges) > 0 LIMIT $offset, $itemsperpage"); while($stories = dbassoc($seriesquery)) { include(_BASEDIR."includes/seriesblock.php"); } } if($scount - $offset < $itemsperpage) { $storyoffset = $offset - $scount > 0 ? $offset - $scount : 0; $remainder = $itemsperpage - $count; list($scount2) = dbrow(dbquery(_STORYCOUNT." AND FIND_IN_SET($chalid, challenges) > 0")); if($scount2 > 0) { $storyquery = _STORYQUERY." AND FIND_IN_SET($chalid, stories.challenges) > 0"; $storyquery .= " LIMIT $offset, $remainder"; $storyresults = dbquery($storyquery); while($stories = dbassoc($storyresults)) { $tpl->newBlock("storyblock"); include(_BASEDIR."includes/storyblock.php"); } } } if($scount + $scount2 > $itemsperpage) { $tpl->gotoBlock( "listings" ); $tpl->assign( "pagelinks", build_pagelinks("challenges.php?chalid=$chalid&", $scount + $scount2, $offset)); } $tpl->gotoBlock( "_ROOT" ); } } $tpl->assign("output", $output); $tpl->printToScreen( ); ?>