[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @package ucp 5 * @version $Id: ucp_pm_viewfolder.php,v 1.46 2006/11/12 15:35:43 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 * View message folder 13 * Called from ucp_pm with mode == 'view' && action == 'view_folder' 14 */ 15 function view_folder($id, $mode, $folder_id, $folder) 16 { 17 global $user, $template, $auth, $db, $cache; 18 global $phpbb_root_path, $config, $phpEx; 19 20 $submit_export = (isset($_POST['submit_export'])) ? true : false; 21 22 $folder_info = get_pm_from($folder_id, $folder, $user->data['user_id']); 23 24 if (!$submit_export) 25 { 26 $user->add_lang('viewforum'); 27 28 // Grab icons 29 $icons = $cache->obtain_icons(); 30 31 $color_rows = array('marked', 'replied'); 32 33 // only show the friend/foe color rows if the module is enabled 34 $zebra_enabled = false; 35 36 $_module = new p_master(); 37 $_module->list_modules('ucp'); 38 $_module->set_active('zebra'); 39 40 $zebra_enabled = ($_module->active_module === false) ? false : true; 41 42 unset($_module); 43 44 if ($zebra_enabled) 45 { 46 $color_rows = array_merge($color_rows, array('friend', 'foe')); 47 } 48 49 foreach ($color_rows as $var) 50 { 51 $template->assign_block_vars('pm_colour_info', array( 52 'IMG' => $user->img("pm_{$var}", ''), 53 'CLASS' => "pm_{$var}_colour", 54 'LANG' => $user->lang[strtoupper($var) . '_MESSAGE']) 55 ); 56 } 57 58 $mark_options = array('mark_important', 'delete_marked'); 59 60 $s_mark_options = ''; 61 foreach ($mark_options as $mark_option) 62 { 63 $s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>'; 64 } 65 66 // We do the folder moving options here too, for template authors to use... 67 $s_folder_move_options = ''; 68 foreach ($folder as $f_id => $folder_ary) 69 { 70 if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id) 71 { 72 continue; 73 } 74 75 $s_folder_move_options .= '<option' . (($f_id != PRIVMSGS_INBOX) ? ' class="blue"' : '') . ' value="' . $f_id . '">'; 76 $s_folder_move_options .= sprintf($user->lang['MOVE_MARKED_TO_FOLDER'], $folder_ary['folder_name']); 77 $s_folder_move_options .= (($folder_ary['unread_messages']) ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>'; 78 } 79 80 $friend = $foe = array(); 81 82 // Get friends and foes 83 $sql = 'SELECT * 84 FROM ' . ZEBRA_TABLE . ' 85 WHERE user_id = ' . $user->data['user_id']; 86 $result = $db->sql_query($sql); 87 88 while ($row = $db->sql_fetchrow($result)) 89 { 90 $friend[$row['zebra_id']] = $row['friend']; 91 $foe[$row['zebra_id']] = $row['foe']; 92 } 93 $db->sql_freeresult($result); 94 95 $template->assign_vars(array( 96 'S_MARK_OPTIONS' => $s_mark_options, 97 'S_MOVE_MARKED_OPTIONS' => $s_folder_move_options) 98 ); 99 100 // Okay, lets dump out the page ... 101 if (sizeof($folder_info['pm_list'])) 102 { 103 $address_list = array(); 104 105 // Build Recipient List if in outbox/sentbox - max two additional queries 106 if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) 107 { 108 $recipient_list = $address = array(); 109 110 foreach ($folder_info['rowset'] as $message_id => $row) 111 { 112 $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address'])); 113 $_save = array('u', 'g'); 114 foreach ($_save as $save) 115 { 116 if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save])) 117 { 118 foreach (array_keys($address[$message_id][$save]) as $ug_id) 119 { 120 $recipient_list[$save][$ug_id] = array('name' => $user->lang['NA'], 'colour' => ''); 121 } 122 } 123 } 124 } 125 126 $_types = array('u', 'g'); 127 foreach ($_types as $ug_type) 128 { 129 if (!empty($recipient_list[$ug_type])) 130 { 131 if ($ug_type == 'u') 132 { 133 $sql = 'SELECT user_id as id, username as name, user_colour as colour 134 FROM ' . USERS_TABLE . ' 135 WHERE '; 136 } 137 else 138 { 139 $sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type 140 FROM ' . GROUPS_TABLE . ' 141 WHERE '; 142 } 143 $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type]))); 144 145 $result = $db->sql_query($sql); 146 147 while ($row = $db->sql_fetchrow($result)) 148 { 149 if ($ug_type == 'g') 150 { 151 $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name']; 152 } 153 154 $recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']); 155 } 156 $db->sql_freeresult($result); 157 } 158 } 159 160 foreach ($address as $message_id => $adr_ary) 161 { 162 foreach ($adr_ary as $type => $id_ary) 163 { 164 foreach ($id_ary as $ug_id => $_id) 165 { 166 $user_colour = ($recipient_list[$type][$ug_id]['colour']) ? ' style="color:#' . $recipient_list[$type][$ug_id]['colour'] . '"' : ''; 167 168 if ($type == 'u') 169 { 170 $link = ($ug_id != ANONYMOUS) ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $ug_id) . '"' . $user_colour . '>' : ''; 171 } 172 else 173 { 174 $link = '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $ug_id) . '"' . $user_colour . '>'; 175 } 176 177 $address_list[$message_id][] = $link . $recipient_list[$type][$ug_id]['name'] . (($link) ? '</a>' : ''); 178 } 179 } 180 } 181 unset($recipient_list, $address); 182 } 183 184 $data = array(); 185 186 foreach ($folder_info['pm_list'] as $message_id) 187 { 188 $row = &$folder_info['rowset'][$message_id]; 189 190 $folder_img = ($row['pm_unread']) ? 'pm_unread' : 'pm_read'; 191 $folder_alt = ($row['pm_unread']) ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES'; 192 193 // Generate all URIs ... 194 $message_author = ($row['author_id'] != ANONYMOUS) ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $row['author_id']) . '">' . $row['username'] . '</a>' : $row['username']; 195 $view_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=view&f=$folder_id&p=$message_id"); 196 $remove_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&action=delete&p=$message_id"); 197 198 $row_indicator = ''; 199 foreach ($color_rows as $var) 200 { 201 if (($var != 'friend' && $var != 'foe' && $row['pm_' . $var]) 202 || 203 (($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']])) 204 { 205 $row_indicator = $var; 206 break; 207 } 208 } 209 210 // Send vars to template 211 $template->assign_block_vars('messagerow', array( 212 'PM_CLASS' => ($row_indicator) ? 'pm_' . $row_indicator . '_colour' : '', 213 214 'FOLDER_ID' => $folder_id, 215 'MESSAGE_ID' => $message_id, 216 'MESSAGE_AUTHOR' => $message_author, 217 'SENT_TIME' => $user->format_date($row['message_time']), 218 'SUBJECT' => censor_text($row['message_subject']), 219 'FOLDER' => (isset($folder[$row['folder_id']])) ? $folder[$row['folder_id']]['folder_name'] : '', 220 'U_FOLDER' => (isset($folder[$row['folder_id']])) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'folder=' . $row['folder_id']) : '', 221 'PM_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '', 222 'FOLDER_IMG' => $user->img($folder_img, $folder_alt), 223 'FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 224 'PM_IMG' => ($row_indicator) ? $user->img('pm_' . $row_indicator, '') : '', 225 'ATTACH_ICON_IMG' => ($auth->acl_get('u_pm_download') && $row['message_attachment'] && $config['allow_pm_attach']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 226 227 'S_PM_DELETED' => ($row['pm_deleted']) ? true : false, 228 'S_AUTHOR_DELETED' => ($row['author_id'] == ANONYMOUS) ? true : false, 229 230 'U_VIEW_PM' => ($row['pm_deleted']) ? '' : $view_message_url, 231 'U_REMOVE_PM' => ($row['pm_deleted']) ? $remove_message_url : '', 232 'RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '') 233 ); 234 } 235 unset($folder_info['rowset']); 236 237 $template->assign_vars(array( 238 'S_SHOW_RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? true : false, 239 'S_SHOW_COLOUR_LEGEND' => true) 240 ); 241 } 242 } 243 else 244 { 245 $export_type = request_var('export_option', ''); 246 $enclosure = request_var('enclosure', ''); 247 $delimiter = request_var('delimiter', ''); 248 249 if ($export_type == 'CSV' && ($delimiter === '' || $enclosure === '')) 250 { 251 $template->assign_var('PROMPT', true); 252 } 253 else 254 { 255 // Build Recipient List if in outbox/sentbox 256 $address = array(); 257 if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) 258 { 259 foreach ($folder_info['rowset'] as $message_id => $row) 260 { 261 $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address'])); 262 } 263 } 264 265 foreach ($folder_info['pm_list'] as $message_id) 266 { 267 $row = &$folder_info['rowset'][$message_id]; 268 269 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); 270 271 $sql = 'SELECT p.message_text, p.bbcode_uid 272 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u 273 WHERE t.user_id = ' . $user->data['user_id'] . " 274 AND p.author_id = u.user_id 275 AND t.folder_id = $folder_id 276 AND t.msg_id = p.msg_id 277 AND p.msg_id = $message_id"; 278 $result = $db->sql_query_limit($sql, 1); 279 $message_row = $db->sql_fetchrow($result); 280 $db->sql_freeresult($result); 281 282 $_types = array('u', 'g'); 283 foreach ($_types as $ug_type) 284 { 285 if (isset($address[$message_id][$ug_type]) && sizeof($address[$message_id][$ug_type])) 286 { 287 if ($ug_type == 'u') 288 { 289 $sql = 'SELECT user_id as id, username as name 290 FROM ' . USERS_TABLE . ' 291 WHERE '; 292 } 293 else 294 { 295 $sql = 'SELECT group_id as id, group_name as name 296 FROM ' . GROUPS_TABLE . ' 297 WHERE '; 298 } 299 $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($address[$message_id][$ug_type]))); 300 301 $result = $db->sql_query($sql); 302 303 while ($info_row = $db->sql_fetchrow($result)) 304 { 305 $address[$message_id][$ug_type][$address[$message_id][$ug_type][$info_row['id']]][] = $info_row['name']; 306 unset($address[$message_id][$ug_type][$info_row['id']]); 307 } 308 $db->sql_freeresult($result); 309 } 310 } 311 312 decode_message($message_row['message_text'], $message_row['bbcode_uid']); 313 314 $data[] = array( 315 'subject' => censor_text($row['message_subject']), 316 'sender' => $row['username'], 317 'date' => $user->format_date($row['message_time']), 318 'to' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '', 319 'message' => $message_row['message_text'] 320 ); 321 } 322 323 switch ($export_type) 324 { 325 case 'CSV': 326 case 'CSV_EXCEL': 327 $mimetype = 'text/csv'; 328 $filetype = 'csv'; 329 330 if ($export_type == 'CSV_EXCEL') 331 { 332 $enclosure = '"'; 333 $delimiter = ','; 334 $newline = "\r\n"; 335 } 336 else 337 { 338 $newline = "\n"; 339 } 340 341 $string = ''; 342 foreach ($data as $value) 343 { 344 $recipients = $value['to']; 345 $value['to'] = $value['bcc'] = ''; 346 347 if (is_array($recipients)) 348 { 349 foreach ($recipients as $values) 350 { 351 $value['bcc'] .= (isset($values['bcc']) && is_array($values['bcc'])) ? ',' . implode(',', $values['bcc']) : ''; 352 $value['to'] .= (isset($values['to']) && is_array($values['to'])) ? ',' . implode(',', $values['to']) : ''; 353 } 354 355 // Remove the commas which will appear before the first entry. 356 $value['to'] = substr($value['to'], 1); 357 $value['bcc'] = substr($value['bcc'], 1); 358 } 359 360 foreach ($value as $tag => $text) 361 { 362 $cell = str_replace($enclosure, $enclosure . $enclosure, $text); 363 364 if (strpos($cell, $enclosure) !== false || strpos($cell, $delimiter) !== false || strpos($cell, $newline) !== false) 365 { 366 $string .= $enclosure . $text . $enclosure . $delimiter; 367 } 368 else 369 { 370 $string .= $cell . $delimiter; 371 } 372 } 373 $string = substr($string, 0, -1) . $newline; 374 } 375 break; 376 377 case 'XML': 378 $mimetype = 'application/xml'; 379 $filetype = 'xml'; 380 $string = '<?xml version="1.0"?>' . "\n"; 381 $string .= "<phpbb>\n"; 382 383 foreach ($data as $value) 384 { 385 $string .= "\t<privmsg>\n"; 386 387 if (is_array($value['to'])) 388 { 389 foreach ($value['to'] as $key => $values) 390 { 391 foreach ($values as $type => $types) 392 { 393 foreach ($types as $name) 394 { 395 $string .= "\t\t<recipient type=\"$type\" status=\"$key\">$name</recipient>\n"; 396 } 397 } 398 } 399 } 400 401 unset($value['to']); 402 403 foreach ($value as $tag => $text) 404 { 405 $string .= "\t\t<$tag>$text</$tag>\n"; 406 } 407 408 $string .= "\t</privmsg>\n"; 409 } 410 $string .= '</phpbb>'; 411 break; 412 } 413 414 header('Pragma: no-cache'); 415 header("Content-Type: $mimetype; name=\"data.$filetype\""); 416 header("Content-disposition: attachment; filename=data.$filetype"); 417 echo $string; 418 exit; 419 } 420 } 421 } 422 423 /** 424 * Get Messages from folder/user 425 */ 426 function get_pm_from($folder_id, $folder, $user_id) 427 { 428 global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx; 429 430 $start = request_var('start', 0); 431 432 // Additional vars later, pm ordering is mostly different from post ordering. :/ 433 $sort_days = request_var('st', 0); 434 $sort_key = request_var('sk', 't'); 435 $sort_dir = request_var('sd', 'd'); 436 437 // PM ordering options 438 $limit_days = array(0 => $user->lang['ALL_MESSAGES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); 439 $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); 440 $sort_by_sql = array('a' => 'u.username', 't' => 'p.message_time', 's' => 'p.message_subject'); 441 442 $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; 443 gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); 444 445 $folder_sql = 't.folder_id = ' . (int) $folder_id; 446 447 // Limit pms to certain time frame, obtain correct pm count 448 if ($sort_days) 449 { 450 $min_post_time = time() - ($sort_days * 86400); 451 452 if (isset($_POST['sort'])) 453 { 454 $start = 0; 455 } 456 457 $sql = 'SELECT COUNT(t.msg_id) AS pm_count 458 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . " p 459 WHERE $folder_sql 460 AND t.user_id = $user_id 461 AND t.msg_id = p.msg_id 462 AND p.message_time >= $min_post_time"; 463 $result = $db->sql_query_limit($sql, 1); 464 $pm_count = (int) $db->sql_fetchfield('pm_count'); 465 $db->sql_freeresult($result); 466 467 $sql_limit_time = "AND p.message_time >= $min_post_time"; 468 } 469 else 470 { 471 $pm_count = $folder[$folder_id]['num_messages']; 472 $sql_limit_time = ''; 473 } 474 475 $template->assign_vars(array( 476 'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&action=view_folder&f=$folder_id&$u_sort_param"), $pm_count, $config['topics_per_page'], $start), 477 'PAGE_NUMBER' => on_page($pm_count, $config['topics_per_page'], $start), 478 'TOTAL_MESSAGES' => (($pm_count == 1) ? $user->lang['VIEW_PM_MESSAGE'] : sprintf($user->lang['VIEW_PM_MESSAGES'], $pm_count)), 479 480 'POST_IMG' => (!$auth->acl_get('u_sendpm')) ? $user->img('button_topic_locked', 'PM_LOCKED') : $user->img('button_pm_new', 'POST_PM'), 481 482 'L_NO_MESSAGES' => (!$auth->acl_get('u_sendpm')) ? $user->lang['POST_PM_LOCKED'] : $user->lang['NO_MESSAGES'], 483 484 'S_SELECT_SORT_DIR' => $s_sort_dir, 485 'S_SELECT_SORT_KEY' => $s_sort_key, 486 'S_SELECT_SORT_DAYS' => $s_limit_days, 487 'S_TOPIC_ICONS' => ($config['enable_pm_icons']) ? true : false, 488 489 'U_POST_NEW_TOPIC' => ($auth->acl_get('u_sendpm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose') : '', 490 'S_PM_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&action=view_folder&f=$folder_id")) 491 ); 492 493 // Grab all pm data 494 $rowset = $pm_list = array(); 495 496 // If the user is trying to reach late pages, start searching from the end 497 $store_reverse = false; 498 $sql_limit = $config['topics_per_page']; 499 if ($start > $pm_count / 2) 500 { 501 $store_reverse = true; 502 503 if ($start + $config['topics_per_page'] > $pm_count) 504 { 505 $sql_limit = min($config['topics_per_page'], max(1, $pm_count - $start)); 506 } 507 508 // Select the sort order 509 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC'); 510 $sql_start = max(0, $pm_count - $sql_limit - $start); 511 } 512 else 513 { 514 // Select the sort order 515 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); 516 $sql_start = $start; 517 } 518 519 $sql = 'SELECT t.*, p.author_id, p.root_level, p.message_time, p.message_subject, p.icon_id, p.to_address, p.message_attachment, p.bcc_address, u.username 520 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u 521 WHERE t.user_id = $user_id 522 AND p.author_id = u.user_id 523 AND $folder_sql 524 AND t.msg_id = p.msg_id 525 $sql_limit_time 526 ORDER BY $sql_sort_order"; 527 $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); 528 529 while ($row = $db->sql_fetchrow($result)) 530 { 531 $rowset[$row['msg_id']] = $row; 532 $pm_list[] = $row['msg_id']; 533 } 534 $db->sql_freeresult($result); 535 536 $pm_list = ($store_reverse) ? array_reverse($pm_list) : $pm_list; 537 538 return array( 539 'pm_count' => $pm_count, 540 'pm_list' => $pm_list, 541 'rowset' => $rowset 542 ); 543 } 544 545 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |