|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package SimplePortal ElkArte |
|
5
|
|
|
* |
|
6
|
|
|
* @author SimplePortal Team |
|
7
|
|
|
* @copyright 2015-2021 SimplePortal Team |
|
8
|
|
|
* @license BSD 3-clause |
|
9
|
|
|
* @version 1.0.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* SimplePortal Profiles Administration controller class. |
|
15
|
|
|
* |
|
16
|
|
|
* - This class handles the adding/editing/listing of profiles for permissions, styles and display |
|
17
|
|
|
*/ |
|
18
|
|
|
class ManagePortalProfile_Controller extends Action_Controller |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Main dispatcher. |
|
22
|
|
|
* This function checks permissions and passes control through. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function action_index() |
|
25
|
|
|
{ |
|
26
|
|
|
global $context, $txt; |
|
27
|
|
|
|
|
28
|
|
|
// Helpers |
|
29
|
|
|
require_once(SUBSDIR . '/PortalAdmin.subs.php'); |
|
30
|
|
|
loadTemplate('PortalAdminProfiles'); |
|
31
|
|
|
|
|
32
|
|
|
// Lots of profile areas and things to do |
|
33
|
|
|
$subActions = array( |
|
34
|
|
|
'listpermission' => array($this, 'action_permission_profiles_list', 'permission' => 'sp_manage_profiles'), |
|
35
|
|
|
'addpermission' => array($this, 'action_permission_profiles_edit', 'permission' => 'sp_manage_profiles'), |
|
36
|
|
|
'editpermission' => array($this, 'action_permission_profiles_edit', 'permission' => 'sp_manage_profiles'), |
|
37
|
|
|
'deletepermission' => array($this, 'action_profiles_delete', 'permission' => 'sp_manage_profiles'), |
|
38
|
|
|
'liststyle' => array($this, 'action_style_profiles_list', 'permission' => 'sp_manage_profiles'), |
|
39
|
|
|
'addstyle' => array($this, 'action_style_profiles_edit', 'permission' => 'sp_manage_profiles'), |
|
40
|
|
|
'editstyle' => array($this, 'action_style_profiles_edit', 'permission' => 'sp_manage_profiles'), |
|
41
|
|
|
'deletestyle' => array($this, 'action_profiles_delete', 'permission' => 'sp_manage_profiles'), |
|
42
|
|
|
'listvisibility' => array($this, 'action_visibility_profiles_list', 'permission' => 'sp_manage_profiles'), |
|
43
|
|
|
'addvisibility' => array($this, 'action_visibility_profiles_edit', 'permission' => 'sp_manage_profiles'), |
|
44
|
|
|
'editvisibility' => array($this, 'action_visibility_profiles_edit', 'permission' => 'sp_manage_profiles'), |
|
45
|
|
|
'deletevisibility' => array($this, 'action_profiles_delete', 'permission' => 'sp_manage_profiles'), |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
// Start up the controller, provide a hook since we can |
|
49
|
|
|
$action = new Action('portal_profile'); |
|
50
|
|
|
|
|
51
|
|
|
// Leave some breadcrumbs so we know our way back |
|
52
|
|
|
$context[$context['admin_menu_name']]['tab_data'] = array( |
|
53
|
|
|
'title' => $txt['sp_admin_profiles_title'], |
|
54
|
|
|
'help' => 'sp_ProfilesArea', |
|
55
|
|
|
'description' => $txt['sp_admin_profiles_desc'], |
|
56
|
|
|
'tabs' => array( |
|
57
|
|
|
'listpermission' => array(), |
|
58
|
|
|
'liststyle' => array(), |
|
59
|
|
|
'listvisibility' => array(), |
|
60
|
|
|
), |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
// Default to the listpermission action |
|
64
|
|
|
$subAction = $action->initialize($subActions, 'listpermission'); |
|
65
|
|
|
$context['sub_action'] = $subAction; |
|
66
|
|
|
|
|
67
|
|
|
// Call the right function for this sub-action, if you have permission |
|
68
|
|
|
$action->dispatch($subAction); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Show page listing of all permission groups in the system |
|
73
|
|
|
*/ |
|
74
|
|
|
public function action_permission_profiles_list() |
|
75
|
|
|
{ |
|
76
|
|
|
global $context, $scripturl, $txt, $modSettings; |
|
77
|
|
|
|
|
78
|
|
|
// Removing some permission profiles via checkbox? |
|
79
|
|
|
$this->_remove_profiles(); |
|
80
|
|
|
|
|
81
|
|
|
// Build the listoption array to display the permission profiles |
|
82
|
|
|
$listOptions = array( |
|
83
|
|
|
'id' => 'portal_permisssions', |
|
84
|
|
|
'title' => $txt['sp_admin_permission_profiles_list'], |
|
85
|
|
|
'items_per_page' => $modSettings['defaultMaxMessages'], |
|
86
|
|
|
'no_items_label' => $txt['error_sp_no_profiles'], |
|
87
|
|
|
'base_href' => $scripturl . '?action=admin;area=portalprofiles;sa=listpermission;', |
|
88
|
|
|
'default_sort_col' => 'name', |
|
89
|
|
|
'get_items' => array( |
|
90
|
|
|
'function' => array($this, 'list_spLoadProfiles'), |
|
91
|
|
|
), |
|
92
|
|
|
'get_count' => array( |
|
93
|
|
|
'function' => array($this, 'list_spCountProfiles'), |
|
94
|
|
|
), |
|
95
|
|
|
'columns' => array( |
|
96
|
|
|
'name' => array( |
|
97
|
|
|
'header' => array( |
|
98
|
|
|
'value' => $txt['sp_admin_profiles_col_name'], |
|
99
|
|
|
), |
|
100
|
|
|
'data' => array( |
|
101
|
|
|
'db' => 'label', |
|
102
|
|
|
), |
|
103
|
|
|
'sort' => array( |
|
104
|
|
|
'default' => 'name', |
|
105
|
|
|
'reverse' => 'name DESC', |
|
106
|
|
|
), |
|
107
|
|
|
), |
|
108
|
|
|
'articles' => array( |
|
109
|
|
|
'header' => array( |
|
110
|
|
|
'value' => $txt['sp_admin_profiles_col_articles'], |
|
111
|
|
|
'class' => 'centertext', |
|
112
|
|
|
), |
|
113
|
|
|
'data' => array( |
|
114
|
|
|
'function' => function ($row) |
|
115
|
|
|
{ |
|
116
|
|
|
return empty($row['articles']) ? '0' : $row['articles']; |
|
117
|
|
|
}, |
|
118
|
|
|
'class' => 'centertext', |
|
119
|
|
|
), |
|
120
|
|
|
), |
|
121
|
|
|
'blocks' => array( |
|
122
|
|
|
'header' => array( |
|
123
|
|
|
'value' => $txt['sp_admin_profiles_col_blocks'], |
|
124
|
|
|
'class' => 'centertext', |
|
125
|
|
|
), |
|
126
|
|
|
'data' => array( |
|
127
|
|
|
'function' => function ($row) |
|
128
|
|
|
{ |
|
129
|
|
|
return empty($row['blocks']) ? '0' : $row['blocks']; |
|
130
|
|
|
}, |
|
131
|
|
|
'class' => 'centertext', |
|
132
|
|
|
), |
|
133
|
|
|
), |
|
134
|
|
|
'categories' => array( |
|
135
|
|
|
'header' => array( |
|
136
|
|
|
'value' => $txt['sp_admin_profiles_col_categories'], |
|
137
|
|
|
'class' => 'centertext', |
|
138
|
|
|
), |
|
139
|
|
|
'data' => array( |
|
140
|
|
|
'function' => function ($row) |
|
141
|
|
|
{ |
|
142
|
|
|
return empty($row['categories']) ? '0' : $row['categories']; |
|
143
|
|
|
}, |
|
144
|
|
|
'class' => 'centertext', |
|
145
|
|
|
), |
|
146
|
|
|
), |
|
147
|
|
|
'pages' => array( |
|
148
|
|
|
'header' => array( |
|
149
|
|
|
'value' => $txt['sp_admin_profiles_col_pages'], |
|
150
|
|
|
'class' => 'centertext', |
|
151
|
|
|
), |
|
152
|
|
|
'data' => array( |
|
153
|
|
|
'function' => function ($row) |
|
154
|
|
|
{ |
|
155
|
|
|
return empty($row['pages']) ? '0' : $row['pages']; |
|
156
|
|
|
}, |
|
157
|
|
|
'class' => 'centertext', |
|
158
|
|
|
), |
|
159
|
|
|
), |
|
160
|
|
|
'shoutboxes' => array( |
|
161
|
|
|
'header' => array( |
|
162
|
|
|
'value' => $txt['sp_admin_profiles_col_shoutboxes'], |
|
163
|
|
|
'class' => 'centertext', |
|
164
|
|
|
), |
|
165
|
|
|
'data' => array( |
|
166
|
|
|
'function' => function ($row) |
|
167
|
|
|
{ |
|
168
|
|
|
return empty($row['shoutboxes']) ? '0' : $row['shoutboxes']; |
|
169
|
|
|
}, |
|
170
|
|
|
'class' => 'centertext', |
|
171
|
|
|
), |
|
172
|
|
|
), |
|
173
|
|
|
'action' => array( |
|
174
|
|
|
'header' => array( |
|
175
|
|
|
'value' => $txt['sp_admin_articles_col_actions'], |
|
176
|
|
|
'class' => 'centertext', |
|
177
|
|
|
), |
|
178
|
|
|
'data' => array( |
|
179
|
|
|
'sprintf' => array( |
|
180
|
|
|
'format' => '<a href="?action=admin;area=portalprofiles;sa=editpermission;profile_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" accesskey="e">' . sp_embed_image('edit') . '</a> |
|
181
|
|
|
<a href="?action=admin;area=portalprofiles;sa=deletepermission;profile_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(' . JavaScriptEscape($txt['sp_admin_profiles_delete_confirm']) . ') && submitThisOnce(this);" accesskey="d">' . sp_embed_image('trash') . '</a>', |
|
182
|
|
|
'params' => array( |
|
183
|
|
|
'id' => true, |
|
184
|
|
|
), |
|
185
|
|
|
), |
|
186
|
|
|
'class' => 'centertext', |
|
187
|
|
|
'style' => "width: 40px", |
|
188
|
|
|
), |
|
189
|
|
|
), |
|
190
|
|
|
'check' => array( |
|
191
|
|
|
'header' => array( |
|
192
|
|
|
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', |
|
193
|
|
|
'class' => 'centertext', |
|
194
|
|
|
), |
|
195
|
|
|
'data' => array( |
|
196
|
|
|
'function' => function ($row) |
|
197
|
|
|
{ |
|
198
|
|
|
return '<input type="checkbox" name="remove[]" value="' . $row['id'] . '" class="input_check" />'; |
|
199
|
|
|
}, |
|
200
|
|
|
'class' => 'centertext', |
|
201
|
|
|
), |
|
202
|
|
|
), |
|
203
|
|
|
), |
|
204
|
|
|
'form' => array( |
|
205
|
|
|
'href' => $scripturl . '?action=admin;area=portalprofiles;sa=listpermission', |
|
206
|
|
|
'include_sort' => true, |
|
207
|
|
|
'include_start' => true, |
|
208
|
|
|
'hidden_fields' => array( |
|
209
|
|
|
$context['session_var'] => $context['session_id'], |
|
210
|
|
|
), |
|
211
|
|
|
), |
|
212
|
|
|
'additional_rows' => array( |
|
213
|
|
|
array( |
|
214
|
|
|
'position' => 'below_table_data', |
|
215
|
|
|
'value' => '<div class="submitbutton"> |
|
216
|
|
|
<input class="right_submit" type="submit" name="remove_profiles" value="' . $txt['sp_admin_profiles_remove'] . '" /> |
|
217
|
|
|
<a class="linkbutton floatright" href="' . $scripturl . '?action=admin;area=portalprofiles;sa=addpermission">' . $txt['sp_admin_profiles_add'] . '</a> |
|
218
|
|
|
</div>', |
|
219
|
|
|
), |
|
220
|
|
|
), |
|
221
|
|
|
); |
|
222
|
|
|
|
|
223
|
|
|
// Set the context values |
|
224
|
|
|
$context['page_title'] = $txt['sp_admin_permission_profiles_list']; |
|
225
|
|
|
$context['sub_template'] = 'show_list'; |
|
226
|
|
|
$context['default_list'] = 'portal_permisssions'; |
|
227
|
|
|
|
|
228
|
|
|
// Create the list. |
|
229
|
|
|
require_once(SUBSDIR . '/GenericList.class.php'); |
|
230
|
|
|
createList($listOptions); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Callback for createList(), |
|
235
|
|
|
* Returns the number of profiles of type |
|
236
|
|
|
* |
|
237
|
|
|
* @param int $type |
|
238
|
|
|
*/ |
|
239
|
|
|
public function list_spCountProfiles($type = 1) |
|
240
|
|
|
{ |
|
241
|
|
|
return sp_count_profiles($type); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Callback for createList() |
|
246
|
|
|
* Returns an array of profiles of type |
|
247
|
|
|
* |
|
248
|
|
|
* @param int $start |
|
249
|
|
|
* @param int $items_per_page |
|
250
|
|
|
* @param string $sort |
|
251
|
|
|
* @param int $type |
|
252
|
|
|
* |
|
253
|
|
|
* @return array |
|
254
|
|
|
*/ |
|
255
|
|
|
public function list_spLoadProfiles($start, $items_per_page, $sort, $type = 1) |
|
256
|
|
|
{ |
|
257
|
|
|
return sp_load_profiles($start, $items_per_page, $sort, $type); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* Add or edit a portal wide permissions profile |
|
262
|
|
|
*/ |
|
263
|
|
|
public function action_permission_profiles_edit() |
|
264
|
|
|
{ |
|
265
|
|
|
global $context, $txt; |
|
266
|
|
|
|
|
267
|
|
|
// New or an edit? |
|
268
|
|
|
$context['is_new'] = empty($_REQUEST['profile_id']); |
|
269
|
|
|
|
|
270
|
|
|
// Saving the form |
|
271
|
|
|
if (!empty($_POST['submit'])) |
|
272
|
|
|
{ |
|
273
|
|
|
// Security first |
|
274
|
|
|
checkSession(); |
|
275
|
|
|
|
|
276
|
|
|
// Always clean the name |
|
277
|
|
|
if (!isset($_POST['name']) || Util::htmltrim(Util::htmlspecialchars($_POST['name'], ENT_QUOTES)) === '') |
|
278
|
|
|
{ |
|
279
|
|
|
throw new Elk_Exception('sp_error_profile_name_empty', false); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
list($groups_allowed, $groups_denied) = $this->_group_permissions(); |
|
283
|
|
|
|
|
284
|
|
|
// Add the data to place in the fields |
|
285
|
|
|
$profile_info = array( |
|
286
|
|
|
'id' => (int) $_POST['profile_id'], |
|
287
|
|
|
'type' => 1, |
|
288
|
|
|
'name' => Util::htmlspecialchars($_POST['name'], ENT_QUOTES), |
|
289
|
|
|
'value' => implode('|', array($groups_allowed, $groups_denied)), |
|
290
|
|
|
); |
|
291
|
|
|
|
|
292
|
|
|
// New we simply insert, or and edit will update |
|
293
|
|
|
$profile_info['id'] = sp_add_permission_profile($profile_info, $context['is_new']); |
|
294
|
|
|
|
|
295
|
|
|
redirectexit('action=admin;area=portalprofiles;sa=listpermission'); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
// Not saving, then its time to show the permission form |
|
299
|
|
|
if ($context['is_new']) |
|
300
|
|
|
{ |
|
301
|
|
|
$context['profile'] = array( |
|
302
|
|
|
'id' => 0, |
|
303
|
|
|
'name' => $txt['sp_profiles_default_name'], |
|
304
|
|
|
'label' => $txt['sp_profiles_default_name'], |
|
305
|
|
|
'groups_allowed' => array(), |
|
306
|
|
|
'groups_denied' => array(), |
|
307
|
|
|
); |
|
308
|
|
|
} |
|
309
|
|
|
else |
|
310
|
|
|
{ |
|
311
|
|
|
$_REQUEST['profile_id'] = (int) $_REQUEST['profile_id']; |
|
312
|
|
|
$context['profile'] = sportal_get_profiles($_REQUEST['profile_id']); |
|
313
|
|
|
|
|
314
|
|
|
// Set the add tab |
|
315
|
|
|
$context[$context['admin_menu_name']]['current_subsection'] = 'listpermission'; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
// Sub template time |
|
319
|
|
|
$context['profile']['groups'] = sp_load_membergroups(); |
|
320
|
|
|
$context['page_title'] = $context['is_new'] ? $txt['sp_admin_permission_profiles_add'] : $txt['sp_admin_profiles_edit']; |
|
321
|
|
|
$context['sub_template'] = 'permission_profiles_edit'; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* Prepares submitted form values for permission profiles |
|
326
|
|
|
* |
|
327
|
|
|
* @return array |
|
328
|
|
|
*/ |
|
329
|
|
|
private function _group_permissions() |
|
330
|
|
|
{ |
|
331
|
|
|
$groups_allowed = $groups_denied = ''; |
|
332
|
|
|
|
|
333
|
|
|
// If specific member groups were picked, build the allow/deny arrays |
|
334
|
|
|
if (!empty($_POST['membergroups']) && is_array($_POST['membergroups'])) |
|
335
|
|
|
{ |
|
336
|
|
|
$groups_allowed = $groups_denied = array(); |
|
337
|
|
|
|
|
338
|
|
|
foreach ($_POST['membergroups'] as $id => $value) |
|
339
|
|
|
{ |
|
340
|
|
|
if ($value == 1) |
|
341
|
|
|
{ |
|
342
|
|
|
$groups_allowed[] = (int) $id; |
|
343
|
|
|
} |
|
344
|
|
|
elseif ($value == -1) |
|
345
|
|
|
{ |
|
346
|
|
|
$groups_denied[] = (int) $id; |
|
347
|
|
|
} |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
$groups_allowed = implode(',', $groups_allowed); |
|
351
|
|
|
$groups_denied = implode(',', $groups_denied); |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
return array($groups_allowed, $groups_denied); |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* Show page listing of all style groups in the system |
|
359
|
|
|
*/ |
|
360
|
|
|
public function action_style_profiles_list() |
|
361
|
|
|
{ |
|
362
|
|
|
global $context, $scripturl, $txt, $modSettings; |
|
363
|
|
|
|
|
364
|
|
|
// Removing some styles via the checkbox? |
|
365
|
|
|
$this->_remove_profiles(); |
|
366
|
|
|
|
|
367
|
|
|
// Build the listoption array to display the style profiles |
|
368
|
|
|
$listOptions = array( |
|
369
|
|
|
'id' => 'portal_styles', |
|
370
|
|
|
'title' => $txt['sp_admin_style_profiles_list'], |
|
371
|
|
|
'items_per_page' => $modSettings['defaultMaxMessages'], |
|
372
|
|
|
'no_items_label' => $txt['error_sp_no_style_profiles'], |
|
373
|
|
|
'base_href' => $scripturl . '?action=admin;area=portalprofiles;sa=liststyle;', |
|
374
|
|
|
'default_sort_col' => 'name', |
|
375
|
|
|
'get_items' => array( |
|
376
|
|
|
'function' => array($this, 'list_spLoadProfiles'), |
|
377
|
|
|
'params' => array( |
|
378
|
|
|
2, |
|
379
|
|
|
), |
|
380
|
|
|
), |
|
381
|
|
|
'get_count' => array( |
|
382
|
|
|
'function' => array($this, 'list_spCountProfiles'), |
|
383
|
|
|
'params' => array( |
|
384
|
|
|
2, |
|
385
|
|
|
), |
|
386
|
|
|
), |
|
387
|
|
|
'columns' => array( |
|
388
|
|
|
'name' => array( |
|
389
|
|
|
'header' => array( |
|
390
|
|
|
'value' => $txt['sp_admin_profiles_col_name'], |
|
391
|
|
|
), |
|
392
|
|
|
'data' => array( |
|
393
|
|
|
'db' => 'label', |
|
394
|
|
|
), |
|
395
|
|
|
'sort' => array( |
|
396
|
|
|
'default' => 'name', |
|
397
|
|
|
'reverse' => 'name DESC', |
|
398
|
|
|
), |
|
399
|
|
|
), |
|
400
|
|
|
'articles' => array( |
|
401
|
|
|
'header' => array( |
|
402
|
|
|
'value' => $txt['sp_admin_profiles_col_articles'], |
|
403
|
|
|
'class' => 'centertext', |
|
404
|
|
|
), |
|
405
|
|
|
'data' => array( |
|
406
|
|
|
'function' => function ($row) |
|
407
|
|
|
{ |
|
408
|
|
|
return empty($row['articles']) ? '0' : $row['articles']; |
|
409
|
|
|
}, |
|
410
|
|
|
'class' => 'centertext', |
|
411
|
|
|
), |
|
412
|
|
|
), |
|
413
|
|
|
'blocks' => array( |
|
414
|
|
|
'header' => array( |
|
415
|
|
|
'value' => $txt['sp_admin_profiles_col_blocks'], |
|
416
|
|
|
'class' => 'centertext', |
|
417
|
|
|
), |
|
418
|
|
|
'data' => array( |
|
419
|
|
|
'function' => function ($row) |
|
420
|
|
|
{ |
|
421
|
|
|
return empty($row['blocks']) ? '0' : $row['blocks']; |
|
422
|
|
|
}, |
|
423
|
|
|
'class' => 'centertext', |
|
424
|
|
|
), |
|
425
|
|
|
), |
|
426
|
|
|
'pages' => array( |
|
427
|
|
|
'header' => array( |
|
428
|
|
|
'value' => $txt['sp_admin_profiles_col_pages'], |
|
429
|
|
|
'class' => 'centertext', |
|
430
|
|
|
), |
|
431
|
|
|
'data' => array( |
|
432
|
|
|
'function' => function ($row) |
|
433
|
|
|
{ |
|
434
|
|
|
return empty($row['pages']) ? '0' : $row['pages']; |
|
435
|
|
|
}, |
|
436
|
|
|
'class' => 'centertext', |
|
437
|
|
|
), |
|
438
|
|
|
), |
|
439
|
|
|
'action' => array( |
|
440
|
|
|
'header' => array( |
|
441
|
|
|
'value' => $txt['sp_admin_articles_col_actions'], |
|
442
|
|
|
'class' => 'centertext', |
|
443
|
|
|
), |
|
444
|
|
|
'data' => array( |
|
445
|
|
|
'sprintf' => array( |
|
446
|
|
|
'format' => ' |
|
447
|
|
|
<a href="?action=admin;area=portalprofiles;sa=editstyle;profile_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" accesskey="e">' . sp_embed_image('edit') . '</a> |
|
448
|
|
|
<a href="?action=admin;area=portalprofiles;sa=deletestyle;profile_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(' . JavaScriptEscape($txt['sp_admin_profiles_delete_confirm']) . ') && submitThisOnce(this);" accesskey="d">' . sp_embed_image('trash') . '</a>', |
|
449
|
|
|
'params' => array( |
|
450
|
|
|
'id' => true, |
|
451
|
|
|
), |
|
452
|
|
|
), |
|
453
|
|
|
'class' => 'centertext', |
|
454
|
|
|
'style' => "width: 40px", |
|
455
|
|
|
), |
|
456
|
|
|
), |
|
457
|
|
|
'check' => array( |
|
458
|
|
|
'header' => array( |
|
459
|
|
|
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', |
|
460
|
|
|
'class' => 'centertext', |
|
461
|
|
|
), |
|
462
|
|
|
'data' => array( |
|
463
|
|
|
'function' => function ($row) |
|
464
|
|
|
{ |
|
465
|
|
|
return '<input type="checkbox" name="remove[]" value="' . $row['id'] . '" class="input_check" />'; |
|
466
|
|
|
}, |
|
467
|
|
|
'class' => 'centertext', |
|
468
|
|
|
), |
|
469
|
|
|
), |
|
470
|
|
|
), |
|
471
|
|
|
'form' => array( |
|
472
|
|
|
'href' => $scripturl . '?action=admin;area=portalprofiles;sa=liststyle', |
|
473
|
|
|
'include_sort' => true, |
|
474
|
|
|
'include_start' => true, |
|
475
|
|
|
'hidden_fields' => array( |
|
476
|
|
|
$context['session_var'] => $context['session_id'], |
|
477
|
|
|
), |
|
478
|
|
|
), |
|
479
|
|
|
'additional_rows' => array( |
|
480
|
|
|
array( |
|
481
|
|
|
'position' => 'below_table_data', |
|
482
|
|
|
'value' => '<div class="submitbutton"> |
|
483
|
|
|
<input class="right_submit" type="submit" name="remove_profiles" value="' . $txt['sp_admin_profiles_remove'] . '" /> |
|
484
|
|
|
<a class="linkbutton floatright" href="' . $scripturl . '?action=admin;area=portalprofiles;sa=addstyle">' . $txt['sp_admin_profiles_add'] . '</a> |
|
485
|
|
|
</div>', |
|
486
|
|
|
), |
|
487
|
|
|
), |
|
488
|
|
|
); |
|
489
|
|
|
|
|
490
|
|
|
// Set the context values |
|
491
|
|
|
$context['page_title'] = $txt['sp_admin_style_profiles_list']; |
|
492
|
|
|
$context['sub_template'] = 'show_list'; |
|
493
|
|
|
$context['default_list'] = 'portal_styles'; |
|
494
|
|
|
|
|
495
|
|
|
// Create the list. |
|
496
|
|
|
require_once(SUBSDIR . '/GenericList.class.php'); |
|
497
|
|
|
createList($listOptions); |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
/** |
|
501
|
|
|
* Add or edit a portal wide style profile |
|
502
|
|
|
*/ |
|
503
|
|
|
public function action_style_profiles_edit() |
|
504
|
|
|
{ |
|
505
|
|
|
global $context, $txt; |
|
506
|
|
|
|
|
507
|
|
|
// New or an edit to an existing style |
|
508
|
|
|
$context['is_new'] = empty($_GET['profile_id']); |
|
509
|
|
|
|
|
510
|
|
|
// Saving the style form |
|
511
|
|
|
if (!empty($_POST['submit'])) |
|
512
|
|
|
{ |
|
513
|
|
|
// Security first |
|
514
|
|
|
checkSession(); |
|
515
|
|
|
|
|
516
|
|
|
// Always clean the profile name |
|
517
|
|
|
if (!isset($_POST['name']) || Util::htmltrim(Util::htmlspecialchars($_POST['name'], ENT_QUOTES)) === '') |
|
518
|
|
|
{ |
|
519
|
|
|
throw new Elk_Exception('sp_error_profile_name_empty', false); |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
// Add the data to place in the fields |
|
523
|
|
|
$profile_info = array( |
|
524
|
|
|
'id' => (int) $_POST['profile_id'], |
|
525
|
|
|
'type' => 2, |
|
526
|
|
|
'name' => Util::htmlspecialchars($_POST['name'], ENT_QUOTES), |
|
527
|
|
|
'value' => sportal_parse_style('implode'), |
|
528
|
|
|
); |
|
529
|
|
|
|
|
530
|
|
|
// New we simply insert, or if editing update |
|
531
|
|
|
$profile_info['id'] = sp_add_permission_profile($profile_info, empty($_POST['profile_id'])); |
|
532
|
|
|
|
|
533
|
|
|
// Tada |
|
534
|
|
|
redirectexit('action=admin;area=portalprofiles;sa=liststyle'); |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
// Not saving, then its time to show the style form |
|
538
|
|
|
if ($context['is_new']) |
|
539
|
|
|
{ |
|
540
|
|
|
$context['profile'] = array( |
|
541
|
|
|
'id' => 0, |
|
542
|
|
|
'name' => $txt['sp_profiles_default_name'], |
|
543
|
|
|
'title_default_class' => 'category_header', |
|
544
|
|
|
'title_custom_class' => '', |
|
545
|
|
|
'title_custom_style' => '', |
|
546
|
|
|
'body_default_class' => 'portalbg', |
|
547
|
|
|
'body_custom_class' => '', |
|
548
|
|
|
'body_custom_style' => '', |
|
549
|
|
|
'no_title' => false, |
|
550
|
|
|
'no_body' => false, |
|
551
|
|
|
); |
|
552
|
|
|
} |
|
553
|
|
|
// Now a new style so fetch an existing one to display |
|
554
|
|
|
else |
|
555
|
|
|
{ |
|
556
|
|
|
$profile_id = (int) $_GET['profile_id']; |
|
557
|
|
|
$context['profile'] = sportal_get_profiles($profile_id); |
|
558
|
|
|
} |
|
559
|
|
|
|
|
560
|
|
|
// Set the style tab |
|
561
|
|
|
$context[$context['admin_menu_name']]['current_subsection'] = 'liststyle'; |
|
562
|
|
|
|
|
563
|
|
|
// We may not have much style, but we have class |
|
564
|
|
|
$context['profile']['classes'] = array( |
|
565
|
|
|
'title' => array('category_header', 'secondary_header', 'custom'), |
|
566
|
|
|
'body' => array('portalbg', 'portalbg2', 'information', 'roundframe', 'custom'), |
|
567
|
|
|
); |
|
568
|
|
|
|
|
569
|
|
|
$context['page_title'] = $context['is_new'] ? $txt['sp_admin_style_profiles_add'] : $txt['sp_admin_profiles_edit']; |
|
570
|
|
|
$context['sub_template'] = 'style_profiles_edit'; |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* Show page listing of all visibility groups in the system |
|
575
|
|
|
*/ |
|
576
|
|
|
public function action_visibility_profiles_list() |
|
577
|
|
|
{ |
|
578
|
|
|
global $context, $scripturl, $txt, $modSettings; |
|
579
|
|
|
|
|
580
|
|
|
// Removing some styles via the checkbox? |
|
581
|
|
|
$this->_remove_profiles(); |
|
582
|
|
|
|
|
583
|
|
|
// Build the listoption array to display the style profiles |
|
584
|
|
|
$listOptions = array( |
|
585
|
|
|
'id' => 'portal_visibility', |
|
586
|
|
|
'title' => $txt['sp_admin_visibility_profiles_list'], |
|
587
|
|
|
'items_per_page' => $modSettings['defaultMaxMessages'], |
|
588
|
|
|
'no_items_label' => $txt['error_sp_no_visibility_profiles'], |
|
589
|
|
|
'base_href' => $scripturl . '?action=admin;area=portalprofiles;sa=listvisibility;', |
|
590
|
|
|
'default_sort_col' => 'name', |
|
591
|
|
|
'get_items' => array( |
|
592
|
|
|
'function' => array($this, 'list_spLoadProfiles'), |
|
593
|
|
|
'params' => array( |
|
594
|
|
|
3, |
|
595
|
|
|
), |
|
596
|
|
|
), |
|
597
|
|
|
'get_count' => array( |
|
598
|
|
|
'function' => array($this, 'list_spCountProfiles'), |
|
599
|
|
|
'params' => array( |
|
600
|
|
|
3, |
|
601
|
|
|
), |
|
602
|
|
|
), |
|
603
|
|
|
'columns' => array( |
|
604
|
|
|
'name' => array( |
|
605
|
|
|
'header' => array( |
|
606
|
|
|
'value' => $txt['sp_admin_profiles_col_name'], |
|
607
|
|
|
), |
|
608
|
|
|
'data' => array( |
|
609
|
|
|
'db' => 'label', |
|
610
|
|
|
), |
|
611
|
|
|
'sort' => array( |
|
612
|
|
|
'default' => 'name', |
|
613
|
|
|
'reverse' => 'name DESC', |
|
614
|
|
|
), |
|
615
|
|
|
), |
|
616
|
|
|
'blocks' => array( |
|
617
|
|
|
'header' => array( |
|
618
|
|
|
'value' => $txt['sp_admin_profiles_col_blocks'], |
|
619
|
|
|
'class' => 'centertext', |
|
620
|
|
|
), |
|
621
|
|
|
'data' => array( |
|
622
|
|
|
'function' => function ($row) |
|
623
|
|
|
{ |
|
624
|
|
|
return empty($row['blocks']) ? '0' : $row['blocks']; |
|
625
|
|
|
}, |
|
626
|
|
|
'class' => 'centertext', |
|
627
|
|
|
), |
|
628
|
|
|
), |
|
629
|
|
|
'action' => array( |
|
630
|
|
|
'header' => array( |
|
631
|
|
|
'value' => $txt['sp_admin_articles_col_actions'], |
|
632
|
|
|
'class' => 'centertext', |
|
633
|
|
|
), |
|
634
|
|
|
'data' => array( |
|
635
|
|
|
'sprintf' => array( |
|
636
|
|
|
'format' => ' |
|
637
|
|
|
<a href="?action=admin;area=portalprofiles;sa=editvisibility;profile_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" accesskey="e">' . sp_embed_image('edit') . '</a> |
|
638
|
|
|
<a href="?action=admin;area=portalprofiles;sa=deletevisibility;profile_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(' . JavaScriptEscape($txt['sp_admin_profiles_delete_confirm']) . ') && submitThisOnce(this);" accesskey="d">' . sp_embed_image('trash') . '</a>', |
|
639
|
|
|
'params' => array( |
|
640
|
|
|
'id' => true, |
|
641
|
|
|
), |
|
642
|
|
|
), |
|
643
|
|
|
'class' => 'centertext', |
|
644
|
|
|
'style' => "width: 40px", |
|
645
|
|
|
), |
|
646
|
|
|
), |
|
647
|
|
|
'check' => array( |
|
648
|
|
|
'header' => array( |
|
649
|
|
|
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', |
|
650
|
|
|
'class' => 'centertext', |
|
651
|
|
|
), |
|
652
|
|
|
'data' => array( |
|
653
|
|
|
'function' => function ($row) |
|
654
|
|
|
{ |
|
655
|
|
|
return '<input type="checkbox" name="remove[]" value="' . $row['id'] . '" class="input_check" />'; |
|
656
|
|
|
}, |
|
657
|
|
|
'class' => 'centertext', |
|
658
|
|
|
), |
|
659
|
|
|
), |
|
660
|
|
|
), |
|
661
|
|
|
'form' => array( |
|
662
|
|
|
'href' => $scripturl . '?action=admin;area=portalprofiles;sa=listvisibility', |
|
663
|
|
|
'include_sort' => true, |
|
664
|
|
|
'include_start' => true, |
|
665
|
|
|
'hidden_fields' => array( |
|
666
|
|
|
$context['session_var'] => $context['session_id'], |
|
667
|
|
|
), |
|
668
|
|
|
), |
|
669
|
|
|
'additional_rows' => array( |
|
670
|
|
|
array( |
|
671
|
|
|
'position' => 'below_table_data', |
|
672
|
|
|
'value' => '<div class="submitbutton"> |
|
673
|
|
|
<input class="right_submit" type="submit" name="remove_profiles" value="' . $txt['sp_admin_profiles_remove'] . '" /> |
|
674
|
|
|
<a class="linkbutton floatright" href="' . $scripturl . '?action=admin;area=portalprofiles;sa=addvisibility">' . $txt['sp_admin_profiles_add'] . '</a> |
|
675
|
|
|
</div>', |
|
676
|
|
|
), |
|
677
|
|
|
), |
|
678
|
|
|
); |
|
679
|
|
|
|
|
680
|
|
|
// Set the context values |
|
681
|
|
|
$context['page_title'] = $txt['sp_admin_visibility_profiles_list']; |
|
682
|
|
|
$context['sub_template'] = 'show_list'; |
|
683
|
|
|
$context['default_list'] = 'portal_visibility'; |
|
684
|
|
|
|
|
685
|
|
|
// Create the list. |
|
686
|
|
|
require_once(SUBSDIR . '/GenericList.class.php'); |
|
687
|
|
|
createList($listOptions); |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
/** |
|
691
|
|
|
* Add or edit a portal wide visibility profile |
|
692
|
|
|
*/ |
|
693
|
|
|
public function action_visibility_profiles_edit() |
|
694
|
|
|
{ |
|
695
|
|
|
global $context, $txt; |
|
696
|
|
|
|
|
697
|
|
|
// New or an edit to an existing visibility |
|
698
|
|
|
$context['is_new'] = empty($_GET['profile_id']); |
|
699
|
|
|
|
|
700
|
|
|
// Saving the visibility form |
|
701
|
|
|
if (!empty($_POST['submit'])) |
|
702
|
|
|
{ |
|
703
|
|
|
// Security first |
|
704
|
|
|
checkSession(); |
|
705
|
|
|
|
|
706
|
|
|
// Always clean the profile name |
|
707
|
|
|
if (!isset($_POST['name']) || Util::htmltrim(Util::htmlspecialchars($_POST['name'], ENT_QUOTES)) === '') |
|
708
|
|
|
{ |
|
709
|
|
|
throw new Elk_Exception('sp_error_profile_name_empty', false); |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
// Get the form values |
|
713
|
|
|
list($selections, $query, $mobile) = $this->_profile_visibility(); |
|
714
|
|
|
|
|
715
|
|
|
// Add the data to place in the fields |
|
716
|
|
|
$profile_info = array( |
|
717
|
|
|
'id' => (int) $_POST['profile_id'], |
|
718
|
|
|
'type' => 3, |
|
719
|
|
|
'name' => Util::htmlspecialchars($_POST['name'], ENT_QUOTES), |
|
720
|
|
|
'value' => implode('|', array(implode(',', $selections), implode(',', $query))) . '|' . $mobile, |
|
721
|
|
|
); |
|
722
|
|
|
|
|
723
|
|
|
// New we simply insert, or if editing update |
|
724
|
|
|
$profile_info['id'] = sp_add_permission_profile($profile_info, empty($_POST['profile_id'])); |
|
725
|
|
|
|
|
726
|
|
|
// Tada |
|
727
|
|
|
redirectexit('action=admin;area=portalprofiles;sa=listvisibility'); |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
// Not saving, then its time to show the visibility form |
|
731
|
|
|
if ($context['is_new']) |
|
732
|
|
|
{ |
|
733
|
|
|
$context['profile'] = array( |
|
734
|
|
|
'id' => 0, |
|
735
|
|
|
'name' => $txt['sp_profiles_default_name'], |
|
736
|
|
|
'query' => '', |
|
737
|
|
|
'selections' => array(), |
|
738
|
|
|
'mobile_view' => false, |
|
739
|
|
|
); |
|
740
|
|
|
} |
|
741
|
|
|
// Not a new visibility profile so fetch the existing one to display |
|
742
|
|
|
else |
|
743
|
|
|
{ |
|
744
|
|
|
$profile_id = (int) $_GET['profile_id']; |
|
745
|
|
|
$context['profile'] = sportal_get_profiles($profile_id); |
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
// Set the visibility tab |
|
749
|
|
|
$context[$context['admin_menu_name']]['current_subsection'] = 'listvisibility'; |
|
750
|
|
|
|
|
751
|
|
|
// All the places we can add portal visibility |
|
752
|
|
|
$context['profile']['actions'] = array( |
|
753
|
|
|
'portal' => $txt['sp-portal'], |
|
754
|
|
|
'forum' => $txt['sp-forum'], |
|
755
|
|
|
'recent' => $txt['recent_posts'], |
|
756
|
|
|
'unread' => $txt['unread_topics_visit'], |
|
757
|
|
|
'unreadreplies' => $txt['unread_replies'], |
|
758
|
|
|
'profile' => $txt['profile'], |
|
759
|
|
|
'pm' => $txt['pm_short'], |
|
760
|
|
|
'calendar' => $txt['calendar'], |
|
761
|
|
|
'admin' => $txt['admin'], |
|
762
|
|
|
'login' => $txt['login'], |
|
763
|
|
|
'register' => $txt['register'], |
|
764
|
|
|
'post' => $txt['post'], |
|
765
|
|
|
'stats' => $txt['forum_stats'], |
|
766
|
|
|
'search' => $txt['search'], |
|
767
|
|
|
'mlist' => $txt['members_list'], |
|
768
|
|
|
'moderate' => $txt['moderate'], |
|
769
|
|
|
'help' => $txt['help'], |
|
770
|
|
|
'who' => $txt['who_title'], |
|
771
|
|
|
); |
|
772
|
|
|
|
|
773
|
|
|
// Load board, cat, page and article values for the template |
|
774
|
|
|
$context['profile'] = array_merge($context['profile'], sp_block_template_helpers()); |
|
775
|
|
|
|
|
776
|
|
|
$context['page_title'] = $context['is_new'] ? $txt['sp_admin_visibility_profiles_add'] : $txt['sp_admin_profiles_edit']; |
|
777
|
|
|
$context['sub_template'] = 'visibility_profiles_edit'; |
|
778
|
|
|
} |
|
779
|
|
|
|
|
780
|
|
|
/** |
|
781
|
|
|
* Load in visibility values from the profile form |
|
782
|
|
|
*/ |
|
783
|
|
|
private function _profile_visibility() |
|
784
|
|
|
{ |
|
785
|
|
|
$selections = array(); |
|
786
|
|
|
$query = array(); |
|
787
|
|
|
$mobile = 0; |
|
788
|
|
|
|
|
789
|
|
|
$types = array('actions', 'boards', 'pages', 'categories', 'articles'); |
|
790
|
|
|
foreach ($types as $type) |
|
791
|
|
|
{ |
|
792
|
|
|
if (!empty($_POST[$type]) && is_array($_POST[$type])) |
|
793
|
|
|
{ |
|
794
|
|
|
foreach ($_POST[$type] as $item) |
|
795
|
|
|
{ |
|
796
|
|
|
$selections[] = Util::htmlspecialchars($item, ENT_QUOTES); |
|
797
|
|
|
} |
|
798
|
|
|
} |
|
799
|
|
|
} |
|
800
|
|
|
|
|
801
|
|
|
if (!empty($_POST['query'])) |
|
802
|
|
|
{ |
|
803
|
|
|
$items = explode(',', $_POST['query']); |
|
804
|
|
|
foreach ($items as $item) |
|
805
|
|
|
{ |
|
806
|
|
|
$item = Util::htmltrim(Util::htmlspecialchars($item, ENT_QUOTES)); |
|
807
|
|
|
$item = str_replace('|', '|', $item); |
|
808
|
|
|
|
|
809
|
|
|
if ($item !== '') |
|
810
|
|
|
{ |
|
811
|
|
|
$query[] = $item; |
|
812
|
|
|
} |
|
813
|
|
|
} |
|
814
|
|
|
} |
|
815
|
|
|
|
|
816
|
|
|
if (!empty($_POST['block_mobile'])) |
|
817
|
|
|
{ |
|
818
|
|
|
$mobile = 1; |
|
819
|
|
|
} |
|
820
|
|
|
|
|
821
|
|
|
return array($selections, $query, $mobile); |
|
822
|
|
|
} |
|
823
|
|
|
|
|
824
|
|
|
/** |
|
825
|
|
|
* Remove a profile (style/visibility/permission) from the system |
|
826
|
|
|
*/ |
|
827
|
|
|
public function action_profiles_delete() |
|
828
|
|
|
{ |
|
829
|
|
|
global $context; |
|
830
|
|
|
|
|
831
|
|
|
checkSession('get'); |
|
832
|
|
|
|
|
833
|
|
|
$profile_id = !empty($_REQUEST['profile_id']) ? (int) $_REQUEST['profile_id'] : 0; |
|
834
|
|
|
|
|
835
|
|
|
sp_delete_profile($profile_id); |
|
836
|
|
|
|
|
837
|
|
|
redirectexit('action=admin;area=portalprofiles;sa=list' . str_replace('delete', '', $context['sub_action'])); |
|
838
|
|
|
} |
|
839
|
|
|
|
|
840
|
|
|
/** |
|
841
|
|
|
* Remove a batch of profiles from the system |
|
842
|
|
|
* |
|
843
|
|
|
* - Acts on checkbox selection from the various profile list areas |
|
844
|
|
|
*/ |
|
845
|
|
|
private function _remove_profiles() |
|
846
|
|
|
{ |
|
847
|
|
|
// Removing some permission profiles via checkbox? |
|
848
|
|
|
if (!empty($_POST['remove_profiles']) && !empty($_POST['remove']) && is_array($_POST['remove'])) |
|
849
|
|
|
{ |
|
850
|
|
|
checkSession(); |
|
851
|
|
|
|
|
852
|
|
|
$remove = array(); |
|
853
|
|
|
foreach ($_POST['remove'] as $index => $profile_id) |
|
854
|
|
|
{ |
|
855
|
|
|
$remove[(int) $index] = (int) $profile_id; |
|
856
|
|
|
} |
|
857
|
|
|
|
|
858
|
|
|
sp_delete_profiles($remove); |
|
859
|
|
|
} |
|
860
|
|
|
} |
|
861
|
|
|
} |
|
862
|
|
|
|