phpBB
Statistics
| Revision:

root / tags / milestone_3 / phpBB / posting.php

History | View | Annotate | Download (63.9 kB)

1 2 thefinn
<?php
2 5114 acydburn
/**
3 5114 acydburn
*
4 5114 acydburn
* @package phpBB3
5 5114 acydburn
* @version $Id$
6 5114 acydburn
* @copyright (c) 2005 phpBB Group
7 5114 acydburn
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 5114 acydburn
*
9 5114 acydburn
*/
10 2 thefinn
11 5114 acydburn
/**
12 5114 acydburn
*/
13 4767 acydburn
define('IN_PHPBB', true);
14 2448 psotfx
$phpbb_root_path = './';
15 4473 psotfx
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16 646 psotfx
include($phpbb_root_path . 'common.'.$phpEx);
17 4460 acydburn
include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
18 2673 psotfx
include($phpbb_root_path . 'includes/functions_posting.'.$phpEx);
19 5247 acydburn
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
20 3572 acydburn
include($phpbb_root_path . 'includes/message_parser.'.$phpEx);
21 169 thefinn
22 4167 psotfx
23 2972 psotfx
// Start session management
24 5247 acydburn
$user->session_begin();
25 2972 psotfx
$auth->acl($user->data);
26 2972 psotfx
27 4167 psotfx
28 3354 psotfx
// Grab only parameters needed here
29 4539 acydburn
$post_id        = request_var('p', 0);
30 4539 acydburn
$topic_id        = request_var('t', 0);
31 4539 acydburn
$forum_id        = request_var('f', 0);
32 4668 acydburn
$draft_id        = request_var('d', 0);
33 4539 acydburn
$lastclick        = request_var('lastclick', 0);
34 3354 psotfx
35 4767 acydburn
$submit                = (isset($_POST['post']));
36 4767 acydburn
$preview        = (isset($_POST['preview']));
37 4767 acydburn
$save                = (isset($_POST['save']));
38 4767 acydburn
$load                = (isset($_POST['load']));
39 4767 acydburn
$cancel                = (isset($_POST['cancel']));
40 4767 acydburn
$confirm        = (isset($_POST['confirm']));
41 4767 acydburn
$delete                = (isset($_POST['delete']));
42 3553 acydburn
43 4668 acydburn
$refresh        = isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['edit_comment']) || isset($_POST['cancel_unglobalise']) || $save || $load;
44 3697 acydburn
45 4767 acydburn
$mode                = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
46 3631 acydburn
47 4170 psotfx
$error = array();
48 4620 psotfx
$current_time = time();
49 4170 psotfx
50 4170 psotfx
51 2958 psotfx
// Was cancel pressed? If so then redirect to the appropriate page
52 4890 acydburn
if ($cancel || ($current_time - $lastclick < 2 && $submit))
53 378 psotfx
{
54 4139 acydburn
        $redirect = ($post_id) ? "viewtopic.$phpEx$SID&p=$post_id#$post_id" : (($topic_id) ? "viewtopic.$phpEx$SID&t=$topic_id" : (($forum_id) ? "viewforum.$phpEx$SID&f=$forum_id" : "index.$phpEx$SID"));
55 2958 psotfx
        redirect($redirect);
56 378 psotfx
}
57 378 psotfx
58 4912 acydburn
if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete', 'popup')) && !$forum_id)
59 4460 acydburn
{
60 4575 acydburn
        trigger_error('NO_FORUM');
61 4460 acydburn
}
62 4460 acydburn
63 2972 psotfx
// What is all this following SQL for? Well, we need to know
64 2972 psotfx
// some basic information in all cases before we do anything.
65 3354 psotfx
switch ($mode)
66 2183 psotfx
{
67 2972 psotfx
        case 'post':
68 4139 acydburn
                $sql = 'SELECT *
69 4139 acydburn
                        FROM ' . FORUMS_TABLE . "
70 4139 acydburn
                        WHERE forum_id = $forum_id";
71 2923 psotfx
                break;
72 2983 psotfx
73 4614 acydburn
        case 'bump':
74 2923 psotfx
        case 'reply':
75 3543 acydburn
                if (!$topic_id)
76 582 psotfx
                {
77 4575 acydburn
                        trigger_error('NO_TOPIC');
78 2183 psotfx
                }
79 824 psotfx
80 4968 acydburn
                $sql = 'SELECT f.*, t.*
81 4139 acydburn
                        FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
82 4139 acydburn
                        WHERE t.topic_id = $topic_id
83 4970 psotfx
                                AND (f.forum_id = t.forum_id
84 4213 psotfx
                                        OR f.forum_id = $forum_id)";
85 3572 acydburn
                break;
86 4970 psotfx
87 2923 psotfx
        case 'quote':
88 2972 psotfx
        case 'edit':
89 2923 psotfx
        case 'delete':
90 3543 acydburn
                if (!$post_id)
91 2383 psotfx
                {
92 4575 acydburn
                        trigger_error('NO_POST');
93 2383 psotfx
                }
94 2305 psotfx
95 4970 psotfx
                $sql = 'SELECT f.*, t.*, p.*, u.username, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
96 4139 acydburn
                        FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
97 4139 acydburn
                        WHERE p.post_id = $post_id
98 2923 psotfx
                                AND t.topic_id = p.topic_id
99 3575 acydburn
                                AND u.user_id = p.poster_id
100 4970 psotfx
                                AND (f.forum_id = t.forum_id
101 4213 psotfx
                                        OR f.forum_id = $forum_id)";
102 2923 psotfx
                break;
103 326 thefinn
104 2986 psotfx
        case 'smilies':
105 4883 acydburn
                $sql = '';
106 4544 acydburn
                generate_smilies('window', $forum_id);
107 2986 psotfx
                break;
108 2986 psotfx
109 4883 acydburn
        case 'popup':
110 4883 acydburn
                $sql = 'SELECT forum_style
111 4883 acydburn
                        FROM ' . FORUMS_TABLE . '
112 4883 acydburn
                        WHERE forum_id = ' . $forum_id;
113 4883 acydburn
                break;
114 4883 acydburn
115 2923 psotfx
        default:
116 4170 psotfx
                $sql = '';
117 4614 acydburn
                trigger_error('NO_POST_MODE');
118 987 psotfx
}
119 2183 psotfx
120 4620 psotfx
if ($sql)
121 2972 psotfx
{
122 2972 psotfx
        $result = $db->sql_query($sql);
123 3354 psotfx
124 4620 psotfx
        extract($db->sql_fetchrow($result));
125 2972 psotfx
        $db->sql_freeresult($result);
126 3572 acydburn
127 4883 acydburn
        if ($mode == 'popup')
128 4883 acydburn
        {
129 4883 acydburn
                upload_popup($forum_style);
130 4883 acydburn
                exit;
131 4883 acydburn
        }
132 3937 ludovic_arnaud
133 4883 acydburn
        $quote_username = (isset($username)) ? $username : ((isset($post_username)) ? $post_username : '');
134 4883 acydburn
135 4460 acydburn
        $forum_id        = (int) $forum_id;
136 4460 acydburn
        $topic_id        = (int) $topic_id;
137 4460 acydburn
        $post_id        = (int) $post_id;
138 3572 acydburn
139 5063 acydburn
        // Global Topic? - Adjust forum id
140 5063 acydburn
        if (!$forum_id && $topic_type == POST_GLOBAL)
141 5063 acydburn
        {
142 5063 acydburn
                $forum_id = request_var('f', 0);
143 5063 acydburn
        }
144 5063 acydburn
145 4883 acydburn
        $post_edit_locked = (isset($post_edit_locked)) ? (int) $post_edit_locked : 0;
146 3989 psotfx
147 4981 acydburn
        $user->setup(array('posting', 'mcp', 'viewtopic'), $forum_style);
148 4460 acydburn
149 4460 acydburn
        if ($forum_password)
150 3969 psotfx
        {
151 4855 acydburn
                $forum_info = array(
152 4970 psotfx
                        'forum_id'                => $forum_id,
153 4857 acydburn
                        'forum_password'=> $forum_password
154 4767 acydburn
                );
155 4970 psotfx
156 4855 acydburn
                login_forum_box($forum_info);
157 4855 acydburn
                unset($forum_info);
158 3969 psotfx
        }
159 3635 acydburn
160 4883 acydburn
        $post_subject = (in_array($mode, array('quote', 'edit', 'delete'))) ? $post_subject : ((isset($topic_title)) ? $topic_title : '');
161 3635 acydburn
162 4883 acydburn
        $topic_time_limit = (isset($topic_time_limit)) ? (($topic_time_limit) ? (int) $topic_time_limit / 86400 : (int) $topic_time_limit) : 0;
163 4981 acydburn
164 4883 acydburn
        $poll_length = (isset($poll_length)) ? (($poll_length) ? (int) $poll_length / 86400 : (int) $poll_length) : 0;
165 4883 acydburn
        $poll_start = (isset($poll_start)) ? (int) $poll_start : 0;
166 3631 acydburn
        $poll_options = array();
167 4978 acydburn
168 4989 acydburn
        if (!isset($icon_id) || in_array($mode, array('quote', 'reply')))
169 4978 acydburn
        {
170 4978 acydburn
                $icon_id = 0;
171 4978 acydburn
        }
172 3572 acydburn
173 3631 acydburn
        // Get Poll Data
174 3631 acydburn
        if ($poll_start)
175 3631 acydburn
        {
176 4970 psotfx
                $sql = 'SELECT poll_option_text
177 4139 acydburn
                        FROM ' . POLL_OPTIONS_TABLE . "
178 4139 acydburn
                        WHERE topic_id = $topic_id
179 3695 acydburn
                        ORDER BY poll_option_id";
180 3631 acydburn
                $result = $db->sql_query($sql);
181 3631 acydburn
182 3631 acydburn
                while ($row = $db->sql_fetchrow($result))
183 3631 acydburn
                {
184 3631 acydburn
                        $poll_options[] = trim($row['poll_option_text']);
185 3631 acydburn
                }
186 3631 acydburn
                $db->sql_freeresult($result);
187 3631 acydburn
        }
188 3631 acydburn
189 4981 acydburn
        $orig_poll_options_size = sizeof($poll_options);
190 4834 acydburn
        $message_parser = new parse_message();
191 4167 psotfx
192 4978 acydburn
        if (isset($post_text))
193 4978 acydburn
        {
194 4978 acydburn
                $message_parser->message = $post_text;
195 4978 acydburn
                unset($post_text);
196 4978 acydburn
        }
197 4978 acydburn
198 4883 acydburn
        $message_parser->get_submitted_attachment_data();
199 4167 psotfx
200 4890 acydburn
        // Set uninitialized variables
201 4890 acydburn
        $uninit = array('post_attachment' => 0, 'poster_id' => 0, 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '');
202 4890 acydburn
        foreach ($uninit as $var_name => $default_value)
203 4890 acydburn
        {
204 4890 acydburn
                if (!isset($$var_name))
205 4890 acydburn
                {
206 4890 acydburn
                        $$var_name = $default_value;
207 4890 acydburn
                }
208 4890 acydburn
        }
209 4978 acydburn
        unset($uninit, $var_name, $default_value);
210 4890 acydburn
211 3961 psotfx
        if ($post_attachment && !$submit && !$refresh && !$preview && $mode == 'edit')
212 3697 acydburn
        {
213 4638 acydburn
                $sql = 'SELECT attach_id, physical_filename, comment, real_filename, extension, mimetype, filesize, filetime, thumbnail
214 4638 acydburn
                        FROM ' . ATTACHMENTS_TABLE . "
215 4883 acydburn
                        WHERE post_msg_id = $post_id
216 4883 acydburn
                                AND in_message = 0
217 4638 acydburn
                        ORDER BY filetime " . ((!$config['display_order']) ? 'DESC' : 'ASC');
218 3697 acydburn
                $result = $db->sql_query($sql);
219 3697 acydburn
220 3960 acydburn
                $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
221 4970 psotfx
222 3697 acydburn
                $db->sql_freeresult($result);
223 3697 acydburn
        }
224 4970 psotfx
225 3961 psotfx
        if ($poster_id == ANONYMOUS || !$poster_id)
226 3575 acydburn
        {
227 4460 acydburn
                $username = (in_array($mode, array('quote', 'edit', 'delete'))) ? trim($post_username) : '';
228 3575 acydburn
        }
229 3575 acydburn
        else
230 3575 acydburn
        {
231 4460 acydburn
                $username = (in_array($mode, array('quote', 'edit', 'delete'))) ? trim($username) : '';
232 3575 acydburn
        }
233 3575 acydburn
234 3635 acydburn
        $enable_urls = $enable_magic_url;
235 4978 acydburn
236 4978 acydburn
        $enable_html = (isset($enable_html)) ? $enable_html : $config['allow_html'];
237 3635 acydburn
238 4460 acydburn
        if (!in_array($mode, array('quote', 'edit', 'delete')))
239 3635 acydburn
        {
240 4767 acydburn
                $enable_sig                = ($config['allow_sig'] && $user->optionget('attachsig'));
241 5108 acydburn
                $enable_smilies        = ($config['allow_smilies'] && $user->optionget('smilies'));
242 4767 acydburn
                $enable_bbcode        = ($config['allow_bbcode'] && $user->optionget('bbcode'));
243 4767 acydburn
                $enable_urls        = true;
244 3635 acydburn
        }
245 3635 acydburn
246 4767 acydburn
        $enable_magic_url = $drafts = false;
247 4467 acydburn
248 4668 acydburn
        // User own some drafts?
249 5117 acydburn
        if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && $mode != 'delete')
