1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace XoopsModules\Wgevents; |
5
|
|
|
|
6
|
|
|
/* |
7
|
|
|
You may not change or alter any portion of this comment or credits |
8
|
|
|
of supporting developers from this source code or any supporting source code |
9
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
10
|
|
|
|
11
|
|
|
This program is distributed in the hope that it will be useful, |
12
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* wgEvents module for xoops |
18
|
|
|
* |
19
|
|
|
* @copyright 2021 XOOPS Project (https://xoops.org) |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @package wgevents |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
* @min_xoops 2.5.11 Beta1 |
24
|
|
|
* @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
use XoopsModule; |
28
|
|
|
use XoopsModules\Wgevents; |
29
|
|
|
|
30
|
|
|
\defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class Object PermissionHandler |
34
|
|
|
*/ |
35
|
|
|
class PermissionHandler extends \XoopsPersistableObjectHandler |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* Constructor |
39
|
|
|
* |
40
|
|
|
* @param null |
41
|
|
|
*/ |
42
|
|
|
public function __construct() |
43
|
|
|
{ |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @private function getPermSubmit |
49
|
|
|
* returns right to submit for given perm |
50
|
|
|
* @param $constantPerm |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
private function getPerm($constantPerm) |
54
|
|
|
{ |
55
|
|
|
global $xoopsUser; |
56
|
|
|
|
57
|
|
|
$moduleDirName = \basename(\dirname(__DIR__));; |
58
|
|
|
$mid = XoopsModule::getByDirname($moduleDirName)->mid(); |
59
|
|
|
$currentuid = 0; |
60
|
|
|
if (isset($xoopsUser) && \is_object($xoopsUser)) { |
61
|
|
|
if ($xoopsUser->isAdmin($mid)) { |
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
$currentuid = $xoopsUser->uid(); |
65
|
|
|
} |
66
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
$memberHandler = \xoops_getHandler('member'); |
70
|
|
|
if (0 == $currentuid) { |
71
|
|
|
$my_group_ids = [\XOOPS_GROUP_ANONYMOUS]; |
72
|
|
|
} else { |
73
|
|
|
$my_group_ids = $memberHandler->getGroupsByUser($currentuid); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
if ($grouppermHandler->checkRight('wgevents_ac', $constantPerm, $my_group_ids, $mid)) { |
|
|
|
|
76
|
|
|
return true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @private function getPermSubmit |
84
|
|
|
* returns right to submit for given perm |
85
|
|
|
* @param $constantPerm |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
|
private function getPermApprove($constantPerm) |
89
|
|
|
{ |
90
|
|
|
if ($this->getPermGlobalApprove()) { |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $this->getPerm($constantPerm); |
95
|
|
|
} |
96
|
|
|
/** |
97
|
|
|
* @private function getPermSubmit |
98
|
|
|
* returns right to submit for given perm |
99
|
|
|
* @param $constantPerm |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
private function getPermSubmit($constantPerm) |
103
|
|
|
{ |
104
|
|
|
if ($this->getPermGlobalSubmit()) { |
105
|
|
|
return true; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $this->getPerm($constantPerm); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @private function getPermView |
113
|
|
|
* returns right for view of given perm |
114
|
|
|
* @param $constantPerm |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
private function getPermView($constantPerm) |
118
|
|
|
{ |
119
|
|
|
if ($this->getPermGlobalView()) { |
120
|
|
|
return true; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this->getPerm($constantPerm); |
124
|
|
|
} |
125
|
|
|
/** |
126
|
|
|
* @public function permGlobalApprove |
127
|
|
|
* returns right for global approve |
128
|
|
|
* |
129
|
|
|
* @param null |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
|
|
public function getPermGlobalApprove() |
133
|
|
|
{ |
134
|
|
|
return $this->getPerm(Constants::PERM_GLOBAL_APPROVE); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @public function permGlobalSubmit |
139
|
|
|
* returns right for global submit |
140
|
|
|
* |
141
|
|
|
* @param null |
142
|
|
|
* @return bool |
143
|
|
|
*/ |
144
|
|
|
public function getPermGlobalSubmit() |
145
|
|
|
{ |
146
|
|
|
if ($this->getPermGlobalApprove()) { |
147
|
|
|
return true; |
148
|
|
|
} |
149
|
|
|
return $this->getPerm(Constants::PERM_GLOBAL_SUBMIT); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @public function permGlobalView |
154
|
|
|
* returns right for global view |
155
|
|
|
* |
156
|
|
|
* @param null |
157
|
|
|
* @return bool |
158
|
|
|
*/ |
159
|
|
|
public function getPermGlobalView() |
160
|
|
|
{ |
161
|
|
|
if ($this->getPermGlobalApprove() || $this->getPermGlobalSubmit()) { |
162
|
|
|
return true; |
163
|
|
|
} |
164
|
|
|
return $this->getPerm(Constants::PERM_GLOBAL_APPROVE); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @public function getPermEventsApprove |
169
|
|
|
* returns right for approve events |
170
|
|
|
* @param null |
171
|
|
|
* @return bool |
172
|
|
|
*/ |
173
|
|
|
public function getPermEventsApprove() |
174
|
|
|
{ |
175
|
|
|
if ($this->getPermGlobalApprove()) { |
176
|
|
|
return true; |
177
|
|
|
} |
178
|
|
|
return $this->getPermApprove(Constants::PERM_EVENTS_APPROVE); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @public function getPermEventsApproveAuto |
183
|
|
|
* returns right for approve events |
184
|
|
|
* @param null |
185
|
|
|
* @return bool |
186
|
|
|
*/ |
187
|
|
|
public function getPermEventsApproveAuto() |
188
|
|
|
{ |
189
|
|
|
if ($this->getPermEventsApprove()) { |
190
|
|
|
return true; |
191
|
|
|
} |
192
|
|
|
return $this->getPermApprove(Constants::PERM_EVENTS_APPROVE_AUTO); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @public function getPermEventsSubmit |
197
|
|
|
* returns right for submit events |
198
|
|
|
* @param null |
199
|
|
|
* @return bool |
200
|
|
|
*/ |
201
|
|
|
public function getPermEventsSubmit() |
202
|
|
|
{ |
203
|
|
|
if ($this->getPermGlobalSubmit()) { |
204
|
|
|
return true; |
205
|
|
|
} |
206
|
|
|
return $this->getPermSubmit(Constants::PERM_EVENTS_SUBMIT); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @public function getPermEventsEdit |
211
|
|
|
* returns right for edit/delete events |
212
|
|
|
* - User must have perm to submit and must be owner |
213
|
|
|
* - transaction is not closed |
214
|
|
|
* @param $evSubmitter |
215
|
|
|
* @param $evStatus |
216
|
|
|
* @return bool |
217
|
|
|
*/ |
218
|
|
|
public function getPermEventsEdit($evSubmitter, $evStatus) |
219
|
|
|
{ |
220
|
|
|
global $xoopsUser, $xoopsModule; |
221
|
|
|
|
222
|
|
|
if ($this->getPermEventsApprove()) { |
223
|
|
|
return true; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
if (Constants::STATUS_LOCKED == $evStatus) { |
227
|
|
|
return false; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
$currentuid = 0; |
231
|
|
|
if (isset($xoopsUser) && \is_object($xoopsUser)) { |
232
|
|
|
if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
233
|
|
|
return true; |
234
|
|
|
} |
235
|
|
|
$currentuid = $xoopsUser->uid(); |
236
|
|
|
} |
237
|
|
|
return $this->getPermEventsSubmit() && $currentuid == $evSubmitter; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @public function getPermEventsView |
242
|
|
|
* returns right for view Event |
243
|
|
|
* @param null |
244
|
|
|
* @return bool |
245
|
|
|
*/ |
246
|
|
|
public function getPermEventsView() |
247
|
|
|
{ |
248
|
|
|
return $this->getPermView(Constants::PERM_EVENTS_VIEW); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @public function getPermQuestionsAdmin |
253
|
|
|
* returns right for submit/edit/delete questions |
254
|
|
|
* - User must have perm edit the event |
255
|
|
|
* @param $evSubmitter |
256
|
|
|
* @param $evStatus |
257
|
|
|
* @return bool |
258
|
|
|
*/ |
259
|
|
|
public function getPermQuestionsAdmin($evSubmitter, $evStatus) |
260
|
|
|
{ |
261
|
|
|
if ($this->getPermEventsEdit($evSubmitter, $evStatus)) { |
262
|
|
|
return true; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
return false; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @public function getPermRegistrationsApprove |
270
|
|
|
* returns right for approve registrations |
271
|
|
|
* - User must have perm edit the event (owner or approver) |
272
|
|
|
* @param $evSubmitter |
273
|
|
|
* @param $evStatus |
274
|
|
|
* @return bool |
275
|
|
|
*/ |
276
|
|
|
public function getPermRegistrationsApprove($evSubmitter, $evStatus) |
277
|
|
|
{ |
278
|
|
|
if ($this->getPermEventsEdit($evSubmitter, $evStatus)) { |
279
|
|
|
return true; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return false; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @public function getPermRegistrationsVerif |
287
|
|
|
* returns right for submit registrations without question verification by mail |
288
|
|
|
* - User must have perm to submit registrations |
289
|
|
|
* @param null |
290
|
|
|
* @return bool |
291
|
|
|
*/ |
292
|
|
|
public function getPermRegistrationsVerif() |
293
|
|
|
{ |
294
|
|
|
return $this->getPerm(Constants::PERM_REGISTRATIONS_AUTOVERIF); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @public function getPermRegistrationsSubmit |
299
|
|
|
* returns right for submit registrations |
300
|
|
|
* @param null |
301
|
|
|
* @return bool |
302
|
|
|
*/ |
303
|
|
|
public function getPermRegistrationsSubmit() |
304
|
|
|
{ |
305
|
|
|
if ($this->getPermRegistrationsVerif()) { |
306
|
|
|
return true; |
307
|
|
|
} |
308
|
|
|
return $this->getPermSubmit(Constants::PERM_REGISTRATIONS_SUBMIT); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @public function getPermRegistrationsEdit |
313
|
|
|
* returns right for edit/delete registrations |
314
|
|
|
* - User have permission to edit the event |
315
|
|
|
* - User must have perm to submit and must be owner |
316
|
|
|
* @param $regIp |
317
|
|
|
* @param $regSubmitter |
318
|
|
|
* @param $evSubmitter |
319
|
|
|
* @param $evStatus |
320
|
|
|
* @return bool |
321
|
|
|
*/ |
322
|
|
|
public function getPermRegistrationsEdit($regIp, $regSubmitter, $evSubmitter, $evStatus) |
323
|
|
|
{ |
324
|
|
|
if ($this->getPermEventsEdit($evSubmitter, $evStatus)) { |
325
|
|
|
return true; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
if ($this->getPermRegistrationsSubmit() && $this->getPermRegistrationsView($regIp, $regSubmitter)) { |
329
|
|
|
return true; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
return false; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @public function getPermRegistrationsView |
337
|
|
|
* returns right for view Registration |
338
|
|
|
* - user must be the submitter_text of registration or same IP must be used |
339
|
|
|
* @param $regIp |
340
|
|
|
* @param $regSubmitter |
341
|
|
|
* @return bool |
342
|
|
|
*/ |
343
|
|
|
public function getPermRegistrationsView($regIp, $regSubmitter) |
344
|
|
|
{ |
345
|
|
|
$uidCurrent = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0; |
346
|
|
|
if ($regSubmitter == $uidCurrent) { |
347
|
|
|
return true; |
348
|
|
|
} |
349
|
|
|
$ipCurrent = $_SERVER['REMOTE_ADDR']; |
350
|
|
|
return $regIp == $ipCurrent; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @public function getPermTextblocksSubmit |
355
|
|
|
* returns right for submit textblocks |
356
|
|
|
* @param null |
357
|
|
|
* @return bool |
358
|
|
|
*/ |
359
|
|
|
public function getPermTextblocksSubmit() |
360
|
|
|
{ |
361
|
|
|
return $this->getPermEventsSubmit(); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @public function getPermTextblocksAdmin |
366
|
|
|
* returns right for edit/delete textblocks |
367
|
|
|
* - User must have perm to submit and must be owner |
368
|
|
|
* @param $tbSubmitter |
369
|
|
|
* @return bool |
370
|
|
|
*/ |
371
|
|
|
public function getPermTextblocksEdit($tbSubmitter) |
372
|
|
|
{ |
373
|
|
|
global $xoopsUser, $xoopsModule; |
374
|
|
|
|
375
|
|
|
if ($this->getPermGlobalApprove()) { |
376
|
|
|
return true; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
$currentuid = 0; |
380
|
|
|
if (isset($xoopsUser) && \is_object($xoopsUser)) { |
381
|
|
|
if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
382
|
|
|
return true; |
383
|
|
|
} |
384
|
|
|
$currentuid = $xoopsUser->uid(); |
385
|
|
|
} |
386
|
|
|
return $this->getPermTextblocksSubmit() && $currentuid == $tbSubmitter; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* @public function getPermTextblocksAdmin |
391
|
|
|
* returns right for edit/delete textblocks |
392
|
|
|
* - User must have perm to submit and must be owner |
393
|
|
|
* @param $tbSubmitter |
394
|
|
|
* @return bool |
395
|
|
|
*/ |
396
|
|
|
public function getPermTextblocksAdmin($tbSubmitter) |
397
|
|
|
{ |
398
|
|
|
global $xoopsUser, $xoopsModule; |
399
|
|
|
|
400
|
|
|
if ($this->getPermGlobalApprove()) { |
401
|
|
|
return true; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
$currentuid = 0; |
405
|
|
|
if (isset($xoopsUser) && \is_object($xoopsUser)) { |
406
|
|
|
if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
407
|
|
|
return true; |
408
|
|
|
} |
409
|
|
|
$currentuid = $xoopsUser->uid(); |
410
|
|
|
} |
411
|
|
|
return $this->getPermTextblocksSubmit() && $currentuid == $tbSubmitter; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
|
415
|
|
|
|
416
|
|
|
|
417
|
|
|
|
418
|
|
|
|
419
|
|
|
|
420
|
|
|
|
421
|
|
|
|
422
|
|
|
/** Check permission for categories |
423
|
|
|
* @param string $permName |
424
|
|
|
* @param int $catId |
425
|
|
|
* @return int |
426
|
|
|
|
427
|
|
|
private function permPermCats($permName, $catId) |
428
|
|
|
{ |
429
|
|
|
global $xoopsUser, $xoopsModule; |
430
|
|
|
|
431
|
|
|
$currentuid = 0; |
432
|
|
|
if (isset($xoopsUser) && \is_object($xoopsUser)) { |
433
|
|
|
if ($xoopsUser->isAdmin()) { |
434
|
|
|
return 1; |
435
|
|
|
} |
436
|
|
|
$currentuid = $xoopsUser->uid(); |
437
|
|
|
} |
438
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
439
|
|
|
$mid = $xoopsModule->mid(); |
440
|
|
|
$memberHandler = \xoops_getHandler('member'); |
441
|
|
|
if (0 == $currentuid) { |
442
|
|
|
$my_group_ids = [\XOOPS_GROUP_ANONYMOUS]; |
443
|
|
|
} else { |
444
|
|
|
$my_group_ids = $memberHandler->getGroupsByUser($currentuid); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
return $grouppermHandler->checkRight($permName, $catId, $my_group_ids, $mid); |
448
|
|
|
}*/ |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @public function getPermCatEventsView |
452
|
|
|
* returns right for view events of this category |
453
|
|
|
* @param int $catId |
454
|
|
|
* @return bool |
455
|
|
|
|
456
|
|
|
public function getPermCatEventsView($catId) |
457
|
|
|
{ |
458
|
|
|
return $this->permPermCats('wgevents_view_cat_events', $catId); |
459
|
|
|
}*/ |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* @public function getPermCatEventsSubmit |
463
|
|
|
* returns right for submit events to this category |
464
|
|
|
* @param int $catId |
465
|
|
|
* @return bool |
466
|
|
|
|
467
|
|
|
public function getPermCatEventsSubmit($catId) |
468
|
|
|
{ |
469
|
|
|
return $this->permPermCats('wgevents_submit_cat_events', $catId); |
470
|
|
|
}*/ |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* @public function getPermCatEventsApprove |
474
|
|
|
* returns right for approve events of this category |
475
|
|
|
* @param int $catId |
476
|
|
|
* @return bool |
477
|
|
|
|
478
|
|
|
public function getPermCatEventsApprove($catId) |
479
|
|
|
{ |
480
|
|
|
return $this->permPermCats('wgevents_approve_cat_events', $catId); |
481
|
|
|
}*/ |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* @public function getPermCatRegsView |
485
|
|
|
* returns right for view registrations of events of this category |
486
|
|
|
* @param int $catId |
487
|
|
|
* @return bool |
488
|
|
|
|
489
|
|
|
public function getPermCatRegsView($catId) |
490
|
|
|
{ |
491
|
|
|
return $this->permPermCats('wgevents_view_cat_regs', $catId); |
492
|
|
|
}*/ |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* @public function getPermCatRegsSubmit |
496
|
|
|
* returns right for submit registrations to events to this category |
497
|
|
|
* @param int $catId |
498
|
|
|
* @return bool |
499
|
|
|
|
500
|
|
|
public function getPermCatRegsSubmit($catId) |
501
|
|
|
{ |
502
|
|
|
return $this->permPermCats('wgevents_submit_cat_regs', $catId); |
503
|
|
|
}*/ |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* @public function getPermCatRegsApprove |
507
|
|
|
* returns right for approve registrations of events of this category |
508
|
|
|
* @param int $catId |
509
|
|
|
* @return bool |
510
|
|
|
|
511
|
|
|
public function getPermCatRegsApprove($catId) |
512
|
|
|
{ |
513
|
|
|
return $this->permPermCats('wgevents_approve_cat_regs', $catId); |
514
|
|
|
}*/ |
515
|
|
|
|
516
|
|
|
} |
517
|
|
|
|