source: temp/test-xoops.ec-cube.net/html/modules/newbb/response.php @ 1257

Revision 1257, 16.7 KB checked in by kakinaka, 19 years ago (diff)
Line 
1<?php
2// $Id: viewforum.php,v 1.7 2006/05/01 02:37:28 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27// Author: Kazumi Ono (AKA onokazu)                                          //
28// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29// Project: The XOOPS Project                                                //
30// ------------------------------------------------------------------------- //
31
32include "header.php";
33
34$forum = intval($_GET['forum']);
35if ( $forum < 1 ) {
36    redirect_header("index.php", 2, _MD_ERRORFORUM);
37    exit();
38}
39$sql = 'SELECT forum_type, forum_name, forum_access, allow_html, allow_sig, posts_per_page, hot_threshold, topics_per_page FROM '.$xoopsDB->prefix('bb_forums').' WHERE forum_id = '.$forum;
40if ( !$result = $xoopsDB->query($sql) ) {
41    redirect_header("index.php", 2, _MD_ERRORCONNECT);
42    exit();
43}
44if ( !$forumdata = $xoopsDB->fetchArray($result) ) {
45    redirect_header("index.php", 2, _MD_ERROREXIST);
46    exit();
47}
48// this page uses smarty template
49// this must be set before including main header.php
50$xoopsOption['template_main_path'] = XOOPS_ROOT_PATH . '/modules/newbb/templates/newbb_response.html';
51include XOOPS_ROOT_PATH."/header.php";
52
53/*
54$can_post = 0;
55$show_reg = 0;
56if ( $forumdata['forum_type'] == 1 ) {
57    // this is a private forum.
58    $xoopsTpl->assign('is_private_forum', true);
59    $accesserror = 0;
60    if ( $xoopsUser ) {
61        if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
62            if ( !check_priv_forum_auth($xoopsUser->getVar("uid"), $forum, false) ) {
63                $accesserror = 1;
64            }
65        }
66    } else {
67        $accesserror = 1;
68    }
69    if ( $accesserror == 1 ) {
70        redirect_header("index.php",2,_MD_NORIGHTTOACCESS);
71        exit();
72    }
73    $can_post = 1;
74    $show_reg = 1;
75} else {
76    // this is not a priv forum
77    $xoopsTpl->assign('is_private_forum', false);
78    if ( $forumdata['forum_access'] == 1 ) {
79        // this is a reg user only forum
80        if ( $xoopsUser ) {
81            $can_post = 1;
82        } else {
83            $show_reg = 1;
84        }
85    } elseif ( $forumdata['forum_access'] == 2 ) {
86        // this is an open forum
87        $can_post = 1;
88    } else {
89        // this is an admin/moderator only forum
90        if ( $xoopsUser ) {
91            if ( $xoopsUserIsAdmin || is_moderator($forum, $xoopsUser->uid()) ) {
92                $can_post = 1;
93            }
94        }
95    }
96}
97$xoopsTpl->assign("forum_id", $forum);
98
99if ( $can_post == 1 ) {
100    $xoopsTpl->assign('viewer_can_post', true);
101    $xoopsTpl->assign('forum_post_or_register', "newtopic.php?forum=".$forum);
102} else {
103    $xoopsTpl->assign('viewer_can_post', false);
104    if ( $show_reg == 1 ) {
105        $xoopsTpl->assign('forum_post_or_register', XOOPS_URL.'/user.php?xoops_redirect='.htmlspecialchars($xoopsRequestUri));
106    } else {
107        $xoopsTpl->assign('forum_post_or_register', "");
108    }
109}
110*/
111
112$xoopsTpl->assign('forum_index_title', sprintf(_MD_FORUMINDEX,$xoopsConfig['sitename']));
113$xoopsTpl->assign('forum_image_folder', $bbImage['folder_topic']);
114$myts =& MyTextSanitizer::getInstance();
115$xoopsTpl->assign('forum_name', $myts->makeTboxData4Show($forumdata['forum_name']));
116$xoopsTpl->assign('lang_moderatedby', _MD_MODERATEDBY);
117
118$forum_moderators = "";
119$count = 0;
120$moderators = get_moderators($forum);
121foreach ( $moderators as $mods ) {
122    foreach ( $mods as $mod_id => $mod_name ) {
123        if ( $count > 0 ) {
124            $forum_moderators .= ", ";
125        }
126        $forum_moderators .=  '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$mod_id.'">'.$myts->makeTboxData4Show($mod_name).'</a>';
127        $count = 1;
128    }
129}
130$xoopsTpl->assign('forum_moderators', $forum_moderators);
131
132
133$sel_sort_array = array("t.topic_response"=>_MD_RESPONSE, "t.topic_title"=>_MD_TOPICTITLE, "t.topic_replies"=>_MD_NUMBERREPLIES, "u.uname"=>_MD_TOPICPOSTER, "t.topic_views"=>_MD_VIEWS, "p.post_time"=>_MD_LASTPOSTTIME);
134if ( !isset($_GET['sortname']) || !in_array($_GET['sortname'], array_keys($sel_sort_array)) ) {
135    $sortname = "p.post_time";
136} else {
137    $sortname = $_GET['sortname'];
138}
139
140$xoopsTpl->assign('lang_sortby', _MD_SORTEDBY);
141
142$forum_selection_sort = '<select name="sortname">';
143foreach ( $sel_sort_array as $sort_k => $sort_v ) {
144    $forum_selection_sort .= '<option value="'.$sort_k.'"'.(($sortname == $sort_k) ? ' selected="selected"' : '').'>'.$sort_v.'</option>';
145}
146$forum_selection_sort .= '</select>';
147
148// assign to template
149$xoopsTpl->assign('forum_selection_sort', $forum_selection_sort);
150
151$sortorder = (!isset($_GET['sortorder']) || $_GET['sortorder'] != "ASC") ? "DESC" : "ASC";
152$forum_selection_order = '<select name="sortorder">';
153$forum_selection_order .= '<option value="ASC"'.(($sortorder == "ASC") ? ' selected="selected"' : '').'>'._MD_ASCENDING.'</option>';
154$forum_selection_order .= '<option value="DESC"'.(($sortorder == "DESC") ? ' selected="selected"' : '').'>'._MD_DESCENDING.'</option>';
155$forum_selection_order .= '</select>';
156
157// assign to template
158$xoopsTpl->assign('forum_selection_order', $forum_selection_order);
159
160$sortsince = !empty($_GET['sortsince']) ? intval($_GET['sortsince']) : 100;
161$sel_since_array = array(1, 2, 5, 10, 20, 30, 40, 60, 75, 100);
162$forum_selection_since = '<select name="sortsince">';
163foreach ($sel_since_array as $sort_since_v) {
164    $forum_selection_since .= '<option value="'.$sort_since_v.'"'.(($sortsince == $sort_since_v) ? ' selected="selected"' : '').'>'.sprintf(_MD_FROMLASTDAYS,$sort_since_v).'</option>';
165}
166$forum_selection_since .= '<option value="365"'.(($sortsince == 365) ? ' selected="selected"' : '').'>'.sprintf(_MD_THELASTYEAR,365).'</option>';
167$forum_selection_since .= '<option value="1000"'.(($sortsince == 1000) ? ' selected="selected"' : '').'>'.sprintf(_MD_BEGINNING,1000).'</option>';
168$forum_selection_since .= '</select>';
169
170// assign to template
171$xoopsTpl->assign('forum_selection_since', $forum_selection_since);
172$xoopsTpl->assign('lang_go', _MD_GO);
173
174$xoopsTpl->assign('h_topic_link', "viewforum.php?forum=$forum&amp;sortname=t.topic_title&amp;sortsince=$sortsince&amp;sortorder=". (($sortname == "t.topic_title" && $sortorder == "DESC") ? "ASC" : "DESC"));
175$xoopsTpl->assign('lang_topic', _MD_TOPIC);
176
177// Âбþ¾õ¶·
178$xoopsTpl->assign('h_reply_response', "viewforum.php?forum=$forum&amp;sortname=t.topic_response&amp;sortsince=$sortsince&amp;sortorder=". (($sortname == "t.topic_response" && $sortorder == "DESC") ? "ASC" : "DESC"));
179$xoopsTpl->assign('lang_response', _MD_RESPONSE);
180
181$xoopsTpl->assign('h_reply_link', "viewforum.php?forum=$forum&amp;sortname=t.topic_replies&amp;sortsince=$sortsince&amp;sortorder=". (($sortname == "t.topic_replies" && $sortorder == "DESC") ? "ASC" : "DESC"));
182$xoopsTpl->assign('lang_replies', _MD_REPLIES);
183
184$xoopsTpl->assign('h_poster_link', "viewforum.php?forum=$forum&amp;sortname=u.uname&amp;sortsince=$sortsince&amp;sortorder=". (($sortname == "u.uname" && $sortorder == "DESC") ? "ASC" : "DESC"));
185$xoopsTpl->assign('lang_poster', _MD_POSTER);
186
187$xoopsTpl->assign('h_views_link', "viewforum.php?forum=$forum&amp;sortname=t.topic_views&amp;sortsince=$sortsince&amp;sortorder=". (($sortname == "t.topic_views" && $sortorder == "DESC") ? "ASC" : "DESC"));
188$xoopsTpl->assign('lang_views', _MD_VIEWS);
189
190$xoopsTpl->assign('h_date_link', "viewforum.php?forum=$forum&amp;sortname=p.post_time&amp;sortsince=$sortsince&amp;sortorder=". (($sortname == "p.post_time" && $sortorder == "DESC") ? "ASC" : "DESC"));
191$xoopsTpl->assign('lang_date', _MD_DATE);
192
193$startdate = time() - (86400* $sortsince);
194$start = !empty($_GET['start']) ? intval($_GET['start']) : 0;
195
196$sql = 'SELECT t.*, p.post_id, p.forum_id, u.uname, u2.uname as last_poster, p.post_time as last_post_time, p.icon FROM '.$xoopsDB->prefix("bb_topics").' t LEFT JOIN '.$xoopsDB->prefix('users').' u ON u.uid = t.topic_poster LEFT JOIN '.$xoopsDB->prefix('bb_posts').' p ON p.post_id = t.topic_last_post_id LEFT JOIN '.$xoopsDB->prefix('users').' u2 ON  u2.uid = p.uid WHERE t.forum_id = '.$forum.' AND (p.post_time > '.$startdate.' OR t.topic_sticky=1) ORDER BY topic_sticky DESC, '.$sortname.' '.$sortorder;
197if ( !$result = $xoopsDB->query($sql,$forumdata['topics_per_page'],$start) ) {
198    redirect_header('index.php',2,_MD_ERROROCCURED);
199    exit();
200}
201
202// Read topic 'lastread' times from cookie, if exists
203$topic_lastread = newbb_get_topics_viewed();
204while ( $myrow = $xoopsDB->fetchArray($result) ) {
205   
206    $sql_user = "SELECT uname FROM " .$xoopsDB->prefix('users'). " WHERE uid = " . $myrow['topic_response_uid'];
207    $result_user = $xoopsDB->query($sql_user);
208    $myrow_user = $xoopsDB->fetchArray($result_user);
209   
210    $sql_tmp = "SELECT p.post_id FROM ".$xoopsDB->prefix('bb_posts')." p WHERE p.pid = 0 AND p.topic_id = ".$myrow['topic_id'];
211    $result_tmp = $xoopsDB->query($sql_tmp);
212    $myrow_tmp = $xoopsDB->fetchArray($result_tmp);
213    $myrow['post_id'] = $myrow_tmp['post_id'];
214   
215    if ( empty($myrow['last_poster']) ) {
216        $myrow['last_poster'] = $xoopsConfig['anonymous'];
217    }
218    if ( $myrow['topic_sticky'] == 1 ) {
219        $image = $bbImage['folder_sticky'];
220    } elseif ( $myrow['topic_status'] == 1 ) {
221        $image = $bbImage['locked_topic'];
222    } else {
223        if ( $myrow['topic_replies'] >= $forumdata['hot_threshold'] ) {
224            if ( empty($topic_lastread[$myrow['topic_id']]) || ($topic_lastread[$myrow['topic_id']] < $myrow['last_post_time'] )) {
225                $image = $bbImage['hot_newposts_topic'];
226            } else {
227                $image = $bbImage['hot_folder_topic'];
228            }
229        } else {
230            if ( empty($topic_lastread[$myrow['topic_id']]) || ($topic_lastread[$myrow['topic_id']] < $myrow['last_post_time'] )) {
231                $image = $bbImage['newposts_topic'];
232            } else {
233                $image = $bbImage['folder_topic'];
234            }
235        }
236    }
237    $pagination = '';
238    $addlink = '';
239    $topiclink = 'viewtopic.php?topic_id='.$myrow['topic_id'].'&amp;forum='.$forum;
240    $totalpages = ceil(($myrow['topic_replies'] + 1) / $forumdata['posts_per_page']);
241    if ( $totalpages > 1 ) {
242        $pagination .= '&nbsp;&nbsp;&nbsp;<img src="'.XOOPS_URL.'/images/icons/posticon.gif" /> ';
243        for ( $i = 1; $i <= $totalpages; $i++ ) {
244
245            if ( $i > 3 && $i < $totalpages ) {
246                $pagination .= "...";
247            } else {
248                $addlink = '&amp;start='.(($i - 1) * $forumdata['posts_per_page']);
249                $pagination .= '[<a href="'.$topiclink.$addlink.'">'.$i.'</a>]';
250            }
251        }
252    }
253    if ( $myrow['icon'] ) {
254        $topic_icon = '<img src="'.XOOPS_URL.'/images/subject/'.htmlspecialchars($myrow['icon']).'" alt="" />';
255    } else {
256        $topic_icon = '<img src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" />';
257    }
258    if ( $myrow['topic_poster'] != 0 && $myrow['uname'] ) {
259        $topic_poster = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$myrow['topic_poster'].'">'.$myrow['uname'].'</a>';
260    } else {
261        $topic_poster = $xoopsConfig['anonymous'];
262    }
263    include_once 'class/class.util.php';
264    $fix = getFixName($myrow['forum_id']);
265
266    $xoopsTpl->append('topics', array('topic_response_user'=>$myrow_user['uname'], 'topic_id'=>$myrow['topic_id'], 'topic_response'=>$myrow['topic_response'], 'topic_response_uname'=>$myrow['topic_response_uname'], 'fix'=>$fix, 'topic_number'=>$myrow['post_id'], 'topic_icon'=>$topic_icon, 'topic_folder'=>$image, 'topic_title'=>$myts->makeTboxData4Show($myrow['topic_title']), 'topic_link'=>$topiclink, 'topic_page_jump'=>$pagination, 'topic_replies'=>$myrow['topic_replies'], 'topic_poster'=>$topic_poster, 'topic_views'=>$myrow['topic_views'], 'topic_last_posttime'=>formatTimestamp($myrow['last_post_time']), 'topic_last_poster'=>$myts->makeTboxData4Show($myrow['last_poster'])));
267}
268
269// Âбþ¾õ¶·
270$xoopsTpl->assign('arrResponse', $arrResponse);
271
272/*
273// ¥æ¡¼¥¶¡¼¾ðÊó¼èÆÀ
274$member_handler =& xoops_gethandler('member');
275$xoopsUserIsAdmin = false;
276$user_id = "";
277$user_name = "";
278if (!empty($_SESSION['xoopsUserId'])) {
279     $xoopsUser =& $member_handler->getUser($_SESSION['xoopsUserId']);
280    if (is_object($xoopsUser)) {
281        $xoopsUserIsAdmin = $xoopsUser->isAdmin();
282    }
283    $user_id = $_SESSION['xoopsUserId'];
284    $user_name = $xoopsUser->uname();
285}
286
287//sfprintr($xoopsUser->uname());
288
289// Âбþ¾õ¶·¹¹¿·¤¹¤ë
290//if($_GET['mode'] == 'response' and $xoopsUserIsAdmin and is_numeric($_GET['topic_id'])){
291if($_GET['mode'] == 'response' and is_numeric($_GET['topic_id'])){
292    $sql = 'UPDATE '.$xoopsDB->prefix("bb_topics").' SET topic_response = '.$_GET["response_".$_GET['topic_id']];
293    if($user_id != ""){
294        $sql .= ', topic_response_uid = '.$user_id;
295    }else{
296        $sql .= ', topic_response_uid = NULL';
297    }
298    $sql .= ' WHERE topic_id = '.$_GET['topic_id'];
299
300    if ( !$xoopsDB->queryF($sql)) {
301        redirect_header('index.php',2,_MD_ERROROCCURED);
302        exit();
303    }
304    // ¥ê¥í¡¼¥É
305    header("Location: " . $_SERVER['PHP_SELF'] . "?forum=" . $_GET['forum'] . "&sortname=p.post_time&sortorder=DESC&sortsince=" . $_GET['sortsince'] . "&start=" . $_GET['start']);
306}
307
308$xoopsTpl->assign('xoopsUserIsAdmin', $xoopsUserIsAdmin);
309*/
310
311$xoopsTpl->assign('lang_by', _MD_BY);
312
313$xoopsTpl->assign('img_newposts', $bbImage['newposts_topic']);
314$xoopsTpl->assign('img_hotnewposts', $bbImage['hot_newposts_topic']);
315$xoopsTpl->assign('img_folder', $bbImage['folder_topic']);
316$xoopsTpl->assign('img_hotfolder', $bbImage['hot_folder_topic']);
317$xoopsTpl->assign('img_locked', $bbImage['locked_topic']);
318$xoopsTpl->assign('img_sticky', $bbImage['folder_sticky']);
319$xoopsTpl->assign('lang_newposts', _MD_NEWPOSTS);
320$xoopsTpl->assign('lang_hotnewposts', _MD_MORETHAN);
321$xoopsTpl->assign('lang_hotnonewposts', _MD_MORETHAN2);
322$xoopsTpl->assign('lang_nonewposts', _MD_NONEWPOSTS);
323$xoopsTpl->assign('lang_legend', _MD_LEGEND);
324$xoopsTpl->assign('lang_topiclocked', _MD_TOPICLOCKED);
325$xoopsTpl->assign('lang_topicsticky', _MD_TOPICSTICKY);
326$xoopsTpl->assign("lang_search", _MD_SEARCH);
327$xoopsTpl->assign("lang_advsearch", _MD_ADVSEARCH);
328
329$sql = 'SELECT COUNT(*) FROM '.$xoopsDB->prefix('bb_topics').' WHERE forum_id = '.$forum.' AND (topic_time > '.$startdate.' OR topic_sticky = 1)';
330if ( !$r = $xoopsDB->query($sql) ) {
331    //redirect_header('index.php',2,_MD_ERROROCCURED);
332    //exit();
333}
334list($all_topics) = $xoopsDB->fetchRow($r);
335if ( $all_topics > $forumdata['topics_per_page'] ) {
336    include XOOPS_ROOT_PATH.'/class/pagenav.php';
337    $nav = new XoopsPageNav($all_topics, $forumdata['topics_per_page'], $start, "start", 'forum='.$forum.'&amp;sortname='.$sortname.'&amp;sortorder='.$sortorder.'&amp;sortsince='.$sortsince);
338    $xoopsTpl->assign('forum_pagenav', $nav->renderNav(4));
339} else {
340    $xoopsTpl->assign('forum_pagenav', '');
341}
342
343// ¥«¥Æ¥´¥ê̾¼èÆÀ
344$sql = "SELECT c.cat_id, c.cat_title FROM ".$xoopsDB->prefix("bb_categories")." c, ".$xoopsDB->prefix("bb_forums")." f WHERE c.cat_id = f.cat_id AND forum_id = $forum";
345
346if ( !$result = $xoopsDB->query($sql) ) {
347    //redirect_header('index.php',2,_MD_ERROROCCURED);
348    //exit();
349}
350$arrCat = $xoopsDB->fetchArray($result);
351$xoopsTpl->assign('arrCat', $arrCat);
352
353$xoopsTpl->assign('forum_jumpbox', make_jumpbox($forum));
354include XOOPS_ROOT_PATH."/footer.php";
355?>
Note: See TracBrowser for help on using the repository browser.