"._YOURSTATS."";
}
$add = isset($_GET['add']) ? $_GET['add'] : false;
$edit = isset($_GET['edit']) ? $_GET['edit'] : false;
$delete = isset($_GET['delete']) ? $_GET['delete'] : false;
if($add) $output .= "
";
else if($edit) $output .= "";
else $output .= "";
if(($add || $edit || $delete) && !isMEMBER) accessDenied( );
if($delete && isNumber($delete)) {
$result = dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '".USERUID."' AND item = '$delete' AND type = 'ST' LIMIT 1");
if($result) $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2ACCT);
else $output .= write_error(_ERROR);
}
if($add && isset($_POST['submit'])) {
$check = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '".USERUID."' AND item = '$sid' AND type = 'ST' LIMIT 1");
if(!dbnumrows($check))
$result = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_favorites(uid, item, type, comments) VALUES ('".USERUID."', '$sid', 'ST', '".escapestring(descript(strip_tags(replace_naughty($_POST['comments']), $allowed_tags)))."')");
if($result) $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2ACCT);
}
if($edit && isset($_POST['submit'])) {
$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_favorites SET comments = '".escapestring(descript(strip_tags(replace_naughty($_POST['comments']), $allowed_tags)))."' WHERE uid = '$uid' AND item = '$edit' AND type = 'ST'");
if($result) $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2ACCT);
else $output .= write_error(_ERROR);
}
if(($add || $edit) && !isset($_POST['submit'])) {
if($add) {
$check = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '".USERUID."' AND item = '$sid' AND type = 'ST' LIMIT 1");
if(dbnumrows($check)) {
$edit = $sid;
$add = false;
}
}
if($edit) {
$query = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '".USERUID."' AND type = 'ST' AND item = '$edit' LIMIT 1");
$info = dbassoc($query);
}
$storyinfo = dbquery(_STORYQUERY." AND sid = '".($edit? $edit : $sid)."'");
$stories = dbassoc($storyinfo);
if(!$stories) $output .= write_error(_ERROR);
else {
$tpl->newBlock("listings");
$tpl->newBlock("storyblock");
include("includes/storyblock.php");
$tpl->gotoBlock("listings");
$tpl->assign("pagelinks", "");
$tpl->gotoBlock("_ROOT");
}
}
else if(!isset($_POST['submit'])) {
$storyquery = "SELECT stories.*, "._PENNAMEFIELD." as penname, fav.comments as comments, stories.date as date, stories.updated as updated FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_favorites as fav, "._AUTHORTABLE." WHERE fav.uid = '$uid' AND fav.type = 'ST' AND stories.uid = "._UIDFIELD." AND fav.item = stories.sid "._ORDERBY;
$countquery = dbquery("SELECT COUNT(item) FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '$uid' AND type = 'ST' GROUP BY uid");
list($storycount) = dbrow($countquery);
if($storycount) {
$list = dbquery($storyquery." LIMIT $offset, $itemsperpage");
$tpl->newBlock("listings");
$count = 0;
while($stories = dbassoc($list)) {
$tpl->newBlock("storyblock");
include("includes/storyblock.php");
if(!empty($stories['comments']) || USERUID == $uid || isADMIN) {
if(file_exists("./$skindir/favcomment.tpl")) $cmt = new TemplatePower( "./$skindir/favcomment.tpl" );
else $cmt = new TemplatePower( "./default_tpls/favcomment.tpl" );
$cmt->prepare( );
$cmt->newBlock("comment");
$cmt->assign("comment", $stories['comments'] ? "" : "");
if(USERUID == $uid)
$cmt->assign("commentoptions", "");
$cmt->assign("oddeven", ($count % 2 ? "odd" : "even"));
$tpl->assign("comment", $cmt->getOutputContent( ));
$tpl->gotoBlock( "listings" );
}
}
if($storycount > $itemsperpage) {
$tpl->gotoBlock("listings");
$tpl->assign("pagelinks", build_pagelinks(basename($_SERVER['PHP_SELF'])."?action=favst&uid=$uid&", $storycount, $offset));
}
}
else $output .= write_message(_NORESULTS);
$tpl->gotoBlock( "_ROOT" );
}
?>