250 4467 acydburn
        {
251 4467 acydburn
                $sql = 'SELECT draft_id
252 4467 acydburn
                        FROM ' . DRAFTS_TABLE . '
253 4668 acydburn
                        WHERE (forum_id = ' . $forum_id . (($topic_id) ? " OR topic_id = $topic_id" : '') . ')
254 4970 psotfx
                                AND user_id = ' . $user->data['user_id'] .
255 4668 acydburn
                                (($draft_id) ? " AND draft_id <> $draft_id" : '');
256 4467 acydburn
                $result = $db->sql_query_limit($sql, 1);
257 4668 acydburn
258 4575 acydburn
                if ($db->sql_fetchrow($result))
259 4467 acydburn
                {
260 4767 acydburn
                        $drafts = true;
261 4467 acydburn
                }
262 4883 acydburn
                $db->sql_freeresult($result);
263 4467 acydburn
        }
264 4978 acydburn
265 4978 acydburn
        $check_value = (($enable_html+1) << 16) + (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1);
266 2972 psotfx
}
267 2983 psotfx
268 2983 psotfx
// Notify user checkbox
269 5117 acydburn
if ($mode != 'post' && $user->data['is_registered'])
270 2983 psotfx
{
271 4139 acydburn
        $sql = 'SELECT topic_id
272 4139 acydburn
                FROM ' . TOPICS_WATCH_TABLE . '
273 4139 acydburn
                WHERE topic_id = ' . $topic_id . '
274 4139 acydburn
                        AND user_id = ' . $user->data['user_id'];
275 4627 acydburn
        $result = $db->sql_query_limit($sql, 1);
276 4093 acydburn
        $notify_set = ($db->sql_fetchrow($result)) ? 1 : 0;
277 2983 psotfx
        $db->sql_freeresult($result);
278 2983 psotfx
}
279 4093 acydburn
else
280 4093 acydburn
{
281 4627 acydburn
        $notify_set = 0;
282 4093 acydburn
}
283 2983 psotfx
284 3961 psotfx
if (!$auth->acl_get('f_' . $mode, $forum_id) && $forum_type == FORUM_POST)
285 2958 psotfx
{
286 5117 acydburn
        if ($user->data['is_registered'])
287 4836 acydburn
        {
288 4836 acydburn
                trigger_error('USER_CANNOT_' . strtoupper($mode));
289 4836 acydburn
        }
290 4970 psotfx
291 4970 psotfx
        login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
292 2972 psotfx
}
293 502 psotfx
294 4167 psotfx
295 2997 psotfx
// Forum/Topic locked?
296 4139 acydburn
if (($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) && !$auth->acl_get('m_edit', $forum_id))
297 2997 psotfx
{
298 3572 acydburn
        $message = ($forum_status == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED';
299 4575 acydburn
        trigger_error($message);
300 2997 psotfx
}
301 2997 psotfx
302 4970 psotfx
// Can we edit this post ... if we're a moderator with rights then always yes
303 4970 psotfx
// else it depends on editing times, lock status and if we're the correct user
304 4970 psotfx
// !$preview && !$refresh && !$submit &&
305 4956 acydburn
if ($mode == 'edit' && !$preview && !$refresh && !$submit && !$auth->acl_get('m_edit', $forum_id))
306 2972 psotfx
{
307 4970 psotfx
        if ($user->data['user_id'] != $poster_id)
308 4970 psotfx
        {
309 4970 psotfx
                trigger_error('USER_CANNOT_EDIT');
310 4970 psotfx
        }
311 4970 psotfx
312 4883 acydburn
        if (!($post_time > time() - $config['edit_time'] || !$config['edit_time']))
313 4883 acydburn
        {
314 4883 acydburn
                trigger_error('CANNOT_EDIT_TIME');
315 4883 acydburn
        }
316 2849 psotfx
317 4883 acydburn
        if ($post_edit_locked)
318 4883 acydburn
        {
319 4883 acydburn
                trigger_error('CANNOT_EDIT_POST_LOCKED');
320 4883 acydburn
        }
321 3553 acydburn
}
322 3553 acydburn
323 4970 psotfx
// Do we want to edit our post ?
324 4970 psotfx
325 3858 ludovic_arnaud
if ($mode == 'edit')
326 3858 ludovic_arnaud
{
327 4486 acydburn
        $message_parser->bbcode_uid = $bbcode_uid;
328 3858 ludovic_arnaud
}
329 3858 ludovic_arnaud
330 4167 psotfx
331 3582 acydburn
// Delete triggered ?
332 5117 acydburn
if ($mode == 'delete' && (($poster_id == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_delete', $forum_id) && $post_id == $topic_last_post_id) || $auth->acl_get('m_delete', $forum_id)))
333 3582 acydburn
{
334 5199 acydburn
        $s_hidden_fields = build_hidden_fields(array(
335 5199 acydburn
                'p'                => $post_id,
336 5199 acydburn
                'f'                => $forum_id,
337 5199 acydburn
                'mode'        => 'delete')
338 5199 acydburn
        );
339 4890 acydburn
340 4890 acydburn
        if (confirm_box(true))
341 3582 acydburn
        {
342 4479 acydburn
                $data = array(
343 5157 acydburn
                        'topic_first_post_id'        => $topic_first_post_id,
344 5157 acydburn
                        'topic_last_post_id'        => $topic_last_post_id,
345 5157 acydburn
                        'topic_approved'                => $topic_approved,
346 5157 acydburn
                        'topic_type'                        => $topic_type,
347 5157 acydburn
                        'post_approved'                        => $post_approved,
348 5157 acydburn
                        'post_time'                                => $post_time,
349 5157 acydburn
                        'poster_id'                                => $poster_id
350 4479 acydburn
                );
351 4970 psotfx
352 4479 acydburn
                $next_post_id = delete_post($mode, $post_id, $topic_id, $forum_id, $data);
353 4970 psotfx
354 4477 acydburn
                if ($topic_first_post_id == $topic_last_post_id)
355 3883 acydburn
                {
356 5157 acydburn
                        add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $topic_title);
357 5157 acydburn
358 5157 acydburn
                        $meta_info = "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id";
359 4614 acydburn
                        $message = $user->lang['POST_DELETED'];
360 3883 acydburn
                }
361 3883 acydburn
                else
362 3883 acydburn
                {
363 5157 acydburn
                        add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_subject);
364 5157 acydburn
365 5157 acydburn
                        $meta_info = "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id#$next_post_id";
366 5157 acydburn
                        $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id#$next_post_id\">", '</a>');
367 3883 acydburn
                }
368 3883 acydburn
369 3980 psotfx
                meta_refresh(3, $meta_info);
370 5157 acydburn
                $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], "<a href=\"{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id\">", '</a>');
371 3883 acydburn
                trigger_error($message);
372 3582 acydburn
        }
373 3582 acydburn
        else
374 3582 acydburn
        {
375 4890 acydburn
                confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields);
376 3582 acydburn
        }
377 3582 acydburn
}
378 3582 acydburn
379 4167 psotfx
380 4139 acydburn
if ($mode == 'delete' && $poster_id != $user->data['user_id'] && !$auth->acl_get('f_delete', $forum_id))
381 3582 acydburn
{
382 4575 acydburn
        trigger_error('DELETE_OWN_POSTS');
383 3582 acydburn
}
384 3582 acydburn
385 4139 acydburn
if ($mode == 'delete' && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $topic_last_post_id)
386 3582 acydburn
{
387 4575 acydburn
        trigger_error('CANNOT_DELETE_REPLIED');
388 3582 acydburn
}
389 3582 acydburn
390 3582 acydburn
if ($mode == 'delete')
391 3582 acydburn
{
392 3582 acydburn
        trigger_error('USER_CANNOT_DELETE');
393 3582 acydburn
}
394 3582 acydburn
395 4167 psotfx
396 4047 ludovic_arnaud
// HTML, BBCode, Smilies, Images and Flash status
397 4767 acydburn
$html_status        = ($config['allow_html'] && $auth->acl_get('f_html', $forum_id));
398 4767 acydburn
$bbcode_status        = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id));
399 4767 acydburn
$smilies_status        = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id));
400 4767 acydburn
$img_status                = ($auth->acl_get('f_img', $forum_id));
401 4767 acydburn
$flash_status        = ($auth->acl_get('f_flash', $forum_id));
402 4767 acydburn
$quote_status        = ($auth->acl_get('f_quote', $forum_id));
403 4047 ludovic_arnaud
404 4614 acydburn
// Bump Topic
405 4634 acydburn
if ($mode == 'bump' && ($bump_time = bump_topic_allowed($forum_id, $topic_bumped, $topic_last_post_time, $topic_poster, $topic_last_poster_id)))
406 4614 acydburn
{
407 4614 acydburn
        $db->sql_transaction();
408 4614 acydburn
409 4614 acydburn
        $db->sql_query('UPDATE ' . POSTS_TABLE . "
410 4614 acydburn
                SET post_time = $current_time
411 4614 acydburn
                WHERE post_id = $topic_last_post_id
412 4614 acydburn
                        AND topic_id = $topic_id");
413 4614 acydburn
414 4614 acydburn
        $db->sql_query('UPDATE ' . TOPICS_TABLE . "
415 4634 acydburn
                SET topic_last_post_time = $current_time,
416 4634 acydburn
                        topic_bumped = 1,
417 4634 acydburn
                        topic_bumper = " . $user->data['user_id'] . "
418 4614 acydburn
                WHERE topic_id = $topic_id");
419 4614 acydburn
420 4614 acydburn
        $db->sql_query('UPDATE ' . FORUMS_TABLE . '
421 4614 acydburn
                SET ' . implode(', ', update_last_post_information('forum', $forum_id)) . "
422 4614 acydburn
                WHERE forum_id = $forum_id");
423 4614 acydburn
424 4614 acydburn
        $db->sql_query('UPDATE ' . USERS_TABLE . "
425 4614 acydburn
                SET user_lastpost_time = $current_time
426 4614 acydburn
                WHERE user_id = " . $user->data['user_id']);
427 4614 acydburn
428 4614 acydburn
        $db->sql_transaction('commit');
429 4970 psotfx
430 4614 acydburn
        markread('post', $forum_id, $topic_id, $current_time);
431 4614 acydburn
432 4634 acydburn
        add_log('mod', $forum_id, $topic_id, sprintf($user->lang['LOGM_BUMP'], $topic_title));
433 4625 acydburn
434 4614 acydburn
        meta_refresh(3, "viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;p=$topic_last_post_id#$topic_last_post_id");
435 4614 acydburn
436 4614 acydburn
        $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="viewtopic.' . $phpEx . $SID . "&amp;f=$forum_id&amp;t=$topic_id&amp;p=$topic_last_post_id#$topic_last_post_id\">", '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID .'&amp;f=' . $forum_id . '">', '</a>');
437 4767 acydburn
438 4614 acydburn
        trigger_error($message);
439 4614 acydburn
}
440 4634 acydburn
else if ($mode == 'bump')
441 4634 acydburn
{
442 4634 acydburn
        trigger_error('BUMP_ERROR');
443 4634 acydburn
}
444 4614 acydburn
445 4467 acydburn
// Save Draft
446 5117 acydburn
if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
447 4467 acydburn
{
448 5108 acydburn
        $subject = request_var('subject', '', true);
449 4767 acydburn
        $subject = (!$subject && $mode != 'post') ? $topic_title : $subject;
450 5108 acydburn
        $message = request_var('message', '', true);
451 4539 acydburn
452 4862 acydburn
        if ($subject && $message)
453 4467 acydburn
        {
454 4668 acydburn
                $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
455 4668 acydburn
                        'user_id'        => $user->data['user_id'],
456 4668 acydburn
                        'topic_id'        => $topic_id,
457 4668 acydburn
                        'forum_id'        => $forum_id,
458 4668 acydburn
                        'save_time'        => $current_time,
459 4668 acydburn
                        'draft_subject' => $subject,
460 4668 acydburn
                        'draft_message' => $message));
461 4467 acydburn
                $db->sql_query($sql);
462 4970 psotfx
463 4767 acydburn
                $meta_info = ($mode == 'post') ? "viewforum.$phpEx$SID&amp;f=$forum_id" : "viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id";
464 4467 acydburn
465 4668 acydburn
                meta_refresh(3, $meta_info);
466 4668 acydburn
467 4668 acydburn
                $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
468 4668 acydburn
                $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
469 4668 acydburn
                $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $forum_id . '">', '</a>');
470 4668 acydburn
471 4668 acydburn
                trigger_error($message);
472 4467 acydburn
        }
473 4539 acydburn
474 4668 acydburn
        unset($subject);
475 4668 acydburn
        unset($message);
476 4467 acydburn
}
477 4467 acydburn
478 4668 acydburn
// Load Draft
479 5117 acydburn
if ($draft_id && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
480 4668 acydburn
{
481 4970 psotfx
        $sql = 'SELECT draft_subject, draft_message
482 4970 psotfx
                FROM ' . DRAFTS_TABLE . "
483 4668 acydburn
                WHERE draft_id = $draft_id
484 4668 acydburn
                        AND user_id = " . $user->data['user_id'];
485 4668 acydburn
        $result = $db->sql_query_limit($sql, 1);
486 4970 psotfx
487 4668 acydburn
        if ($row = $db->sql_fetchrow($result))
488 4668 acydburn
        {
489 5063 acydburn
                $_REQUEST['subject'] = strtr($row['draft_subject'], array_flip(get_html_translation_table(HTML_ENTITIES)));
490 5063 acydburn
                $_POST['message'] = strtr($row['draft_message'], array_flip(get_html_translation_table(HTML_ENTITIES)));
491 4668 acydburn
                $refresh = true;
492 4668 acydburn
                $template->assign_var('S_DRAFT_LOADED', true);
493 4668 acydburn
        }
494 4668 acydburn
        else
495 4668 acydburn
        {
496 4668 acydburn
                $draft_id = 0;
497 4668 acydburn
        }
498 4668 acydburn
}
499 4467 acydburn
500 4668 acydburn
// Load Drafts
501 4668 acydburn
if ($load && $drafts)
502 4668 acydburn
{
503 4668 acydburn
        load_drafts($topic_id, $forum_id);
504 4668 acydburn
}
505 4668 acydburn
506 3961 psotfx
if ($submit || $preview || $refresh)
507 2923 psotfx
{
508 4539 acydburn
        $topic_cur_post_id        = request_var('topic_cur_post_id', 0);
509 5108 acydburn
        $subject = request_var('subject', '', true);
510 3631 acydburn
511 4767 acydburn
        if (strcmp($subject, strtoupper($subject)) == 0 && $subject)
512 3631 acydburn
        {
513 5003 acydburn
                $subject = strtolower($subject);
514 3631 acydburn
        }
515 4970 psotfx
516 5108 acydburn
        $message_parser->message = request_var('message', '', true);
517 4486 acydburn
518 4890 acydburn
        $username                        = (isset($_POST['username'])) ? request_var('username', '') : $username;
519 4890 acydburn
        $post_edit_reason        = (isset($_POST['edit_reason']) && !empty($_POST['edit_reason']) && $mode == 'edit' && $user->data['user_id'] != $poster_id) ? request_var('edit_reason', '') : '';
520 4767 acydburn
521 4504 acydburn
        $topic_type                        = (isset($_POST['topic_type'])) ? (int) $_POST['topic_type'] : (($mode != 'post') ? $topic_type : POST_NORMAL);
522 4545 acydburn
        $topic_time_limit        = (isset($_POST['topic_time_limit'])) ? (int) $_POST['topic_time_limit'] : (($mode != 'post') ? $topic_time_limit : 0);
523 4539 acydburn
        $icon_id                        = request_var('icon', 0);
524 3572 acydburn
525 4890 acydburn
        $enable_html                 = (!$html_status || isset($_POST['disable_html'])) ? false : true;
526 4890 acydburn
        $enable_bbcode                 = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
527 4890 acydburn
        $enable_smilies                = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
528 3582 acydburn
        $enable_urls                 = (isset($_POST['disable_magic_url'])) ? 0 : 1;
529 5117 acydburn
        $enable_sig                        = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
530 3937 ludovic_arnaud
531 4890 acydburn
        $notify                                = (isset($_POST['notify']));
532 4767 acydburn
        $topic_lock                        = (isset($_POST['lock_topic']));
533 4767 acydburn
        $post_lock                        = (isset($_POST['lock_post']));
534 3572 acydburn
535 4767 acydburn
        $poll_delete                = (isset($_POST['poll_delete']));
536 4970 psotfx
537 4978 acydburn
        if ($submit)
538 4978 acydburn
        {
539 4978 acydburn
                $status_switch        = (($enable_html+1) << 16) + (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1);
540 4978 acydburn
                $status_switch = ($status_switch != $check_value);
541 4978 acydburn
        }
542 4978 acydburn
        else
543 4978 acydburn
        {
544 4978 acydburn
                $status_switch = 1;
545 4978 acydburn
        }
546 4093 acydburn
547 4981 acydburn
        // Delete Poll
548 4981 acydburn
        if ($poll_delete && $mode == 'edit' && $poll_options &&
549 4981 acydburn
                ((!$poll_last_vote && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id)))
550 3631 acydburn
        {
551 4981 acydburn
                switch (SQL_LAYER)
552 4981 acydburn
                {
553 4981 acydburn
                        case 'mysql4':
554 5138 acydburn
                        case 'mysqli':
555 4981 acydburn
                                $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ', ' . POLL_VOTES_TABLE . "
556 4981 acydburn
                                        WHERE topic_id = $topic_id";
557 4981 acydburn
                                $db->sql_query($sql);
558 4981 acydburn
                                break;
559 3631 acydburn
560 4981 acydburn
                        default:
561 4981 acydburn
                                $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
562 4981 acydburn
                                        WHERE topic_id = $topic_id";
563 4981 acydburn
                                $db->sql_query($sql);
564 4981 acydburn
565 4981 acydburn
                                $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
566 4981 acydburn
                                        WHERE topic_id = $topic_id";
567 4981 acydburn
                                $db->sql_query($sql);
568 4981 acydburn
                }
569 4981 acydburn
570 3883 acydburn
                $topic_sql = array(
571 3920 psotfx
                        'poll_title'                => '',
572 3920 psotfx
                        'poll_start'                 => 0,
573 3920 psotfx
                        'poll_length'                => 0,
574 4970 psotfx
                        'poll_last_vote'        => 0,
575 4981 acydburn
                        'poll_max_options'        => 0,
576 4981 acydburn
                        'poll_vote_change'        => 0
577 3883 acydburn
                );
578 3883 acydburn
579 4970 psotfx
                $sql = 'UPDATE ' . TOPICS_TABLE . '
580 4970 psotfx
                        SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
581 4139 acydburn
                        WHERE topic_id = $topic_id";
582 3883 acydburn
                $db->sql_query($sql);
583 3883 acydburn
584 4981 acydburn
                $poll_title = $poll_option_text = '';
585 4981 acydburn
                $poll_vote_change = $poll_max_options = $poll_length = 0;
586 3631 acydburn
        }
587 3631 acydburn
        else
588 3631 acydburn
        {
589 4539 acydburn
                $poll_title                        = request_var('poll_title', '');
590 4539 acydburn
                $poll_length                = request_var('poll_length', 0);
591 4539 acydburn
                $poll_option_text        = request_var('poll_option_text', '');
592 4539 acydburn
                $poll_max_options        = request_var('poll_max_options', 1);
593 4981 acydburn
                $poll_vote_change        = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
594 3631 acydburn
        }
595 3631 acydburn
596 3072 psotfx
        // If replying/quoting and last post id has changed
597 4093 acydburn
        // give user option to continue submit or return to post
598 3543 acydburn
        // notify and show user the post made between his request and the final submit
599 4668 acydburn
        if (($mode == 'reply' || $mode == 'quote') && $topic_cur_post_id && $topic_cur_post_id != $topic_last_post_id)
600 3072 psotfx
        {
601 4551 acydburn
                if (topic_review($topic_id, $forum_id, 'post_review', $topic_cur_post_id))
602 3898 acydburn
                {
603 4767 acydburn
                        $template->assign_var('S_POST_REVIEW', true);
604 3898 acydburn
                }
605 4767 acydburn
                $submit = false;
606 4767 acydburn
                $refresh = true;
607 3072 psotfx
        }
608 3072 psotfx
609 4819 acydburn
        // Parse Attachments - before checksum is calculated
610 5108 acydburn
        $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
611 4170 psotfx
612 3354 psotfx
        // Grab md5 'checksum' of new message
613 3816 acydburn
        $message_md5 = md5($message_parser->message);
614 2972 psotfx
615 2983 psotfx
        // Check checksum ... don't re-parse message if the same
616 4978 acydburn
        $update_message = ($mode != 'edit' || $message_md5 != $post_checksum || $status_switch) ? true : false;
617 5011 acydburn
618 4938 acydburn
        // Parse message
619 4938 acydburn
        if ($update_message)
620 2923 psotfx
        {
621 4696 ludovic_arnaud
                $message_parser->parse($enable_html, $enable_bbcode, $enable_urls, $enable_smilies, $img_status, $flash_status, $quote_status);
622 2972 psotfx
        }
623 4938 acydburn
        else
624 4938 acydburn
        {
625 4938 acydburn
                $message_parser->bbcode_bitfield = $bbcode_bitfield;
626 4938 acydburn
        }
627 2183 psotfx
628 4696 ludovic_arnaud
        if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
629 3697 acydburn
        {
630 2972 psotfx
                // Flood check
631 4699 acydburn
                $last_post_time = 0;
632 4699 acydburn
633 5117 acydburn
                if ($user->data['is_registered'])
634 4575 acydburn
                {
635 4699 acydburn
                        $last_post_time = $user->data['user_lastpost_time'];
636 4575 acydburn
                }
637 4575 acydburn
                else
638 4575 acydburn
                {
639 4696 ludovic_arnaud
                        $sql = 'SELECT post_time AS last_post_time
640 4696 ludovic_arnaud
                                FROM ' . POSTS_TABLE . "
641 4696 ludovic_arnaud
                                WHERE poster_ip = '" . $user->ip . "'
642 4696 ludovic_arnaud
                                        AND post_time > " . ($current_time - $config['flood_interval']);
643 4699 acydburn
                        $result = $db->sql_query_limit($sql, 1);
644 4699 acydburn
                        if ($row = $db->sql_fetchrow($result))
645 4699 acydburn
                        {
646 4699 acydburn
                                $last_post_time = $row['last_post_time'];
647 4699 acydburn
                        }
648 4883 acydburn
                        $db->sql_freeresult($result);
649 4575 acydburn
                }
650 2183 psotfx
651 4699 acydburn
                if ($last_post_time)
652 2972 psotfx
                {
653 4699 acydburn
                        if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
654 2972 psotfx
                        {
655 4167 psotfx
                                $error[] = $user->lang['FLOOD_ERROR'];
656 2972 psotfx
                        }
657 2972 psotfx
                }
658 2972 psotfx
        }
659 2183 psotfx
660 2972 psotfx
        // Validate username
661 5117 acydburn
        if (($username && !$user->data['is_registered']) || ($mode == 'edit' && $post_username))
662 2972 psotfx
        {
663 3926 acydburn
                include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
664 4970 psotfx
665 4770 acydburn
                if (($result = validate_username(($mode == 'edit' && $post_username) ? $post_username : $username)) != false)
666 2972 psotfx
                {
667 4167 psotfx
                        $error[] = $result;
668 2972 psotfx
                }
669 2923 psotfx
        }
670 2183 psotfx
671 2972 psotfx
        // Parse subject
672 4767 acydburn
        if (!$subject && ($mode == 'post' || ($mode == 'edit' && $topic_first_post_id == $post_id)))
673 2972 psotfx
        {
674 4167 psotfx
                $error[] = $user->lang['EMPTY_SUBJECT'];
675 2972 psotfx
        }
676 4970 psotfx
677 4981 acydburn
        $poll_last_vote = (isset($poll_last_vote)) ? $poll_last_vote : 0;
678 3631 acydburn
679 4981 acydburn
        if ($poll_option_text &&
680 4981 acydburn
                ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id))))
681 4981 acydburn
                && $auth->acl_get('f_poll', $forum_id))
682 4981 acydburn
        {
683 4981 acydburn
                $poll = array(
684 4981 acydburn
                        'poll_title'                => $poll_title,
685 4981 acydburn
                        'poll_length'                => $poll_length,
686 4981 acydburn
                        'poll_max_options'        => $poll_max_options,
687 4981 acydburn
                        'poll_option_text'        => $poll_option_text,
688 4981 acydburn
                        'poll_start'                => $poll_start,
689 4981 acydburn
                        'poll_last_vote'        => $poll_last_vote,
690 4981 acydburn
                        'poll_vote_change'        => $poll_vote_change,
691 4981 acydburn
                        'enable_html'                => $enable_html,
692 4981 acydburn
                        'enable_bbcode'                => $enable_bbcode,
693 4981 acydburn
                        'enable_urls'                => $enable_urls,
694 4981 acydburn
                        'enable_smilies'        => $enable_smilies,
695 4981 acydburn
                        'img_status'                => $img_status
696 4981 acydburn
                );
697 2183 psotfx
698 4981 acydburn
                $message_parser->parse_poll($poll);
699 4981 acydburn
700 4981 acydburn
                $poll_options = isset($poll['poll_options']) ? $poll['poll_options'] : '';
701 4981 acydburn
                $poll_title = isset($poll['poll_title']) ? $poll['poll_title'] : '';
702 3631 acydburn
703 4981 acydburn
                if ($poll_last_vote && ($poll['poll_options_size'] < $orig_poll_options_size))
704 4981 acydburn
                {
705 4981 acydburn
                        $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
706 4981 acydburn
                }
707 4981 acydburn
        }
708 4981 acydburn
        else
709 4981 acydburn
        {
710 4981 acydburn
                $poll = array();
711 4981 acydburn
        }
712 4981 acydburn
713 2983 psotfx
        // Check topic type
714 4627 acydburn
        if ($topic_type != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $topic_first_post_id == $post_id)))
715 2983 psotfx
        {
716 2983 psotfx
                switch ($topic_type)
717 2983 psotfx
                {
718 3980 psotfx
                        case POST_GLOBAL:
719 3553 acydburn
                        case POST_ANNOUNCE:
720 4167 psotfx
                                $auth_option = 'f_announce';
721 2983 psotfx
                                break;
722 3553 acydburn
                        case POST_STICKY:
723 4167 psotfx
                                $auth_option = 'f_sticky';
724 2983 psotfx
                                break;
725 4167 psotfx
                        default:
726 4167 psotfx
                                $auth_option = '';
727 2983 psotfx
                }
728 2983 psotfx
729 4167 psotfx
                if (!$auth->acl_get($auth_option, $forum_id))
730 2983 psotfx
                {
731 4627 acydburn
                        $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
732 2983 psotfx
                }
733 2983 psotfx
        }
734 2983 psotfx
735 4184 acydburn
        if (sizeof($message_parser->warn_msg))
736 4184 acydburn
        {
737 4184 acydburn
                $error[] = implode('<br />', $message_parser->warn_msg);
738 4184 acydburn
        }
739 4184 acydburn
740 2981 psotfx
        // Store message, sync counters
741 4167 psotfx
        if (!sizeof($error) && $submit)
