forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layers.php
371 lines (336 loc) · 13 KB
/
layers.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
<?php
/**
* This page handles managing a user's layers
* and works with layer_ajax.php to make changes.
*/
include_once 'includes/init.php';
send_no_cache_header();
$layer_user = $login;
$public = getValue( 'public' );
$u_url = '';
$updating_public = false;
if ( $is_admin && ! empty ( $public ) && $PUBLIC_ACCESS == 'Y' ) {
$layer_user = '__public__';
$u_url = '&public=1';
$updating_public = true;
}
load_user_layers ( $layer_user, 1 );
$layers_enabled = 0;
$res = dbi_execute ( 'SELECT cal_value FROM webcal_user_pref
WHERE cal_setting = "LAYERS_STATUS"
AND cal_login = ?', [$layer_user] );
if ( $res ) {
$row = dbi_fetch_row ( $res );
$layers_enabled = ( $row[0] == 'Y' ? 1 : 0 );
dbi_free_result ( $res );
}
$areYouSureStr = translate( 'Are you sure you want to delete this layer?' );
$colorStr = translate( 'Color' );
$deleteLayerStr = translate( 'Delete layer' );
$deleteStr = translate( 'Delete' );
$disabledStr = translate( 'Disabled' );
$duplicatesStr = translate( 'Duplicates' );
$editLayerStr = translate( 'Edit layer' );
$editStr = translate( 'Edit' );
$enableLayersStr = translate( 'Enable layers' );
$layerStr = translate( 'Layer' );
$LAYERS_DISABLED = translate( 'Layers are currently disabled.' );
$LAYERS_ENABLED = translate( 'Layers are currently enabled.' );
$noStr = translate( 'No' );
$sourceStr = translate( 'Source' );
$yesStr = translate( 'Yes' );
$LOADING = '<center><img src="images/loading_animation.gif" alt="" /></center>';
$public_link = str_replace( 'XXX', $PUBLIC_ACCESS_FULLNAME,
translate( 'Click to modify layers settings for XXX' ) );
// Add ModalBox javascript/CSS & Tab code
$headExtras = '
<script type="text/javascript" src="includes/tabcontent/tabcontent.js"></script>
<link type="text/css" href="includes/tabcontent/tabcontent.css" rel="stylesheet" />
<script type="text/javascript" src="includes/js/modalbox/modalbox.js"></script>
<link rel="stylesheet" href="includes/js/modalbox/modalbox.css" type="text/css"
media="screen" />
';
print_header( array( 'js/translate.js.php', 'js/visible.js/true' ),
$headExtras, 'onload="load_layers();"' );
if ( $ALLOW_VIEW_OTHER != 'Y' )
echo print_not_auth();
else {
if( empty( $PUBLIC_ACCESS ) )
$PUBLIC_ACCESS = 'N';
if( $is_admin && empty( $public ) && $PUBLIC_ACCESS == 'Y' ) {
?>
<div class="rightsidetip">
<a href="layers.php?public=1"><?php echo $public_link;?></a>
</div>
<?php
}
echo '
<h2>' . ( $updating_public
? translate ( $PUBLIC_ACCESS_FULLNAME ) . ' ' : '' )
. translate ( 'Layers' ) . ' <img src="images/help.gif" alt="'
. translate ( 'Help' ) . '" class="help" onclick="window.open( '
. '\'help_layers.php\', \'cal_help\', \'dependent,menubar,scrollbars,'
. 'height=400,width=400,innerHeight=420,outerWidth=420\' );" /></h2>
' . display_admin_link();
?>
<form>
<div class="note">
<span id="layerstatus">
<?php echo $layers_enabled ? $LAYERS_ENABLED : $LAYERS_DISABLED;?>
</span>
<input type="button" onclick="return set_layer_status(true);" value=<?php echo $enableLayersStr;?>" id="enablebutton" <?php echo $layers_enabled ? 'disabled="true"' : '';?> />
<input type="button" onclick="return set_layer_status(false);" value=<?php etranslate("Disable Layers");?>" <?php echo $layers_enabled ? '' : 'disabled="true"';?> id="disablebutton" />
</div>
<br /><br />
<div id="layerlist" style="margin-left: 25px;"> <?php echo $LOADING;?> </div>
<br />
<div class="layerButtons" style="margin-left: 25px;">
<input type="button" value="<?php etranslate('Add layer');?>..."
onclick="return edit_layer(-1)" />
</div>
<br />
<!--
<input type="button" value="Refresh"
onclick="return load_layers()" /> <br />
-->
<?php
}
// Create list of users for edit layer dialog.
$userlist = [];
if ( $single_user == 'N' ) {
$otherlist = $userlist = get_my_users ( '', 'view' );
if ( $NONUSER_ENABLED == 'Y' ) {
// Restrict NUC list if groups are enabled.
$nonusers = get_my_nonusers ( $login, true, 'view' );
$userlist = ( $NONUSER_AT_TOP == 'Y'
? array_merge ( $nonusers, $userlist )
: array_merge ( $userlist, $nonusers ) );
}
if ( $REMOTES_ENABLED == 'Y' ) {
$remotes = get_nonuser_cals ( $login, true );
$userlist = ( $NONUSER_AT_TOP == 'Y'
? array_merge ( $remotes, $userlist )
: array_merge ( $userlist, $remotes ) );
}
$num_users = $osize = $size = 0;
$others = $users = '';
for ( $i = 0, $cnt = count ( $userlist ); $i < $cnt; $i++ ) {
if ( $userlist[$i]['cal_login'] != $layer_user ) {
$users .= '<option value="' . $userlist[$i]['cal_login'] . '"' .
'>' . $userlist[$i]['cal_fullname'] . '</option>';
}
}
for ( $i = 0, $cnt = count ( $otherlist ); $i < $cnt; $i++ ) {
if ( $otherlist[$i]['cal_login'] != $layer_user ) {
$osize++;
$others .= '<option value="' . $otherlist[$i]['cal_login'] . '">'
. $otherlist[$i]['cal_fullname'] . '</option>';
}
}
// TODO: handle $otherlist like 1.2 code
}
?>
</form>
<div id="editLayerDiv" style="display: none;">
<div style="background-color: <?php echo $BGCOLOR;?>; color: <?php echo $TEXTCOLOR;?>; padding: 10px;">
<form name="editLayerForm" id="editLayerForm">
<input type="hidden" name="editLayerId" id="editLayerId" value="" />
<input type="hidden" name="editLayerDelete" id="editLayerDelete" value="0" />
<table>
<tr><td class="tooltip" title="<?php etranslate('Specifies the user that you would like to see displayed in your calendar.');?>"><label><?php echo $sourceStr;?>:</label></td>
<td><select id="editLayerSource" name="editLayerSource">
<?php echo $users;?>
</td></tr>
<tr><td class="tooltip" title="<?php etranslate('The text color of the new layer that will be displayed in your calendar.');?>"><label><?php echo $colorStr;?>:</label></td>
<td><?php echo print_color_input_html ( 'editLayerColor', '',
'#000000' );?>
</td></tr>
<tr><td class="tooltip" title="<?php etranslate('If checked, events that are duplicates of your events will be shown.');?>"><label><?php echo $duplicatesStr;?>:</label></td>
<td><input type="checkbox" name="editLayerDups" id="editLayerDups" />
</td></tr>
</table>
<br />
<center>
<input id="editLayerDeleteButton" type="button" value="<?php etranslate("Delete");?>"
onclick="if ( confirm ( '<?php echo $areYouSureStr;?>' ) ) {
$('editLayerDelete').setAttribute ( 'value', '1' );
edit_window_closed (); Modalbox.hide ();
}" />
<input type="button" value="<?php etranslate("Save");?>"
onclick="edit_window_closed(); Modalbox.hide() " /></center>
</form>
</div>
</div>
<script type="text/javascript">
var layers = [];
// Set the LAYER_STATUS value in webcal_user_pref for either the current
// user or the public user ('__public__') with an AJAX call to
// layers_ajax.php.
function set_layer_status (enable)
{
var status = ( enable ? 'enable' : 'disable' );
new Ajax.Request('layers_ajax.php',
{
method:'post',
parameters: { action: status<?php
if ( $updating_public ) { echo ", public: 1"; }
?> },
onSuccess: function( transport ) {
var response = transport.responseText || "no response text";
try {
response = transport.responseText.evalJSON();
} catch ( err ) {
alert ( '<?php etranslate('Error');?>: <?php etranslate('JSON error');?> - ' + err + "\n\n" + transport.responseText );
return;
}
if ( response.error ) {
alert ( '<?php etranslate("Error");?>:\n\n' + response.message );
} else {
//alert("Success! \n\n" + response);
if ( enable ) {
$('layerstatus').innerHTML = '<?php echo $LAYERS_ENABLED;?>';
$('enablebutton').setAttribute ( 'disabled', 'true' );
$('disablebutton').removeAttribute ( 'disabled' );
alert('<?php echo strip_tags ( $LAYERS_ENABLED );?>');
} else {
$('layerstatus').innerHTML = '<?php echo $LAYERS_DISABLED;?>';
$('disablebutton').setAttribute ( 'disabled', 'true' );
$('enablebutton').removeAttribute ( 'disabled' );
alert('<?php echo strip_tags ( $LAYERS_DISABLED );?>');
}
}
},
onFailure: function() { alert( '<?php etranslate( 'Error' );?>' ) }
});
return true;
}
function load_layers()
{
layers = [];
$('layerlist').innerHTML = '<?php echo $LOADING;?>';
new Ajax.Request('layers_ajax.php',
{
method:'post',
parameters: { action: 'list'<?php
if ( $updating_public ) { echo ", public: 1"; }
?> },
onSuccess: function( transport ) {
if ( ! transport.responseText ) {
alert ( '<?php etranslate('Error');?>: <?php etranslate('no response from server');?>' );
return;
}
//alert ( "Response:\n" + transport.responseText );
try {
response = transport.responseText.evalJSON();
} catch ( err ) {
alert ( '<?php etranslate('Error');?>: <?php etranslate('JSON error');?> - ' + err + "\n\n" + transport.responseText );
return;
}
if ( response.error ) {
alert ( '<?php etranslate('Error');?>: ' + response.message );
return;
}
var x = '<table id="layertable" border="1"><th><?php echo $sourceStr;?></th><th><?php echo $colorStr;?></th><th><?php echo $duplicatesStr;?></th></tr>\n';
for ( var i = 0; i < response.layers.length; i++ ) {
var cl = ( i % 2 == 0 ) ? 'even' : 'odd';
var l = response.layers[i];
layers[l.id] = { id: l.id, source: l.source, color: l.color,
dups: l.dups, fullname: l.fullname };
x += '<tr onclick="return edit_layer(' + l.id + ')">' +
'<td class="' + cl + '">' + l.fullname + '</td><td class="' +
cl + '">' + l.color +
'<span class="colorsample" style="background-color: ' + l.color +
'"> </span></td><td class="' + cl + '">' +
( l.dups == 'Y' ? '<?php echo $yesStr;?>' : '<?php echo $noStr;?>' ) +
'</td></tr>\n';
}
x += '</table>\n';
$('layerlist').innerHTML = x;
},
onFailure: function() { alert( '<?php etranslate( 'Error' );?>' ) }
});
return true;
}
function edit_window_closed () {
var layeruser = '<?php echo $layer_user;?>';
var o = $('editLayerSource');
var source = o.options[o.selectedIndex].value;
var color = $('editLayerColor').value;
var dups = $('editLayerDups').checked ? 'Y' : 'N';
var del = $('editLayerDelete').value;
var id = $('editLayerId').value;
var action = ( del > 0 ) ? 'delete' : 'save';
//alert ( "Sending save...\nid: " + id + "\nlayeruser: " + layeruser +
// "\nsource: " + source + "\ncolor: " + color + "\ndups: " + dups +
// "\ndelete: " + del );
new Ajax.Request('layers_ajax.php',
{
method:'post',
parameters: { action: action, id: id, layeruser: layeruser,
source: source, color: color, dups: dups },
onSuccess: function( transport ) {
var response = transport.responseText || "no response text";
try {
response = transport.responseText.evalJSON();
} catch ( err ) {
alert ( '<?php etranslate('Error');?>: <?php etranslate('JSON error');?> - ' + err + "\n\n" + response );
return;
}
if ( response.error ) {
alert ( '<?php etranslate("Error");?>:\n\n' + response.message );
} else {
//alert("Success! \n\n" + response);
// Reload layers
load_layers();
}
},
onFailure: function() { alert( '<?php etranslate( 'Error' );?>' ) }
});
return true;
}
function edit_layer (id)
{
var titleStr = '';
if ( id < 0 )
titleStr = '<?php etranslate('Add Layer');?>';
else
titleStr = '<?php etranslate('Edit Layer');?>';
// While I like the visual effects that you get with transitions enabled,
// it causes some of the javascript (setting selectedIndex) to fail for
// some reason. So, it is disabled here.
Modalbox.show($('editLayerDiv'), {title: titleStr, width: 375, transitions: false, closeString: '<?php etranslate('Cancel');?>' });
if ( id < 0 ) {
$('editLayerDeleteButton').setAttribute ( 'disabled', 'true' );
} else {
$('editLayerDeleteButton').removeAttribute ( 'disabled' );
}
$('editLayerDelete').setAttribute ( "value", 0 );
// Find correct user in select list
var o = $('editLayerSource');
var found = false;
if ( id > 0 ) {
var n = layers[id]['source'];
for ( var i = 0; i < o.options.length; i++ ) {
if ( o.options[i].value == n ) {
o.selectedIndex = i;
}
}
}
$('editLayerId').setAttribute ( "value", id );
$('editLayerColor').setAttribute ( "value", id < 0 ? '#000000' : layers[id]['color'] );
// Also change the background color of the sample.
$('editLayerColor_sample').style.background =
( id < 0 ? '#000000' : layers[id]['color'] );
if ( id < 0 )
$('editLayerDups').removeAttribute ( "checked" );
else if ( layers[id]['dups'] == 'Y' )
$('editLayerDups').setAttribute ( "checked", "checked" );
else
$('editLayerDups').removeAttribute ( "checked" );
}
</script>
<?php
echo print_trailer();
?>