forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
access.php
458 lines (414 loc) · 16.5 KB
/
access.php
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
<?php
/**
* $Id: access.php,v 1.60.2.1 2012/02/28 15:43:09 cknudsen Exp $
*
* This page is used to manage user access rights.
*
* It has three different modes:
* - list users to manage (no parameters)
* - manage a single user's rights (just "user" parameter)
* this will include which functions the user can access and
* (if $ALLOW_VIEW_OTHER is 'Y') which calendars thay can view/edit/approve
* - update the database (form handler)
*
* Input Parameters:
* user - specifies which user to manage, a form will be presented
* that allows editing rights of this user
*
* access_N - where N is 0 to ACCESS_NUMBER_FUNCTIONS as defined in
* includes/access.php. Each should be either 'Y' or 'N'.
*/
include_once 'includes/init.php';
require_valid_referring_url ();
$allow_view_other =
( ! empty( $ALLOW_VIEW_OTHER ) && $ALLOW_VIEW_OTHER == 'Y' );
if( ! access_is_enabled() ) {
echo print_not_auth();
exit;
}
$dbErrStr = translate( 'Database error XXX.' );
$defConfigStr = translate( 'DEFAULT CONFIGURATION' );
$goStr = '
</select>
<input type="submit" value="' . translate( 'Go' ) . '" />
</form>';
$saveStr = translate( 'Save' );
$undoStr = translate( 'Undo' );
$saved = '';
// Are we handling the access form?
// If so, do that, then redirect.
// Handle function access first.
if( getPostValue( 'auser' ) != '' && getPostValue( 'submit' ) == $saveStr ) {
$auser = getPostValue( 'auser' );
$perm = '';
for( $i = 0; $i < ACCESS_NUMBER_FUNCTIONS; $i++ ) {
$perm .= ( getPostValue( 'access_' . $i ) == 'Y' ? 'Y' : 'N' );
}
dbi_execute( 'DELETE FROM webcal_access_function
WHERE cal_login = ?', [$auser] );
if( ! dbi_execute( 'INSERT INTO webcal_access_function( cal_login,
cal_permissions ) VALUES ( ?, ? )', [$auser, $perm] ) )
die_miserable_death( str_replace( 'XXX', dbi_error(), $dbErrStr ) );
$saved = true;
}
// Are we handling the other user form? If so, do that, then redirect.
if( getPostValue( 'otheruser' ) != '' && getPostValue( 'submit' ) == $saveStr ) {
$puser = getPostValue( 'guser' );
$pouser = getPostValue( 'otheruser' );
if( $allow_view_other ) {
// Handle access to other users' calendars.
// If user is not admin,
// reverse values so they are granting access to their own calendar.
if( ! $is_admin )
list( $puser, $pouser ) = [$pouser, $puser];
dbi_execute( 'DELETE FROM webcal_access_user WHERE cal_login = ?
AND cal_other_user = ?', [$puser, $pouser] );
$approve_total = $edit_total = $view_total = 0;
for( $i = 1; $i <= 256; ) {
$approve_total += getPostValue( 'a_' . $i );
$edit_total += getPostValue( 'e_' . $i );
$view_total += getPostValue( 'v_' . $i );
$i += $i;
}
$email = getPostValue( 'email' );
$invite = getPostValue( 'invite' );
$time = getPostValue( 'time' );
if( ! dbi_execute( 'INSERT INTO webcal_access_user ( cal_login,
cal_other_user, cal_can_view, cal_can_edit, cal_can_approve,
cal_can_invite, cal_can_email, cal_see_time_only )
VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )',
[
$puser,
$pouser,
( $view_total > 0 ? $view_total : 0 ),
( $edit_total > 0 && $puser != '__public__' ? $edit_total : 0 ),
( $approve_total > 0 && $puser != '__public__' ? $approve_total : 0 ),
( strlen( $invite ) ? $invite : 'N' ),
( strlen( $email ) ? $email : 'N' ),
( strlen( $time ) ? $time : 'N' )] ) )
die_miserable_death( str_replace( 'XXX', dbi_error(), $dbErrStr ) );
$saved = true;
}
}
$checked = ' checked="checked"';
$guser = getPostValue( 'guser' );
$selected = ' selected="selected"';
if( $guser == '__default__' ) {
$otheruser = $guser;
$user_fullname = $defConfigStr;
} else
$otheruser = getPostValue( 'otheruser' );
if( $otheruser == '__default__' ) {
$otheruser_fullname = $defConfigStr;
$otheruser_login = '__default__';
} elseif( $otheruser == '__public__' ) {
$otheruser_fullname = translate( 'Public Access' );
$otheruser_login = '__public__';
}
if( ! empty( $otheruser ) ) {
if( $allow_view_other ) {
user_load_variables( $otheruser, 'otheruser_' );
// Turn off admin override so we see the users own settings.
$ADMIN_OVERRIDE_UAC = 'N';
// Now load all the data from webcal_access_user.
$allPermissions = access_load_user_permissions( false );
// Load default-default values if exist.
if( ! empty( $allPermissions['__default__.__default__'] ) )
$op = $allPermissions['__default__.__default__'];
if( $is_admin ) {
// Load user-default values if exist.
if( ! empty( $allPermissions[ $guser . '.__default__' ] ) )
$op = $allPermissions[ $guser . '.__default__' ];
// Load user-otheruser values if exist.
if( ! empty( $allPermissions[ $guser . '.' . $otheruser ] ) )
$op = $allPermissions[ $guser . '.' . $otheruser ];
} else {
// Load default-user values if exist.
if( ! empty( $allPermissions['__default__.' . $guser] ) )
$op = $allPermissions['__default__.' . $guser ];
// Load otheruser-user values if exist.
if( ! empty( $allPermissions[$otheruser . '.' . $guser] ) )
$op = $allPermissions[$otheruser . '.' . $guser];
}
}
}
print_header( '',
'<script type="text/javascript" src="includes/js/access.js?'
. filemtime( 'includes/js/access.js' ) . '"></script>
<link type="text/css" href="includes/css/access.css?'
. filemtime( 'includes/css/access.css' ) . '" rel="stylesheet" />',
( ! empty( $op['time'] ) && $op['time'] == 'Y'
? 'onload="enableAll( true );"' : '' ) );
echo print_success( $saved );
if( ! empty( $guser ) && $is_admin )
user_load_variables( $guser, 'user_' );
if( $is_admin ) {
$adminStr = translate( 'Admin' );
$userlist = get_my_users();
$nonuserlist = get_nonuser_cals();
// If we are here... we must need to print out a list of users.
echo '
<h2>' . translate( 'User Access Control' )
. ( empty( $user_fullname ) ? '' : ': ' . $user_fullname ) . '</h2>
' . display_admin_link( false ) . '
<form action="access.php" method="post" name="SelectUser">
<select name="guser" onchange="document.SelectUser.submit()">'
// Add a DEFAULT CONFIGURATION to be used as a mask.
. '
<option value="__default__"'
. ( $guser == '__default__' ? $selected : '' )
. '>' . $defConfigStr . '</option>';
for( $i = 0, $cnt = count( $userlist ); $i < $cnt; $i++ ) {
echo '
<option value="' . $userlist[$i]['cal_login'] . '"'
. ( $guser == $userlist[$i]['cal_login'] ? $selected : '' )
. '>' . $userlist[$i]['cal_fullname'] . '</option>';
}
for( $i = 0, $cnt = count( $nonuserlist ); $i < $cnt; $i++ ) {
echo '
<option value="' . $nonuserlist[$i]['cal_login'] . '"'
. ( $guser == $nonuserlist[$i]['cal_login'] ? $selected : '' )
. '>' . $nonuserlist[$i]['cal_fullname'] . ' '
. ( $nonuserlist[$i]['cal_is_public'] == 'Y' ? '*' : '' ) . '</option>';
}
echo $goStr;
} //end admin $guser !- default test
if( ! empty( $guser ) || ! $is_admin ) {
if( $is_admin ) {
// Present a page to allow editing a user's rights.
$access = access_load_user_functions( $guser );
$div = ceil( ACCESS_NUMBER_FUNCTIONS / 4 );
// We can reorder the display of user rights here.
$order = [
1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 27,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26];
// Make sure that we have defined all the types of access
// defined in access.php.
assert( count( $order ) == ACCESS_NUMBER_FUNCTIONS );
echo '
<form action="access.php" method="post" id="accessform" name="accessform">
<input type="hidden" name="auser" value="' . $guser . '" />
<input type="hidden" name="guser" value="' . $guser . '" />
<table>
<tbody>
<tr>
<td>';
for( $i = 0; $i < ACCESS_NUMBER_FUNCTIONS; $i++ ) {
// Public access and NUCs can never use some of these functions.
$show = true;
if( $guser == '__public__'
|| substr( $guser, 0, 5 ) == $NONUSER_PREFIX ) {
switch( $order[$i] ) {
case ACCESS_ACCESS_MANAGEMENT:
case ACCESS_ACCOUNT_INFO:
case ACCESS_ACTIVITY_LOG:
case ACCESS_ADMIN_HOME:
case ACCESS_ASSISTANTS:
case ACCESS_CATEGORY_MANAGEMENT:
case ACCESS_IMPORT:
case ACCESS_PREFERENCES:
case ACCESS_SYSTEM_SETTINGS:
case ACCESS_USER_MANAGEMENT:
case ACCESS_VIEW_MANAGEMENT:
// Skip these...
$show = false;
}
}
if( $show )
echo print_checkbox ( ['access_' . $order[$i], 'Y',
access_get_function_description( $order[$i] ),
substr( $access, $order[$i], 1 )], 'dito' ) . '<br />';
if( ( $i + 1 ) % $div == 0 )
echo '
</td>
<td>';
}
echo '
</td>
</tr>
</tbody>
</table>
<input type="submit" value="' . $undoStr . '" />
<input type="submit" name="submit" value="' . $saveStr . '" />
</form>';
$pagetitle = translate( 'Allow Access to Other Users Calendar' );
} else {
// Get list of users that this user can see (may depend on group settings)
// along with all nonuser calendars.
// if( $guser != '__default__' ) {
$guser = $login;
$pagetitle = translate( 'Grant This User Access to My Calendar' );
}
if( $guser == '__default__' ) {
$userlist = ['__default__'];
$otheruser = $otheruser_login = '__default__';
$otheruser_fullname = $defConfigStr;
} else
if( $allow_view_other ) {
$userlist = get_list_of_users( $guser );
echo '
<h2 style="margin-bottom: 2px;">' . $pagetitle . '</h2>
<form action="access.php" method="post" name="SelectOther">
<input type="hidden" name="guser" value="' . $guser . '" />
<select name="otheruser" onchange="document.SelectOther.submit()">'
// Add a DEFAULT CONFIGURATION to be used as a mask.
. '
<option value="__default__"'
. ( $otheruser == '__default__' ? $selected : '' )
. '>' . $defConfigStr . '</option>';
for( $i = 0, $cnt = count( $userlist ); $i < $cnt; $i++ ) {
if( $userlist[$i]['cal_login'] != $guser )
echo '
<option value="' . $userlist[$i]['cal_login'] . '"'
. ( ! empty( $otheruser ) && $otheruser == $userlist[$i]['cal_login']
? $selected : '' )
. '>' . $userlist[$i]['cal_fullname'] . '</option>';
}
echo $goStr;
}
}
if( ! empty( $otheruser ) ) {
if( $allow_view_other ) {
$typeStr = translate( 'Type' );
echo '
<form action="access.php" method="post" name="EditOther">
<input type="hidden" name="guser" value="' . $guser . '" />
<input type="hidden" name="otheruser" value="' . $otheruser . '" /><br />
<table cellpadding="5">
<tbody>
<tr>
<th class="boxtop boxbottom boxleft" width='
. ( $guser == '__public__'
? '"60%" class="aligncenter">' . translate( 'Calendar' ) . '</th>
<th class="boxtop boxbottom" width="20%">' . $typeStr . '</th>
<th class="boxtop boxright boxbottom" colspan="3" width="20%">'
. translate( 'View Event' )
: '"25%">' . $otheruser_fullname . '</th>
<th class="boxtop boxbottom" width="15%">' . $typeStr . '</th>
<th width="15%" colspan="3" class="boxtop boxbottom">'
. translate( 'View' ) . '</th>
<th width="15%" colspan="3" class="boxtop boxbottom">'
. translate( 'Edit' ) . '</th>
<th width="15%" colspan="3" class="boxtop boxright boxbottom">'
. translate( 'Approve/Reject' ) ) . '</th>
</tr>';
$access_type = [
'',
translate( 'Events' ),
translate( 'Tasks' ),
'',
translate( 'Journals' )];
for( $j = 1; $j < 5; $j++ ) {
$bottomedge = '';
if( $j == 3 )
continue;
echo '
<tr>
<td class="boxleft leftpadded' . ( $j > 3 ? ' boxbottom' : '' )
. '"><input type="checkbox" value="Y" name=';
if( $j == 1 )
echo '"invite"'
. ( ! empty( $op['invite'] ) && $op['invite'] == 'N' ? '' : $checked )
. ' />' . translate( 'Can Invite' );
elseif( $j == 2 )
echo '"email"'
. ( ! empty( $op['email'] ) && $op['email'] == 'N' ? '' : $checked )
. ' />' . translate( 'Can Email' );
else {
echo '"time"'
. ( ! empty( $op['time'] ) && $op['time'] == 'Y' ? $checked : '' )
. ' onclick="enableAll( this.checked );" />'
. translate( 'Can See Time Only' );
$bottomedge = 'boxbottom';
}
echo '</td>
<td class="aligncenter boxleft ' . $bottomedge . '">'
. $access_type[$j] . '</td>
<td class="aligncenter boxleft pub ' . $bottomedge . '">'
. '<input type="checkbox" value="' . $j . '" name="v_' . $j . '"'
. ( ! empty( $op['view'] ) && ( $op['view'] & $j ) ? $checked : '' )
. ' /></td>
<td class="conf ' . $bottomedge . '"><input type="checkbox" value="'
. $j * 8 . '" name="v_' . $j * 8 . '"'
. ( ! empty( $op['view'] ) && ( $op['view'] & ( $j * 8 ) )
? $checked : '' ) . ' /></td>
<td class="priv ' . $bottomedge . '"><input type="checkbox" value="'
. $j * 64 . '" name="v_' . $j * 64 . '"'
. ( ! empty( $op['view'] ) && ( $op['view'] & ( $j * 64 ) )
? $checked : '' ) . ' /></td>'
. ( $guser != '__public__' ? '
<td class="aligncenter boxleft pub ' . $bottomedge . '"><input '
. 'type="checkbox" value="' . $j . '" name="e_' . $j . '"'
. ( ! empty( $op['edit'] ) && ( $op['edit'] & $j ) ? $checked : '' )
. ' /></td>
<td class="conf ' . $bottomedge . '"><input type="checkbox" value="'
. $j * 8 . '" name="e_' . $j * 8 . '"'
. ( ! empty( $op['edit'] ) && ( $op['edit'] & ( $j * 8 ) )
? $checked : '' ) . ' /></td>
<td class="priv ' . $bottomedge . '"><input type="checkbox" value="'
. $j * 64 . '" name="e_' . $j * 64 . '"'
. ( ! empty( $op['edit'] ) && ( $op['edit'] & ( $j * 64 ) )
? $checked : '' ) . ' /></td>
<td class="aligncenter boxleft pub ' . $bottomedge . '"><input '
. 'type="checkbox" value="' . $j . '" name="a_' . $j . '"'
. ( ! empty( $op['approve'] ) && ( $op['approve'] & $j )
? $checked : '' ) . ' /></td>
<td class="conf ' . $bottomedge . '"><input type="checkbox" value="'
. $j * 8 . '" name="a_' . $j * 8 . '"'
. ( ! empty( $op['approve'] ) && ( $op['approve'] & ( $j * 8 ) )
? $checked : '' ) . ' /></td>
<td class="boxright priv ' . $bottomedge
. '"><input type="checkbox" value="' . $j * 64 . '" name="a_' . $j * 64
. '"' . ( ! empty( $op['approve'] ) && ( $op['approve'] & ( $j * 64 ) )
? $checked : '' ) . ' /></td>'
: '' ) . '
</tr>';
}
echo '
<tr>
<td colspan="2" class="boxleft alignright">'
. ( $otheruser != '__default__' && $otheruser != '__public__' ? '
<input type="button" value="' . translate( 'Assistant' )
. '" onclick="selectAll(63);" /> ' : '' ) . '
<input type="button" value="' . translate( 'Select All' )
. '" onclick="selectAll(256);" />
<input type="button" value="' . translate( 'Clear All' )
. '" onclick="selectAll(0);" />
</td>
<td colspan="9" class="boxright">
<table class="aligncenter" cellpadding="5" cellspacing="2">
<tr>
<td class="pub">' . translate( 'Public' ) . '</td>
<td class="conf">' . translate( 'Confidential' ) . '</td>
<td class="priv">' . translate( 'Private' ) . '</td>
</tr>
</table>
</td>
</tr>';
}
echo '
<tr>
<td colspan="11" class="boxleft boxbottom boxright">
<input type="submit" value="' . $undoStr . '" />
<input type="submit" name="submit" value="' . $saveStr . '" />
</td>
</tr>
</tbody>
</table>
</form>';
}
echo print_trailer();
/**
* Get the list of users that the specified user can see.
*/
function get_list_of_users( $user ) {
global $is_admin, $is_nonuser_admin;
$u = get_my_users( $user, 'view' );
if( $is_admin || $is_nonuser_admin ) {
// Get public NUCs also.
$nonusers = get_my_nonusers( $user, true );
$u = array_merge( $nonusers, $u );
}
return $u;
}
?>