~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/php/phpBB3/includes/ucp/ucp_main.php

  • Committer: William Grant
  • Date: 2009-02-23 23:47:02 UTC
  • mfrom: (1099.1.211 new-dispatch)
  • Revision ID: grantw@unimelb.edu.au-20090223234702-db4b1llly46ignwo
Merge from lp:~ivle-dev/ivle/new-dispatch.

Pretty much everything changes. Reread the setup docs. Backup your databases.
Every file is now in a different installed location, the configuration system
is rewritten, the dispatch system is rewritten, URLs are different, the
database is different, worksheets and exercises are no longer on the
filesystem, we use a templating engine, jail service protocols are rewritten,
we don't repeat ourselves, we have authorization rewritten, phpBB is gone,
and probably lots of other things that I cannot remember.

This is certainly the biggest commit I have ever made, and hopefully
the largest I ever will.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
*
4
 
* @package ucp
5
 
* @version $Id: ucp_main.php,v 1.91 2007/10/05 14:36:33 acydburn Exp $
6
 
* @copyright (c) 2005 phpBB Group
7
 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8
 
*
9
 
*/
10
 
 
11
 
/**
12
 
* @ignore
13
 
*/
14
 
if (!defined('IN_PHPBB'))
15
 
{
16
 
        exit;
17
 
}
18
 
 
19
 
/**
20
 
* ucp_main
21
 
* UCP Front Panel
22
 
* @package ucp
23
 
*/
24
 
class ucp_main
25
 
{
26
 
        var $p_master;
27
 
        var $u_action;
28
 
        
29
 
        function ucp_main(&$p_master)
30
 
        {
31
 
                $this->p_master = &$p_master;
32
 
        }
33
 
 
34
 
        function main($id, $mode)
35
 
        {
36
 
                global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
37
 
 
38
 
                switch ($mode)
39
 
                {
40
 
                        case 'front':
41
 
 
42
 
                                $user->add_lang('memberlist');
43
 
 
44
 
                                $sql_from = TOPICS_TABLE . ' t ';
45
 
                                $sql_select = '';
46
 
 
47
 
                                if ($config['load_db_track'])
48
 
                                {
49
 
                                        $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
50
 
                                                AND tp.user_id = ' . $user->data['user_id'] . ')';
51
 
                                        $sql_select .= ', tp.topic_posted';
52
 
                                }
53
 
 
54
 
                                if ($config['load_db_lastread'])
55
 
                                {
56
 
                                        $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
57
 
                                                AND tt.user_id = ' . $user->data['user_id'] . ')';
58
 
                                        $sql_select .= ', tt.mark_time';
59
 
                                }
60
 
 
61
 
                                $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
62
 
                                $folder = 'global_read';
63
 
                                $folder_new = 'global_unread';
64
 
 
65
 
                                // Get cleaned up list... return only those forums not having the f_read permission
66
 
                                $forum_ary = $auth->acl_getf('!f_read', true);
67
 
                                $forum_ary = array_unique(array_keys($forum_ary));
68
 
 
69
 
                                // Determine first forum the user is able to read into - for global announcement link
70
 
                                $sql = 'SELECT forum_id
71
 
                                        FROM ' . FORUMS_TABLE . '
72
 
                                        WHERE forum_type = ' . FORUM_POST;
73
 
        
74
 
                                if (sizeof($forum_ary))
75
 
                                {
76
 
                                        $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
77
 
                                }
78
 
                                $result = $db->sql_query_limit($sql, 1);
79
 
                                $g_forum_id = (int) $db->sql_fetchfield('forum_id');
80
 
                                $db->sql_freeresult($result);
81
 
 
82
 
                                $sql = "SELECT t.* $sql_select
83
 
                                        FROM $sql_from
84
 
                                        WHERE t.forum_id = 0
85
 
                                                AND t.topic_type = " . POST_GLOBAL . '
86
 
                                        ORDER BY t.topic_last_post_time DESC';
87
 
 
88
 
                                $topic_list = $rowset = array();
89
 
                                // If the user can't see any forums, he can't read any posts because fid of 0 is invalid
90
 
                                if ($g_forum_id)
91
 
                                {
92
 
                                        $result = $db->sql_query($sql);
93
 
 
94
 
                                        while ($row = $db->sql_fetchrow($result))
95
 
                                        {
96
 
                                                $topic_list[] = $row['topic_id'];
97
 
                                                $rowset[$row['topic_id']] = $row;
98
 
                                        }
99
 
                                        $db->sql_freeresult($result);
100
 
                                }
101
 
 
102
 
                                $topic_tracking_info = array();
103
 
                                if ($config['load_db_lastread'])
104
 
                                {
105
 
                                        $topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, false, $topic_list);
106
 
                                }
107
 
                                else
108
 
                                {
109
 
                                        $topic_tracking_info = get_complete_topic_tracking(0, $topic_list, $topic_list);
110
 
                                }
111
 
 
112
 
                                foreach ($topic_list as $topic_id)
113
 
                                {
114
 
                                        $row = &$rowset[$topic_id];
115
 
 
116
 
                                        $forum_id = $row['forum_id'];
117
 
                                        $topic_id = $row['topic_id'];
118
 
 
119
 
                                        $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
120
 
 
121
 
                                        $folder_img = ($unread_topic) ? $folder_new : $folder;
122
 
                                        $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
123
 
 
124
 
                                        if ($row['topic_status'] == ITEM_LOCKED)
125
 
                                        {
126
 
                                                $folder_img .= '_locked';
127
 
                                        }
128
 
 
129
 
                                        // Posted image?
130
 
                                        if (!empty($row['topic_posted']) && $row['topic_posted'])
131
 
                                        {
132
 
                                                $folder_img .= '_mine';
133
 
                                        }
134
 
 
135
 
                                        $template->assign_block_vars('topicrow', array(
136
 
                                                'FORUM_ID'                                      => $forum_id,
137
 
                                                'TOPIC_ID'                                      => $topic_id,
138
 
                                                'TOPIC_AUTHOR'                          => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
139
 
                                                'TOPIC_AUTHOR_COLOUR'           => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
140
 
                                                'TOPIC_AUTHOR_FULL'                     => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
141
 
                                                'FIRST_POST_TIME'                       => $user->format_date($row['topic_time']),
142
 
                                                'LAST_POST_SUBJECT'                     => censor_text($row['topic_last_post_subject']),
143
 
                                                'LAST_POST_TIME'                        => $user->format_date($row['topic_last_post_time']),
144
 
                                                'LAST_VIEW_TIME'                        => $user->format_date($row['topic_last_view_time']),
145
 
                                                'LAST_POST_AUTHOR'                      => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
146
 
                                                'LAST_POST_AUTHOR_COLOUR'       => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
147
 
                                                'LAST_POST_AUTHOR_FULL'         => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
148
 
                                                'TOPIC_TITLE'                           => censor_text($row['topic_title']),
149
 
                                                'TOPIC_TYPE'                            => $topic_type,
150
 
 
151
 
                                                'TOPIC_FOLDER_IMG'              => $user->img($folder_img, $folder_alt),
152
 
                                                'TOPIC_FOLDER_IMG_SRC'  => $user->img($folder_img, $folder_alt, false, '', 'src'),
153
 
                                                'ATTACH_ICON_IMG'               => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
154
 
 
155
 
                                                'S_USER_POSTED'         => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
156
 
                                                'S_UNREAD'                      => $unread_topic,
157
 
 
158
 
                                                'U_TOPIC_AUTHOR'                => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
159
 
                                                'U_LAST_POST'                   => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&amp;t=$topic_id&amp;p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
160
 
                                                'U_LAST_POST_AUTHOR'    => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
161
 
                                                'U_NEWEST_POST'                 => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
162
 
                                                'U_VIEW_TOPIC'                  => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&amp;t=$topic_id"))
163
 
                                        );
164
 
                                }
165
 
 
166
 
                                if ($config['load_user_activity'])
167
 
                                {
168
 
                                        if (!function_exists('display_user_activity'))
169
 
                                        {
170
 
                                                include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
171
 
                                        }
172
 
                                        display_user_activity($user->data);
173
 
                                }
174
 
 
175
 
                                // Do the relevant calculations
176
 
                                $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
177
 
                                $posts_per_day = $user->data['user_posts'] / $memberdays;
178
 
                                $percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
179
 
 
180
 
                                $template->assign_vars(array(
181
 
                                        'USER_COLOR'            => (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '',
182
 
                                        'JOINED'                        => $user->format_date($user->data['user_regdate']),
183
 
                                        'VISITED'                       => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
184
 
                                        'WARNINGS'                      => ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
185
 
                                        'POSTS'                         => ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
186
 
                                        'POSTS_DAY'                     => sprintf($user->lang['POST_DAY'], $posts_per_day),
187
 
                                        'POSTS_PCT'                     => sprintf($user->lang['POST_PCT'], $percentage),
188
 
 
189
 
                                        'OCCUPATION'    => (!empty($row['user_occ'])) ? $row['user_occ'] : '',
190
 
                                        'INTERESTS'             => (!empty($row['user_interests'])) ? $row['user_interests'] : '',
191
 
 
192
 
//                                      'S_GROUP_OPTIONS'       => $group_options,
193
 
 
194
 
                                        'U_SEARCH_USER'         => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&amp;sr=posts') : '',
195
 
                                ));
196
 
 
197
 
                        break;
198
 
 
199
 
                        case 'subscribed':
200
 
 
201
 
                                include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
202
 
 
203
 
                                $user->add_lang('viewforum');
204
 
 
205
 
                                add_form_key('ucp_front_subscribed');
206
 
 
207
 
                                $unwatch = (isset($_POST['unwatch'])) ? true : false;
208
 
 
209
 
                                if ($unwatch)
210
 
                                {
211
 
                                        if (check_form_key('ucp_front_subscribed'))
212
 
                                        {
213
 
                                                $forums = array_keys(request_var('f', array(0 => 0)));
214
 
                                                $topics = array_keys(request_var('t', array(0 => 0)));
215
 
                                                $msg = '';
216
 
 
217
 
                                                if (sizeof($forums) || sizeof($topics))
218
 
                                                {
219
 
                                                        $l_unwatch = '';
220
 
                                                        if (sizeof($forums))
221
 
                                                        {
222
 
                                                                $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
223
 
                                                                        WHERE ' . $db->sql_in_set('forum_id', $forums) . '
224
 
                                                                                AND user_id = ' . $user->data['user_id'];
225
 
                                                                $db->sql_query($sql);
226
 
 
227
 
                                                                $l_unwatch .= '_FORUMS';
228
 
                                                        }
229
 
 
230
 
                                                        if (sizeof($topics))
231
 
                                                        {
232
 
                                                                $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
233
 
                                                                        WHERE ' . $db->sql_in_set('topic_id', $topics) . '
234
 
                                                                                AND user_id = ' . $user->data['user_id'];
235
 
                                                                $db->sql_query($sql);
236
 
 
237
 
                                                                $l_unwatch .= '_TOPICS';
238
 
                                                        }
239
 
                                                        $msg = $user->lang['UNWATCHED' . $l_unwatch];
240
 
 
241
 
                                                }
242
 
                                        }
243
 
                                        else
244
 
                                        {
245
 
                                                $msg = $user->lang['FORM_INVALID'];
246
 
                                        }
247
 
                                        $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed") . '">', '</a>');
248
 
                                        meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed"));
249
 
                                        trigger_error($message);
250
 
                                }
251
 
 
252
 
                                $forbidden_forums = array();
253
 
 
254
 
                                if ($config['allow_forum_notify'])
255
 
                                {
256
 
                                        $forbidden_forums = $auth->acl_getf('!f_read', true);
257
 
                                        $forbidden_forums = array_unique(array_keys($forbidden_forums));
258
 
                                        
259
 
                                        $sql_array = array(
260
 
                                                'SELECT'        => 'f.*',
261
 
 
262
 
                                                'FROM'          => array(
263
 
                                                        FORUMS_WATCH_TABLE      => 'fw',
264
 
                                                        FORUMS_TABLE            => 'f'
265
 
                                                ),
266
 
 
267
 
                                                'WHERE'         => 'fw.user_id = ' . $user->data['user_id'] . '
268
 
                                                        AND f.forum_id = fw.forum_id
269
 
                                                        AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
270
 
 
271
 
                                                'ORDER_BY'      => 'left_id'
272
 
                                        );
273
 
 
274
 
                                        if ($config['load_db_lastread'])
275
 
                                        {
276
 
                                                $sql_array['LEFT_JOIN'] = array(
277
 
                                                        array(
278
 
                                                                'FROM'  => array(FORUMS_TRACK_TABLE => 'ft'),
279
 
                                                                'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
280
 
                                                        )
281
 
                                                );
282
 
 
283
 
                                                $sql_array['SELECT'] .= ', ft.mark_time ';
284
 
                                        }
285
 
                                        else
286
 
                                        {
287
 
                                                $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
288
 
                                                $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
289
 
                                        }
290
 
 
291
 
                                        $sql = $db->sql_build_query('SELECT', $sql_array);
292
 
                                        $result = $db->sql_query($sql);
293
 
 
294
 
                                        while ($row = $db->sql_fetchrow($result))
295
 
                                        {
296
 
                                                $forum_id = $row['forum_id'];
297
 
 
298
 
                                                if ($config['load_db_lastread'])
299
 
                                                {
300
 
                                                        $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
301
 
                                                }
302
 
                                                else
303
 
                                                {
304
 
                                                        $forum_check = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
305
 
                                                }
306
 
 
307
 
                                                $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
308
 
 
309
 
                                                // Which folder should we display?
310
 
                                                if ($row['forum_status'] == ITEM_LOCKED)
311
 
                                                {
312
 
                                                        $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
313
 
                                                        $folder_alt = 'FORUM_LOCKED';
314
 
                                                }
315
 
                                                else
316
 
                                                {
317
 
                                                        $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
318
 
                                                        $folder_alt = ($unread_forum) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
319
 
                                                }
320
 
 
321
 
                                                // Create last post link information, if appropriate
322
 
                                                if ($row['forum_last_post_id'])
323
 
                                                {
324
 
                                                        $last_post_time = $user->format_date($row['forum_last_post_time']);
325
 
                                                        $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
326
 
                                                }
327
 
                                                else
328
 
                                                {
329
 
                                                        $last_post_time = $last_post_url = '';
330
 
                                                }
331
 
 
332
 
                                                $template->assign_block_vars('forumrow', array(
333
 
                                                        'FORUM_ID'                              => $forum_id,
334
 
                                                        'FORUM_FOLDER_IMG'              => $user->img($folder_image, $folder_alt),
335
 
                                                        'FORUM_FOLDER_IMG_SRC'  => $user->img($folder_image, $folder_alt, false, '', 'src'),
336
 
                                                        'FORUM_IMAGE'                   => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
337
 
                                                        'FORUM_IMAGE_SRC'               => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
338
 
                                                        'FORUM_NAME'                    => $row['forum_name'],
339
 
                                                        'LAST_POST_SUBJECT'             => $row['forum_last_post_subject'],
340
 
                                                        'LAST_POST_TIME'                => $last_post_time,
341
 
 
342
 
                                                        'LAST_POST_AUTHOR'                      => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
343
 
                                                        'LAST_POST_AUTHOR_COLOUR'       => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
344
 
                                                        'LAST_POST_AUTHOR_FULL'         => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
345
 
                                                        'U_LAST_POST_AUTHOR'            => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
346
 
 
347
 
                                                        'U_LAST_POST'                   => $last_post_url,
348
 
                                                        'U_VIEWFORUM'                   => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
349
 
                                                );
350
 
                                        }
351
 
                                        $db->sql_freeresult($result);
352
 
                                }
353
 
 
354
 
                                // Subscribed Topics
355
 
                                if ($config['allow_topic_notify'])
356
 
                                {
357
 
                                        if (empty($forbidden_forums))
358
 
                                        {
359
 
                                                $forbidden_forums = $auth->acl_getf('!f_read', true);
360
 
                                                $forbidden_forums = array_unique(array_keys($forbidden_forums));
361
 
                                        }
362
 
                                        $this->assign_topiclist('subscribed', $forbidden_forums);
363
 
                                }
364
 
 
365
 
                                $template->assign_vars(array(
366
 
                                        'S_TOPIC_NOTIFY'                => $config['allow_topic_notify'],
367
 
                                        'S_FORUM_NOTIFY'                => $config['allow_forum_notify'],
368
 
                                ));
369
 
 
370
 
                        break;
371
 
 
372
 
                        case 'bookmarks':
373
 
 
374
 
                                if (!$config['allow_bookmarks'])
375
 
                                {
376
 
                                        $template->assign_vars(array(
377
 
                                                'S_NO_DISPLAY_BOOKMARKS'        => true)
378
 
                                        );
379
 
                                        break;
380
 
                                }
381
 
 
382
 
                                include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
383
 
 
384
 
                                $user->add_lang('viewforum');
385
 
 
386
 
                                if (isset($_POST['unbookmark']))
387
 
                                {
388
 
                                        $s_hidden_fields = array('unbookmark' => 1);
389
 
                                        $topics = (isset($_POST['t'])) ? array_keys(request_var('t', array(0 => 0))) : array();
390
 
                                        $url = $this->u_action;
391
 
 
392
 
                                        if (!sizeof($topics))
393
 
                                        {
394
 
                                                trigger_error('NO_BOOKMARKS_SELECTED');
395
 
                                        }
396
 
 
397
 
                                        foreach ($topics as $topic_id)
398
 
                                        {
399
 
                                                $s_hidden_fields['t'][$topic_id] = 1;
400
 
                                        }
401
 
 
402
 
                                        if (confirm_box(true))
403
 
                                        {
404
 
                                                $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
405
 
                                                        WHERE user_id = ' . $user->data['user_id'] . '
406
 
                                                                AND ' . $db->sql_in_set('topic_id', $topics);
407
 
                                                $db->sql_query($sql);
408
 
 
409
 
                                                meta_refresh(3, $url);
410
 
                                                $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
411
 
                                                trigger_error($message);
412
 
                                        }
413
 
                                        else
414
 
                                        {
415
 
                                                confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
416
 
                                        }
417
 
                                }
418
 
                                $forbidden_forums = $auth->acl_getf('!f_read', true);
419
 
                                $forbidden_forums = array_unique(array_keys($forbidden_forums));
420
 
                                
421
 
                                $this->assign_topiclist('bookmarks', $forbidden_forums);
422
 
 
423
 
                        break;
424
 
 
425
 
                        case 'drafts':
426
 
 
427
 
                                $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
428
 
                                $template->assign_var('S_SHOW_DRAFTS', true);
429
 
 
430
 
                                $user->add_lang('posting');
431
 
 
432
 
                                $edit           = (isset($_REQUEST['edit'])) ? true : false;
433
 
                                $submit         = (isset($_POST['submit'])) ? true : false;
434
 
                                $draft_id       = ($edit) ? intval($_REQUEST['edit']) : 0;
435
 
                                $delete         = (isset($_POST['delete'])) ? true : false;
436
 
 
437
 
                                $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
438
 
                                $draft_subject = $draft_message = '';
439
 
                                add_form_key('ucp_draft');
440
 
 
441
 
                                if ($delete)
442
 
                                {
443
 
                                        if (check_form_key('ucp_draft'))
444
 
                                        {
445
 
                                                $drafts = array_keys(request_var('d', array(0 => 0)));
446
 
 
447
 
                                                if (sizeof($drafts))
448
 
                                                {
449
 
                                                        $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
450
 
                                                                WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
451
 
                                                                        AND user_id = ' . $user->data['user_id'];
452
 
                                                        $db->sql_query($sql);
453
 
                                                }
454
 
                                                $msg = $user->lang['DRAFTS_DELETED'];
455
 
                                                unset($drafts);
456
 
                                        }
457
 
                                        else
458
 
                                        {
459
 
                                                $msg = $user->lang['FORM_INVALID'];
460
 
                                        }
461
 
                                        $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
462
 
                                        meta_refresh(3, $this->u_action);
463
 
                                        trigger_error($message);
464
 
                                }
465
 
 
466
 
                                if ($submit && $edit)
467
 
                                {
468
 
                                        $draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
469
 
                                        $draft_message = utf8_normalize_nfc(request_var('message', '', true));
470
 
                                        if (check_form_key('ucp_draft'))
471
 
                                        {
472
 
                                                if ($draft_message && $draft_subject)
473
 
                                                {
474
 
                                                        $draft_row = array(
475
 
                                                                'draft_subject' => $draft_subject,
476
 
                                                                'draft_message' => $draft_message
477
 
                                                        );
478
 
 
479
 
                                                        $sql = 'UPDATE ' . DRAFTS_TABLE . '
480
 
                                                                SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
481
 
                                                                WHERE draft_id = $draft_id
482
 
                                                                        AND user_id = " . $user->data['user_id'];
483
 
                                                        $db->sql_query($sql);
484
 
 
485
 
                                                        $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
486
 
 
487
 
                                                        meta_refresh(3, $this->u_action);
488
 
                                                        trigger_error($message);
489
 
                                                }
490
 
                                                else
491
 
                                                {
492
 
                                                        $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
493
 
                                                }
494
 
                                        }
495
 
                                        else
496
 
                                        {
497
 
                                                $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
498
 
                                        }
499
 
                                }
500
 
 
501
 
                                if (!$pm_drafts)
502
 
                                {
503
 
                                        $sql = 'SELECT d.*, f.forum_name
504
 
                                                FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
505
 
                                                WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
506
 
                                                        (($edit) ? "AND d.draft_id = $draft_id" : '') . '
507
 
                                                        AND f.forum_id = d.forum_id
508
 
                                                ORDER BY d.save_time DESC';
509
 
                                }
510
 
                                else
511
 
                                {
512
 
                                        $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
513
 
                                                WHERE user_id = ' . $user->data['user_id'] . ' ' .
514
 
                                                        (($edit) ? "AND draft_id = $draft_id" : '') . '
515
 
                                                        AND forum_id = 0
516
 
                                                        AND topic_id = 0
517
 
                                                ORDER BY save_time DESC';
518
 
                                }
519
 
                                $result = $db->sql_query($sql);
520
 
 
521
 
                                $draftrows = $topic_ids = array();
522
 
 
523
 
                                while ($row = $db->sql_fetchrow($result))
524
 
                                {
525
 
                                        if ($row['topic_id'])
526
 
                                        {
527
 
                                                $topic_ids[] = (int) $row['topic_id'];
528
 
                                        }
529
 
                                        $draftrows[] = $row;
530
 
                                }
531
 
                                $db->sql_freeresult($result);
532
 
 
533
 
                                if (sizeof($topic_ids))
534
 
                                {
535
 
                                        $sql = 'SELECT topic_id, forum_id, topic_title
536
 
                                                FROM ' . TOPICS_TABLE . '
537
 
                                                WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
538
 
                                        $result = $db->sql_query($sql);
539
 
 
540
 
                                        while ($row = $db->sql_fetchrow($result))
541
 
                                        {
542
 
                                                $topic_rows[$row['topic_id']] = $row;
543
 
                                        }
544
 
                                        $db->sql_freeresult($result);
545
 
                                }
546
 
                                unset($topic_ids);
547
 
 
548
 
                                $template->assign_var('S_EDIT_DRAFT', $edit);
549
 
 
550
 
                                $row_count = 0;
551
 
                                foreach ($draftrows as $draft)
552
 
                                {
553
 
                                        $link_topic = $link_forum = $link_pm = false;
554
 
                                        $insert_url = $view_url = $title = '';
555
 
 
556
 
                                        if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
557
 
                                        {
558
 
                                                $link_topic = true;
559
 
                                                $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id']);
560
 
                                                $title = $topic_rows[$draft['topic_id']]['topic_title'];
561
 
 
562
 
                                                $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id'] . '&amp;mode=reply&amp;d=' . $draft['draft_id']);
563
 
                                        }
564
 
                                        else if ($auth->acl_get('f_read', $draft['forum_id']))
565
 
                                        {
566
 
                                                $link_forum = true;
567
 
                                                $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
568
 
                                                $title = $draft['forum_name'];
569
 
 
570
 
                                                $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=post&amp;d=' . $draft['draft_id']);
571
 
                                        }
572
 
                                        else if ($pm_drafts)
573
 
                                        {
574
 
                                                $link_pm = true;
575
 
                                                $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d=" . $draft['draft_id']);
576
 
                                        }
577
 
 
578
 
                                        $template_row = array(
579
 
                                                'DATE'                  => $user->format_date($draft['save_time']),
580
 
                                                'DRAFT_MESSAGE' => ($submit) ? $draft_message : $draft['draft_message'],
581
 
                                                'DRAFT_SUBJECT' => ($submit) ? $draft_subject : $draft['draft_subject'],
582
 
                                                'TITLE'                 => $title,
583
 
 
584
 
                                                'DRAFT_ID'      => $draft['draft_id'],
585
 
                                                'FORUM_ID'      => $draft['forum_id'],
586
 
                                                'TOPIC_ID'      => $draft['topic_id'],
587
 
 
588
 
                                                'U_VIEW'                => $view_url,
589
 
                                                'U_VIEW_EDIT'   => $this->u_action . '&amp;edit=' . $draft['draft_id'],
590
 
                                                'U_INSERT'              => $insert_url,
591
 
 
592
 
                                                'S_LINK_TOPIC'          => $link_topic,
593
 
                                                'S_LINK_FORUM'          => $link_forum,
594
 
                                                'S_LINK_PM'                     => $link_pm,
595
 
                                                'S_HIDDEN_FIELDS'       => $s_hidden_fields
596
 
                                        );
597
 
                                        $row_count++;
598
 
 
599
 
                                        ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
600
 
                                }
601
 
 
602
 
                                if (!$edit)
603
 
                                {
604
 
                                        $template->assign_var('S_DRAFT_ROWS', $row_count);
605
 
                                }
606
 
 
607
 
                        break;
608
 
                }
609
 
 
610
 
 
611
 
                $template->assign_vars(array(
612
 
                        'L_TITLE'                       => $user->lang['UCP_MAIN_' . strtoupper($mode)],
613
 
 
614
 
                        'S_DISPLAY_MARK_ALL'    => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
615
 
                        'S_HIDDEN_FIELDS'               => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
616
 
                        'S_UCP_ACTION'                  => $this->u_action,
617
 
 
618
 
                        'LAST_POST_IMG'                 => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
619
 
                        'NEWEST_POST_IMG'               => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
620
 
                ));
621
 
 
622
 
                // Set desired template
623
 
                $this->tpl_name = 'ucp_main_' . $mode;
624
 
                $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
625
 
        }
626
 
 
627
 
        /**
628
 
        * Build and assign topiclist for bookmarks/subscribed topics
629
 
        */
630
 
        function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
631
 
        {
632
 
                global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx;
633
 
 
634
 
                $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
635
 
                $start = request_var('start', 0);
636
 
 
637
 
                $sql_array = array(
638
 
                        'SELECT'        => 'COUNT(t.topic_id) as topics_count',
639
 
 
640
 
                        'FROM'          => array(
641
 
                                $table                  => 'i',
642
 
                                TOPICS_TABLE    => 't'
643
 
                        ),
644
 
 
645
 
                        'WHERE'         =>      'i.topic_id = t.topic_id
646
 
                                AND i.user_id = ' . $user->data['user_id'] . '
647
 
                                AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
648
 
                );
649
 
                $sql = $db->sql_build_query('SELECT', $sql_array);
650
 
                $result = $db->sql_query($sql);
651
 
                $topics_count = (int) $db->sql_fetchfield('topics_count');
652
 
                $db->sql_freeresult($result);
653
 
 
654
 
                if ($topics_count)
655
 
                {
656
 
                        $template->assign_vars(array(
657
 
                                'PAGINATION'    => generate_pagination($this->u_action, $topics_count, $config['topics_per_page'], $start),
658
 
                                'PAGE_NUMBER'   => on_page($topics_count, $config['topics_per_page'], $start),
659
 
                                'TOTAL_TOPICS'  => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count))
660
 
                        );
661
 
                }
662
 
 
663
 
                if ($mode == 'subscribed')
664
 
                {
665
 
                        $sql_array = array(
666
 
                                'SELECT'        => 't.*, f.forum_name',
667
 
 
668
 
                                'FROM'          => array(
669
 
                                        TOPICS_WATCH_TABLE      => 'tw',
670
 
                                        TOPICS_TABLE            => 't'
671
 
                                ),
672
 
 
673
 
                                'WHERE'         => 'tw.user_id = ' . $user->data['user_id'] . '
674
 
                                        AND t.topic_id = tw.topic_id
675
 
                                        AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
676
 
                                        
677
 
 
678
 
                                'ORDER_BY'      => 't.topic_last_post_time DESC'
679
 
                        );
680
 
 
681
 
                        $sql_array['LEFT_JOIN'] = array();
682
 
                }
683
 
                else
684
 
                {
685
 
                        $sql_array = array(
686
 
                                'SELECT'        => 't.*, f.forum_name, b.topic_id as b_topic_id',
687
 
 
688
 
                                'FROM'          => array(
689
 
                                        BOOKMARKS_TABLE         => 'b',
690
 
                                ),
691
 
 
692
 
                                'WHERE'         => 'b.user_id = ' . $user->data['user_id'] . '
693
 
                                        AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
694
 
 
695
 
                                'ORDER_BY'      => 't.topic_last_post_time DESC'
696
 
                        );
697
 
 
698
 
                        $sql_array['LEFT_JOIN'] = array();
699
 
                        $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
700
 
                }
701
 
 
702
 
                $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
703
 
 
704
 
                if ($config['load_db_lastread'])
705
 
                {
706
 
                        $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
707
 
                        $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
708
 
                        $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
709
 
                }
710
 
 
711
 
                if ($config['load_db_track'])
712
 
                {
713
 
                        $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
714
 
                        $sql_array['SELECT'] .= ', tp.topic_posted';
715
 
                }
716
 
 
717
 
                $sql = $db->sql_build_query('SELECT', $sql_array);
718
 
                $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
719
 
 
720
 
                $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
721
 
                while ($row = $db->sql_fetchrow($result))
722
 
                {
723
 
                        $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
724
 
 
725
 
                        $topic_list[] = $topic_id;
726
 
                        $rowset[$topic_id] = $row;
727
 
 
728
 
                        $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
729
 
                        $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
730
 
 
731
 
                        if ($row['topic_type'] == POST_GLOBAL)
732
 
                        {
733
 
                                $global_announce_list[] = $topic_id;
734
 
                        }
735
 
                }
736
 
                $db->sql_freeresult($result);
737
 
 
738
 
                $topic_tracking_info = array();
739
 
                if ($config['load_db_lastread'])
740
 
                {
741
 
                        foreach ($topic_forum_list as $f_id => $topic_row)
742
 
                        {
743
 
                                $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), ($f_id == 0) ? $global_announce_list : false);
744
 
                        }
