Issues (1014)

Themes/default/PersonalMessage.template.php (4 issues)

Labels
Severity
1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines https://www.simplemachines.org
7
 * @copyright 2022 Simple Machines and individual contributors
8
 * @license https://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1.2
11
 */
12
13
/**
14
 * This is for stuff above the menu in the personal messages section
15
 */
16
function template_pm_above()
17
{
18
	global $context, $txt;
19
20
	echo '
21
	<div id="personal_messages">';
22
23
	// Show the capacity bar, if available.
24
	if (!empty($context['limit_bar']))
25
		echo '
26
		<div class="cat_bar">
27
			<h3 class="catbg">
28
				<span class="floatleft">', $txt['pm_capacity'], ':</span>
29
				<span class="floatleft capacity_bar">
30
					<span class="', $context['limit_bar']['percent'] > 85 ? 'full' : ($context['limit_bar']['percent'] > 40 ? 'filled' : 'empty'), '" style="width: ', $context['limit_bar']['percent'] / 10, 'em;"></span>
31
				</span>
32
				<span class="floatright', $context['limit_bar']['percent'] > 90 ? ' alert' : '', '">', $context['limit_bar']['text'], '</span>
33
			</h3>
34
		</div>';
35
36
	// Message sent? Show a small indication.
37
	if (isset($context['pm_sent']))
38
		echo '
39
		<div class="infobox">
40
			', $txt['pm_sent'], '
41
		</div>';
42
}
43
44
/**
45
 * Just the end of the index bar, nothing special.
46
 */
47
function template_pm_below()
48
{
49
	echo '
50
	</div><!-- #personal_messages -->';
51
}
52
53
/**
54
 * Displays a popup with information about your personal messages
55
 */
56
function template_pm_popup()
57
{
58
	global $context, $txt, $scripturl;
59
60
	// Unlike almost every other template, this is designed to be included into the HTML directly via $().load()
61
	echo '
62
		<div class="pm_bar">
63
			<div class="pm_sending block">
64
				', $context['can_send_pm'] ? '<a href="' . $scripturl . '?action=pm;sa=send">' . $txt['pm_new_short'] . '</a>' : '', '
65
				', $context['can_draft'] ? ' | <a href="' . $scripturl . '?action=pm;sa=showpmdrafts">' . $txt['pm_drafts_short'] . '</a>' : '', '
66
				<a href="', $scripturl, '?action=pm;sa=settings" class="floatright">', $txt['pm_settings_short'], '</a>
67
			</div>
68
			<div class="pm_mailbox centertext">
69
				<a href="', $scripturl, '?action=pm" class="button">', $txt['inbox'], '</a>
70
				<a href="', $scripturl, '?action=pm;f=sent" class="button">', $txt['sent_items'], '</a>
71
			</div>
72
		</div>
73
		<div class="pm_unread">';
74
75
	if (empty($context['unread_pms']))
76
		echo '
77
			<div class="no_unread">', $txt['pm_no_unread'], '</div>';
78
	else
79
	{
80
		foreach ($context['unread_pms'] as $id_pm => $pm_details)
81
			echo '
82
			<div class="unread_notify">
83
				<div class="unread_notify_image">
84
					', !empty($pm_details['member']) ? $pm_details['member']['avatar']['image'] : '', '
85
				</div>
86
				<div class="details">
87
					<div class="subject">', $pm_details['pm_link'], '</div>
88
					<div class="sender">
89
						', $pm_details['replied_to_you'] ? '<span class="main_icons replied centericon" style="margin-right: 4px" title="' . $txt['pm_you_were_replied_to'] . '"></span>' : '<span class="main_icons im_off centericon" style="margin-right: 4px" title="' . $txt['pm_was_sent_to_you'] . '"></span>',
90
						!empty($pm_details['member']) ? $pm_details['member']['link'] : $pm_details['member_from'], ' - ', $pm_details['time'], '
91
					</div>
92
				</div>
93
			</div>';
94
	}
95
96
	echo '
97
		</div><!-- #pm_unread -->';
98
}
99
100
/**
101
 * Shows a particular folder (eg inbox or outbox), all the PMs in it, etc.
102
 */
