<?php
error_reporting(7);
require("./global.php");
adminlog();
cpheader();
echo "Custom Postbit Hack by Xenon Version 1.00
";
if (isset($action)==0) {
$action="view";
}
// ###################### Start Add #######################
if($action=="add") {
//$postbit = $DB_site->query_first("SELECT * FROM custompostbit WHERE postbitid=$postbitid");
doformheader("admincpb","insert");
maketableheader("Add custom postbit");
makeinputcode("Userids (separate with spaces)","userid");
makeinputcode("Usergroupids (separate with spaces)","usergroupid");
maketextareacode("Content","content",stripslashes(gettemplate('postbit')),20,80);
doformfooter();
}
// ###################### Start Insert #######################
if ($HTTP_POST_VARS['action']=="insert") {
$DB_site->query("INSERT INTO custompostbit (postbitid,userid,usergroupid,content,validated) VALUES (NULL,' ".trim($userid)." ',' ".trim($usergroupid)." ','".addslashes($content)."',1)");
echo "<p>Record added!</p>";
$action="view";
}
// ###################### Start Preview #######################
if($action=="preview") {
doformheader("","");
$custompostbit=$DB_site->query_first("SELECT custompostbit.*,user.username FROM custompostbit LEFT JOIN user ON (user.userid=custompostbit.author) WHERE custompostbit.postbitid=$postbitid");
maketableheader("Custom Postbit #".$custompostbit[postbitid]." by $custompostbit[username]");
$post=$bbuserinfo;
$post[dateline]=time();
$post[showsignature]=1;
$post[pagetext]="Thats a postbit test\n\nHow does it look?";
$post[ip]="111.111.11.11";
$post[postbitid]=0;
$postbit=getpostbit($post,$custompostbit[postbitid]);
$postbit = str_replace("{imagesfolder}","../"."{imagesfolder}",$postbit);
echo "<tr class='".getrowbg()."'><td colspan=2 align='center'>";
$gzipoutput=0;
echo dovars($postbit,0);
echo "</td></tr>";
dotablefooter();
$action="edit";
}
// ###################### Start Edit #######################
if($action=="edit") {
$postbit = $DB_site->query_first("SELECT * FROM custompostbit WHERE postbitid=$postbitid");
doformheader("admincpb","doedit");
maketableheader("Edit Postbit #".$postbitid);
makehiddencode("postbitid",$postbitid);
makeinputcode("Author","author",$postbit[author]);
if($postbit[validated]!=1) makeyesnocode("Validate?","validate",0);
makeinputcode("Userids (separate with spaces)","userid",$postbit[userid]);
makeinputcode("Usergroupids (separate with spaces)","usergroupid",$postbit[usergroupid]);
maketextareacode("Content","content",$postbit[content],20,80);
doformfooter();
}
// ###################### Start Update #######################
if ($HTTP_POST_VARS['action']=="doedit") {
$DB_site->query("UPDATE custompostbit SET ".iif($validate==1,"validated=1,","")."author='$author',content='".addslashes($content)."',userid=' ".trim($userid)." ',usergroupid=' ".trim($usergroupid)." ' WHERE postbitid=$postbitid");
echo "<p>Record updated!</p>";
$action="view";
}
// ###################### Start Remove #######################
if ($action=="remove") {
doformheader("admincpb","kill");
makehiddencode("postbitid",$postbitid);
maketableheader("Confirm deletion");
makedescription("Are you sure you want to delete this custom postbit?");
doformfooter("Yes","",2,"No");
}
// ###################### Start Kill #######################
if ($HTTP_POST_VARS['action']=="kill") {
$DB_site->query("DELETE FROM custompostbit WHERE postbitid=$postbitid");
$DB_site->query("UPDATE user SET postbitid=0 WHERE postbitid=$postbitid");
echo "<p>Deleted!</p>";
$action="view";
}
// ###################### Start Validate #######################
if ($action=="validate") {
$unvalid=$DB_site->query_first("SELECT COUNT(*) AS number FROM custompostbit WHERE validated=0");
if($unvalid[number]==0) {
echo "<p>Nothing to do!</p>";
$action="view";
} else {
$custompostbits=$DB_site->query("SELECT custompostbit.postbitid,custompostbit.content,user.username FROM custompostbit LEFT JOIN user ON (user.userid=custompostbit.author) WHERE validated=0");
$counter=0;
doformheader("admincpb","dovalidate");
maketableheader("Validate Custom Postbits");
while($postbit=$DB_site->fetch_array($custompostbits)) {
$counter++;
maketextareacode("Content
".makelinkcode("preview","admincpb.php?s=$session[sessionhash]&action=preview&postbitid=$postbit[postbitid]"),"content[$counter]",$postbit[content],20,80);
makehiddencode("postbitid[$counter]",$postbit[postbitid]);
makedescription("Author: ".$postbit[username]." <input type=\"checkbox\" name=\"kill[$counter]\" value=\"1\"> click here to delete this postbit");
makeyesnocode("Validate","validate[$counter]",0);
makehrcode();
}
makehiddencode("amount",$counter);
makehiddencode("allpb",$unvalid[number]);
doformfooter();
}
}
// ###################### Start doValidate #######################
if ($HTTP_POST_VARS['action']=="dovalidate") {
$validated = 0;
$deleted = 0;
for($counter=1;$counter<=$amount;$counter++) {
if($validate[$counter]==1 and $kill[$counter]!=1) {
$validated++;
$DB_site->query("UPDATE custompostbit SET validated=1 WHERE postbitid=".$postbitid[$counter]);
} elseif($validate[$counter]==0 and $kill[$counter]==1) {
$deleted++;
$DB_site->query("DELETE FROM custompostbit WHERE validated=0 AND postbitid=".$postbitid[$counter]);
}
}
echo "<p>$validated validated, $deleted deleted! ".($allpb-$validated-$deleted)." remain unvalidated!</p>";
$action="view";
}
// ###################### Start Overview #######################
if($action=="view") {
$unvalid=$DB_site->query_first("SELECT COUNT(*) AS number FROM custompostbit WHERE validated=0");
if ($unvalid[number]>0) echo "<a href=\"admincpb.php?s=$session[sessionhash]&action=validate\">There are currently ".$unvalid[number]." custom postbits to validate!</a>
";
doformheader("","");
maketableheader("Custom Postbits");
$post=$bbuserinfo;
$post[dateline]=time();
$post[showsignature]=1;
$post[pagetext]="Thats a postbit test\n\nHow does it look?";
$post[ip]="111.111.11.11";
$post[postbitid]=0;
$custompostbits=$DB_site->query("SELECT custompostbit.*,user.username FROM custompostbit LEFT JOIN user ON (user.userid=custompostbit.author) WHERE validated=1");
$counter=1;
while($custompostbit=$DB_site->fetch_array($custompostbits)) {
$postbit=getpostbit($post,$custompostbit[postbitid]);
$postbit = str_replace("{imagesfolder}","../"."{imagesfolder}",$postbit);
echo "<tr class='".getrowbg()."'><td>";
$gzipoutput=0;
echo dovars($postbit,0);
echo "</td><td>Postbit-id: $custompostbit[postbitid]
User-ids: $custompostbit[userid]
Usergroup-ids: $custompostbit[usergroupid]";
echo "
Author: ".iif($custompostbit[author]==0,"Admin created",$custompostbit[username]);
echo "
".makelinkcode("Edit","admincpb.php?s=$session[sessionhash]&action=edit&postbitid=$custompostbit[postbitid]");
echo " ".makelinkcode("Remove","admincpb.php?s=$session[sessionhash]&action=remove&postbitid=$custompostbit[postbitid]");
echo "</td></tr>";
$counter++;
}
dotablefooter();
}
cpfooter();
?>