745
 
                }
746
 
                else
747
 
                {
748
 
                        foreach ($topic_forum_list as $f_id => $topic_row)
749
 
                        {
750
 
                                $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list);
751
 
                        }
752
 
                }
753
 
 
754
 
                foreach ($topic_list as $topic_id)
755
 
                {
756
 
                        $row = &$rowset[$topic_id];
757
 
 
758
 
                        $forum_id = $row['forum_id'];
759
 
                        $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
760
 
 
761
 
                        $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
762
 
 
763
 
                        // Replies
764
 
                        $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
765
 
 
766
 
                        if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
767
 
                        {
768
 
                                $topic_id = $row['topic_moved_id'];
769
 
                        }
770
 
 
771
 
                        // Get folder img, topic status/type related information
772
 
                        $folder_img = $folder_alt = $topic_type = '';
773
 
                        topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
774
 
 
775
 
                        $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
776
 
 
777
 
                        // Send vars to template
778
 
                        $template->assign_block_vars('topicrow', array(
779
 
                                'FORUM_ID'                                      => $forum_id,
780
 
                                'TOPIC_ID'                                      => $topic_id,
781
 
                                'FIRST_POST_TIME'                       => $user->format_date($row['topic_time']),
782
 
                                'LAST_POST_SUBJECT'                     => $row['topic_last_post_subject'],
783
 
                                'LAST_POST_TIME'                        => $user->format_date($row['topic_last_post_time']),
784
 
                                'LAST_VIEW_TIME'                        => $user->format_date($row['topic_last_view_time']),
785
 
 
786
 
                                'TOPIC_AUTHOR'                          => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
787
 
                                'TOPIC_AUTHOR_COLOUR'           => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
788
 
                                'TOPIC_AUTHOR_FULL'                     => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
789
 
                                'U_TOPIC_AUTHOR'                        => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
790
 
 
791
 
                                'LAST_POST_AUTHOR'                      => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
792
 
                                'LAST_POST_AUTHOR_COLOUR'       => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
793
 
                                'LAST_POST_AUTHOR_FULL'         => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
794
 
                                'U_LAST_POST_AUTHOR'            => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
795
 
 
796
 
                                'S_DELETED_TOPIC'       => (!$row['topic_id']) ? true : false,
797
 
                                'S_GLOBAL_TOPIC'        => (!$forum_id) ? true : false,
798
 
 
799
 
                                'PAGINATION'            => topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&amp;t=$topic_id")),
800
 
                                'REPLIES'                       => $replies,
801
 
                                'VIEWS'                         => $row['topic_views'],
802
 
                                'TOPIC_TITLE'           => censor_text($row['topic_title']),
803
 
                                'TOPIC_TYPE'            => $topic_type,
804
 
                                'FORUM_NAME'            => $row['forum_name'],
805
 
 
806
 
                                'TOPIC_FOLDER_IMG'              => $user->img($folder_img, $folder_alt),
807
 
                                'TOPIC_FOLDER_IMG_SRC'  => $user->img($folder_img, $folder_alt, false, '', 'src'),
808
 
                                'TOPIC_ICON_IMG'                => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
809
 
                                'TOPIC_ICON_IMG_WIDTH'  => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
810
 
                                'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
811
 
                                'ATTACH_ICON_IMG'               => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
812
 
 
813
 
                                'S_TOPIC_TYPE'                  => $row['topic_type'],
814
 
                                'S_USER_POSTED'                 => (!empty($row['topic_posted'])) ? true : false,
815
 
                                'S_UNREAD_TOPIC'                => $unread_topic,
816
 
 
817
 
                                'U_NEWEST_POST'                 => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
818
 
                                'U_LAST_POST'                   => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
819
 
                                'U_VIEW_TOPIC'                  => $view_topic_url,
820
 
                                'U_VIEW_FORUM'                  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
821
 
                        ));
822
 
                }
823
 
        }
824
 
}
825
 
 
826
 
?>
 
 
b'\\ No newline at end of file'