Location: PHPKode > projects > WH Community > wh_community/topic.php
<?php require('layout/header.php'); ?>

    <script type="text/javascript">
    	function insert(was) {
    	document.topic.reply.value += was + " ";
    	document.topic.reply.focus();
    	}
    </script>

<div id="content_wrapper">
    <div class="content"><?php

		if((isset($_GET['id'])) && (is_numeric($_GET['id']))) {
		
		$id = mysql_real_escape_string($_GET['id']);
		$id = intval($_GET['id']);
	
			}else{
			
			echo '<p align="center" class="false">' . $lang['invalid_id'] . '!</p>';
			exit();
			}

		include_once('functions/bbcode.php');
		include_once('functions/badwords.php');
		
		$sql = "SELECT
					topics.topic_id,
					topics.topic_subject,
					topics.topic_cat,
					categories.cat_id,
					categories.cat_name
				FROM
					topics
				LEFT JOIN
					categories
				ON
					topics.topic_cat = categories.cat_id
				WHERE
					topic_id = " . $id;
		
		$result = mysql_query($sql) OR die(mysql_error());
		
		$id = mysql_real_escape_string($_GET['id']);
		$id = intval($_GET['id']);
		
		if(!$result) {
		
		echo '<p class="false">' . $lang['no_topic'] . '.</p>';
		
			}else{
			
			if(intval(mysql_num_rows($result)) == 0) {
			
			echo '<p class="false">' . $lang['no_topic'] . '.</p>';
		
		}else{
		
		while($row = mysql_fetch_assoc($result)) {
		
    		$viewsql = "UPDATE
    						topics
    					SET
    						topic_views = topic_views + 1
    					WHERE
    						topic_id = " . $id;
    		
    		$viewcount = mysql_query($viewsql) OR die(mysql_error());
		
		echo '<table width="100%" cellpadding="5" class="cleantable">
    		  <tr>
    		  <td width="70%" valign="top"><a href="' . $index . '">Forum</a> &raquo;&nbsp;<a href="category.php?id=' . $row['cat_id'] . '">' . htmlentities($row['cat_name'], ENT_QUOTES) . '</a> &raquo;&nbsp;<span class="blue">' . ((strlen($row['topic_subject'])<6) ? $row['topic_subject'] : substr($row['topic_subject'],0,50).'') . '</span></td>
    		  <td width="30%" align="right" valign="top"><a href="rss.php" target="_blank"><img src="images/rss.png" hspace="7"></a> <span class="topic_tags"><a href="create.php?id=' . $row['cat_id'] . '" class="topic_tags">' . $lang['new_topic'] . '</a></span></td>
    		  </tr>';
    	echo '<tr>
              <td align="right" colspan="2">';
              
    	$pfad = $_SERVER['PHP_SELF'];
		$query = mysql_query("SELECT post_topic FROM posts WHERE post_topic = '" . $id . "'") OR die(mysql_error());
		$total = intval(mysql_num_rows($query));
		$seiten = ceil($total / $datensaetze_pro_seite);

		if(empty($_GET['page'])) {
			$page = 1;

		}elseif($_GET['page'] <= 0 || $_GET['page'] > $seiten) {
			$page = 1;

			}else{

			$page = mysql_real_escape_string($_GET['page']);
			}

		$links = array();

		if(($page - $p) < 1){ $davor = $page - 1;  }else { $davor = $p; }
		if(($page + $p) > $seiten){ $danach = $seiten - $page; }else{ $danach = $p; }
			$off = ($page - $davor);

		if($page- $davor > 1) {
			$first = 1;
			$links[] = '<a href="topic.php?id=' . $row['topic_id'] . '&page=' . $first . '" title="' . $lang['goto_first_page'] . '" class="topicby">&laquo; ' . $lang['first'] . ' ...</a>';
			}

		if($page != 1) {
			$prev = $page-1;
			$links[] = '<a href="topic.php?id=' . $row['topic_id'] . '&page=' . $prev . '" title="' . $lang['page_back'] . '" class="topicby"> &laquo;</a>';
			}

		for($i = $off; $i <= ($page + $danach); $i++) {
		if($i != $page) {
			$links[] = '<a href="topic.php?id=' . $row['topic_id'] . '&page=' . $i . '" class="topicby">' . $i . '</a>';

		}elseif($i == $seiten) {
			$links[] = '<span class="current_main">' . $i . '</span>';

		}elseif($i == $page) {
			$links[] = '<span class="current_main">' . $i . '</span>';
			}
		}

		if($page != $seiten) {
			$next = $page+1;
			$links[] = '<a href="topic.php?id=' . $row['topic_id'] . '&page=' . $next . '" title="' . $lang['next_page'] . '" class="topicby"> &raquo;</a>';
			}

		if($seiten - $page - $p > 0 ) {
			$last = $seiten;
			$links[] = '<a href="topic.php?id=' . $row['topic_id'] . '&page=' . $last . '" title="' . $lang['last_page'] . '" class="topicby">... ' . $lang['last'] . ' &raquo;</a>';
			}

		$start = ($page-1) * $datensaetze_pro_seite;
		$site_links = implode(" ", $links);
    	
    	echo $site_links;
        echo '</td></tr>
    		  </table>';
		
		echo '<table width="100%" cellpadding="5" class="maintable">';
		
		$pfad = $_SERVER['PHP_SELF'];
		$query = mysql_query("SELECT post_topic FROM posts WHERE post_topic = '" . $id . "'") OR die(mysql_error());
		$total = intval(mysql_num_rows($query));
		$seiten = ceil($total / $datensaetze_pro_seite);
		
		if(empty($_GET['page'])) {
			$page = 1;
		
		}elseif($_GET['page'] <= 0 || $_GET['page'] > $seiten) {
			$page = 1;
		
			}else{
			
			$page = mysql_real_escape_string($_GET['page']);
			}
		
		$links = array();
		
		if(($page - $p) < 1){ $davor = $page - 1;  }else { $davor = $p; }            
		if(($page + $p) > $seiten){ $danach = $seiten - $page; }else{ $danach = $p; }    
			$off = ($page - $davor);
		
		if($page- $davor > 1) {
			$first = 1;
			$links[] = '<a href="topic.php?id=' . (int)$row['topic_id'] . '&page=' . $first . '" title="' . $lang['goto_first_page'] . '">&laquo; ' . $lang['first'] . ' ...</a>';
			}
		
		if($page != 1) {
			$prev = $page-1;
			$links[] = '<a href="topic.php?id=' . (int)$row['topic_id'] . '&page=' . $prev . '" title="' . $lang['page_back'] . '"> &laquo;</a>';
			}
		
		for($i = $off; $i <= ($page + $danach); $i++) {
		if($i != $page) {
			$links[] = '<a href="topic.php?id=' . (int)$row['topic_id'] . '&page=' . $i . '">' . $i . '</a>';
		
		}elseif($i == $seiten) {
			$links[] = '<span class="current">[ <u>' . $i . '</u> ]</span>';  
		
		}elseif($i == $page) {
			$links[] = '<span class="current">[ <u>' . $i . '</u> ]</span>';
			}
		}                
		
		if($page != $seiten) {
			$next = $page+1;
			$links[] = '<a href="topic.php?id=' . $row['topic_id'] . '&page=' . $next . '" title="' . $lang['next_page'] . '"> &raquo;</a>';
			}
		
		if($seiten - $page - $p > 0 ) {
			$last = $seiten; 
			$links[] = '<a href="topic.php?id=' . $row['topic_id'] . '&page=' . $last . '" title="' . $lang['last_page'] . '">... ' . $lang['last'] . ' &raquo;</a>';
			}
		
		$start = ($page-1) * $datensaetze_pro_seite;
		$link_string = implode(" ", $links);
		
		$posts_sql = "SELECT
						  posts.post_topic,
						  posts.post_content,
						  posts.post_date,
						  posts.post_by,
						  users.user_id,
						  users.user_name,
						  users.user_date,
						  users.user_level,
						  users.user_signature,
						  users.user_avatar
					  FROM
						  posts
					  LEFT JOIN
						  users
					  ON
						  posts.post_by = users.user_id
					  WHERE
						  posts.post_topic = '" . $id . "'
					  LIMIT
						  $start,$datensaetze_pro_seite";
		
		$posts_result = mysql_query($posts_sql) OR die(mysql_error());
		
		if(!$posts_result) {
		
		echo '<tr><td><p class="false">' . $lang['post_not_exists'] . '.</p></td></tr>
		      </table>';
		
		}else{
		
		while($posts_row = mysql_fetch_assoc($posts_result)) {

    		echo '<tr>
    		      <td width="17%" valign="top"><br>'; if($posts_row['user_avatar'] == '') {
    			     echo '<img src="images/avatars/default.png">';
    		      }else{
    			     echo '<img src="images/avatars/' . htmlentities($posts_row['user_avatar'], ENT_QUOTES) . '">'; }
            echo '<p><a href="profile.php?user_id=' . (int)$posts_row['user_id'] . '">' . htmlentities($posts_row['user_name'], ENT_QUOTES) . '</a><br><br>';
    		echo '<small>'; if($posts_row['user_level'] == 0) {
    			echo '<span class="user">User</span>';
    		}elseif($posts_row['user_level'] == 2) {
    			echo '<span class="mod">Moderator</span>';
    		}elseif($posts_row['user_level'] == 1) {
    			echo '<span class="admin">Administrator</span>'; }
    		echo '<br><span class="blue_small">' . $lang['member_since'] . ':</span> ';
            
            if($language == "de") {
                echo date('d.m.Y', strtotime($posts_row['user_date']));
    
            }elseif($language == "en") {
                echo date('Y-m-d', strtotime($posts_row['user_date'])); }
            
            echo '</small></p></td>
    		      <td width="83%" valign="top"><p>' . parseBBCode2HTML(delBad(nl2br(stripslashes($posts_row['post_content'])))) . '</p></td>
    		      </tr>
    		      <tr>
    		      <td width="17%">&nbsp;</td>
    		      <td width="83%">'; if($posts_row['user_signature']) {
                      echo '<div id="line">&nbsp;</div><small>' . stripslashes(strip_tags($posts_row['user_signature'])) . '</small>';
                  }elseif($posts_row['user_signature']== "") {
    		          echo ''; }
            echo '</td></tr>
    		      <tr>
    		      <td class="signature_left" align="left"><img src="images/post.png" border="0">&nbsp;&nbsp;<small>';
            
            if($language == "de") {
                echo date('d.m.Y - H:i', strtotime($posts_row['post_date']));
    
            }elseif($language == "en") {
                echo date('Y-m-d - H:i', strtotime($posts_row['post_date'])); }
            
    		echo '</small></td>
                  <td class="signature_right" align="right">
    		      <a href="#reply"><img src="images/icons/answer.png" border="0" title="' . $lang['to_answer'] . '"></a>&nbsp;&nbsp;&nbsp;<a href="profile.php?user_id=' . $posts_row['user_id'] . '"><img src="images/icons/profile.png" border="0" title="' . $lang['user_profile'] . '"></a>&nbsp;&nbsp;&nbsp;<a href="#top"><img src="images/icons/top.png" border="0" title="Top"></a></td>
    		      </tr>';
    		}
    	
    	echo '</table>';
		
		echo '<br><div id="navigation">
		      <span class="pages">' . $lang['page'] . ' <u>' . $page . '</u> ' . $lang['by'] . ' ' . $seiten . '</span>';
		echo $link_string;
		echo '</div>';				
		}
		
        echo '<br>';
		
		if(!isset($_SESSION['signed_in'])) {
		
		echo '<a name="reply" id="reply"></a><br>
              <h1>' . $lang['want_to_answer'] . '</h1>
              ' . $lang['you_need_to'] . ' <a href="signin.php">' . $lang['signin_s'] . '</a>. - ' . $lang['not_yet'] . ' <a href="signup.php">' . $lang['registered'] . '</a>?<br><br>';
		
			}else{
			
			include_once('functions/flood.php');
			
			echo "<a name=\"reply\" id=\"reply\"></a><br>
                  <h1><img src=\"images/write.png\"> " . $lang['to_answer'] . "</h1><br>
    			  <form name=\"topic\" method=\"post\" action=\"reply.php?id=" . $row['topic_id'] . "\">
    			  <a href=\"javascript:insert('[b][/b]','')\"><img border=\"0\" src=\"images/bbcode/bold.png\" title=\"" . $lang['bold'] . "\"></a><a href=\"javascript:insert('[i][/i]','')\"><img border=\"0\" src=\"images/bbcode/italic.png\" title=\"" . $lang['italic'] . "\"></a><a href=\"javascript:insert('[u][/u]','')\"><img border=\"0\" src=\"images/bbcode/underline.png\" title=\"" . $lang['underline'] . "\"></a><a href=\"javascript:insert('[url]http://[/url]','')\"><img border=\"0\" src=\"images/bbcode/link.png\" title=\"" . $lang['url_with'] . "\"></a><br>
    			  <textarea name=\"reply\" class=\"fields_text\"></textarea><br>
    			  <p><small>" . $lang['spam_protection_question'] . " *</small><br>
    			  <strong>" . $lang['sum_of'] . " " . $random1 . " + " . $code . " =</strong> <input size=\"5\" name=\"zip\" id=\"Spamschutz\" type=\"text\" class=\"fields\" /><input type=\"hidden\" name=\"zip2\" value=" . $rand_result . "></p>
    			  <p><input type=\"submit\" class=\"button\" value=\"" . $lang['to_answer'] . "\" alt=\"" . $lang['to_answer'] . "\"></p>
    			  </form>";
        
        }}}}
		
        echo '<div class="spacer_div">&nbsp;</div>';

		?>
	</div>
</div>

<div id="infobox_wrapper">
    <div class="infobox">
        <?php include('layout/infobox.php'); ?>
    </div>
</div>

<?php require('layout/footer.php'); ?>
Return current item: WH Community