742 2972 psotfx
        {
743 4460 acydburn
                // Check if we want to de-globalize the topic... and ask for new forum
744 4460 acydburn
                if ($topic_type != POST_GLOBAL)
745 3817 acydburn
                {
746 4461 acydburn
                        $sql = 'SELECT topic_type, forum_id
747 4460 acydburn
                                FROM ' . TOPICS_TABLE . "
748 4460 acydburn
                                WHERE topic_id = $topic_id";
749 4460 acydburn
                        $result = $db->sql_query_limit($sql, 1);
750 3817 acydburn
751 4460 acydburn
                        $row = $db->sql_fetchrow($result);
752 4970 psotfx
753 4767 acydburn
                        if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
754 4460 acydburn
                        {
755 4539 acydburn
                                $to_forum_id = request_var('to_forum_id', 0);
756 4970 psotfx
757 4460 acydburn
                                if (!$to_forum_id)
758 4460 acydburn
                                {
759 4460 acydburn
                                        $template->assign_vars(array(
760 4767 acydburn
                                                'S_FORUM_SELECT'        => make_forum_select(false, false, false, true, true),
761 4970 psotfx
                                                'S_UNGLOBALISE'                => true)
762 4460 acydburn
                                        );
763 4970 psotfx
764 4767 acydburn
                                        $submit = false;
765 4767 acydburn
                                        $refresh = true;
766 4460 acydburn
                                }
767 4460 acydburn
                                else
768 4460 acydburn
                                {
769 4460 acydburn
                                        $forum_id = $to_forum_id;
770 4460 acydburn
                                }
771 4460 acydburn
                        }
772 3817 acydburn
                }
773 3817 acydburn
774 4460 acydburn
                if ($submit)
775 3817 acydburn
                {
776 4460 acydburn
                        // Lock/Unlock Topic
777 4460 acydburn
                        $change_topic_status = $topic_status;
778 5117 acydburn
                        $perm_lock_unlock = ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster));
779 3817 acydburn
780 4575 acydburn
                        if ($topic_status == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
781 4460 acydburn
                        {
782 4460 acydburn
                                $change_topic_status = ITEM_UNLOCKED;
783 4460 acydburn
                        }
784 4575 acydburn
                        else if ($topic_status == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
785 4460 acydburn
                        {
786 4460 acydburn
                                $change_topic_status = ITEM_LOCKED;
787 4460 acydburn
                        }
788 4970 psotfx
789 4460 acydburn
                        if ($change_topic_status != $topic_status)
790 4460 acydburn
                        {
791 4460 acydburn
                                $sql = 'UPDATE ' . TOPICS_TABLE . "
792 4460 acydburn
                                        SET topic_status = $change_topic_status
793 4460 acydburn
                                        WHERE topic_id = $topic_id
794 4460 acydburn
                                                AND topic_moved_id = 0";
795 4460 acydburn
                                $db->sql_query($sql);
796 4970 psotfx
797 5117 acydburn
                                $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster) ? 'USER_' : '';
798 4767 acydburn
799 4920 acydburn
                                add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $topic_title);
800 4460 acydburn
                        }
801 4460 acydburn
802 4460 acydburn
                        // Lock/Unlock Post Edit
803 4460 acydburn
                        if ($mode == 'edit' && $post_edit_locked == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
804 4460 acydburn
                        {
805 4460 acydburn
                                $post_edit_locked = ITEM_UNLOCKED;
806 4460 acydburn
                        }
807 4460 acydburn
                        else if ($mode == 'edit' && $post_edit_locked == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
808 4460 acydburn
                        {
809 4460 acydburn
                                $post_edit_locked = ITEM_LOCKED;
810 4460 acydburn
                        }
811 4460 acydburn
812 4460 acydburn
                        $post_data = array(
813 4767 acydburn
                                'topic_title'                        => (!$topic_title) ? $subject : $topic_title,
814 4890 acydburn
                                'topic_first_post_id'        => (isset($topic_first_post_id)) ? (int) $topic_first_post_id : 0,
815 4890 acydburn
                                'topic_last_post_id'        => (isset($topic_last_post_id)) ? (int) $topic_last_post_id : 0,
816 4545 acydburn
                                'topic_time_limit'                => (int) $topic_time_limit,
817 4545 acydburn
                                'post_id'                                => (int) $post_id,
818 4545 acydburn
                                'topic_id'                                => (int) $topic_id,
819 4545 acydburn
                                'forum_id'                                => (int) $forum_id,
820 4545 acydburn
                                'icon_id'                                => (int) $icon_id,
821 4545 acydburn
                                'poster_id'                                => (int) $poster_id,
822 4545 acydburn
                                'enable_sig'                        => (bool) $enable_sig,
823 4545 acydburn
                                'enable_bbcode'                        => (bool) $enable_bbcode,
824 4545 acydburn
                                'enable_html'                         => (bool) $enable_html,
825 4545 acydburn
                                'enable_smilies'                => (bool) $enable_smilies,
826 4545 acydburn
                                'enable_urls'                        => (bool) $enable_urls,
827 4668 acydburn
                                'enable_indexing'                => (bool) $enable_indexing,
828 4890 acydburn
                                'message_md5'                        => (string) $message_md5,
829 4890 acydburn
                                'post_time'                                => (isset($post_time)) ? (int) $post_time : $current_time,
830 4890 acydburn
                                'post_checksum'                        => (isset($post_checksum)) ? (string) $post_checksum : '',
831 4767 acydburn
                                'post_edit_reason'                => $post_edit_reason,
832 4890 acydburn
                                'post_edit_user'                => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_edit_user)) ? (int) $post_edit_user : 0),
833 4460 acydburn
                                'forum_parents'                        => $forum_parents,
834 4535 acydburn
                                'forum_name'                        => $forum_name,
835 4460 acydburn
                                'notify'                                => $notify,
836 4460 acydburn
                                'notify_set'                        => $notify_set,
837 4890 acydburn
                                'poster_ip'                                => (isset($poster_ip)) ? (int) $poster_ip : $user->ip,
838 4545 acydburn
                                'post_edit_locked'                => (int) $post_edit_locked,
839 4978 acydburn
                                'bbcode_bitfield'                => (int) $message_parser->bbcode_bitfield,
840 4978 acydburn
                                'bbcode_uid'                        => $message_parser->bbcode_uid,
841 4978 acydburn
                                'message'                                => $message_parser->message,
842 4978 acydburn
                                'attachment_data'                => $message_parser->attachment_data,
843 4978 acydburn
                                'filename_data'                        => $message_parser->filename_data
844 4460 acydburn
                        );
845 4978 acydburn
                        unset($message_parser);
846 4970 psotfx
847 4978 acydburn
                        submit_post($mode, $subject, $username, $topic_type, $poll, $post_data, $update_message);
848 4460 acydburn
                }
849 4970 psotfx
        }
850 3538 psotfx
851 4542 acydburn
        $post_subject = stripslashes($subject);
852 3572 acydburn
}
853 2983 psotfx
854 4139 acydburn
// Preview
855 4167 psotfx
if (!sizeof($error) && $preview)
856 3553 acydburn
{
857 4170 psotfx
        $post_time = ($mode == 'edit') ? $post_time : $current_time;
858 3812 ludovic_arnaud
859 4978 acydburn
        $preview_message = $message_parser->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies, false);
860 4167 psotfx
861 4170 psotfx
        $preview_signature = ($mode == 'edit') ? $user_sig : $user->data['user_sig'];
862 4170 psotfx
        $preview_signature_uid = ($mode == 'edit') ? $user_sig_bbcode_uid : $user->data['user_sig_bbcode_uid'];
863 4170 psotfx
        $preview_signature_bitfield = ($mode == 'edit') ? $user_sig_bbcode_bitfield : $user->data['user_sig_bbcode_bitfield'];
864 4170 psotfx
865 4978 acydburn
        // Signature
866 4978 acydburn
        if ($enable_sig && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
867 4978 acydburn
        {
868 4978 acydburn
                $parse_sig = new parse_message($preview_signature);
869 4978 acydburn
                $parse_sig->bbcode_uid = $preview_signature_uid;
870 4978 acydburn
                $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
871 3812 ludovic_arnaud
872 4978 acydburn
                // Not sure about parameters for bbcode/smilies/urls... in signatures
873 4978 acydburn
                $parse_sig->format_display($config['allow_html'], $config['allow_bbcode'], true, $config['allow_smilies']);
874 4978 acydburn
                $preview_signature = $parse_sig->message;
875 4978 acydburn
                unset($parse_sig);
876 4978 acydburn
        }
877 4978 acydburn
        else
878 4978 acydburn
        {
879 4978 acydburn
                $preview_signature = '';
880 4978 acydburn
        }
881 4978 acydburn
882 4978 acydburn
        $preview_subject = censor_text($subject);
883 4978 acydburn
884 3631 acydburn
        // Poll Preview
885 4981 acydburn
        if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id))))
886 4981 acydburn
        && $auth->acl_get('f_poll', $forum_id))
887 3572 acydburn
        {
888 4981 acydburn
                $parse_poll = new parse_message($poll_title);
889 4981 acydburn
                $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
890 4981 acydburn
                $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
891 4981 acydburn
892 4981 acydburn
                $parse_poll->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies);
893 4981 acydburn
894 3631 acydburn
                $template->assign_vars(array(
895 4981 acydburn
                        'S_HAS_POLL_OPTIONS'=> (sizeof($poll_options)),
896 4981 acydburn
                        'S_IS_MULTI_CHOICE'        => ($poll_max_options > 1) ? true : false,
897 4981 acydburn
898 4981 acydburn
                        'POLL_QUESTION'                => $parse_poll->message,
899 4981 acydburn
900 4981 acydburn
                        'L_POLL_LENGTH'                => ($poll_length) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_length + $poll_start)) : '',
901 4981 acydburn
                        'L_MAX_VOTES'                => ($poll_max_options == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $poll_max_options))
902 3631 acydburn
                );
903 3631 acydburn
904 4981 acydburn
                $parse_poll->message = implode("\n", $poll_options);
905 4981 acydburn
                $parse_poll->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies);
906 4981 acydburn
                $preview_poll_options = explode('<br />', $parse_poll->message);
907 4981 acydburn
                unset($parse_poll);
908 4981 acydburn
909 4981 acydburn
                foreach ($preview_poll_options as $option)
910 3631 acydburn
                {
911 4981 acydburn
                        $template->assign_block_vars('poll_option', array('POLL_OPTION_CAPTION' => $option));
912 3631 acydburn
                }
913 4981 acydburn
                unset($preview_poll_options);
914 3572 acydburn
        }
915 4139 acydburn
916 4139 acydburn
        // Attachment Preview
917 4139 acydburn
        if (sizeof($message_parser->attachment_data))
918 4139 acydburn
        {
919 4139 acydburn
                $extensions = $update_count = array();
920 4970 psotfx
921 4767 acydburn
                $template->assign_var('S_HAS_ATTACHMENTS', true);
922 4984 acydburn
923 4984 acydburn
                $attachment_data = $message_parser->attachment_data;
924 5032 acydburn
                $unset_attachments = parse_inline_attachments($preview_message, $attachment_data, $update_count, $forum_id, true);
925 4984 acydburn
926 4984 acydburn
                foreach ($unset_attachments as $index)
927 4984 acydburn
                {
928 4984 acydburn
                        unset($attachment_data[$index]);
929 4984 acydburn
                }
930 4984 acydburn
931 4984 acydburn
                foreach ($attachment_data as $i => $attachment)
932 4984 acydburn
                {
933 4984 acydburn
                        $template->assign_block_vars('attachment', array(
934 4984 acydburn
                                'DISPLAY_ATTACHMENT'        => $attachment)
935 4984 acydburn
                        );
936 4984 acydburn
                }
937 4984 acydburn
                unset($attachment_data, $attachment);
938 4139 acydburn
        }
939 3553 acydburn
940 4978 acydburn
        if (!sizeof($error))
941 4978 acydburn
        {
942 4978 acydburn
                $template->assign_vars(array(
943 4978 acydburn
                        'PREVIEW_SUBJECT'                => $preview_subject,
944 4978 acydburn
                        'PREVIEW_MESSAGE'                => $preview_message,
945 4978 acydburn
                        'PREVIEW_SIGNATURE'                => $preview_signature,
946 4167 psotfx
947 4978 acydburn
                        'S_DISPLAY_PREVIEW'                => true)
948 4978 acydburn
                );
949 4978 acydburn
        }
950 3879 ludovic_arnaud
951 4978 acydburn
        unset($post_text);