103
function template_folder()
104
{
105
	global $context, $scripturl, $txt;
106
107
	// The every helpful javascript!
108
	echo '
109
		<script>
110
			var allLabels = {};
111
			var currentLabels = {};
112
			function loadLabelChoices()
113
			{
114
				var listing = document.forms.pmFolder.elements;
115
				var theSelect = document.forms.pmFolder.pm_action;
116
				var add, remove, toAdd = {length: 0}, toRemove = {length: 0};
117
118
				if (theSelect.childNodes.length == 0)
119
					return;
120
121
				// This is done this way for internationalization reasons.
122
				if (!(\'-1\' in allLabels))
123
				{
124
					for (var o = 0; o < theSelect.options.length; o++)
125
						if (theSelect.options[o].value.substr(0, 4) == "rem_")
126
							allLabels[theSelect.options[o].value.substr(4)] = theSelect.options[o].text;
127
				}
128
129
				for (var i = 0; i < listing.length; i++)
130
				{
131
					if (listing[i].name != "pms[]" || !listing[i].checked)
132
						continue;
133
134
					var alreadyThere = [], x;
135
					for (x in currentLabels[listing[i].value])
136
					{
137
						if (!(x in toRemove))
138
						{
139
							toRemove[x] = allLabels[x];
140
							toRemove.length++;
141
						}
142
						alreadyThere[x] = allLabels[x];
143
					}
144
145
					for (x in allLabels)
146
					{
147
						if (!(x in alreadyThere))
148
						{
149
							toAdd[x] = allLabels[x];
150
							toAdd.length++;
151
						}
152
					}
153
				}
154
155
				while (theSelect.options.length > 2)
156
					theSelect.options[2] = null;
157
158
				if (toAdd.length != 0)
159
				{
160
					theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_apply'], '", "");
161
					setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_apply'], '");
162
					theSelect.options[theSelect.options.length - 1].disabled = true;
163
164
					for (i in toAdd)
165
					{
166
						if (i != "length")
167
							theSelect.options[theSelect.options.length] = new Option(toAdd[i], "add_" + i);
168
					}
169
				}
170
171
				if (toRemove.length != 0)
172
				{
173
					theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_remove'], '", "");
174
					setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_remove'], '");
175
					theSelect.options[theSelect.options.length - 1].disabled = true;
176
177
					for (i in toRemove)
178
					{
179
						if (i != "length")
180
							theSelect.options[theSelect.options.length] = new Option(toRemove[i], "rem_" + i);
181
					}
182
				}
183
			}
184
		</script>';
185
186
	echo '
187
		<form class="flow_hidden" action="', $scripturl, '?action=pm;sa=pmactions;', $context['display_mode'] == 2 ? 'conversation;' : '', 'f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '" method="post" accept-charset="', $context['character_set'], '" name="pmFolder" id="pmFolder">';
188
189
	// If we are not in single display mode show the subjects on the top!
190
	if ($context['display_mode'] != 1)
191
	{
192
		template_subject_list();
193
194
		echo '
195
			<div class="clear_right"><br></div>';
196
	}
197
198
	// Got some messages to display?
199
	if ($context['get_pmessage']('message', true))
200
	{
201
		// Show a few buttons if we are in conversation mode and outputting the first message.
202
		if ($context['display_mode'] == 2)
203
		{
204
			// This bit uses info set in template_subject_list, so it's wrapped
205
			// in an if just in case a mod or custom theme breaks it.
206
			if (!empty($context['current_pm_subject']))
207
			{
208
				echo '
209
			<div class="cat_bar">
210
				<h3 class="catbg">
211
					<span>', $txt['conversation'], '</span>
212
				</h3>
213
			</div>
214
			<div class="roundframe">
215
				<div class="display_title">', $context['current_pm_subject'], '</div>
216
				<p>', $txt['started_by'], ' ', $context['current_pm_author'], ', ', $context['current_pm_time'], '</p>';
217
			}
218
			else
219
			{
220
				echo '
221
			<div class="roundframe">';
222
			}
223
224
			// Show the conversation buttons.
225
			template_button_strip($context['conversation_buttons'], 'right');
226
227
			echo '
228
			</div>';
229
		}
230
231
		while ($message = $context['get_pmessage']('message'))
232
			template_single_pm($message);
233
234
		if (empty($context['display_mode']))
235
			echo '
236
			<div class="pagesection">
237
				<div class="pagelinks">', $context['page_index'], '</div>
238
				<div class="floatright">
239
					<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button">
240
				</div>
241
			</div>';
242
243
		// Show a few buttons if we are in conversation mode and outputting the first message.
244
		elseif ($context['display_mode'] == 2 && isset($context['conversation_buttons']))
245
		{
246
			echo '
247
			<div class="pagesection">';
248
249
			template_button_strip($context['conversation_buttons'], 'right');
250
251
			echo '
252
			</div>';
253
		}
254
255
		echo '
256
			<br>';
257
	}
258
259
	// Individual messages = buttom list!
260
	if ($context['display_mode'] == 1)
261
	{
262
		template_subject_list();
263
		echo '<br>';
264
	}
265
266
	echo '
267
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
268
		</form>';
269
}
270
271
/**
272
 * Template for displaying a single personal message.
273
 *
274
 * @param array $message An array of information about the message to display.
275
 */
276
function template_single_pm($message)
277
{
278
	global $context, $scripturl, $txt, $settings, $options, $modSettings;
279
280
	echo '
281
	<div class="windowbg" id="msg', $message['id'],'">
282
		<div class="post_wrapper">
283
			<div class="poster">';
284
285
	// Are there any custom fields above the member name?
286
	if (!empty($message['custom_fields']['above_member']))
287
	{
288
		echo '
289
				<div class="custom_fields_above_member">
290
					<ul class="nolist">';
291
292
		foreach ($message['custom_fields']['above_member'] as $custom)
293
			echo '
294
						<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
295
296
		echo '
297
					</ul>
298
				</div>';
299
	}
300
301
	echo '
302
				<h4>';
303
304
	// Show online and offline buttons?
305
	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
306
		echo '
307
					<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>';
308
309
	// Custom fields BEFORE the username?
310
	if (!empty($message['custom_fields']['before_member']))
311
		foreach ($message['custom_fields']['before_member'] as $custom)
312
			echo '
313
					<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
314
315
	// Show a link to the member's profile.
316
	echo '
317
		', $message['member']['link'];
318
319
	// Custom fields AFTER the username?
320
	if (!empty($message['custom_fields']['after_member']))
321
		foreach ($message['custom_fields']['after_member'] as $custom)
322
			echo '
323
					<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
324
325
	echo '
326
				</h4>';
327
328
	echo '
329
				<ul class="user_info">';
330
331
	// Show the member's custom title, if they have one.
332
	if (isset($message['member']['title']) && $message['member']['title'] != '')
333
		echo '
334
					<li class="title">', $message['member']['title'], '</li>';
335
336
	// Show the member's primary group (like 'Administrator') if they have one.
337
	if (isset($message['member']['group']) && $message['member']['group'] != '')
338
		echo '
339
					<li class="membergroup">', $message['member']['group'], '</li>';
340
341
	// Show the user's avatar.
342
	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
343
		echo '
344
					<li class="avatar">
345
						<a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '">', $message['member']['avatar']['image'], '</a>
346
					</li>';
347
348
	// Are there any custom fields below the avatar?
349
	if (!empty($message['custom_fields']['below_avatar']))
350
		foreach ($message['custom_fields']['below_avatar'] as $custom)
351
			echo '
352
					<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
353
354
	// Don't show these things for guests.
355
	if (!$message['member']['is_guest'])
356
	{
357
		// Show the post group icons
358
		echo '
359
					<li class="icons">', $message['member']['group_icons'], '</li>';
360
361
		// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
362
		if ((empty($modSettings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '')
363
			echo '
364
					<li class="postgroup">', $message['member']['post_group'], '</li>';
365
366
		// Show how many posts they have made.
367
		if (!isset($context['disabled_fields']['posts']))
368
			echo '
369
					<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
370
371
		// Show their personal text?
372
		if (!empty($modSettings['show_blurb']) && $message['member']['blurb'] != '')
373
			echo '
374
					<li class="blurb">', $message['member']['blurb'], '</li>';
375
376
		// Any custom fields to show as icons?
377
		if (!empty($message['custom_fields']['icons']))
378
		{
379
			echo '
380
					<li class="im_icons">
381
						<ol>';
382
383
			foreach ($message['custom_fields']['icons'] as $custom)
384
				echo '
385
							<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
386
387
			echo '
388
						</ol>
389
					</li>';
390
		}
391
392
		// Show the IP to this user for this post - because you can moderate?
393
		if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
394
			echo '
395
					<li class="poster_ip">
396
						<a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a>
397
					</li>';
398
399
		// Or, should we show it because this is you?
400
		elseif ($message['can_see_ip'])
401
			echo '
402
					<li class="poster_ip">
403
						<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a>
404
					</li>';
405
406
		// Okay, you are logged in, then we can show something about why IPs are logged...
407
		else
408
			echo '
409
					<li class="poster_ip">
410
						<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a>
411
					</li>';
412
413
		// Show the profile, website, email address, and personal message buttons.
414
		if ($message['member']['show_profile_buttons'])
415
		{
416
			echo '
417
					<li class="profile">
418
						<ol class="profile_icons">';
419
420
			// Show the profile button
421
			if ($message['member']['can_view_profile'])
422
				echo '
423
							<li><a href="', $message['member']['href'], '" title="' . $txt['view_profile'] . '">', ($settings['use_image_buttons'] ? '<span class="main_icons profile_sm"></span>' : $txt['view_profile']), '</a></li>';
424
425
			// Don't show an icon if they haven't specified a website.
426
			if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website']))
427
				echo '
428
							<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="main_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
429
430
			// Don't show the email address if they want it hidden.
431
			if ($message['member']['show_email'])
432
				echo '
433
							<li><a href="mailto:', $message['member']['email'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="main_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
434
435
			// Since we know this person isn't a guest, you *can* message them.
436
			if ($context['can_send_pm'] && $message['member']['id'] != 0)
437
				echo '
438
							<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="main_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
439
440
			echo '
441
						</ol>
442
					</li>';
443
		}
444
445
		// Any custom fields for standard placement?
446
		if (!empty($message['custom_fields']['standard']))
447
			foreach ($message['custom_fields']['standard'] as $custom)
448
				echo '
449
					<li class="custom ', $custom['col_name'], '">', $custom['title'], ': ', $custom['value'], '</li>';
450
451
		// Are we showing the warning status?
452
		if ($message['member']['can_see_warning'])
453
			echo '
454
					<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="main_icons warning_', $message['member']['warning_status'], '"></span>', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
455
456
		// Are there any custom fields to show at the bottom of the poster info?
457
		if (!empty($message['custom_fields']['bottom_poster']))
458
			foreach ($message['custom_fields']['bottom_poster'] as $custom)
459
				echo '
460
					<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
461
	}
462
463
	// Done with the information about the poster... on to the post itself.
464
	echo '
465
				</ul>
466
			</div><!-- .poster -->
467
			<div class="postarea">
468
				<div class="keyinfo">
469
					<div id="subject_', $message['id'], '" class="subject_title">
470
						<h5>', $message['subject'], '</h5>
471
					</div>
472
					<div class="postinfo">';
473
474
	// Show who the message was sent to.
475
	echo '
476
						<span class="smalltext"><strong> ', $txt['sent_to'], ':</strong> ';
477
478
	// People it was sent directly to....
479
	if (!empty($message['recipients']['to']))
480
		echo implode(', ', $message['recipients']['to']);
481
482
	// Otherwise, we're just going to say "some people"...
483
	elseif ($context['folder'] != 'sent')
484
		echo '(', $txt['pm_undisclosed_recipients'], ')';
485
486
	echo '
487
							<strong> ', $txt['on'], ':</strong> ', $message['time'], '
488
						</span>';
489
490
	// If we're in the sent items, show who it was sent to besides the "To:" people.
491
	if (!empty($message['recipients']['bcc']))
492
		echo '
493
						<span class="smalltext"><strong> ', $txt['pm_bcc'], ':</strong> ', implode(', ', $message['recipients']['bcc']), ' </span>';
494
495
	if (!empty($message['is_replied_to']))
496
		echo '
497
						<span class="smalltext">', $context['folder'] == 'sent' ? $txt['pm_sent_is_replied_to'] : $txt['pm_is_replied_to'], ' </span>';
498
499
	echo '
500
					</div><!-- .postinfo -->
501
				</div><!-- .keyinfo -->
502
				<div class="post">
503
					<div class="inner" id="msg_', $message['id'], '"', '>
504
						', $message['body'], '
505
					</div>
506
				</div><!-- .post -->
507
				<div class="under_message">';
508
509
	// Add an extra line at the bottom if we have labels enabled.
510
	if ($context['folder'] != 'sent' && !empty($context['currently_using_labels']) && $context['display_mode'] != 2)
511
	{
512
		echo '
513
				<div class="labels floatleft">';
514
515
		// Add the label drop down box.
516
		if (!empty($context['currently_using_labels']))
517
		{
518
			echo '
519
					<select name="pm_actions[', $message['id'], ']" onchange="if (this.options[this.selectedIndex].value) form.submit();">
520
						<option value="">', $txt['pm_msg_label_title'], ':</option>
521
						<option value="" disabled>---------------</option>';
522
523
			// Are there any labels which can be added to this?
524
			if (!$message['fully_labeled'])
525
			{
526
				echo '
527
						<option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>';
528
529
				foreach ($context['labels'] as $label)
530
					if (!isset($message['labels'][$label['id']]))
531
						echo '
532
						<option value="', $label['id'], '">', $label['name'], '</option>';
533
			}
534
535
			// ... and are there any that can be removed?
536
			if (!empty($message['labels']) && (count($message['labels']) > 1 || !isset($message['labels'][-1])))
537
			{
538
				echo '
539
						<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
540
541
				foreach ($message['labels'] as $label)
542
					echo '
543
						<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
544
			}
545
			echo '
546
					</select>
547
					<noscript>
548
						<input type="submit" value="', $txt['pm_apply'], '" class="button">
549
					</noscript>';
550
		}
551
		echo '
552
				</div><!-- .labels -->';
553
	}
554
555
	// Message options
556
	template_quickbuttons($message['quickbuttons'], 'pm');
557
558
	echo '
559
				</div><!-- .under_message -->
560
			</div><!-- .postarea -->
561
			<div class="moderatorbar">';
562
563
	// Are there any custom profile fields for above the signature?
564
	if (!empty($message['custom_fields']['above_signature']))
565
	{
566
		echo '
567
				<div class="custom_fields_above_signature">
568
					<ul class="nolist">';
569
570
		foreach ($message['custom_fields']['above_signature'] as $custom)
571
			echo '
572
						<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
573
574
		echo '
575
					</ul>
576
				</div>';
577
	}
578
579
	// Show the member's signature?
580
	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
581
		echo '
582
				<div class="signature">
583
					', $message['member']['signature'], '
584
				</div>';
585
586
	// Are there any custom profile fields for below the signature?
587
	if (!empty($message['custom_fields']['below_signature']))
588
	{
589
		echo '
590
				<div class="custom_fields_below_signature">
591
					<ul class="nolist">';
592
593
		foreach ($message['custom_fields']['below_signature'] as $custom)
594
			echo '
595
						<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
596
597
		echo '
598
					</ul>
599
				</div>';
600
	}
601
602
	echo '
603
			</div><!-- .moderatorbar -->
604
		</div><!-- .post_wrapper -->
605
	</div><!-- .windowbg -->';
606
}
607
608
/**
609
 * Just list all the personal message subjects - to make templates easier.
610
 */
611
function template_subject_list()
612
{
613
	global $context, $settings, $txt, $scripturl;
614
615
	echo '
616
	<div class="cat_bar">
617
		<h3 class="catbg">
618
			', $context['folder'] == 'sent' ? $txt['sent_items'] : $context['current_label'], '
619
		</h3>
620
	</div>
621
	<table class="table_grid">
622
		<thead>
623
			<tr class="title_bar">
624
				<th class="centercol table_icon pm_icon">
625
					<a href="', $scripturl, '?action=pm;view;f=', $context['folder'], ';start=', $context['start'], ';sort=', $context['sort_by'], ($context['sort_direction'] == 'up' ? '' : ';desc'), ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), '"> <span class="main_icons switch" title="', $txt['pm_change_view'], '"></span></a>
626
				</th>
627
				<th class="lefttext quarter_table pm_time">
628
					<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=date', $context['sort_by'] == 'date' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['date'], $context['sort_by'] == 'date' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
629
				</th>
630
				<th class="lefttext half_table pm_subject">
631
					<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
632
				</th>
633
				<th class="lefttext pm_from_to">
634
					<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', ($context['from_or_to'] == 'from' ? $txt['from'] : $txt['pm_to']), $context['sort_by'] == 'name' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
635
				</th>
636
				<th class="centercol table_icon pm_moderation">
637
					<input type="checkbox" onclick="invertAll(this, this.form);">
638
				</th>
639
			</tr>
640
		</thead>
641
		<tbody>';
642
643
	if (!$context['show_delete'])
644
		echo '
645
			<tr class="windowbg">
646
				<td colspan="5">', $txt['pm_alert_none'], '</td>
647
			</tr>';
648
649
	while ($message = $context['get_pmessage']('subject'))
650
	{
651
		// Used for giving extra info in conversation view
652
		if ($context['current_pm'] == $message['id'])
653
		{
654
			$context['current_pm_subject'] = $message['subject'];
655
			$context['current_pm_time'] = $message['time'];
656
			$context['current_pm_author'] = $message['member']['link'];
657
		}
658
659
		echo '
660
			<tr class="windowbg', $message['is_unread'] ? ' unread_pm' : '', '">
661
				<td class="table_icon pm_icon">
662
					<script>
663
						currentLabels[', $message['id'], '] = {';
664
665
		if (!empty($message['labels']))
666
		{
667
			$first = true;
668
			foreach ($message['labels'] as $label)
669
			{
670
				echo $first ? '' : ',', '
671
				"', $label['id'], '": "', $label['name'], '"';
672
				$first = false;
673
			}
674
		}
675
676
		echo '
677
						};
678
					</script>
679
					', $message['is_replied_to'] ? '<span class="main_icons replied" title="' . $txt['pm_replied'] . '"></span>' : '<span class="main_icons im_off" title="' . $txt['pm_read'] . '"></span>', '
680
				</td>
681
				<td class="pm_time">', $message['time'], '</td>
682
				<td class="pm_subject">
683
					', ($context['display_mode'] != 0 && $context['current_pm'] == $message['id'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*">' : ''), '<a href="', ($context['display_mode'] == 0 || $context['current_pm'] == $message['id'] ? '' : ($scripturl . '?action=pm;pmid=' . $message['id'] . ';kstart;f=' . $context['folder'] . ';start=' . $context['start'] . ';sort=' . $context['sort_by'] . ($context['sort_direction'] == 'up' ? ';' : ';desc') . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''))), '#msg', $message['id'], '">', $message['subject'], $message['is_unread'] ? '&nbsp;<span class="new_posts">' . $txt['new'] . '</span>' : '', '</a>
684
					<span class="pm_inline_time"><span class="main_icons ', ($context['from_or_to'] == 'to' && count($message['recipients']['to']) > 1) ? 'people' : 'members', '"></span> ', ($context['from_or_to'] == 'from' ? $message['member']['link'] : (empty($message['recipients']['to']) ? '' : implode(', ', $message['recipients']['to']))), '  <span class="main_icons time_online"></span> ', $message['time'], '</span>
685
				</td>
686
				<td class="pm_from_to">
687
					', ($context['from_or_to'] == 'from' ? $message['member']['link'] : (empty($message['recipients']['to']) ? '' : implode(', ', $message['recipients']['to']))), '
688
				</td>
689
				<td class="centercol table_icon pm_moderation">
690
					<input type="checkbox" name="pms[]" id="deletelisting', $message['id'], '" value="', $message['id'], '"', $message['is_selected'] ? ' checked' : '', ' onclick="if (document.getElementById(\'deletedisplay', $message['id'], '\')) document.getElementById(\'deletedisplay', $message['id'], '\').checked = this.checked;">
691
				</td>
692
			</tr>';
693
	}
694
695
	echo '
696
		</tbody>
697
	</table>
698
	<div class="pagesection">
699
		<div class="pagelinks">', $context['page_index'], '</div>
700
		<div class="floatright">&nbsp;';
701
702
	if ($context['show_delete'])
703
	{
704
		if (!empty($context['currently_using_labels']) && $context['folder'] != 'sent')
705
		{
706
			echo '
707
			<select name="pm_action" onchange="if (this.options[this.selectedIndex].value) this.form.submit();" onfocus="loadLabelChoices();">
708
				<option value="">', $txt['pm_sel_label_title'], ':</option>
709
				<option value="" disabled>---------------</option>
710
				<option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>';
711
712
			foreach ($context['labels'] as $label)
713
			{
714
				if ($label['id'] != $context['current_label_id'])
715
					echo '
716
				<option value="add_', $label['id'], '">&nbsp;', $label['name'], '</option>';
717
			}
718
719
			echo '
720
				<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
721
722
			foreach ($context['labels'] as $label)
723
				echo '
724
				<option value="rem_', $label['id'], '">&nbsp;', $label['name'], '</option>';
725
726
			echo '
727
			</select>
728
			<noscript>
729
				<input type="submit" value="', $txt['pm_apply'], '" class="button">
730
			</noscript>';
731
		}
732
733
		echo '
734
			<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button">';
735
	}
736
737
	echo '
738
		</div><!-- .floatright -->
739
	</div><!-- .pagesection -->';
740
}
741
742
/**
743
 * The form for the PM search feature
744
 */
745
function template_search()
746
{
747
	global $context, $scripturl, $txt;
748
749
	if (!empty($context['search_errors']))
750
		echo '
751
		<div class="errorbox">
752
			', implode('<br>', $context['search_errors']['messages']), '
753
		</div>';
754
755
	echo '
756
	<form action="', $scripturl, '?action=pm;sa=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
757
		<div class="cat_bar">
758
			<h3 class="catbg">', $txt['pm_search_title'], '</h3>
759
		</div>
760
		<div id="advanced_search" class="roundframe">
761
			<input type="hidden" name="advanced" value="1">
762
			<dl id="search_options" class="settings">
763
				<dt>
764
					<strong><label for="searchfor">', $txt['pm_search_text'], ':</label></strong>
765
				</dt>
766
				<dd>
767
					<input type="search" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40">
768
					<script>
769
						createEventListener(window);
770
						window.addEventListener("load", initSearch, false);
771
					</script>
772
				</dd>
773
				<dt>
774
					<label for="searchtype">', $txt['search_match'], ':</label>
775
				</dt>
776
				<dd>
777
					<select name="searchtype">
778
						<option value="1"', empty($context['search_params']['searchtype']) ? ' selected' : '', '>', $txt['pm_search_match_all'], '</option>
779
						<option value="2"', !empty($context['search_params']['searchtype']) ? ' selected' : '', '>', $txt['pm_search_match_any'], '</option>
780
					</select>
781
				</dd>
782
				<dt>
783
					<label for="userspec">', $txt['pm_search_user'], ':</label>
784
				</dt>
785
				<dd>
786
					<input type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40">
787
				</dd>
788
				<dt>
789
					<label for="sort">', $txt['pm_search_order'], ':</label>
790
				</dt>
791
				<dd>
792
					<select name="sort">
793
						<option value="relevance|desc">', $txt['pm_search_orderby_relevant_first'], '</option>
794
						<option value="id_pm|desc">', $txt['pm_search_orderby_recent_first'], '</option>
795
						<option value="id_pm|asc">', $txt['pm_search_orderby_old_first'], '</option>
796
					</select>
797
				</dd>
798
				<dt class="options">
799
					', $txt['pm_search_options'], ':
800
				</dt>
801
				<dd class="options">
802
					<label for="show_complete">
803
						<input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked' : '', '> ', $txt['pm_search_show_complete'], '
804
					</label><br>
805
					<label for="subject_only">
806
						<input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked' : '', '> ', $txt['pm_search_subject_only'], '
807
					</label>
808
				</dd>
809
				<dt class="between">
810
					', $txt['pm_search_post_age'], ':
811
				</dt>
812
				<dd>
813
					', $txt['pm_search_between'], '
814
					<input type="number" name="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="5" min="0" max="9999">
815
					', $txt['pm_search_between_and'], '
816
					<input type="number" name="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="5" min="0" max="9999">
817
					', $txt['pm_search_between_days'], '
818
				</dd>
819
			</dl>';
820
821
	if (!$context['currently_using_labels'])
822
		echo '
823
				<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button floatright">';
824
825
	echo '
826
		</div><!-- .roundframe -->';
827
828
	// Do we have some labels setup? If so offer to search by them!
829
	if ($context['currently_using_labels'])
830
	{
831
		echo '
832
		<fieldset class="labels">
833
			<div class="roundframe alt">
834
				<div class="title_bar">
835
					<h3 class="titlebg">
836
						<span id="advanced_panel_toggle" class="toggle_up floatright" style="display: none;"></span><a href="#" id="advanced_panel_link">', $txt['pm_search_choose_label'], '</a>
837
					</h3>
838
				</div>
839
				<div id="advanced_panel_div">
840
					<ul id="search_labels">';
841
842
		foreach ($context['search_labels'] as $label)
843
			echo '
844
						<li>
845
							<label for="searchlabel_', $label['id'], '"><input type="checkbox" id="searchlabel_', $label['id'], '" name="searchlabel[', $label['id'], ']" value="', $label['id'], '"', $label['checked'] ? ' checked' : '', '>
846
							', $label['name'], '</label>
847
						</li>';
848
849
		echo '
850
					</ul>
851
				</div>
852
				<br class="clear">
853
				<div class="padding">
854
					<input type="checkbox" name="all" id="check_all" value=""', $context['check_all'] ? ' checked' : '', ' onclick="invertAll(this, this.form, \'searchlabel\');">
855
					<label for="check_all"><em>', $txt['check_all'], '</em></label>
856
					<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button floatright">
857
				</div class="padding">
858
			</div><!-- .roundframe -->
859
		</fieldset>';
860
861
		// Some javascript for the advanced toggling
862
		echo '
863
		<script>
864
			var oAdvancedPanelToggle = new smc_Toggle({
865
				bToggleEnabled: true,
866
				bCurrentlyCollapsed: true,
867
				aSwappableContainers: [
868
					\'advanced_panel_div\'
869
				],
870
				aSwapImages: [
871
					{
872
						sId: \'advanced_panel_toggle\',
873
						altExpanded: ', JavaScriptEscape($txt['hide']), ',
874
						altCollapsed: ', JavaScriptEscape($txt['show']), '
875
					}
876
				],
877
				aSwapLinks: [
878
					{
879
						sId: \'advanced_panel_link\',
880
						msgExpanded: ', JavaScriptEscape($txt['pm_search_choose_label']), ',
881
						msgCollapsed: ', JavaScriptEscape($txt['pm_search_choose_label']), '
882
					}
883
				]
884
			});
885
		</script>';
886
	}
887
888
	echo '
889
	</form>';
890
}
891
892
/**
893
 * Displays results from a PM search
894
 */
895
function template_search_results()
896
{
897
	global $context, $txt;
898
899
	echo '
900
		<div class="cat_bar">
901
			<h3 class="catbg">', $txt['pm_search_results'], '</h3>
902
		</div>
903
		<div class="roundframe noup">
904
			', sprintf($txt['pm_search_results_info'], $context['num_results'], sentence_list($context['search_in'])), '
905
		</div>
906
		<div class="pagesection">
907
			<div class="pagelinks">', $context['page_index'], '</div>
908
		</div>';
909
910
	// Complete results?
911
	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
912
		echo '
913
		<table class="table_grid">
914
			<thead>
915
				<tr class="title_bar">
916
					<th class="lefttext quarter_table">', $txt['date'], '</th>
917
					<th class="lefttext half_table">', $txt['subject'], '</th>
918
					<th class="lefttext quarter_table">', $txt['from'], '</th>
919
				</tr>
920
			</thead>
921
			<tbody>';
922
923
	// Print each message out...
924
	foreach ($context['personal_messages'] as $message)
925
	{
926
		// Are we showing it all?
927
		if (!empty($context['search_params']['show_complete']))
928
			template_single_pm($message);
929
930
		// Otherwise just a simple list!
931
		// @todo No context at all of the search?
932
		else
933
			echo '
934
				<tr class="windowbg">
935
					<td>', $message['time'], '</td>
936
					<td>', $message['link'], '</td>
937
					<td>', $message['member']['link'], '</td>
938
				</tr>';
939
	}
940
941
	// Finish off the page...
942
	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
943
		echo '
944
			</tbody>
945
		</table>';
946
947
	// No results?
948
	if (empty($context['personal_messages']))
949
		echo '
950
		<div class="windowbg">
951
			<p class="centertext">', $txt['pm_search_none_found'], '</p>
952
		</div>';
953
954
	echo '
955
		<div class="pagesection">
956
			<div class="pagelinks">', $context['page_index'], '</div>
957
		</div>';
958
959
}
960
961
/**
962
 * The form for sending a new PM
963
 */
964
function template_send()
965
{
966
	global $context, $options, $scripturl, $modSettings, $txt;
967
968
	// Show which messages were sent successfully and which failed.
969
	if (!empty($context['send_log']))
970
	{
971
		echo '
972
		<div class="cat_bar">
973
			<h3 class="catbg">', $txt['pm_send_report'], '</h3>
974
		</div>
975
		<div class="windowbg noup">';
976
977
		if (!empty($context['send_log']['sent']))
978
			foreach ($context['send_log']['sent'] as $log_entry)
979
				echo '
980
			<span class="error">', $log_entry, '</span><br>';
981
982
		if (!empty($context['send_log']['failed']))
983
			foreach ($context['send_log']['failed'] as $log_entry)
984
				echo '
985
			<span class="error">', $log_entry, '</span><br>';
986
987
		echo '
988
		</div>
989
		<br>';
990
	}
991
992
	// Show the preview of the personal message.
993
	echo '
994
		<div id="preview_section"', isset($context['preview_message']) ? '' : ' class="hidden"', '>
995
			<div class="cat_bar">
996
				<h3 class="catbg">
997
					<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
998
				</h3>
999
			</div>
1000
			<div class="windowbg noup">
1001
				<div class="post" id="preview_body">
1002
					', empty($context['preview_message']) ? '<br>' : $context['preview_message'], '
1003
				</div>
1004
			</div>
1005
			<br class="clear">
1006
		</div>';
1007
1008
	// Main message editing box.
1009
	echo '
1010
		<form action="', $scripturl, '?action=pm;sa=send2" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="submitonce(this);">
1011
			<div class="cat_bar">
1012
				<h3 class="catbg">
1013
					<span class="main_icons inbox icon" title="', $txt['new_message'], '"></span> ', $txt['new_message'], '
1014
				</h3>
1015
			</div>
1016
			<div class="roundframe noup">';
1017
1018
	// If there were errors for sending the PM, show them.
1019
	echo '
1020
				<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '', empty($context['post_error']['messages']) ? ' hidden' : '', '" id="errors">
1021
					<dl>
1022
						<dt>
1023
							<strong id="error_serious">', $txt['error_while_submitting'], '</strong>
1024
						</dt>
1025
						<dd class="error" id="error_list">
1026
							', empty($context['post_error']['messages']) ? '' : implode('<br>', $context['post_error']['messages']), '
1027
						</dd>
1028
					</dl>
1029
				</div>';
1030
1031
	if (!empty($modSettings['drafts_pm_enabled']))
1032
		echo '
1033
				<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
1034
					sprintf($txt['draft_pm_saved'], $scripturl . '?action=pm;sa=showpmdrafts'), '
1035
					', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
1036
				</div>';
1037
1038
	echo '
1039
				<dl id="post_header">';
1040
1041
	// To and bcc. Include a button to search for members.
1042
	echo '
1043
					<dt>
1044
						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' class="error"' : ''), ' id="caption_to">', $txt['pm_to'], ':</span>
1045
					</dt>';
1046
1047
	// Autosuggest will be added by the JavaScript later on.
1048
	echo '
1049
					<dd id="pm_to" class="clear_right">
1050
						<input type="text" name="to" id="to_control" value="', $context['to_value'], '" tabindex="', $context['tabindex']++, '" size="20">';
1051
1052
	// A link to add BCC, only visible with JavaScript enabled.
1053
	echo '
1054
						<span class="smalltext" id="bcc_link_container" style="display: none;"></span>';
1055
1056
	// A div that'll contain the items found by the autosuggest.
1057
	echo '
1058
						<div id="to_item_list_container"></div>';
1059
1060
	echo '
1061
					</dd>';
1062
1063
	// This BCC row will be hidden by default if JavaScript is enabled.
1064
	echo '
1065
					<dt  class="clear_left" id="bcc_div">
1066
						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_bcc']) ? ' class="error"' : ''), ' id="caption_bbc">', $txt['pm_bcc'], ':</span>
1067
					</dt>
1068
					<dd id="bcc_div2">
1069
						<input type="text" name="bcc" id="bcc_control" value="', $context['bcc_value'], '" tabindex="', $context['tabindex']++, '" size="20">
1070
						<div id="bcc_item_list_container"></div>
1071
					</dd>';
1072
1073
	// The subject of the PM.
1074
	echo '
1075
					<dt class="clear_left">
1076
						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
1077
					</dt>
1078
					<dd id="pm_subject">
1079
						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="80"', isset($context['post_error']['no_subject']) ? ' class="error"' : '', '>
1080
					</dd>
1081
				</dl>';
1082
1083
	// Show BBC buttons, smileys and textbox.
1084
	echo '
1085
				', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
0 ignored issues
show
'smileyBox_message' of type string is incompatible with the type boolean|null expected by parameter $smileyContainer of template_control_richedit(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1085
				', template_control_richedit($context['post_box_name'], /** @scrutinizer ignore-type */ 'smileyBox_message', 'bbcBox_message');
Loading history...
'bbcBox_message' of type string is incompatible with the type boolean|null expected by parameter $bbcContainer of template_control_richedit(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1085
				', template_control_richedit($context['post_box_name'], 'smileyBox_message', /** @scrutinizer ignore-type */ 'bbcBox_message');
Loading history...
Are you sure the usage of template_control_richedi...age', 'bbcBox_message') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1086
1087
	// If the admin enabled the pm drafts feature, show a draft selection box
1088
	if (!empty($context['drafts_pm_save']) && !empty($context['drafts']) && !empty($options['drafts_show_saved_enabled']))
1089
	{
1090
		echo '
1091
				<div id="post_draft_options_header" class="title_bar">
1092
					<h4 class="titlebg">
1093
						<span id="postDraftExpand" class="toggle_up floatright" style="display: none;"></span> <strong><a href="#" id="postDraftExpandLink">', $txt['drafts_show'], '</a></strong>
1094
					</h4>
1095
				</div>
1096
				<div id="post_draft_options">
1097
					<dl class="settings">
1098
						<dt><strong>', $txt['subject'], '</strong></dt>
1099
						<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
1100
1101
		foreach ($context['drafts'] as $draft)
1102
			echo '
1103
						<dt>', $draft['link'], '</dt>
1104
						<dd>', $draft['poster_time'], '</dd>';
1105
		echo '
1106
					</dl>
1107
				</div>';
1108
	}
1109
1110
	// Require an image to be typed to save spamming?
1111
	if ($context['require_verification'])
1112
		echo '
1113
				<div class="post_verification">
1114
					<strong>', $txt['pm_visual_verification_label'], ':</strong>
1115
					', template_control_verification($context['visual_verification_id'], 'all'), '
1116
				</div>';
1117
1118
	// Send, Preview, spellcheck buttons.
1119
	echo '
1120
				<span id="post_confirm_buttons">
1121
					', template_control_richedit_buttons($context['post_box_name']), '
0 ignored issues
show
Are you sure the usage of template_control_richedi...ntext['post_box_name']) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1122
				</span>
1123
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1124
				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
1125
				<input type="hidden" name="replied_to" value="', !empty($context['quoted_message']['id']) ? $context['quoted_message']['id'] : 0, '">
1126
				<input type="hidden" name="pm_head" value="', !empty($context['quoted_message']['pm_head']) ? $context['quoted_message']['pm_head'] : 0, '">
1127
				<input type="hidden" name="f" value="', isset($context['folder']) ? $context['folder'] : '', '">
1128
				<input type="hidden" name="l" value="', isset($context['current_label_id']) ? $context['current_label_id'] : -1, '">
1129
				<br class="clear_right">
1130
			</div><!-- .roundframe -->
1131
		</form>';
1132
1133
	echo '
1134
		<script>';
1135
1136
	// The functions used to preview a personal message without loading a new page.
1137
	echo '
1138
			var txt_preview_title = "', $txt['preview_title'], '";
1139
			var txt_preview_fetch = "', $txt['preview_fetch'], '";
1140
			function previewPost()
1141
			{
1142
				if (window.XMLHttpRequest)
1143
				{
1144
					// Opera didn\'t support setRequestHeader() before 8.01.
1145
					// @todo Remove support for old browsers
1146
					if (\'opera\' in window)
1147
					{
1148
						var test = new XMLHttpRequest();
1149
						if (!(\'setRequestHeader\' in test))
1150
							return submitThisOnce(document.forms.postmodify);
1151
					}
1152
					// @todo Currently not sending poll options and option checkboxes.
1153
					var x = new Array();
1154
					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'to\', \'bcc\'];
1155
					var numericFields = [\'recipient_to[]\', \'recipient_bcc[]\'];
1156
					var checkboxFields = [];
1157
1158
					for (var i = 0, n = textFields.length; i < n; i++)
1159
						if (textFields[i] in document.forms.postmodify)
1160
						{
1161
							// Handle the WYSIWYG editor.
1162
							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
1163
								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).php_to8bit().php_urlencode();
1164
							else
1165
								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.php_to8bit().php_urlencode();
1166
						}
1167
					for (var i = 0, n = numericFields.length; i < n; i++)
1168
						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
1169
							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
1170
					for (var i = 0, n = checkboxFields.length; i < n; i++)
1171
						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
1172
							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
1173
1174
					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=pm;sa=send2;preview;xml\', x.join(\'&\'), onDocSent);
1175
1176
					document.getElementById(\'preview_section\').style.display = \'\';
1177
					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
1178
					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
1179
1180
					return false;
1181
				}
1182
				else
1183
					return submitThisOnce(document.forms.postmodify);
1184
			}
1185
			function onDocSent(XMLDoc)
1186
			{
1187
				if (!XMLDoc)
1188
				{
1189
					document.forms.postmodify.preview.onclick = new function ()
1190
					{
1191
						return true;
1192
					}
1193
					document.forms.postmodify.preview.click();
1194
				}
1195
1196
				// Show the preview section.
1197
				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
1198
				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
1199
1200
				var bodyText = \'\';
1201
				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
1202
					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
1203
1204
				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
1205
				document.getElementById(\'preview_body\').className = \'post\';
1206
1207
				// Show a list of errors (if any).
1208
				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
1209
				var errorList = new Array();
1210
				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
1211
					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
1212
				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
1213
				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br>\'));
1214
1215
				// Adjust the color of captions if the given data is erroneous.
1216
				var captions = errors.getElementsByTagName(\'caption\');
1217
				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
1218
					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
1219
						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
1220
1221
				if (errors.getElementsByTagName(\'post_error\').length == 1)
1222
					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
1223
				else if (document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
1224
				{
1225
					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
1226
						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
1227
					else
1228
						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
1229
				}
1230
				location.hash = \'#\' + \'preview_section\';
1231
			}';
1232
1233
	// Code for showing and hiding drafts
1234
	if (!empty($context['drafts']))
1235
		echo '
1236
			var oSwapDraftOptions = new smc_Toggle({
1237
				bToggleEnabled: true,
1238
				bCurrentlyCollapsed: true,
1239
				aSwappableContainers: [
1240
					\'post_draft_options\',
1241
				],
1242
				aSwapImages: [
1243
					{
1244
						sId: \'postDraftExpand\',
1245
						altExpanded: \'-\',
1246
						altCollapsed: \'+\'
1247
					}
1248
				],
1249
				aSwapLinks: [
1250
					{
1251
						sId: \'postDraftExpandLink\',
1252
						msgExpanded: ', JavaScriptEscape($txt['draft_hide']), ',
1253
						msgCollapsed: ', JavaScriptEscape($txt['drafts_show']), '
1254
					}
1255
				]
1256
			});';
1257
1258
	echo '
1259
		</script>';
1260
1261
	// Show the message you're replying to.
1262
	if ($context['reply'])
1263
		echo '
1264
		<br><br>
1265
		<div class="cat_bar">
1266
			<h3 class="catbg">', $txt['subject'], ': ', $context['quoted_message']['subject'], '</h3>
1267
		</div>
1268
		<div class="windowbg">
1269
			<div class="clear">
1270
				<span class="smalltext floatright">', $txt['on'], ': ', $context['quoted_message']['time'], '</span>
1271
				<strong>', $txt['from'], ': ', $context['quoted_message']['member']['name'], '</strong>
1272
			</div>
1273
			<hr>
1274
			', $context['quoted_message']['body'], '
1275
		</div>
1276
		<br class="clear">';
1277
1278
	echo '
1279
		<script>
1280
			var oPersonalMessageSend = new smf_PersonalMessageSend({
1281
				sSelf: \'oPersonalMessageSend\',
1282
				sSessionId: smf_session_id,
1283
				sSessionVar: smf_session_var,
1284
				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
1285
				sToControlId: \'to_control\',
1286
				aToRecipients: [';
1287
1288
	foreach ($context['recipients']['to'] as $i => $member)
1289
		echo '
1290
					{
1291
						sItemId: ', JavaScriptEscape($member['id']), ',
1292
						sItemName: ', JavaScriptEscape($member['name']), '
1293
					}', $i == count($context['recipients']['to']) - 1 ? '' : ',';
1294
1295
	echo '
1296
				],
1297
				aBccRecipients: [';
1298
1299
	foreach ($context['recipients']['bcc'] as $i => $member)
1300
		echo '
1301
					{
1302
						sItemId: ', JavaScriptEscape($member['id']), ',
1303
						sItemName: ', JavaScriptEscape($member['name']), '
1304
					}', $i == count($context['recipients']['bcc']) - 1 ? '' : ',';
1305
1306
	echo '
1307
				],
1308
				sBccControlId: \'bcc_control\',
1309
				sBccDivId: \'bcc_div\',
1310
				sBccDivId2: \'bcc_div2\',
1311
				sBccLinkId: \'bcc_link\',
1312
				sBccLinkContainerId: \'bcc_link_container\',
1313
				bBccShowByDefault: ', empty($context['recipients']['bcc']) && empty($context['bcc_value']) ? 'false' : 'true', ',
1314
				sShowBccLinkTemplate: ', JavaScriptEscape('
1315
					<a href="#" id="bcc_link">' . $txt['make_bcc'] . '</a> <a href="' . $scripturl . '?action=helpadmin;help=pm_bcc" onclick="return reqOverlayDiv(this.href);">(?)</a>'
1316
				), '
1317
			});';
1318
1319
	echo '
1320
		</script>';
1321
}
1322
1323
/**
1324
 * This template asks the user whether they wish to empty out their folder/messages.
1325
 */
1326
function template_ask_delete()
1327
{
1328
	global $context, $scripturl, $txt;
1329
1330
	echo '
1331
		<div class="cat_bar">
1332
			<h3 class="catbg">
1333
				', ($context['delete_all'] ? $txt['delete_message'] : $txt['delete_all']), '
1334
			</h3>
1335
		</div>
1336
		<div class="windowbg">
1337
			<p>', $txt['delete_all_confirm'], '</p>
1338
			<br>
1339
			<strong><a href="', $scripturl, '?action=pm;sa=removeall2;f=', $context['folder'], ';', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="javascript:history.go(-1);">', $txt['no'], '</a></strong>
1340
		</div>';
1341
}
1342
1343
/**
1344
 * This template asks the user what messages they want to prune.
1345
 */
1346
function template_prune()
1347
{
1348
	global $context, $scripturl, $txt;
1349
1350
	echo '
1351
		<div class="cat_bar">
1352
			<h3 class="catbg">', $txt['pm_prune'], '</h3>
1353
		</div>
1354
		<div class="windowbg">
1355
			<form action="', $scripturl, '?action=pm;sa=prune" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['pm_prune_warning'], '\');">
1356
				<p>', $txt['pm_prune_desc1'], ' <input type="text" name="age" size="3" value="14"> ', $txt['pm_prune_desc2'], '</p>
1357
				<input type="submit" value="', $txt['delete'], '" class="button">
1358
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1359
			</form>
1360
		</div>
1361
		<div class="windowbg">
1362
			<form action="', $scripturl, '?action=pm;sa=removeall2" method="post" onsubmit="return confirm(\'', $txt['pm_remove_all_warning'], '\');">
1363
				<p>', $txt['pm_remove_all'], '</p>
1364
				<input type="submit" value="', $txt['delete_all_prune'], '" class="button">
1365
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1366
			</form>
1367
		</div>';
1368
}
1369
1370
/**
1371
 * Here we allow the user to setup labels, remove labels and change rules for labels (i.e, do quite a bit)
1372
 */
1373
function template_labels()
1374
{
1375
	global $context, $scripturl, $txt;
1376
1377
	echo '
1378
	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
1379
		<div class="cat_bar">
1380
			<h3 class="catbg">', $txt['pm_manage_labels'], '</h3>
1381
		</div>
1382
		<div class="information">
1383
			', $txt['pm_labels_desc'], '
1384
		</div>
1385
		<table class="table_grid">
1386
			<thead>
1387
				<tr class="title_bar">
1388
					<th class="lefttext">
1389
						', $txt['pm_label_name'], '
1390
					</th>
1391
					<th class="centertext table_icon">';
1392
1393
	if (count($context['labels']) > 2)
1394
		echo '
1395
						<input type="checkbox" onclick="invertAll(this, this.form);">';
1396
1397
	echo '
1398
					</th>
1399
				</tr>
1400
			</thead>
1401
			<tbody>';
1402
	if (count($context['labels']) < 2)
1403
		echo '
1404
				<tr class="windowbg">
1405
					<td colspan="2">', $txt['pm_labels_no_exist'], '</td>
1406
				</tr>';
1407
	else
1408
	{
1409
		foreach ($context['labels'] as $label)
1410
		{
1411
			if ($label['id'] == -1)
1412
				continue;
1413
1414
			echo '
1415
				<tr class="windowbg">
1416
					<td>
1417
						<input type="text" name="label_name[', $label['id'], ']" value="', $label['name'], '" size="30" maxlength="30">
1418
					</td>
1419
					<td class="table_icon"><input type="checkbox" name="delete_label[', $label['id'], ']"></td>
1420
				</tr>';
1421
		}
1422
	}
1423
	echo '
1424
			</tbody>
1425
		</table>';
1426
1427
	if (!count($context['labels']) < 2)
1428
		echo '
1429
		<div class="block righttext">
1430
			<input type="submit" name="save" value="', $txt['save'], '" class="button">
1431
			<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" data-confirm="', $txt['pm_labels_delete'], '" class="button you_sure">
1432
		</div>';
1433
1434
	echo '
1435
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1436
	</form>
1437
	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
1438
		<div class="cat_bar">
1439
			<h3 class="catbg">', $txt['pm_label_add_new'], '</h3>
1440
		</div>
1441
		<div class="windowbg">
1442
			<dl class="settings">
1443
				<dt>
1444
					<strong><label for="add_label">', $txt['pm_label_name'], '</label>:</strong>
1445
				</dt>
1446
				<dd>
1447
					<input type="text" id="add_label" name="label" value="" size="30" maxlength="30">
1448
				</dd>
1449
			</dl>
1450
			<input type="submit" name="add" value="', $txt['pm_label_add_new'], '" class="button floatright">
1451
		</div>
1452
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1453
	</form>
1454
	<br>';
1455
}
1456
1457
/**
1458
 * Template for reporting a personal message.
1459
 */
1460
function template_report_message()
1461
{
1462
	global $context, $txt, $scripturl;
1463
1464
	echo '
1465
	<form action="', $scripturl, '?action=pm;sa=report;l=', $context['current_label_id'], '" method="post" accept-charset="', $context['character_set'], '">
1466
		<input type="hidden" name="pmsg" value="', $context['pm_id'], '">
1467
		<div class="information">
1468
			', $txt['pm_report_desc'], '
1469
		</div>
1470
		<div class="cat_bar">
1471
			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
1472
		</div>
1473
		<div class="windowbg">
1474
			<dl class="settings">';
1475
1476
	// If there is more than one admin on the forum, allow the user to choose the one they want to direct to.
1477
	// @todo Why?
1478
	if ($context['admin_count'] > 1)
1479
	{
1480
		echo '
1481
				<dt>
1482
					<strong>', $txt['pm_report_admins'], ':</strong>
1483
				</dt>
1484
				<dd>
1485
					<select name="id_admin">
1486
						<option value="0">', $txt['pm_report_all_admins'], '</option>';
1487
1488
		foreach ($context['admins'] as $id => $name)
1489
			echo '
1490
						<option value="', $id, '">', $name, '</option>';
1491
1492
		echo '
1493
					</select>
1494
				</dd>';
1495
	}
1496
1497
	echo '
1498
				<dt>
1499
					<strong>', $txt['pm_report_reason'], ':</strong>
1500
				</dt>
1501
				<dd>
1502
					<textarea name="reason" rows="4" cols="70" style="width: 80%;"></textarea>
1503
				</dd>
1504
			</dl>
1505
			<div class="righttext">
1506
				<input type="submit" name="report" value="', $txt['pm_report_message'], '" class="button">
1507
			</div>
1508
		</div><!-- .windowbg -->
1509
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1510
	</form>';
1511
}
1512
1513
/**
1514
 * Little template just to say "Yep, it's been submitted"
1515
 */
1516
function template_report_message_complete()
1517
{
1518
	global $context, $txt, $scripturl;
1519
1520
	echo '
1521
		<div class="cat_bar">
1522
			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
1523
		</div>
1524
		<div class="windowbg">
1525
			<p>', $txt['pm_report_done'], '</p>
1526
			<a href="', $scripturl, '?action=pm;l=', $context['current_label_id'], '">', $txt['pm_report_return'], '</a>
1527
		</div>';
1528
}
1529
1530
/**
1531
 * Manage rules.
1532
 */
1533
function template_rules()
1534
{
1535
	global $context, $txt, $scripturl;
1536
1537
	echo '
1538
	<form action="', $scripturl, '?action=pm;sa=manrules" method="post" accept-charset="', $context['character_set'], '" name="manRules" id="manrules">
1539
		<div class="cat_bar">
1540
			<h3 class="catbg">', $txt['pm_manage_rules'], '</h3>
1541
		</div>
1542
		<div class="information">
1543
			', $txt['pm_manage_rules_desc'], '
1544
		</div>
1545
		<table class="table_grid">
1546
			<thead>
1547
				<tr class="title_bar">
1548
					<th class="lefttext">
1549
						', $txt['pm_rule_title'], '
1550
					</th>
1551
					<th class="centertext table_icon">';
1552
1553
	if (!empty($context['rules']))
1554
		echo '
1555
						<input type="checkbox" onclick="invertAll(this, this.form);">';
1556
1557
	echo '
1558
					</th>
1559
				</tr>
1560
			</thead>
1561
			<tbody>';
1562
1563
	if (empty($context['rules']))
1564
		echo '
1565
				<tr class="windowbg">
1566
					<td colspan="2">
1567
						', $txt['pm_rules_none'], '
1568
					</td>
1569
				</tr>';
1570
1571
	foreach ($context['rules'] as $rule)
1572
		echo '
1573
				<tr class="windowbg">
1574
					<td>
1575
						<a href="', $scripturl, '?action=pm;sa=manrules;add;rid=', $rule['id'], '">', $rule['name'], '</a>
1576
					</td>
1577
					<td class="table_icon">
1578
						<input type="checkbox" name="delrule[', $rule['id'], ']">
1579
					</td>
1580
				</tr>';
1581
1582
	echo '
1583
			</tbody>
1584
		</table>
1585
		<div class="righttext">
1586
			<a class="button" href="', $scripturl, '?action=pm;sa=manrules;add;rid=0">', $txt['pm_add_rule'], '</a>';
1587
1588
	if (!empty($context['rules']))
1589
		echo '
1590
			[<a href="', $scripturl, '?action=pm;sa=manrules;apply;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['pm_js_apply_rules_confirm'], '\');">', $txt['pm_apply_rules'], '</a>]';
1591
1592
	if (!empty($context['rules']))
1593
		echo '
1594
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1595
			<input type="submit" name="delselected" value="', $txt['pm_delete_selected_rule'], '" data-confirm="', $txt['pm_js_delete_rule_confirm'], '" class="button smalltext you_sure">';
1596
1597
	echo '
1598
		</div>
1599
	</form>';
1600
1601
}
1602
1603
/**
1604
 * Template for adding/editing a rule.
1605
 */
1606
function template_add_rule()
1607
{
1608
	global $context, $txt, $scripturl;
1609
1610
	echo '
1611
	<script>
1612
		var criteriaNum = 0;
1613
		var actionNum = 0;
1614
		var groups = new Array()
1615
		var labels = new Array()';
1616
1617
	foreach ($context['groups'] as $id => $title)
1618
		echo '
1619
		groups[', $id, '] = "', addslashes($title), '";';
1620
1621
	foreach ($context['labels'] as $label)
1622
		if ($label['id'] != -1)
1623
			echo '
1624
		labels[', ($label['id']), '] = "', addslashes($label['name']), '";';
1625
1626
	echo '
1627
		function addCriteriaOption()
1628
		{
1629
			if (criteriaNum == 0)
1630
			{
1631
				for (var i = 0; i < document.forms.addrule.elements.length; i++)
1632
					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
1633
						criteriaNum++;
1634
			}
1635
1636
			if (criteriaNum++ >= ', $context['rule_limiters']['criteria'], ')
1637
				return false;
1638
1639
			setOuterHTML(document.getElementById("criteriaAddHere"), \'<br><select name="ruletype[\' + criteriaNum + \']" id="ruletype\' + criteriaNum + \'" onchange="updateRuleDef(\' + criteriaNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_criteria_pick']), ':<\' + \'/option><option value="mid">', addslashes($txt['pm_rule_mid']), '<\' + \'/option><option value="gid">', addslashes($txt['pm_rule_gid']), '<\' + \'/option><option value="sub">', addslashes($txt['pm_rule_sub']), '<\' + \'/option><option value="msg">', addslashes($txt['pm_rule_msg']), '<\' + \'/option><option value="bud">', addslashes($txt['pm_rule_bud']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="defdiv\' + criteriaNum + \'" style="display: none;"><input type="text" name="ruledef[\' + criteriaNum + \']" id="ruledef\' + criteriaNum + \'" onkeyup="rebuildRuleDesc();" value=""><\' + \'/span><span id="defseldiv\' + criteriaNum + \'" style="display: none;"><select name="ruledefgroup[\' + criteriaNum + \']" id="ruledefgroup\' + criteriaNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_group']), '<\' + \'/option>';
1640
1641
	foreach ($context['groups'] as $id => $group)
1642
		echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>';
1643
1644
	echo '<\' + \'/select><\' + \'/span><span id="criteriaAddHere"><\' + \'/span>\');
1645
1646
				if (criteriaNum + 1 > ', $context['rule_limiters']['criteria'], ')
1647
					document.getElementById(\'addonjs1\').style.display = \'none\';
1648
			}
1649
1650
			function addActionOption()
1651
			{
1652
				if (actionNum == 0)
1653
				{
1654
					for (var i = 0; i < document.forms.addrule.elements.length; i++)
1655
						if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
1656
							actionNum++;
1657
				}
1658
				if (actionNum++ >= ', $context['rule_limiters']['actions'], ')
1659
					return false;
1660
1661
				setOuterHTML(document.getElementById("actionAddHere"), \'<br><select name="acttype[\' + actionNum + \']" id="acttype\' + actionNum + \'" onchange="updateActionDef(\' + actionNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_action']), ':<\' + \'/option><option value="lab">', addslashes($txt['pm_rule_label']), '<\' + \'/option><option value="del">', addslashes($txt['pm_rule_delete']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="labdiv\' + actionNum + \'" style="display: none;"><select name="labdef[\' + actionNum + \']" id="labdef\' + actionNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_label']), '<\' + \'/option>';
1662
1663
	foreach ($context['labels'] as $label)
1664
		if ($label['id'] != -1)
1665
			echo '<option value="', ($label['id']), '">', addslashes($label['name']), '<\' + \'/option>';
1666
1667
	echo '<\' + \'/select><\' + \'/span><span id="actionAddHere"><\' + \'/span>\');
1668
1669
				if (actionNum + 1 > ', $context['rule_limiters']['actions'], ')
1670
					document.getElementById(\'addonjs2\').style.display = \'none\';
1671
			}
1672
1673
			// Rebuild the rule description!
1674
			function rebuildRuleDesc()
1675
			{
1676
				// Start with nothing.
1677
				var text = "";
1678
				var joinText = "";
1679
				var actionText = "";
1680
				var hadBuddy = false;
1681
				var foundCriteria = false;
1682
				var foundAction = false;
1683
				var curNum, curVal, curDef;
1684
1685
				for (var i = 0; i < document.forms.addrule.elements.length; i++)
1686
				{
1687
					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
1688
					{
1689
						if (foundCriteria)
1690
							joinText = document.getElementById("logic").value == \'and\' ? ', JavaScriptEscape(' <em>' . $txt['pm_readable_and'] . '</em> '), ' : ', JavaScriptEscape(' <em>' . $txt['pm_readable_or'] . '</em> '), ';
1691
						else
1692
							joinText = \'\';
1693
						foundCriteria = true;
1694
1695
						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
1696
						curVal = document.forms.addrule.elements[i].value;
1697
						if (curVal == "gid")
1698
							curDef = document.getElementById("ruledefgroup" + curNum).value.php_htmlspecialchars();
1699
						else if (curVal != "bud")
1700
							curDef = document.getElementById("ruledef" + curNum).value.php_htmlspecialchars();
1701
						else
1702
							curDef = "";
1703
1704
						// What type of test is this?
1705
						if (curVal == "mid" && curDef)
1706
							text += joinText + ', JavaScriptEscape($txt['pm_readable_member']), '.replace("{MEMBER}", curDef);
1707
						else if (curVal == "gid" && curDef && groups[curDef])
1708
							text += joinText + ', JavaScriptEscape($txt['pm_readable_group']), '.replace("{GROUP}", groups[curDef]);
1709
						else if (curVal == "sub" && curDef)
1710
							text += joinText + ', JavaScriptEscape($txt['pm_readable_subject']), '.replace("{SUBJECT}", curDef);
1711
						else if (curVal == "msg" && curDef)
1712
							text += joinText + ', JavaScriptEscape($txt['pm_readable_body']), '.replace("{BODY}", curDef);
1713
						else if (curVal == "bud" && !hadBuddy)
1714
						{
1715
							text += joinText + ', JavaScriptEscape($txt['pm_readable_buddy']), ';
1716
							hadBuddy = true;
1717
						}
1718
					}
1719
					if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
1720
					{
1721
						if (foundAction)
1722
							joinText = ', JavaScriptEscape(' <em>' . $txt['pm_readable_and'] . '</em> '), ';
1723
						else
1724
							joinText = "";
1725
						foundAction = true;
1726
1727
						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
1728
						curVal = document.forms.addrule.elements[i].value;
1729
						if (curVal == "lab")
1730
							curDef = document.getElementById("labdef" + curNum).value.php_htmlspecialchars();
1731
						else
1732
							curDef = "";
1733
1734
						// Now pick the actions.
1735
						if (curVal == "lab" && curDef && labels[curDef])
1736
							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_label']), '.replace("{LABEL}", labels[curDef]);
1737
						else if (curVal == "del")
1738
							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_delete']), ';
1739
					}
1740
				}
1741
1742
				// If still nothing make it default!
1743
				if (text == "" || !foundCriteria)
1744
					text = "', $txt['pm_rule_not_defined'], '";
1745
				else
1746
				{
1747
					if (actionText != "")
1748
						text += ', JavaScriptEscape(' <strong>' . $txt['pm_readable_then'] . '</strong> '), ' + actionText;
1749
					text = ', JavaScriptEscape($txt['pm_readable_start']), ' + text + ', JavaScriptEscape($txt['pm_readable_end']), ';
1750
				}
1751
1752
				// Set the actual HTML!
1753
				setInnerHTML(document.getElementById("ruletext"), text);
1754
			}
1755
	</script>';
1756
1757
	echo '
1758
	<form action="', $scripturl, '?action=pm;sa=manrules;save;rid=', $context['rid'], '" method="post" accept-charset="', $context['character_set'], '" name="addrule" id="addrule" class="flow_hidden">
1759
		<div class="cat_bar">
1760
			<h3 class="catbg">', $context['rid'] == 0 ? $txt['pm_add_rule'] : $txt['pm_edit_rule'], '</h3>
1761
		</div>
1762
		<div class="windowbg">
1763
			<dl class="addrules">
1764
				<dt class="floatleft">
1765
					<strong>', $txt['pm_rule_name'], ':</strong><br>
1766
					<span class="smalltext">', $txt['pm_rule_name_desc'], '</span>
1767
				</dt>
1768
				<dd class="floatleft">
1769
					<input type="text" name="rule_name" value="', empty($context['rule']['name']) ? $txt['pm_rule_name_default'] : $context['rule']['name'], '" size="50">
1770
				</dd>
1771
			</dl>
1772
			<fieldset>
1773
				<legend>', $txt['pm_rule_criteria'], '</legend>';
1774
1775
	// Add a dummy criteria to allow expansion for none js users.
1776
	$context['rule']['criteria'][] = array('t' => '', 'v' => '');
1777
1778
	// For each criteria print it out.
1779
	$isFirst = true;
1780
	foreach ($context['rule']['criteria'] as $k => $criteria)
1781
	{
1782
		if (!$isFirst && $criteria['t'] == '')
1783
			echo '<div id="removeonjs1">';
1784
1785
		elseif (!$isFirst)
1786
			echo '<br>';
1787
1788
		echo '
1789
				<select name="ruletype[', $k, ']" id="ruletype', $k, '" onchange="updateRuleDef(', $k, '); rebuildRuleDesc();">
1790
					<option value="">', $txt['pm_rule_criteria_pick'], ':</option>';
1791
1792
		foreach (array('mid', 'gid', 'sub', 'msg', 'bud') as $cr)
1793
			echo '
1794
					<option value="', $cr, '"', $criteria['t'] == $cr ? ' selected' : '', '>', $txt['pm_rule_' . $cr], '</option>';
1795
1796
		echo '
1797
				</select>
1798
				<span id="defdiv', $k, '" ', !in_array($criteria['t'], array('gid', 'bud')) ? '' : 'style="display: none;"', '>
1799
					<input type="text" name="ruledef[', $k, ']" id="ruledef', $k, '" onkeyup="rebuildRuleDesc();" value="', in_array($criteria['t'], array('mid', 'sub', 'msg')) ? $criteria['v'] : '', '">
1800
				</span>
1801
				<span id="defseldiv', $k, '" ', $criteria['t'] == 'gid' ? '' : 'style="display: none;"', '>
1802
					<select name="ruledefgroup[', $k, ']" id="ruledefgroup', $k, '" onchange="rebuildRuleDesc();">
1803
						<option value="">', $txt['pm_rule_sel_group'], '</option>';
1804
1805
		foreach ($context['groups'] as $id => $group)
1806
			echo '
1807
						<option value="', $id, '"', $criteria['t'] == 'gid' && $criteria['v'] == $id ? ' selected' : '', '>', $group, '</option>';
1808
		echo '
1809
					</select>
1810
				</span>';
1811
1812
		// If this is the dummy we add a means to hide for non js users.
1813
		if ($isFirst)
1814
			$isFirst = false;
1815
1816
		elseif ($criteria['t'] == '')
1817
			echo '</div><!-- .removeonjs1 -->';
1818
	}
1819
1820
	echo '
1821
				<span id="criteriaAddHere"></span><br>
1822
				<a href="#" onclick="addCriteriaOption(); return false;" id="addonjs1" style="display: none;">(', $txt['pm_rule_criteria_add'], ')</a>
1823
				<br><br>
1824
				', $txt['pm_rule_logic'], ':
1825
				<select name="rule_logic" id="logic" onchange="rebuildRuleDesc();">
1826
					<option value="and"', $context['rule']['logic'] == 'and' ? ' selected' : '', '>', $txt['pm_rule_logic_and'], '</option>
1827
					<option value="or"', $context['rule']['logic'] == 'or' ? ' selected' : '', '>', $txt['pm_rule_logic_or'], '</option>
1828
				</select>
1829
			</fieldset>
1830
			<fieldset>
1831
				<legend>', $txt['pm_rule_actions'], '</legend>';
1832
1833
	// As with criteria - add a dummy action for "expansion".
1834
	$context['rule']['actions'][] = array('t' => '', 'v' => '');
1835
1836
	// Print each action.
1837
	$isFirst = true;
1838
	foreach ($context['rule']['actions'] as $k => $action)
1839
	{
1840
		if (!$isFirst && $action['t'] == '')
1841
			echo '<div id="removeonjs2">';
1842
		elseif (!$isFirst)
1843
			echo '<br>';
1844
1845
		echo '
1846
				<select name="acttype[', $k, ']" id="acttype', $k, '" onchange="updateActionDef(', $k, '); rebuildRuleDesc();">
1847
					<option value="">', $txt['pm_rule_sel_action'], ':</option>
1848
					<option value="lab"', $action['t'] == 'lab' ? ' selected' : '', '>', $txt['pm_rule_label'], '</option>
1849
					<option value="del"', $action['t'] == 'del' ? ' selected' : '', '>', $txt['pm_rule_delete'], '</option>
1850
				</select>
1851
				<span id="labdiv', $k, '">
1852
					<select name="labdef[', $k, ']" id="labdef', $k, '" onchange="rebuildRuleDesc();">
1853
						<option value="">', $txt['pm_rule_sel_label'], '</option>';
1854
1855
		foreach ($context['labels'] as $label)
1856
			if ($label['id'] != -1)
1857
				echo '
1858
						<option value="', ($label['id']), '"', $action['t'] == 'lab' && $action['v'] == $label['id'] ? ' selected' : '', '>', $label['name'], '</option>';
1859
1860
		echo '
1861
					</select>
1862
				</span>';
1863
1864
		if ($isFirst)
1865
			$isFirst = false;
1866
1867
		elseif ($action['t'] == '')
1868
			echo '</div><!-- .removeonjs2 -->';
1869
	}
1870
1871
	echo '
1872
				<span id="actionAddHere"></span><br>
1873
				<a href="#" onclick="addActionOption(); return false;" id="addonjs2" style="display: none;">(', $txt['pm_rule_add_action'], ')</a>
1874
			</fieldset>
1875
			<div class="cat_bar">
1876
				<h3 class="catbg">', $txt['pm_rule_description'], '</h3>
1877
			</div>
1878
			<div class="information">
1879
				<div id="ruletext">', $txt['pm_rule_js_disabled'], '</div>
1880
			</div>
1881
			<div class="righttext">
1882
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1883
				<input type="submit" name="save" value="', $txt['pm_rule_save'], '" class="button">
1884
			</div>
1885
		</div><!-- .windowbg -->
1886
	</form>';
1887
1888
	// Now setup all the bits!
1889
	echo '
1890
	<script>';
1891
1892
	foreach ($context['rule']['criteria'] as $k => $c)
1893
		echo '
1894
			updateRuleDef(', $k, ');';
1895
1896
	foreach ($context['rule']['actions'] as $k => $c)
1897
		echo '
1898
			updateActionDef(', $k, ');';
1899
1900
	echo '
1901
			rebuildRuleDesc();';
1902
1903
	// If this isn't a new rule and we have JS enabled remove the JS compatibility stuff.
1904
	if ($context['rid'])
1905
		echo '
1906
			document.getElementById("removeonjs1").style.display = "none";
1907
			document.getElementById("removeonjs2").style.display = "none";';
1908
1909
	if (count($context['rule']['criteria']) <= $context['rule_limiters']['criteria'])
1910
		echo '
1911
			document.getElementById("addonjs1").style.display = "";';
1912
1913
	if (count($context['rule']['actions']) <= $context['rule_limiters']['actions'])
1914
		echo '
1915
			document.getElementById("addonjs2").style.display = "";';
1916
1917
	echo '
1918
		</script>';
1919
}
1920
1921
/**
1922
 * Template for showing all of a user's PM drafts.
1923
 */
1924
function template_showPMDrafts()
1925
{
1926
	global $context, $scripturl, $txt;
1927
1928
	echo '
1929
		<div class="cat_bar">
1930
			<h3 class="catbg">
1931
				<span class="main_icons inbox"></span> ', $txt['drafts_show'], '
1932
			</h3>
1933
		</div>
1934
		<p class="information">
1935
			', $txt['drafts_show_desc'], '
1936
		</p>';
1937
1938
	// No drafts? Just show an informative message.
1939
	if (empty($context['drafts']))
1940
		echo '
1941
		<div class="windowbg centertext">
1942
			', $txt['draft_none'], '
1943
		</div>';
1944
	else
1945
	{
1946
		echo '
1947
		<div class="pagesection">
1948
			<div class="pagelinks">', $context['page_index'], '</div>
1949
		</div>';
1950
1951
		// For every draft to be displayed, give it its own div, and show the important details of the draft.
1952
		foreach ($context['drafts'] as $draft)
1953
		{
1954
			echo '
1955
		<div class="windowbg">
1956
			<div class="page_number floatright"> #', $draft['counter'], '</div>
1957
			<div class="topic_details">
1958
				<h5>
1959
					<strong>', $draft['subject'], '</strong>
1960
				</h5>
1961
				<div class="smalltext">
1962
					<div class="recipient_to"><strong>', $txt['pm_to'], ':</strong> ', implode(', ', $draft['recipients']['to']), '</div>';
1963
1964
			if(!empty($draft['recipients']['bcc']))
1965
				echo'
1966
					<div class="pm_bbc"><strong>', $txt['pm_bcc'], ':</strong> ', implode(', ', $draft['recipients']['bcc']), '</div>';
1967
1968
			echo '
1969
				</div>
1970
				<div class="smalltext">
1971
					<strong>', $txt['draft_saved_on'], ':</strong> ', sprintf($txt['draft_days_ago'], $draft['age']), (!empty($draft['remaining']) ? ', ' . sprintf($txt['draft_retain'], $draft['remaining']) : ''), '
1972
				</div>
1973
			</div>
1974
			<div class="list_posts">
1975
				', $draft['body'], '
1976
			</div>';
1977
1978
			// Draft buttons
1979
			template_quickbuttons($draft['quickbuttons'], 'pm_drafts');
1980
1981
			echo '
1982
		</div><!-- .windowbg -->';
1983
		}
1984
1985
		// Show page numbers.
1986
		echo '
1987
		<div class="pagesection">
1988
			<div class="pagelinks">', $context['page_index'], '</div>
1989
		</div>';
1990
	}
1991
}
1992
1993
?>