Passed
Pull Request — development (#3504)
by Elk
07:41
created

template_profile_options()   D

Complexity

Conditions 30
Paths 102

Size

Total Lines 138
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 57
dl 0
loc 138
rs 4.15
c 1
b 0
f 0
cc 30
nc 102
nop 0

How to fix   Long Method    Complexity   

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
/**
4
 * @package   ElkArte Forum
5
 * @copyright ElkArte Forum contributors
6
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
7
 *
8
 * This file contains code covered by:
9
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
10
 *
11
 * @version 2.0 dev
12
 *
13
 */
14
15
/**
16
 * We need this template in order to look at ignored boards
17
 */
18
function template_ProfileOptions_init()
19
{
20
	global $context, $txt;
21
22
	theme()->getTemplates()->load('GenericBoards');
23
24
	if (!empty($context['menu_item_selected']) && $context['menu_item_selected'] === 'notification')
25
	{
26
		loadJavascriptFile('jquery.multiselect.min.js');
27
		theme()->addInlineJavascript('
28
		$(\'.select_multiple\').multiselect({\'language_strings\': {\'Select all\': ' . JavascriptEscape($txt['notify_select_all']) . '}});', true);
29
		loadCSSFile('multiselect.css');
30
	}
31
}
32
33
/**
34
 * Template for showing all the buddies of the current user.
35
 */
36
function template_editBuddies()
37
{
38
	global $context, $txt;
39
40
	echo '
41
	<div id="edit_buddies">
42
		<h2 class="category_header hdicon cat_img_buddies">
43
			', $txt['editBuddies'], '
44
		</h2>
45
		<table class="table_grid">
46
			<tr class="table_head">
47
				<th scope="col" class="grid20">', $txt['name'], '</th>
48
				<th scope="col">', $txt['status'], '</th>';
49
50
	if ($context['can_send_email'])
51
	{
52
		echo '
53
				<th scope="col">', $txt['email'], '</th>';
54
	}
55
56
	echo '
57
				<th scope="col">', $txt['profile_contact'], '</th>
58
				<th scope="col"></th>
59
			</tr>';
60
61
	// If they don't have any buddies don't list them!
62
	if (empty($context['buddies']))
63
	{
64
		echo '
65
			<tr>
66
				<td colspan="5" class="centertext">
67
					<strong>', $txt['no_buddies'], '</strong>
68
				</td>
69
			</tr>';
70
	}
71
72
	// Now loop through each buddy showing info on each.
73
	foreach ($context['buddies'] as $buddy)
74
	{
75
		echo '
76
			<tr>
77
				<td>', $buddy['link'], '</td>
78
				<td>
79
					', template_member_online($buddy), '
80
				</td>';
81
82
		if ($context['can_send_email'])
83
		{
84
			echo '
85
				<td>', template_member_email($buddy), '</td>';
86
		}
87
88
		//  Any custom profile (with icon) fields to show
89
		$im = array();
90
		if (!empty($buddy['custom_fields']))
91
		{
92
93
			foreach ($buddy['custom_fields'] as $key => $cpf)
94
			{
95
				if ($cpf['placement'] == 1)
96
				{
97
					$im[] = $cpf['value'];
98
				}
99
			}
100
		}
101
102
		echo '
103
				<td>' . implode(' | ', $im) . '</td>';
104
105
		echo '
106
				<td class="righttext">
107
					<a href="', getUrl('action', ['action' => 'profile', 'area' => 'lists', 'sa' => 'buddies', 'u' => $context['id_member'], 'remove' => $buddy['id'], '{session_data}']), '" class="icon i-remove" title="', $txt['buddy_remove'], '"></a>
108
				</td>
109
			</tr>';
110
	}
111
112
	echo '
113
		</table>
114
	</div>';
115
116
	// Add a new buddy?
117
	echo '
118
	<form action="', getUrl('action', ['action' => 'profile', 'u' => $context['id_member'], 'area' => 'lists', 'sa' => 'buddies']), '" method="post" accept-charset="UTF-8">
119
		<div class="add_buddy">
120
			<h2 class="category_header">', $txt['buddy_add'], '</h2>
121
			<div class="well">
122
				<dl class="settings">
123
					<dt>
124
						<label for="new_buddy">', $txt['who_member'], '</label>
125
					</dt>
126
					<dd>
127
						<input type="text" name="new_buddy" id="new_buddy" size="30" class="input_text" />
128
						<input type="submit" value="', $txt['buddy_add_button'], '" />
129
					</dd>
130
				</dl>';
131
132
	if (!empty($context['token_check']))
133
	{
134
		echo '
135
				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
136
	}
137
138
	echo '
139
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
140
			</div>
141
		</div>
142
	</form>';
143
144
	// Initialize the autosuggest object
145
	theme()->addInlineJavascript('
146
		new smc_AutoSuggest({
147
			sSessionId: elk_session_id,
148
			sSessionVar: elk_session_var,
149
			sSuggestId: \'new_buddy\',
150
			sControlId: \'new_buddy\',
151
			sSearchType: \'member\',
152
			sTextDeleteItem: ' . JavaScriptEscape($txt['autosuggest_delete_item']) . ',
153
			bItemList: false
154
		});', true);
155
}
156
157
/**
158
 * Template for showing the ignore list of the current user.
159
 */
160
function template_editIgnoreList()
161
{
162
	global $context, $txt;
163
164
	echo '
165
	<div id="edit_buddies">
166
		<h2 class="category_header hdicon cat_img_profile">
167
			', $txt['editIgnoreList'], '
168
		</h2>
169
		<table class="table_grid">
170
			<tr class="table_head">
171
				<th scope="col" style="width: 20%;">', $txt['name'], '</th>
172
				<th scope="col">', $txt['status'], '</th>';
173
174
	if ($context['can_send_email'])
175
	{
176
		echo '
177
				<th scope="col">', $txt['email'], '</th>';
178
	}
179
180
	echo '
181
				<th scope="col"></th>
182
			</tr>';
183
184
	// If they don't have anyone on their ignore list, don't list it!
185
	if (empty($context['ignore_list']))
186
	{
187
		echo '
188
			<tr>
189
				<td colspan="4" class="centertext">
190
					<strong>', $txt['no_ignore'], '</strong>
191
				</td>
192
			</tr>';
193
	}
194
195
	// Now loop through each buddy showing info on each.
196
	foreach ($context['ignore_list'] as $member)
197
	{
198
		echo '
199
			<tr>
200
				<td>', $member['link'], '</td>
201
				<td>
202
					', template_member_online($member), '
203
				</td>';
204
205
		if ($context['can_send_email'])
206
		{
207
			echo '
208
				<td>', template_member_email($member), '</td>';
209
		}
210
211
		echo '
212
				<td class="righttext">
213
					<a href="', getUrl('profile', ['action' => 'profile', 'u' => $context['id_member'], 'name' => $context['member']['name'], 'area' => 'lists', 'sa' => 'ignore', 'remove' => $member['id'], '{session_data}']), '" class="icon i-remove" title="', $txt['ignore_remove'], '">
214
					</a>
215
				</td>
216
			</tr>';
217
	}
218
219
	echo '
220
		</table>
221
	</div>';
222
223
	// Add to the ignore list?
224
	echo '
225
	<form action="', getUrl('action', ['action' => 'profile', 'u' => $context['id_member'], 'area' => 'lists', 'sa' => 'ignore']) . '" method="post" accept-charset="UTF-8">
226
		<div class="add_buddy">
227
			<h2 class="category_header">', $txt['ignore_add'], '</h2>
228
			<div class="well">
229
				<dl class="settings">
230
					<dt>
231
						<label for="new_ignore">', $txt['who_member'], '</label>
232
					</dt>
233
					<dd>
234
						<input type="text" name="new_ignore" id="new_ignore" size="25" class="input_text" />
235
						<input type="submit" value="', $txt['ignore_add_button'], '" />
236
					</dd>
237
				</dl>';
238
239
	if (!empty($context['token_check']))
240
	{
241
		echo '
242
				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
243
	}
244
245
	echo '
246
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
247
			</div>
248
		</div>
249
	</form>';
250
251
	theme()->addInlineJavascript('
252
		new smc_AutoSuggest({
253
			sSessionId: elk_session_id,
254
			sSessionVar: elk_session_var,
255
			sSuggestId: \'new_ignore\',
256
			sControlId: \'new_ignore\',
257
			sSearchType: \'member\',
258
			sTextDeleteItem: ' . JavaScriptEscape($txt['autosuggest_delete_item']) . ',
259
			bItemList: false
260
		});', true);
261
}
262
263
/**
264
 * Template for editing profile options.
265
 *
266
 * @uses ParseError
267
 */
268
function template_edit_options()
269
{
270
	global $context, $txt;
271
272
	// The main header!
273
	echo '
274
		<form action="', (!empty($context['profile_custom_submit_url']) ? $context['profile_custom_submit_url'] : getUrl('action', ['action' => 'profile', 'area' => $context['menu_item_selected'], 'u' => $context['id_member']])), '" method="post" accept-charset="UTF-8" name="creator" id="creator" enctype="multipart/form-data" onsubmit="return checkProfileSubmit();">
275
			<h2 class="category_header hdicon cat_img_profile">';
276
277
	// Don't say "Profile" if this isn't the profile...
278
	if (!empty($context['profile_header_text']))
279
	{
280
		echo '
281
				', $context['profile_header_text'];
282
	}
283
	else
284
	{
285
		echo '
286
				', $txt['profile'];
287
	}
288
289
	echo '
290
			</h2>';
291
292
	// Have we some description?
293
	if ($context['page_desc'])
294
	{
295
		echo '
296
			<p class="description">', $context['page_desc'], '</p>';
297
	}
298
299
	echo '
300
			<div class="content">';
301
302
	// Any bits at the start?
303
	if (!empty($context['profile_prehtml']))
304
	{
305
		echo '
306
				<div>', $context['profile_prehtml'], '</div>';
307
	}
308
309
	// Profile fields, standard and custom
310
	$lastItem = template_profile_options();
311
	template_custom_profile_options($lastItem);
312
313
	// Any closing HTML?
314
	if (!empty($context['profile_posthtml']))
315
	{
316
		echo '
317
				<div>', $context['profile_posthtml'], '</div>';
318
	}
319
320
	// Only show the password box if it's actually needed.
321
	template_profile_save();
322
323
	echo '
324
			</div>
325
		</form>';
326
327
	// Some javascript!
328
	echo '
329
		<script>
330
			function checkProfileSubmit()
331
			{';
332
333
	// If this part requires a password, make sure to give a warning.
334
	if ($context['require_password'])
335
	{
336
		echo '
337
				// Did you forget to type your password?
338
				if (document.forms.creator.oldpasswrd.value === "")
339
				{
340
					alert("', $txt['required_security_reasons'], '");
341
					return false;
342
				}';
343
	}
344
345
	// Any onsubmit javascript?
346
	if (!empty($context['profile_onsubmit_javascript']))
347
	{
348
		echo '
349
				', $context['profile_onsubmit_javascript'];
350
	}
351
352
	echo '
353
			}
354
		</script>';
355
356
	// Any final spellchecking stuff?
357
	if (!empty($context['show_spellchecking']))
358
	{
359
		echo '
360
		<form name="spell_form" id="spell_form" method="post" accept-charset="UTF-8" target="spellWindow" action="', getUrl('action', ['action' => 'spellcheck']), '">
361
			<input type="hidden" id="spellstring" name="spellstring" value="" />
362
			<input type="hidden" id="fulleditor" name="fulleditor" value="" />
363
		</form>';
364
	}
365
}
366
367
/**
368
 * All of the profile options as defined in profile.subs or via an addon
369
 */
370
function template_profile_options() {
371
	global $context;
372
373
	if (empty($context['profile_fields']))
374
	{
375
		return '';
376
	}
377
378
	// Start the big old loop 'of love.
379
	echo '
380
				<dl>';
381
382
	$lastItem = 'hr';
383
	foreach ($context['profile_fields'] as $key => $field)
384
	{
385
		// We add a little hack to be sure we never get more than one hr in a row!
386
		if ($lastItem === 'hr' && $field['type'] === 'hr')
387
		{
388
			continue;
389
		}
390
391
		$lastItem = $field['type'];
392
		if ($field['type'] === 'hr')
393
		{
394
			echo '
395
				</dl>
396
				<hr class="clear" />
397
				<dl>';
398
		}
399
		elseif ($field['type'] === 'callback')
400
		{
401
			if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
402
			{
403
				$callback_func = 'template_profile_' . $field['callback_func'];
404
				$callback_func();
405
			}
406
		}
407
		else
408
		{
409
			echo '
410
					<dt>
411
						<label', !empty($field['is_error']) ? ' class="error"' : '', ' for="' . $key . '">', $field['label'], '</label>';
412
413
			// Does it have any subtext to show?
414
			if (!empty($field['subtext']))
415
			{
416
				echo '
417
						<p class="smalltext">', $field['subtext'], '</p>';
418
			}
419
420
			echo '
421
					</dt>
422
					<dd>';
423
424
			// Want to put something in front of the box?
425
			if (!empty($field['preinput']))
426
			{
427
				echo '
428
						', $field['preinput'];
429
			}
430
431
			// What type of data are we showing?
432
			if ($field['type'] === 'label')
433
			{
434
				echo '
435
						', $field['value'];
436
			}
437
			// Maybe it's a text box - very likely!
438
			elseif (in_array($field['type'], array('int', 'float', 'text', 'password')))
439
			{
440
				echo '
441
				
442
						<input type="', $field['type'] === 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], ' class="input_', $field['type'] === 'password' ? 'password' : 'text', '" />';
443
			}
444
			// Maybe it's an html5 input
445
			elseif (in_array($field['type'], array('url', 'search', 'date', 'email', 'color')))
446
			{
447
				echo '
448
						<input type="', $field['type'], '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" ', $field['input_attr'], ' class="input_', $field['type'] == 'password' ? 'password' : 'text', '" />';
449
			}
450
			// You "checking" me out? ;)
451
			elseif ($field['type'] === 'check')
452
			{
453
				echo '
454
				<input type="hidden" name="', $key, '" value="0" /><input type="checkbox" name="', $key, '" id="', $key, '" ', !empty($field['value']) ? ' checked="checked"' : '', ' value="1" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], ' />';
455
			}
456
			// Always fun - select boxes!
457
			elseif ($field['type'] === 'select')
458
			{
459
				echo '
460
						<select name="', $key, '" id="', $key, '">';
461
462
				if (isset($field['options']))
463
				{
464
					// Is this some code to generate the options?
465
					if (!is_array($field['options']))
466
					{
467
						try
468
						{
469
							$field['options'] = eval($field['options']);
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
470
						}
471
						catch (ParseError $e)
472
						{
473
							$field['options'] = '';
474
						}
475
					}
476
477
					// Assuming we now have some!
478
					if (is_array($field['options']))
479
					{
480
						foreach ($field['options'] as $value => $name)
481
						{
482
							echo '
483
							<option value="', $value, '" ', $value == $field['value'] ? 'selected="selected"' : '', '>', $name, '</option>';
484
						}
485
					}
486
				}
487
488
				echo '
489
						</select>';
490
			}
491
492
			// Something to end with?
493
			if (!empty($field['postinput']))
494
			{
495
				echo '
496
						', $field['postinput'];
497
			}
498
499
			echo '
500
					</dd>';
501
		}
502
	}
503
504
	echo '
505
				</dl>';
506
507
	return $lastItem;
508
}
509
510
/**
511
 * Output any custom profile fields
512
 *
513
 * @param string $lastItem
514
 */
515
function template_custom_profile_options($lastItem = '')
516
{
517
	global $context;
518
519
	if (empty($context['custom_fields']))
520
	{
521
		return;
522
	}
523
524
	// Are there any custom profile fields - if so print them!
525
	if ($lastItem !== 'hr')
526
	{
527
		echo '
528
				<hr class="clear" />';
529
	}
530
531
	echo '
532
				<dl>';
533
534
	foreach ($context['custom_fields'] as $field)
535
	{
536
		echo '
537
					<dt>
538
						<strong>', $field['name'], '</strong><br />
539
						<span class="smalltext">', $field['desc'], '</span>
540
					</dt>
541
					<dd>
542
						', $field['input_html'], '
543
					</dd>';
544
	}
545
546
	echo '
547
			</dl>';
548
}
549
550
/**
551
 * Personal Message settings.
552
 */
553
function template_profile_pm_settings()
554
{
555
	global $context, $modSettings, $txt;
556
557
	echo '
558
							<dt>
559
								<label for="pm_settings">', $txt['pm_display_mode'], '</label>
560
							</dt>
561
							<dd>
562
								<select name="pm_settings" id="pm_settings">
563
									<option value="0"', $context['display_mode'] == 0 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_all'], '</option>
564
									<option value="1"', $context['display_mode'] == 1 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_one'], '</option>
565
									<option value="2"', $context['display_mode'] == 2 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_linked'], '</option>
566
								</select>
567
							</dd>
568
							<dt>
569
								<label for="view_newest_pm_first">', $txt['recent_pms_at_top'], '</label>
570
							</dt>
571
							<dd>
572
								<input type="hidden" name="default_options[view_newest_pm_first]" value="0" />
573
								<input type="checkbox" name="default_options[view_newest_pm_first]" id="view_newest_pm_first" value="1"', !empty($context['member']['options']['view_newest_pm_first']) ? ' checked="checked"' : '', ' />
574
							</dd>
575
						</dl>
576
						<dl>
577
							<dt>
578
								<label for="pm_email_notify">', $txt['email_notify'], '</label>
579
							</dt>
580
							<dd>
581
								<select name="pm_email_notify" id="pm_email_notify">
582
									<option value="0"', empty($context['send_email']) ? ' selected="selected"' : '', '>', $txt['email_notify_never'], '</option>
583
									<option value="1"', !empty($context['send_email']) && ($context['send_email'] == 1 || (empty($modSettings['enable_buddylist']) && $context['send_email'] > 1)) ? ' selected="selected"' : '', '>', $txt['email_notify_always'], '</option>';
584
585
	if (!empty($modSettings['enable_buddylist']))
586
	{
587
		echo '
588
										<option value="2"', !empty($context['send_email']) && $context['send_email'] > 1 ? ' selected="selected"' : '', '>', $txt['email_notify_buddies'], '</option>';
589
	}
590
591
	echo '
592
								</select>
593
								</dd>
594
								<dt>
595
										<label for="popup_messages">', $txt['popup_messages'], '</label>
596
								</dt>
597
								<dd>
598
										<input type="hidden" name="default_options[popup_messages]" value="0" />
599
										<input type="checkbox" name="default_options[popup_messages]" id="popup_messages" value="1"', !empty($context['member']['options']['popup_messages']) ? ' checked="checked"' : '', ' />
600
								</dd>
601
						</dl>
602
						<dl>
603
								<dt>
604
										<label for="pm_remove_inbox_label">', $txt['pm_remove_inbox_label'], '</label>
605
								</dt>
606
								<dd>
607
										<input type="hidden" name="default_options[pm_remove_inbox_label]" value="0" />
608
										<input type="checkbox" name="default_options[pm_remove_inbox_label]" id="pm_remove_inbox_label" value="1"', !empty($context['member']['options']['pm_remove_inbox_label']) ? ' checked="checked"' : '', ' />
609
								</dd>';
610
}
611
612
/**
613
 * Template for showing theme settings. Note: template_options() actually adds the theme specific options.
614
 */
