template_edit_group()   F
last analyzed

Complexity

Conditions 41
Paths 2304

Size

Total Lines 272
Code Lines 100

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 41
eloc 100
nop 0
dl 0
loc 272
rs 0
c 0
b 0
f 0
nc 2304

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
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2019 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 RC2
11
 */
12
13
/**
14
 * The main page listing all the groups.
15
 */
16
function template_main()
17
{
18
	template_show_list('regular_membergroups_list');
19
20
	echo '<br><br>';
21
22
	template_show_list('post_count_membergroups_list');
23
}
24
25
/**
26
 * Add a new membergroup.
27
 */
28
function template_new_group()
29
{
30
	global $context, $scripturl, $txt, $modSettings;
31
32
	echo '
33
		<form id="new_group" action="', $scripturl, '?action=admin;area=membergroups;sa=add" method="post" accept-charset="', $context['character_set'], '">
34
			<div class="cat_bar">
35
				<h3 class="catbg">', $txt['membergroups_new_group'], '</h3>
36
			</div>
37
			<div class="windowbg">
38
				<dl class="settings">
39
					<dt>
40
						<label for="group_name_input"><strong>', $txt['membergroups_group_name'], ':</strong></label>
41
					</dt>
42
					<dd>
43
						<input type="text" name="group_name" id="group_name_input" size="30">
44
					</dd>';
45
46
	if ($context['undefined_group'])
47
	{
48
		echo '
49
					<dt>
50
						<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], '</strong>:</label>
51
					</dt>
52
					<dd>
53
						<fieldset id="group_type">
54
							<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
55
							<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" checked onclick="swapPostGroup(0);">', $txt['membergroups_group_type_private'], '</label><br>';
56
57
		if ($context['allow_protected'])
58
			echo '
59
							<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" onclick="swapPostGroup(0);">', $txt['membergroups_group_type_protected'], '</label><br>';
60
61
		echo '
62
							<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" onclick="swapPostGroup(0);">', $txt['membergroups_group_type_request'], '</label><br>
63
							<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" onclick="swapPostGroup(0);">', $txt['membergroups_group_type_free'], '</label><br>
64
							<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" onclick="swapPostGroup(1);">', $txt['membergroups_group_type_post'], '</label><br>
65
						</fieldset>
66
					</dd>';
67
	}
68
69
	if ($context['post_group'] || $context['undefined_group'])
70
		echo '
71
					<dt id="min_posts_text">
72
						<strong>', $txt['membergroups_min_posts'], ':</strong>
73
					</dt>
74
					<dd>
75
						<input type="number" name="min_posts" id="min_posts_input" size="5">
76
					</dd>';
77
78
	if (!$context['post_group'] || !empty($modSettings['permission_enable_postgroups']))
