Umlaut Problem

myS4D

Grünschnabel
Hallo,

ich habe CMS (FusionCMS 5.4 ein reines WoW Server CMS) dort gibt es ein internes Forum.
Alle Umlaute auf der Homepage selbst werden korrekt dargestellt außer die im Forum, die Thread Namen werden noch korrekt dargestellt aber der Post selber sieht dann so aus:

Code:
ae = ä
oe = ö
ue = ü
sz = Ã?

Nun habe ich bei meinem Provider nachgefragt ob es eventuell an der MySQL liegt das er dort in einem anderen Format abspeichert aber er sagte es sei alles Positiv und es liegt nicht an der Datenbank. In der Datenbank selbst speichert er die Umlaute wie oben ab.

Der Provider sagte mir ich solle schauen ob der Foreneditor die Eingabe auch in UTF-8 abspeichert aber ich weiß nicht wo ich da genau nachsehen sollte.

Der CMS Entwickler gab mir folgenden Code:

Code:
$string = str_replace(array('Ö', 'ö', 'Ä', 'ä','Ü', 'ü', 'ß'), array('Ö', 'ö', 'Ä', 'ä', 'Ü', 'ü', 'ß'),

Diesen Code sollte ich in einer bestimmten Zeile in der der forum.php einfügen, auch das funktionierte nicht. Wie kann ich das Umlaut Problem nun beseitigen?

Hier nochmal die forum.php

PHP:
<?php 
class forum {
	var $c;
	var $db;
	var $rank = "guest";
	
	function __construct() {
		global $db, $logon;
		
		$this->c = mysql_pconnect($db['site']['host'], $db['site']['user'], $db['site']['pass']) or die("CMS: ".mysql_error());
		$this->db = $db['site']['db'];
		
		
		$this->change_viewing();
		
		if($logon->online) {
			$q = mysql_query("SELECT forum_reputation, forum_rank FROM ".$this->db.".account_info WHERE `user`='".$logon->username."'", $this->c);
			$r = mysql_fetch_assoc($q);
			
			$this->update_rank($r['forum_reputation'], $r['forum_rank']);
		}
	}
	
	function dc() {
		mysql_close($this->c);
	}
	
	function update_rank($c_rep, $c_rank, $user = "x") {
		global $ranks_reputation, $logon;
		
		if($user == "x") {
			$this->rank = $c_rank;
			
			if($ranks_reputation[$c_rank] != "-") {
			
				$top_rank['rep'] = 0;
				$top_rank['rank'] = "beginner";
				
				foreach($ranks_reputation as $rank => $rep) {
					if($c_rank != $rank && $rep != "-" && $c_rep >= $rep) {
						if($rep > $top_rank['rep']) {
							$top_rank['rep'] = $rep;
							$top_rank['rank'] = $rank;
						}
					}
				}
			
				if($top_rank['rank'] != $c_rank && $top_rank['rep'] > $ranks_reputation[$c_rank]) {
					mysql_query("UPDATE ".$this->db.".account_info SET forum_rank = '".$top_rank['rank']."' WHERE `user`='".$logon->username."'", $this->c);
					$this->rank = $top_rank['rank'];
				}
			}

		} else {
			if($ranks_reputation[$c_rank] != "-") {
			
				$top_rank['rep'] = 0;
				$top_rank['rank'] = "beginner";
				
				foreach($ranks_reputation as $rank => $rep) {
					if($c_rank != $rank && $rep != "-" && $c_rep >= $rep) {
						if($rep > $top_rank['rep']) {
							$top_rank['rep'] = $rep;
							$top_rank['rank'] = $rank;
						}
					}
				}
			
				if($top_rank['rank'] != $c_rank && $top_rank['rep'] > $ranks_reputation[$c_rank]) {
					mysql_query("UPDATE ".$this->db.".account_info SET forum_rank = '".$top_rank['rank']."' WHERE `user`='".$user."'", $this->c);
				}
			}
		}
	}
	
	function is_mod() {
		global $forum_ranks, $logon;
		
		if($forum_ranks[$this->rank] == "mod" && $logon->online) {
			return true;
		} else {
			return false;
		}
	}
	
	function title() {
		if(isset($_GET['f'])) {
			$f = $_GET['f'];
		} elseif(isset($_GET['p']) && $_GET['p'] == "forum") { 
			$f = "front";
		} else {
			$f = "none";
		}
		
		switch($f) {
			case "none": return ""; break;
			case "front": return ": Forum"; break;
			case "category":
				if(isset($_GET['id'])) {
					$q = mysql_query("SELECT name FROM ".$this->db.".forum_sub_categories WHERE id=".mysql_real_escape_string($_GET['id'])."", $this->c);
					$r = mysql_fetch_assoc($q);
					
					return ": ".$r['name'];
				} else {
					return "";
				}
			break;
			
			case "thread":
				if(isset($_GET['id'])) {
					$q = mysql_query("SELECT name FROM ".$this->db.".forum_threads WHERE id=".mysql_real_escape_string($_GET['id'])."", $this->c);
					$r = mysql_fetch_assoc($q);
					
					return ": ".$r['name'];
				} else {
					return "";
				}
			break;
		}
	}
	
	function frontpage() {
		global $logon, $staff_ranks, $dev_ranks, $acp_ranks;
		
		$cat = mysql_query("SELECT * FROM ".$this->db.".forum_categories ORDER BY id ASC", $this->c);
		$cat_r = mysql_fetch_assoc($cat);
		
		if(empty($cat_r['id']))
			die("Please create a forum");
		
		do {
			
			$display1[$cat_r['id']] = false;
					
					switch($cat_r['view_group']) {
						case "ALL":
							$display1[$cat_r['id']] = true;
						break;
						
						case "USERS":
							if($logon->online)
								$display1[$cat_r['id']] = true;
						break;
						
						case "GUESTS":
							if(!$logon->online)
								$display1[$cat_r['id']] = true;
						break;
						
						case "STAFF":
							if($logon->online && in_array($logon->rank,$staff_ranks))
								$display1[$cat_r['id']] = true;
						break;
						
						case "DEVELOPERS":
							if($logon->online && in_array($logon->rank,$dev_ranks))
								$display1[$cat_r['id']] = true;
						break;
						
						case "ADMINS":
							if($logon->online && in_array($logon->rank,$acp_ranks))
								$display1[$cat_r['id']] = true;
						break;
						
					}
					
			if($display1[$cat_r['id']]) {
			
				$category[$cat_r['id']] = '<div class="realm_button" style="text-align:left;padding-left:20px;width:96%;"><a href="#">'.$cat_r['name'].'</a></div>
									<table class="table" width="100%" style="font-size:10px;" >
										<tr class="stats_top" style="font-size:11px;">
											<td width="4%"></td>
											<td width="30%">Forum</td>
											<td width="15%">Threads</td>
											<td width="15%">Posts</td>
											<td>Last thread</td>
										</tr>';
			}
		} while($cat_r = mysql_fetch_assoc($cat));
		
		$s_cat = mysql_query("SELECT * FROM ".$this->db.".forum_sub_categories ORDER BY id ASC", $this->c);
		$s_cat_r = mysql_fetch_assoc($s_cat);
		
		if(empty($s_cat_r['id']))
			die("Please create a category");
		
		$threads = 0;
		$posts = 0;
		
		$odd_even = "even";
		
		do {
			if(isset($category[$s_cat_r['category']])) {
				
				$threads = $threads + $s_cat_r['threads'];
				$posts = $posts + $s_cat_r['posts'];
				
				if($display1[$s_cat_r['category']]) {
				
					if(empty($s_cat_r['latest_id'])) {
						$link[$s_cat_r['id']] = "#";
					} else {
						$link[$s_cat_r['id']] = '?p=forum&f=thread&id='.$s_cat_r['latest_id'];
					}
					
					if(empty($s_cat_r['latest_thread'])) {
						$last_thread = "-";
					} else {
						$last_thread = $s_cat_r['latest_thread'];
					}
					
					$category[$s_cat_r['category']] .= '<tr class="'.$odd_even.'">
												<td><img src="images/forum/'.$s_cat_r['icon'].'.png" /></td>
												<td><a href="?p=forum&f=category&id='.$s_cat_r['id'].'">'.$s_cat_r['name'].' 
													<div class="viewing">('.$this->get_viewing($s_cat_r['id']).' viewing)</div></a></td>
												<td>'.$s_cat_r['threads'].'</td>
												<td>'.$s_cat_r['posts'].'</td>
												<td><a href="'.$link[$s_cat_r['id']].'">'.stripslashes($last_thread).'</a></td>
											</tr>';
											
					if($odd_even == "odd") {
						$odd_even = "even";
					} elseif($odd_even == "even") {
						$odd_even = "odd";
					}
				}
			}
		} while($s_cat_r = mysql_fetch_assoc($s_cat));
		
		
		$all = "";
		
		if(!isset($category)) {
			$all .= "<center>Please log in!</center>";
		} else {
			foreach($category as $x) {
				$all .= $x."</table>";
			}
		}
		
		return '<div class="right_box">
							<div class="right_box_top">Discussion board</div>
							<div class="right_box_body">
								'.$all.'			
								<br /><br /><div class="forum_stats">The forum contains '.$threads.' threads and '.$posts.' posts.<br /></div>
								<div class="clear"></div>
							</div>
						</div>';
	}
	
	function category() {
		
		$s_cat = mysql_query("SELECT * FROM ".$this->db.".forum_sub_categories WHERE `id`='".mysql_real_escape_string($_GET['id'])."'", $this->c);
		$s_cat_r = mysql_fetch_assoc($s_cat);
		
		if(empty($s_cat_r['id']))
			die("Please create a category");
		
		
		$cat = mysql_query("SELECT * FROM ".$this->db.".forum_categories WHERE `id`='".$s_cat_r['category']."'", $this->c);
		$cat_r = mysql_fetch_assoc($cat);
		
		if(empty($cat_r['id']))
			die("Please create a forum");	
		
		global $logon, $staff_ranks, $dev_ranks, $acp_ranks;
			
			$display = false;
					
					switch($cat_r['view_group']) {
						case "ALL":
							$display = true;
						break;
						
						case "USERS":
							if($logon->online)
								$display = true;
						break;
						
						case "GUESTS":
							if(!$logon->online)
								$display = true;
						break;
						
						case "STAFF":
							if($logon->online && in_array($logon->rank,$staff_ranks))
								$display = true;
						break;
						
						case "DEVELOPERS":
							if($logon->online && in_array($logon->rank,$dev_ranks))
								$display = true;
						break;
						
						case "ADMINS":
							if($logon->online && in_array($logon->rank,$acp_ranks))
								$display = true;
						break;
						
					}
					
			if($display) {
				
				$display_post = false;
					
					switch($cat_r['thread_group']) {
						case "ALL":
							$display_post = true;
						break;
						
						case "USERS":
							if($logon->online)
								$display_post = true;
						break;
						
						case "GUESTS":
							if(!$logon->online)
								$display_post = true;
						break;
						
						case "STAFF":
							if($logon->online && in_array($logon->rank,$staff_ranks))
								$display_post = true;
						break;
						
						case "DEVELOPERS":
							if($logon->online && in_array($logon->rank,$dev_ranks))
								$display_post = true;
						break;
						
						case "ADMINS":
							if($logon->online && in_array($logon->rank,$acp_ranks))
								$display_post = true;
						break;
						
					}
					
				if($display_post) {
					$post_thread = '<a class="small_button" href="javascript:makeThread()" style="width:90px;margin-bottom:10px;">Make thread</a>';
				} else {
					$post_thread = '<a class="small_button" href="#" style="width:90px;margin-bottom:10px;">Locked</a>';
				}
				
				$rowsPerPage = 10;
				
				if(!isset($_GET['pg']) || !is_numeric($_GET['pg']) || $_GET['pg'] == 0) {
					$pg = 0;
					$cpg = 1;
				} else {
					$pg = ($_GET['pg']-1)*$rowsPerPage;
					$cpg = $_GET['pg'];
				}
				
				$result = mysql_query("SELECT COUNT(*) AS numrows FROM ".$this->db.".forum_threads WHERE category='".$s_cat_r['id']."'", $this->c) or die(mysql_error());
				$row = mysql_fetch_assoc($result);
				$numrows = $row['numrows'];

				$maxPage = ceil($numrows/$rowsPerPage);
			
				
				if($cpg > $maxPage && $cpg != 1) {
					header("Location: ?p=forum");
				}
				
				$navigation  = '';
				
				if($cpg != $maxPage && $maxPage != ($cpg-1)) { // not last page and last is not next
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=category&id='.$_GET['id'].'&pg='.$maxPage.'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.$maxPage.'</a></div>';
				}
				
				if($maxPage != ($cpg+2) && $maxPage != ($cpg+1) && $cpg != $maxPage && $maxPage != 0) { // if maxPage isn't +1, +2 or current, show dots
					$navigation .= '<div style="float:right;"><a class="small_button" href="#" style="width:20px;margin-bottom:10px;margin-right:3px;">...</a></div>';
				}
				
				if(($cpg+1) > 1 && ($cpg+1) < $maxPage) { // next page is greater than 1 and smaller than last page
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=category&id='.$_GET['id'].'&pg='.($cpg+1).'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.($cpg+1).'</a></div>';
				}
				
				// current page
				$navigation .= '<div style="float:right;"><a class="small_button_selected" href="?p=forum&f=category&id='.$_GET['id'].'&pg='.$cpg.'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.$cpg.'</a></div>';
				
				if(($cpg-1) < $maxPage && ($cpg-1) > 1 && ($cpg-1) != 0) { // previous page is smaller than last page
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=category&id='.$_GET['id'].'&pg='.($cpg-1).'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.($cpg-1).'</a></div>';
				}
				
				// if first page isn't -1, -2 or current, show dots
				if(1 != ($cpg-2) && 1 != ($cpg-1) && $cpg != 1) { // if first page isn't +1, +2 or current, show dots
					$navigation .= '<div style="float:right;"><a class="small_button" href="#" style="width:20px;margin-bottom:10px;margin-right:3px;">...</a></div>';
				}
				
				if($cpg != 1) { // not first page and first is not previous
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=category&id='.$_GET['id'].'&pg=1" style="width:20px;margin-bottom:10px;margin-right:3px;">1</a></div>';
				}
				
				$category  = '<div class="realm_button" style="text-align:left;padding-left:20px;width:96%;margin-bottom:30px;"><a href="?p=forum">'.$cat_r['name'].'</a> <a href="#">></a> <a href="?p=forum&f=category&id='.$s_cat_r['id'].'">'.$s_cat_r['name'].'</a></div>
				'.$navigation.'
				
				'.$post_thread.'
				
									<table class="table" width="100%" style="font-size:10px;" >
										<tr class="stats_top" style="font-size:11px;">
											<td width="30%">Thread</td>
											<td width="15%">Date</td>
											<td width="15%">Author</td>
											<td width="10%">Replies</td>
											<td width="10%">Views</td>
											<td width="20%">Last post</td>
										</tr>';
			}
		
			$threads = $s_cat_r['threads'];
			$posts = $s_cat_r['posts'];
			
			// sticky
			$s_threads_q = mysql_query("SELECT id, `name`, `date`, `author`, `replies`, `views`, `latest_when` FROM ".$this->db.".forum_threads WHERE `category`='".$s_cat_r['id']."' AND sticky='1' ORDER BY latest_time DESC", $this->c);
			$s_threads_r = mysql_fetch_assoc($s_threads_q);
			
			$odd_even = "even";
			
			if(!empty($s_threads_r['id'])) {
				do {
				
				$category .= '<tr class="'.$odd_even.'">
								<td><a href="?p=forum&f=thread&id='.$s_threads_r['id'].'"><span style="color:red;">[Sticky]</span> '.stripslashes($s_threads_r['name']).'</a></td>
								<td>'.$s_threads_r['date'].'</td>
								<td><a href="#'.$s_threads_r['author'].'">'.$s_threads_r['author'].'</a></td>
								<td>'.$s_threads_r['replies'].'</td>
								<td>'.$s_threads_r['views'].'</td>
								<td>'.$s_threads_r['latest_when'].'</td>
							</tr>';
				} while($s_threads_r = mysql_fetch_assoc($s_threads_q));
				
				if($odd_even == "odd") {
					$odd_even = "even";
				} elseif($odd_even == "even") {
					$odd_even = "odd";
				}
			}
			
			// regular
			$threads_q = mysql_query("SELECT id, `name`, `date`, `author`, `replies`, `views`, `latest_when` FROM ".$this->db.".forum_threads WHERE `category`='".$s_cat_r['id']."' AND sticky != '1' ORDER BY latest_time DESC LIMIT ".$pg.", $rowsPerPage", $this->c);
			$threads_r = mysql_fetch_assoc($threads_q);
			
			if(!empty($threads_r['id'])) {
				do {
				
				$category .= '<tr class="'.$odd_even.'">
								<td><a href="?p=forum&f=thread&id='.$threads_r['id'].'">'.stripslashes($threads_r['name']).'</a></td>
								<td>'.$threads_r['date'].'</td>
								<td><a href="#'.$threads_r['author'].'">'.$threads_r['author'].'</a></td>
								<td>'.$threads_r['replies'].'</td>
								<td>'.$threads_r['views'].'</td>
								<td>'.$threads_r['latest_when'].'</td>
							</tr>';
							
					if($odd_even == "odd") {
						$odd_even = "even";
					} elseif($odd_even == "even") {
						$odd_even = "odd";
					}
				} while($threads_r = mysql_fetch_assoc($threads_q));
			}
		
		
			$all = "";
		
			$all .= $category."</table>";
		
		return '<div id="preview_spot"></div><div class="right_box">
							<div class="right_box_top" id="headline">Discussion board</div>
							<div class="right_box_body" id="forum_ajax">
								<div id="category_content">'.$all.'			
								<br /><br /><div class="forum_stats">This category contains '.$threads.' threads and '.$posts.' posts.<br /></div>
								</div>
								'.$this->create_thread($s_cat_r['category']).'
								<div class="clear"></div>
							</div>
						</div>';
	}
	
	function create_thread($cat) {
		global $logon;
		
		if(!$logon->online) {
			$user = '<tr>
					<td style="padding-left:10px;">Username:</td>
					<td style="padding-right:10px;">
						<input type="text" name="thread_user" id="thread_user" style="width:98%;"/>
					</td>
				</tr>';
		} else {
			$mycolor = '<div style="float:right;font-size:10px;padding:2px;padding-right:20px;">'.$this->get_text_color($logon->username, 1, 'Your default text color ').' <a href="?p=forum_settings">(change)</a></div>';
		}
		
		
		return '<div id="create_thread" style="display:none;">
		<form action="?p=forum&createthread='.$cat.'" method="post">
			<table class="table" width="100%" >
				'.@$user.'
				<tr>
					<td style="padding-left:10px;">Thread title:</td>
					<td style="padding-right:10px;">
						<input type="text" name="thread_title" id="thread_title" style="width:100%;"/>
					</td>
				</tr>
			</table>
			<table class="table" width="100%" >
				<tr>
					<td style="padding-left:10px;padding-right:10px;">'.@$mycolor.'
						<script>edToolbar("thread_editor");</script>
						<textarea style="width:100%;height:300px" name="thread_editor" id="thread_editor" class="ed"></textarea>
					</td>
				</tr>
				</table>
				<center>
					<input type="button" value="Submit" style="width:150px;" onClick="submitThread()"/> <input type="button" value="Preview" style="width:150px;" onClick="previewThread()"/><input type="hidden" id="thread_category" value="'.$_GET['id'].'"/>
				</center>
			</form>
		</div>';
	}
	
	function thread() {
		global $cms;
		$id = mysql_real_escape_string($_GET['id']);
		
		$q = mysql_query("SELECT id, category, name, message, date, author, author_real, sticky, closed FROM ".$this->db.".forum_threads WHERE id='".$id."'", $this->c);
		$r = mysql_fetch_assoc($q);
		
		if(empty($r['name'])) {
			header("Location: ?p=forum");
		} else {
			mysql_query("UPDATE ".$this->db.".forum_threads SET views = views + 1 WHERE id='".$id."'", $this->c);
			
			$rowsPerPage = 5;
				
			if(!isset($_GET['pg']) || !is_numeric($_GET['pg']) || $_GET['pg'] == 0) {
				$pg = 0;
				$cpg = 1;
			} else {
				$pg = ($_GET['pg']-1)*$rowsPerPage;
				$cpg = $_GET['pg'];
			}
				
			if($cpg == 1) {
				$out = '<div id="mod_move"></div><div class="right_box">
							<div class="right_box_top" id="headline">'.stripslashes($r['name']).'</div>
							<div class="right_box_body" id="forum_spot">
							<table width="100%" id="thread_'.$r['id'].'" class="forum_thread" >
								<tr>
									'.$this->side_profile($r['author'], $r['author_real'], $r['id'], 1, $r['sticky'], $r['closed']).'
									<td id="thread_content" class="forum_right" valign="top" width="77%">
									<div style="float:right;padding:5px;"><a href="#to_editor" onClick="quoteMessage(\''.base64_encode($r['message']).'\')" class="small_button">Quote</a></div>
									'.$this->get_text_color($r['author'], $r['author_real'],stripslashes(bb($r['message']))).'
									'.$this->get_signature($r['author'], $r['author_real']).'
									<br /><br />
									</td>
								</tr>
							</table>
								'.$this->posts($r['id'], $r['category'], $r['closed']).'
								<div class="clear"></div>
							</div>
						</div>';
				} else {
					$out = '<div class="right_box">
							<div class="right_box_top" id="headline">'.stripslashes($r['name']).'</div>
							<div class="right_box_body" id="forum_spot">
								'.$this->posts($r['id'], $r['category'], $r['closed']).'
								<div class="clear"></div>
							</div>
						</div>';
				}
				
			return $out;
		}
	}
	
	function posts($thread, $cat, $closed) {
		global $logon, $staff_ranks, $dev_ranks, $acp_ranks;
		
		$rowsPerPage = 5;
				
				if(!isset($_GET['pg']) || !is_numeric($_GET['pg']) || $_GET['pg'] == 0) {
					$pg = 0;
					$cpg = 1;
				} else {
					$pg = ($_GET['pg']-1)*$rowsPerPage;
					$cpg = $_GET['pg'];
				}
				
				$result = mysql_query("SELECT COUNT(*) AS numrows FROM ".$this->db.".forum_posts WHERE `thread`='".mysql_real_escape_string($_GET['id'])."'", $this->c) or die(mysql_error());
				$row = mysql_fetch_assoc($result);
				$numrows = $row['numrows'];

				$maxPage = ceil($numrows/$rowsPerPage);
				
				if($cpg > $maxPage && $cpg != 1) {
					header("Location: ?p=forum");
				}
				
				$navigation  = '';
				
				if($cpg != $maxPage && $maxPage != ($cpg-1)) { // not last page and last is not next
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=thread&id='.$_GET['id'].'&pg='.$maxPage.'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.$maxPage.'</a></div>';
				}
				
				if($maxPage != ($cpg+2) && $maxPage != ($cpg+1) && $cpg != $maxPage && $maxPage != 0) { // if maxPage isn't +1, +2 or current, show dots
					$navigation .= '<div style="float:right;"><a class="small_button" href="#" style="width:20px;margin-bottom:10px;margin-right:3px;">...</a></div>';
				}
				
				if(($cpg+1) > 1 && ($cpg+1) < $maxPage) { // next page is greater than 1 and smaller than last page
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=thread&id='.$_GET['id'].'&pg='.($cpg+1).'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.($cpg+1).'</a></div>';
				}
				
				// current page
				$navigation .= '<div style="float:right;"><a class="small_button_selected" href="?p=forum&f=thread&id='.$_GET['id'].'&pg='.$cpg.'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.$cpg.'</a></div>';
				
				if(($cpg-1) < $maxPage && ($cpg-1) > 1 && ($cpg-1) != 0) { // previous page is smaller than last page
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=thread&id='.$_GET['id'].'&pg='.($cpg-1).'" style="width:20px;margin-bottom:10px;margin-right:3px;">'.($cpg-1).'</a></div>';
				}
				
				// if first page isn't -1, -2 or current, show dots
				if(1 != ($cpg-2) && 1 != ($cpg-1) && $cpg != 1) { // if first page isn't +1, +2 or current, show dots
					$navigation .= '<div style="float:right;"><a class="small_button" href="#" style="width:20px;margin-bottom:10px;margin-right:3px;">...</a></div>';
				}
				
				if($cpg != 1) { // not first page and first is not previous
					$navigation .= '<div style="float:right;"><a class="small_button" href="?p=forum&f=thread&id='.$_GET['id'].'&pg=1" style="width:20px;margin-bottom:10px;margin-right:3px;">1</a></div>';
				}
		
		$posts_q = mysql_query("SELECT * FROM ".$this->db.".forum_posts WHERE `thread`='".mysql_real_escape_string($_GET['id'])."' ORDER BY `time` ASC LIMIT ".$pg.", $rowsPerPage", $this->c);
			
			$posts_r = mysql_fetch_assoc($posts_q);
			
			$out = "";
			
			if(!empty($posts_r['id'])) {
				do {
				
				$out .= '<table width="100%" id="post_'.$posts_r['id'].'" class="forum_post" >
								<tr>
									'.$this->side_profile($posts_r['author'], $posts_r['author_real'], $posts_r['id'], 0).'
									<td id="post_content" class="forum_right" valign="top" width="77%">
									<div style="float:right;padding:5px;"><a href="#to_editor" onClick="quoteMessage(\''.base64_encode($posts_r['message']).'\')" class="small_button">Quote</a></div>
									'.$this->get_text_color($posts_r['author'], $posts_r['author_real'], stripslashes(bb($posts_r['message']))).'	
									'.$this->get_signature($posts_r['author'], $posts_r['author_real']).'
									<br /><br />
									</td>
								</tr>
							</table>';
							
				} while($posts_r = mysql_fetch_assoc($posts_q));
			}
							
		$s_cat_q = mysql_query("SELECT category FROM ".$this->db.".forum_sub_categories WHERE id='".$cat."'", $this->c);
		$s_cat_r = mysql_fetch_assoc($s_cat_q);
		
		$cat_q = mysql_query("SELECT post_group FROM ".$this->db.".forum_categories WHERE id='".$s_cat_r['category']."'", $this->c);
		$cat_r = mysql_fetch_assoc($cat_q);
		
		$display = false;
					
					switch($cat_r['post_group']) {
						case "ALL":
							$display = true;
						break;
						
						case "USERS":
							if($logon->online)
								$display = true;
						break;
						
						case "GUESTS":
							if(!$logon->online)
								$display = true;
						break;
						
						case "STAFF":
							if($logon->online && in_array($logon->rank,$staff_ranks))
								$display = true;
						break;
						
						case "DEVELOPERS":
							if($logon->online && in_array($logon->rank,$dev_ranks))
								$display = true;
						break;
						
						case "ADMINS":
							if($logon->online && in_array($logon->rank,$acp_ranks))
								$display = true;
						break;
						
					}
		
		if($display) {

			if($logon->online) {
				$guest_name = '<input type="hidden" value="user" id="user" />';
			} else {
				$guest_name = '<table class="table" width="100%">
								<tr>
									<td>
										Username:
									</td>
									<td>
										<input type="text" id="user" style="width:98%;"/>
									</td>
								</tr>
								</table>';
			}
			
			if($logon->online) {
				$text_color = '<div style="float:right;font-size:10px;padding:2px;padding-right:20px;">'.$this->get_text_color($logon->username, 1, 'Your default text color ').' <a href="?p=forum_settings">(change)</a></div>';
			}
			
			if(!$closed)
			{
				$out .='<div id="my_post">
						'.$guest_name.'
						<input type="hidden" id="thread" value="'.$_GET['id'].'" readonly="true" />
						<table class="table" width="100%" >
								<tr>
									<td>
										'.@$text_color.'<script>edToolbar("thread_editor");</script>
										<div style="text-align:center;"><textarea style="width:665px;height:150px" name="thread_editor" id="thread_editor" class="ed"></textarea></div>
									</td>
								</tr>
								</table>
								<input type="button" value="Post reply!" style="width:150px;" onClick="submitPost()"/></div><a name="to_editor"></a>';
			}
			else
			{
				$out .= 'The thread is closed. You can\'t reply.';
			}
		}
		
		return $out.$navigation;
	}
	
	function get_signature($user, $real) {
		if(forum_signatures) {
			if($real == 0) {
				return '';
			} else {
				$q = mysql_query("SELECT forum_signature FROM ".$this->db.".account_info WHERE `user`='".$user."'", $this->c);
				$r = mysql_fetch_assoc($q);
				if(!empty($r['forum_signature'])) {
					return '<div class="forum_signature">'.bb($r['forum_signature']).'</div>';
				} else {
					return '';
				}
			}
		}
	}
	
	function get_text_color($user, $real, $string) {
		if($real == 0) {
			return $string;
		} else {
			$q = mysql_query("SELECT forum_text_color FROM ".$this->db.".account_info WHERE `user`='".$user."'", $this->c);
			$r = mysql_fetch_assoc($q);
			
			if(!empty($r['forum_text_color']) && ctype_alnum($r['forum_text_color'])) {
				return '<span style="color:#'.$r['forum_text_color'].';">'.$string.'</span>';
			} else {
				return $string;
			}
		}
	}
	
	function side_profile($user, $real, $post, $thread, $sticky = 0, $closed = 0) {
		global $logon;
		
		if($real == 1) {
			$q = mysql_query("SELECT * FROM ".$this->db.".account_info WHERE `user`='".$user."'", $this->c);
			$r = mysql_fetch_assoc($q);
			
			$rank = $r['forum_rank'];
			$posts = $r['forum_posts'];
			
			$avatar = $r['forum_avatar'];
			
			if(empty($avatar))
			{
				$avatar = "theme/".theme."/images/noavatar.jpg";
			}
			
			$location = $r['forum_country'];
			$rank = $r['forum_rank'];
			$rep = $r['forum_reputation'];
			
			$this->update_rank($rep, $rank, $user);
			
			if(!empty($location)) {
				$loc = '<div class="forum_info"><table width="100%" ><tr><td width="13%"><img src="images/icons/world.png" /> </td><td width="40%"><b> Location:</b></td><td width="47%">'.htmlentities($location).'</td></tr></table></div>';
			}
			
			if($logon->online && $user != $logon->username) {
				$tools = '<div style="height:10px;"></div>
			<div class="forum_info"><table width="100%" ><tr><td><img src="images/icons/accept.png" /> </td><td width="87%"><b><a href="javascript:addReputation(\''.$user.'\', '.$post.', '.$thread.')">Add reputation</a><span id="rep_ajax_'.$post.'_'.$thread.'"></span></b></td></tr></table></div>
			<div class="forum_info"><table width="100%" ><tr><td><img src="images/icons/error.png" /> </td><td width="87%"><b><a href="javascript:reportPost('.$post.', '.$thread.')">Report post</a></b></td></tr></table></div>';
	
				/*---------------
				USER PM FUNCTION
				HAS BEEN DISABLED
				DUE TO LACK OF
				DEVELOPMENT TIME
				-----------------
$pm = '<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/email.png" /> </td><td width="87%"><b><a href="javascript:sendPm(\''.$user.'\')">Send message</a></b></td></tr></table></div>';
				*/

			}
			
			return '<td class="forum_left">
			<div class="forum_user"><a href="#'.$user.'" style="color:'.$this->rank_to_color($rank).';">'.$user.'</a></div>
			<div class="forum_avatar"><a href="#'.$user.'"><img src="'.$avatar.'" height="100" width="100" border="0"/></a></div>
			<div class="forum_rank"><img src="images/ranks/'.$rank.'.jpg" /></div>
			'.@$loc.'
			<div class="forum_info"><table width="100%" ><tr><td><img src="images/icons/comment.png" /> </td><td width="40%"><b> Posts:</b></td><td width="47%">'.$posts.'</td></tr></table></div>
			'.@$tools.@$pm.$this->mod_tools($post, $user, $thread, $sticky, $closed).'
			</td>';
		} else {
			if($logon->online) {
				$tools = '<div style="height:10px;"></div>
			<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/error.png" /> </td><td width="87%"><b><a href="javascript:reportPost('.$post.', '.$thread.')">Report post</a></b></td></tr></table></div>';
			}
			
			$rank = "guest";
			
			return '<td class="forum_left">
			<div class="forum_user"><span style="color:'.$this->rank_to_color($rank).';">'.$user.'</span></div>
			<div class="forum_avatar"><img src="theme/'.theme.'/images/noavatar.jpg" height="100" width="100" border="0"/></div>
			<div class="forum_rank"><img src="images/ranks/'.$rank.'.jpg" /></div>
			'.@$tools.$this->mod_tools($post, $user, $thread, $sticky, $closed).'
			</td>';
		}
	}
	
	private function mod_tools($post, $user, $is_thread, $sticky = 0, $closed)
	{
		$tools = '';
		
		if($this->is_mod())
		{
			if($is_thread == 1)
			{
				if($sticky == 1)
				{
					$sticky = '<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/medal_gold_delete.png" /> </td><td width="87%"><b><a href="javascript:stickyThread('.$post.', 0)">Remove sticky</a></b></td></tr></table></div>';
				}
				else
				{
					$sticky = '<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/medal_gold_add.png" /> </td><td width="87%"><b><a href="javascript:stickyThread('.$post.', 1)">Sticky thread</a></b></td></tr></table></div>';
				}
				
				if($closed == 1)
				{
					$closed = '<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/accept.png" /> </td><td width="87%"><b><a href="javascript:closeThread('.$post.', 0)">Open thread</a></b></td></tr></table></div>';
				}
				else
				{
					$closed = '<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/error.png" /> </td><td width="87%"><b><a href="javascript:closeThread('.$post.', 1)">Close thread</a></b></td></tr></table></div>';
				}
				
				
				$tools .= '<div style="height:10px;"></div>
					<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/comments_delete.png" /> </td><td width="87%"><b><a href="javascript:removePost('.$post.', '.$is_thread.', 1, 0)">Remove thread</a></b></td></tr></table></div>
					
					<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/page_go.png" /> </td><td width="87%"><b><a href="javascript:moveThread('.$post.')">Move thread</a></b></td></tr></table></div>
					
					'.$sticky.$closed;
			}
			elseif($is_thread == 2)
			{ 
				// ?
			}
			else
			{
				$tools .= '<div style="height:10px;"></div>
					<div class="forum_info"><table width="100%"><tr><td><img src="images/icons/comment_delete.png" /> </td><td width="87%"><b><a href="javascript:removePost('.$post.', '.$is_thread.', 1, 0)">Remove post</a></b></td></tr></table></div>';
			}
			return $tools;
		}
		else
		{
			return '';
		}
	}
	
	function rank_to_color($rank) {
		global $rank_colors;
			
		return $rank_colors[$rank];
	}
	
	function change_viewing() {
		$q = mysql_query("SELECT * FROM ".$this->db.".forum_viewing WHERE `ip`='".$_SERVER['REMOTE_ADDR']."'", $this->c);
		$r = mysql_fetch_assoc($q);
		
		if(isset($_GET['p']) && $_GET['p'] == "forum" && isset($_GET['f']) && $_GET['f'] == "category" && isset($_GET['id'])) {
			$page = mysql_real_escape_string($_GET['id']);
		} else {
			$page = "";
		}
		
		if($r['time']+recent_time < time() || $r['category'] != $page) {
		
			if(empty($r['ip'])) {
				mysql_query("INSERT INTO ".$this->db.".forum_viewing VALUES('".$_SERVER['REMOTE_ADDR']."', '".time()."', '".$page."')", $this->c);
			} else {
				mysql_query("UPDATE ".$this->db.".forum_viewing SET `time`='".time()."', `category`='".$page."' WHERE `ip` = '".$_SERVER['REMOTE_ADDR']."'", $this->c);
			}
		}
	}
	
	function get_viewing($cat) {
		$q = mysql_query("SELECT COUNT(*) AS viewing FROM ".$this->db.".forum_viewing WHERE `category`='".$cat."' AND `time` > '".(time() - recent_time)."'", $this->c) or die(mysql_error());
		$r = mysql_fetch_assoc($q);
		
		return $r['viewing'];
	}
	
	function ajax()
	{
		if(isset($_POST['ajax']))
		{
			switch($_POST['ajax'])
			{
				case 1:  $this->submitThread();                  break;
				case 2:  $this->reportPost();                    break;
				case 3:  $this->modDelete();                     break;
				case 4:  $this->submitPost();                    break;
				case 5:  $this->addReputation();                 break;
				case 6:  $this->modBan();                        break;
				case 7:  $this->previewThread();                 break;
				case 8:  $this->saveSettings();                  break;
				case 9:  $this->modDelete(); $this->modIgnore(); break;
				case 10: $this->modIgnore();                     break;
				case 11: $this->moveThread();                    break;
				case 12: $this->do_moveThread();                 break;
				case 13: $this->stickyThread();                  break;
				case 14: $this->closeThread();                  break;
			}
		}
	}
	
	private function moveThread()
	{
		if($this->is_mod())
		{
			$q = mysql_query("SELECT * FROM ".$this->db.".forum_sub_categories ORDER BY id ASC", $this->c);
			$r = mysql_fetch_assoc($q);
			
			$list = "";
			
			do
			{
				$list .= "<option value='".$r['id']."'>".$r['name']."</option>";
			}
			while($r = mysql_fetch_assoc($q));
			
			echo "<center>Select which category the thread should be moved to: <select id='move_thread_to'>".$list."</select><input type='hidden' id='move_thread_id' value='".$_POST['id']."' /><br /> <input type='button' value='Move thread!' onClick='do_moveThread()'/></center>";
		}
	}
	
	private function do_moveThread()
	{
		if($this->is_mod())
		{			
			$id = $_POST['id'];
			$to = $_POST['to'];
			
			$q = mysql_query("SELECT replies, category, name FROM ".$this->db.".forum_threads WHERE id='".$id."'", $this->c) or die(mysql_error());
			$r = mysql_fetch_assoc($q);
			
			mysql_query("UPDATE ".$this->db.".forum_threads SET category = '".$to."' WHERE id = '".$id."'", $this->c) or die(mysql_error());
			mysql_query("UPDATE ".$this->db.".forum_sub_categories SET threads = threads + 1, posts = posts + ".$r['replies']." WHERE id = '".$to."'", $this->c) or die(mysql_error());
			mysql_query("UPDATE ".$this->db.".forum_sub_categories SET threads = threads - 1, posts = posts - ".$r['replies']." WHERE id = '".$r['category']."'", $this->c) or die(mysql_error());
			
			$q2 = mysql_query("SELECT latest_thread FROM ".$this->db.".forum_sub_categories WHERE id='".$r['category']."'", $this->c) or die(mysql_error());
			$r2 = mysql_fetch_assoc($q2);
			
			if($r2['latest_thread'] == $r['name'])
			{
				mysql_query("UPDATE ".$this->db.".forum_sub_categories SET latest_thread = '-' WHERE id = '".$r['category']."'", $this->c) or die(mysql_error());
			}
			
			$q3 = mysql_query("SELECT latest_thread FROM ".$this->db.".forum_sub_categories WHERE id='".$to."'", $this->c) or die(mysql_error());
			$r3 = mysql_fetch_assoc($q3);
			
			if($r3['latest_thread'] == "-")
			{
				mysql_query("UPDATE ".$this->db.".forum_sub_categories SET latest_thread = '".$r['name']."', latest_id = '".$id."' WHERE id = '".$to."'", $this->c) or die(mysql_error());
			}
			
			die("Thread has been moved. Click <a href='?p=forum'>here</a> to go back to the forum index.");
		}
	}
	
	private function stickyThread()
	{
		if($this->is_mod())
		{			
			$id = $_POST['id'];
			$s = $_POST['s'];
			
			if(is_numeric($s))
			{
				mysql_query("UPDATE ".$this->db.".forum_threads SET sticky = '".$s."' WHERE id = '".$id."'", $this->c) or die(mysql_error());
			
				if($s == 0)
				{
					die("Sticky has been removed!");
				}
				else
				{
					die("Thread has been stickied!");
				}
			}
		}
	}
	
	private function closeThread()
	{
		if($this->is_mod())
		{			
			$id = $_POST['id'];
			$s = $_POST['s'];
			
			if(is_numeric($s))
			{
				mysql_query("UPDATE ".$this->db.".forum_threads SET closed = '".$s."' WHERE id = '".$id."'", $this->c) or die(mysql_error());
			
				if($s == 0)
				{
					die("Thread has been re-opened");
				}
				else
				{
					die("Thread has been closed");
				}
			}
		}
	}
	
	function modDelete() {
		global $logon;
		
		if($logon->online && $this->is_mod()) {
			$id = mysql_real_escape_string($_POST['id']);
			$is_thread = mysql_real_escape_string($_POST['is_thread']);
			
			if($is_thread == 1) {
				
				$q = mysql_query("SELECT category, replies FROM ".$this->db.".forum_threads WHERE id='".$id."' LIMIT 1", $this->c) or die(mysql_error());
				$r = mysql_fetch_assoc($q);
				
				mysql_query("DELETE FROM ".$this->db.".forum_threads WHERE id='".$id."'", $this->c);
				
				$q2 = mysql_query("SELECT name, id, latest_time FROM ".$this->db.".forum_threads WHERE category='".$r['category']."' ORDER BY latest_time DESC LIMIT 1", $this->c) or die(mysql_error());
				$r2 = mysql_fetch_assoc($q2);
				
				mysql_query("UPDATE ".$this->db.".forum_sub_categories SET threads = threads - 1, posts = posts - ".$r['replies'].", latest_when = '".$r2['latest_time']."', latest_thread='".$r2['name']."', latest_id='".$r2['id']."' WHERE id='".$r['category']."'", $this->c);
				
				mysql_query("DELETE FROM ".$this->db.".forum_posts WHERE thread='".$id."'", $this->c);
				
			} else {
				$q2 = mysql_query("SELECT thread FROM ".$this->db.".forum_posts WHERE id='".$id."'", $this->c) or die(mysql_error());
				
				$r2 = mysql_fetch_assoc($q2);
				
				
				$q = mysql_query("SELECT category, id FROM ".$this->db.".forum_threads WHERE id='".$r2['thread']."'", $this->c) or die(mysql_error());
				
				$r = mysql_fetch_assoc($q);
				
				mysql_query("UPDATE ".$this->db.".forum_threads SET replies = replies - 1 WHERE id='".$r['id']."'", $this->c);
				mysql_query("UPDATE ".$this->db.".forum_sub_categories SET posts = posts - 1 WHERE id='".$r['category']."'", $this->c);
				
				mysql_query("DELETE FROM ".$this->db.".forum_posts WHERE id='".$id."'", $this->c);
		
			}
		}
	}
	
	function submitThread() {
		global $logon, $staff_ranks, $dev_ranks, $acp_ranks;
		
		$title = mysql_real_escape_string(htmlspecialchars($_POST['title']));
		$content = mysql_real_escape_string($_POST['content']);
		$category = mysql_real_escape_string($_POST['category']);
		
		if(strlen($title) < 5) {
			die("Title must contain more than 5 characters.");
		}
		
		if(strlen($content) < 15) {
			die("Thread must contain more than 15 characters.");
		}
		
		if($logon->online) {
			$user = $logon->username;
			$real = 1;
		} else {
			$user = mysql_real_escape_string($_POST['user']);
			$real = 0;
			
			if(strlen($user) > 15) {
				die("Guest username can't be more than 15 characters.");
			}
		}
		
		$s_c_q = mysql_query("SELECT id, category FROM ".$this->db.".forum_sub_categories WHERE id='".$category."' LIMIT 1", $this->c);
		$s_c_r = mysql_fetch_assoc($s_c_q);
		
		if(empty($s_c_r['id'])) {
			die("Category doesn't exist");
		} else {
			
			$c_q = mysql_query("SELECT thread_group FROM ".$this->db.".forum_categories WHERE id='".$s_c_r['category']."' LIMIT 1", $this->c);
			$c_r = mysql_fetch_assoc($c_q);
			
			$display = false;
					
					switch($c_r['thread_group']) {
						case "ALL":
							$display = true;
						break;
						
						case "USERS":
							if($logon->online)
								$display = true;
						break;
						
						case "GUESTS":
							if(!$logon->online)
								$display = true;
						break;
						
						case "STAFF":
							if($logon->online && in_array($logon->rank,$staff_ranks))
								$display = true;
						break;
						
						case "DEVELOPERS":
							if($logon->online && in_array($logon->rank,$dev_ranks))
								$display = true;
						break;
						
						case "ADMINS":
							if($logon->online && in_array($logon->rank,$acp_ranks))
								$display = true;
						break;
						
					}
					
			if(!$display) {
				die("You don't have the required permission to start threads in this category.");
			} else {
				mysql_query("INSERT INTO ".$this->db.".forum_threads(`category`, `name`, `message`, `date`, `author`, `author_real`, `latest_when`, `latest_time`) 
							VALUES('".$category."', '".htmlspecialchars($title)."', '".$content."', '".date("Y-m-d")."', '".$user."', '".$real."', '".date("Y-m-d H:i")."', '".time()."')", $this->c) 
							or die("Something went wrong, please try again!");
							
				$my_t = mysql_query("SELECT id FROM ".$this->db.".forum_threads WHERE author='".$user."' AND author_real='".$real."' AND name='".$title."'", $this->c) or die(mysql_error());
				$my_r = mysql_fetch_assoc($my_t);
			
										
				mysql_query("UPDATE ".$this->db.".forum_sub_categories SET latest_thread='".$title."', latest_id='".$my_r['id']."', latest_when='".date("Y-m-d H:i")."', threads=threads+1 WHERE id='".$category."'", $this->c) or die(mysql_error());
				
				if($real == 1) {
					mysql_query("UPDATE ".$this->db.".account_info SET forum_threads = forum_threads +1, forum_posts = forum_posts +1 WHERE `user`='".$user."'", $this->c) or die(mysql_error());
				}
					
				die("<script type='text/javascript'>window.location='?p=forum&f=thread&id=".$my_r['id']."'</script>");
				
			}	
		}
	}
	
	function submitPost() {
		global $logon, $staff_ranks, $dev_ranks, $acp_ranks;
		
		$thread = mysql_real_escape_string($_POST['thread']);
		$content = mysql_real_escape_string($_POST['content']);
			
		if(!is_numeric($thread)) {
			die("Thread id must be a number.");
		}
		
		if(strlen($content) < 5) {
			die("Post must contain more than 5 characters.");
		}
		
		if($logon->online) {
			$user = $logon->username;
			$real = 1;
		} else {
			$user = mysql_real_escape_string($_POST['user']);
			$real = 0;
			
			if(strlen($user) > 15) {
				die("Guest username can't be more than 15 characters.");
			}
		}
		
		$t_q = mysql_query("SELECT category FROM ".$this->db.".forum_threads WHERE id='".$thread."' LIMIT 1", $this->c) or die("Thread doesn't exist.");
		$t_r = mysql_fetch_assoc($t_q);
		
		$s_c_q = mysql_query("SELECT id, category FROM ".$this->db.".forum_sub_categories WHERE id='".$t_r['category']."' LIMIT 1", $this->c);
		$s_c_r = mysql_fetch_assoc($s_c_q);
		
		if(empty($s_c_r['id'])) {
			die("Category doesn't exist");
		} else {
			
			$c_q = mysql_query("SELECT post_group FROM ".$this->db.".forum_categories WHERE id='".$s_c_r['category']."' LIMIT 1", $this->c);
			$c_r = mysql_fetch_assoc($c_q);
			
			$display = false;
					
					switch($c_r['post_group']) {
						case "ALL":
							$display = true;
						break;
						
						case "USERS":
							if($logon->online)
								$display = true;
						break;
						
						case "GUESTS":
							if(!$logon->online)
								$display = true;
						break;
						
						case "STAFF":
							if($logon->online && in_array($logon->rank,$staff_ranks))
								$display = true;
						break;
						
						case "DEVELOPERS":
							if($logon->online && in_array($logon->rank,$dev_ranks))
								$display = true;
						break;
						
						case "ADMINS":
							if($logon->online && in_array($logon->rank,$acp_ranks))
								$display = true;
						break;
						
					}
					
			if(!$display) {
				die("You don't have the required permission to post in this category.");
			} else {
				
				$last_q = mysql_query("SELECT id, message, author, author_real FROM ".$this->db.".forum_posts WHERE thread='".$thread."' ORDER BY id DESC LIMIT 1", $this->c);
				$last = mysql_fetch_assoc($last_q);
				
				if(empty($last['author'])) {
					$can_post = true;
				} else {
					if($last['author'] != $logon->username) {
						$can_post = true;
					} else {
						if($last['author'] == $logon->username && $real != $last['author_real']) {
							$can_post = true;
						} else {
							$can_post = false;
						}
					}
				}
				
				if($can_post) {
					mysql_query("INSERT INTO ".$this->db.".forum_posts(`thread`, `message`, `author`, `author_real`, `time`) 
								VALUES('".$thread."', '".$content."', '".$user."', '".$real."', '".time()."')", $this->c) 
								or die("Something went wrong, please try again!");
				
											
					mysql_query("UPDATE ".$this->db.".forum_threads SET latest_time='".time()."', latest_when='".date("Y-m-d H:i")."', replies = replies + 1 WHERE id='".$thread."'", $this->c) or die(mysql_error());
					
					mysql_query("UPDATE ".$this->db.".forum_sub_categories SET posts = posts + 1 WHERE id='".$t_r['category']."'", $this->c) or die(mysql_error());
					
					if($real == 1) {
						mysql_query("UPDATE ".$this->db.".account_info SET forum_posts = forum_posts +1 WHERE `user`='".$user."'", $this->c) or die(mysql_error());
					} 
				} else {
					# AUTO MERGER
					mysql_query("UPDATE ".$this->db.".forum_posts SET message='".$last['message']."\n\n".$content."' WHERE id='".$last['id']."'", $this->c);
				}
				
				die('<table width="100%" id="post_new" class="forum_post">
									<tr>
										'.$this->side_profile($user, $real, $thread, 0).'
										<td id="post_content" class="forum_right" valign="top" width="77%">	'.$this->get_text_color($user, $real, stripslashes(bb($content))).'
										'.$this->get_signature($user, $real).'
										<br /><br />
										</td>
									</tr>
								</table>');
				
			}
		}
	}
	
	function previewThread() {
		global $logon;
		
		$content = mysql_real_escape_string($_POST['content']);
		$thread = 0;
		
		if($logon->online) {
			$real = 1;
			$user = $logon->username;
		} else {
			$real = 0;
			$user = mysql_real_escape_string($_POST['user']);
		}
		
		echo '<table width="100%" id="post_new" class="forum_post">
								<tr>
									'.$this->side_profile($user, $real, $thread, 2).'
									<td id="post_content" class="forum_right" valign="top" width="77%">	'.$this->get_text_color($user, $real, stripslashes(bb($content))).'
									'.$this->get_signature($user, $real).'
									<br /><br />
									</td>
								</tr>
							</table>';
	}
	
	function reportPost() {
		global $logon;
		
		if($logon->online) {
			$reason = mysql_real_escape_string($_POST['reason']);
			$id = mysql_real_escape_string($_POST['id']);
			$is_thread = mysql_real_escape_string($_POST['is_thread']);
			
			if(is_numeric($id)) {
				mysql_query("INSERT INTO ".$this->db.".forum_reports(post_id, reason, thread, reporter) VALUES('".$id."', '".$reason."', '".$is_thread."', '".$logon->username."')", $this->c);
			}
		}
	}
	
	function addReputation() {
		global $logon;
		
		if($logon->online) {
			$from = $logon->username;
			$to = mysql_real_escape_string($_POST['user']);
			$post = mysql_real_escape_string($_POST['id']);
			$is_thread = mysql_real_escape_string($_POST['is_thread']);
			
			
			$q = mysql_query("SELECT COUNT(*) AS total FROM ".$this->db.".forum_reputation WHERE `from` = '".$from."' AND `post`='".$post."' AND is_thread='".$is_thread."'",$this->c) or die(mysql_error());
			$r = mysql_fetch_assoc($q);
			
			$q2 = mysql_query("SELECT COUNT(*) AS total FROM ".$this->db.".forum_reputation WHERE `from` = '".$from."' AND `time` > ".(time()-60*60*24)."",$this->c) or die(mysql_error());
			$r2 = mysql_fetch_assoc($q2);
			
			$q3 = mysql_query("SELECT COUNT(*) AS total FROM ".$this->db.".forum_reputation WHERE `from` = '".$from."' AND `to`='".$to."' AND `time` > ".(time()-60*30)."",$this->c) or die(mysql_error());
			$r3 = mysql_fetch_assoc($q3);
			
			if($r['total'] == 0 && $r2['total'] < daily_reputation_cap && $r3['total'] == 0) {
				
				mysql_query("INSERT INTO ".$this->db.".forum_reputation(`from`, `to`, `time`, `post`, `is_thread`) VALUES('".$from."', '".$to."', '".time()."', '".$post."', '".$is_thread."')", $this->c) or die("Something went wrong, please try again (debug: 1)");
				
				mysql_query("UPDATE ".$this->db.".account_info SET forum_reputation = forum_reputation + 1 WHERE `user`='".$to."'", $this->c) or die("Something went wrong, please try again (debug: 1)");
				
				echo "Reputation has been given to ".$to."! \n\nYou have spent ".($r2['total']+1)." of ".daily_reputation_cap." reputation points today.";
			} else {
				echo "You were not able to give reputation for this post. \n\nThis depends on the following:\n\n-You have given out more than ".daily_reputation_cap." reputation points today.\n-You have already given this post reputation.\n-You have already given ".$to." reputation within the last 30 minutes.";
			}
		}
	}
	
	function settings() {
		global $logon;
		
		if($logon->online) {
			$q = mysql_query("SELECT forum_country, forum_text_color, forum_avatar, forum_signature FROM ".$this->db.".account_info WHERE `user`='".$logon->username."'", $this->c);
			$r = mysql_fetch_assoc($q);
			
			if(empty($r['forum_avatar']))
			{
				$r['forum_avatar'] = "theme/".theme."/images/noavatar.jpg";
			}
			
			$out = '<div class="right_box">
								<div class="right_box_top" id="headline">Forum user settings</div>
								<div class="right_box_body" id="forum_spot">
									<table class="table" width="550px" id="register">
										<tr>
											<td style="padding-left:20px;">Location:</td>
											<td>
												<input type="text" id="forum_location" value="'.@$r['forum_country'].'" maxlength="9"/>
											</td>
										</tr>
										<tr>
											<td style="padding-left:20px;">Default color:</td>
											<td>
												<input type="text" id="forum_color" value="'.@$r['forum_text_color'].'" maxlength="6"/>
											</td>
										</tr>
										<tr>
											<td style="padding-left:20px;">Avatar:</td>
											<td>
											<div style="margin:10px;" class="forum_avatar"><img src="'.@$r['forum_avatar'].'" width="100" height="100" /></div>
											<div style="font-size:10px;padding:10px;padding-top:0px;">Current: <a href="'.@$r['forum_avatar'].'" target="_blank">here</a></div>
												<input type="text" id="forum_avatar" value="'.@$r['forum_avatar'].'" maxlength="255"/>
											</td>
										</tr>
										';
										
			if(forum_signatures) {
				$out .= '<tr>
											<td style="padding-left:20px;">Signature: (bbcode enabled)</td>
											<td>
												<input type="text" id="forum_signature" value="'.@$r['forum_signature'].'" maxlength="100"/>
											</td>
										</tr>';
										
			}
			$out .= '</table><center>
									<input type="button" value="Change!" onClick="saveForumSettings()" />
								</center><br /><br /><div id="ajax_spot" style="text-align:center;"></div>
	
								<div class="clear"></div>
								</div>
							</div>';
			return $out;
		}
	}
	
	function isImage($url) {
		// http://stackoverflow.com/questions/676949/best-way-to-determine-if-a-url-is-an-image-in-php
		// ^ thank you :)
		
		if($url = "theme/".theme."/images/noavatar.jpg") {
			return true;
		} else {
		
			$params = array('http' => array(
						'method' => 'HEAD'
					));
			$ctx = stream_context_create($params);
			$fp = @fopen($url, 'rb', false, $ctx);
			if (!$fp) 
				return false;  // Problem with url
		
			$meta = stream_get_meta_data($fp);
			if ($meta === false)
			{
				fclose($fp);
				return false;  // Problem reading data from url
			}
		
			$wrapper_data = $meta["wrapper_data"];
			if(is_array($wrapper_data)){
				foreach(array_keys($wrapper_data) as $hh){
					if (substr($wrapper_data[$hh], 0, 19) == "Content-Type: image") // strlen("Content-Type: image") == 19 
					{
						fclose($fp);
						return true;
					}
				}
			}
		
			fclose($fp);
			return false;
		}
	}
  
	function saveSettings() {
		global $logon;
		
		if($logon->online) {
			$location = mysql_real_escape_string($_POST['location']);
			$color = mysql_real_escape_string($_POST['color']);
			$avatar = mysql_real_escape_string($_POST['avatar']);
			
			if(forum_signatures)
			{
				$signature = mysql_real_escape_string($_POST['signature']);
			}
			else
			{
				$signature = "";
			}
		
			if(strlen($location) > 9) {
				die("Location may not exceed 9 characters.");
			}
			
			if(strlen($color) > 6) {
				die("Color may not exceed 6 characters.");
			}
			
			if(strlen($signature) > 100) {
				die("Signature may not exceed 100 characters.");
			}
			
			if(!$this->isImage($avatar)) {
				die("Avatar is not a valid image.");
			}
			
			mysql_query("UPDATE ".$this->db.".account_info SET forum_country = '".$location."', forum_text_color='".$color."', forum_avatar='".$avatar."', forum_signature='".$signature."' WHERE `user`='".$logon->username."'", $this->c) or die("Something went wrong, please try again!");
			
			echo "Your settings have been updated!";
		}
	}
	
	function modPanel() {
		global $logon;
		
		if($logon->online && $this->is_mod()) {
			$q = mysql_query("SELECT * FROM ".$this->db.".forum_reports ORDER BY id ASC", $this->c);
			$r = mysql_fetch_assoc($q);
		
			$post_or_thread = array(0 => "post", 1 => "thread");
		
			$out = '<div class="right_box">
								<div class="right_box_top" id="headline">Manage forum reports</div>
								<div class="right_box_body" id="forum_spot">
										<table class="table" width="100%">
											<tr class="stats_top">
												<td>Reported post</td>
												<td>Reason</td>
												<td>Reporter</td>
												<td>Moderator tools</td>
											</tr>';
											
			if(!empty($r['id'])) {
				do {		
					$out .= '<tr id="'.$post_or_thread[$r['thread']].'_'.$r['post_id'].'">
									<td valign="top">'.$this->get_text_from_id($r['post_id'], $r['thread']).'</td>
									<td valign="top" width="15%">'.stripslashes($r['reason']).'</td>
									<td valign="top" width="10%">'.$r['reporter'].'</td>
									<td valign="top" width="23%">
										<table style="border-bottom:1px dotted #999;" width="100%">
											<tr>
												<td width="10%"><img src="images/icons/comment_delete.png" /></td>
												<td><a href="javascript:removePost('.$r['post_id'].','. $r['thread'].', 2, '.$r['id'].')">Delete post</a></td>
											</tr>
										</table>
										<table>
											<tr>
												<td width="10%"><img src="images/icons/error_delete.png" /></td>
												<td><a href="javascript:mod_ignore('.$r['id'].', '.$r['post_id'].','. $r['thread'].')">Ignore report</a></td>
											</tr>
										</table>
									</td>
								</tr>';
				} while($r = mysql_fetch_assoc($q));
			}
			
			$out .= '</table>
							<div class="clear"></div>
						</div>
					</div>';
					
			return $out;
		} else {
			return '<center>No access</center>';
		}
	}
	
	function get_text_from_id($id, $is_thread) {
		if($is_thread == 1) {
			$q = mysql_query("SELECT message FROM ".$this->db.".forum_threads WHERE id='".$id."'", $this->c);
			$r = mysql_fetch_assoc($q);
			
			return $r['message'];
		} else {
			$q = mysql_query("SELECT message FROM ".$this->db.".forum_posts WHERE id='".$id."'", $this->c);
			$r = mysql_fetch_assoc($q);
			
			return $r['message'];
		}
	}
	
	function modIgnore() {
		global $logon;
		
		if($logon->online && $this->is_mod()) {
			$id = mysql_real_escape_string($_POST['report_id']);
			
			mysql_query("DELETE FROM ".$this->db.".forum_reports WHERE id='".$id."'", $this->c);
		}
	}
}
?>
 
Wow! es gibt also immernoch CMS welche in Spaghetti-Code geschrieben sind....
Wie sieht denn die Besagte Zeile aus welche dir dein Programmierer geschrieben hat?
Ich hab jetzt keine Lust mir nen Wolf zu suchen in der riesen Datei....
 
Zwei Dinge, die simpel zu überprüfen sind:

(A) Mit welcher Kodierung will Dein Browser die Seite anzeigen?
(B) Kannst Du das Problem mit manuell ausgewählter Kodierung verhindern?
(C) Mit welcher Kodierung ist zB forum.php gespeichert?

mfg chmee
 

Neue Beiträge

Zurück