Completed
Push — release-2.1 ( e077db...35b3d8 )
by Colin
07:37
created

PersonalMessage.template.php ➔ template_showPMDrafts()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 53
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 2
nop 0
dl 0
loc 53
rs 8.9849
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2017 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 Beta 4
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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
function template_pm_popup()
54
{
55
	global $context, $txt, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
56
57
	// Unlike almost every other template, this is designed to be included into the HTML directly via $().load()
58
	echo '
59
		<div class="pm_bar">
60
			<div class="pm_sending block">
61
				', $context['can_send_pm'] ? '<a href="' . $scripturl . '?action=pm;sa=send">' . $txt['pm_new_short'] . '</a> | ' : '', '
62
				', $context['can_draft'] ? '<a href="' . $scripturl . '?action=pm;sa=showpmdrafts">' . $txt['pm_drafts_short'] . '</a>' : '', '
63
				<a href="', $scripturl, '?action=pm;sa=settings" class="floatright">', $txt['pm_settings_short'], '</a>
64
			</div>
65
			<div class="pm_mailbox centertext">
66
				<a href="', $scripturl, '?action=pm" class="button">', $txt['inbox'], '</a>
67
			</div>
68
		</div>
69
		<div class="pm_unread">';
70
71
	if (empty($context['unread_pms']))
72
		echo '
73
			<div class="no_unread">', $txt['pm_no_unread'], '</div>';
74
	else
75
	{
76
		foreach ($context['unread_pms'] as $id_pm => $pm_details)
77
			echo '
78
			<div class="unread">
79
				', !empty($pm_details['member']) ? $pm_details['member']['avatar']['image'] : '', '
80
				<div class="details">
81
					<div class="subject">', $pm_details['pm_link'], '</div>
82
					<div class="sender">
83
						', $pm_details['replied_to_you'] ? '<span class="generic_icons replied centericon" style="margin-right: 4px" title="' . $txt['pm_you_were_replied_to'] . '"></span>' : '<span class="generic_icons im_off centericon" style="margin-right: 4px" title="' . $txt['pm_was_sent_to_you'] . '"></span>',
84
						!empty($pm_details['member']) ? $pm_details['member']['link'] : $pm_details['member_from'], ' - ', $pm_details['time'], '
85
					</div>
86
				</div>
87
			</div>';
88
	}
89
90
	echo '
91
		</div><!-- #pm_unread -->';
92
}
93
94
/**
95
 * Shows a particular folder (eg inbox or outbox), all the PMs in it, etc.
96
 */
