Codechange: Klassen im Tabellenkopf eingefügt und via CSS dazugehörige Breitenangaben...
[wmmkf.git] / board_entry.php
blob268e8f4711a0b63f292be7cfd86e24ffe58cf100
1 <?php
2 ###############################################################################
3 # my little forum #
4 # Copyright (C) 2005 Alex #
5 # http://www.mylittlehomepage.net/ #
6 # #
7 # This program is free software; you can redistribute it and/or #
8 # modify it under the terms of the GNU General Public License #
9 # as published by the Free Software Foundation; either version 2 #
10 # of the License, or (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program; if not, write to the Free Software #
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
20 ###############################################################################
22 include("inc.php");
23 include_once("functions/include.prepare.php");
26 function nav_b($be_page, $entries_per_page, $entry_count, $id, $da, $page, $category, $order, $descasc) {
27 global $lang, $select_submit_button;
29 $output = '';
31 if ($entry_count > $entries_per_page)
33 # entry_count
34 # $entries_per_page
35 # $be_page
36 # $id
37 # $da
38 # $page
39 # $category
40 # $order
41 # $descasc
42 # number of pages for the thread
43 $countPages = ceil($entry_count / $entries_per_page);
44 # start: output
45 $output .= '&nbsp;&nbsp;';
46 $new_index_before = $be_page - 1;
47 $new_index_after = $be_page + 1;
48 if ($new_index_before >= 0)
50 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?&amp;id='.$id.'&amp;be_page=';
51 $output .= $new_index_before.'&amp;da='.$da.'&amp;page='.$page;
52 $output .= ($category > 0) ? '&amp;category='.$category : '';
53 $output .= '&amp;order='.$order.'&amp;descasc='.$descasc.'" title="';
54 $output .= outputLangDebugInAttributes($lang['previous_page_linktitle']).'"><img src="img/prev.png" alt="&laquo;"';
55 $output .= 'width="12" height="9" onmouseover="this.src=\'img/prev_mo.png\';"';
56 $output .= ' onmouseout="this.src=\'img/prev.png\';" /></a>';
58 if ($new_index_before >= 0 && $new_index_after < $countPages)
60 $output .= '&nbsp;';
62 if ($new_index_after < $countPages)
64 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?&amp;id='.$id.'&amp;be_page=';
65 $output .= $new_index_after.'&amp;da='.$da.'&amp;page='.$page;
66 $output .= ($category > 0) ? '&amp;category='.$category : '';
67 $output .= '&amp;order='.$order.'&amp;descasc='.$descasc.'" title="';
68 $output .= outputLangDebugInAttributes($lang['next_page_linktitle']).'"><img src="img/next.png" alt="&laquo;"';
69 $output .= 'width="12" height="9" onmouseover="this.src=\'img/next_mo.png\';"';
70 $output .= ' onmouseout="this.src=\'img/next.png\';" /></a>';
72 $output .= '&nbsp;<form method="get" action="'.$_SERVER["SCRIPT_NAME"].'"';
73 $output .= ' title="'.outputLangDebugInAttributes($lang['choose_page_formtitle']).'">';
74 $output .= "\n".'<div class="inline-form">'."\n";
75 if (isset($id))
77 $output .= '<input type="hidden" name="id" value="'.$id.'">'."\n";
79 if (isset($da))
81 $output .= '<input type="hidden" name="da" value="'.$da.'">'."\n";
83 $output .= '<input type="hidden" name="page" value="'.$page.'">'."\n";
84 if ($category > 0)
86 $output .= '<input type="hidden" name="category" value="'.$category.'">'."\n";
88 $output .= '<input type="hidden" name="order" value="'.$order.'">'."\n";
89 $output .= '<input type="hidden" name="descasc" value ="'.$descasc.'">'."\n";
90 $output .= '<select class="kat" size="1" name="be_page" onchange="this.form.submit();">'."\n";
91 $output .= '<option value="0"';
92 $output .= ($be_page == 0) ? ' selected="selected"' : '';
93 $output .= '>1</option>'."\n";
94 for ($a = 1; $a < $countPages; $a++)
96 $output .= '<option value="'.$a.'"';
97 $output .= ($be_page == $a) ? ' selected="selected"' : '';
98 $output .= '>'.($a + 1).'</option>'."\n";
100 $output .= '</select>'."\n".'<noscript><p class="inline-form">&nbsp;<input type="image" name="" value="" src="img/submit.png" alt="&raquo;" /></p></noscript>'."\n".'</div>'."\n".'</form>'."\n";
102 return $output;
103 } # End: nav_b
105 if (!isset($_SESSION[$settings['session_prefix'].'user_id'])
106 && isset($_COOKIE['auto_login'])
107 && isset($settings['autologin'])
108 && $settings['autologin'] == 1)
110 $id = isset($_GET['id']) ? 'id='.intval($_GET['id']) : '';
111 if (!empty($id))
113 $lid = '&'.$id;
114 $did = '&amp;'.$id;
116 header("location: ".$settings['forum_address']."login.php?referer=board_entry.php".$lid);
117 die("<a href=\"login.php?referer=board_entry.php".$did."\">further...</a>");
120 if ($settings['access_for_users_only'] == 1
121 && isset($_SESSION[$settings['session_prefix'].'user_name'])
122 || $settings['access_for_users_only'] != 1)
125 if (empty($page)) $page = 0;
126 if (empty($order)) $order = "last_answer";
127 if (empty($descasc)) $descasc = "DESC";
128 $category = empty($category) ? 0 : intval($category);
129 $be_page = (empty($_GET['be_page'])) ? 0 : intval($_GET['be_page']);
130 if (empty($da)) $da = "ASC";
131 $ul = $be_page * $settings['answers_per_topic'];
133 unset($entrydata);
134 unset($thread);
136 if (isset($id))
138 $id = (int) $id;
139 if ($id > 0)
141 $firstPostingQuery = "SELECT
143 tid,
144 pid,
145 user_id,
146 DATE_FORMAT(time + INTERVAL ".$time_difference." HOUR, '".$lang['time_format_sql']."') AS posting_time,
147 UNIX_TIMESTAMP(time) AS time,
148 UNIX_TIMESTAMP(edited + INTERVAL ".$time_difference." HOUR) AS e_time,
149 UNIX_TIMESTAMP(edited - INTERVAL ".$settings['edit_delay']." MINUTE) AS edited_diff,
150 edited_by,
151 user_id,
152 name,
153 email,
154 subject,
156 place,
157 text,
158 show_signature,
159 category,
160 locked,
161 INET_NTOA(ip_addr) AS ip_address
162 FROM ".$db_settings['forum_table']."
163 WHERE id = ".$id." LIMIT 1";
164 $result_t = mysql_query($firstPostingQuery, $connid);
165 $thread = mysql_fetch_assoc($result_t);
166 mysql_free_result($result_t);
168 # Look if id correct:
169 if ($thread['pid'] != 0)
171 header("location: ".$settings['forum_address']."board_entry.php?id=".$thread['tid']."&page=".$page."&category=".$category."&order=".$order."&descasc=".$descasc."#p".$id);
174 # category of this posting accessible by user?
175 if (!(isset($_SESSION[$settings['session_prefix'].'user_type'])
176 && $_SESSION[$settings['session_prefix'].'user_type'] == "admin"))
178 if (is_array($category_ids) && !in_array($thread['category'], $category_ids))
180 header("location: ".$settings['forum_address']."board.php");
181 die('<a href="'. $settings['forum_address'] .'board.php">further...</a>');
185 # count views:
186 if (isset($settings['count_views']) && $settings['count_views'] == 1)
188 mysql_query("UPDATE ".$db_settings['forum_table']." SET time=time, last_answer=last_answer, edited=edited, views=views+1 WHERE tid=".$id, $connid);
191 if ($thread["user_id"] > 0)
193 $userdataByIdQuery = "SELECT
194 user_name,
195 user_type,
196 user_email,
197 hide_email,
198 user_hp,
199 user_place,
200 signature
201 FROM ".$db_settings['userdata_table']."
202 WHERE user_id = ".intval($thread["user_id"]);
203 $userdata_result_t = mysql_query($userdataByIdQuery, $connid);
204 if (!$userdata_result_t) die($lang['db_error']);
205 $userdata = mysql_fetch_assoc($userdata_result_t);
206 mysql_free_result($userdata_result_t);
207 $thread["email"] = $userdata["user_email"];
208 $thread["hide_email"] = $userdata["hide_email"];
209 $thread["place"] = $userdata["user_place"];
210 $thread["hp"] = $userdata["user_hp"];
211 $mark = outputStatusMark($mark, $userdata["user_type"], $connid);
212 if ($thread["show_signature"]==1)
214 $signature = $userdata["signature"];
216 } # End: if ($thread["user_id"] > 0)
217 $allPostingsQuery = "SELECT
219 tid,
220 pid,
221 user_id,
222 DATE_FORMAT(time + INTERVAL ".$time_difference." HOUR, '".$lang['time_format_sql']."') AS posting_time,
223 UNIX_TIMESTAMP(time) AS time,
224 UNIX_TIMESTAMP(edited + INTERVAL ".$time_difference." HOUR) AS e_time,
225 UNIX_TIMESTAMP(edited - INTERVAL ".$settings['edit_delay']." MINUTE) AS edited_diff,
226 edited_by,
227 name,
228 email,
229 subject,
231 place,
232 text,
233 show_signature,
234 category,
235 locked,
236 INET_NTOA(ip_addr) AS ip_address
237 FROM ".$db_settings['forum_table']."
238 WHERE tid = ".intval($id)." AND id != ".intval($id)."
239 ORDER BY time ".mysql_real_escape_string($da)."
240 LIMIT ".$ul.", ".$settings['answers_per_topic'];
241 $result = mysql_query($allPostingsQuery, $connid);
242 $result_c = mysql_query("SELECT tid FROM ".$db_settings['forum_table']." WHERE tid = ".$id." AND id != ".$id, $connid);
243 if(!$result or !$result_t) die($lang['db_error']);
244 $thread_count = mysql_num_rows($result_c);
245 mysql_free_result($result_c);
247 } # End: if ($thread['pid'] != 0)
248 else
250 header("location: ".$settings['forum_address']."board.php");
253 if (empty($thread))
255 header("location: ".$settings['forum_address']."board.php");
258 $wo = $thread["subject"];
259 $subnav_1 = '<a class="textlink" href="board.php" title="';
260 $subnav_1 .= outputLangDebugInAttributes($lang['back_to_board_linktitle']).'">'.$lang['back_to_board_linkname'].'</a>';
261 $cat = ($_SESSION[$settings['session_prefix'].'category'] > 0) ? '&amp;category='.intval($_SESSION[$settings['session_prefix'].'category']) : '';
262 $subnav_2 = '';
263 if ($da=="DESC")
265 $order_order = 'ASC';
266 $order_title = $lang['order_linktitle_3'];
267 $linktext = $lang['order_linkname'];
269 else
271 $order_order = 'DESC';
272 $order_title = $lang['order_linktitle_4'];
273 $linktext = $lang['order_linkname'];
275 $url = 'board_entry.php?id='.$thread["tid"].'&amp;da='.$order_order.'&amp;page='.$page.'&amp;order='.$order.'&amp;descasc='.$descasc;
276 $url .= $cat;
277 $class = 'order-postings';
278 $title = outputLangDebugInAttributes($order_title);
279 $subnav_2 .= outputSingleLink($url, $linktext, $title, $class);
280 if ($settings['thread_view']==1)
282 $url = 'forum_entry.php?view=thread&amp;id='.$thread["tid"];
283 $class = 'thread-view';
284 $title = outputLangDebugInAttributes($lang['thread_view_linktitle']);
285 $linktext = $lang['thread_view_linkname'];
286 $subnav_2 .= outputSingleLink($url, $linktext, $title, $class);
288 if ($settings['mix_view']==1)
290 $url = 'mix_entry.php?view=mix&amp;id='.$thread["tid"];
291 $class = 'mix-view';
292 $title = outputLangDebugInAttributes($lang['mix_view_linktitle']);
293 $linktext = $lang['mix_view_linkname'];
294 $subnav_2 .= outputSingleLink($url, $linktext, $title, $class);
296 $subnav_2 .= nav_b($be_page, $settings['answers_per_topic'], $thread_count, $thread["tid"], $da, $page, $category, $order, $descasc);
298 parse_template();
299 echo $header;
300 echo outputDebugSession();
302 # import posting template
303 $sPosting = file_get_contents('data/templates/posting.board.html');
304 echo '<table class="board-entry">'."\n";
305 if ($be_page==0)
307 $posting = $sPosting;
308 $pHeadline = htmlspecialchars($thread["subject"]);
309 if(isset($categories[$thread["category"]])
310 && $categories[$thread["category"]]!='')
312 $pHeadline .= '&nbsp;<span class="category">('.$categories[$thread["category"]].')</span>';
314 if ($thread['locked'] == 0)
316 if ($settings['entries_by_users_only'] == 0
317 or ($settings['entries_by_users_only'] == 1
318 and isset($_SESSION[$settings['session_prefix'].'user_name'])))
320 $qs = '';
321 $qs .= !empty($page) ? '&amp;page='.intval($page) : '';
322 $qs .= !empty($order) ? '&amp;order='.urlencode($order) : '';
323 $qs .= !empty($descasc) ? '&amp;descasc='.urlencode($descasc) : '';
324 $qs .= ($category > 0) ? '&amp;category='.intval($category) : '';
325 $answerlink = '<a class="textlink" href="posting.php?id='.$thread["id"].$qs;
326 $answerlink .= '&amp;view=board" title="'.outputLangDebugInAttributes($lang['board_answer_linktitle']).'">';
327 $answerlink .= $lang['board_answer_linkname'].'</a>';
330 else
332 $answerlink = '<span class="xsmall"><img src="img/lock.png" alt="" width="12" height="12" />'.$lang['thread_locked'].'</span>';
334 $ftext = ($thread["text"]=="") ? $lang['no_text'] : outputPreparePosting($thread["text"]);
335 $signature = (isset($signature) && $signature != "") ? $signature = '<div class="signature">'.outputPreparePosting($settings['signature_separator']."\n".$signature, 'signature').'</div>'."\n" : '';
336 # generate HTML source code of posting
337 $posting = str_replace('{postingID}', 'p'.$thread['id'], $posting);
338 $posting = str_replace('{postingheadline}', $pHeadline, $posting);
339 $posting = str_replace('{authorinfo}', outputAuthorInfo($mark, $thread, $page, $order, 'board', $category), $posting);
340 $posting = str_replace('{posting}', $ftext, $posting);
341 $posting = str_replace('{signature}', $signature, $posting);
342 $posting = str_replace('{answer-locked}', $answerlink, $posting);
343 $posting = str_replace('{editmenu}', outputPostingEditMenu($thread, 'board', 'opener'), $posting);
344 echo $posting;
346 $i=0;
347 while ($entrydata = mysql_fetch_assoc($result))
349 unset($signature);
350 unset($posting);
351 $mark['admin'] = 0;
352 $mark['mod'] = 0;
353 $mark['user'] = 0;
354 if ($entrydata["user_id"] > 0)
356 $userdataPerPostingQuery = "SELECT
357 user_name,
358 user_type,
359 user_email,
360 hide_email,
361 user_hp,
362 user_place,
363 signature
364 FROM ".$db_settings['userdata_table']."
365 WHERE user_id = ".intval($entrydata["user_id"]);
366 $userdata_result = mysql_query($userdataPerPostingQuery, $connid);
367 if (!$userdata_result) die($lang['db_error']);
368 $userdata = mysql_fetch_assoc($userdata_result);
369 mysql_free_result($userdata_result);
370 $entrydata["email"] = $userdata["user_email"];
371 $entrydata["hide_email"] = $userdata["hide_email"];
372 $entrydata["place"] = $userdata["user_place"];
373 $entrydata["hp"] = $userdata["user_hp"];
374 $mark = outputStatusMark($mark, $userdata["user_type"], $connid);
375 if ($entrydata["show_signature"]==1)
377 $signature = $userdata["signature"];
381 # Posting heraussuchen, auf das geantwortet wurde:
382 $result_a = mysql_query("SELECT name FROM ".$db_settings['forum_table']." WHERE id = ".$entrydata["pid"], $connid);
383 $posting_a = mysql_fetch_assoc($result_a);
384 mysql_free_result($result_a);
385 $entrydata['answer'] = $posting_a['name'];
387 $posting = $sPosting;
388 $pHeadline = htmlspecialchars($entrydata["subject"]);
389 if ($entrydata['locked'] == 0)
391 if ($settings['entries_by_users_only'] == 0
392 or ($settings['entries_by_users_only'] == 1
393 and isset($_SESSION[$settings['session_prefix'].'user_name'])))
395 $qs = '';
396 $qs .= !empty($page) ? '&amp;page='.intval($page) : '';
397 $qs .= !empty($order) ? '&amp;order='.urlencode($order) : '';
398 $qs .= !empty($descasc) ? '&amp;descasc='.urlencode($descasc) : '';
399 $qs .= ($category > 0) ? '&amp;category='.intval($category) : '';
400 $answerlink = '<a class="textlink" href="posting.php?id='.$entrydata["id"].$qs;
401 $answerlink .= '&amp;view=board" title="'.outputLangDebugInAttributes($lang['board_answer_linktitle']).'">';
402 $answerlink .= $lang['board_answer_linkname'].'</a>';
405 else
407 $answerlink = '<span class="xsmall"><img src="img/lock.png" alt="" width="12" height="12" />'.$lang['thread_locked'].'</span>';
409 $ftext = ($entrydata["text"]=="") ? $lang['no_text'] : outputPreparePosting($entrydata["text"]);
410 $signature = (isset($signature) && $signature != "") ? $signature = '<div class="signature">'.outputPreparePosting($settings['signature_separator']."\n".$signature, 'signature').'</div>'."\n" : '';
411 # generate HTML source code of posting
412 $posting = str_replace('{postingID}', 'p'.$entrydata['id'], $posting);
413 $posting = str_replace('{postingheadline}', $pHeadline, $posting);
414 $posting = str_replace('{authorinfo}', outputAuthorInfo($mark, $entrydata, $page, $order, 'board', $category), $posting);
415 $posting = str_replace('{posting}', $ftext, $posting);
416 $posting = str_replace('{signature}', $signature, $posting);
417 $posting = str_replace('{answer-locked}', $answerlink, $posting);
418 $posting = str_replace('{editmenu}', outputPostingEditMenu($entrydata, 'board'), $posting);
419 echo $posting;
421 mysql_free_result($result);
422 echo '</table>'."\n";
423 echo $footer;
425 else
427 header("location: ".$settings['forum_address']."login.php?msg=noaccess");
428 die("<a href=\"login.php?msg=noaccess\">further...</a>");