";
$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 .= "
";
}
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 .= "
";
}
}
}
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", "
");
$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( );
?>