<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

$page = $_GET['page'];
$announcement = $_GET['announcement'];
$delete = $_GET['delete'];
$edit = $_GET['edit'];
$topic = $_GET['topic'];
if(!$topic) $topic = $_POST['topic'];
$addreply = $_GET['addreply'];
if(!$addreply) $addreply = $_POST['topic'];
$type = $_GET['type'];
$quoteID = $_GET['quoteID'];
$do_sticky = (isset($_POST['sticky']) ? '1' : '0');

if($_POST['newreply'] && $_POST['preview']==0) {
	include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  if(!$userID) die('Not logged in.');

	$message = $_POST['message'];
	$topic = $_POST['topic'];
	$page = $_POST['page'];
	
	if(!(strlen(trim($message)))) die("You forgot to enter a message!");
	$ds=mysql_fetch_array(safe_query("SELECT closed FROM ".PREFIX."forum_topics WHERE topicID='".$topic."'"));
	if($ds['closed']) die("The topic has been closed!");	

  $date=time();
	safe_query("INSERT INTO ".PREFIX."forum_posts ( boardID, topicID, date, poster, message ) VALUES( '$_REQUEST[board]', '$topic', '$date', '$userID', '".mysql_escape_string($message)."' ) ");
	safe_query("UPDATE ".PREFIX."forum_boards SET posts=posts+1 WHERE boardID='".$_REQUEST['board']."' ");
	safe_query("UPDATE ".PREFIX."forum_topics SET lastdate='$date', lastposter='$userID', replys=replys+1, sticky='$do_sticky' WHERE topicID='$topic' ");
	
	$ergebnis=safe_query("SELECT userID FROM ".PREFIX."forum_notify WHERE topicID='$topic'");
  while($ds=mysql_fetch_array($ergebnis)) {
    $de=mysql_fetch_array(safe_query("SELECT email FROM ".PREFIX."user WHERE userID='$ds[userID]'"));
		$emails[] = $de[email];
	}
	safe_query("DELETE FROM ".PREFIX."forum_notify WHERE topicID='$topic'");
		
	if(is_array($emails)) {
		
		$de=mysql_fetch_array(safe_query("SELECT nickname FROM ".PREFIX."user WHERE userID='$userID'"));
		$poster=$de[nickname];
		$de=mysql_fetch_array(safe_query("SELECT topic FROM ".PREFIX."forum_topics WHERE topicID='$topic'"));
		$topicname=getinput($de[topic]);
		
		$link="http://".$hp_url."/index.php?site=forum_topic&topic=".$topic;
	
		$forum_topic_notify = "new reply by $poster in topic: $topicname
-----------------------------------------------------------------------------------

use this link to jump to this topic: $link

-----------------------------------------------------------------------------------
".PAGETITLE."
http://$hp_url

[powered by webspell.org]";

		$header = "From:".$admin_email."\r\nX-Mailer: PHP/" . phpversion();
		
		foreach($emails as $email) mail($email,"new Reply on: ".PAGETITLE,$forum_topic_notify,$header);
	}
			
	if($_POST['notify']) {
		safe_query("INSERT INTO ".PREFIX."forum_notify (topicID, userID) values('$topic', '$userID') ");
	}
 header("Location: index.php?site=forum_topic&topic=$topic&page=$page");
}
elseif($_POST['editreply']) {
	include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  
  if(!isforumposter($userID,$_POST['id']) AND !isforumadmin($userID) AND !ismoderator($userID,$_GET['board'])) die('No access.');
  
  $message = $_POST['message'];
  $id = $_POST['id'];
  $check=mysql_num_rows(safe_query("SELECT postID FROM ".PREFIX."forum_posts WHERE postID='".$id."' AND poster='".$userID."'"));
  if(($check OR isforumadmin($userID) OR ismoderator($userID,$_GET['board'])) AND strlen(trim($message))) {
		$date=date("d.m.Y - H:i", time());
		safe_query("UPDATE ".PREFIX."forum_posts SET message = '".mysql_escape_string($message)."' WHERE postID='$id' ");
    safe_query("UPDATE ".PREFIX."forum_topics SET sticky='$do_sticky' WHERE topicID='".$_GET['topic']."'");
    safe_query("DELETE FROM ".PREFIX."forum_notify WHERE userID='$userID' AND topicID='".$_GET['topic']."'");
    if($_POST['notify']) safe_query("INSERT INTO ".PREFIX."forum_notify (`notifyID`, `topicID`, `userID`) VALUES ('', '$userID', '".$_GET['topic']."')");
	}	
	header("Location: index.php?site=forum_topic&topic=".$_GET['topic']."&page=".$_GET['page']);
}
elseif($_POST['saveannouncement']) {
	include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  if(!isanyadmin($userID)) die('No access.');

  $board = $_POST['board'];
	$date=time();
    $ds=mysql_fetch_array(safe_query("SELECT intern FROM ".PREFIX."forum_boards WHERE boardID='$board'"));
	$intern=$ds[intern];
	
	safe_query("INSERT INTO ".PREFIX."forum_announcements (boardID, intern, userID, date, topic, announcement) VALUES ('$board', '".$_POST['intern']."', '$userID', '".$date."', '".$_POST['topic']."', '".$_POST['message']."')");
	$id=mysql_insert_id();
	
	header("Location: index.php?site=forum_topic&announcement=$id");
}
elseif($_POST['editannouncement']) {
	include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  if(!isanyadmin($userID)) die('No access.');
  $announcement = $_POST['announcement'];
	$date=time();
	safe_query("UPDATE ".PREFIX."forum_announcements SET topic='".$_POST['topic']."', announcement='".$_POST['message']."', date='$date' WHERE announceID='$announcement' ");
	header("Location: index.php?site=forum_topic&announcement=$announcement");
}
elseif($_GET['delete']) {
	include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  if(!isanyadmin($userID)) die('No access.');

	safe_query("DELETE FROM ".PREFIX."forum_announcements WHERE announceID='".$_GET['announcement']."'");
	header("Location: index.php?site=forum&board=".$_GET['board']);
}
elseif($_POST['saveedittopic']) {
	include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  if(!isforumadmin($userID) AND !isforumposter($userID,$_POST['post']) AND !ismoderator($userID,$_GET['board'])) die('No access.');
	
	$board = $_GET['board'];
	$topic = $_GET['topic'];
	$post = $_POST['post'];
	$notify = $_POST['notify'];
	$topicname = $_POST['topicname'];
	$message = $_POST['message'];
	$icon = $_POST['icon'];
	
	safe_query("UPDATE ".PREFIX."forum_posts SET message='".mysql_escape_string($message)."' WHERE postID='".$post."'");
	safe_query("UPDATE ".PREFIX."forum_topics SET topic='".mysql_escape_string($topicname)."', icon='".$icon."', sticky='".$do_sticky."' WHERE topicID='".$topic."'");

	if($notify==1) {
		$notified = safe_query("SELECT * FROM ".PREFIX."forum_notify WHERE topicID='".$topic."' AND userID='".$userID."'");
		if(mysql_num_rows($notified)!=1) {
			safe_query("INSERT INTO ".PREFIX."forum_notify (notifyID, topicID, userID) VALUES ('', '$topic', '$userID')");
		}
	} else {
		safe_query("DELETE FROM ".PREFIX."forum_notify WHERE topicID='".$topic."' AND userID='".$userID."'");
	}
	header("Location: index.php?site=forum&board=".$board);
}

function showtopic($topic, $edit, $id, $addreply, $quoteID, $type) {
	global $userID;
	global $loggedin;
	global $page;
	global $maxposts;
	global $preview;
	global $message;
	global $picsize_l;
	
	$pagebg=PAGEBG;
	$border=BORDER;
	$bghead=BGHEAD;
	$bgcat=BGCAT;
	
	$thread = safe_query("SELECT * FROM ".PREFIX."forum_topics WHERE topicID='$topic' ");
	$dt = mysql_fetch_array($thread);
	
	$gesamt = mysql_num_rows(safe_query("SELECT topicID FROM ".PREFIX."forum_posts WHERE topicID='$topic'"));
	if($gesamt==0) die("Topic could not be found. <a href=\"javascript:history.back()\">back</a>");
	$pages=1;
	if(!isset($page) || $site='') $page=1;
	if(!isset($type)) $type = "ASC";
	$max=$maxposts;
	
	for ($n=$max; $n<=$gesamt; $n+=$max) {
		if($gesamt>$n) $pages++;
	}
	
	if($pages>1) $page_link = makepagelink("index.php?site=forum_topic&topic=$topic&type=$type", $page, $pages);
	if($type=="ASC") {
		$sorter='<a href="index.php?site=forum_topic&topic='.$topic.'&page='.$page.'&sort='.$sort.'&type=DESC">Sort:</a> <img src="images/icons/asc.gif" width="9" height="7">';
	} else {
		$sorter='<a href="index.php?site=forum_topic&topic='.$topic.'&page='.$page.'&sort='.$sort.'&type=ASC">Sort:</a> <img src="images/icons/desc.gif" width="9" height="7">';
	}
	
	if($page==1) $start=0;
	if($page>1) $start=$page*$max-$max;
	
	safe_query("UPDATE ".PREFIX."forum_topics SET views=views+1 WHERE topicID='$topic' ");
	
	// viewed topics
	$getviewedtopics=safe_query("SELECT topics FROM ".PREFIX."user WHERE userID='$userID'");
	$gv=mysql_fetch_array($getviewedtopics);
	if($gv[topics]=="") {  //wenn noch keine topics besucht wurden
	    $array[]=$topic;
	    $array[]=time();
	}
	else {
		$string=$gv[topics];
		$array=explode(":", $string);
		$anzarray=count($array);
		
		for($i=0; $i<$anzarray; $i++) {
			if($array[$i]==$topic) {   // wenn topic bereits besucht wurde, timestamp updaten
				$array[$i+1]=time();
				$found=true;
			}
		}
		if(!$found) { // wenn topic noch nicht besucht wurde, neu eintragen
			$array[]=$topic;
			$array[]=time();
		}
	}
	$string_new=implode(":", $array);
	safe_query("UPDATE ".PREFIX."user SET topics='$string_new' WHERE userID='$userID'");
	// end viewed topics
	
	$topicname=getinput($dt[topic]);
	
	$ergebnis = safe_query("SELECT * FROM ".PREFIX."forum_boards WHERE boardID='$dt[boardID]' ");
	$db = mysql_fetch_array($ergebnis);
	$boardname = $db[name];
	
	$moderators=getmoderators($dt[boardID]);
	
	if($db[intern]) {
	    if(! isinternboarduser($userID)) die('You have no permission to view intern boards!<br><br>
		                                  <meta http-equiv="refresh" content="3;URL=index.php?site=forum">');
	}	 
		 
	$topicactions='<a href="printview.php?board='.$dt[boardID].'&topic='.$topic.'" target="_blank"><img src="images/icons/printview.gif" border="0" alt="printview"></a> ';
	if($loggedin) $topicactions.='<a href="index.php?site=forum&addtopic=true&action=newtopic&board='.$dt[boardID].'"><img src="images/icons/newtopic.gif" border="0" alt="new topic"></a> ';
	if($dt[closed]) $closed='<img src="images/icons/closed.gif">';
	else {
		$closed='';
		$topicactions.='<a href="index.php?site=forum_topic&topic='.$topic.'&addreply=true&page='.$pages.'&type='.$type.'"><img src="images/icons/newreply.gif" border="0" alt="reply"></a>';
	}
	$posttype='topic';
	eval ("\$forum_topics_title = \"".gettemplate("forum_topics_title")."\";");
	echo $forum_topics_title;

	eval ("\$forum_topics_actions = \"".gettemplate("forum_topics_actions")."\";");
	echo $forum_topics_actions;
	
	if($dt[closed]) {
	    echo'<br><br><img src="images/icons/closed.gif"><br><br>'; 
	}

	if($edit && !$dt[closed]) {

		$id = $_GET['id'];
		$dr = mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."forum_posts WHERE postID='".$id."'"));
		$topic = $_GET['topic'];
		$bg1=BG_1;
		$_sticky = ($dt[sticky] == '1') ? 'checked="checked"' : '';
		
		$anz = mysql_num_rows(safe_query("SELECT * FROM ".PREFIX."forum_posts WHERE topicID='".$dt[topicID]."' AND postID='".$id."' AND poster='".$userID."' ORDER BY date ASC LIMIT 0,1"));		
		if($anz OR isforumadmin($userID) OR ismoderator($userID,$dt[boardID])) {
			if(istopicpost($dt[topicID], $id)) {
				$bg1=BG_1;
				
				// topicmessage
				$message = getinput($dr['message']);
				$post = $id;
				$board = $dt['boardID'];
				
				// notification check
				$notifyqry = safe_query("SELECT * FROM ".PREFIX."forum_notify WHERE topicID='".$topic."' AND userID='".$userID."'");
				if(mysql_num_rows($notifyqry)) {
					$notify = '<input class="input" type="checkbox" name="notify" value="1" checked> Notify me when a reply is posted<br>';
				} else {
					$notify = '<input class="input" type="checkbox" name="notify" value="1"> Notify me when a reply is posted<br>';
				}
				//STICKY
				if(isforumadmin($userID) || ismoderator($userID, $board)) {
          $chk_sticky = '<br />'."\n".' <input class="input" type="checkbox" name="sticky" value="1" '.$_sticky.'> Make this topic sticky';
        }
        else {
          $chk_sticky = '';
        }
				
				// topic icon list
				$iconlist = '
									<tr bgcolor="'.$bg1.'"> 
										<td><input type="radio" class="input" name="icon" value="ausrufezeichen.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/ausrufezeichen.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="biggrin.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/biggrin.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="boese.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/boese.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="bored.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/bored.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="cool.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/cool.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="eek.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/eek.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="frage.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/frage.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="frown.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/frown.gif" width="15" height="15"></td>
									</tr>
									<tr bgcolor="'.$bg1.'"> 
										<td><input type="radio" class="input" name="icon" value="lampe.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/lampe.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="mad.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/mad.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="pfeil.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/pfeil.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="smile.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/smile.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="text.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/text.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="thumb_down.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/thumb_down.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="thumb_up.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/thumb_up.gif" width="15" height="15"></td>
										<td><input type="radio" class="input" name="icon" value="wink.gif" width="15" height="15"> 
											<img src="images/icons/topicicons/wink.gif" width="15" height="15"></td>
									</tr>
				';
				$iconlist = str_replace('value="'.$dt[icon].'"', 'value="'.$dt[icon].'" checked', $iconlist);
				
				eval ("\$addbbcode = \"".gettemplate("addbbcode")."\";");
				eval ("\$forum_edittopic = \"".gettemplate("forum_edittopic")."\";");
				echo $forum_edittopic;		
			} else {
        //STICKY
				if(isforumadmin($userID) || ismoderator($userID, $board)) {
          $chk_sticky = '<br />'."\n".' <input class="input" type="checkbox" name="sticky" value="1" '.$_sticky.'> Make this topic sticky';
        }
        else {
          $chk_sticky = '';
        }
				$dr['message']=getinput($dr['message']);
				eval ("\$addbbcode = \"".gettemplate("addbbcode")."\";");
				eval ("\$forum_editpost = \"".gettemplate("forum_editpost")."\";");
				echo $forum_editpost;
			}
		} else {
			echo 'Permission denied.<br><br>';
		}

		$replys = safe_query("SELECT * FROM ".PREFIX."forum_posts WHERE topicID='$topic' ORDER BY date DESC LIMIT $start, $max");
	}
	elseif($addreply && !$dt[closed]) {
        if($loggedin) {
        	if($_POST['preview']) {
				$bg1=BG_1;
				$bg2=BG_2;
				
				$time=date("H:i", time());
				$date="today";
			
				$message_preview = $_POST['message'];

				$message = cleartext($_POST['message']);
				$message = toggle($message, 'xx');
				$username='<a href="index.php?site=profile&id='.$userID.'"><b>'.getnickname($userID).'</b></a>';
		
				if(isclanmember($userID)) $member=' <img src="images/icons/member.gif" width="6" height="11" alt="Clanmember">';
				else $member='';
				if(getavatar($userID)) $avatar='<img src="images/avatars/'.getavatar($userID).'">';
				else $avatar='';
				if(getsignatur($userID)) $signatur='<hr width="200" noshade color="'.BORDER.'" align="left" size="1">'.cleartext(getsignatur($userID));
				else $signatur='';
				if (getemail($userID)) $email = '<a href="mailto:'.getemail($userID).'"><img src="images/icons/email.gif" border="0" width="15" height="11" alt="email"></a>';
				else $email='';
				$pm='';
				$buddy='';
				$statuspic='<img src="images/icons/online.gif" width="7" height="7" alt="online">';
				$sem = '^[http://]+[a-z0-9_\.-]+[a-z0-9_-]+$';
				if(!(eregi($sem, gethomepage($userID)))) $hp='';
				else $hp='<a href="'.gethomepage($userID).'" target="_blank"><img src="images/icons/hp.gif" border="0" width="14" height="14" alt="homepage"></a>';
				$registered = getregistered($userID);
				$posts = getuserforumposts($userID);
				$_sticky = ($dt[sticky] == '1' || $_POST['sticky'] == '1') ? 'checked="checked"' : '';
				if(isforumadmin($userID) || isanymoderator($userID)) {
				  if(isanymoderator($userID)) {
					    $usertype="Moderator";
					    $rang='<img src="images/icons/ranks/moderator.gif">';
					    $chk_sticky = '<br />'."\n".' <input class="input" type="checkbox" name="sticky" value="1" '.$_sticky.'> Make this topic sticky';
					}
					if(isforumadmin($userID)) {
					    $usertype="Administrator";
						$rang='<img src="images/icons/ranks/admin.gif">';
						$chk_sticky = '<br />'."\n".' <input class="input" type="checkbox" name="sticky" value="1" '.$_sticky.'> Make this topic sticky';
					}	
				}	
				else {
				    $ergebnis=safe_query("SELECT * FROM ".PREFIX."forum_ranks WHERE $posts >= postmin AND $posts <= postmax");
					$ds=mysql_fetch_array($ergebnis);
					$usertype=$ds[rank];
					$rang='<img src="images/icons/ranks/'.$ds[pic].'">';
					$chk_sticky = '';
				}
				$action='';
				
				echo'<table width="100%" cellspacing="1" cellpadding="2" bgcolor="'.BORDER.'">
				 		<tr bgcolor="'.BGHEAD.'"><td colspan="2" class="title" align="center">Preview</td></tr>
				 		<tr bgcolor="'.PAGEBG.'"><td colspan="2"></td></tr>';
				eval ("\$forum_topic_content = \"".gettemplate("forum_topic_content")."\";");
			    echo $forum_topic_content;
				echo'</table>';
				
				$message = $message_preview;
			}
			else {
				if($quoteID) {
			   	    $ergebnis=safe_query("SELECT poster,message FROM ".PREFIX."forum_posts WHERE postID='$quoteID'");
					$ds=mysql_fetch_array($ergebnis);
					$message='[quote]'.getnickname($ds[poster]).' wrote:[hr]'.getinput($ds[message]).'[/quote]';
				}
			}
			$_sticky = ($dt[sticky] == '1' || $_POST['sticky'] == '1') ? 'checked="checked"' : '';
			if(isforumadmin($userID) || ismoderator($userID, $dt[boardID])) {
        $chk_sticky = '<br />'."\n".' <input class="input" type="checkbox" name="sticky" value="1" '.$_sticky.'> Make this topic sticky';
			}
			else {
			  $chk_sticky = '';
			}
      
			$bg1=BG_1;
			$board = $dt[boardID];
			
			eval ("\$addbbcode = \"".gettemplate("addbbcode")."\";");
			eval ("\$forum_newreply = \"".gettemplate("forum_newreply")."\";");
			echo $forum_newreply;	   
		}
		else {
    		echo'<br><br>To start or to reply to a topic you have to be registered and logged in!<br><br>
	     	&#8226; <b><a href="index.php?site=register">register now</a></b>';
		}			
		$replys = safe_query("SELECT * FROM ".PREFIX."forum_posts WHERE topicID='$topic' ORDER BY date DESC LIMIT 0, $max");
	}
	else $replys = safe_query("SELECT * FROM ".PREFIX."forum_posts WHERE topicID='$topic' ORDER BY date $type LIMIT $start, $max");
	
	eval ("\$forum_topic_head = \"".gettemplate("forum_topic_head")."\";");
	echo $forum_topic_head;
	$i=1;
	while($dr=mysql_fetch_array($replys)) {
		if($i%2) {
			$bg1=BG_1;
			$bg2=BG_2;
		}
		else {
			$bg1=BG_3;
			$bg2=BG_4;
		}
		
		$date=date("d.m.Y", $dr[date]);
		$time=date("H:i", $dr[date]);

		$today=date("d.m.Y", time());
		$yesterday = date("d.m.Y", time()-3600*24);
		
		if($date==$today) $date="today";
		elseif($date==$yesterday && $date<$today) $date="yesterday";
		else $date=$date;
		
		$message = cleartext($dr[message]);
		$message = toggle($message, $dr[postID]);
		$postID= $dr[postID];

		$username='<a href="index.php?site=profile&id='.$dr[poster].'"><b>'.getnickname($dr[poster]).'</b></a>';
		
		if(isclanmember($dr[poster])) $member=' <img src="images/icons/member.gif" width="6" height="11" alt="Clanmember">';
		else $member='';

		if(getavatar($dr[poster])) $avatar='<img src="images/avatars/'.getavatar($dr[poster]).'">';
		else $avatar='';
		
		if(getsignatur($dr[poster])) $signatur='<hr width="200" noshade color="'.BORDER.'" align="left" size="1">'.cleartext(getsignatur($dr[poster]));
		else $signatur='';
		
		if (getemail($dr[poster])) $email = '<a href="mailto:'.getemail($dr[poster]).'"><img src="images/icons/email.gif" border="0" width="15" height="11" alt="email"></a>';
		else $email='';
		
		$pm='';
		$buddy='';
		if($loggedin && $dr[poster]!=$userID) {
			$pm='<a href="index.php?site=messenger&action=touser&touser='.$dr[poster].'"><img src="images/icons/pm.gif" border="0" width="12" height="13" alt="messenger"></a>';
			if(isignored($userID, $dr[poster])) $buddy='<a href="buddys.php?action=readd&id='.$dr[poster].'&userID='.$userID.'"><img src="images/icons/buddy_readd.gif" width="16" height="16" border="0" alt="back to buddy-list"></a>';
			elseif(isbuddy($userID, $dr[poster])) $buddy='<a href="buddys.php?action=ignore&id='.$dr[poster].'&userID='.$userID.'"><img src="images/icons/buddy_ignore.gif" width="16" height="16" border="0" alt="ignore user"></a>';
			else $buddy='<a href="buddys.php?action=add&id='.$dr[poster].'&userID='.$userID.'"><img src="images/icons/buddy_add.gif" width="16" height="16" border="0" alt="add to buddylist"></a>';
		}
		
		if(isonline($dr[poster])=="offline") $statuspic='<img src="images/icons/offline.gif" width="7" height="7" alt="offline">';
		else $statuspic='<img src="images/icons/online.gif" width="7" height="7" alt="online">';
		
		$sem = '^[http://]+[a-z0-9_\.-]+[a-z0-9_-]+$';
		if(!(eregi($sem, gethomepage($dr[poster])))) $hp='';
		else $hp='<a href="'.gethomepage($dr[poster]).'" target="_blank"><img src="images/icons/hp.gif" border="0" width="14" height="14" alt="homepage"></a>';
		
		if(!$dt[closed]) $quote='<a href="index.php?site=forum_topic&addreply=true&board='.$dt[boardID].'&topic='.$topic.'&quoteID='.$dr[postID].'&page='.$page.'&type='.$type.'"><img src="images/icons/quote.gif" border="0" alt="quote"></a>';
		
		$registered = getregistered($dr[poster]);
		
		$posts = getuserforumposts($dr[poster]);
		
		if(isforumadmin($dr[poster]) || isanymoderator($dr[poster])) {
		    if(isanymoderator($userID)) {
			    $usertype="Moderator";
			    $rang='<img src="images/icons/ranks/moderator.gif">';
			}
			if(isforumadmin($dr[poster])) {
			    $usertype="Administrator";
				$rang='<img src="images/icons/ranks/admin.gif">';
			}	
		}	
		else {
		    $ergebnis=safe_query("SELECT * FROM ".PREFIX."forum_ranks WHERE $posts >= postmin AND $posts <= postmax");
			$ds=mysql_fetch_array($ergebnis);
			$usertype=$ds[rank];
			$rang='<img src="images/icons/ranks/'.$ds[pic].'">';
		}
		
		$action='';
		if(($userID == $dr[poster] OR isforumadmin($userID) OR ismoderator($userID,$dt[boardID]))&& !$dt[closed]) $actions=' <a href="index.php?site=forum_topic&topic='.$topic.'&edit=true&id='.$dr[postID].'"><img src="images/icons/edit.gif" border="0" alt="edit"></a> ';
		if(isforumadmin($userID) OR ismoderator($userID,$dt[boardID])) $actions.='<input class="input" type="checkbox" name="postID[]" value="'.$dr[postID].'">';
		
		eval ("\$forum_topic_content = \"".gettemplate("forum_topic_content")."\";");
	    echo $forum_topic_content;
		unset($actions);
		$i++;
	}
	
	if(isforumadmin($userID) OR ismoderator($userID,$dt['boardID'])) {
	
		if($dt[closed]) $close='<option value="opentopic">- reopen topic</option>';
		else $close='<option value="closetopic">- close topic</option>';
		
		$adminactions='<input class="input" type="checkbox" name="ALL" value="ALL" onClick="SelectAll(this.form);"> select all <select name="admaction">
		               <option value="0">Admin-Actions:</option>
					   <option value="delposts">- delete selected posts</option>
					   <option value="stickytopic">- make topic sticky</option>
					   <option value="unstickytopic">- make topic unsticky</option>
					   <option value="movetopic">- move topic</option>
					   '.$close.'
					   <option value="deletetopic">- delete topic</option>
					   </select>
					   <input type="hidden" name="topicID" value="'.$topic.'">
					   <input type="hidden" name="board" value="'.$dt[boardID].'">
					   <input type="submit" name="submit" value="GO">';
					   
	}
					   
	eval ("\$forum_topic_foot = \"".gettemplate("forum_topic_foot")."\";");
	echo $forum_topic_foot;
	
	eval ("\$forum_topics_actions = \"".gettemplate("forum_topics_actions")."\";");
	echo $forum_topics_actions;
	
	echo'<div align="right">'.$adminactions.'</div></form>';
		     
	if($dt[closed]) {
	    echo'<img src="images/icons/closed.gif">'; 
	}
	else {
		if(!$loggedin && !$edit) {
			echo'To reply to this topic you have to be registered and logged in!<br><br>
				&#8226; <a href="index.php?site=register">register now</a><br>
				&#8226; <a href="index.php?site=login">log in</a>';
		}
	}  
}

