37 |
40 |
38 // Load the viewforum.php language file |
41 // Load the viewforum.php language file |
39 require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php'; |
42 require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php'; |
40 |
43 |
41 // Fetch some info about the forum |
44 // Fetch some info about the forum |
42 $result = $db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error()); |
45 $result = $pun_db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics FROM '.$pun_db->prefix.'forums AS f LEFT JOIN '.$pun_db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error()); |
43 if (!$db->num_rows($result)) |
46 if (!$pun_db->num_rows($result)) |
44 message($lang_common['Bad request']); |
47 message($lang_common['Bad request']); |
45 |
48 |
46 $cur_forum = $db->fetch_assoc($result); |
49 $cur_forum = $pun_db->fetch_assoc($result); |
47 |
50 |
48 // Is this a redirect forum? In that case, redirect! |
51 // Is this a redirect forum? In that case, redirect! |
49 if ($cur_forum['redirect_url'] != '') |
52 if ($cur_forum['redirect_url'] != '') |
50 { |
53 { |
51 header('Location: '.$cur_forum['redirect_url']); |
54 header('Location: '.$cur_forum['redirect_url']); |
108 |
111 |
109 // Fetch list of topics to display on this page |
112 // Fetch list of topics to display on this page |
110 if ($pun_user['is_guest'] || $pun_config['o_show_dot'] == '0') |
113 if ($pun_user['is_guest'] || $pun_config['o_show_dot'] == '0') |
111 { |
114 { |
112 // Without "the dot" |
115 // Without "the dot" |
113 $sql = 'SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']; |
116 $sql = 'SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$pun_db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']; |
114 } |
117 } |
115 else |
118 else |
116 { |
119 { |
117 // With "the dot" |
120 // With "the dot" |
118 switch ($db_type) |
121 switch ($db_type) |
119 { |
122 { |
120 case 'mysql': |
123 case 'mysql': |
121 case 'mysqli': |
124 case 'mysqli': |
122 $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']; |
125 $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$pun_db->prefix.'topics AS t LEFT JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']; |
123 break; |
126 break; |
124 |
127 |
125 case 'sqlite': |
128 case 'sqlite': |
126 $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.id IN(SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'].') GROUP BY t.id ORDER BY t.sticky DESC, t.last_post DESC'; |
129 $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$pun_db->prefix.'topics AS t LEFT JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.id IN(SELECT id FROM '.$pun_db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'].') GROUP BY t.id ORDER BY t.sticky DESC, t.last_post DESC'; |
127 break; |
130 break; |
128 |
131 |
129 default: |
132 default: |
130 $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to, p.poster_id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']; |
133 $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$pun_db->prefix.'topics AS t LEFT JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to, p.poster_id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']; |
131 break; |
134 break; |
132 |
135 |
133 } |
136 } |
134 } |
137 } |
135 |
138 |
136 $result = $db->query($sql) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); |
139 $result = $pun_db->query($sql) or error('Unable to fetch topic list', __FILE__, __LINE__, $pun_db->error()); |
137 |
140 |
138 // If there are topics in this forum. |
141 // If there are topics in this forum. |
139 if ($db->num_rows($result)) |
142 if ($pun_db->num_rows($result)) |
140 { |
143 { |
141 while ($cur_topic = $db->fetch_assoc($result)) |
144 while ($cur_topic = $pun_db->fetch_assoc($result)) |
142 { |
145 { |
143 $icon_text = $lang_common['Normal icon']; |
146 $icon_text = $lang_common['Normal icon']; |
144 $item_status = ''; |
147 $item_status = ''; |
145 $icon_type = 'icon'; |
148 $icon_type = 'icon'; |
146 |
149 |