$ed | ");
}
rawoutput("$del ]");
}
}
function motditem($subject,$body,$author,$date,$id){
if ($date)
rawoutput("");
output_notl("`b`^%s`0`b", $subject);
if ($id > "") {
motd_admin($id);
}
if ($date || $author) output_notl("`n");
if ($author > "") {
output_notl("`3%s`0", $author);
}
if ($date>"")
output_notl("`0 `#%s`0", $date, true);
if ($date || $author) output_notl("`n");
output_notl("`2%s`0", nltoappon($body), true);
if ($date) rawoutput("");
rawoutput("
");
}
function pollitem($id,$subject,$body,$author,$date,$showpoll=true){
global $session;
$sql = "SELECT count(resultid) AS c, MAX(choice) AS choice FROM " . db_prefix("pollresults") . " WHERE motditem='$id' AND account='{$session['user']['acctid']}'";
$result = db_query($sql);
$row = db_fetch_assoc($result);
$choice = $row['choice'];
$body = unserialize($body);
$poll = translate_inline("Poll:");
if ($session['user']['loggedin'] && $showpoll) {
rawoutput("");
}
rawoutput("
",true);
}
function motd_form($id) {
global $session;
$subject = httppost('subject');
$body = httppost('body');
$preview = httppost('preview');
if ($subject=="" || $body=="" || $preview>""){
$edit = translate_inline("Edit a MoTD");
$add = translate_inline("Add a MoTD");
$ret = translate_inline("Return");
$row = array(
"motditem"=>0,
"motdauthorname"=>"",
"motdtitle"=>"",
"motdbody"=>"",
);
if ($id>""){
$sql = "SELECT " . db_prefix("motd") . ".*,name AS motdauthorname FROM " . db_prefix("motd") . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid = " . db_prefix("motd") . ".motdauthor WHERE motditem='$id'";
$result = db_query($sql);
if (db_num_rows($result)>0){
$row = db_fetch_assoc($result);
$msg = $edit;
}else{
$msg = $add;
}
}else{
$msg = $add;
}
output_notl("`b%s`b", $msg);
rawoutput("[ $ret ]
");
rawoutput("");
}else{
if ($id>""){
$sql = " SET motdtitle='$subject', motdbody='$body'";
if (httppost('changeauthor'))
$sql.=", motdauthor={$session['user']['acctid']}";
if (httppost('changedate'))
$sql.=", motddate='".date("Y-m-d H:i:s")."'";
$sql = "UPDATE " . db_prefix("motd") . $sql . " WHERE motditem='$id'";
db_query($sql);
invalidatedatacache("motd");
invalidatedatacache("lastmotd");
invalidatedatacache("motddate");
}
if ($id=="" || db_affected_rows()==0){
if ($id>""){
$sql = "SELECT * FROM " . db_prefix("motd") . " WHERE motditem='$id'";
$result = db_query($sql);
if (db_num_rows($result)>0) $doinsert = false;
else $doinsert=true;
}else{
$doinsert=true;
}
if ($doinsert){
$sql = "INSERT INTO " . db_prefix("motd") . " (motdtitle,motdbody,motddate,motdauthor) VALUES (\"$subject\",\"$body\",'".date("Y-m-d H:i:s")."','{$session['user']['acctid']}')";
db_query($sql);
invalidatedatacache("motd");
invalidatedatacache("lastmotd");
invalidatedatacache("motddate");
}
}
header("Location: motd.php");
exit();
}
}
function motd_poll_form() {
global $session;
$subject = httppost('subject');
$body = httppost('body');
if ($subject=="" || $body==""){
output("`\$NOTE:`^ Polls cannot be edited after they are begun in order to ensure fairness and accuracy of results.`0`n`n");
rawoutput("");
}else{
$opt = httppost("opt");
$body = array("body"=>$body,"opt"=>$opt);
$sql = "INSERT INTO " . db_prefix("motd") . " (motdtitle,motdbody,motddate,motdtype,motdauthor) VALUES (\"$subject\",\"".addslashes(serialize($body))."\",'".date("Y-m-d H:i:s")."',1,'{$session['user']['acctid']}')";
db_query($sql);
invalidatedatacache("motd");
invalidatedatacache("lastmotd");
invalidatedatacache("motddate");
header("Location: motd.php");
exit();
}
}
function motd_del($id) {
$sql = "DELETE FROM " . db_prefix("motd") . " WHERE motditem=\"$id\"";
db_query($sql);
invalidatedatacache("motd");
invalidatedatacache("lastmotd");
invalidatedatacache("motddate");
header("Location: motd.php");
exit();
}
?>