PageRenderTime 70ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/ucp/ucp_main.php

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