79
	{
80
		echo '
81
					<dt>
82
						<label for="permission_base"><strong>', $txt['membergroups_permissions'], ':</strong></label><br>
83
						<span class="smalltext">', $txt['membergroups_can_edit_later'], '</span>
84
					</dt>
85
					<dd>
86
						<fieldset id="permission_base">
87
							<legend>', $txt['membergroups_select_permission_type'], '</legend>
88
							<input type="radio" name="perm_type" id="perm_type_inherit" value="inherit" checked>
89
							<label for="perm_type_inherit">', $txt['membergroups_new_as_inherit'], ':</label>
90
							<select name="inheritperm" id="inheritperm_select" onclick="document.getElementById(\'perm_type_inherit\').checked = true;">
91
								<option value="-1">', $txt['membergroups_guests'], '</option>
92
								<option value="0" selected>', $txt['membergroups_members'], '</option>';
93
94
		foreach ($context['groups'] as $group)
95
			echo '
96
								<option value="', $group['id'], '">', $group['name'], '</option>';
97
98
		echo '
99
							</select>
100
							<br>
101
							<input type="radio" name="perm_type" id="perm_type_copy" value="copy">
102
							<label for="perm_type_copy">', $txt['membergroups_new_as_copy'], ':</label>
103
							<select name="copyperm" id="copyperm_select" onclick="document.getElementById(\'perm_type_copy\').checked = true;">
104
								<option value="-1">', $txt['membergroups_guests'], '</option>
105
								<option value="0" selected>', $txt['membergroups_members'], '</option>';
106
107
		foreach ($context['groups'] as $group)
108
			echo '
109
								<option value="', $group['id'], '">', $group['name'], '</option>';
110
111
		echo '
112
							</select>
113
							<br>
114
							<input type="radio" name="perm_type" id="perm_type_predefined" value="predefined">
115
							<label for="perm_type_predefined">', $txt['membergroups_new_as_type'], ':</label>
116
							<select name="level" id="level_select" onclick="document.getElementById(\'perm_type_predefined\').checked = true;">
117
								<option value="restrict">', $txt['permitgroups_restrict'], '</option>
118
								<option value="standard" selected>', $txt['permitgroups_standard'], '</option>
119
								<option value="moderator">', $txt['permitgroups_moderator'], '</option>
120
								<option value="maintenance">', $txt['permitgroups_maintenance'], '</option>
121
							</select>
122
						</fieldset>
123
					</dd>';
124
	}
125
126
	echo '
127
					<dt>
128
						<strong>', $txt['membergroups_new_board'], ':</strong>', $context['post_group'] ? '<br>
129
						<span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
130
					</dt>
131
					<dd>';
132
133
	template_add_edit_group_boards_list(false);
134
135
	echo '
136
					</dd>
137
				</dl>
138
				<input type="submit" value="', $txt['membergroups_add_group'], '" class="button">
139
			</div><!-- .windowbg -->';
140
141
	if ($context['undefined_group'])
142
		echo '
143
			<script>
144
				function swapPostGroup(isChecked)