function announcement($announcement, $delete, $edit) {
  global $userID;
	global $loggedin;
	global $picsize_l;
	
	$pagebg=PAGEBG;
	$border=BORDER;
	$bghead=BGHEAD;
	$bgcat=BGCAT;
	$bg1=BG_1;
	$bg2=BG_2;
	$bg3=BG_3;
	$bg4=BG_4;
	
	if($edit) {
    $ergebnis = safe_query("SELECT * FROM ".PREFIX."forum_announcements WHERE announceID='$announcement' ");
		$ds = mysql_fetch_array($ergebnis);

		eval ("\$addbbcode = \"".gettemplate("addbbcode")."\";");
		eval ("\$forum_announcement_edit = \"".gettemplate("forum_announcement_edit")."\";");
		echo $forum_announcement_edit;
	}
	else {
		$ergebnis = safe_query("SELECT * FROM ".PREFIX."forum_announcements WHERE announceID='$announcement' ");
		$ds = mysql_fetch_array($ergebnis);
		
		$topicname=cleartext($ds[topic]);

		$ergebnis = safe_query("SELECT * FROM ".PREFIX."forum_boards WHERE boardID='$ds[boardID]' ");
		$db = mysql_fetch_array($ergebnis);
		$dt[boardID]=$ds[boardID];
		$boardname = $db[name];
		$topic=$announcement;
		$posttype='announcement';
		$moderators=getmoderators($ds[boardID]);
		
		if($db[intern]) {
		    if(! isinternboarduser($userID)) die('You have no permission to view intern boards!<br><br>
			                                      <meta http-equiv="refresh" content="3;URL=index.php?site=forum">');
		}	 
			 
		eval ("\$forum_topics_title = \"".gettemplate("forum_topics_title")."\";");
		echo $forum_topics_title;
		
		eval ("\$forum_topic_head = \"".gettemplate("forum_topic_head")."\";");
		echo $forum_topic_head;
		
		echo '<br>';
		
		$date=date("d.m.Y", $ds[date]);
		$time=date("H:i", $ds[date]);
	
		$today=date("d.m.Y", time());
		$yesterday = date("d.m.Y", time()-3600*24);
			
		if($date==$today) $date="today";
		elseif($date==$yesterday && $date<$today) $date="yesterday";
		else $date=$date;
			
		$message=cleartext($ds[announcement]);
		$message = toggle($message, $ds[announceID]);
				
		$username=getnickname($ds[userID]);
		$member=' <img src="images/icons/member.gif" width="6" height="11" alt="Clanmember">';
		if(getavatar($ds[userID])) $avatar='<img src="images/avatars/'.getavatar($ds[userID]).'">';
		else $avatar='';
			
		if(getsignatur($ds[userID])) $signatur='<hr width="200" noshade color="'.BORDER.'" align="left" size="1">'.cleartext(getsignatur($ds[userID]));
		else $signatur='';
			
		if (getemail($ds[userID])) $email = '<a href="mailto:'.getemail($ds[userID]).'"><img src="images/icons/email.gif" border="0" width="15" height="11" alt="email"></a>';
		else $email='';
			
		if($loggedin && $ds[userID] != $userID) {
			$pm='<a href="index.php?site=messenger&action=touser&touser='.$ds[userID].'"><img src="images/icons/pm.gif" border="0" width="12" height="13" alt="messenger"></a>';
			if(isignored($userID, $ds[userID])) $buddy='<a href="buddys.php?action=readd&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_readd.gif" width="16" height="16" border="0" alt="back to buddy-list"></a>';
			elseif(isbuddy($userID, $ds[userID])) $buddy='<a href="buddys.php?action=ignore&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_ignore.gif" width="16" height="16" border="0" alt="ignore user"></a>';
			else $buddy='<a href="buddys.php?action=add&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_add.gif" width="16" height="16" border="0" alt="add to buddylist"></a>';
		}
			
		if(isonline($ds[userID])=="offline") $statuspic='<img src="images/icons/offline.gif" width="7" height="7" alt="offline">';
		else $statuspic='<img src="images/icons/online.gif" width="7" height="7" alt="online">';
			
		$sem = '^[http://]+[a-z0-9_\.-]+[a-z0-9_-]+$';
		if(!(eregi($sem, gethomepage($ds[userID])))) $hp='';
		else $hp='<a href="'.gethomepage($ds[userID]).'" target="_blank"><img src="images/icons/hp.gif" border="0" width="14" height="14" alt="homepage"></a>';
			
		$registered = getregistered($ds[userID]);
		$posts = getuserforumposts($ds[userID]);
			
		if(isforumadmin($ds[userID]) || isanymoderator($userID)) {
		    if(isanymoderator($userID)) {
			    $usertype="Moderator";
			    $rang='<img src="images/icons/ranks/moderator.gif">';
			}
			if(isforumadmin($ds[userID])) {
			    $usertype="Administrator";
				$rang='<img src="images/icons/ranks/admin.gif">';
			}	
		}	
		else {
		    $result=safe_query("SELECT * FROM ".PREFIX."forum_ranks WHERE $posts >= postmin AND $posts <= postmax");
			$dr=mysql_fetch_array($result);
			$usertype=$dr[rank];
			$rang='<img src="images/icons/ranks/'.$dr[pic].'">';
		}
		
		if(isforumadmin($userID)) $actions='<a href="index.php?site=forum_topic&announcement='.$announcement.'&edit=true"><img src="images/icons/edit.gif" border="0" alt="edit"></a>
		                                    <a href="forum_topic.php?board='.$ds[boardID].'&announcement='.$announcement.'&delete=true"><img src="images/icons/delete.gif" border="0" alt="delete"></a>';
		else $actions='';

		$bg1=BG_1;
		$bg2=BG_2;
		eval ("\$forum_topic_content = \"".gettemplate("forum_topic_content")."\";");
	    echo $forum_topic_content;
					   
		eval ("\$forum_topic_foot = \"".gettemplate("forum_topic_foot")."\";");
		echo $forum_topic_foot;
	}	
}
if($announcement) announcement($announcement, $delete, $edit);
else showtopic($topic, $edit, $id, $addreply, $quoteID, $type);

?>
