-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooker.module.php
More file actions
773 lines (725 loc) · 24.1 KB
/
Copy pathBooker.module.php
File metadata and controls
773 lines (725 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<?php
#------------------------------------------------------------------------
# Module: Booker - a resource booking module for CMS Made Simple
# Mostly copyright (C) 2015-2017 Tom Phane <@>
# This project's forge-page is: http://dev.cmsmadesimple.org/projects/booker
#
# This module is free software. You can redistribute and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of that License, or (at your option)
# any later version.
#
# This module is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License (www.gnu.org/licenses/licenses.html#AGPL)
# for more details
#-----------------------------------------------------------------------
define('DBGBKG', FALSE);
class Booker extends CMSModule
{
const MINGRPID = 16384; //lowest id in items-table for a group
const USERSTYLES = 5; //no. of styles available for bookings-table styling
//sub-group allocation protocol
const ALLOCNONE = 0;
const ALLOCFIRST = 1;
const ALLOCRAND = 2;
const ALLOCROTE = 3;
const ALLOCCHOOSE = 4;
/*list-display formats
LISTSU group by slotstart, show each interval, [resource,] user
LISTRS group by resource,slotstart, show each user interval i.e. ~same as LISTSU unless is group
[LISTUR group by user,resource, show each interval] i.e. only for groups
LISTUS group by user, show each interval [,resource]
*/
const LISTSU = 1;
const LISTRS = 2; //default for imported groups
const LISTUR = 3;
const LISTUS = 4;
//bookings-table-column durations
const SEGDAY = 0;
const SEGWEEK = 1;
const SEGMTH = 2;
// const SEGYR = 3;
//booking-display-periods
const RANGEDAY = 0;
const RANGEWEEK = 1;
const RANGEMTH = 2;
const RANGEYR = 3;
//OnceTable/RepeatTable status codes (Status::StatusKeys() must conform to these)
const STATNONE = 0;//unknown/normal/default
//request-stage
const STATNEW = 1;//new, approver consideration pending
const STATCHG = 2;//change request, approver consideration pending
const STATDEL = 3;//delete request, approver consideration pending
const STATTELL = 4;//further information submitted
const STATASK = 5;//booker queried, waiting for response
const STATCANCEL = 6;//(request to be) abandoned by user, or admin on user's behalf
const STATMAXREQ = 9;//last-recognised request-status value
//later stage
const STATOK = 10;//aka APPROVED done/processed
const STATADMINREC = 11;//booking recorded by admin
const STATSELFREC = 12;//recorded by approved user (i.e. no request)
const STATTEMP = 18;//user-recorded, pending admin confirmation, or at least 'nfa' flag
const STATDEFERRED = 19;//booking to be re-scheduled, per user request or admin imposition
const STATGONE = 20;//deletion pending, while its historical data needed
const STATMAXOK = 20;//last-recognised request-done-ok value
//problems
const STATBIG = 21;//too many slots requested
const STATDEFER = 22;//request not yet processed cuz' too far ahead
const STATLATE = 23;//request past or not far-enough ahead
const STATNA = 24;//resouce N/A at requested time, cannot accept
const STATDUP = 25;//duplicate request, cannot accept
const STATPERM = 26;//user not permitted
const STATNFEE = 27;//request not (entirely) pre/post-paid
const STATERR = 28;//system error while processing
const STATRETRY = 34;//some temporary problem, try again later
const STATFAILED = 35;//generic request-failure
const STATMAXBAD = 39;//last-recognised request-bad value
//statpay codes
const STATFREE = 40;//no fee for use
const STATPAID = 41;//fee pre- or post-paid
const STATCREDITED = 42;//fee to be paid upon request
const STATPAYABLE = 43;//fee applies, none yet paid
const STATPARTPAID = 44;//fee not yet fully paid
const STATNOTPAID = 45;//payable but unpaid for some non-credit-related reason
const STATOVRDUE = 46;//payment overdue
const STATMAXPAY = 49;//last-recognised statpay value
//CreditTable status codes
const CREDITADDED = 50;//prepayment amount
const CREDITUSED = 51;//past credit offset against other use
const CREDITEXPIRED = 52;//past credit timed out
//DispTable bulk-codes/flags (unused)
const BULKSINGL1 = 0;
const BULKSINGLGRP = 1;
const BULKREPT1 = 20;
const BULKREPTGRP = 21;
//cache-key seed/prefixes
const CARTKEY = 'bkr_Cart';
const PARMKEY = 'bkr_Parm';
const SESSIONKEY = 'bkr_Sess';
const PATNADDRESS = '/^\S+@[^\s.]+\.\S+$/';
const PATNPHONE = '/^(\+\d{1,4} *)?[\d ]{5,15}$/';
public $dbHandle; //cached connection to adodb
public $AuthTable; //authenticated-users data
public $BookerTable; //booker details
public $DispTable; //bookings data for display
public $FeeTable; //payment amounts/rates and associated conditions
public $GroupTable; //group-relationships
public $ItemTable; //resources and resource-groups
public $OnceTable; //non-repeated bookings-data
public $CreditTable; //payment-credit data
public $RepeatTable; //repeated bookings-data
public $UserTable; //admin users (who may 'own' resource/group)
public $before20;
public $oldtemplates;
public $havenotifier;
protected $PermStructName = 'Booker Module Admin';
protected $PermAdminName = 'Booker Admin';
protected $PermSeeName = 'Booker View';
protected $PermEditName = 'Booker Modify';
protected $PermAddName = 'Booker Resource Add';
protected $PermModName = 'Booker Resource Modify';
protected $PermDelName = 'Booker Resource Delete';
protected $PermPerName = 'Booker User Modify';
public function __construct()
{
parent::__construct();
$this->RegisterModulePlugin(TRUE);
$this->dbHandle = cmsms()->GetDb();
$pre = cms_db_prefix();
$this->AuthTable = $pre.'module_auth_users'; //table belongs to Auther module
$this->BookerTable = $pre.'module_bkr_bookers';
$this->DispTable = $pre.'module_bkr_data';
$this->FeeTable = $pre.'module_bkr_fees';
$this->GroupTable = $pre.'module_bkr_groups';
$this->ItemTable = $pre.'module_bkr_items';
$this->OnceTable = $pre.'module_bkr_singls';
$this->CreditTable = $pre.'module_bkr_adjust';
$this->RepeatTable = $pre.'module_bkr_repeats';
$this->UserTable = $pre.'users';
global $CMS_VERSION;
$this->before20 = (version_compare($CMS_VERSION,'2.0') < 0);
$this->oldtemplates = $this->before20 || 1; //TODO
$ob = cms_utils::get_module('Notifier');
if ($ob) {
unset($ob);
$this->havenotifier = TRUE;
} else {
$this->havenotifier = FALSE;
}
spl_autoload_register(array($this,'cmsms_spacedload'));
}
public function __destruct()
{
spl_autoload_unregister(array($this,'cmsms_spacedload'));
if (function_exists('parent::__destruct'))
parent::__destruct();
}
/* namespace autoloader - CMSMS default autoloader doesn't do spacing */
private function cmsms_spacedload($class)
{
$prefix = get_class().'\\'; //our namespace prefix
$o = ($class[0] != '\\') ? 0:1;
$p = strpos($class, $prefix, $o);
if ($p === 0 || ($p == 1 && $o == 1)) {
// directory for the namespace
$bp = __DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR;
} else {
$p = strpos($class, '\\', 1);
if ($p === FALSE) {
return;
}
$prefix = substr($class, $o, $p-$o);
$bp = dirname(__DIR__).DIRECTORY_SEPARATOR.$prefix.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR;
}
// relative class name
$len = strlen($prefix) + $o;
$relative_class = trim(substr($class, $len), '\\');
if (($p = strrpos($relative_class,'\\',-1)) !== FALSE) {
$relative_dir = strtr ($relative_class, '\\', DIRECTORY_SEPARATOR);
$bp .= substr($relative_dir, 0, $p+1);
$base = substr($relative_dir, $p+1);
} else {
$base = $relative_class;
}
$fp = $bp.'class.'.$base.'.php';
if (file_exists($fp)) {
include $fp;
return;
}
$fp = $bp.$base.'.php';
if (file_exists($fp)) {
include $fp;
}
}
public function AllowAutoInstall()
{
return FALSE;
}
public function AllowAutoUpgrade()
{
return FALSE;
}
//for 1.11+
public function AllowSmartyCaching()
{
return FALSE;
}
public function GetName()
{
return 'Booker';
}
public function GetFriendlyName()
{
return $this->Lang('title_bookings'); //OR 'friendlyname' post-installation change no effect?!
}
public function GetHelp()
{
$fn = cms_join_path(__DIR__,'css','public.css');
$cont = @file_get_contents($fn);
if ($cont) {
$example = preg_replace(array('~\s?/\*(.*)?\*/~Usm','~\s?//.*$~m'),array('',''),$cont);
$example = str_replace(array("\n\n","\n","\t"),array('<br />','<br />',' '),trim($example));
} else {
$example = $this->Lang('missing');
}
$fn = cms_join_path(__DIR__,'lib','doc','modhelp.htm');
$cont = @file_get_contents($fn);
return sprintf($cont,$example);
}
public function GetVersion()
{
return '0.6';
}
public function GetAuthor()
{
return 'tomphantoo';
}
public function GetAuthorEmail()
{
return 'tpgww@onepost.net';
}
public function GetChangeLog()
{
$fn = cms_join_path(__DIR__,'lib','doc','changelog.htm');
return @file_get_contents($fn);
}
public function IsPluginModule()
{
return TRUE;
}
public function HasAdmin()
{
return TRUE;
}
/*
LazyLoadAdmin() for 1.10 and later
*/
public function LazyLoadAdmin()
{
return TRUE; //NB changing this after the module is installed seems to have no effect
}
public function GetAdminSection()
{
return 'content';
}
public function GetAdminDescription()
{
return $this->Lang('moddescription');
}
public function VisibleToAdminUser()
{
return $this->_CheckAccess();
}
/*public function AdminStyle()
{
}
*/
public function GetHeaderHTML()
{
$base = $this->GetModuleURLPath();
return <<<EOS
<link rel="stylesheet" type="text/css" id="adminstyler" href="{$base}/css/admin.min.css" />
<link rel="stylesheet" type="text/css" href="{$base}/css/alertable.min.css" />
<link rel="stylesheet" type="text/css" href="{$base}/css/pikaday.min.css" />
EOS;
}
public function SuppressAdminOutput(&$request)
{
//prevent output of general admin content when doing an export,
//and when processing an ajax call
if (isset($request['mact'])) {
if (strpos($request['mact'],'exportbooking',6)) return TRUE;
if (isset($request['m1_export'])) return TRUE;
if (isset($request['m1_exportbkg'])) return TRUE;
if (strpos($request['mact'],'sortlike',6)) return TRUE;
}
return FALSE;
}
public function GetDependencies()
{
// return array('Auther'=>'0.2'); NOT YET
return array();
}
/*
LazyLoadFrontend() for 1.10 and later
*/
public function LazyLoadFrontend()
{
return FALSE; //enable routes NB changing this after the module is installed seems to have no effect
}
public function MinimumCMSVersion()
{
return '1.11'; //smarty3 needed CHECKME
}
/*public function MaximumCMSVersion()
{
return '2.2.99';
}
*/
public function InstallPostMessage()
{
return $this->Lang('postinstall');
}
public function UninstallPreMessage()
{
return $this->Lang('really_uninstall');
}
public function UninstallPostMessage()
{
return $this->Lang('postuninstall');
}
/*
SetParameters() for pre-1.10
*/
public function SetParameters()
{
$this->InitializeAdmin();
$this->InitializeFrontend();
}
/*
InitializeFrontend() partial setup for 1.10
*/
public function InitializeFrontend()
{
$this->RestrictUnknownParams();
//TODO parameter types
$this->SetParameterType('account',CLEAN_STRING);
$this->SetParameterType('amount',CLEAN_STRING);
$this->SetParameterType('apply',CLEAN_STRING); //change view enum
$this->SetParameterType('authdata',CLEAN_STRING); //data from authpanel
$this->SetParameterType('bookat',CLEAN_INT);
$this->SetParameterType('bookertype',CLEAN_INT);
$this->SetParameterType('bkgid',CLEAN_INT);
$this->SetParameterType('calendarinput',CLEAN_STRING);
$this->SetParameterType('cancel',CLEAN_NONE);
$this->SetParameterType('captcha',CLEAN_STRING);
$this->SetParameterType('cart',CLEAN_NONE);
$this->SetParameterType('cartcomment',CLEAN_STRING); //array of comments
$this->SetParameterType('cartsel',CLEAN_STRING); //array of keys
$this->SetParameterType('itempick',CLEAN_INT);
$this->SetParameterType('clickat',CLEAN_STRING);
$this->SetParameterType('comment',CLEAN_STRING); //booking-request parameters
$this->SetParameterType('contact',CLEAN_STRING);
$this->SetParameterType('contactnew',CLEAN_STRING);
$this->SetParameterType('delete',CLEAN_NONE); //cart-item action
$this->SetParameterType('find',CLEAN_NONE);
$this->SetParameterType('findpick',CLEAN_INT);
$this->SetParameterType('findfirst',CLEAN_STRING);
$this->SetParameterType('findlast',CLEAN_STRING);
$this->SetParameterType('finduser',CLEAN_STRING);
$this->SetParameterType('findusertype',CLEAN_INT);
$this->SetParameterType('firstpick',CLEAN_INT);
$this->SetParameterType('item',CLEAN_STRING); //id or alias
$this->SetParameterType('item_id',CLEAN_INT); //for zooms
$this->SetParameterType('itemkeys',CLEAN_STRING);
$this->SetParameterType('listformat',CLEAN_INT); //list-format enum
$this->SetParameterType('message',CLEAN_STRING);
$this->SetParameterType('name',CLEAN_STRING);
$this->SetParameterType('newlist',CLEAN_INT); //list-format change boolean
$this->SetParameterType('origreturnid',CLEAN_INT); //something? related to captcha module
$this->SetParameterType('pagerows',CLEAN_INT); //table-pager value
$this->SetParameterType('passwd',CLEAN_STRING);
$this->SetParameterType('range',CLEAN_STRING); //enum or period-name
$this->SetParameterType('rangepick',CLEAN_INT); //change view-range enum
$this->SetParameterType('register',CLEAN_NONE);
$this->SetParameterType('request',CLEAN_NONE);
$this->SetParameterType('requesttype',CLEAN_INT);
$this->SetParameterType('search',CLEAN_NONE);
$this->SetParameterType('searchsel',CLEAN_NONE);
$this->SetParameterType('slide',CLEAN_INT); //value matches button label
// $this->SetParameterType('slotlen',CLEAN_INT);
// $this->SetParameterType('slotstart',CLEAN_INT);
$this->SetParameterType('showfrom',CLEAN_STRING);
// $this->SetParameterType('paramskey',CLEAN_STRING);
$this->SetParameterType('subgrpcount',CLEAN_INT);
$this->SetParameterType('submit',CLEAN_NONE);
$this->SetParameterType('task',CLEAN_STRING);
$this->SetParameterType('toggle',CLEAN_NONE);
$this->SetParameterType('until',CLEAN_STRING);
// $this->SetParameterType('user',CLEAN_STRING);
$this->SetParameterType('view',CLEAN_STRING); //table or list
$this->SetParameterType('when',CLEAN_STRING);
$this->SetParameterType('zoomin',CLEAN_NONE);
$this->SetParameterType('zoomout',CLEAN_NONE);
$this->SetParameterType(CLEAN_REGEXP.'/bkr_.*/',CLEAN_STRING);
/* register 'routes' to use for pretty url parsing
these regexes are for site-root-url-relative 'paths', they translate
url-element(s) to $param[](s) be supplied to the specified actions
(default calls ->DisplayModuleOutput()) so the routes need to conform
to parameter-usage in handler-func(s).
(?P<name>regex) captures the text matched by "regex" into the group "name",
which can contain letters and numbers but must start with a letter.
See also: Booker\Utils->GetLink() which needs to conform to this.
*/
// display bookings for a specific group/item
//NB the correct page-id is needed (in the URL or otherwise) to display
//generated content on the correct page! TODO find a dynamic way around this
$pageid = $this->GetPreference('sitepage','');
if ($pageid) {
$manager = cmsms()->GetHierarchyManager();
$node = $manager->sureGetNodeByAlias($pageid);
if ($node) {
$onpage = $node->getID();
$this->RegisterRoute('/[Bb]ook(ings?|er)?\/(?P<item>.+)\/submit$/',array('action'=>'dobooking','bookat'=>-1,'returnid'=>$onpage));
$this->RegisterRoute('/[Bb]ook(ings?|er)?\/(?P<item>.+)$/',array('action'=>'default','returnid'=>$onpage));
$this->RegisterRoute('/[Bb]ook(ings?|er)?\/submit$/',array('action'=>'dobooking','bookwhat'=>-1,'returnid'=>$onpage));
}
}
$this->RegisterRoute('/[Bb]ook(ings?|er)?\/(?P<returnid>[0-9]+)\/(?P<item>.+)$/',array('action'=>'default'));
}
/*
InitializeAdmin() partial setup for 1.10
*/
public function InitializeAdmin()
{
$this->CreateParameter('item','',$this->Lang('help_item'));
$this->CreateParameter('showfrom','',$this->Lang('help_showfrom'));
$this->CreateParameter('range',$this->Lang('week'),$this->Lang('help_range'));
$this->CreateParameter('view','table',$this->Lang('help_view'));
}
/*
get_tasks:
Specify the tasks that this module uses
Returns: CmsRegularTask-compliant object, or array of them
*/
public function get_tasks()
{
return array(
new Booker\Cleanold_task(),
new Booker\Clearcache_task()
);
}
/**
DoAction:
@action:
@id: session identifier
@params:
@returnid:
*/
public function DoAction($action, $id, $params, $returnid=-1)
{
switch ($action) {
case 'announce':
case 'default':
case 'defaultadmin':
case 'delete':
case 'dobooking':
case 'exportbooking':
case 'findbooking':
case 'import':
case 'notifybooker':
case 'openbooker':
case 'openbooking':
case 'openrequest':
case 'auth':
case 'openfees':
case 'opencart':
case 'setprefs':
case 'swapgroups':
case 'sortlike':
case 'processreport':
case 'filter':
break;
case 'bookerbookings':
case 'itembookings':
if (isset($params['importbkg']))
$action = 'import';
break;
case 'adminbooker':
if (isset($params['importbkr']))
$action = 'import';
break;
/* case 'adminbooking':
if (isset($params['importbkg']))
$action = 'import';
elseif (isset($params['find']))
$action = 'findbooking'; //TODO admin, not frontend
else
$action = 'processrequest';
break;
*/
case 'processitem': //multiple/selected/?export?/delete etc
if (isset($params['setfees']))
$action = 'openfees';
elseif (isset($params['importitm']) || isset($params['importfee']))
$action = 'import';
break;
case 'processrequest':
if (isset($params['importbkg']))
$action = 'import';
break;
/* case 'approve':
case 'reject':
//TODO others
case 'rapprove':
case 'rreject':
case 'rdelete':
case 'redit':
case 'rnotify':
case 'rsee':
$action = 'processrequest';
break;
*/
case 'openitem':
if (isset($params['modfee'])) //in-page edit-fees button clicked
$action = 'openfees';
elseif (isset($params['sortlike']))
$action = 'sortlike';
break;
case 'addfee':
case 'delfee':
case 'modfee':
$action = 'openfees';
break;
case 'toggle': //[de]activate
$this->_ActivateItem($id, $params, $returnid); //trivial func, don't bother with separate action file
$action = 'defaultadmin';
break;
default:
if (isset($params['active_tab'])) //TODO if backend
$action = 'defaultadmin';
else
return;
}
parent::DoAction($action,$id,$params,$returnid);
}
/**
_CheckAccess($permission='',$warn=FALSE)
NOT PART OF THE MODULE API
*/
public function _CheckAccess($permission='', $warn=FALSE)
{
switch ($permission) {
case '': //anything relevant
$name = '';
$ok = $this->CheckPermission($this->PermAdminName);
if (!$ok) $ok = $this->CheckPermission($this->PermSeeName);
if (!$ok) $ok = $this->CheckPermission($this->PermEditName);
if (!$ok) $ok = $this->CheckPermission($this->PermPerName);
if (!$ok) $ok = $this->CheckPermission($this->PermAddName);
if (!$ok) $ok = $this->CheckPermission($this->PermDelName);
if (!$ok) $ok = $this->CheckPermission($this->PermModName);
if (!$ok) $ok = $this->CheckPermission($this->PermStructName);
break;
//bookings
case 'view':
$name = $this->PermSeeName;
$ok = $this->CheckPermission($name);
break;
case 'book':
$name = $this->PermEditName;
$ok = $this->CheckPermission($name);
break;
case 'admin':
$name = $this->PermAdminName;
$ok = $this->CheckPermission($name);
break;
//bookers
case 'booker':
$name = $this->PermPerName;
$ok = $this->CheckPermission($name);
break;
//resources
case 'add':
$name = $this->PermAddName;
$ok = $this->CheckPermission($name);
break;
case 'modify':
$name = $this->PermModName;
$ok = $this->CheckPermission($name);
break;
case 'delete':
$name = $this->PermDelName;
$ok = $this->CheckPermission($name);
break;
//module
case 'module':
$name = $this->PermStructName;
$ok = $this->CheckPermission($name);
break;
default:
$name = '';
$ok = FALSE;
}
if (!$ok && $warn) {
if ($name == '') $name = $this->Lang('perm_some');
echo '<p class="error">'.$this->Lang('accessdenied',$name).'</p>';
}
return $ok;
}
/* *
_GetActiveTab(&$params)
Get name of active tab (in a multi-tab page)
*/
/*public function _GetActiveTab(&$params)
{
if (empty($params['active_tab']))
return 'data';
else
return $params['active_tab'];
}
*/
/**
_PrettyMessage:
@text: text to display, or if @key = TRUE, a lang-key for the text to display
@success: optional default TRUE whether to style message as positive
@key: optional default TRUE whether @text is a lang key or raw
*/
public function _PrettyMessage($text, $success=TRUE, $key=TRUE)
{
$base = ($key) ? $this->Lang($text) : $text;
if ($success)
return $this->ShowMessage($base);
else {
$msg = $this->ShowErrors($base);
// if ($faillink == FALSE) {
//strip the link
$pos = strpos($msg,'<a href=');
$part1 = ($pos !== FALSE) ? substr($msg,0,$pos) : '';
$pos = strpos($msg,'</a>',$pos);
$part2 = ($pos !== FALSE) ? substr($msg,$pos+4) : $msg;
$msg = $part1.$part2;
// }
return $msg;
}
}
/**
_CreateInputLinks:
Generate xhtml for image and/or submit input(s) which can be styled like an icon
and/or link, using class "fakeicon" for an image, "fakelink" for a standard link.
Such object(s) is(are) needed where the handler/action requires all form data,
instead of just the data for the oject itself (which happens for a normal link)
@id: session identifier
@name: name of action to be performed when (either of) the object(s) is clicked
@iconfile: optional name of theme icon, or module-relative or absolute URL
of some other icon for image input, default FALSE i.e. no image
@link: optional whether to (also) create a submit input, default FALSE
@text: optional title and tip for an image, or mandatory displayed text for a link, default ''
@extra: optional additional text that should be added into the object, default ''
*/
public function _CreateInputLinks($id, $name, $iconfile=FALSE, $link=FALSE, $text='', $extra='')
{
if ($iconfile) {
$p = strpos($iconfile,'/');
if ($p === FALSE) {
$theme = ($this->before20) ? cmsms()->get_variable('admintheme'):
cms_utils::get_theme_object();
$imgstr = $theme->DisplayImage('icons/system/'.$iconfile,$text,'','','fakeicon systemicon');
//trim string like <img src="..." class="fakeicon systemicon" alt="$text" title="$text" />
$imgstr = str_replace(array('<img','/>'),array('',''),$imgstr);
} elseif ($p == 0) {
$imgstr = $this->GetModuleURLPath().$iconfile; } elseif (strpos($iconfile,'://',$p-1) === $p-1) {
$imgstr = $iconfile; } else {
$imgstr = $this->GetModuleURLPath().'/'.$iconfile; }
$ret = '<input type="image" '.$imgstr.' name="'.$id.$name.'"'; //conservative assumption about spaces
if ($extra)
$ret .= ' '.$extra;
$ret .= ' />';
} else
$ret = '';
if ($link && $text) {
if ($ret)
$ret .=' ';
$ret .='<input type="submit" value="'.$text.'" name="'.$id.$name.'" class="fakelink"';
if ($extra)
$ret .= ' '.$extra;
$ret .= ' />';
}
return $ret;
}
/**
_ActivateItem:
@id: session identifier
@params: array of parameters for the action
@returnid:
[de]activate the item passed in @params
See also: Booker\Itemops::ToggleItemActive()
*/
public function _ActivateItem($id, &$params, $returnid)
{
if (isset($params['item_id'])) {
$qdata = array();
if (isset($params['active'])) {
if ($params['active'] > 0) { //1 always; 2 inherit
$qdata[] = 0;
} else { //0 inactive; -1 deletion pending
$qdata[] = 1;
}
} else {
$qdata[] = 0;
}
$qdata[] = $params['item_id'];
$sql = 'UPDATE '.$this->ItemTable.' SET active=? WHERE item_id=?';
$this->dbHandle->Execute($sql,$qdata);
if ($params['item_id'] < Booker::MINGRPID) {
$params = array('active_tab' => 'items');
} else {
$params = array('active_tab' => 'groups');
}
} else {
$params = array('active_tab' => 'items');
}
}
}