145
				{
146
					var min_posts_text = document.getElementById(\'min_posts_text\');
147
					document.getElementById(\'min_posts_input\').disabled = !isChecked;
148
					min_posts_text.style.color = isChecked ? "" : "#888888";
149
				}
150
				swapPostGroup(', $context['post_group'] ? 'true' : 'false', ');
151
			</script>';
152
153
	echo '
154
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
155
			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '">
156
		</form>';
157
}
158
159
/**
160
 * Edit an existing membergroup.
161
 */
162
function template_edit_group()
163
{
164
	global $context, $scripturl, $txt, $modSettings;
165
166
	echo '
167
		<form action="', $scripturl, '?action=admin;area=membergroups;sa=edit;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="groupForm" id="groupForm">
168
			<div class="cat_bar">
169
				<h3 class="catbg">', $txt['membergroups_edit_group'], ' - ', $context['group']['name'], '
170
				</h3>
171
			</div>
172
			<div class="windowbg">
173
				<dl class="settings">
174
					<dt>
175
						<label for="group_name_input"><strong>', $txt['membergroups_edit_name'], ':</strong></label>
176
					</dt>
177
					<dd>
178
						<input type="text" name="group_name" id="group_name_input" value="', $context['group']['editable_name'], '" size="30">
179
					</dd>';
180
181
	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
182
		echo '
183
					<dt id="group_desc_text">
184
						<label for="group_desc_input"><strong>', $txt['membergroups_edit_desc'], ':</strong></label>
185
					</dt>
186
					<dd>
187
						<textarea name="group_desc" id="group_desc_input" rows="4" cols="40">', $context['group']['description'], '</textarea>
188
					</dd>';
189
190
	// Group type...
191
	if ($context['group']['allow_post_group'])
192
	{
193
		echo '
194
					<dt>
195
						<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], ':</strong></label>
196
					</dt>
197
					<dd>
198
						<fieldset id="group_type">
199
							<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
200
							<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0"', !$context['group']['is_post_group'] && $context['group']['type'] == 0 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_private'], '</label><br>';
201
202
		if ($context['group']['allow_protected'])
203
			echo '
204
							<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1"', $context['group']['type'] == 1 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_protected'], '</label><br>';
205
206
		echo '
207
							<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2"', $context['group']['type'] == 2 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_request'], '</label><br>
208
							<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3"', $context['group']['type'] == 3 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_free'], '</label><br>
209
							<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1"', $context['group']['is_post_group'] ? ' checked' : '', ' onclick="swapPostGroup(1);">', $txt['membergroups_group_type_post'], '</label><br>
210
						</fieldset>
211
					</dd>';
212
	}
213
214
	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
215
		echo '
216
					<dt id="group_moderators_text">
217
						<label for="group_moderators"><strong>', $txt['moderators'], ':</strong></label>
218
					</dt>
219
					<dd>
220
						<input type="text" name="group_moderators" id="group_moderators" value="', $context['group']['moderator_list'], '" size="30">
221
						<div id="moderator_container"></div>
222
					</dd>
223
					<dt id="group_hidden_text">
224
						<label for="group_hidden_input"><strong>', $txt['membergroups_edit_hidden'], ':</strong></label>
225
					</dt>
226
					<dd>
227
						<select name="group_hidden" id="group_hidden_input" onchange="if (this.value == 2 &amp;&amp; !confirm(\'', $txt['membergroups_edit_hidden_warning'], '\')) this.value = 0;">
228
							<option value="0"', $context['group']['hidden'] ? '' : ' selected', '>', $txt['membergroups_edit_hidden_no'], '</option>
229
							<option value="1"', $context['group']['hidden'] == 1 ? ' selected' : '', '>', $txt['membergroups_edit_hidden_boardindex'], '</option>
230
							<option value="2"', $context['group']['hidden'] == 2 ? ' selected' : '', '>', $txt['membergroups_edit_hidden_all'], '</option>
231
						</select>
232
					</dd>';
233
234
	// Can they inherit permissions?
235
	if ($context['group']['id'] > 1 && $context['group']['id'] != 3)
236
	{
237
		echo '
238
					<dt id="group_inherit_text">
239
						<label for="group_inherit_input"><strong>', $txt['membergroups_edit_inherit_permissions'], '</strong></label>:<br>
240
						<span class="smalltext">', $txt['membergroups_edit_inherit_permissions_desc'], '</span>
241
					</dt>
242
					<dd>
243
						<select name="group_inherit" id="group_inherit_input">
244
							<option value="-2">', $txt['membergroups_edit_inherit_permissions_no'], '</option>
245
							<option value="-1"', $context['group']['inherited_from'] == -1 ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_guests'], '</option>
246
							<option value="0"', $context['group']['inherited_from'] == 0 ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_members'], '</option>';
247
248
		// For all the inheritable groups show an option.
249
		foreach ($context['inheritable_groups'] as $id => $group)
250
			echo '
251
							<option value="', $id, '"', $context['group']['inherited_from'] == $id ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $group, '</option>';
252
253
		echo '
254
						</select>
255
						<input type="hidden" name="old_inherit" value="', $context['group']['inherited_from'], '">
256
					</dd>';
257
	}
258
259
	if ($context['group']['allow_post_group'])
260
		echo '
261
262
					<dt id="min_posts_text">
263
						<label for="min_posts_input"><strong>', $txt['membergroups_min_posts'], ':</strong></label>
264
					</dt>
265
					<dd>
266
						<input type="number" name="min_posts" id="min_posts_input"', $context['group']['is_post_group'] ? ' value="' . $context['group']['min_posts'] . '"' : '', ' size="6">
267
					</dd>';
268
269
	echo '
270
					<dt>
271
						<label for="online_color_input"><strong>', $txt['membergroups_online_color'], ':</strong></label>
272
					</dt>
273
					<dd>
274
						<input type="text" name="online_color" id="online_color_input" value="', $context['group']['color'], '" size="20">
275
					</dd>
276
					<dt>
277
						<label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label>
278
					</dt>
279
					<dd>
280
						<input type="number" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4">
281
					</dd>';
