AcmlmBoard-1.92.08/announcement.php

204 lines
9.1 KiB
PHP

<?php
require 'lib/function.php';
require 'lib/layout.php';
if(!$f) $f=0;
if(@mysql_num_rows(mysql_query("SELECT user FROM forummods WHERE forum=$f and user=$loguserid"))) $ismod=1;
$canpost=($isadmin or ($ismod && $f>0));
if($_GET[action]=='edit' or $_POST[action]=='editannc'){
$annc=mysql_fetch_array(mysql_query("SELECT * FROM announcements WHERE id=$id"));
if($annc[forum]>0 && $ismod) $canpost=true;
}
$smilies=readsmilies();
if(!$action){
loadtlayout();
$ppp=($log?$loguser[postsperpage]:20);
$min=$ppp*$page;
$anncs=mysql_query("SELECT a.*,u.*,a.title atitle,u.id uid FROM announcements a,users u WHERE forum=$f AND a.user=u.id ORDER BY a.id DESC LIMIT $min,$ppp");
$annctotal=@mysql_result(mysql_query("SELECT count(*) FROM announcements WHERE forum=$f"),0,0);
$pagelinks=$smallfont.'Pages:';
for($i=0;$i<($annctotal/$ppp);$i++){
if($i==$page) $pagelinks.=' '.($i+1);
else $pagelinks.=" <a href=announcement.php?f=$f&page=$i>".($i+1).'</a>';
}
$annclist="$tccellh width=150>User</td>$tccellh colspan=2>Announcement<tr>";
while($annc=mysql_fetch_array($anncs)){
if($annccount) $annclist.='<tr>';
$annccount++;
$bg=$bg%2+1;
$edit='&nbsp;';
if($isadmin or ($ismod && $f)){
$edit="<a href=announcement.php?id=$annc[0]&action=edit>Edit</a> | <a href=announcement.php?id=$annc[0]&action=delete&f=$f>Delete</a>";
if($isadmin) $ip=" | IP: $annc[3]";
}
if($loguser[viewsig]==2){
$annc[headtext]=$annc[postheader];
$annc[signtext]=$annc[signature];
}
$annc[text]="<center><b>$annc[atitle]</b></center><hr>$annc[text]";
$annclist.=threadpost($annc,$bg);
}
}
if($canpost){
if($_GET[action]=='delete'){
mysql_query("DELETE FROM announcements WHERE id=$id");
$annclist.="
$tccell1>Announcement deleted.
<br>".redirect("announcement.php?f=$f",'return to the announcements',0);
}
if($_GET[action]=='new'){
if($log){
$username=htmlspecialchars($loguser[name]);
$password=$logpassword;
}
$annclist="
<FORM ACTION=announcement.php NAME=REPLIER METHOD=POST>
$tccellh width=150>&nbsp</td>$tccellh>&nbsp;<tr>
$tccell1><b>User name:</b></td> $tccell2l>$inpt=username VALUE=\"$username\" SIZE=25 MAXLENGTH=25><tr>
$tccell1><b>Password:</b></td> $tccell2l>$inpp=password VALUE=\"$password\" SIZE=13 MAXLENGTH=32><tr>
$tccell1><b>Announcement title:</b></td>$tccell2l>$inpt=subject SIZE=70 MAXLENGTH=100><tr>
$tccell1><b>Announcement:</b></td> $tccell2l>$txta=message ROWS=20 COLS=$numcols></TEXTAREA><tr>
$tccell1>&nbsp;</td> $tccell2l>$inph=action VALUE=postannc>$inph=f VALUE=$f>
$inps=submit VALUE=\"Post announcement\">
$inps=preview VALUE=\"Preview announcement\"></td></FORM>
";
}
if($_GET[action]=='edit'){
if(!$annc[headid]) $head=$annc[headtext];
else $head=mysql_result(mysql_query("SELECT text FROM postlayouts WHERE id=$annc[headid]"),0,0);
if(!$annc[signid]) $sign=$annc[signtext];
else $sign=mysql_result(mysql_query("SELECT text FROM postlayouts WHERE id=$annc[signid]"),0,0);
sbr(1,$annc[text]);
sbr(1,$head);
sbr(1,$sign);
$annclist="
<FORM ACTION=announcement.php NAME=REPLIER METHOD=POST>
$tccellh width=150>&nbsp</td>$tccellh>&nbsp;<tr>
$tccell1><b>Announcement title:</b></td>$tccell2l>$inpt=subject VALUE=\"$annc[title]\" SIZE=70 MAXLENGTH=100><tr>
$tccell1><b>Header:</b></td> $tccell2l>$txta=head ROWS=8 COLS=$numcols>$head</TEXTAREA><tr>
$tccell1><b>Announcement:</b></td> $tccell2l>$txta=message ROWS=12 COLS=$numcols>$annc[text]</TEXTAREA><tr>
$tccell1><b>Signature:</b></td> $tccell2l>$txta=sign ROWS=8 COLS=$numcols>$sign</TEXTAREA><tr>
$tccell1>&nbsp</td> $tccell2l>
$inph=action VALUE=editannc>
$inph=f VALUE=$annc[forum]>
$inph=id VALUE=$id>
$inph=edited VALUE=\"$annc[edited]\">
$inps=submit VALUE=\"Edit announcement\">
$inps=preview VALUE=\"Preview announcement\"></td></FORM>
";
}
if($_POST[action]=='postannc'){
$userid=checkuser($username,$password);
$user=@mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id=$userid"));
if($userid!=-1){
$sign=$user[signature];
$head=$user[postheader];
if($user[postbg]) $head="<div style=background:url($user[postbg]);height=100%>$head";
$numposts=$user[posts];
$numdays=(ctime()-$user[regdate])/86400;
$message=doreplace($message,$numposts,$numdays,$username);
$rsign=doreplace($sign,$numposts,$numdays,$username);
$rhead=doreplace($head,$numposts,$numdays,$username);
squot(0,$subject);
$currenttime=ctime();
if($submit){
if(!$f) $f=0;
$headid=getpostlayoutid($head);
$signid=getpostlayoutid($sign);
mysql_query("INSERT INTO `announcements` (`user`, `date`, `ip`, `title`, `forum`, `text`, `headid`, `signid`, `tagval`) VALUES ('$userid', '$currenttime', '$userip', '$subject', '$f', '$message', '$headid', '$signid', '$tagval')");
$annclist="
$tccell1>Thank you, $user[name], for posting your announcement.<br>
".redirect("announcement.php?f=$f","the announcements",0)."</table></table>";
}else{
loadtlayout();
$ppost=$user;
$ppost[uid]=$userid;
$ppost[date]=$currenttime;
$ppost[headtext]=$rhead;
$ppost[signtext]=$rsign;
$ppost[text]="<center><b>". stripslashes($subject) ."</b></center><hr>". stripslashes($message);
if($isadmin) $ip=$userip;
$annclist="
<body onload=window.document.REPLIER.message.focus()>
$tccellh>Announcement preview
$tblend$tblstart
".threadpost($ppost,1)."
$tblend<br>$tblstart
<FORM ACTION=announcement.php NAME=REPLIER METHOD=POST>
$tccellh width=150>&nbsp</td>$tccellh>&nbsp<tr>
$tccell1><b>Announcement title:</td>$tccell2l>$inpt=subject SIZE=70 MAXLENGTH=100 VALUE=\"". stripslashes($subject) ."\"><tr>
$tccell1><b>Announcement:</td> $tccell2l>$txta=message ROWS=10 COLS=$numcols>". stripslashes($message) ."</TEXTAREA><tr>
$tccell1>&nbsp</td>$tccell2l>
$inps=submit VALUE=\"Submit announcement\">
$inps=preview VALUE=\"Preview announcement\">
$inph=username VALUE=\"".htmlspecialchars($username)."\">
$inph=password VALUE=\"$password\">
$inph=action VALUE=postannc>
$inph=f VALUE=$f>
</td></FORM>
";
}
}else
$annclist="
$tccell1>Couldn't enter the announcement. You haven't entered the right username or password.
".redirect('announcement.php','return to the announcements',0);
}
if($_POST[action]=='editannc'){
print $tblstart;
$numposts=$loguser[posts];
$numdays=(ctime()-$loguser[regdate])/86400;
$message=doreplace($message,$numposts,$numdays,$loguser[name]);
if($submit){
$edited.="(edited by $loguser[name] on ".date("m-d-y h:i A",ctime()).")<br>";
$headid=@mysql_result(mysql_query("SELECT id FROM postlayouts WHERE text='$head' LIMIT 1"),0,'id');
$signid=@mysql_result(mysql_query("SELECT id FROM postlayouts WHERE text='$sign' LIMIT 1"),0,'id');
if($headid) $head=''; else $headid=0;
if($signid) $sign=''; else $signid=0;
mysql_query("UPDATE announcements SET title='$subject', text='$message', headtext='$head', signtext='$sign', edited='$edited',headid=$headid,signid=$signid WHERE id=$id");
$annclist="
$tccell1>Thank you, ".$loguser[name].", for editing the announcement.<br>
".redirect("announcement.php?f=$f","go to the announcements",0);
}else{
loadtlayout();
$annc=mysql_fetch_array(mysql_query("SELECT * FROM announcements WHERE id=$id"));
$ppost=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id=$annc[user]"));
$subject = stripslashes($subject);
$message = stripslashes($message);
$head = stripslashes($head);
$sign = stripslashes($sign);
$ppost[uid]=$annc[user];
$ppost[date]=$annc[date];
$ppost[tagval]=$annc[tagval];
$ppost[headtext]=$head;
$ppost[signtext]=$sign;
$ppost[text]="<center><b>$subject</b></center><hr>$message";
if($isadmin) $ip=$annc[ip];
$annclist="
<body onload=window.document.REPLIER.message.focus()>
$tccellh>Announcement preview
$tblend$tblstart
".threadpost($ppost,1)."
$tblend<br>$tblstart
<FORM ACTION=announcement.php NAME=REPLIER METHOD=POST>
$tccellh width=150>&nbsp</td>$tccellh>&nbsp<tr>
$tccell1><b>Announcement title:</b></td>$tccell2l>$inpt=subject VALUE=\"$subject\" SIZE=70 MAXLENGTH=100><tr>
$tccell1><b>Header:</td> $tccell2l>$txta=head ROWS=4 COLS=$numcols>$head</TEXTAREA><tr>
$tccell1><b>Announcement:</td> $tccell2l>$txta=message ROWS=6 COLS=$numcols>$message</TEXTAREA><tr>
$tccell1><b>Signature:</td> $tccell2l>$txta=sign ROWS=4 COLS=$numcols>$sign</TEXTAREA><tr>
$tccell1>&nbsp</td>$tccell2l>
$inps=submit VALUE=\"Edit announcement\">
$inps=preview VALUE=\"Preview announcement\">
$inph=action VALUE=editannc>
$inph=id VALUE=$id>
$inph=f VALUE=$f>
</td></FORM>
";
}
}
$postnew="<a href=announcement.php?action=new&f=$f>Post new announcement</a>";
}
print "$header
<table width=100%><td align=left>$fonttag<a href=index.php>$boardname</a> - Announcements</td><td align=right>$smallfont$postnew</table>
$pagelinks$tblstart$annclist$tblend$pagelinks$footer
";
printtimedif($startingtime);
?>