952 3858 ludovic_arnaud
}
953 987 psotfx
954 4978 acydburn
// Decode text for message display
955 4978 acydburn
$bbcode_uid = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $bbcode_uid : $message_parser->bbcode_uid;
956 4978 acydburn
$message_parser->decode_message($bbcode_uid);
957 3631 acydburn
958 4139 acydburn
if ($mode == 'quote' && !$preview && !$refresh)
959 3572 acydburn
{
960 4978 acydburn
        $message_parser->message = '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
961 3572 acydburn
}
962 3572 acydburn
963 4139 acydburn
if (($mode == 'reply' || $mode == 'quote') && !$preview && !$refresh)
964 3631 acydburn
{
965 4836 acydburn
        $post_subject = ((!preg_match('/^Re:/', $post_subject)) ? 'Re: ' : '') . censor_text($post_subject);
966 3631 acydburn
}
967 3631 acydburn
968 4978 acydburn
$attachment_data = $message_parser->attachment_data;
969 4978 acydburn
$filename_data = $message_parser->filename_data;
970 4978 acydburn
$post_text = $message_parser->message;
971 4981 acydburn
972 4981 acydburn
if (sizeof($poll_options) && $poll_title)
973 4981 acydburn
{
974 4981 acydburn
        $message_parser->message = $poll_title;
975 4981 acydburn
        $message_parser->bbcode_uid = $bbcode_uid;
976 4981 acydburn
977 4981 acydburn
        $message_parser->decode_message();
978 4981 acydburn
        $poll_title = $message_parser->message;
979 4981 acydburn
980 4981 acydburn
        $message_parser->message = implode("\n", $poll_options);
981 4981 acydburn
        $message_parser->decode_message();
982 4981 acydburn
        $poll_options = explode("\n", $message_parser->message);
983 4981 acydburn
}
984 4978 acydburn
unset($message_parser);
985 4167 psotfx
986 2923 psotfx
// MAIN POSTING PAGE BEGINS HERE
987 470 thefinn
988 3014 psotfx
// Forum moderators?
989 3572 acydburn
get_moderators($moderators, $forum_id);
990 3014 psotfx
991 5108 acydburn
// Generate smiley listing
992 4544 acydburn
generate_smilies('inline', $forum_id);
993 487 psotfx
994 4819 acydburn
// Generate inline attachment select box
995 4978 acydburn
posting_gen_inline_attachments($attachment_data);
996 4819 acydburn
997 4919 acydburn
998 4968 acydburn
// Do show topic type selection only in first post.
999 4968 acydburn
$topic_type_toggle = false;
1000 4919 acydburn
1001 4139 acydburn
if ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id))
1002 3553 acydburn
{
1003 4883 acydburn
        $topic_type_toggle = posting_gen_topic_types($forum_id, $topic_type);
1004 4968 acydburn
}
1005 4919 acydburn
1006 4968 acydburn
$s_topic_icons = false;
1007 4968 acydburn
if ($enable_icons)
1008 4968 acydburn
{
1009 4968 acydburn
        $s_topic_icons = posting_gen_topic_icons($mode, $icon_id);
1010 487 psotfx
}
1011 323 thefinn
1012 4575 acydburn
$html_checked                = (isset($enable_html)) ? !$enable_html : (($config['allow_html']) ? !$user->optionget('html') : 1);
1013 4575 acydburn
$bbcode_checked                = (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1014 5108 acydburn
$smilies_checked        = (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1015 4139 acydburn
$urls_checked                = (isset($enable_urls)) ? !$enable_urls : 0;
1016 4139 acydburn
$sig_checked                = $enable_sig;
1017 5117 acydburn
$notify_checked                = (isset($notify)) ? $notify : ((!$notify_set) ? (($user->data['is_registered']) ? $user->data['user_notify'] : 0) : 1);
1018 4139 acydburn
$lock_topic_checked        = (isset($topic_lock)) ? $topic_lock : (($topic_status == ITEM_LOCKED) ? 1 : 0);
1019 4139 acydburn
$lock_post_checked        = (isset($post_lock)) ? $post_lock : $post_edit_locked;
1020 2983 psotfx
1021 3338 ludovic_arnaud
// Page title & action URL, include session_id for security purpose
1022 4139 acydburn
$s_action = "posting.$phpEx?sid=" . $user->session_id . "&amp;mode=$mode&amp;f=$forum_id";
1023 4139 acydburn
$s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
1024 4139 acydburn
$s_action .= ($post_id) ? "&amp;p=$post_id" : '';
1025 3575 acydburn
1026 3354 psotfx
switch ($mode)
1027 836 psotfx
{
1028 2972 psotfx
        case 'post':
1029 3022 psotfx
                $page_title = $user->lang['POST_TOPIC'];
1030 987 psotfx
                break;
1031 824 psotfx
1032 3553 acydburn
        case 'quote':
1033 987 psotfx
        case 'reply':
1034 3022 psotfx
                $page_title = $user->lang['POST_REPLY'];
1035 987 psotfx
                break;
1036 987 psotfx
1037 3575 acydburn
        case 'delete':
1038 2972 psotfx
        case 'edit':
1039 3061 psotfx
                $page_title = $user->lang['EDIT_POST'];
1040 836 psotfx
}
1041 824 psotfx
1042 3553 acydburn
$forum_data = array(
1043 4139 acydburn
        'parent_id'                => $parent_id,
1044 4920 acydburn
        'left_id'                => $left_id,
1045 4920 acydburn
        'right_id'                => $right_id,
1046 4139 acydburn
        'forum_parents'        => $forum_parents,
1047 4139 acydburn
        'forum_name'        => $forum_name,
1048 4139 acydburn
        'forum_id'                => $forum_id,
1049 4870 acydburn
        'forum_type'        => $forum_type,
1050 4903 acydburn
        'forum_desc'        => $forum_desc,
1051 4903 acydburn
        'forum_rules'        => $forum_rules,
1052 4903 acydburn
        'forum_rules_flags' => $forum_rules_flags,
1053 4978 acydburn
        'forum_rules_bbcode_uid' => $forum_rules_bbcode_uid,
1054 4978 acydburn
        'forum_rules_bbcode_bitfield' => $forum_rules_bbcode_bitfield,
1055 4903 acydburn
        'forum_rules_link' => $forum_rules_link
1056 3553 acydburn
);
1057 4903 acydburn
1058 4904 acydburn
// Build Navigation Links
1059 3538 psotfx
generate_forum_nav($forum_data);
1060 3354 psotfx
1061 4904 acydburn
// Build Forum Rules
1062 4903 acydburn
generate_forum_rules($forum_data);
1063 4903 acydburn
1064 3631 acydburn
$s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $topic_last_post_id . '" />' : '';
1065 4625 acydburn
$s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1066 4668 acydburn
$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . ((isset($_REQUEST['draft_loaded'])) ? intval($_REQUEST['draft_loaded']) : $draft_id) . '" />' : '';
1067 3631 acydburn
1068 4883 acydburn
$form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || @ini_get('file_uploads') == '0' || !$config['allow_attachments'] || !$auth->acl_gets('f_attach', 'u_attach', $forum_id)) ? '' : ' enctype="multipart/form-data"';
1069 3631 acydburn
1070 2923 psotfx
// Start assigning vars for main posting page ...
1071 2183 psotfx
$template->assign_vars(array(
1072 3572 acydburn
        'L_POST_A'                                => $page_title,
1073 4970 psotfx
        'L_ICON'                                => ($mode == 'reply' || $mode == 'quote') ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1074 3572 acydburn
        'L_MESSAGE_BODY_EXPLAIN'=> (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1075 1609 psotfx
1076 3572 acydburn
        'FORUM_NAME'                         => $forum_name,
1077 4767 acydburn
        'FORUM_DESC'                        => ($forum_desc) ? strip_tags($forum_desc) : '',
1078 3572 acydburn
        'TOPIC_TITLE'                         => $topic_title,
1079 3842 psotfx
        'MODERATORS'                         => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1080 4178 acydburn
        'USERNAME'                                => ((!$preview && $mode != 'quote') || $preview) ? stripslashes($username) : '',
1081 3631 acydburn
        'SUBJECT'                                => $post_subject,
1082 4978 acydburn
        'MESSAGE'                                => $post_text,
1083 3572 acydburn
        'HTML_STATUS'                        => ($html_status) ? $user->lang['HTML_IS_ON'] : $user->lang['HTML_IS_OFF'],
1084 3572 acydburn
        'BBCODE_STATUS'                        => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . "faq.$phpEx$SID&amp;mode=bbcode" . '" target="_phpbbcode">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . "faq.$phpEx$SID&amp;mode=bbcode" . '" target="_phpbbcode">', '</a>'),
1085 3572 acydburn
        'IMG_STATUS'                        => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1086 3572 acydburn
        'FLASH_STATUS'                        => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1087 3572 acydburn
        'SMILIES_STATUS'                => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1088 3816 acydburn
        'MINI_POST_IMG'                        => $user->img('icon_post', $user->lang['POST']),
1089 3572 acydburn
        'POST_DATE'                                => ($post_time) ? $user->format_date($post_time) : '',
1090 4970 psotfx
        'ERROR'                                        => (sizeof($error)) ? implode('<br />', $error) : '',
1091 4545 acydburn
        'TOPIC_TIME_LIMIT'                => (int) $topic_time_limit,
1092 4767 acydburn
        'EDIT_REASON'                        => $post_edit_reason,
1093 1609 psotfx
1094 3572 acydburn
        'U_VIEW_FORUM'                         => "viewforum.$phpEx$SID&amp;f=" . $forum_id,
1095 4139 acydburn
        'U_VIEWTOPIC'                         => ($mode != 'post') ? "viewtopic.$phpEx$SID&amp;$forum_id&amp;t=$topic_id" : '',
1096 4912 acydburn
        'U_PROGRESS_BAR'                => "posting.$phpEx$SID&f=$forum_id&mode=popup", // do NOT replace & with &amp; here
1097 3572 acydburn
1098 4890 acydburn
        'S_PRIVMSGS'                        => false,
1099 4883 acydburn
        'S_CLOSE_PROGRESS_WINDOW'        => isset($_POST['add_file']),
1100 4504 acydburn
        'S_EDIT_POST'                        => ($mode == 'edit'),
1101 4767 acydburn
        'S_EDIT_REASON'                        => ($mode == 'edit' && $user->data['user_id'] != $poster_id),
1102 5117 acydburn
        'S_DISPLAY_USERNAME'        => (!$user->data['is_registered'] || ($mode == 'edit' && $post_username)),
1103 3572 acydburn
        'S_SHOW_TOPIC_ICONS'        => $s_topic_icons,
1104 4767 acydburn
        'S_DELETE_ALLOWED'                 => ($mode == 'edit' && (($post_id == $topic_last_post_id && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))),
1105 3572 acydburn
        'S_HTML_ALLOWED'                => $html_status,
1106 4504 acydburn
        'S_HTML_CHECKED'                 => ($html_checked) ? ' checked="checked"' : '',
1107 3572 acydburn
        'S_BBCODE_ALLOWED'                => $bbcode_status,
1108 4504 acydburn
        'S_BBCODE_CHECKED'                 => ($bbcode_checked) ? ' checked="checked"' : '',
1109 3572 acydburn
        'S_SMILIES_ALLOWED'                => $smilies_status,
1110 4504 acydburn
        'S_SMILIES_CHECKED'         => ($smilies_checked) ? ' checked="checked"' : '',
1111 5117 acydburn
        'S_SIG_ALLOWED'                        => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']),
1112 4504 acydburn
        'S_SIGNATURE_CHECKED'         => ($sig_checked) ? ' checked="checked"' : '',
1113 5117 acydburn
        'S_NOTIFY_ALLOWED'                => ($user->data['is_registered']),
1114 4504 acydburn
        'S_NOTIFY_CHECKED'                 => ($notify_checked) ? ' checked="checked"' : '',
1115 5117 acydburn
        'S_LOCK_TOPIC_ALLOWED'        => (($mode == 'edit' || $mode == 'reply' || $mode == 'quote') && ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster))),
1116 4504 acydburn
        'S_LOCK_TOPIC_CHECKED'        => ($lock_topic_checked) ? ' checked="checked"' : '',
1117 4767 acydburn
        'S_LOCK_POST_ALLOWED'        => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)),
1118 4504 acydburn
        'S_LOCK_POST_CHECKED'        => ($lock_post_checked) ? ' checked="checked"' : '',
1119 4504 acydburn
        'S_MAGIC_URL_CHECKED'         => ($urls_checked) ? ' checked="checked"' : '',
1120 3572 acydburn
        'S_TYPE_TOGGLE'                        => $topic_type_toggle,
1121 5117 acydburn
        'S_SAVE_ALLOWED'                => ($auth->acl_get('u_savedrafts') && $user->data['is_registered']),
1122 5117 acydburn
        'S_HAS_DRAFTS'                        => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $drafts),
1123 3697 acydburn
        'S_FORM_ENCTYPE'                => $form_enctype,
1124 3697 acydburn
1125 3572 acydburn
        'S_POST_ACTION'                 => $s_action,
1126 3631 acydburn
        'S_HIDDEN_FIELDS'                => $s_hidden_fields)
1127 487 psotfx
);
1128 347 psotfx
1129 3631 acydburn
// Poll entry
1130 4981 acydburn
if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id))))
1131 4981 acydburn
        && $auth->acl_get('f_poll', $forum_id))