282
283
	// Do we have any possible icons to select from?
284
	if (!empty($context['possible_icons']))
285
	{
286
		echo '
287
					<dt>
288
						<label for="icon_image_input"><strong>', $txt['membergroups_icon_image'], ':</strong></label><br>
289
						<span class="smalltext">', $txt['membergroups_icon_image_note'], '</span>
290
						<span class="smalltext">', $txt['membergroups_icon_image_size'], '</span>
291
					</dt>
292
					<dd>
293
						', $txt['membergroups_images_url'], '
294
						<select name="icon_image" id="icon_image_input">';
295
296
		// For every possible icon, create an option.
297
		foreach ($context['possible_icons'] as $icon)
298
			echo '
299
							<option value="', $icon, '"', $context['group']['icon_image'] == $icon ? ' selected' : '', '>', $icon, '</option>';
300
301
		echo '
302
						</select>
303
						<img id="icon_preview" src="" alt="*">
304
					</dd>';
305
	}
306
307
	// No? Hide the entire control.
308
	else
309
		echo '
310
					<input type="hidden" name="icon_image" value="">';
311
312
	echo '
313
					<dt>
314
						<label for="max_messages_input"><strong>', $txt['membergroups_max_messages'], ':</strong></label><br>
315
						<span class="smalltext">', $txt['membergroups_max_messages_note'], '</span>
316
					</dt>
317
					<dd>
318
						<input type="text" name="max_messages" id="max_messages_input" value="', $context['group']['id'] == 1 ? 0 : $context['group']['max_messages'], '" size="6"', $context['group']['id'] == 1 ? ' disabled' : '', '>
319
					</dd>';
320
321
	// Force 2FA for this membergroup?
322
	if (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] == 2)
323
		echo '
324
					<dt>
325
						<label for="group_tfa_force_input"><strong>', $txt['membergroups_tfa_force'], ':</strong></label><br>
326
						<span class="smalltext">', $txt['membergroups_tfa_force_note'], '</span>
327
					</dt>
328
					<dd>
329
						<input type="checkbox" name="group_tfa_force"', $context['group']['tfa_required'] ? ' checked' : '', '>
330
					</dd>';
331
332
	if (!empty($context['categories']))
333
	{
334
		echo '
335
					<dt>
336
						<strong>', $txt['membergroups_new_board'], ':</strong>', $context['group']['is_post_group'] ? '<br>
337
						<span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
338
					</dt>
339
					<dd>';
340
341
		if (!empty($context['can_manage_boards']))
342
			echo $txt['membergroups_can_manage_access'];
343
344
		else
345
			template_add_edit_group_boards_list(true, 'groupForm');
346
347
		echo '
348
					</dd>';
349
	}
350
351
	echo '
352
				</dl>
353
				<input type="submit" name="save" value="', $txt['membergroups_edit_save'], '" class="button">', $context['group']['allow_delete'] ? '
354
				<input type="submit" name="delete" value="' . $txt['membergroups_delete'] . '" data-confirm="' . ($context['is_moderator_group'] ? $txt['membergroups_confirm_delete_mod'] : $txt['membergroups_confirm_delete']) . '" class="button you_sure">' : '', '
355
			</div><!-- .windowbg -->
356
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
357
			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '">
358
		</form>
359
	<script>
360
		var oModeratorSuggest = new smc_AutoSuggest({
361
			sSelf: \'oModeratorSuggest\',
362
			sSessionId: smf_session_id,
363
			sSessionVar: smf_session_var,
364
			sSuggestId: \'group_moderators\',
365
			sControlId: \'group_moderators\',
366
			sSearchType: \'member\',
367
			bItemList: true,
368
			sPostName: \'moderator_list\',
369
			sURLMask: \'action=profile;u=%item_id%\',
370
			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
371
			sItemListContainerId: \'moderator_container\',
372
			aListItems: [';
373
374
	foreach ($context['group']['moderators'] as $id_member => $member_name)
375
		echo '
376
				{
377
					sItemId: ', JavaScriptEscape($id_member), ',
378
					sItemName: ', JavaScriptEscape($member_name), '
379
				}', $id_member == $context['group']['last_moderator_id'] ? '' : ',';
380
381
	echo '
382
			]
383
		});
