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