1132 3631 acydburn
{
1133 3631 acydburn
        $template->assign_vars(array(
1134 4767 acydburn
                'S_SHOW_POLL_BOX'                => true,
1135 4981 acydburn
                'S_POLL_VOTE_CHANGE'        => ($auth->acl_get('f_votechg', $forum_id)),
1136 4767 acydburn
                'S_POLL_DELETE'                        => ($mode == 'edit' && $poll_options && ((!$poll_last_vote && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))),
1137 3631 acydburn
1138 3631 acydburn
                'L_POLL_OPTIONS_EXPLAIN'=> sprintf($user->lang['POLL_OPTIONS_EXPLAIN'], $config['max_poll_options']),
1139 3631 acydburn
1140 4981 acydburn
                'VOTE_CHANGE_CHECKED'        => (isset($poll_vote_change) && $poll_vote_change) ? ' checked="checked"' : '',
1141 4890 acydburn
                'POLL_TITLE'                         => (isset($poll_title)) ? $poll_title : '',
1142 4890 acydburn
                'POLL_OPTIONS'                        => (isset($poll_options) && $poll_options) ? implode("\n", $poll_options) : '',
1143 4970 psotfx
                'POLL_MAX_OPTIONS'                => (isset($poll_max_options)) ? (int) $poll_max_options : 1,
1144 4139 acydburn
                'POLL_LENGTH'                         => $poll_length)
1145 3631 acydburn
        );
1146 3631 acydburn
}
1147 3631 acydburn
1148 3697 acydburn
// Attachment entry
1149 4978 acydburn
// Not using acl_gets here, because it is using OR logic
1150 4978 acydburn
if ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype)
1151 3697 acydburn
{
1152 4978 acydburn
        posting_gen_attachment_entry($attachment_data, $filename_data);
1153 3697 acydburn
}
1154 3697 acydburn
1155 2923 psotfx
// Output page ...
1156 3969 psotfx
page_header($page_title);
1157 2923 psotfx
1158 2923 psotfx
$template->set_filenames(array(
1159 3072 psotfx
        'body' => 'posting_body.html')
1160 2923 psotfx
);
1161 3572 acydburn
1162 2923 psotfx
make_jumpbox('viewforum.'.$phpEx);
1163 2923 psotfx
1164 3575 acydburn
// Topic review
1165 3575 acydburn
if ($mode == 'reply' || $mode == 'quote')
1166 3575 acydburn
{
1167 4551 acydburn
        if (topic_review($topic_id, $forum_id))
1168 4542 acydburn
        {
1169 4767 acydburn
                $template->assign_var('S_DISPLAY_REVIEW', true);
1170 4542 acydburn
        }
1171 3575 acydburn
}
1172 3575 acydburn
1173 3969 psotfx
page_footer();
1174 487 psotfx
1175 4167 psotfx
1176 5114 acydburn
/**
1177 5114 acydburn
* Delete Post
1178 5114 acydburn
*/
1179 4984 acydburn
function delete_post($mode, $post_id, $topic_id, $forum_id, &$data)
1180 4479 acydburn
{
1181 4479 acydburn
        global $db, $user, $config, $auth, $phpEx, $SID;
1182 4479 acydburn
1183 4479 acydburn
        // Specify our post mode
1184 4479 acydburn
        $post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'delete_topic' : (($data['topic_first_post_id'] == $post_id) ? 'delete_first_post' : (($data['topic_last_post_id'] == $post_id) ? 'delete_last_post' : 'delete'));
1185 4551 acydburn
        $sql_data = array();
1186 4479 acydburn
        $next_post_id = 0;
1187 4479 acydburn
1188 4479 acydburn
        $db->sql_transaction();
1189 4479 acydburn
1190 4767 acydburn
        if (!delete_posts('post_id', array($post_id), false))
1191 4479 acydburn
        {
1192 4479 acydburn
                // Try to delete topic, we may had an previous error causing inconsistency
1193 4479 acydburn
                if ($post_mode = 'delete_topic')
1194 4479 acydburn
                {
1195 4767 acydburn
                        delete_topics('topic_id', array($topic_id), false);
1196 4479 acydburn
                }
1197 4575 acydburn
                trigger_error('ALREADY_DELETED');
1198 4479 acydburn
        }
1199 4479 acydburn
1200 4479 acydburn
        $db->sql_transaction('commit');
1201 4479 acydburn
1202 4479 acydburn
        // Collect the necessary informations for updating the tables
1203 4682 acydburn
        $sql_data[FORUMS_TABLE] = '';
1204 4479 acydburn
        switch ($post_mode)
1205 4479 acydburn
        {
1206 4479 acydburn
                case 'delete_topic':
1207 4767 acydburn
                        delete_topics('topic_id', array($topic_id), false);
1208 4767 acydburn
                        set_config('num_topics', $config['num_topics'] - 1, true);
1209 4479 acydburn
1210 4504 acydburn
                        if ($data['topic_type'] != POST_GLOBAL)
1211 4504 acydburn
                        {
1212 4682 acydburn
                                $sql_data[FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics_real = forum_topics_real - 1';
1213 4682 acydburn
                                $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_topics = forum_topics - 1' : '';
1214 4504 acydburn
                        }
1215 4504 acydburn
1216 4767 acydburn
                        $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
1217 4682 acydburn
                        $sql_data[FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id));
1218 4682 acydburn
                        $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
1219 4479 acydburn
                        break;
1220 4479 acydburn
1221 4479 acydburn
                case 'delete_first_post':
1222 4970 psotfx
                        $sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username
1223 4479 acydburn
                                FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
1224 4970 psotfx
                                WHERE p.topic_id = $topic_id
1225 4970 psotfx
                                        AND p.poster_id = u.user_id
1226 4479 acydburn
                                ORDER BY p.post_time ASC";
1227 4479 acydburn
                        $result = $db->sql_query_limit($sql, 1);
1228 4479 acydburn
1229 4479 acydburn
                        $row = $db->sql_fetchrow($result);
1230 4479 acydburn
                        $db->sql_freeresult($result);
1231 4479 acydburn
1232 4504 acydburn
                        if ($data['topic_type'] != POST_GLOBAL)
1233 4504 acydburn
                        {
1234 4682 acydburn
                                $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
1235 4504 acydburn
                        }
1236 4504 acydburn
1237 4682 acydburn
                        $sql_data[TOPICS_TABLE] = 'topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'";
1238 4682 acydburn
                        $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
1239 4479 acydburn
1240 4479 acydburn
                        $next_post_id = (int) $row['post_id'];
1241 4479 acydburn
                        break;
1242 4970 psotfx
1243 4479 acydburn
                case 'delete_last_post':
1244 4504 acydburn
                        if ($data['topic_type'] != POST_GLOBAL)
1245 4504 acydburn
                        {
1246 4682 acydburn
                                $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
1247 4504 acydburn
                        }
1248 4504 acydburn
1249 4767 acydburn
                        $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
1250 4682 acydburn
                        $sql_data[FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id));
1251 4682 acydburn
                        $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
1252 4678 acydburn
1253 4682 acydburn
                        $update = update_last_post_information('topic', $topic_id);
1254 4479 acydburn
                        if (sizeof($update))
1255 4479 acydburn
                        {
1256 4682 acydburn
                                $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update);
1257 4678 acydburn
                                $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update[0]);
1258 4479 acydburn
                        }
1259 4678 acydburn
                        else
1260 4678 acydburn
                        {
1261 4678 acydburn
                                $sql = 'SELECT MAX(post_id) as last_post_id
1262 4678 acydburn
                                        FROM ' . POSTS_TABLE . "
1263 4678 acydburn
                                        WHERE topic_id = $topic_id " .
1264 5088 acydburn
                                                ((!$auth->acl_get('m_approve')) ? 'AND post_approved = 1' : '');
1265 4678 acydburn
                                $result = $db->sql_query($sql);
1266 4678 acydburn
                                $row = $db->sql_fetchrow($result);
1267 4678 acydburn
                                $db->sql_freeresult($result);
1268 4970 psotfx
1269 4678 acydburn
                                $next_post_id = (int) $row['last_post_id'];
1270 4678 acydburn
                        }
1271 4479 acydburn
                        break;
1272 4970 psotfx
1273 4479 acydburn
                case 'delete':
1274 4479 acydburn
                        $sql = 'SELECT post_id
1275 4479 acydburn
                                FROM ' . POSTS_TABLE . "
1276 4970 psotfx
                                WHERE topic_id = $topic_id " .
1277 5088 acydburn
                                        ((!$auth->acl_get('m_approve')) ? 'AND post_approved = 1' : '') . '
1278 4479 acydburn
                                        AND post_time > ' . $data['post_time'] . '
1279 4479 acydburn
                                ORDER BY post_time ASC';
1280 4479 acydburn
                        $result = $db->sql_query_limit($sql, 1);
1281 4479 acydburn
1282 4479 acydburn
                        $row = $db->sql_fetchrow($result);
1283 4479 acydburn
                        $db->sql_freeresult($result);
1284 4479 acydburn
1285 4504 acydburn
                        if ($data['topic_type'] != POST_GLOBAL)
1286 4504 acydburn
                        {
1287 4682 acydburn
                                $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
1288 4504 acydburn
                        }
1289 4504 acydburn
1290 4682 acydburn
                        $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
1291 4479 acydburn
                        $next_post_id = (int) $row['post_id'];
1292 4479 acydburn
        }
1293 4970 psotfx
1294 4682 acydburn
        $sql_data[USERS_TABLE] = ($auth->acl_get('f_postcount', $forum_id)) ? 'user_posts = user_posts - 1' : '';
1295 4767 acydburn
        set_config('num_posts', $config['num_posts'] - 1, true);
1296 4479 acydburn
1297 4479 acydburn
        $db->sql_transaction();
1298 4479 acydburn
1299 4682 acydburn
        $where_sql = array(FORUMS_TABLE => "forum_id = $forum_id", TOPICS_TABLE => "topic_id = $topic_id", USERS_TABLE => 'user_id = ' . $data['poster_id']);
1300 4479 acydburn
1301 4682 acydburn
        foreach ($sql_data as $table => $update_sql)
1302 4479 acydburn
        {
1303 4767 acydburn
                if ($update_sql)
1304 4682 acydburn
                {
1305 4682 acydburn
                        $db->sql_query("UPDATE $table SET $update_sql WHERE " . $where_sql[$table]);
1306 4682 acydburn
                }
1307 4479 acydburn
        }
1308 4479 acydburn
1309 4479 acydburn
        $db->sql_transaction('commit');
1310 4479 acydburn
1311 4479 acydburn
        return $next_post_id;
1312 4479 acydburn
}
1313 4479 acydburn
1314 4479 acydburn
1315 5114 acydburn
/**
1316 5114 acydburn
* Submit Post
1317 5114 acydburn
*/
1318 4984 acydburn
function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
1319 4477 acydburn
{
1320 4920 acydburn
        global $db, $auth, $user, $config, $phpEx, $SID, $template, $phpbb_root_path;
1321 4477 acydburn
1322 4477 acydburn
        // We do not handle erasing posts here
1323 4477 acydburn
        if ($mode == 'delete')
1324 4477 acydburn
        {
1325 4477 acydburn
                return;
1326 4477 acydburn
        }
1327 4970 psotfx
1328 4477 acydburn
        $current_time = time();
1329 4477 acydburn
1330 4477 acydburn
        if ($mode == 'post')
1331 4477 acydburn
        {
1332 4477 acydburn
                $post_mode = 'post';
1333 4938 acydburn
                $update_message = true;
1334 4477 acydburn
        }
1335 4477 acydburn
        else if ($mode != 'edit')
1336 4477 acydburn
        {
1337 4477 acydburn
                $post_mode = 'reply';
1338 4938 acydburn
                $update_message = true;
1339 4477 acydburn
        }
1340 4477 acydburn
        else if ($mode == 'edit')
1341 4477 acydburn
        {
1342 4477 acydburn
                $post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit'));
1343 4477 acydburn
        }
1344 4477 acydburn
1345 4970 psotfx
1346 4477 acydburn
        // Collect some basic informations about which tables and which rows to update/insert
1347 4477 acydburn
        $sql_data = array();
1348 4477 acydburn
        $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id'];
1349 4477 acydburn
1350 4477 acydburn
        // Collect Informations
1351 4477 acydburn
        switch ($post_mode)
1352 4477 acydburn
        {
1353 4477 acydburn
                case 'post':
1354 4477 acydburn
                case 'reply':
1355 4682 acydburn
                        $sql_data[POSTS_TABLE]['sql'] = array(
1356 4477 acydburn
                                'forum_id'                         => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
1357 4477 acydburn
                                'poster_id'                 => (int) $user->data['user_id'],
1358 4970 psotfx
                                'icon_id'                        => $data['icon_id'],
1359 4477 acydburn
                                'poster_ip'                 => $user->ip,
1360 4477 acydburn
                                'post_time'                        => $current_time,
1361 5066 acydburn
                                'post_approved'         => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1,
1362 4477 acydburn
                                'enable_bbcode'         => $data['enable_bbcode'],
1363 4477 acydburn
                                'enable_html'                 => $data['enable_html'],
1364 4477 acydburn
                                'enable_smilies'         => $data['enable_smilies'],
1365 4477 acydburn
                                'enable_magic_url'         => $data['enable_urls'],
1366 4477 acydburn
                                'enable_sig'                 => $data['enable_sig'],
1367 5117 acydburn
                                'post_username'                => (!$user->data['is_registered']) ? stripslashes($username) : '',
1368 4477 acydburn
                                'post_subject'                => $subject,
1369 4978 acydburn
                                'post_text'                 => $data['message'],
1370 4477 acydburn
                                'post_checksum'                => $data['message_md5'],
1371 4477 acydburn
                                'post_encoding'                => $user->lang['ENCODING'],
1372 5138 acydburn
                                'post_attachment'        => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0,
1373 4477 acydburn
                                'bbcode_bitfield'        => $data['bbcode_bitfield'],
1374 4978 acydburn
                                'bbcode_uid'                => $data['bbcode_uid'],
1375 4477 acydburn
                                'post_edit_locked'        => $data['post_edit_locked']
1376 4477 acydburn
                        );
1377 4477 acydburn
                        break;
1378 4477 acydburn
1379 4477 acydburn
                case 'edit_first_post':
1380 4477 acydburn
                case 'edit':
1381 5068 acydburn
1382 4767 acydburn
                        if (!$auth->acl_gets('m_', 'a_') || $data['post_edit_reason'])
1383 4486 acydburn
                        {
1384 4682 acydburn
                                $sql_data[POSTS_TABLE]['sql'] = array(
1385 4486 acydburn
                                        'post_edit_time'        => $current_time
1386 4486 acydburn
                                );
1387 4970 psotfx
1388 4682 acydburn
                                $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
1389 4486 acydburn
                        }
1390 4477 acydburn
1391 4890 acydburn
                case 'edit_last_post':
1392 5068 acydburn
                case 'edit_topic':
1393 5068 acydburn
1394 5068 acydburn
                        if (($post_mode == 'edit_last_post' || $post_mode == 'edit_topic') && $data['post_edit_reason'])
1395 4890 acydburn
                        {
1396 4890 acydburn
                                $sql_data[POSTS_TABLE]['sql'] = array(
1397 4890 acydburn
                                        'post_edit_time'        => $current_time
1398 4890 acydburn
                                );
1399 4970 psotfx
1400 4890 acydburn
                                $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
1401 4890 acydburn
                        }
1402 4890 acydburn
1403 4890 acydburn
                        if (!isset($sql_data[POSTS_TABLE]['sql']))
1404 4890 acydburn
                        {
1405 4890 acydburn
                                $sql_data[POSTS_TABLE]['sql'] = array();
1406 4890 acydburn
                        }
1407 4890 acydburn
1408 4682 acydburn
                        $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(
1409 4477 acydburn
                                'forum_id'                         => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
1410 4477 acydburn
                                'poster_id'                 => $data['poster_id'],
1411 4477 acydburn
                                'icon_id'                        => $data['icon_id'],
1412 5066 acydburn
                                'post_approved'         => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1,
1413 4477 acydburn
                                'enable_bbcode'         => $data['enable_bbcode'],
1414 4477 acydburn
                                'enable_html'                 => $data['enable_html'],
1415 4477 acydburn
                                'enable_smilies'         => $data['enable_smilies'],
1416 4477 acydburn
                                'enable_magic_url'         => $data['enable_urls'],
1417 4477 acydburn
                                'enable_sig'                 => $data['enable_sig'],
1418 4970 psotfx
                                'post_username'                => ($username && $data['poster_id'] == ANONYMOUS) ? stripslashes($username) : '',
1419 4477 acydburn
                                'post_subject'                => $subject,
1420 4767 acydburn
                                'post_edit_reason'        => $data['post_edit_reason'],
1421 4855 acydburn
                                'post_edit_user'        => (int) $data['post_edit_user'],
1422 4477 acydburn
                                'post_checksum'                => $data['message_md5'],
1423 4477 acydburn
                                'post_encoding'                => $user->lang['ENCODING'],
1424 5138 acydburn
                                'post_attachment'        => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0,
1425 4477 acydburn
                                'bbcode_bitfield'        => $data['bbcode_bitfield'],
1426 4978 acydburn
                                'bbcode_uid'                => $data['bbcode_uid'],
1427 4482 acydburn
                                'post_edit_locked'        => $data['post_edit_locked'])
1428 4482 acydburn
                        );
1429 4938 acydburn
1430 4938 acydburn
                        if ($update_message)
1431 4938 acydburn
                        {
1432 4978 acydburn
                                $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message'];
1433 4938 acydburn
                        }
1434 4938 acydburn
1435 4938 acydburn
                        break;
1436 4477 acydburn
        }
1437 4970 psotfx
1438 4477 acydburn
        // And the topic ladies and gentlemen
1439 4477 acydburn
        switch ($post_mode)
1440 4477 acydburn
        {
1441 4477 acydburn
                case 'post':
1442 4682 acydburn
                        $sql_data[TOPICS_TABLE]['sql'] = array(
1443 4477 acydburn
                                'topic_poster'                => (int) $user->data['user_id'],
1444 4477 acydburn
                                'topic_time'                => $current_time,
1445 4477 acydburn
                                'forum_id'                         => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
1446 4477 acydburn
                                'icon_id'                        => $data['icon_id'],
1447 5066 acydburn
                                'topic_approved'        => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1,
1448 4477 acydburn
                                'topic_title'                 => $subject,
1449 5117 acydburn
                                'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? stripslashes($username) : $user->data['username'],
1450 4477 acydburn
                                'topic_type'                => $topic_type,
1451 4545 acydburn
                                'topic_time_limit'        => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
1452 5138 acydburn
                                'topic_attachment'        => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0
1453 4477 acydburn
                        );
1454 4477 acydburn
1455 4890 acydburn
                        if (isset($poll['poll_options']) && !empty($poll['poll_options']))
1456 4477 acydburn
                        {
1457 4682 acydburn
                                $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array(
1458 4477 acydburn
                                        'poll_title'                => $poll['poll_title'],
1459 4970 psotfx
                                        'poll_start'                => ($poll['poll_start']) ? $poll['poll_start'] : $current_time,
1460 4970 psotfx
                                        'poll_max_options'        => $poll['poll_max_options'],
1461 4981 acydburn
                                        'poll_length'                => ($poll['poll_length'] * 86400),
1462 4981 acydburn
                                        'poll_vote_change'        => $poll['poll_vote_change'])
1463 4477 acydburn
                                );
1464 4477 acydburn
                        }
1465 4970 psotfx
1466 4682 acydburn
                        $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : '');
1467 5063 acydburn
1468 5082 acydburn
                        if ($topic_type != POST_GLOBAL)
1469 4890 acydburn
                        {
1470 5066 acydburn
                                if (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve'))
1471 5063 acydburn
                                {
1472 5063 acydburn
                                        $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
1473 5063 acydburn
                                }
1474 5066 acydburn
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? ', forum_topics = forum_topics + 1' : '');
1475 4890 acydburn
                        }
1476 4477 acydburn
                        break;
1477 4970 psotfx
1478 4477 acydburn
                case 'reply':
1479 5066 acydburn
                        $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? ', topic_replies = topic_replies + 1' : '');
1480 4682 acydburn
                        $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : '');
1481 5063 acydburn
1482 5066 acydburn
                        if ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) && $topic_type != POST_GLOBAL)
1483 4890 acydburn
                        {
1484 4890 acydburn
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
1485 4890 acydburn
                        }
1486 4477 acydburn
                        break;
1487 4477 acydburn
1488 4477 acydburn
                case 'edit_topic':
1489 4477 acydburn
                case 'edit_first_post':
1490 4477 acydburn
1491 4682 acydburn
                        $sql_data[TOPICS_TABLE]['sql'] = array(
1492 4477 acydburn
                                'forum_id'                                         => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
1493 4477 acydburn
                                'icon_id'                                        => $data['icon_id'],
1494 5066 acydburn
                                'topic_approved'                        => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1,
1495 4477 acydburn
                                'topic_title'                                 => $subject,
1496 4535 acydburn
                                'topic_first_poster_name'        => stripslashes($username),
1497 4477 acydburn
                                'topic_type'                                => $topic_type,
1498 4545 acydburn
                                'topic_time_limit'                        => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
1499 4767 acydburn
                                'poll_title'                                => ($poll['poll_options']) ? $poll['poll_title'] : '',
1500 4970 psotfx
                                'poll_start'                                => ($poll['poll_options']) ? (($poll['poll_start']) ? $poll['poll_start'] : $current_time) : 0,
1501 4970 psotfx
                                'poll_max_options'                        => ($poll['poll_options']) ? $poll['poll_max_options'] : 1,
1502 4981 acydburn
                                'poll_length'                                => ($poll['poll_options']) ? ($poll['poll_length'] * 86400) : 0,
1503 4981 acydburn
                                'poll_vote_change'                        => $poll['poll_vote_change'],
1504 4545 acydburn
1505 5138 acydburn
                                'topic_attachment'                        => ($post_mode == 'edit_topic') ? ((isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0) : $data['topic_attachment']
1506 4477 acydburn
                        );
1507 4477 acydburn
                        break;
1508 4477 acydburn
        }
1509 4970 psotfx
1510 4634 acydburn
        $db->sql_transaction();
1511 4477 acydburn
1512 4477 acydburn
        // Submit new topic
1513 4477 acydburn
        if ($post_mode == 'post')
1514 4477 acydburn
        {
1515 4970 psotfx
                $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' .
1516 4682 acydburn
                        $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']);
1517 4477 acydburn
                $db->sql_query($sql);
1518 4477 acydburn
1519 4477 acydburn
                $data['topic_id'] = $db->sql_nextid();
1520 4477 acydburn
1521 4682 acydburn
                $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(
1522 4482 acydburn
                        'topic_id' => $data['topic_id'])
1523 4477 acydburn
                );
1524 4682 acydburn
                unset($sql_data[TOPICS_TABLE]['sql']);
1525 4477 acydburn
        }
1526 4477 acydburn
1527 4477 acydburn
        // Submit new post
1528 4477 acydburn
        if ($post_mode == 'post' || $post_mode == 'reply')
1529 4477 acydburn
        {
1530 4477 acydburn
                if ($post_mode == 'reply')
1531 4477 acydburn
                {
1532 4682 acydburn
                        $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(
1533 4482 acydburn
                                'topic_id' => $data['topic_id'])
1534 4477 acydburn
                        );
1535 4477 acydburn
                }
1536 4477 acydburn
1537 4477 acydburn
                $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' .
1538 4682 acydburn
                        $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']);
1539 4477 acydburn
                $db->sql_query($sql);
1540 4477 acydburn
                $data['post_id'] = $db->sql_nextid();
1541 4477 acydburn
1542 4477 acydburn
                if ($post_mode == 'post')
1543 4477 acydburn
                {
1544 4682 acydburn
                        $sql_data[TOPICS_TABLE]['sql'] = array(
1545 5074 acydburn
                                'topic_first_post_id'        => $data['post_id'],
1546 5074 acydburn
                                'topic_last_post_id'        => $data['post_id'],
1547 5074 acydburn
                                'topic_last_post_time'        => $current_time,
1548 5074 acydburn
                                'topic_last_poster_id'        => (int) $user->data['user_id'],
1549 5117 acydburn
                                'topic_last_poster_name'=> (!$user->data['is_registered'] && $username) ? stripslashes($username) : $user->data['username']
1550 4477 acydburn
                        );
1551 4477 acydburn
                }
1552 4477 acydburn
1553 4682 acydburn
                unset($sql_data[POSTS_TABLE]['sql']);
1554 4477 acydburn
        }
1555 4477 acydburn
1556 4767 acydburn
        $make_global = false;
1557 4504 acydburn
1558 4504 acydburn
        // Are we globalising or unglobalising?
1559 4504 acydburn
        if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic')
1560 4504 acydburn
        {
1561 4504 acydburn
                $sql = 'SELECT topic_type, topic_replies_real, topic_approved
1562 4504 acydburn
                        FROM ' . TOPICS_TABLE . '
1563 4504 acydburn
                        WHERE topic_id = ' . $data['topic_id'];
1564 4504 acydburn
                $result = $db->sql_query($sql);
1565 4504 acydburn
                $row = $db->sql_fetchrow($result);
1566 5074 acydburn
                $db->sql_freeresult($result);
1567 4504 acydburn
1568 4504 acydburn
                // globalise
1569 5074 acydburn
                if ($row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL)
1570 4504 acydburn
                {
1571 4504 acydburn
                        // Decrement topic/post count
1572 4767 acydburn
                        $make_global = true;
1573 4682 acydburn
                        $sql_data[FORUMS_TABLE]['stat'] = array();
1574 4504 acydburn
1575 4682 acydburn
                        $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($row['topic_replies_real'] + 1);
1576 4682 acydburn
                        $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . (($row['topic_approved']) ? ', forum_topics = forum_topics - 1' : '');
1577 4970 psotfx
1578 4700 acydburn
                        // Update forum_ids for all posts
1579 4970 psotfx
                        $sql = 'UPDATE ' . POSTS_TABLE . '
1580 4970 psotfx
                                SET forum_id = 0
1581 4700 acydburn
                                WHERE topic_id = ' . $data['topic_id'];
1582 4700 acydburn
                        $db->sql_query($sql);
1583 4504 acydburn
                }
1584 4504 acydburn
                // unglobalise
1585 5074 acydburn
                else if ($row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL)
1586 4504 acydburn
                {
1587 4504 acydburn
                        // Increment topic/post count
1588 4767 acydburn
                        $make_global = true;
1589 4682 acydburn
                        $sql_data[FORUMS_TABLE]['stat'] = array();
1590 4504 acydburn
1591 4682 acydburn
                        $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($row['topic_replies_real'] + 1);
1592 4682 acydburn
                        $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($row['topic_approved']) ? ', forum_topics = forum_topics + 1' : '');
1593 4700 acydburn
1594 4700 acydburn
                        // Update forum_ids for all posts
1595 4970 psotfx
                        $sql = 'UPDATE ' . POSTS_TABLE . '
1596 4970 psotfx
                                SET forum_id = ' . $data['forum_id'] . '
1597 4700 acydburn
                                WHERE topic_id = ' . $data['topic_id'];
1598 4700 acydburn
                        $db->sql_query($sql);
1599 4504 acydburn
                }
1600 4504 acydburn
        }
1601 4504 acydburn
1602 4477 acydburn
        // Update the topics table
1603 4682 acydburn
        if (isset($sql_data[TOPICS_TABLE]['sql']))