384
	</script>';
385
386
	if ($context['group']['allow_post_group'])
387
		echo '
388
	<script>
389
		function swapPostGroup(isChecked)
390
		{
391
			var is_moderator_group = ', (int)$context['is_moderator_group'], ';
392
			var group_type = ', $context['group']['type'], ';
393
			var min_posts_text = document.getElementById(\'min_posts_text\');
394
			var group_desc_text = document.getElementById(\'group_desc_text\');
395
			var group_hidden_text = document.getElementById(\'group_hidden_text\');
396
			var group_moderators_text = document.getElementById(\'group_moderators_text\');
397
398
			// If it\'s a moderator group, warn of possible problems... and remember the group type
399
			if (isChecked && is_moderator_group && !confirm(\'', $txt['membergroups_swap_mod'], '\'))
400
			{
401
				isChecked = false;
402
403
				switch(group_type)
404
				{
405
					case 0:
406
						document.getElementById(\'group_type_private\').checked = true;
407
						break;
408
					case 1:
409
						document.getElementById(\'group_type_protected\').checked = true;
410
						break;
411
					case 2:
412
						document.getElementById(\'group_type_request\').checked = true;
413
						break;
414
					case 3:
415
						document.getElementById(\'group_type_free\').checked = true;
416
						break;
417
					default:
418
						document.getElementById(\'group_type_private\').checked = true;
419
						break;
420
				}
421
			}
422
423
			document.forms.groupForm.min_posts.disabled = !isChecked;
424
			min_posts_text.style.color = isChecked ? "" : "#888888";
425
			document.forms.groupForm.group_desc_input.disabled = isChecked;
426
			group_desc_text.style.color = !isChecked ? "" : "#888888";
427
			document.forms.groupForm.group_hidden_input.disabled = isChecked;
428
			group_hidden_text.style.color = !isChecked ? "" : "#888888";
429
			document.forms.groupForm.group_moderators.disabled = isChecked;
430
			group_moderators_text.style.color = !isChecked ? "" : "#888888";
431
		}
432
433
		swapPostGroup(', $context['group']['is_post_group'] ? 'true' : 'false', ');
434
	</script>';
435
}
436
437
/**
438
 * The template for determining which boards a group has access to.
439
 *
440
 * @param bool $collapse Whether to collapse the list by default
441
 */
442
function template_add_edit_group_boards_list($collapse = true, $form_id = 'new_group')
443
{
444
	global $context, $txt, $modSettings;
445
446
	echo '
447
							<fieldset id="visible_boards"', !empty($modSettings['deny_boards_access']) ? ' class="denyboards_layout"' : '', '>
448
								<legend>', $txt['membergroups_new_board_desc'], '</legend>
449
								<ul class="padding floatleft">';
450
451
	foreach ($context['categories'] as $category)
452
	{
453
		if (empty($modSettings['deny_boards_access']))
454
			echo '
455
									<li class="category">
456
										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \''.$form_id.'\'); return false;"><strong>', $category['name'], '</strong></a>
457
										<ul>';
458
		else
459
			echo '
460
									<li class="category clear">
461
										<strong>', $category['name'], '</strong>
462
										<span class="select_all_box floatright">
463
											<em class="all_boards_in_cat">', $txt['all_boards_in_cat'], ': </em>
464
											<select onchange="select_in_category(', $category['id'], ', this, [', implode(',', array_keys($category['boards'])), ']);">
465
												<option>---</option>
466
												<option value="allow">', $txt['board_perms_allow'], '</option>
467
												<option value="ignore">', $txt['board_perms_ignore'], '</option>
468
												<option value="deny">', $txt['board_perms_deny'], '</option>
469
											</select>
470
										</span>
471
										<ul id="boards_list_', $category['id'], '">';
472
473
		foreach ($category['boards'] as $board)
474
		{
475
			if (empty($modSettings['deny_boards_access']))
476
				echo '
477
											<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
478
												<input type="checkbox" name="boardaccess[', $board['id'], ']" id="brd', $board['id'], '" value="allow"', $board['allow'] ? ' checked' : '', '> <label for="brd', $board['id'], '">', $board['name'], '</label>
479
											</li>';
480
			else
481
				echo '
482
											<li class="board clear">
483
												<span style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">', $board['name'], ': </span>
484
												<span class="floatright">
485
													<input type="radio" name="boardaccess[', $board['id'], ']" id="allow_brd', $board['id'], '" value="allow"', $board['allow'] ? ' checked' : '', '> <label for="allow_brd', $board['id'], '">', $txt['permissions_option_on'], '</label>
486
													<input type="radio" name="boardaccess[', $board['id'], ']" id="ignore_brd', $board['id'], '" value="ignore"', !$board['allow'] && !$board['deny'] ? ' checked' : '', '> <label for="ignore_brd', $board['id'], '">', $txt['permissions_option_off'], '</label>
487
													<input type="radio" name="boardaccess[', $board['id'], ']" id="deny_brd', $board['id'], '" value="deny"', $board['deny'] ? ' checked' : '', '> <label for="deny_brd', $board['id'], '">', $txt['permissions_option_deny'], '</label>
488
												</span>
489
											</li>';
490
		}
491
492
		echo '
493
										</ul>
494
									</li>';
495
	}
496
497
	echo '
498
								</ul>';
499
500
	if (empty($modSettings['deny_boards_access']))
501
		echo '
502
								<br class="clear"><br>
503
								<input type="checkbox" id="checkall_check" onclick="invertAll(this, this.form, \'boardaccess\');">
504
								<label for="checkall_check"><em>', $txt['check_all'], '</em></label>
505
							</fieldset>';
506
	else
507
		echo '
508
								<br class="clear">
509
								<span class="select_all_box">
510
									<em>', $txt['all'], ': </em>
511
									<input type="radio" name="select_all" id="allow_all" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'allow\');"> <label for="allow_all">', $txt['board_perms_allow'], '</label>
512
									<input type="radio" name="select_all" id="ignore_all" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'ignore\');"> <label for="ignore_all">', $txt['board_perms_ignore'], '</label>
513
									<input type="radio" name="select_all" id="deny_all" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'deny\');"> <label for="deny_all">', $txt['board_perms_deny'], '</label>
514
								</span>
515
							</fieldset>
516
							<script>
517
								$(document).ready(function () {
518
									$(".select_all_box").each(function () {
519
										$(this).removeClass(\'select_all_box\');
520
									});
521
								});
522
							</script>';
523
524
	if ($collapse)
525
		echo '
526
							<a href="javascript:void(0);" onclick="document.getElementById(\'visible_boards\').classList.remove(\'hidden\'); document.getElementById(\'visible_boards_link\').classList.add(\'hidden\'); return false;" id="visible_boards_link" class="hidden">[ ', $txt['membergroups_select_visible_boards'], ' ]</a>
527
							<script>
528
								document.getElementById("visible_boards_link").classList.remove(\'hidden\');
529
								document.getElementById("visible_boards").classList.add(\'hidden\');
530
							</script>';
531
}
532
533
/**
534
 * Template for viewing the members of a group.
535
 */
536
function template_group_members()
537
{
538
	global $context, $scripturl, $txt;
539
540
	echo '
541
		<form action="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '" id="view_group">
542
			<div class="cat_bar">
543
				<h3 class="catbg">', $context['page_title'], '</h3>
544
			</div>
545
			<div class="windowbg">
546
				<dl class="settings">
547
					<dt>
548
						<strong>', $txt['name'], ':</strong>
549
					</dt>
550
					<dd>
551
						<span ', $context['group']['online_color'] ? 'style="color: ' . $context['group']['online_color'] . ';"' : '', '>', $context['group']['name'], '</span> ', $context['group']['icons'], '
552
					</dd>';
553
554
	// Any description to show?
555
	if (!empty($context['group']['description']))
556
		echo '
557
					<dt>
558
						<strong>' . $txt['membergroups_members_description'] . ':</strong>
559
					</dt>
560
					<dd>
561
						', $context['group']['description'], '
562
					</dd>';
563
564
	echo '
565
					<dt>
566
						<strong>', $txt['membergroups_members_top'], ':</strong>
567
					</dt>
568
					<dd>
569
						', $context['total_members'], '
570
					</dd>';
571
572
	// Any group moderators to show?
573
	if (!empty($context['group']['moderators']))
574
	{
575
		$moderators = array();
576
		foreach ($context['group']['moderators'] as $moderator)
577
			$moderators[] = '<a href="' . $scripturl . '?action=profile;u=' . $moderator['id'] . '">' . $moderator['name'] . '</a>';
578
579
		echo '
580
					<dt>
581
						<strong>', $txt['membergroups_members_group_moderators'], ':</strong>
582
					</dt>
583
					<dd>
584
						', implode(', ', $moderators), '
585
					</dd>';
586
	}
587
588
	echo '
589
				</dl>
590
			</div><!-- .windowbg -->
591
			<br>
592
			<div class="cat_bar">
593
				<h3 class="catbg">', $txt['membergroups_members_group_members'], '</h3>
594
			</div>
595
			<br>
596
			<div class="pagesection">', $context['page_index'], '</div>
597
			<table class="table_grid" id="group_members">
598
				<thead>
599
					<tr class="title_bar">
600
						<th class="user_name"><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['name'], $context['sort_by'] == 'name' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a></th>';
601
602
	if ($context['can_send_email'])
603
		echo '
604
						<th class="email"><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=email', $context['sort_by'] == 'email' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['email'], $context['sort_by'] == 'email' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a></th>';
605
606
	echo '
607
						<th class="last_active"><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=active', $context['sort_by'] == 'active' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['membergroups_members_last_active'], $context['sort_by'] == 'active' ? '<span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a></th>
608
						<th class="date_registered"><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=registered', $context['sort_by'] == 'registered' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['date_registered'], $context['sort_by'] == 'registered' ? '<span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a></th>
609
						<th class="posts"', empty($context['group']['assignable']) ? ' colspan="2"' : '', '>
610
							<a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=posts', $context['sort_by'] == 'posts' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['posts'], $context['sort_by'] == 'posts' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
611
						</th>';
612
613
	if (!empty($context['group']['assignable']))
614
		echo '
615
						<th class="quick_moderation" style="width: 4%"><input type="checkbox" onclick="invertAll(this, this.form);"></th>';
616
617
	echo '
618
					</tr>
619
				</thead>
620
				<tbody>';
621
622
	if (empty($context['members']))
623
		echo '
624
					<tr class="windowbg">
625
						<td colspan="6">', $txt['membergroups_members_no_members'], '</td>
626
					</tr>';
627
628
	foreach ($context['members'] as $member)
629
	{
630
		echo '
631
					<tr class="windowbg">
632
						<td class="user_name">', $member['name'], '</td>';
633
634
		if ($context['can_send_email'])
635
			echo '
636
						<td class="email">
637
								<a href="mailto:', $member['email'], '">', $member['email'], '</a>
638
						</td>';
639
640
		echo '
641
						<td class="last_active">', $member['last_online'], '</td>
642
						<td class="date_registered">', $member['registered'], '</td>
643
						<td class="posts"', empty($context['group']['assignable']) ? ' colspan="2"' : '', '>', $member['posts'], '</td>';
644
645
		if (!empty($context['group']['assignable']))
646
			echo '
647
						<td class="quick_moderation" style="width: 4%"><input type="checkbox" name="rem[]" value="', $member['id'], '" ', ($context['user']['id'] == $member['id'] && $context['group']['id'] == 1 ? 'onclick="if (this.checked) return confirm(\'' . $txt['membergroups_members_deadmin_confirm'] . '\')" ' : ''), '/></td>';
648
649
		echo '
650
					</tr>';
651
	}
652
653
	echo '
654
				</tbody>
655
			</table>';
656
657
	if (!empty($context['group']['assignable']))
658
		echo '
659
			<div class="floatright">
660
				<input type="submit" name="remove" value="', $txt['membergroups_members_remove'], '" class="button ">
661
			</div>';
662
663
	echo '
664
			<div class="pagesection flow_hidden">
665
				<div class="floatleft">', $context['page_index'], '</div>
666
			</div>
667
			<br>';
668
669
	if (!empty($context['group']['assignable']))
670
		echo '
671
			<div class="cat_bar">
672
				<h3 class="catbg">', $txt['membergroups_members_add_title'], '</h3>
673
			</div>
674
			<div class="windowbg">
675
				<dl class="settings">
676
					<dt>
677
						<strong><label for="toAdd">', $txt['membergroups_members_add_desc'], ':</label></strong>
678
					</dt>
679
					<dd>
680
						<input type="text" name="toAdd" id="toAdd" value="">
681
						<div id="toAddItemContainer"></div>
682
					</dd>
683
				</dl>
684
				<input type="submit" name="add" value="', $txt['membergroups_members_add'], '" class="button">
685
			</div>';
686
687
	echo '
688
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
689
			<input type="hidden" name="', $context['mod-mgm_token_var'], '" value="', $context['mod-mgm_token'], '">
690
		</form>';
691
692
	if (!empty($context['group']['assignable']))
693
		echo '
694
	<script>
695
		var oAddMemberSuggest = new smc_AutoSuggest({
696
			sSelf: \'oAddMemberSuggest\',
697
			sSessionId: \'', $context['session_id'], '\',
698
			sSessionVar: \'', $context['session_var'], '\',
699
			sSuggestId: \'to_suggest\',
700
			sControlId: \'toAdd\',
701
			sSearchType: \'member\',
702
			sPostName: \'member_add\',
703
			sURLMask: \'action=profile;u=%item_id%\',
704
			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
705
			bItemList: true,
706
			sItemListContainerId: \'toAddItemContainer\'
707
		});
708
	</script>';
709
}
710
711
/**
712
 * Allow the moderator to enter a reason to each user being rejected.
713
 */
714
function template_group_request_reason()
715
{
716
	global $context, $txt, $scripturl;
717
718
	// Show a welcome message to the user.
719
	echo '
720
	<div id="moderationcenter">
721
		<form action="', $scripturl, '?action=groups;sa=requests" method="post" accept-charset="', $context['character_set'], '">
722
			<div class="cat_bar">
723
				<h3 class="catbg">', $txt['mc_groups_reason_title'], '</h3>
724
			</div>
725
			<div class="windowbg">
726
				<dl class="settings">';
727
728
	// Loop through and print out a reason box for each...
729
	foreach ($context['group_requests'] as $request)
730
		echo '
731
					<dt>
732
						<strong>', sprintf($txt['mc_groupr_reason_desc'], $request['member_link'], $request['group_link']), ':</strong>
733
					</dt>
734
					<dd>
735
						<input type="hidden" name="groupr[]" value="', $request['id'], '">
736
						<textarea name="groupreason[', $request['id'], ']" rows="3" cols="40"></textarea>
737
					</dd>';
738
739
	echo '
740
				</dl>
741
				<input type="submit" name="go" value="', $txt['mc_groupr_submit'], '" class="button">
742
				<input type="hidden" name="req_action" value="got_reason">
743
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
744
				<input type="hidden" name="', $context['mod-gr_token_var'], '" value="', $context['mod-gr_token'], '">
745
			</div><!-- .windowbg -->
746
		</form>
747
	</div><!-- #moderationcenter -->';
748
}
749
750
?>