97
function template_folder()
98
{
99
	global $context, $settings, $options, $scripturl, $modSettings, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
100
101
	// The every helpful javascript!
102
	echo '
103
		<script>
104
			var allLabels = {};
105
			var currentLabels = {};
106
			function loadLabelChoices()
107
			{
108
				var listing = document.forms.pmFolder.elements;
109
				var theSelect = document.forms.pmFolder.pm_action;
110
				var add, remove, toAdd = {length: 0}, toRemove = {length: 0};
111
112
				if (theSelect.childNodes.length == 0)
113
					return;
114
115
				// This is done this way for internationalization reasons.
116
				if (!(\'-1\' in allLabels))
117
				{
118
					for (var o = 0; o < theSelect.options.length; o++)
119
						if (theSelect.options[o].value.substr(0, 4) == "rem_")
120
							allLabels[theSelect.options[o].value.substr(4)] = theSelect.options[o].text;
121
				}
122
123
				for (var i = 0; i < listing.length; i++)
124
				{
125
					if (listing[i].name != "pms[]" || !listing[i].checked)
126
						continue;
127
128
					var alreadyThere = [], x;
129
					for (x in currentLabels[listing[i].value])
130
					{
131
						if (!(x in toRemove))
132
						{
133
							toRemove[x] = allLabels[x];
134
							toRemove.length++;
135
						}
136
						alreadyThere[x] = allLabels[x];
137
					}
138
139
					for (x in allLabels)
140
					{
141
						if (!(x in alreadyThere))
142
						{
143
							toAdd[x] = allLabels[x];
144
							toAdd.length++;
145
						}
146
					}
147
				}
148
149
				while (theSelect.options.length > 2)
150
					theSelect.options[2] = null;
151
152
				if (toAdd.length != 0)
153
				{
154
					theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_apply'], '", "");
155
					setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_apply'], '");
156
					theSelect.options[theSelect.options.length - 1].disabled = true;
157
158
					for (i in toAdd)
159
					{
160
						if (i != "length")
161
							theSelect.options[theSelect.options.length] = new Option(toAdd[i], "add_" + i);
162
					}
163
				}
164
165
				if (toRemove.length != 0)
166
				{
167
					theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_remove'], '", "");
168
					setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_remove'], '");
169
					theSelect.options[theSelect.options.length - 1].disabled = true;
170
171
					for (i in toRemove)
172
					{
173
						if (i != "length")
174
							theSelect.options[theSelect.options.length] = new Option(toRemove[i], "rem_" + i);
175
					}
176
				}
177
			}
178
		</script>';
179
180
	echo '
181
		<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">';
182
183
	// If we are not in single display mode show the subjects on the top!
184
	if ($context['display_mode'] != 1)
185
	{
186
		template_subject_list();
187
188
		echo '
189
			<div class="clear_right"><br></div>';
190
	}
191
192
	// Got some messages to display?
193
	if ($context['get_pmessage']('message', true))
194
	{
195
		// Show the helpful titlebar - generally.
196
		if ($context['display_mode'] != 1)
197
			echo '
198
			<div class="cat_bar">
199
				<h3 class="catbg">
200
					<span id="author">', $txt['author'], '</span>
201
					<span id="topic_title">', $txt[$context['display_mode'] == 0 ? 'messages' : 'conversation'], '</span>
202
				</h3>
203
			</div>';
204
205
		// Show a few buttons if we are in conversation mode and outputting the first message.
206 View Code Duplication
		if ($context['display_mode'] == 2)
207
		{
208
			// Show the conversation buttons.
209
			echo '
210
			<div class="pagesection">';
211
212
			template_button_strip($context['conversation_buttons'], 'right');
213
214
			echo '
215
			</div>';
216
		}
217
218
		while ($message = $context['get_pmessage']('message'))
219
		{
220
221
			echo '
222
			<div class="windowbg">
223
				<div class="poster">';
224
225
			// Are there any custom fields above the member name?
226 View Code Duplication
			if (!empty($message['custom_fields']['above_member']))
227
			{
228
				echo '
229
					<div class="custom_fields_above_member">
230
						<ul class="nolist">';
231
232
				foreach ($message['custom_fields']['above_member'] as $custom)
233
					echo '
234
							<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
235
236
				echo '
237
						</ul>
238
					</div>';
239
			}
240
241
			echo '
242
					<h4>
243
						<a id="msg', $message['id'], '"></a>';
244
245
			// Show online and offline buttons?
246
			if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
247
				echo '
248
						<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>';
249
250
			// Custom fields BEFORE the username?
251 View Code Duplication
			if (!empty($message['custom_fields']['before_member']))
252
				foreach ($message['custom_fields']['before_member'] as $custom)
253
					echo '
254
						<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
255
256
			// Show a link to the member's profile.
257
			echo '
258
				', $message['member']['link'];
259
260
				// Custom fields AFTER the username?
261 View Code Duplication
				if (!empty($message['custom_fields']['after_member']))
262
					foreach ($message['custom_fields']['after_member'] as $custom)
263
						echo '
264
						<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
265
266
			echo '
267
					</h4>';
268
269
			echo '
270
					<ul class="user_info">';
271
272
			// Show the user's avatar.
273 View Code Duplication
			if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
274
				echo '
275
						<li class="avatar">
276
							<a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '">', $message['member']['avatar']['image'], '</a>
277
						</li>';
278
279
			// Are there any custom fields below the avatar?
280 View Code Duplication
			if (!empty($message['custom_fields']['below_avatar']))
281
				foreach ($message['custom_fields']['below_avatar'] as $custom)
282
					echo '
283
						<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
284
285
			if (!$message['member']['is_guest'])
286
				echo '
287
						<li class="icons">', $message['member']['group_icons'], '</li>';
288
			// Show the member's primary group (like 'Administrator') if they have one.
289 View Code Duplication
			if (isset($message['member']['group']) && $message['member']['group'] != '')
290
				echo '
291
						<li class="membergroup">', $message['member']['group'], '</li>';
292
293
			// Show the member's custom title, if they have one.
294 View Code Duplication
			if (isset($message['member']['title']) && $message['member']['title'] != '')
295
				echo '
296
						<li class="title">', $message['member']['title'], '</li>';
297
298
			// Don't show these things for guests.
299
			if (!$message['member']['is_guest'])
300
			{
301
				// 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.
302
				if ((empty($modSettings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '')
303
					echo '
304
						<li class="postgroup">', $message['member']['post_group'], '</li>';
305
306
				// Show how many posts they have made.
307 View Code Duplication
				if (!isset($context['disabled_fields']['posts']))
308
					echo '
309
						<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
310
311
				// Show their personal text?
312 View Code Duplication
				if (!empty($modSettings['show_blurb']) && $message['member']['blurb'] != '')
313
					echo '
314
						<li class="blurb">', $message['member']['blurb'], '</li>';
315
316
				// Any custom fields to show as icons?
317 View Code Duplication
				if (!empty($message['custom_fields']['icons']))
318
				{
319
					echo '
320
						<li class="im_icons">
321
							<ol>';
322
323
					foreach ($message['custom_fields']['icons'] as $custom)
324
						echo '
325
								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
326
327
					echo '
328
							</ol>
329
						</li>';
330
				}
331
332
				// Show the IP to this user for this post - because you can moderate?
333
				if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
334
					echo '
335
						<li class="poster_ip">
336
							<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>
337
						</li>';
338
339
				// Or, should we show it because this is you?
340
				elseif ($message['can_see_ip'])
341
					echo '
342
						<li class="poster_ip">
343
							<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a>
344
						</li>';
345
346
				// Okay, you are logged in, then we can show something about why IPs are logged...
347
				else
348
					echo '
349
						<li class="poster_ip">
350
							<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a>
351
						</li>';
352
353
				// Show the profile, website, email address, and personal message buttons.
354
				if ($message['member']['show_profile_buttons'])
355
				{
356
					echo '
357
						<li class="profile">
358
							<ol class="profile_icons">';
359
360
					// Show the profile button
361
					if ($message['member']['can_view_profile'])
362
						echo '
363
								<li><a href="', $message['member']['href'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="' . $txt['view_profile'] . '" title="' . $txt['view_profile'] . '">' : $txt['view_profile']), '</a></li>';
364
365
					// Don't show an icon if they haven't specified a website.
366 View Code Duplication
					if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website']))
367
						echo '
368
								<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
369
370
					// Don't show the email address if they want it hidden.
371 View Code Duplication
					if ($message['member']['show_email'])
372
						echo '
373
								<li><a href="mailto:', $message['member']['email'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
374
375
					// Since we know this person isn't a guest, you *can* message them.
376 View Code Duplication
					if ($context['can_send_pm'])
377
						echo '
378
								<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="generic_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>';
379
380
					echo '
381
							</ol>
382
						</li>';
383
				}
384
385
				// Any custom fields for standard placement?
386 View Code Duplication
				if (!empty($message['custom_fields']['standard']))
387
					foreach ($message['custom_fields']['standard'] as $custom)
388
						echo '
389
						<li class="custom ', $custom['col_name'] ,'">', $custom['title'], ': ', $custom['value'], '</li>';
390
391
				// Are we showing the warning status?
392
				if ($message['member']['can_see_warning'])
393
					echo '
394
						<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_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>';
395
396
				// Are there any custom fields to show at the bottom of the poster info?
397 View Code Duplication
				if (!empty($message['custom_fields']['bottom_poster']))
398
					foreach ($message['custom_fields']['bottom_poster'] as $custom)
399
						echo '
400
						<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
401
			}
402
403
			// Done with the information about the poster... on to the post itself.
404
			echo '
405
					</ul>
406
				</div><!-- .poster -->
407
				<div class="postarea">
408
					<div class="flow_hidden">
409
						<div class="keyinfo">
410
							<h5 id="subject_', $message['id'], '">
411
								', $message['subject'], '
412
							</h5>';
413
414
			// Show who the message was sent to.
415
			echo '
416
							<span class="smalltext">&#171; <strong> ', $txt['sent_to'], ':</strong> ';
417
418
			// People it was sent directly to....
419 View Code Duplication
			if (!empty($message['recipients']['to']))
420
				echo implode(', ', $message['recipients']['to']);
421
422
			// Otherwise, we're just going to say "some people"...
423
			elseif ($context['folder'] != 'sent')
424
				echo '(', $txt['pm_undisclosed_recipients'], ')';
425
426
			echo '
427
								<strong> ', $txt['on'], ':</strong> ', $message['time'], ' &#187;
428
							</span>';
429
430
			// If we're in the sent items, show who it was sent to besides the "To:" people.
431
			if (!empty($message['recipients']['bcc']))
432
				echo '<br>
433
							<span class="smalltext">&#171; <strong> ', $txt['pm_bcc'], ':</strong> ', implode(', ', $message['recipients']['bcc']), ' &#187;</span>';
434
435
			if (!empty($message['is_replied_to']))
436
				echo '<br>
437
							<span class="smalltext">&#171; ', $context['folder'] == 'sent' ? $txt['pm_sent_is_replied_to'] : $txt['pm_is_replied_to'], ' &#187;</span>';
438
439
			echo '
440
						</div><!-- .keyinfo -->
441
					</div><!-- .flow_hidden -->
442
					<div class="post">
443
						<div class="inner" id="msg_', $message['id'], '"', '>
444
							', $message['body'], '
445
						</div>';
446
447
			if ($message['can_report'] || $context['can_send_pm'])
448
				echo '
449
						<div class="under_message">';
450
451
			if ($message['can_report'])
452
				echo '
453
							<a href="' . $scripturl . '?action=pm;sa=report;l=' . $context['current_label_id'] . ';pmsg=' . $message['id'] . '" class="floatright">' . $txt['pm_report_to_admin'] . '</a>';
454
455
			echo '
456
							<ul class="quickbuttons">';
457
458
			// Show reply buttons if you have the permission to send PMs.
459
			if ($context['can_send_pm'])
460
			{
461
				// You can't really reply if the member is gone.
462
				if (!$message['member']['is_guest'])
463
				{
464
					// Is there than more than one recipient you can reply to?
465 View Code Duplication
					if ($message['number_recipients'] > 1)
466
						echo '
467
								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=all"><span class="generic_icons reply_all_button"></span>', $txt['reply_to_all'], '</a></li>';
468
469
					echo '
470
								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>
471
								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote', $context['folder'] == 'sent' ? '' : ';u=' . $message['member']['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
472
				}
473
				// This is for "forwarding" - even if the member is gone.
474
				else
475
					echo '
476
								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote"><span class="generic_icons quote"></span>', $txt['reply_quote'], '</a></li>';
477
			}
478
			echo '
479
								<li><a href="', $scripturl, '?action=pm;sa=pmactions;pm_actions%5b', $message['id'], '%5D=delete;f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', addslashes($txt['remove_message_question']), '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['delete'], '</a></li>';
480
481
			if (empty($context['display_mode']))
482
				echo '
483
								<li><input type="checkbox" name="pms[]" id="deletedisplay', $message['id'], '" value="', $message['id'], '" onclick="document.getElementById(\'deletelisting', $message['id'], '\').checked = this.checked;"></li>';
484
485
			echo '
486
							</ul>';
487
488
			if ($message['can_report'] || $context['can_send_pm'])
489
			echo '
490
						</div><!-- .under_message -->';
491
492
			// Are there any custom profile fields for above the signature?
493 View Code Duplication
			if (!empty($message['custom_fields']['above_signature']))
494
			{
495
				echo '
496
						<div class="custom_fields_above_signature">
497
							<ul class="nolist">';
498
499
				foreach ($message['custom_fields']['above_signature'] as $custom)
500
					echo '
501
								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
502
503
				echo '
504
							</ul>
505
						</div>';
506
			}
507
508
			// Show the member's signature?
509
			if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
510
				echo '
511
						<div class="signature">
512
							', $message['member']['signature'], '
513
						</div>';
514
515
			// Are there any custom profile fields for below the signature?
516 View Code Duplication
			if (!empty($message['custom_fields']['below_signature']))
517
			{
518
				echo '
519
						<div class="custom_fields_below_signature">
520
							<ul class="nolist">';
521
522
				foreach ($message['custom_fields']['below_signature'] as $custom)
523
					echo '
524
								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
525
526
				echo '
527
							</ul>
528
						</div>';
529
			}
530
531
			// Add an extra line at the bottom if we have labels enabled.
532
			if ($context['folder'] != 'sent' && !empty($context['currently_using_labels']) && $context['display_mode'] != 2)
533
			{
534
				echo '
535
						<div class="labels righttext flow_auto">';
536
537
				// Add the label drop down box.
538
				if (!empty($context['currently_using_labels']))
539
				{
540
					echo '
541
							<select name="pm_actions[', $message['id'], ']" onchange="if (this.options[this.selectedIndex].value) form.submit();">
542
								<option value="">', $txt['pm_msg_label_title'], ':</option>
543
								<option value="" disabled>---------------</option>';
544
545
					// Are there any labels which can be added to this?
546
					if (!$message['fully_labeled'])
547
					{
548
						echo '
549
								<option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>';
550
551
						foreach ($context['labels'] as $label)
552
							if (!isset($message['labels'][$label['id']]))
553
								echo '
554
								<option value="', $label['id'], '">', $label['name'], '</option>';
555
					}
556
557
					// ... and are there any that can be removed?
558
					if (!empty($message['labels']) && (count($message['labels']) > 1 || !isset($message['labels'][-1])))
559
					{
560
						echo '
561
								<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
562
563
						foreach ($message['labels'] as $label)
564
							echo '
565
								<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
566
					}
567
					echo '
568
							</select>
569
							<noscript>
570
								<input type="submit" value="', $txt['pm_apply'], '" class="button">
571
							</noscript>';
572
				}
573
				echo '
574
						</div><!-- .labels -->';
575
			}
576
577
			echo '
578
					</div><!-- .post -->
579
				</div><!-- .postarea -->
580
				<div class="moderatorbar"></div>
581
			</div><!-- .windowbg -->';
582
		}
583
584
		if (empty($context['display_mode']))
585
			echo '
586
			<div class="pagesection">
587
				<div class="floatleft">', $context['page_index'], '</div>
588
				<div class="floatright">
589
					<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button">
590
				</div>
591
			</div>';
592
593
		// Show a few buttons if we are in conversation mode and outputting the first message.
594 View Code Duplication
		elseif ($context['display_mode'] == 2 && isset($context['conversation_buttons']))
595
		{
596
			echo '
597
			<div class="pagesection">';
598
599
			template_button_strip($context['conversation_buttons'], 'right');
600
601
			echo '
602
			</div>';
603
		}
604
605
		echo '
606
			<br>';
607
	}
608
609
	// Individual messages = buttom list!
610
	if ($context['display_mode'] == 1)
611
	{
612
		template_subject_list();
613
		echo '<br>';
614
	}
615
616
	echo '
617
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
618
		</form>';
619
}
620
621
/**
622
 * Just list all the personal message subjects - to make templates easier.
623
 */
624
function template_subject_list()
625
{
626
	global $context, $settings, $txt, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
627
628
	echo '
629
	<table class="table_grid">
630
		<thead>
631
			<tr class="title_bar">
632
				<th class="centercol table_icon">
633
					<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="generic_icons switch" title="', $txt['pm_change_view'], '"></span></a>
634
				</th>
635
				<th class="lefttext quarter_table">
636
					<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="generic_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
637
				</th>
638
				<th class="lefttext half_table">
639
					<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="generic_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
640
				</th>
641
				<th class="lefttext">
642
					<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['to']), $context['sort_by'] == 'name' ? ' <span class="generic_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
643
				</th>
644
				<th class="centercol table_icon">
645
					<input type="checkbox" onclick="invertAll(this, this.form);">
646
				</th>
647
			</tr>
648
		</thead>
649
		<tbody>';
650
651
	if (!$context['show_delete'])
652
		echo '
653
			<tr class="windowbg">
654
				<td colspan="5">', $txt['pm_alert_none'], '</td>
655
			</tr>';
656
657
	while ($message = $context['get_pmessage']('subject'))
658
	{
659
		echo '
660
			<tr class="windowbg', $message['is_unread'] ? ' unread_pm' : '','">
661
				<td class="table_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="generic_icons replied" title="' . $txt['pm_replied'] . '"></span>' : '<span class="generic_icons im_off" title="' . $txt['pm_read'] . '"></span>', '
680
				</td>
681
				<td>', $message['time'], '</td>
682
				<td>
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
				</td>
685
				<td>
686
					', ($context['from_or_to'] == 'from' ? $message['member']['link'] : (empty($message['recipients']['to']) ? '' : implode(', ', $message['recipients']['to']))), '
687
				</td>
688
				<td class="centercol table_icon">
689
					<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;">
690
				</td>
691
			</tr>';
692
	}
693
694
	echo '
695
		</tbody>
696
	</table>
697
	<div class="pagesection">
698
		<div class="floatleft">', $context['page_index'], '</div>
699
		<div class="floatright">&nbsp;';
700
701
	if ($context['show_delete'])
702
	{
703
		if (!empty($context['currently_using_labels']) && $context['folder'] != 'sent')
704
		{
705
			echo '
706
			<select name="pm_action" onchange="if (this.options[this.selectedIndex].value) this.form.submit();" onfocus="loadLabelChoices();">
707
				<option value="">', $txt['pm_sel_label_title'], ':</option>
708
				<option value="" disabled>---------------</option>
709
				<option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>';
710
711 View Code Duplication
			foreach ($context['labels'] as $label)
712
			{
713
				if ($label['id'] != $context['current_label_id'])
714
					echo '
715
				<option value="add_', $label['id'], '">&nbsp;', $label['name'], '</option>';
716
			}
717
718
			echo '
719
				<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
720
721
			foreach ($context['labels'] as $label)
722
				echo '
723
				<option value="rem_', $label['id'], '">&nbsp;', $label['name'], '</option>';
724
725
			echo '
726
			</select>
727
			<noscript>
728
				<input type="submit" value="', $txt['pm_apply'], '" class="button">
729
			</noscript>';
730
		}
731
732
		echo '
733
			<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button">';
734
	}
735
736
	echo '
737
		</div><!-- .floatright -->
738
	</div><!-- .pagesection -->';
739
}
740
741
/**
742
 * The form for the PM search feature
743
 */
744
function template_search()
0 ignored issues
show
Best Practice introduced by
The function template_search() has been defined more than once; this definition is ignored, only the first definition in Themes/default/Memberlist.template.php (L145-190) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
745
{
746
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
747
748
	echo '
749
	<form action="', $scripturl, '?action=pm;sa=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
750
		<div class="cat_bar">
751
			<h3 class="catbg">', $txt['pm_search_title'], '</h3>
752
		</div>';
753
754 View Code Duplication
	if (!empty($context['search_errors']))
755
		echo '
756
		<div class="errorbox">
757
			', implode('<br>', $context['search_errors']['messages']), '
758
		</div>';
759
760
761
	echo '
762
		<fieldset id="advanced_search">
763
			<div class="roundframe">
764
				<input type="hidden" name="advanced" value="1">
765
				<span class="enhanced">
766
					<strong>', $txt['pm_search_text'], ':</strong>
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
					<select name="searchtype">
773
						<option value="1"', empty($context['search_params']['searchtype']) ? ' selected' : '', '>', $txt['pm_search_match_all'], '</option>
774
						<option value="2"', !empty($context['search_params']['searchtype']) ? ' selected' : '', '>', $txt['pm_search_match_any'], '</option>
775
					</select>
776
				</span>
777
				<dl id="search_options">
778
					<dt>', $txt['pm_search_user'], ':</dt>
779
					<dd><input type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40"></dd>
780
					<dt>', $txt['pm_search_order'], ':</dt>
781
					<dd>
782
						<select name="sort">
783
							<option value="relevance|desc">', $txt['pm_search_orderby_relevant_first'], '</option>
784
							<option value="id_pm|desc">', $txt['pm_search_orderby_recent_first'], '</option>
785
							<option value="id_pm|asc">', $txt['pm_search_orderby_old_first'], '</option>
786
						</select>
787
					</dd>
788
					<dt class="options">', $txt['pm_search_options'], ':</dt>
789
					<dd class="options">
790
						<label for="show_complete">
791
							<input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked' : '', '> ', $txt['pm_search_show_complete'], '
792
						</label><br>
793
						<label for="subject_only">
794
							<input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked' : '', '> ', $txt['pm_search_subject_only'], '
795
						</label>
796
					</dd>
797
					<dt class="between">', $txt['pm_search_post_age'], ':</dt>
798
					<dd>
799
						', $txt['pm_search_between'], '
800
						<input type="number" name="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="5" min="0" max="9999">
801
						', $txt['pm_search_between_and'], '
802
						<input type="number" name="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="5" min="0" max="9999">
803
						', $txt['pm_search_between_days'], '
804
					</dd>
805
				</dl>';
806
807
	if (!$context['currently_using_labels'])
808
		echo '
809
				<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button">';
810
811
	echo '
812
				<br class="clear_right">
813
			</div><!-- .roundframe -->
814
		</fieldset>';
815
816
	// Do we have some labels setup? If so offer to search by them!
817
	if ($context['currently_using_labels'])
818
	{
819
		echo '
820
		<fieldset class="labels">
821
			<div class="roundframe">
822
				<div class="cat_bar">
823
					<h3 class="catbg">
824
						<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>
825
					</h3>
826
				</div>
827
				<div id="advanced_panel_div">
828
					<ul id="searchLabelsExpand">';
829
830
		foreach ($context['search_labels'] as $label)
831
			echo '
832
						<li>
833
							<label for="searchlabel_', $label['id'], '"><input type="checkbox" id="searchlabel_', $label['id'], '" name="searchlabel[', $label['id'], ']" value="', $label['id'], '"', $label['checked'] ? ' checked' : '', '>
834
							', $label['name'], '</label>
835
						</li>';
836
837
		echo '
838
					</ul>
839
				</div>
840
				<p>
841
					<span class="floatleft">
842
						<input type="checkbox" name="all" id="check_all" value=""', $context['check_all'] ? ' checked' : '', ' onclick="invertAll(this, this.form, \'searchlabel\');"><em> <label for="check_all">', $txt['check_all'], '</label></em>
843
					</span>
844
					<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button">
845
				</p>
846
				<br class="clear_right">
847
			</div><!-- .roundframe -->
848
		</fieldset>';
849
850
		// Some javascript for the advanced toggling
851
		echo '
852
		<script>
853
			var oAdvancedPanelToggle = new smc_Toggle({
854
				bToggleEnabled: true,
855
				bCurrentlyCollapsed: true,
856
				aSwappableContainers: [
857
					\'advanced_panel_div\'
858
				],
859
				aSwapImages: [
860
					{
861
						sId: \'advanced_panel_toggle\',
862
						altExpanded: ', JavaScriptEscape($txt['hide']), ',
863
						altCollapsed: ', JavaScriptEscape($txt['show']), '
864
					}
865
				],
866
				aSwapLinks: [
867
					{
868
						sId: \'advanced_panel_link\',
869
						msgExpanded: ', JavaScriptEscape($txt['pm_search_choose_label']), ',
870
						msgCollapsed: ', JavaScriptEscape($txt['pm_search_choose_label']), '
871
					}
872
				]
873
			});
874
		</script>';
875
	}
876
877
	echo '
878
	</form>';
879
}
880
881
/**
882
 * Displays results from a PM search
883
 */
884
function template_search_results()
885
{
886
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
887
888
	echo '
889
		<div class="cat_bar">
890
			<h3 class="catbg">', $txt['pm_search_results'], '</h3>
891
		</div>
892
		<div class="pagesection">
893
			', $context['page_index'], '
894
		</div>';
895
896
	// Complete results?
897
	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
898
		echo '
899
		<table class="table_grid">
900
			<thead>
901
				<tr class="title_bar">
902
					<th class="lefttext quarter_table">', $txt['date'], '</th>
903
					<th class="lefttext half_table">', $txt['subject'], '</th>
904
					<th class="lefttext quarter_table">', $txt['from'], '</th>
905
				</tr>
906
			</thead>
907
			<tbody>';
908
909
	// Print each message out...
910
	foreach ($context['personal_messages'] as $message)
911
	{
912
		// Are we showing it all?
913
		if (!empty($context['search_params']['show_complete']))
914
		{
915
			echo '
916
			<div class="cat_bar">
917
				<h3 class="catbg">
918
					<span class="floatright">', $txt['search_on'], ': ', $message['time'], '</span>
919
					<span class="floatleft">', $message['counter'], '&nbsp;&nbsp;<a href="', $message['href'], '">', $message['subject'], '</a></span>
920
				</h3>
921
			</div>
922
			<div class="cat_bar">
923
				<h3 class="catbg">', $txt['from'], ': ', $message['member']['link'], ', ', $txt['to'], ': ';
924
925
			// Show the recipients.
926
			// @todo This doesn't deal with the sent item searching quite right for bcc.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
927 View Code Duplication
			if (!empty($message['recipients']['to']))
928
				echo implode(', ', $message['recipients']['to']);
929
930
			// Otherwise, we're just going to say "some people"...
931
			elseif ($context['folder'] != 'sent')
932
				echo '(', $txt['pm_undisclosed_recipients'], ')';
933
934
			echo '
935
				</h3>
936
			</div>
937
			<div class="windowbg">
938
				', $message['body'], '
939
				<p class="pm_reply righttext">';
940
941
			if ($context['can_send_pm'])
942
			{
943
				$quote_button = create_button('quote.png', 'reply_quote', 'reply_quote', 'class="centericon"');
944
				$reply_button = create_button('im_reply.png', 'reply', 'reply', 'class="centericon"');
945
946
				// You can only reply if they are not a guest...
947
				if (!$message['member']['is_guest'])
948
					echo '
949
					<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=', $context['folder'] == 'sent' ? '' : $message['member']['id'], '">', $quote_button , '</a>', $context['menu_separator'], '
950
					<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '">', $reply_button , '</a> ', $context['menu_separator'];
951
952
				// This is for "forwarding" - even if the member is gone.
953 View Code Duplication
				else
954
					echo '
955
					<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote">', $quote_button , '</a>', $context['menu_separator'];
956
			}
957
958
			echo '
959
				</p>
960
			</div><!-- .windowbg -->';
961
		}
962
		// Otherwise just a simple list!
963
		// @todo No context at all of the search?
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
964
		else
965
			echo '
966
				<tr class="windowbg">
967
					<td>', $message['time'], '</td>
968
					<td>', $message['link'], '</td>
969
					<td>', $message['member']['link'], '</td>
970
				</tr>';
971
	}
972
973
	// Finish off the page...
974
	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
975
		echo '
976
			</tbody>
977
		</table>';
978
979
	// No results?
980
	if (empty($context['personal_messages']))
981
		echo '
982
		<div class="windowbg">
983
			<p class="centertext">', $txt['pm_search_none_found'], '</p>
984
		</div>';
985
986
	echo '
987
		<div class="pagesection">
988
			', $context['page_index'], '
989
		</div>';
990
991
}
992
993
/**
994
 * The form for sending a new PM
995
 */
996
function template_send()
997
{
998
	global $context, $options, $scripturl, $modSettings, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
999
1000
	// Show which messages were sent successfully and which failed.
1001
	if (!empty($context['send_log']))
1002
	{
1003
		echo '
1004
		<div class="cat_bar">
1005
			<h3 class="catbg">', $txt['pm_send_report'], '</h3>
1006
		</div>
1007
		<div class="windowbg">';
1008
1009 View Code Duplication
		if (!empty($context['send_log']['sent']))
1010
			foreach ($context['send_log']['sent'] as $log_entry)
1011
				echo '
1012
			<span class="error">', $log_entry, '</span><br>';
1013
1014 View Code Duplication
		if (!empty($context['send_log']['failed']))
1015
			foreach ($context['send_log']['failed'] as $log_entry)
1016
				echo '
1017
			<span class="error">', $log_entry, '</span><br>';
1018
1019
		echo '
1020
		</div>
1021
		<br>';
1022
	}
1023
1024
	// Show the preview of the personal message.
1025
	echo '
1026
		<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
1027
			<div class="cat_bar">
1028
				<h3 class="catbg">
1029
					<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
1030
				</h3>
1031
			</div>
1032
			<div class="windowbg noup">
1033
				<div class="post" id="preview_body">
1034
					', empty($context['preview_message']) ? '<br>' : $context['preview_message'], '
1035
				</div>
1036
			</div>
1037
			<br class="clear">
1038
		</div>';
1039
1040
	// Main message editing box.
1041
	echo '
1042
		<div class="cat_bar">
1043
			<h3 class="catbg">
1044
				<span class="generic_icons inbox icon" title="', $txt['new_message'], '"></span> ', $txt['new_message'], '
1045
			</h3>
1046
		</div>';
1047
1048
	echo '
1049
		<form action="', $scripturl, '?action=pm;sa=send2" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="submitonce(this);">
1050
			<div class="roundframe noup">
1051
				<br class="clear">';
1052
1053
	// If there were errors for sending the PM, show them.
1054
	echo '
1055
				<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
1056
					<dl>
1057
						<dt>
1058
							<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
1059
						</dt>
1060
						<dd class="error" id="error_list">
1061
							', empty($context['post_error']['messages']) ? '' : implode('<br>', $context['post_error']['messages']), '
1062
						</dd>
1063
					</dl>
1064
				</div>';
1065
1066
	if (!empty($modSettings['drafts_pm_enabled']))
1067
		echo '
1068
				<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
1069
					sprintf($txt['draft_pm_saved'], $scripturl . '?action=pm;sa=showpmdrafts'), '
1070
					', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
1071
				</div>';
1072
1073
	echo '
1074
				<dl id="post_header">';
1075
1076
	// To and bcc. Include a button to search for members.
1077
	echo '
1078
					<dt>
1079
						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' class="error"' : ''), ' id="caption_to">', $txt['pm_to'], ':</span>
1080
					</dt>';
1081
1082
	// Autosuggest will be added by the JavaScript later on.
1083
	echo '
1084
					<dd id="pm_to" class="clear_right">
1085
						<input type="text" name="to" id="to_control" value="', $context['to_value'], '" tabindex="', $context['tabindex']++, '" size="20">';
1086
1087
	// A link to add BCC, only visible with JavaScript enabled.
1088
	echo '
1089
						<span class="smalltext" id="bcc_link_container" style="display: none;"></span>';
1090
1091
	// A div that'll contain the items found by the autosuggest.
1092
	echo '
1093
						<div id="to_item_list_container"></div>';
1094
1095
	echo '
1096
					</dd>';
1097
1098
	// This BCC row will be hidden by default if JavaScript is enabled.
1099
	echo '
1100
					<dt  class="clear_left" id="bcc_div">
1101
						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_bcc']) ? ' class="error"' : ''), ' id="caption_bbc">', $txt['pm_bcc'], ':</span>
1102
					</dt>
1103
					<dd id="bcc_div2">
1104
						<input type="text" name="bcc" id="bcc_control" value="', $context['bcc_value'], '" tabindex="', $context['tabindex']++, '" size="20">
1105
						<div id="bcc_item_list_container"></div>
1106
					</dd>';
1107
1108
	// The subject of the PM.
1109
	echo '
1110
					<dt class="clear_left">
1111
						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
1112
					</dt>
1113
					<dd id="pm_subject">
1114
						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="80"',isset($context['post_error']['no_subject']) ? ' class="error"' : '', '>
1115
					</dd>
1116
				</dl>
1117
				<hr>';
1118
1119
	// Showing BBC?
1120
	if ($context['show_bbc'])
1121
		echo '
1122
				<div id="bbcBox_message"></div>';
1123
1124
	// What about smileys?
1125 View Code Duplication
	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
1126
		echo '
1127
				<div id="smileyBox_message"></div>';
1128
1129
	// Show BBC buttons, smileys and textbox.
1130
	echo '
1131
				', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
0 ignored issues
show
Documentation introduced by
'smileyBox_message' is of type string, but the function expects a null|boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'bbcBox_message' is of type string, but the function expects a null|boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1132
1133
	// Require an image to be typed to save spamming?
1134 View Code Duplication
	if ($context['require_verification'])
1135
		echo '
1136
				<div class="post_verification">
1137
					<strong>', $txt['pm_visual_verification_label'], ':</strong>
1138
					', template_control_verification($context['visual_verification_id'], 'all'), '
1139
				</div>';
1140
1141
	// Send, Preview, spellcheck buttons.
1142
	echo '
1143
				<hr>
1144
				<span id="post_confirm_strip" class="righttext">
1145
					', template_control_richedit_buttons($context['post_box_name']), '
1146
				</span>
1147
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1148
				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
1149
				<input type="hidden" name="replied_to" value="', !empty($context['quoted_message']['id']) ? $context['quoted_message']['id'] : 0, '">
1150
				<input type="hidden" name="pm_head" value="', !empty($context['quoted_message']['pm_head']) ? $context['quoted_message']['pm_head'] : 0, '">
1151
				<input type="hidden" name="f" value="', isset($context['folder']) ? $context['folder'] : '', '">
1152
				<input type="hidden" name="l" value="', isset($context['current_label_id']) ? $context['current_label_id'] : -1, '">
1153
				<br class="clear_right">
1154
			</div><!-- .roundframe -->
1155
		</form>';
1156
1157
	// If the admin enabled the pm drafts feature, show a draft selection box
1158 View Code Duplication
	if (!empty($context['drafts_pm_save']) && !empty($context['drafts']) && !empty($options['drafts_show_saved_enabled']))
1159
	{
1160
		echo '
1161
		<br>
1162
		<div id="postDraftOptionsHeader" class="cat_bar">
1163
			<h3 class="catbg">
1164
				<span id="postDraftExpand" class="toggle_up floatright" style="display: none;"></span> <strong><a href="#" id="postDraftExpandLink">', $txt['draft_load'], '</a></strong>
1165
			</h3>
1166
		</div>
1167
		<div id="postDraftOptions" class="load_drafts padding">
1168
			<dl class="settings">
1169
				<dt><strong>', $txt['subject'], '</strong></dt>
1170
				<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
1171
1172
		foreach ($context['drafts'] as $draft)
1173
			echo '
1174
				<dt>', $draft['link'], '</dt>
1175
				<dd>', $draft['poster_time'], '</dd>';
1176
		echo '
1177
			</dl>
1178
		</div>';
1179
	}
1180
1181
	echo '
1182
		<script>';
1183
1184
	// The functions used to preview a personal message without loading a new page.
1185
	echo '
1186
			var txt_preview_title = "', $txt['preview_title'], '";
1187
			var txt_preview_fetch = "', $txt['preview_fetch'], '";
1188
			function previewPost()
1189
			{
1190
				if (window.XMLHttpRequest)
1191
				{
1192
					// Opera didn\'t support setRequestHeader() before 8.01.
1193
					// @todo Remove support for old browsers
1194
					if (\'opera\' in window)
1195
					{
1196
						var test = new XMLHttpRequest();
1197
						if (!(\'setRequestHeader\' in test))
1198
							return submitThisOnce(document.forms.postmodify);
1199
					}
1200
					// @todo Currently not sending poll options and option checkboxes.
1201
					var x = new Array();
1202
					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'to\', \'bcc\'];
1203
					var numericFields = [\'recipient_to[]\', \'recipient_bcc[]\'];
1204
					var checkboxFields = [];
1205
1206
					for (var i = 0, n = textFields.length; i < n; i++)
1207
						if (textFields[i] in document.forms.postmodify)
1208
						{
1209
							// Handle the WYSIWYG editor.
1210
							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
1211
								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).php_to8bit().php_urlencode();
1212
							else
1213
								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.php_to8bit().php_urlencode();
1214
						}
1215
					for (var i = 0, n = numericFields.length; i < n; i++)
1216
						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
1217
							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
1218
					for (var i = 0, n = checkboxFields.length; i < n; i++)
1219
						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
1220
							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
1221
1222
					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=pm;sa=send2;preview;xml\', x.join(\'&\'), onDocSent);
1223
1224
					document.getElementById(\'preview_section\').style.display = \'\';
1225
					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
1226
					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
1227
1228
					return false;
1229
				}
1230
				else
1231
					return submitThisOnce(document.forms.postmodify);
1232
			}
1233
			function onDocSent(XMLDoc)
1234
			{
1235
				if (!XMLDoc)
1236
				{
1237
					document.forms.postmodify.preview.onclick = new function ()
1238
					{
1239
						return true;
1240
					}
1241
					document.forms.postmodify.preview.click();
1242
				}
1243
1244
				// Show the preview section.
1245
				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
1246
				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
1247
1248
				var bodyText = \'\';
1249
				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
1250
					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
1251
1252
				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
1253
				document.getElementById(\'preview_body\').className = \'post\';
1254
1255
				// Show a list of errors (if any).
1256
				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
1257
				var errorList = new Array();
1258
				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
1259
					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
1260
				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
1261
				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br>\'));
1262
1263
				// Adjust the color of captions if the given data is erroneous.
1264
				var captions = errors.getElementsByTagName(\'caption\');
1265
				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
1266
					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
1267
						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
1268
1269
				if (errors.getElementsByTagName(\'post_error\').length == 1)
1270
					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
1271
				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\')
1272
				{
1273
					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
1274
						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
1275
					else
1276
						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
1277
				}
1278
				location.hash = \'#\' + \'preview_section\';
1279
			}';
1280
1281
	// Code for showing and hiding drafts
1282 View Code Duplication
	if (!empty($context['drafts']))
1283
		echo '
1284
			var oSwapDraftOptions = new smc_Toggle({
1285
				bToggleEnabled: true,
1286
				bCurrentlyCollapsed: true,
1287
				aSwappableContainers: [
1288
					\'postDraftOptions\',
1289
				],
1290
				aSwapImages: [
1291
					{
1292
						sId: \'postDraftExpand\',
1293
						altExpanded: \'-\',
1294
						altCollapsed: \'+\'
1295
					}
1296
				],
1297
				aSwapLinks: [
1298
					{
1299
						sId: \'postDraftExpandLink\',
1300
						msgExpanded: ', JavaScriptEscape($txt['draft_hide']), ',
1301
						msgCollapsed: ', JavaScriptEscape($txt['draft_load']), '
1302
					}
1303
				]
1304
			});';
1305
1306
	echo '
1307
		</script>';
1308
1309
	// Show the message you're replying to.
1310
	if ($context['reply'])
1311
		echo '
1312
		<br><br>
1313
		<div class="cat_bar">
1314
			<h3 class="catbg">', $txt['subject'], ': ', $context['quoted_message']['subject'], '</h3>
1315
		</div>
1316
		<div class="windowbg2">
1317
			<div class="clear">
1318
				<span class="smalltext floatright">', $txt['on'], ': ', $context['quoted_message']['time'], '</span>
1319
				<strong>', $txt['from'], ': ', $context['quoted_message']['member']['name'], '</strong>
1320
			</div>
1321
			<hr>
1322
			', $context['quoted_message']['body'], '
1323
		</div>
1324
		<br class="clear">';
1325
1326
	echo '
1327
		<script>
1328
			var oPersonalMessageSend = new smf_PersonalMessageSend({
1329
				sSelf: \'oPersonalMessageSend\',
1330
				sSessionId: smf_session_id,
1331
				sSessionVar: smf_session_var,
1332
				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
1333
				sToControlId: \'to_control\',
1334
				aToRecipients: [';
1335
1336 View Code Duplication
	foreach ($context['recipients']['to'] as $i => $member)
1337
		echo '
1338
					{
1339
						sItemId: ', JavaScriptEscape($member['id']), ',
1340
						sItemName: ', JavaScriptEscape($member['name']), '
1341
					}', $i == count($context['recipients']['to']) - 1 ? '' : ',';
1342
1343
	echo '
1344
				],
1345
				aBccRecipients: [';
1346
1347 View Code Duplication
	foreach ($context['recipients']['bcc'] as $i => $member)
1348
		echo '
1349
					{
1350
						sItemId: ', JavaScriptEscape($member['id']), ',
1351
						sItemName: ', JavaScriptEscape($member['name']), '
1352
					}', $i == count($context['recipients']['bcc']) - 1 ? '' : ',';
1353
1354
	echo '
1355
				],
1356
				sBccControlId: \'bcc_control\',
1357
				sBccDivId: \'bcc_div\',
1358
				sBccDivId2: \'bcc_div2\',
1359
				sBccLinkId: \'bcc_link\',
1360
				sBccLinkContainerId: \'bcc_link_container\',
1361
				bBccShowByDefault: ', empty($context['recipients']['bcc']) && empty($context['bcc_value']) ? 'false' : 'true', ',
1362
				sShowBccLinkTemplate: ', JavaScriptEscape('
1363
					<a href="#" id="bcc_link">' . $txt['make_bcc'] . '</a> <a href="' . $scripturl . '?action=helpadmin;help=pm_bcc" onclick="return reqOverlayDiv(this.href);">(?)</a>'
1364
				), '
1365
			});';
1366
1367
	echo '
1368
		</script>';
1369
}
1370
1371
/**
1372
 * This template asks the user whether they wish to empty out their folder/messages.
1373
 */
1374
function template_ask_delete()
1375
{
1376
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1377
1378
	echo '
1379
		<div class="cat_bar">
1380
			<h3 class="catbg">
1381
				', ($context['delete_all'] ? $txt['delete_message'] : $txt['delete_all']), '
1382
			</h3>
1383
		</div>
1384
		<div class="windowbg">
1385
			<p>', $txt['delete_all_confirm'], '</p>
1386
			<br>
1387
			<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>
1388
		</div>';
1389
}
1390
1391
/**
1392
 * This template asks the user what messages they want to prune.
1393
 */
1394
function template_prune()
1395
{
1396
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1397
1398
	echo '
1399
		<div class="cat_bar">
1400
			<h3 class="catbg">', $txt['pm_prune'], '</h3>
1401
		</div>
1402
		<div class="windowbg">
1403
			<form action="', $scripturl, '?action=pm;sa=prune" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['pm_prune_warning'], '\');">
1404
				<p>', $txt['pm_prune_desc1'], ' <input type="text" name="age" size="3" value="14"> ', $txt['pm_prune_desc2'], '</p>
1405
				<input type="submit" value="', $txt['delete'], '" class="button">
1406
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1407
			</form>
1408
		</div>
1409
		<div class="windowbg">
1410
			<form action="', $scripturl, '?action=pm;sa=removeall2" method="post" onsubmit="return confirm(\'', $txt['pm_remove_all_warning'], '\');">
1411
				<p>', $txt['pm_remove_all'], '</p>
1412
				<input type="submit" value="', $txt['delete_all_prune'], '" class="button">
1413
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1414
			</form>
1415
		</div>';
1416
}
1417
1418
/**
1419
 * Here we allow the user to setup labels, remove labels and change rules for labels (i.e, do quite a bit)
1420
 */
1421
function template_labels()
1422
{
1423
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1424
1425
	echo '
1426
	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
1427
		<div class="cat_bar">
1428
			<h3 class="catbg">', $txt['pm_manage_labels'], '</h3>
1429
		</div>
1430
		<div class="information">
1431
			', $txt['pm_labels_desc'], '
1432
		</div>
1433
		<table class="table_grid">
1434
			<thead>
1435
				<tr class="title_bar">
1436
					<th class="lefttext">
1437
						', $txt['pm_label_name'], '
1438
					</th>
1439
					<th class="centertext table_icon">';
1440
1441
	if (count($context['labels']) > 2)
1442
		echo '
1443
						<input type="checkbox" onclick="invertAll(this, this.form);">';
1444
1445
	echo '
1446
					</th>
1447
				</tr>
1448
			</thead>
1449
			<tbody>';
1450
	if (count($context['labels']) < 2)
1451
		echo '
1452
				<tr class="windowbg">
1453
					<td colspan="2">', $txt['pm_labels_no_exist'], '</td>
1454
				</tr>';
1455
	else
1456
	{
1457 View Code Duplication
		foreach ($context['labels'] as $label)
1458
		{
1459
			if ($label['id'] == -1)
1460
				continue;
1461
1462
				echo '
1463
				<tr class="windowbg">
1464
					<td>
1465
						<input type="text" name="label_name[', $label['id'], ']" value="', $label['name'], '" size="30" maxlength="30">
1466
					</td>
1467
					<td class="table_icon"><input type="checkbox" name="delete_label[', $label['id'], ']"></td>
1468
				</tr>';
1469
		}
1470
	}
1471
	echo '
1472
			</tbody>
1473
		</table>';
1474
1475
	if (!count($context['labels']) < 2)
1476
		echo '
1477
		<div class="padding">
1478
			<input type="submit" name="save" value="', $txt['save'], '" class="button">
1479
			<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" data-confirm="', $txt['pm_labels_delete'] ,'" class="button you_sure">
1480
		</div>';
1481
1482
	echo '
1483
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1484
	</form>
1485
	<br class="clear">
1486
	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
1487
		<div class="cat_bar">
1488
			<h3 class="catbg">', $txt['pm_label_add_new'], '</h3>
1489
		</div>
1490
		<div class="windowbg">
1491
			<dl class="settings">
1492
				<dt>
1493
					<strong><label for="add_label">', $txt['pm_label_name'], '</label>:</strong>
1494
				</dt>
1495
				<dd>
1496
					<input type="text" id="add_label" name="label" value="" size="30" maxlength="30">
1497
				</dd>
1498
			</dl>
1499
			<input type="submit" name="add" value="', $txt['pm_label_add_new'], '" class="button">
1500
		</div>
1501
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1502
	</form>
1503
	<br>';
1504
}
1505
1506
/**
1507
 * Template for reporting a personal message.
1508
 */
1509
function template_report_message()
1510
{
1511
	global $context, $txt, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1512
1513
	echo '
1514
	<form action="', $scripturl, '?action=pm;sa=report;l=', $context['current_label_id'], '" method="post" accept-charset="', $context['character_set'], '">
1515
		<input type="hidden" name="pmsg" value="', $context['pm_id'], '">
1516
		<div class="cat_bar">
1517
			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
1518
		</div>
1519
		<div class="information">
1520
			', $txt['pm_report_desc'], '
1521
		</div>
1522
		<div class="windowbg">
1523
			<dl class="settings">';
1524
1525
	// If there is more than one admin on the forum, allow the user to choose the one they want to direct to.
1526
	// @todo Why?
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
1527
	if ($context['admin_count'] > 1)
1528
	{
1529
		echo '
1530
				<dt>
1531
					<strong>', $txt['pm_report_admins'], ':</strong>
1532
				</dt>
1533
				<dd>
1534
					<select name="id_admin">
1535
						<option value="0">', $txt['pm_report_all_admins'], '</option>';
1536
1537
		foreach ($context['admins'] as $id => $name)
1538
			echo '
1539
						<option value="', $id, '">', $name, '</option>';
1540
1541
		echo '
1542
					</select>
1543
				</dd>';
1544
	}
1545
1546
	echo '
1547
				<dt>
1548
					<strong>', $txt['pm_report_reason'], ':</strong>
1549
				</dt>
1550
				<dd>
1551
					<textarea name="reason" rows="4" cols="70" style="width: 80%;"></textarea>
1552
				</dd>
1553
			</dl>
1554
			<div class="righttext">
1555
				<input type="submit" name="report" value="', $txt['pm_report_message'], '" class="button">
1556
			</div>
1557
		</div><!-- .windowbg -->
1558
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1559
	</form>';
1560
}
1561
1562
/**
1563
 * Little template just to say "Yep, it's been submitted"
1564
 */
1565
function template_report_message_complete()
1566
{
1567
	global $context, $txt, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1568
1569
	echo '
1570
		<div class="cat_bar">
1571
			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
1572
		</div>
1573
		<div class="windowbg">
1574
			<p>', $txt['pm_report_done'], '</p>
1575
			<a href="', $scripturl, '?action=pm;l=', $context['current_label_id'], '">', $txt['pm_report_return'], '</a>
1576
		</div>';
1577
}
1578
1579
/**
1580
 * Manage rules.
1581
 */
1582
function template_rules()
1583
{
1584
	global $context, $txt, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1585
1586
	echo '
1587
	<form action="', $scripturl, '?action=pm;sa=manrules" method="post" accept-charset="', $context['character_set'], '" name="manRules" id="manrules">
1588
		<div class="cat_bar">
1589
			<h3 class="catbg">', $txt['pm_manage_rules'], '</h3>
1590
		</div>
1591
		<div class="information">
1592
			', $txt['pm_manage_rules_desc'], '
1593
		</div>
1594
		<table class="table_grid">
1595
			<thead>
1596
				<tr class="title_bar">
1597
					<th class="lefttext">
1598
						', $txt['pm_rule_title'], '
1599
					</th>
1600
					<th class="centertext table_icon">';
1601
1602
	if (!empty($context['rules']))
1603
		echo '
1604
						<input type="checkbox" onclick="invertAll(this, this.form);">';
1605
1606
	echo '
1607
					</th>
1608
				</tr>
1609
			</thead>
1610
			<tbody>';
1611
1612
	if (empty($context['rules']))
1613
		echo '
1614
				<tr class="windowbg">
1615
					<td colspan="2">
1616
						', $txt['pm_rules_none'], '
1617
					</td>
1618
				</tr>';
1619
1620
	foreach ($context['rules'] as $rule)
1621
		echo '
1622
				<tr class="windowbg">
1623
					<td>
1624
						<a href="', $scripturl, '?action=pm;sa=manrules;add;rid=', $rule['id'], '">', $rule['name'], '</a>
1625
					</td>
1626
					<td class="table_icon">
1627
						<input type="checkbox" name="delrule[', $rule['id'], ']">
1628
					</td>
1629
				</tr>';
1630
1631
	echo '
1632
			</tbody>
1633
		</table>
1634
		<div class="righttext">
1635
			<a class="button" href="', $scripturl, '?action=pm;sa=manrules;add;rid=0">', $txt['pm_add_rule'], '</a>';
1636
1637 View Code Duplication
	if (!empty($context['rules']))
1638
		echo '
1639
			[<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>]';
1640
1641 View Code Duplication
	if (!empty($context['rules']))
1642
		echo '
1643
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1644
			<input type="submit" name="delselected" value="', $txt['pm_delete_selected_rule'], '" data-confirm="', $txt['pm_js_delete_rule_confirm'] ,'" class="button smalltext you_sure">';
1645
1646
	echo '
1647
		</div>
1648
	</form>';
1649
1650
}
1651
1652
/**
1653
 * Template for adding/editing a rule.
1654
 */
1655
function template_add_rule()
1656
{
1657
	global $context, $txt, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1658
1659
	echo '
1660
	<script>
1661
		var criteriaNum = 0;
1662
		var actionNum = 0;
1663
		var groups = new Array()
1664
		var labels = new Array()';
1665
1666
	foreach ($context['groups'] as $id => $title)
1667
		echo '
1668
		groups[', $id, '] = "', addslashes($title), '";';
1669
1670 View Code Duplication
	foreach ($context['labels'] as $label)
1671
		if ($label['id'] != -1)
1672
			echo '
1673
		labels[', ($label['id']), '] = "', addslashes($label['name']), '";';
1674
1675
	echo '
1676
		function addCriteriaOption()
1677
		{
1678
			if (criteriaNum == 0)
1679
			{
1680
				for (var i = 0; i < document.forms.addrule.elements.length; i++)
1681
					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
1682
						criteriaNum++;
1683
			}
1684
			criteriaNum++
1685
1686
			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>';
1687
1688
	foreach ($context['groups'] as $id => $group)
1689
		echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>';
1690
1691
	echo '<\' + \'/select><\' + \'/span><span id="criteriaAddHere"><\' + \'/span>\');
1692
			}
1693
1694
			function addActionOption()
1695
			{
1696
				if (actionNum == 0)
1697
				{
1698
					for (var i = 0; i < document.forms.addrule.elements.length; i++)
1699
						if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
1700
							actionNum++;
1701
				}
1702
				actionNum++
1703
1704
				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>';
1705
1706 View Code Duplication
	foreach ($context['labels'] as $label)
1707
		if ($label['id'] != -1)
1708
			echo '<option value="', ($label['id']), '">', addslashes($label['name']), '<\' + \'/option>';
1709
1710
	echo '<\' + \'/select><\' + \'/span><span id="actionAddHere"><\' + \'/span>\');
1711
			}
1712
1713
			// Rebuild the rule description!
1714
			function rebuildRuleDesc()
1715
			{
1716
				// Start with nothing.
1717
				var text = "";
1718
				var joinText = "";
1719
				var actionText = "";
1720
				var hadBuddy = false;
1721
				var foundCriteria = false;
1722
				var foundAction = false;
1723
				var curNum, curVal, curDef;
1724
1725
				for (var i = 0; i < document.forms.addrule.elements.length; i++)
1726
				{
1727
					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
1728
					{
1729
						if (foundCriteria)
1730
							joinText = document.getElementById("logic").value == \'and\' ? ', JavaScriptEscape(' ' . $txt['pm_readable_and'] . ' '), ' : ', JavaScriptEscape(' ' . $txt['pm_readable_or'] . ' '), ';
1731
						else
1732
							joinText = \'\';
1733
						foundCriteria = true;
1734
1735
						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
1736
						curVal = document.forms.addrule.elements[i].value;
1737
						if (curVal == "gid")
1738
							curDef = document.getElementById("ruledefgroup" + curNum).value.php_htmlspecialchars();
1739
						else if (curVal != "bud")
1740
							curDef = document.getElementById("ruledef" + curNum).value.php_htmlspecialchars();
1741
						else
1742
							curDef = "";
1743
1744
						// What type of test is this?
1745
						if (curVal == "mid" && curDef)
1746
							text += joinText + ', JavaScriptEscape($txt['pm_readable_member']), '.replace("{MEMBER}", curDef);
1747
						else if (curVal == "gid" && curDef && groups[curDef])
1748
							text += joinText + ', JavaScriptEscape($txt['pm_readable_group']), '.replace("{GROUP}", groups[curDef]);
1749
						else if (curVal == "sub" && curDef)
1750
							text += joinText + ', JavaScriptEscape($txt['pm_readable_subject']), '.replace("{SUBJECT}", curDef);
1751
						else if (curVal == "msg" && curDef)
1752
							text += joinText + ', JavaScriptEscape($txt['pm_readable_body']), '.replace("{BODY}", curDef);
1753
						else if (curVal == "bud" && !hadBuddy)
1754
						{
1755
							text += joinText + ', JavaScriptEscape($txt['pm_readable_buddy']), ';
1756
							hadBuddy = true;
1757
						}
1758
					}
1759
					if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
1760
					{
1761
						if (foundAction)
1762
							joinText = ', JavaScriptEscape(' ' . $txt['pm_readable_and'] . ' '), ';
1763
						else
1764
							joinText = "";
1765
						foundAction = true;
1766
1767
						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
1768
						curVal = document.forms.addrule.elements[i].value;
1769
						if (curVal == "lab")
1770
							curDef = document.getElementById("labdef" + curNum).value.php_htmlspecialchars();
1771
						else
1772
							curDef = "";
1773
1774
						// Now pick the actions.
1775
						if (curVal == "lab" && curDef && labels[curDef])
1776
							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_label']), '.replace("{LABEL}", labels[curDef]);
1777
						else if (curVal == "del")
1778
							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_delete']), ';
1779
					}
1780
				}
1781
1782
				// If still nothing make it default!
1783
				if (text == "" || !foundCriteria)
1784
					text = "', $txt['pm_rule_not_defined'], '";
1785
				else
1786
				{
1787
					if (actionText != "")
1788
						text += ', JavaScriptEscape(' ' . $txt['pm_readable_then'] . ' '), ' + actionText;
1789
					text = ', JavaScriptEscape($txt['pm_readable_start']), ' + text + ', JavaScriptEscape($txt['pm_readable_end']), ';
1790
				}
1791
1792
				// Set the actual HTML!
1793
				setInnerHTML(document.getElementById("ruletext"), text);
1794
			}
1795
	</script>';
1796
1797
	echo '
1798
	<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">
1799
		<div class="cat_bar">
1800
			<h3 class="catbg">', $context['rid'] == 0 ? $txt['pm_add_rule'] : $txt['pm_edit_rule'], '</h3>
1801
		</div>
1802
		<div class="windowbg">
1803
			<dl class="addrules">
1804
				<dt class="floatleft">
1805
					<strong>', $txt['pm_rule_name'], ':</strong><br>
1806
					<span class="smalltext">', $txt['pm_rule_name_desc'], '</span>
1807
				</dt>
1808
				<dd class="floatleft">
1809
					<input type="text" name="rule_name" value="', empty($context['rule']['name']) ? $txt['pm_rule_name_default'] : $context['rule']['name'], '" size="50">
1810
				</dd>
1811
			</dl>
1812
			<fieldset>
1813
				<legend>', $txt['pm_rule_criteria'], '</legend>';
1814
1815
	// Add a dummy criteria to allow expansion for none js users.
1816
	$context['rule']['criteria'][] = array('t' => '', 'v' => '');
1817
1818
	// For each criteria print it out.
1819
	$isFirst = true;
1820
	foreach ($context['rule']['criteria'] as $k => $criteria)
1821
	{
1822 View Code Duplication
		if (!$isFirst && $criteria['t'] == '')
1823
			echo '<div id="removeonjs1">';
1824
1825
		elseif (!$isFirst)
1826
			echo '<br>';
1827
1828
		echo '
1829
				<select name="ruletype[', $k, ']" id="ruletype', $k, '" onchange="updateRuleDef(', $k, '); rebuildRuleDesc();">
1830
					<option value="">', $txt['pm_rule_criteria_pick'], ':</option>';
1831
1832
		foreach (array('mid', 'gid', 'sub', 'msg', 'bud') as $cr)
1833
			echo '
1834
					<option value="', $cr, '"', $criteria['t'] == $cr ? ' selected' : '', '>', $txt['pm_rule_' . $cr], '</option>';
1835
1836
		echo '
1837
				</select>
1838
				<span id="defdiv', $k, '" ', !in_array($criteria['t'], array('gid', 'bud')) ? '' : 'style="display: none;"', '>
1839
					<input type="text" name="ruledef[', $k, ']" id="ruledef', $k, '" onkeyup="rebuildRuleDesc();" value="', in_array($criteria['t'], array('mid', 'sub', 'msg')) ? $criteria['v'] : '', '">
1840
				</span>
1841
				<span id="defseldiv', $k, '" ', $criteria['t'] == 'gid' ? '' : 'style="display: none;"', '>
1842
					<select name="ruledefgroup[', $k, ']" id="ruledefgroup', $k, '" onchange="rebuildRuleDesc();">
1843
						<option value="">', $txt['pm_rule_sel_group'], '</option>';
1844
1845
		foreach ($context['groups'] as $id => $group)
1846
			echo '
1847
						<option value="', $id, '"', $criteria['t'] == 'gid' && $criteria['v'] == $id ? ' selected' : '', '>', $group, '</option>';
1848
		echo '
1849
					</select>
1850
				</span>';
1851
1852
		// If this is the dummy we add a means to hide for non js users.
1853
		if ($isFirst)
1854
			$isFirst = false;
1855
1856
		elseif ($criteria['t'] == '')
1857
			echo '</div><!-- .removeonjs1 -->';
1858
	}
1859
1860
	echo '
1861
				<span id="criteriaAddHere"></span><br>
1862
				<a href="#" onclick="addCriteriaOption(); return false;" id="addonjs1" style="display: none;">(', $txt['pm_rule_criteria_add'], ')</a>
1863
				<br><br>
1864
				', $txt['pm_rule_logic'], ':
1865
				<select name="rule_logic" id="logic" onchange="rebuildRuleDesc();">
1866
					<option value="and"', $context['rule']['logic'] == 'and' ? ' selected' : '', '>', $txt['pm_rule_logic_and'], '</option>
1867
					<option value="or"', $context['rule']['logic'] == 'or' ? ' selected' : '', '>', $txt['pm_rule_logic_or'], '</option>
1868
				</select>
1869
			</fieldset>
1870
			<fieldset>
1871
				<legend>', $txt['pm_rule_actions'], '</legend>';
1872
1873
	// As with criteria - add a dummy action for "expansion".
1874
	$context['rule']['actions'][] = array('t' => '', 'v' => '');
1875
1876
	// Print each action.
1877
	$isFirst = true;
1878
	foreach ($context['rule']['actions'] as $k => $action)
1879
	{
1880 View Code Duplication
		if (!$isFirst && $action['t'] == '')
1881
			echo '<div id="removeonjs2">';
1882
		elseif (!$isFirst)
1883
			echo '<br>';
1884
1885
		echo '
1886
				<select name="acttype[', $k, ']" id="acttype', $k, '" onchange="updateActionDef(', $k, '); rebuildRuleDesc();">
1887
					<option value="">', $txt['pm_rule_sel_action'] , ':</option>
1888
					<option value="lab"', $action['t'] == 'lab' ? ' selected' : '', '>', $txt['pm_rule_label'] , '</option>
1889
					<option value="del"', $action['t'] == 'del' ? ' selected' : '', '>', $txt['pm_rule_delete'] , '</option>
1890
				</select>
1891
				<span id="labdiv', $k, '">
1892
					<select name="labdef[', $k, ']" id="labdef', $k, '" onchange="rebuildRuleDesc();">
1893
						<option value="">', $txt['pm_rule_sel_label'], '</option>';
1894
1895
		foreach ($context['labels'] as $label)
1896
			if ($label['id'] != -1)
1897
				echo '
1898
						<option value="', ($label['id']), '"', $action['t'] == 'lab' && $action['v'] == $label['id'] ? ' selected' : '', '>', $label['name'], '</option>';
1899
1900
		echo '
1901
					</select>
1902
				</span>';
1903
1904
		if ($isFirst)
1905
			$isFirst = false;
1906
1907
		elseif ($action['t'] == '')
1908
			echo '</div><!-- .removeonjs2 -->';
1909
	}
1910
1911
	echo '
1912
				<span id="actionAddHere"></span><br>
1913
				<a href="#" onclick="addActionOption(); return false;" id="addonjs2" style="display: none;">(', $txt['pm_rule_add_action'], ')</a>
1914
			</fieldset>
1915
			<div class="cat_bar">
1916
				<h3 class="catbg">', $txt['pm_rule_description'], '</h3>
1917
			</div>
1918
			<div class="information">
1919
				<div id="ruletext">', $txt['pm_rule_js_disabled'], '</div>
1920
			</div>
1921
			<div class="righttext">
1922
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1923
				<input type="submit" name="save" value="', $txt['pm_rule_save'], '" class="button">
1924
			</div>
1925
		</div><!-- .windowbg -->
1926
	</form>';
1927
1928
	// Now setup all the bits!
1929
		echo '
1930
	<script>';
1931
1932
	foreach ($context['rule']['criteria'] as $k => $c)
1933
		echo '
1934
			updateRuleDef(', $k, ');';
1935
1936
	foreach ($context['rule']['actions'] as $k => $c)
1937
		echo '
1938
			updateActionDef(', $k, ');';
1939
1940
	echo '
1941
			rebuildRuleDesc();';
1942
1943
	// If this isn't a new rule and we have JS enabled remove the JS compatibility stuff.
1944
	if ($context['rid'])
1945
		echo '
1946
			document.getElementById("removeonjs1").style.display = "none";
1947
			document.getElementById("removeonjs2").style.display = "none";';
1948
1949
	echo '
1950
			document.getElementById("addonjs1").style.display = "";
1951
			document.getElementById("addonjs2").style.display = "";';
1952
1953
	echo '
1954
		</script>';
1955
}
1956
1957
/**
1958
 * Template for showing all of a user's PM drafts.
1959
 */
1960
function template_showPMDrafts()
1961
{
1962
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1963
1964
	echo '
1965
		<div class="cat_bar">
1966
			<h3 class="catbg">
1967
				<span class="generic_icons inbox"></span> ', $txt['drafts_show'], '
1968
			</h3>
1969
		</div>
1970
		<div class="pagesection">
1971
			<span>', $context['page_index'], '</span>
1972
		</div>';
1973
1974
	// No drafts? Just show an informative message.
1975
	if (empty($context['drafts']))
1976
		echo '
1977
		<div class="windowbg2 centertext">
1978
			', $txt['draft_none'], '
1979
		</div>';
1980
	else
1981
	{
1982
		// For every draft to be displayed, give it its own div, and show the important details of the draft.
1983
		foreach ($context['drafts'] as $draft)
1984
		{
1985
			echo '
1986
		<div class="windowbg">
1987
			<div class="counter">', $draft['counter'], '</div>
1988
			<div class="topic_details">
1989
				<h5>
1990
					<strong>', $draft['subject'], '</strong>
1991
				</h5>
1992
				<span class="smalltext">&#171;&nbsp;<strong>', $txt['draft_saved_on'], ':</strong> ', sprintf($txt['draft_days_ago'], $draft['age']), (!empty($draft['remaining']) ? ', ' . sprintf($txt['draft_retain'], $draft['remaining']) : ''), '&#187;</span><br>
1993
				<span class="smalltext">&#171;&nbsp;<strong>', $txt['to'], ':</strong> ', implode(', ', $draft['recipients']['to']), '&nbsp;&#187;</span><br>
1994
				<span class="smalltext">&#171;&nbsp;<strong>', $txt['pm_bcc'], ':</strong> ', implode(', ', $draft['recipients']['bcc']), '&nbsp;&#187;</span>
1995
			</div>
1996
			<div class="list_posts">
1997
				', $draft['body'], '
1998
			</div>
1999
			<ul class="quickbuttons">
2000
				<li><a href="', $scripturl, '?action=pm;sa=showpmdrafts;id_draft=', $draft['id_draft'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons modifybutton"></span>', $txt['draft_edit'], '</a></li>
2001
				<li><a href="', $scripturl, '?action=pm;sa=showpmdrafts;delete=', $draft['id_draft'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['draft_remove'] ,'?" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['draft_delete'], '</a></li>
2002
			</ul>
2003
		</div><!-- .windowbg -->';
2004
		}
2005
	}
2006
2007
	// Show page numbers.
2008
	echo '
2009
	<div class="pagesection">
2010
		<span>', $context['page_index'], '</span>
2011
	</div>';
2012
}
2013
2014
?>