615
function template_profile_theme_settings()
616
{
617
	global $context, $modSettings, $txt;
618
619
	echo '
620
							<dt>
621
								<label for="use_sidebar_menu">', $txt['use_sidebar_menu'], '</label>
622
							</dt>
623
							<dd>
624
								<input type="hidden" name="default_options[use_sidebar_menu]" value="0" />
625
								<input type="checkbox" name="default_options[use_sidebar_menu]" id="use_sidebar_menu" value="1"', !empty($context['member']['options']['use_sidebar_menu']) ? ' checked="checked"' : '', ' />
626
							</dd>
627
							<dt>
628
								<label for="use_click_menu">', $txt['use_click_menu'], '</label>
629
							</dt>
630
							<dd>
631
								<input type="hidden" name="default_options[use_click_menu]" value="0" />
632
								<input type="checkbox" name="default_options[use_click_menu]" id="use_click_menu" value="1"', !empty($context['member']['options']['use_click_menu']) ? ' checked="checked"' : '', ' />
633
							</dd>
634
							<dt>
635
								<label for="show_no_avatars">', $txt['show_no_avatars'], '</label>
636
							</dt>
637
							<dd>
638
								<input type="hidden" name="default_options[show_no_avatars]" value="0" />
639
								<input type="checkbox" name="default_options[show_no_avatars]" id="show_no_avatars" value="1"', !empty($context['member']['options']['show_no_avatars']) ? ' checked="checked"' : '', ' />
640
							</dd>
641
							<dt>
642
								<label for="hide_poster_area">', $txt['hide_poster_area'], '</label>
643
							</dt>
644
							<dd>
645
								<input type="hidden" name="default_options[hide_poster_area]" value="0" />
646
								<input type="checkbox" name="default_options[hide_poster_area]" id="hide_poster_area" value="1"', !empty($context['member']['options']['hide_poster_area']) ? ' checked="checked"' : '', ' />
647
							</dd>
648
							<dt>
649
								<label for="show_no_signatures">', $txt['show_no_signatures'], '</label>
650
							</dt>
651
							<dd>
652
								<input type="hidden" name="default_options[show_no_signatures]" value="0" />
653
								<input type="checkbox" name="default_options[show_no_signatures]" id="show_no_signatures" value="1"', !empty($context['member']['options']['show_no_signatures']) ? ' checked="checked"' : '', ' />
654
							</dd>';
655
656
	if ($context['allow_no_censored'])
657
	{
658
		echo '
659
							<dt>
660
								<label for="show_no_censored">', $txt['show_no_censored'], '</label>
661
							</dt>
662
							<dd>
663
								<input type="hidden" name="default_options[show_no_censored]" value="0" />
664
								<input type="checkbox" name="default_options[show_no_censored]" id="show_no_censored" value="1"' . (!empty($context['member']['options']['show_no_censored']) ? ' checked="checked"' : '') . ' />
665
							</dd>';
666
	}
667
668
	echo '
669
							<dt>
670
								<label for="return_to_post">', $txt['return_to_post'], '</label>
671
							</dt>
672
							<dd>
673
								<input type="hidden" name="default_options[return_to_post]" value="0" />
674
								<input type="checkbox" name="default_options[return_to_post]" id="return_to_post" value="1"', !empty($context['member']['options']['return_to_post']) ? ' checked="checked"' : '', ' />
675
							</dd>
676
							<dt>
677
								<label for="no_new_reply_warning">', $txt['no_new_reply_warning'], '</label>
678
							</dt>
679
							<dd>
680
								<input type="hidden" name="default_options[no_new_reply_warning]" value="0" />
681
								<input type="checkbox" name="default_options[no_new_reply_warning]" id="no_new_reply_warning" value="1"', !empty($context['member']['options']['no_new_reply_warning']) ? ' checked="checked"' : '', ' />
682
							</dd>
683
							<dt>
684
								<label for="wysiwyg_default">', $txt['wysiwyg_default'], '</label>
685
							</dt>
686
							<dd>
687
								<input type="hidden" name="default_options[wysiwyg_default]" value="0" />
688
								<input type="checkbox" name="default_options[wysiwyg_default]" id="wysiwyg_default" value="1"', !empty($context['member']['options']['wysiwyg_default']) ? ' checked="checked"' : '', ' />
689
							</dd>';
690
691
	if (empty($modSettings['disableCustomPerPage']))
692
	{
693
		echo '
694
							<dt>
695
								<label for="topics_per_page">', $txt['topics_per_page'], '</label>
696
							</dt>
697
							<dd>
698
								<select name="default_options[topics_per_page]" id="topics_per_page">
699
									<option value="0"', empty($context['member']['options']['topics_per_page']) ? ' selected="selected"' : '', '>', $txt['per_page_default'], ' (', $modSettings['defaultMaxTopics'], ')</option>
700
									<option value="5"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 5 ? ' selected="selected"' : '', '>5</option>
701
									<option value="10"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 10 ? ' selected="selected"' : '', '>10</option>
702
									<option value="25"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 25 ? ' selected="selected"' : '', '>25</option>
703
									<option value="50"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 50 ? ' selected="selected"' : '', '>50</option>
704
								</select>
705
							</dd>
706
							<dt>
707
								<label for="messages_per_page">', $txt['messages_per_page'], '</label>
708
							</dt>
709
							<dd>
710
								<select name="default_options[messages_per_page]" id="messages_per_page">
711
									<option value="0"', empty($context['member']['options']['messages_per_page']) ? ' selected="selected"' : '', '>', $txt['per_page_default'], ' (', $modSettings['defaultMaxMessages'], ')</option>
712
									<option value="5"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 5 ? ' selected="selected"' : '', '>5</option>
713
									<option value="10"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 10 ? ' selected="selected"' : '', '>10</option>
714
									<option value="25"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 25 ? ' selected="selected"' : '', '>25</option>
715
									<option value="50"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 50 ? ' selected="selected"' : '', '>50</option>
716
								</select>
717
							</dd>';
718
	}
719
720
	if (!empty($modSettings['cal_enabled']))
721
	{
722
		echo '
723
							<dt>
724
								<label for="calendar_start_day">', $txt['calendar_start_day'], '</label>
725
							</dt>
726
							<dd>
727
								<select name="default_options[calendar_start_day]" id="calendar_start_day">
728
									<option value="0"', empty($context['member']['options']['calendar_start_day']) ? ' selected="selected"' : '', '>', $txt['days'][0], '</option>
729
									<option value="1"', !empty($context['member']['options']['calendar_start_day']) && $context['member']['options']['calendar_start_day'] == 1 ? ' selected="selected"' : '', '>', $txt['days'][1], '</option>
730
									<option value="6"', !empty($context['member']['options']['calendar_start_day']) && $context['member']['options']['calendar_start_day'] == 6 ? ' selected="selected"' : '', '>', $txt['days'][6], '</option>
731
								</select>
732
								</dd>';
733
	}
734
735
	if (!empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_autosave_enabled']))
736
	{
737
		echo '
738
							<dt>
739
								<label for="drafts_autosave_enabled">', $txt['drafts_autosave_enabled'], '</label>
740
							</dt>
741
							<dd>
742
								<input type="hidden" name="default_options[drafts_autosave_enabled]" value="0" />
743
								<label for="drafts_autosave_enabled"><input type="checkbox" name="default_options[drafts_autosave_enabled]" id="drafts_autosave_enabled" value="1"', !empty($context['member']['options']['drafts_autosave_enabled']) ? ' checked="checked"' : '', ' /></label>
744
							</dd>';
745
	}
746
747
	echo '
748
							<dt>
749
								<label for="display_quick_reply">', $txt['display_quick_reply'], '</label>
750
							</dt>
751
							<dd>
752
								<input type="hidden" name="default_options[display_quick_reply]" value="0" />
753
								<input type="checkbox" name="default_options[display_quick_reply]" id="display_quick_reply" value="1"', !empty($context['member']['options']['display_quick_reply']) ? ' checked="checked"' : '', ' />
754
							</dd>
755
							<dt>
756
								<label for="use_editor_quick_reply">', $txt['use_editor_quick_reply'], '</label>
757
							</dt>
758
							<dd>
759
								<input type="hidden" name="default_options[use_editor_quick_reply]" value="0" />
760
								<input type="checkbox" name="default_options[use_editor_quick_reply]" id="use_editor_quick_reply" value="1"', !empty($context['member']['options']['use_editor_quick_reply']) ? ' checked="checked"' : '', ' />
761
							</dd>
762
							<dt>
763
								<label for="display_quick_mod">', $txt['display_quick_mod'], '</label>
764
							</dt>
765
							<dd>
766
								<select name="default_options[display_quick_mod]" id="display_quick_mod">
767
									<option value="0"', empty($context['member']['options']['display_quick_mod']) ? ' selected="selected"' : '', '>', $txt['display_quick_mod_none'], '</option>
768
									<option value="1"', !empty($context['member']['options']['display_quick_mod']) && $context['member']['options']['display_quick_mod'] == 1 ? ' selected="selected"' : '', '>', $txt['display_quick_mod_check'], '</option>
769
									<option value="2"', !empty($context['member']['options']['display_quick_mod']) && $context['member']['options']['display_quick_mod'] != 1 ? ' selected="selected"' : '', '>', $txt['display_quick_mod_image'], '</option>
770
								</select>
771
							</dd>';
772
}
773
774
/**
775
 * Template for setting up how and what you want to be notified about
776
 */
777
function template_action_notification()
778
{
779
	global $context, $txt, $modSettings;
780
781
	// The main containing header.
782
	echo '
783
		<form id="creator" class="flow_hidden" action="', getUrl('action', ['action' => 'profile', 'area' => 'notification']), '" method="post" accept-charset="UTF-8">
784
			<h2 class="category_header hdicon cat_img_profile">
785
				', $txt['profile'], '
786
			</h2>
787
			<p class="description">', $txt['notification_info'], '</p>
788
			<div class="content">
789
				<dl>';
790
791
	foreach ($context['mention_types'] as $type => $mention_methods)
792
	{
793
		echo '
794
					<dt>
795
						<label for="notify_', $type, '">', $txt['notify_type_' . $type], '</label>
796
					</dt>
797
					<dd>
798
						<label for="notify_', $type, '_default">', $txt['notify_method_use_default'], '</label>
799
						<input id="notify_', $type, '_default" name="', $mention_methods['default_input_name'], '" class="toggle_notify" type="checkbox" value="', $mention_methods['value'], '" ', $mention_methods['value'] ? '' : 'checked="checked"', '/>
800
						<select class="select_multiple" multiple="multiple" id="notify_', $type, '" name="', $mention_methods['default_input_name'], '[]">';
801
		foreach ($mention_methods['data'] as $key => $method)
802
		{
803
			echo '
804
							<option value="', $key, '"', $method['enabled'] ? ' selected="selected"' : '', '>', $method['text'], '</option>';
805
		}
806
807
		echo '
808
						</select>';
809
810
		echo '
811
					</dd>';
812
	}
813
814
	echo '
815
				</dl>
816
				<dl>';
817
818
	// Allow notification on announcements to be disabled?
819
	if (!empty($modSettings['allow_disableAnnounce']))
820
	{
821
		echo '
822
					<dt>
823
						<label for="notify_announcements">', $txt['notify_important_email'], '</label>
824
					</dt>
825
					<dd>
826
						<input type="hidden" name="notify_announcements" value="0" />
827
						<input type="checkbox" id="notify_announcements" name="notify_announcements"', !empty($context['member']['notify_announcements']) ? ' checked="checked"' : '', ' />
828
					</dd>';
829
	}
830
831
	// Auto notification when you reply / start a topic?
832
	echo '
833
					<dt>
834
						<label for="auto_notify">', $txt['auto_notify'], '</label>
835
					</dt>
836
					<dd>
837
						<input type="hidden" name="default_options[auto_notify]" value="0" />
838
						<input type="checkbox" id="auto_notify" name="default_options[auto_notify]" value="1"', !empty($context['member']['options']['auto_notify']) ? ' checked="checked"' : '', ' />
839
						', (!empty($modSettings['maillist_enabled']) ? $txt['auto_notify_pbe_post'] : ''), '
840
					</dd>';
841
842
	// Can the body of the post be sent, PBE will ensure it can
843
	if (empty($modSettings['disallow_sendBody']))
844
	{
845
		echo '
846
					<dt>
847
						<label for="notify_send_body">', $txt['notify_send_body' . (!empty($modSettings['maillist_enabled']) ? '_pbe' : '')], '</label>
848
					</dt>
849
					<dd>
850
						<input type="hidden" name="notify_send_body" value="0" />
851
						<input type="checkbox" id="notify_send_body" name="notify_send_body"', !empty($context['member']['notify_send_body']) ? ' checked="checked"' : '', ' />
852
						', (!empty($modSettings['maillist_enabled']) ? $txt['notify_send_body_pbe_post'] : ''), '
853
					</dd>';
854
	}
855
856
	// How often do you want to hear from us, instant, daily, weekly?
857
	echo '
858
					<dt>
859
						<label for="notify_regularity">', $txt['notify_regularity'], '</label>
860
					</dt>
861
					<dd>
862
						<select name="notify_regularity" id="notify_regularity">
863
							<option value="0"', $context['member']['notify_regularity'] == 0 ? ' selected="selected"' : '', '>', $txt['notify_regularity_instant'], '</option>
864
							<option value="1"', $context['member']['notify_regularity'] == 1 ? ' selected="selected"' : '', '>', $txt['notify_regularity_first_only'], '</option>
865
							<option value="2"', $context['member']['notify_regularity'] == 2 ? ' selected="selected"' : '', '>', $txt['notify_regularity_daily'], '</option>
866
							<option value="3"', $context['member']['notify_regularity'] == 3 ? ' selected="selected"' : '', '>', $txt['notify_regularity_weekly'], '</option>
867
							<option value="99"', $context['member']['notify_regularity'] == 99 ? ' selected="selected"' : '', '>', $txt['notify_regularity_none'], '</option>
868
						</select>
869
					</dd>
870
					<dt>
871
						<label for="notify_types">', $txt['notify_send_types'], '</label>
872
					</dt>
873
					<dd>
874
						<select name="notify_types" id="notify_types">';
875
876
	// Using the maillist functions, then limit the options so they make sense
877
	if (empty($modSettings['maillist_enabled']) || (empty($modSettings['pbe_no_mod_notices']) && !empty($modSettings['maillist_enabled'])))
878
	{
879
		echo '
880
							<option value="1"', $context['member']['notify_types'] == 1 ? ' selected="selected"' : '', '>', $txt['notify_send_type_everything'], '</option>
881
							<option value="2"', $context['member']['notify_types'] == 2 ? ' selected="selected"' : '', '>', $txt['notify_send_type_everything_own'], '</option>';
882
	}
883
884
	echo '
885
							<option value="3"', $context['member']['notify_types'] == 3 ? ' selected="selected"' : '', '>', $txt['notify_send_type_only_replies' . (!empty($modSettings['maillist_enabled']) ? '_pbe' : '')], '</option>
886
							<option value="4"', $context['member']['notify_types'] == 4 ? ' selected="selected"' : '', '>', $txt['notify_send_type_nothing'], '</option>
887
						</select>
888
					</dd>
889
				</dl>
890
				<div class="submitbutton">
891
					<input id="notify_submit" name="notify_submit" type="submit" value="', $txt['notify_save'], '" />
892
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />', !empty($context['token_check']) ? '
893
					<input type="hidden" name="' . $context[$context['token_check'] . '_token_var'] . '" value="' . $context[$context['token_check'] . '_token'] . '" />' : '', '
894
					<input type="hidden" name="u" value="', $context['id_member'], '" />
895
					<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
896
					<input type="hidden" name="save" value="save" />
897
				</div>
898
			</div>
899
		</form>';
900
901
	// Show the boards you have on notify
902
	template_show_list('board_notification_list');
903
904
	echo '
905
		<br />';
906
907
	// And any topics you are watching as well
908
	template_show_list('topic_notification_list');
909
}
910
911
/**
912
 * Template for choosing group membership.
913
 */
914
function template_groupMembership()
915
{
916
	global $context, $txt;
917
918
	// The main containing header.
919
	echo '
920
		<form action="', getUrl('action', ['action' => 'profile', 'area' => 'groupmembership']), '" method="post" accept-charset="UTF-8" name="creator" id="creator">
921
			<h2 class="category_header hdicon cat_img_profile">
922
				', $txt['profile'], '
923
			</h2>
924
			<p class="description">', $txt['groupMembership_info'], '</p>';
925
926
	// Do we have an update message?
927
	if (!empty($context['update_message']))
928
	{
929
		echo '
930
			<div class="successbox">
931
				', $context['update_message'], '
932
			</div>';
933
	}
934
935
	// Requesting membership to a group?
936
	if (!empty($context['group_request']))
937
	{
938
		echo '
939
			<div class="groupmembership">
940
				<h2 class="category_header">', $txt['request_group_membership'], '</h2>
941
				<div class="well">
942
					', $txt['request_group_membership_desc'], ':
943
					<textarea name="reason" rows="4" style="width: 99%;"></textarea>
944
					<div class="submitbutton">
945
						<input type="hidden" name="gid" value="', $context['group_request']['id'], '" />
946
						<input type="submit" name="req" value="', $txt['submit_request'], '" />
947
					</div>
948
				</div>
949
			</div>';
950
	}
951
	else
952
	{
953
		echo '
954
			<table class="table_grid">
955
				<thead>
956
					<tr class="table_head">
957
						<th scope="col" ', $context['can_edit_primary'] ? ' colspan="2"' : '', '>', $txt['current_membergroups'], '</th>
958
						<th scope="col"></th>
959
					</tr>
960
				</thead>
961
				<tbody>';
962
963
		foreach ($context['groups']['member'] as $group)
964
		{
965
			echo '
966
					<tr  id="primdiv_', $group['id'], '">';
967
968
			if ($context['can_edit_primary'])
969
			{
970
				echo '
971
						<td>
972
							<input type="radio" name="primary" id="primary_', $group['id'], '" value="', $group['id'], '" ', $group['is_primary'] ? 'checked="checked" ' : '', $group['can_be_primary'] ? '' : 'disabled="disabled" ', ' />
973
						</td>';
974
			}
975
976
			echo '
977
						<td>
978
							<label for="primary_', $group['id'], '">
979
								<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br /><span class="smalltext">' . $group['desc'] . '</span>' : ''), '
980
							</label>
981
						</td>
982
						<td class="grid17 righttext">';
983
984
			// Can they leave their group?
985
			if ($group['can_leave'])
986
			{
987
				echo '
988
							<a class="linkbutton" href="' . getUrl('action', ['action' => 'profile', 'save', 'u' => $context['id_member'], 'area' => 'groupmembership', '{session_data}', 'gid' => $group['id'], $context[$context['token_check'] . '_token_var'] => $context[$context['token_check'] . '_token']]), '">' . $txt['leave_group'] . '</a>';
989
			}
990
991
			echo '
992
						</td>
993
					</tr>';
994
		}
995
996
		echo '
997
				</tbody>
998
			</table>';
999
1000
		if ($context['can_edit_primary'])
1001
		{
1002
			echo '
1003
			<div class="submitbutton">
1004
				<input type="submit" value="', $txt['make_primary'], '" />
1005
			</div>';
1006
		}
1007
1008
		// Any groups they can join?
1009
		if (!empty($context['groups']['available']))
1010
		{
1011
			echo '
1012
			<br />
1013
			<table class="table_grid">
1014
				<thead>
1015
					<tr class="table_head">
1016
						<th scope="col">
1017
							', $txt['available_groups'], '
1018
						</th>
1019
						<th scope="col"></th>
1020
					</tr>
1021
				</thead>
1022
				<tbody>';
1023
1024
			foreach ($context['groups']['available'] as $group)
1025
			{
1026
				echo '
1027
					<tr>
1028
						<td>
1029
							<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br /><span class="smalltext">' . $group['desc'] . '</span>' : ''), '
1030
						</td>
1031
						<td class="lefttext">';
1032
1033
				if ($group['type'] == 3)
1034
				{
1035
					echo '
1036
							<a class="linkbutton floatright" href="', getUrl('action', ['action' => 'profile', 'save', 'u' => $context['id_member'], 'area' => 'groupmembership', '{session_data}', 'gid' => $group['id'], $context[$context['token_check'] . '_token_var'] => $context[$context['token_check'] . '_token']]), '">', $txt['join_group'], '</a>';
1037
				}
1038
				elseif ($group['type'] == 2 && $group['pending'])
1039
				{
1040
					echo '
1041
							', $txt['approval_pending'];
1042
				}
1043
				elseif ($group['type'] == 2)
1044
				{
1045
					echo '
1046
							<a class="linkbutton floatright" href="', getUrl('action', ['action' => 'profile', 'u' => $context['id_member'], 'area' => 'groupmembership', 'request' => $group['id'], '{session_data}']), '">', $txt['request_group'], '</a>';
1047
				}
1048
// @todo
1049
//				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
1050
1051
				echo '
1052
						</td>
1053
					</tr>';
1054
			}
1055
1056
			echo '
1057
				</tbody>
1058
			</table>';
1059
		}
1060
1061
		// Javascript for the selector stuff.
1062
		echo '
1063
		<script>
1064
			var prevClass = "",
1065
				prevDiv = "";';
1066
1067
		if (isset($context['groups']['member'][$context['primary_group']]))
1068
		{
1069
			echo '
1070
			initHighlightSelection("primdiv_' . $context['primary_group'] . '");';
1071
		}
1072
1073
		echo '
1074
		</script>';
1075
	}
1076
1077
	if (!empty($context['token_check']))
1078
	{
1079
		echo '
1080
				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
1081
	}
1082
1083
	echo '
1084
				<input type="hidden" name="save" value="save" />
1085
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
1086
				<input type="hidden" name="u" value="', $context['id_member'], '" />
1087
			</form>';
1088
}
1089
1090
/**
1091
 * Display a list of boards so a user can choose to ignore some
1092
 */
1093
function template_ignoreboards()
1094
{
1095
	global $txt;
1096
1097
	// The main containing header.
1098
	echo '
1099
	<form id="creator" action="', getUrl('action', ['action' => 'profile', 'area' => 'ignoreboards']), '" method="post" accept-charset="UTF-8" name="creator">
1100
		<h2 class="category_header hdicon cat_img_profile">
1101
			', $txt['profile'], '
1102
		</h2>
1103
		<p class="description">', $txt['ignoreboards_info'], '</p>
1104
		<div class="content flow_hidden">';
1105
1106
	template_pick_boards('creator', 'ignore_brd', false);
1107
1108
	// Show the standard "Save Settings" profile button.
1109
	template_profile_save();
1110
1111
	echo '
1112
			<input type="hidden" name="save" value="save" />
1113
		</div>
1114
	</form>
1115
	<br />';
1116
}
1117
1118
/**
1119
 * Display a load of drop down selectors for allowing the user to change group.
1120
 */
1121
function template_profile_group_manage()
1122
{
1123
	global $context, $txt;
1124
1125
	echo '
1126
							<dt>
1127
								<label>', $txt['primary_membergroup'], '</label>
1128
								<p class="smalltext">[<a href="', getUrl('action', ['action' => 'quickhelp', 'help' => 'moderator_why_missing']), '" onclick="return reqOverlayDiv(this.href);">', $txt['moderator_why_missing'], '</a>]</p>
1129
							</dt>
1130
							<dd>
1131
								<select name="id_group" ', ($context['user']['is_owner'] && $context['member']['group_id'] == 1 ? 'onchange="if (this.value != 1 &amp;&amp; !confirm(\'' . $txt['deadmin_confirm'] . '\')) this.value = 1;"' : ''), '>';
1132
1133
	// Fill the select box with all primary membergroups that can be assigned to a member.
1134
	foreach ($context['member_groups'] as $member_group)
1135
	{
1136
		if (!empty($member_group['can_be_primary']))
1137
		{
1138
			echo '
1139
									<option value="', $member_group['id'], '"', $member_group['is_primary'] ? ' selected="selected"' : '', '>
1140
										', $member_group['name'], '
1141
									</option>';
1142
		}
1143
	}
1144
1145
	echo '
1146
								</select>
1147
							</dd>
1148
							<dt>
1149
								<label>', $txt['additional_membergroups'], '</label>
1150
							</dt>
1151
							<dd>
1152
								<input type="hidden" name="additional_groups[]" value="0" />
1153
								<fieldset id="additional_groupsList">
1154
									<legend data-collapsed="true">', $txt['additional_membergroups_show'], '</legend>
1155
									<ul>';
1156
1157
	// For each membergroup show a checkbox so members can be assigned to more than one group.
1158
	foreach ($context['member_groups'] as $member_group)
1159
	{
1160
		if ($member_group['can_be_additional'])
1161
		{
1162
			echo '
1163
										<li>
1164
											<label for="additional_groups-', $member_group['id'], '"><input type="checkbox" name="additional_groups[]" value="', $member_group['id'], '" id="additional_groups-', $member_group['id'], '"', $member_group['is_additional'] ? ' checked="checked"' : '', ' /> ', $member_group['name'], '</label>
1165
										</li>';
1166
		}
1167
	}
1168
1169
	echo '
1170
									</ul>
1171
								</fieldset>
1172
							</dd>';
1173
}
1174
1175
/**
1176
 * Callback function for entering a birth date!
1177
 */
1178
function template_profile_birthdate()
1179
{
1180
	global $txt, $context;
1181
1182
	// Just show the pretty box!
1183
	echo '
1184
							<dt>
1185
								<label>', $txt['dob'], '</label>
1186
								<p class="smalltext">', $txt['dob_year'], ' - ', $txt['dob_month'], ' - ', $txt['dob_day'], '</p>
1187
							</dt>
1188
							<dd>
1189
								<input type="text" name="bday3" size="4" maxlength="4" value="', $context['member']['birth_date']['year'], '" class="input_text" /> -
1190
								<input type="text" name="bday1" size="2" maxlength="2" value="', $context['member']['birth_date']['month'], '" class="input_text" /> -
1191
								<input type="text" name="bday2" size="2" maxlength="2" value="', $context['member']['birth_date']['day'], '" class="input_text" />
1192
							</dd>';
1193
}
1194
1195
/**
1196
 * Show the signature editing box.
1197
 */
1198
function template_profile_signature_modify()
1199
{
1200
	global $txt, $context;
1201
1202
	echo '
1203
							<dt id="current_signature"', !isset($context['member']['current_signature']) ? ' class="hide"' : '', '>
1204
								<label>', $txt['current_signature'], ':</label>
1205
							</dt>
1206
							<dd id="current_signature_display"', !isset($context['member']['current_signature']) ? ' class="hide"' : '', '>
1207
								', $context['member']['current_signature'] ?? '', '<hr />
1208
							</dd>
1209
1210
							<dt id="preview_signature"', !isset($context['member']['signature_preview']) ? ' class="hide"' : '', '>
1211
								<label>', $txt['signature_preview'], ':</label>
1212
							</dt>
1213
							<dd id="preview_signature_display"', !isset($context['member']['signature_preview']) ? ' class="hide"' : '', '>
1214
								', $context['member']['signature_preview'] ?? '', '<hr />
1215
							</dd>
1216
							<dt>
1217
								<label>', $txt['signature'], '</label>
1218
								<p class="smalltext">', $txt['sig_info'], '</p>
1219
							</dt>
1220
							<dd>
1221
								<textarea class="editor" onkeyup="calcCharLeft();" id="signature" name="signature" rows="5" cols="50" style="min-width: 50%; width: 99%;">', $context['member']['signature'], '</textarea>';
1222
1223
	// If there is a limit at all!
1224
	if (!empty($context['signature_limits']['max_length']))
1225
	{
1226
		echo '
1227
								<p class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></p>';
1228
	}
1229
1230
	if ($context['show_spellchecking'])
1231
	{
1232
		echo '
1233
								<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\', false);"  tabindex="', $context['tabindex']++, '" class="right_submit" />';
1234
	}
1235
1236
	if (!empty($context['show_preview_button']))
1237
	{
1238
		echo '
1239
								<input type="submit" name="preview_signature" id="preview_button" value="', $txt['preview_signature'], '"  tabindex="', $context['tabindex']++, '" class="right_submit" />';
1240
	}
1241
1242
	if ($context['signature_warning'])
1243
	{
1244
		echo '
1245
								<span class="smalltext">', $context['signature_warning'], '</span>';
1246
	}
1247
1248
	// Some javascript used to count how many characters have been used so far in the signature.
1249
	echo '
1250
								<script>
1251
									var maxLength = ', $context['signature_limits']['max_length'], ';
1252
1253
									$(function() {
1254
										calcCharLeft();
1255
										$("#preview_button").click(function() {
1256
											return ajax_getSignaturePreview(true);
1257
										});
1258
									});
1259
								</script>
1260
							</dd>';
1261
}
1262
1263
/**
1264
 * Interface to select an avatar in profile.
1265
 */
1266
function template_profile_avatar_select()
1267
{
1268
	global $context, $txt, $modSettings;
1269
1270
	// Start with left side menu
1271
	echo '
1272
							<dt>
1273
								<label id="personal_picture">', $txt['personal_picture'], '</label>
1274
								<ul id="avatar_choices">
1275
									<li>
1276
										<input type="radio" onclick="swap_avatar();" name="avatar_choice" id="avatar_choice_none" value="none"' . ($context['member']['avatar']['choice'] == 'none' ? ' checked="checked"' : '') . ' />
1277
										<label for="avatar_choice_none"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>
1278
											' . $txt['no_avatar'] . '
1279
										</label>
1280
									</li>', !empty($context['member']['avatar']['allow_server_stored']) ? '
1281
									<li>
1282
										<input type="radio" onclick="swap_avatar();" name="avatar_choice" id="avatar_choice_server_stored" value="server_stored"' . ($context['member']['avatar']['choice'] == 'server_stored' ? ' checked="checked"' : '') . ' />
1283
										<label for="avatar_choice_server_stored"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>
1284
											' . $txt['choose_avatar_gallery'] . '
1285
										</label>
1286
									</li>' : '', !empty($context['member']['avatar']['allow_external']) ? '
1287
									<li>
1288
										<input type="radio" onclick="swap_avatar();" name="avatar_choice" id="avatar_choice_external" value="external"' . ($context['member']['avatar']['choice'] == 'external' ? ' checked="checked"' : '') . ' />
1289
										<label for="avatar_choice_external"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>
1290
											' . $txt['my_own_pic'] . '
1291
										</label>
1292
									</li>' : '', !empty($context['member']['avatar']['allow_gravatar']) ? '
1293
									<li>
1294
										<input type="radio" onclick="swap_avatar();" name="avatar_choice" id="avatar_choice_gravatar" value="gravatar"' . ($context['member']['avatar']['choice'] == 'gravatar' ? ' checked="checked"' : '') . ' />
1295
										<label for="avatar_choice_gravatar"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>
1296
											' . $txt['gravatar'] . '
1297
										</label>
1298
									</li>' : '', !empty($context['member']['avatar']['allow_upload']) ? '
1299
									<li>
1300
										<input type="radio" onclick="swap_avatar();" name="avatar_choice" id="avatar_choice_upload" value="upload"' . ($context['member']['avatar']['choice'] == 'upload' ? ' checked="checked"' : '') . ' />
1301
										<label for="avatar_choice_upload"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>
1302
											' . $txt['avatar_will_upload'] . '
1303
										</label>
1304
									</li>' : '', '
1305
								</ul>
1306
							</dt>
1307
							<dd>';
1308
1309
	// If users are allowed to choose avatars stored on the server show the selection boxes to choose them.
1310
	if (!empty($context['member']['avatar']['allow_server_stored']))
1311
	{
1312
		echo '
1313
								<div id="avatar_server_stored">
1314
									<div>
1315
										<select name="cat" id="cat" size="10" onchange="changeSel(\'\');">';
1316
1317
		// This lists all the file categories.
1318
		foreach ($context['avatars'] as $avatar)
1319
		{
1320
			echo '
1321
											<option value="', $avatar['filename'] . ($avatar['is_dir'] ? '/' : ''), '"', ($avatar['checked'] ? ' selected="selected"' : ''), '>', $avatar['name'], '</option>';
1322
		}
1323
1324
		echo '
1325
										</select>
1326
									</div>
1327
									<div>
1328
										<select id="file" name="file" size="10" class="hide" onchange="showAvatar()" disabled="disabled">
1329
											<option> </option>
1330
										</select>
1331
									</div>
1332
									<div>
1333
										<img id="avatar" src="', $modSettings['avatar_url'] . '/blank.png', '" alt="" />
1334
									</div>
1335
								</div>';
1336
	}
1337
1338
	// If the user can link to an off server avatar, show them a box to input the address.
1339
	if (!empty($context['member']['avatar']['allow_external']))
1340
	{
1341
		echo '
1342
								<div id="avatar_external">
1343
									<div class="smalltext">
1344
										<label for="userpicpersonal">', $txt['avatar_by_url'], '</label>
1345
									</div>
1346
									<input type="text" id="userpicpersonal" name="userpicpersonal" value="', $context['member']['avatar']['external'], '" onchange="previewExternalAvatar(this.value);" class="input_text" />
1347
									<br /><br />
1348
									<img id="external" src="', !empty($context['member']['avatar']['allow_external']) && $context['member']['avatar']['choice'] == 'external' ? $context['member']['avatar']['external'] : $modSettings['avatar_url'] . '/blank.png', '" alt="" ', !empty($modSettings['avatar_max_height']) ? 'height="' . $modSettings['avatar_max_height'] . '" ' : '', !empty($modSettings['avatar_max_width']) ? 'width="' . $modSettings['avatar_max_width'] . '"' : '', '/>
1349
								</div>';
1350
	}
1351
1352
	// If the user is allowed to use a Gravatar.
1353
	if (!empty($context['member']['avatar']['allow_gravatar']))
1354
	{
1355
		echo '
1356
								<div id="avatar_gravatar">
1357
									<img src="' . $context['member']['avatar']['gravatar_preview'] . '" alt="" />
1358
								</div>';
1359
	}
1360
1361
	// If the user is able to upload avatars to the server show them an upload box.
1362
	if (!empty($context['member']['avatar']['allow_upload']))
1363
	{
1364
		echo '
1365
								<div id="avatar_upload">
1366
									<input type="file" name="attachment" id="avatar_upload_box" class="input_file" />
1367
									', ($context['member']['avatar']['id_attach'] > 0 ? '
1368
									<br /><br />
1369
									<img src="' . $context['member']['avatar']['href'] . (strpos($context['member']['avatar']['href'], '?') === false ? '?' : '&') . 'time=' . time() . '" alt="" />
1370
									<input type="hidden" name="id_attach" value="' . $context['member']['avatar']['id_attach'] . '" />' : ''), '
1371
								</div>';
1372
	}
1373
1374
	echo '
1375
								<script>
1376
									var files = ["' . implode('", "', $context['avatar_list']) . '"],
1377
										cat = document.getElementById("cat"),
1378
										file = document.getElementById("file"),
1379
										selavatar = "' . $context['avatar_selected'] . '",
1380
										avatardir = "' . $modSettings['avatar_url'] . '/",
1381
										refuse_too_large = ', !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_refuse' ? 'true' : 'false', ',
1382
										maxHeight = ', !empty($modSettings['avatar_max_height']) ? $modSettings['avatar_max_height'] : 0, ',
1383
										maxWidth = ', !empty($modSettings['avatar_max_width']) ? $modSettings['avatar_max_width'] : 0, ';
1384
1385
									// Display the right avatar box based on what they are using
1386
									init_avatars();
1387
								</script>
1388
							</dd>';
1389
}
1390
1391
/**
1392
 * Callback for modifying karma.
1393
 */
1394
function template_profile_karma_modify()
1395
{
1396
	global $context, $modSettings, $txt;
1397
1398
	echo '
1399
							<dt>
1400
								<label>', $modSettings['karmaLabel'], '</label>
1401
							</dt>
1402
							<dd>
1403
								<label for="karma_good">', $modSettings['karmaApplaudLabel'], '</label> <input type="text" id="karma_good" name="karma_good" size="4" value="', $context['member']['karma']['good'], '" style="margin-right: 2ex;" class="input_text" />
1404
								<label for="karma_bad">', $modSettings['karmaSmiteLabel'], '</label> <input type="text" id="karma_bad" name="karma_bad" size="4" value="', $context['member']['karma']['bad'], '" class="input_text" /><br />
1405
								(', $txt['total'], ': <span id="karmaTotal">', ($context['member']['karma']['good'] - $context['member']['karma']['bad']), '</span>)
1406
							</dd>';
1407
}
1408
1409
/**
1410
 * Select the time format!.
1411
 */
1412
function template_profile_timeformat_modify()
1413
{
1414
	global $context, $txt;
1415
1416
	echo '
1417
							<dt>
1418
								<label for="easyformat">', $txt['time_format'], '</label>
1419
								<p>
1420
									<a href="', getUrl('action', ['action' => 'quickhelp', 'help' => 'time_format']), '" onclick="return reqOverlayDiv(this.href);" class="helpicon i-help"><s>', $txt['help'], '</s></a>
1421
									&nbsp;', $txt['date_format'], '
1422
								</p>
1423
							</dt>
1424
							<dd>
1425
								<select name="easyformat" id="easyformat" onchange="document.forms.creator.time_format.value = this.options[this.selectedIndex].value;" style="margin-bottom: 4px;">';
1426
1427
	// Help the user by showing a list of common time formats.
1428
	foreach ($context['easy_timeformats'] as $time_format)
1429
	{
1430
		echo '
1431
									<option value="', $time_format['format'], '"', $time_format['format'] == $context['member']['time_format'] ? ' selected="selected"' : '', '>', $time_format['title'], '</option>';
1432
	}
1433
1434
	echo '
1435
								</select>
1436
								<br />
1437
								<input type="text" name="time_format" id="time_format" value="', $context['member']['time_format'], '" size="30" class="input_text" />
1438
							</dd>';
1439
}
1440
1441
/**
1442
 * Time offset.
1443
 */
1444
function template_profile_timeoffset_modify()
1445
{
1446
	global $txt, $context;
1447
1448
	echo '
1449
							<dt>
1450
								<label', (isset($context['modify_error']['bad_offset']) ? ' class="error"' : ''), ' for="time_offset">', $txt['time_offset'], '</label>
1451
								<p>', $txt['personal_time_offset'], '</p>
1452
							</dt>
1453
							<dd>
1454
								<input type="text" name="time_offset" id="time_offset" size="5" maxlength="5" value="', $context['member']['time_offset'], '" class="input_text" /> ', $txt['hours'], ' <a class="linkbutton" href="javascript:void(0);" onclick="currentDate = new Date(', $context['current_forum_time_js'], '); document.getElementById(\'time_offset\').value = autoDetectTimeOffset(currentDate); return false;">', $txt['timeoffset_autodetect'], '</a><br />', $txt['current_time'], ': <em>', $context['current_forum_time'], '</em>
1455
							</dd>';
1456
}
1457
1458
/**
1459
 * Interface to allow the member to pick a theme.
1460
 */
1461
function template_profile_theme_pick()
1462
{
1463
	global $txt, $context;
1464
1465
	echo '
1466
							<dt>
1467
								<label>', $txt['current_theme'], '</label>
1468
							</dt>
1469
							<dd>
1470
								', $context['member']['theme']['name'], ' <a class="linkbutton" href="', getUrl('action', ['action' => 'theme', 'sa' => 'pick', 'u' => $context['id_member'], '{session_data}']), '">', $txt['change'], '</a>
1471
							</dd>';
1472
}
1473
1474
/**
1475
 * Smiley set picker.
1476
 */
1477
function template_profile_smiley_pick()
1478
{
1479
	global $txt, $context, $modSettings, $settings;
1480
1481
	echo '
1482
							<dt>
1483
								<label for="smiley_set">', $txt['smileys_current'], '</label>
1484
							</dt>
1485
							<dd>
1486
								<select name="smiley_set" id="smiley_set" onchange="document.getElementById(\'smileypr\').src = this.selectedIndex == 0 ? \'', $settings['images_url'], '/blank.png\' : \'', $modSettings['smileys_url'], '/\' + (this.selectedIndex != 1 ? this.options[this.selectedIndex].value : \'', !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'], '\') + \'/smiley.gif\';">';
1487
1488
	foreach ($context['smiley_sets'] as $set)
1489
	{
1490
		echo '
1491
									<option value="', $set['id'], '"', $set['selected'] ? ' selected="selected"' : '', '>', $set['name'], '</option>';
1492
	}
1493
1494
	echo '
1495
								</select>
1496
								<img id="smileypr" class="icon-middle" src="', $context['member']['smiley_set']['id'] != 'none' ? $modSettings['smileys_url'] . '/' . ($context['member']['smiley_set']['id'] != '' ? $context['member']['smiley_set']['id'] : (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'])) . '/smiley.gif' : $settings['images_url'] . '/blank.png', '" alt=":)"  style="padding-left: 1.25em;" />
1497
							</dd>';
1498
}
1499
1500
/**
1501
 * Interface to allow the member to change the way they login to the forum.
1502
 */
1503
function template_authentication_method()
1504
{
1505
	global $context, $modSettings, $txt;
1506
1507
	// The main header!
1508
	echo '
1509
		<form action="', getUrl('action', ['action' => 'profile', 'area' => 'authentication']), '" method="post" accept-charset="UTF-8" name="creator" id="creator" enctype="multipart/form-data">
1510
			<h2 class="category_header hdicon cat_img_profile">
1511
				', $txt['authentication'], '
1512
			</h2>
1513
			<p class="description">', $txt['change_authentication'], '</p>
1514
			<div class="content">
1515
				<dl>
1516
					<dt>
1517
						<input type="radio" name="authenticate" value="passwd" id="auth_pass"', $context['auth_method'] == 'password' ? ' checked="checked"' : '', ' />
1518
						<label for="auth_pass">', $txt['authenticate_password'], '</label>
1519
					</dt>
1520
					<dd>
1521
						<dl id="password1_group">
1522
							<dt>
1523
								<em>', $txt['choose_pass'], ':</em>
1524
							</dt>
1525
							<dd>
1526
								<input type="password" name="passwrd1" id="elk_autov_pwmain" size="30" tabindex="', $context['tabindex']++, '" class="input_password" placeholder="', $txt['choose_pass'], '" />
1527
								<span id="elk_autov_pwmain_div" class="hide">
1528
									<i id="elk_autov_pwmain_img" class="icon i-warn" alt="*"></i>
1529
								</span>
1530
							</dd>
1531
						</dl>
1532
						<dl id="password2_group">
1533
							<dt>
1534
								<em for="elk_autov_pwverify">', $txt['verify_pass'], ':</em>
1535
							</dt>
1536
							<dd>
1537
								<input type="password" name="passwrd2" id="elk_autov_pwverify" size="30" tabindex="', $context['tabindex']++, '" class="input_password" placeholder="', $txt['verify_pass'], '" />
1538
								<span id="elk_autov_pwverify_div" class="hide">
1539
									<i id="elk_autov_pwverify_img" class="icon i-warn" alt="*"></i>
1540
								</span>
1541
							</dd>
1542
						</dl>
1543
					</dd>
1544
				</dl>';
1545
1546
	template_profile_save();
1547
1548
	echo '
1549
				<input type="hidden" name="save" value="save" />
1550
			</div>
1551
		</form>';
1552
1553
	// The password stuff.
1554
	echo '
1555
	<script>
1556
		var regTextStrings = {
1557
			"password_short": "', $txt['registration_password_short'], '",
1558
			"password_reserved": "', $txt['registration_password_reserved'], '",
1559
			"password_numbercase": "', $txt['registration_password_numbercase'], '",
1560
			"password_no_match": "', $txt['registration_password_no_match'], '",
1561
			"password_valid": "', $txt['registration_password_valid'], '"
1562
		};
1563
		var verificationHandle = new elkRegister("creator", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
1564
1565
	</script>';
1566
}
1567