1604 4477 acydburn
        {
1605 4970 psotfx
                $db->sql_query('UPDATE ' . TOPICS_TABLE . '
1606 4682 acydburn
                        SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . '
1607 4614 acydburn
                        WHERE topic_id = ' . $data['topic_id']);
1608 4477 acydburn
        }
1609 4477 acydburn
1610 4477 acydburn
        // Update the posts table
1611 4682 acydburn
        if (isset($sql_data[POSTS_TABLE]['sql']))
1612 4477 acydburn
        {
1613 4614 acydburn
                $db->sql_query('UPDATE ' . POSTS_TABLE . '
1614 4682 acydburn
                        SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . '
1615 4614 acydburn
                        WHERE post_id = ' . $data['post_id']);
1616 4477 acydburn
        }
1617 4477 acydburn
1618 4819 acydburn
        // Update Poll Tables
1619 4890 acydburn
        if (isset($poll['poll_options']) && !empty($poll['poll_options']))
1620 4477 acydburn
        {
1621 4477 acydburn
                $cur_poll_options = array();
1622 4970 psotfx
1623 4477 acydburn
                if ($poll['poll_start'] && $mode == 'edit')
1624 4477 acydburn
                {
1625 4970 psotfx
                        $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . '
1626 4477 acydburn
                                WHERE topic_id = ' . $data['topic_id'] . '
1627 4477 acydburn
                                ORDER BY poll_option_id';
1628 4477 acydburn
                        $result = $db->sql_query($sql);
1629 4477 acydburn
1630 4477 acydburn
                        while ($cur_poll_options[] = $db->sql_fetchrow($result));
1631 4477 acydburn
                        $db->sql_freeresult($result);
1632 4477 acydburn
                }
1633 4477 acydburn
1634 5249 acydburn
                $sql_insert_ary = array();
1635 4984 acydburn
                for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++)
1636 4477 acydburn
                {
1637 4477 acydburn
                        if (trim($poll['poll_options'][$i]))
1638 4477 acydburn
                        {
1639 4767 acydburn
                                if (!$cur_poll_options[$i])
1640 4477 acydburn
                                {
1641 5247 acydburn
                                        $sql_insert_ary[] = array(
1642 5247 acydburn
                                                'poll_option_id'        => (int) $i,
1643 5247 acydburn
                                                'topic_id'                        => (int) $data['topic_id'],
1644 5247 acydburn
                                                'poll_option_text'        => (string) $poll['poll_options'][$i]
1645 5247 acydburn
                                        );
1646 4477 acydburn
                                }
1647 4477 acydburn
                                else if ($poll['poll_options'][$i] != $cur_poll_options[$i])
1648 4477 acydburn
                                {
1649 4970 psotfx
                                        $sql = "UPDATE " . POLL_OPTIONS_TABLE . "
1650 4477 acydburn
                                                SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "'
1651 4477 acydburn
                                                WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . "
1652 4477 acydburn
                                                        AND topic_id = " . $data['topic_id'];
1653 4477 acydburn
                                        $db->sql_query($sql);
1654 4477 acydburn
                                }
1655 4477 acydburn
                        }
1656 4477 acydburn
                }
1657 4970 psotfx
1658 5247 acydburn
                if (sizeof($sql_insert_ary))
1659 5247 acydburn
                {
1660 5247 acydburn
                        switch (SQL_LAYER)
1661 5247 acydburn
                        {
1662 5247 acydburn
                                case 'mysql':
1663 5247 acydburn
                                case 'mysql4':
1664 5247 acydburn
                                case 'mysqli':
1665 5247 acydburn
                                        $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_insert_ary);
1666 5247 acydburn
                                break;
1667 5247 acydburn
1668 5247 acydburn
                                default:
1669 5247 acydburn
                                        foreach ($sql_insert_ary as $ary)
1670 5247 acydburn
                                        {
1671 5247 acydburn
                                                $db->sql_query('INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_insert_ary));
1672 5247 acydburn
                                        }
1673 5247 acydburn
                                break;
1674 5247 acydburn
                        }
1675 5247 acydburn
                }
1676 5247 acydburn
1677 4477 acydburn
                if (sizeof($poll['poll_options']) < sizeof($cur_poll_options))
1678 4477 acydburn
                {
1679 4477 acydburn
                        $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
1680 4981 acydburn
                                WHERE poll_option_id >= ' . sizeof($poll['poll_options']) . '
1681 4477 acydburn
                                        AND topic_id = ' . $data['topic_id'];
1682 4477 acydburn
                        $db->sql_query($sql);
1683 4477 acydburn
                }
1684 4477 acydburn
        }
1685 4477 acydburn
1686 4477 acydburn
        // Submit Attachments
1687 4978 acydburn
        if (sizeof($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit')))
1688 4477 acydburn
        {
1689 4668 acydburn
                $space_taken = $files_added = 0;
1690 4819 acydburn
1691 4978 acydburn
                foreach ($data['attachment_data'] as $pos => $attach_row)
1692 4477 acydburn
                {
1693 4539 acydburn
                        if ($attach_row['attach_id'])
1694 4477 acydburn
                        {
1695 4477 acydburn
                                // update entry in db if attachment already stored in db and filespace
1696 4970 psotfx
                                $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
1697 4970 psotfx
                                        SET comment = '" . $db->sql_escape($attach_row['comment']) . "'
1698 4477 acydburn
                                        WHERE attach_id = " . (int) $attach_row['attach_id'];
1699 4477 acydburn
                                $db->sql_query($sql);
1700 4477 acydburn
                        }
1701 4477 acydburn
                        else
1702 4477 acydburn
                        {
1703 4970 psotfx
                                // insert attachment into db
1704 5108 acydburn
                                if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($attach_row['physical_filename'])))
1705 5108 acydburn
                                {
1706 5108 acydburn
                                        continue;
1707 5108 acydburn
                                }
1708 5108 acydburn
1709 4477 acydburn
                                $attach_sql = array(
1710 4883 acydburn
                                        'post_msg_id'                => $data['post_id'],
1711 4638 acydburn
                                        'topic_id'                        => $data['topic_id'],
1712 4883 acydburn
                                        'in_message'                => 0,
1713 4638 acydburn
                                        'poster_id'                        => $poster_id,
1714 5032 acydburn
                                        'physical_filename'        => basename($attach_row['physical_filename']),
1715 5032 acydburn
                                        'real_filename'                => basename($attach_row['real_filename']),
1716 4477 acydburn
                                        'comment'                        => $attach_row['comment'],
1717 4477 acydburn
                                        'extension'                        => $attach_row['extension'],
1718 4477 acydburn
                                        'mimetype'                        => $attach_row['mimetype'],
1719 4477 acydburn
                                        'filesize'                        => $attach_row['filesize'],
1720 4477 acydburn
                                        'filetime'                        => $attach_row['filetime'],
1721 4477 acydburn
                                        'thumbnail'                        => $attach_row['thumbnail']
1722 4477 acydburn
                                );
1723 4477 acydburn
1724 4970 psotfx
                                $sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' .
1725 4477 acydburn
                                        $db->sql_build_array('INSERT', $attach_sql);
1726 4477 acydburn
                                $db->sql_query($sql);
1727 4668 acydburn
1728 4668 acydburn
                                $space_taken += $attach_row['filesize'];
1729 4668 acydburn
                                $files_added++;
1730 4477 acydburn
                        }
1731 4477 acydburn
                }
1732 4970 psotfx
1733 4978 acydburn
                if (sizeof($data['attachment_data']))
1734 4477 acydburn
                {
1735 4477 acydburn
                        $sql = 'UPDATE ' . POSTS_TABLE . '
1736 4477 acydburn
                                SET post_attachment = 1
1737 4477 acydburn
                                WHERE post_id = ' . $data['post_id'];
1738 4477 acydburn
                        $db->sql_query($sql);
1739 4477 acydburn
1740 4477 acydburn
                        $sql = 'UPDATE ' . TOPICS_TABLE . '
1741 4477 acydburn
                                SET topic_attachment = 1
1742 4477 acydburn
                                WHERE topic_id = ' . $data['topic_id'];
1743 4477 acydburn
                        $db->sql_query($sql);
1744 4477 acydburn
                }
1745 4510 acydburn
1746 4767 acydburn
                set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
1747 4767 acydburn
                set_config('num_files', $config['num_files'] + $files_added, true);
1748 4477 acydburn
        }
1749 4477 acydburn
1750 4634 acydburn
        $db->sql_transaction('commit');
1751 4477 acydburn
1752 4477 acydburn
        if ($post_mode == 'post' || $post_mode == 'reply' || $post_mode == 'edit_last_post')
1753 4477 acydburn
        {
1754 4477 acydburn
                if ($topic_type != POST_GLOBAL)
1755 4477 acydburn
                {
1756 5088 acydburn
                        $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id']));
1757 4477 acydburn
                }
1758 4682 acydburn
1759 4682 acydburn
                $update = update_last_post_information('topic', $data['topic_id']);
1760 4682 acydburn
                if (sizeof($update))
1761 4682 acydburn
                {
1762 4682 acydburn
                        $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update);
1763 4682 acydburn
                }
1764 4477 acydburn
        }
1765 4477 acydburn
1766 4504 acydburn
        if ($make_global)
1767 4504 acydburn
        {
1768 4682 acydburn
                $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id']));
1769 4504 acydburn
        }
1770 4504 acydburn
1771 4477 acydburn
        if ($post_mode == 'edit_topic')
1772 4477 acydburn
        {
1773 4682 acydburn
                $update = update_last_post_information('topic', $data['topic_id']);
1774 4682 acydburn
                if (sizeof($update))
1775 4682 acydburn
                {
1776 4682 acydburn
                        $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update);
1777 4682 acydburn
                }
1778 4477 acydburn
        }
1779 4477 acydburn
1780 4668 acydburn
        // Update total post count, do not consider moderated posts/topics
1781 5066 acydburn
        if (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve'))
1782 4668 acydburn
        {
1783 4477 acydburn
                if ($post_mode == 'post')
1784 4477 acydburn
                {
1785 4767 acydburn
                        set_config('num_topics', $config['num_topics'] + 1, true);
1786 4767 acydburn
                        set_config('num_posts', $config['num_posts'] + 1, true);
1787 4477 acydburn
                }
1788 4477 acydburn
1789 4477 acydburn
                if ($post_mode == 'reply')
1790 4477 acydburn
                {
1791 4767 acydburn
                        set_config('num_posts', $config['num_posts'] + 1, true);
1792 4477 acydburn
                }
1793 4668 acydburn
        }
1794 4477 acydburn
1795 4477 acydburn
        // Update forum stats
1796 4477 acydburn
        $db->sql_transaction();
1797 4477 acydburn
1798 4682 acydburn
        $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $user->data['user_id']);
1799 4477 acydburn
1800 4682 acydburn
        foreach ($sql_data as $table => $update_ary)
1801 4477 acydburn
        {
1802 4890 acydburn
                if (isset($update_ary['stat']) && implode('', $update_ary['stat']))
1803 4682 acydburn
                {
1804 4682 acydburn
                        $db->sql_query("UPDATE $table SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]);
1805 4682 acydburn
                }
1806 4477 acydburn
        }
1807 4477 acydburn
1808 4699 acydburn
        // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
1809 4699 acydburn
        if ($make_global)
1810 4696 ludovic_arnaud
        {
1811 4696 ludovic_arnaud
                $db->sql_query('DELETE FROM ' . TOPICS_TABLE . '
1812 4696 ludovic_arnaud
                        WHERE topic_moved_id = ' . $data['topic_id']);
1813 4699 acydburn
        }
1814 4696 ludovic_arnaud
1815 4477 acydburn
        // Fulltext parse
1816 4978 acydburn
        if ($update_message && $data['enable_indexing'])
1817 4477 acydburn
        {
1818 4477 acydburn
                $search = new fulltext_search();
1819 4978 acydburn
                $result = $search->add($mode, $data['post_id'], $data['message'], $subject);
1820 4477 acydburn
        }
1821 4477 acydburn
1822 4477 acydburn
        $db->sql_transaction('commit');
1823 4970 psotfx
1824 4668 acydburn
        // Delete draft if post was loaded...
1825 4668 acydburn
        $draft_id = request_var('draft_loaded', 0);
1826 4668 acydburn
        if ($draft_id)
1827 4668 acydburn
        {
1828 4668 acydburn
                $db->sql_query('DELETE FROM ' . DRAFTS_TABLE . " WHERE draft_id = $draft_id AND user_id = " . $user->data['user_id']);
1829 4668 acydburn
        }
1830 4668 acydburn
1831 4477 acydburn
        // Topic Notification
1832 4627 acydburn
        if (!$data['notify_set'] && $data['notify'])
1833 4477 acydburn
        {
1834 4477 acydburn
                $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id)
1835 4477 acydburn
                        VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')';
1836 4477 acydburn
                $db->sql_query($sql);
1837 4477 acydburn
        }
1838 4627 acydburn
        else if ($data['notify_set'] && !$data['notify'])
1839 4477 acydburn
        {
1840 4477 acydburn
                $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
1841 4477 acydburn
                        WHERE user_id = ' . $user->data['user_id'] . '
1842 4477 acydburn
                                AND topic_id = ' . $data['topic_id'];
1843 4477 acydburn
                $db->sql_query($sql);
1844 4477 acydburn
        }
1845 4970 psotfx
1846 4477 acydburn
        // Mark this topic as read and posted to.
1847 4477 acydburn
        $mark_mode = ($mode == 'post' || $mode == 'reply' || $mode == 'quote') ? 'post' : 'topic';
1848 4477 acydburn
        markread($mark_mode, $data['forum_id'], $data['topic_id'], $data['post_time']);
1849 4477 acydburn
1850 4477 acydburn
        // Send Notifications
1851 5066 acydburn
        if ($mode != 'edit' && $mode != 'delete' && (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')))
1852 4477 acydburn
        {
1853 4535 acydburn
                user_notification($mode, stripslashes($subject), stripslashes($data['topic_title']), stripslashes($data['forum_name']), $data['forum_id'], $data['topic_id'], $data['post_id']);
1854 4477 acydburn
        }
1855 4477 acydburn
1856 4956 acydburn
        if ($mode == 'post')
1857 4956 acydburn
        {
1858 5066 acydburn
                $url = (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=" . $data['forum_id'] . '&amp;t=' . $data['topic_id'] : "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=" . $data['forum_id'];
1859 4956 acydburn
        }
1860 4956 acydburn
        else
1861 4956 acydburn
        {
1862 5066 acydburn
                $url = (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ?  "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}&amp;p={$data['post_id']}#{$data['post_id']}" : "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}";
1863 4956 acydburn
        }
1864 4477 acydburn
1865 4920 acydburn
        meta_refresh(3, $url);
1866 4920 acydburn
1867 5066 acydburn
        $message = ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? (($mode == 'edit') ? 'POST_EDITED_MOD' : 'POST_STORED_MOD') : (($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED');
1868 5066 acydburn
        $message = $user->lang[$message] . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $url . '">', '</a>') : '') . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID .'&amp;f=' . $data['forum_id'] . '">', '</a>');
1869 4477 acydburn
        trigger_error($message);
1870 4477 acydburn
}
1871 4477 acydburn
1872 4883 acydburn
function upload_popup($forum_style)
1873 4668 acydburn
{
1874 4883 acydburn
        global $template, $user;
1875 4539 acydburn
1876 4883 acydburn
        $user->setup('posting', $forum_style);
1877 4668 acydburn
1878 4883 acydburn
        page_header('PROGRESS_BAR');
1879 4668 acydburn
1880 4883 acydburn
        $template->set_filenames(array(
1881 4883 acydburn
                'popup'        => 'posting_progress_bar.html')
1882 4883 acydburn
        );
1883 4668 acydburn
1884 4912 acydburn
        $template->assign_vars(array(
1885 4912 acydburn
                'PROGRESS_BAR'        => $user->img('attach_progress_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1886 4912 acydburn
        );
1887 4912 acydburn
1888 4883 acydburn
        $template->display('popup');
1889 4668 acydburn
}
1890 4668 acydburn
1891 3277 psotfx
?>