forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remotecal_mgmt.php
709 lines (668 loc) · 32.7 KB
/
remotecal_mgmt.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
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
<?php
/**
* Remote Calendar Management.
* NOTE: Very similar to user_mgmt.php with a lot of code copied from there.
*/
require_once 'includes/init.php';
// Verify access to this page is allowed.
if (empty($login) || $login == '__public__') {
// Do not allow public access.
do_redirect(empty($STARTVIEW) ? 'month.php' : $STARTVIEW);
exit;
}
if ($REMOTES_ENABLED != 'Y' || (access_is_enabled() && !access_can_access_function(ACCESS_IMPORT))) {
do_redirect(empty($STARTVIEW) ? 'month.php' : $STARTVIEW);
}
$LOADING = '<center><div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div></center>';
$cannotLoadStr = translate('Your PHP setting for allow_url_fopen will not allow a remote calendar to be loaded.');
$areYouSure = translate('Are you sure you want to delete this remote calendar?');
$deleteUserInfo = translate('This will remove all events for this remote calendar.') .
' ' . translate('This action cannot be undone.');
$noLoginError = translate('Username cannot be blank.');
$noNameError = translate('Name is required');
$invalidIDError = translate('The ID is limited to letters, numbers and underscore only.');
$noUrlError = translate('You have not entered a URL.');
$noTooltip = translate('This remote calendar does not have a layer. Add a layer for this calendar to view it in your calendar.');
$sourceStr = translate('Source');
$colorStr = translate('Color');
$duplicatesStr = translate('Duplicates');
print_header ( [], '', 'onload="load_users();"' );
?>
<h3><?php etranslate('Remote Calendars'); ?></h3>
<?php
// Make sure allow_url_fopen is enabled. Otherwise, the ICS URL cannot be downloaded.
// cannotLoadStr
if (!ini_get('allow_url_fopen')) { ?>
<div id="main-dialog-load-error" class="alert alert-warning">
<span id="loadMessage"><?php echo $cannotLoadStr; ?></span>
<button type="button" class="close" onclick="$('.alert').hide()">×</button>
</div>
<?php } ?>
<!-- Error Alert -->
<div id="main-dialog-alert" class="alert alert-info" style="display: none">
<span id="infoMessage"></span>
<button type="button" class="close" onclick="$('.alert').hide()">×</button>
</div>
<!-- Users loaded via AJAX -->
<table class="table table-striped table-responsive" id="user-table">
<thead>
<tr>
<th scope="col">
<div data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Unique Calendar ID for remote calendar') ?>"><?php etranslate('Calendar ID') ?></div>
</th>
<th scope="col"><?php etranslate('Name') ?></th>
<th scope="col">
<div data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Calendar user who created this remote calendar') ?>"><?php etranslate('Created By') ?></div>
</th>
<?php if (!empty($PUBLIC_ACCESS) && $PUBLIC_ACCESS == 'Y') { ?>
<th scope="col">
<div data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Enabling allows this remote calendar to be used as a public calendar, and a link directly to it will be displayed on the login page.') ?>"><?php etranslate('Public Access') ?></div>
</th>
<?php } ?>
<th scope="col">
<div data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Number of events currently in the remote calendar') ?>"><?php etranslate('Events') ?></div>
</th>
<th scope="col">
<div data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Date the remote calendar was last updated') ?>"><?php etranslate('Last Updated') ?></div>
</th>
<th scope="col">
<div data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Date the remote calendar was last checked for an update. The update may have been skipped if it the remote calendar had not changes since the last update.') ?>"><?php etranslate('Last Checked') ?></div>
</th>
<th scope="col">
<div data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('URL for the ICS file used to import events for this remote calendar') ?>"><?php etranslate('Calendar URL') ?></div>
</th>
<th scope="col">
<!-- dropdown menu -->
</th>
</tr>
<tbody id="user-tbody">
</tbody>
</thead>
</table>
<br>
<div class="userButtons">
<button class="btn btn-primary" type="button" onclick="return edit_user('')">
<?php etranslate ( 'Add Remote Calendar' ); ?>...</button>
</div>
<!-- add/edit user modal dialog -->
<div id="edit-user-dialog" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="edit-user-title" class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="$('#edit-user-dialog').hide();">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- Error Alert -->
<div id="edit-user-dialog-alert" class="alert alert-danger" style="display: none">
<strong><?php etranslate("Error"); ?>!</strong> <span id="errorMessage">A problem has been occurred while submitting your data.</span>
<button type="button" class="close" onclick="$('.alert').hide()">×</button>
</div>
<form class="needs-validation" novalidate name="editUserForm" id="editUserForm">
<?php print_form_key(); ?>
<input type="hidden" name="editUserAdd" id="editUserAdd" value="0">
<div class="form-inline" id="divEditUsername">
<label class="col-5" for="editUsername" data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Unique Calendar ID for remote calendar') ?>"><?php etranslate('Calendar ID') ?>: </label>
<input required type="text" pattern="[A-Za-z0-9_]+" title="<?php etranslate('word characters only'); ?>" class="col-7 form-control" id="editUsername" name="editUsername" placeholder="<?php echo translate('New ID') . ' (' . translate('required') . ')'; ?>">
<div id="invalid-id-error" class="invalid-feedback text-right">
<?php echo $invalidIDError; ?>
</div>
</div>
<div class="form-inline mt-1" id="div-Name">
<label class="col-5 for=" editName"><?php etranslate('Name') ?>: </label>
<input required type="text" class="col-7 form-control" id="editName" name="editName">
<div id="invalid-name-error" class="invalid-feedback text-right">
<?php echo $noNameError; ?>
</div>
</div>
<?php if (!empty($PUBLIC_ACCESS) && $PUBLIC_ACCESS == 'Y') { ?>
<div class="form-inline mt-1" id="div-editPublic">
<label class="col-5 for=" editPublic" data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('Enabling allows this remote calendar to be used as a public calendar, and a link directly to it will be displayed on the login page.') ?>"><?php etranslate('Public Access') ?>: </label>
<?php echo print_radio('editPublic'); ?>
</div>
<?php } ?>
<div class="form-inline mt-1" id="div-editURL">
<label class="col-5 for=" editURL" data-toggle="tooltip" data-placement="bottom" title="<?php etranslate('URL for the ICS file used to import events for this remote calendar') ?>"><?php etranslate('URL') ?>: </label>
<input required type="email" class="col-7 form-control" id="editURL" name="editURL">
<div id="invalid-url-error" class="invalid-feedback text-right">
<?php echo $noUrlError; ?>
</div>
</div>
<div class="modal-footer mt-2">
<button class="btn btn-secondary" data-dismiss="modal"
type="button" onclick="$('#edit-user-dialog').hide();"><?php
etranslate ( 'Cancel' ); ?></button>
<button class="btn btn-primary" data-dismiss="modal"
type="button" onclick="save_handler();"><?php etranslate ( 'Save' ) ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- delete user modal dialog -->
<div id="delete-user-dialog" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="delete-user-title" class="modal-title"><?php etranslate('Delete Remote Calendar'); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="$('#delete-user-dialog').hide();">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="p-3"><?php echo $areYouSure; ?></div>
<div class="p-3 m-3 text-danger"><?php echo $deleteUserInfo; ?></div>
<form name="deleteUserForm" id="deleteUserForm">
<?php print_form_key(); ?>
<div class="form-inline" id="divdeleteUsername">
<label class="col-5" for="deleteUsername"><?php etranslate('Username') ?>: </label>
<input disabled type="text" class="col-7 form-control" id="deleteUsername" name="deleteUsername">
</div>
</form>
<br>
<div class="modal-footer">
<button class="form-control btn btn-secondary"
data-dismiss="modal" type="button" onclick="$('#delete-user-dialog').hide();">
<?php etranslate ( 'Cancel' ); ?></button>
<button class="form-control btn btn-danger" name="delete"
type="submit" onclick="delete_handler ();"><?php
etranslate ( 'Delete' ) ?></button>
</div>
</div>
</div>
</div>
</div>
<div id="edit-layer-dialog" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="edit-layer-title" class="modal-title"><?php etranslate('Add Layer'); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="$('#edit-layer-dialog').hide();">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form name="editLayerForm" id="editLayerForm">
<input type="hidden" name="addLayerRemoteCalendarLogin" id="addLayerRemoteCalendarLogin" value="">
<table>
<tr>
<td style="padding-right: 2em" data-toggle="tooltip" data-placement="top" 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 style="padding-right: 2em" data-toggle="tooltip" data-placement="top" title="<?php etranslate('If checked, events that are duplicates of your events will be shown.'); ?>"><label><?php echo $duplicatesStr; ?>:</label></td>
<td><input class="form-control" type="checkbox" name="editLayerDups" id="editLayerDups">
</td>
</tr>
</table>
<div class="modal-footer">
<button class="form-control btn btn-secondary"
data-dismiss="modal" type="button" onclick="$('#edit-layer-dialog').hide();">
<?php etranslate ( 'Cancel' ); ?></button>
<button class="form-control btn btn-primary"
data-dismiss="modal" type="button" onclick="edit_layer_window_closed();
$('#edit-layer-dialog').hide();"><?php etranslate ( 'Save' ); ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
var myLogin = '<?php echo $login; ?>';
function user_menu(login, showAddLayer) {
// Dropdown menu
ret = '<div class="btn-group dropleft float-right">\n' +
'<button type="button" class="btn btn-sm dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
'<span class="sr-only">Toggle Dropdown</span> </button> <div class="dropdown-menu">\n';
// Edit
ret += "<a class='clickable dropdown-item' onclick=\"return edit_user('" + login +
"');\"><?php etranslate('Edit'); ?>...</a>";
// Reload events
ret += "<a class='clickable dropdown-item' onclick=\"return reload_events('" + login +
"');\"><?php etranslate('Reload'); ?></a>";
if (showAddLayer) {
ret += "<a class='clickable dropdown-item' onclick=\"return add_layer('" + login +
"');\"><?php etranslate('Add Layer'); ?>...</a>";
}
// Delete User
<?php if ($is_admin && $admin_can_delete_user && access_can_access_function(ACCESS_USER_MANAGEMENT)) { ?>
// Cannot delete yourself
if (myLogin != login) {
ret += '<div class="dropdown-divider"></div>';
ret += "<a class='clickable dropdown-item' onclick=\"return delete_user('" + login +
"');\"><?php etranslate('Delete'); ?></a>";
}
<?php } ?>
ret += "</div></div>\n";
return ret;
}
// Remove any PHP warnings/errors at the beginning of our response.
// Example:
// <b>Warning</b>: Cannot modify header information - headers already sent in <b>/var/www/html/includes/ajax.php</b> on line <b>78</b><br>
// {"error":0,"status":"OK","message":"35 events added, 0 events deleted"}
function trim_json(str) {
console.log("Trimming JSON string: " + str);
if (!(typeof str === "string" || str instanceof String)) {
console.log("Cannot clean object with trim_json.")
return str;
}
var ret = "";
var lines = str.split(/\r?\n/);
for (let i = 0; i < lines.length; i++) {
if (lines[i].startsWith('<')) {
// Ignore
console.log("Ignoring HTML in response: " + lines[i]);
} else {
if (ret.length == 0)
ret = lines[i];
else
ret += lines[i];
}
}
return ret;
}
function load_users() {
console.log("In load_users");
users = [];
$('#user-tbody').html('<tr><td colspan="5"><?php echo $LOADING; ?></td></tr>');
$.post('users_ajax.php', {
action: 'remote-cal-list',
csrf_form_key: '<?php echo getFormKey(); ?>'
},
function(data, status) {
var stringified = JSON.stringify(data);
console.log("Data: " + stringified + "\nStatus: " + status);
try {
var response = jQuery.parseJSON(stringified);
} catch (err) {
alert('<?php etranslate('Error'); ?>: <?php etranslate('JSON error'); ?> - ' + err);
return;
}
if (response.error) {
alert('<?php etranslate('Error'); ?>: ' + response.message);
return;
}
console.log('response.users.length=' + response.users.length);
var tbody = '';
for (var i = 0; i < response.users.length; i++) {
var u = response.users[i];
users[i] = {
login: u.login,
lastname: u.lastname,
firstname: u.firstname,
admin: u.admin,
public: u.public,
url: u.url,
fullname: u.fullname,
layercount: u.layercount,
eventcount: u.eventcount,
lastupdated: u.lastupdated,
lastchecked: u.lastchecked
};
var tooltip = u.layercount == 0 ? 'data-toggle="tooltip" data-placement="bottom" title="<?php echo $noTooltip; ?>"' : '';
var warning = u.layercount == 0 ? '<img class="button-icon-inverse" src="images/bootstrap-icons/exclamation-triangle-fill.svg">' : '';
var id = u.login.substring(0, 5) == '<?php echo $NONUSER_PREFIX; ?>' ? u.login.substring(5) : u.login;
tbody += '<tr><td ' + tooltip + '>' + warning + id +
'</td><td>' + (u.fullname == null ? '' : u.fullname) + '</td><td>' + (u.admin == null ? '' : u.admin) +
<?php if (!empty($PUBLIC_ACCESS) && $PUBLIC_ACCESS == 'Y') { ?> '</td><td>' + (u.public == 'Y' ? '<img class="button-icon-inverse" src="images/bootstrap-icons/check-circle.svg">' : '') +
<?php } ?> '</td><td>' + u.eventcount + '</td><td>' + u.lastupdated + '</td><td>' + u.lastchecked + '</td><td>' +
(u.url == null ? '' : u.url) +
'</td><td>' + user_menu(u.login, u.layercount == 0) + '</td></tr>\n';
}
$('#user-tbody').html(tbody);
//console.log('tbody=' + tbody);
// Update tooltips
$('[data-toggle="tooltip"]').tooltip();
},
'json');
}
function reload_events(login) {
console.log("Reloading remote cal, login: " + login);
var error = '';
var message = '';
$.post('users_ajax.php', {
action: "reload-remote-cal",
login: login,
csrf_form_key: '<?php echo getFormKey(); ?>'
},
function(data, status) {
//console.log('Data: ' + data);
if (typeof data === "string" || data instanceof String) {
stringified = data;
} else {
stringified = "" + JSON.stringify(data);
}
//console.log("stringified: " + stringified);
var cleaned = trim_json(stringified);
//console.log('Cleaned Data: ' + cleaned);
console.log("reload_events Data: " + stringified + "\nStatus: " + status);
var response = null;
try {
response = jQuery.parseJSON(cleaned);
console.log('reload_events response=' + response);
console.log('response.error=' + response.error);
console.log('response.status=' + response.status);
console.log('response.message=' + response.message);
} catch (err) {
console.log("JSON Error: " + err);
//alert('<?php etranslate('Error'); ?>: <?php etranslate('JSON error'); ?> - ' + err);
error = err;
return;
}
if (response.error) {
console.log("Response error: " + response.error);
error = response.message;
//alert('<?php etranslate('Error'); ?>: ' + response.message);
return;
}
if (error == '') {
if (response.message)
message = ": " + response.message;
console.log("Message: " + message);
// Reload layers
load_users();
}
})
.done(function() {
if (error.length == 0) {
$('#infoMessage').html('<?php echo translate('Remote Calendar successfully reloaded') ?>' + message);
$('#main-dialog-alert').show();
} else {
alert('<?php etranslate('Error'); ?>: ' + error);
}
})
.fail(function(jqxhr, settings, ex) {
alert('<?php etranslate('Error'); ?>: ' + ex);
});
}
// Minimal URL validation.
function validateURL() {
var elem = $("#editURL").val();
// Replace "webcal://" with "https://"
if (elem.match(/^webcal:\/\//)) {
var upd = 'https://' + elem.substring(9);
$("#editURL").val(upd);
}
elem = $("#editURL").val();
var regex = /^(http|https|ftp):\/\/[^\s]+$/;
if (elem.match(regex))
return true;
else
return false;
}
function validateID() {
var elem = $("#editUsername").val();
console.log("Validate ID: " + elem);
// Replace " " with "_"
if (elem.match(/ /)) {
var newval = elem.replace(/ /g, "_");
$("#editUsername").val(newval);
console.log("Replacing ID: " + newval);
}
elem = $("#editUsername").val();
var regex = /^\w+$/;
if (elem.match(regex))
return true;
else {
console.log("Calendar ID is not valid: " + elem);
return false;
}
}
function edit_user(login) {
console.log('edit_user(' + login + ')');
$('#edit-user-dialog-alert').hide();
$('#invalid-id-error').hide();
$('#invalid-name-error').hide();
$('#invalid-url-error').hide();
// Find correct user in our user list
var user = null;
for (var i = 0; i < users.length; i++) {
if (login == users[i]['login']) {
found = true;
user = users[i];
}
}
if (login == "") {
// Add user
$('#edit-user-title').html('<?php etranslate('Add Remote Calendar'); ?>');
$('#editUserAdd').prop("value", "1");
$('#editUsername').prop("disabled", false);
$('#editUsername').prop("value", "");
$('#editName').prop("value", "");
<?php if (!empty($PUBLIC_ACCESS) && $PUBLIC_ACCESS == 'Y') { ?>
$('#editPublic_N').prop("checked", true);
<?php } ?>
$('#editURL').prop("value", "");
} else {
// Edit user
$('#edit-user-title').html('<?php etranslate('Edit'); ?>');
$('#editUserAdd').prop("value", "0");
$('#editUsername').prop("value", user['login'].substring('<?php echo $NONUSER_PREFIX; ?>'.length));
$('#editUsername').prop("disabled", true);
$('#editName').prop("value", user['fullname']);
<?php if (!empty($PUBLIC_ACCESS) && $PUBLIC_ACCESS == 'Y') { ?>
if (user['public'] == 'Y')
$('#editPublic_Y').prop("checked", true);
else
$('#editPublic_N').prop("checked", true);
<?php } ?>
// We don't edit the admin (manager) of the remote calendar.
$('#editURL').prop("value", user['url']);
}
$('#edit-user-dialog').show();
}
function save_handler() {
var login = '<?php echo $NONUSER_PREFIX; ?>' + $('#editUsername').val();
var lastname = $('#editName').val();
var firstname = '';
<?php if (!empty($PUBLIC_ACCESS) && $PUBLIC_ACCESS == 'Y') { ?>
console.log('editPublic_Y: ' + $('#editPublic_Y').is(':checked'));
var public = $('#editPublic_Y').is(':checked') ? 'Y' : 'N';
<?php } else { ?>
var public = 'N';
<?php } ?>
$('#invalid-id-error').hide();
$('#invalid-name-error').hide();
$('#invalid-url-error').hide();
var add = $('#editUserAdd').val();
if (add == "1") {
if (login.length == 0) {
$('#errorMessage').html('<?php echo $noLoginError; ?>');
$('#edit-user-dialog-alert').show();
return;
}
}
var foundError = false;
// Name required
if ($('#editName').val() == "") {
$('#invalid-name-error').show();
foundError = true;
}
// Validate URL
if (!validateURL()) {
//$('#errorMessage').html('<?php echo $noUrlError; ?>');
$('#invalid-url-error').show();
foundError = true;
}
// Validate ID
if (!validateID()) {
//$('#errorMessage').html('<?php echo $invalidIDError; ?>');
$('#invalid-id-error').show();
foundError = true;
return;
}
// Update login in case validateID modified it.
login = '<?php echo $NONUSER_PREFIX; ?>' + $('#editUsername').val();
var url = $('#editURL').val();
if (url.length == 0) {
//$('#errorMessage').html('<?php echo $noUrlError; ?>');
$('#invalid-url-error').show();
//$('#edit-user-dialog-alert').show();
foundError = true;
}
if (foundError)
return;
console.log("Sending save...\nadd " + add + ", login: " + login + "\nfirstname: " + firstname +
"\nlastname: " + lastname + "\npublic: " + public + "\nurl: " + url);
var error = '';
$.post('users_ajax.php', {
add: add, // "1" or "0"
action: "save-remote-cal",
login: login,
firstname: firstname,
lastname: lastname,
public: public,
url: url,
csrf_form_key: '<?php echo getFormKey(); ?>'
},
function(data, status) {
console.log('Data: ' + data);
var stringified = JSON.stringify(data);
console.log("save_handler Data: " + stringified + "\nStatus: " + status);
try {
var response = jQuery.parseJSON(stringified);
console.log('save_handler response=' + response);
} catch (err) {
//alert('<?php etranslate('Error'); ?>: <?php etranslate('JSON error'); ?> - ' + err);
error = err;
return;
}
if (response.error) {
error = response.message;
//alert('<?php etranslate('Error'); ?>: ' + response.message);
return;
}
if (error == '') {
// Close window
$('#edit-user-dialog').hide();
// Reload layers
load_users();
}
},
'json')
.done(function() {
if (error.length == 0) {
if (add == 1) {
$('#infoMessage').html('<?php echo translate('Remote Calendar successfully added. You must add a new layer to your calendar to view the events from this remote calendar on your calendar.') ?>');
} else {
$('#infoMessage').html('<?php etranslate('Remote Calendar successfully updated.') ?>');
}
$('#main-dialog-alert').show();
} else {
$('#errorMessage').html(error);
$('#edit-user-dialog-alert').show();
}
})
.fail(function(jqxhr, settings, ex) {
$('#errorMessage').html('<?php etranslate('Error'); ?>:' + ex);
$('#edit-user-dialog-alert').show();
});
}
function delete_user(user) {
console.log('delete_user(' + user + ')');
$('#deleteUsername').val(user.substring('<?php echo $NONUSER_PREFIX; ?>'.length));
$('#delete-user-dialog').show();
}
function delete_handler() {
var login = '<?php echo $NONUSER_PREFIX; ?>' + $('#deleteUsername').val();
console.log("Sending delete for username: " + login);
var error = '';
$.post('users_ajax.php', {
action: "delete-remote-cal",
login: login,
csrf_form_key: '<?php echo getFormKey(); ?>'
},
function(data, status) {
console.log('Data: ' + data);
var stringified = JSON.stringify(data);
console.log("delete_handler Data: " + stringified + "\nStatus: " + status);
try {
var response = jQuery.parseJSON(stringified);
console.log('delete_handler response=' + response);
} catch (err) {
console.log('Error: ' + err);
error = '<?php etranslate('JSON error'); ?>' + ' - ' + err;
return;
}
if (response.error) {
console.log('Error: ' + response.message);
error = '<?php etranslate('Error'); ?>' + ' - ' + response.message;
return;
}
})
.done(function() {
if (error.length == 0) {
// Close window
$('#delete-user-dialog').hide();
// Reload layers
load_users();
$('#infoMessage').html('<?php etranslate('Remote calendar successfully deleted.') ?>');
$('#main-dialog-alert').show();
} else {
alert('<?php etranslate('Error'); ?>: ' + error);
}
})
.fail(function(jqxhr, settings, ex) {
alert('<?php etranslate('Error'); ?>:' + ex);
});
}
// Add a new layer
function add_layer(remoteCalLogin) {
console.log('add_layer(' + remoteCalLogin + ')');
// Find correct user in select list
$('#addLayerRemoteCalendarLogin').val(remoteCalLogin);
$('#editLayerColor').prop("value", '#000000'); // default to black
// Also change the background color of the sample.
//$('#editLayerColor_sample').style.background =
// ( id < 0 ? '#000000' : layers[id]['color'] );
$('#editLayerDups').prop("checked", false);
$('#edit-layer-dialog').show();
}
// Handler for save in Add Layer window
function edit_layer_window_closed() {
var layeruser = '<?php echo $login; ?>';
var source = $('#addLayerRemoteCalendarLogin').val();
var color = $('#editLayerColor').val();
var dups = $('#editLayerDups').is(':checked') ? 'Y' : 'N';
var action = 'save';
console.log("Sending save...\nlayeruser: " + layeruser +
"\nsource: " + source + "\ncolor: " + color + "\ndups: " + dups);
$.post('layers_ajax.php', {
action: action,
id: -1,
layeruser: layeruser,
source: source,
color: color,
dups: dups,
csrf_form_key: '<?php echo getFormKey(); ?>'
},
function(data, status) {
var stringified = JSON.stringify(data);
console.log("set_layer_status Data: " + stringified + "\nStatus: " + status);
try {
var response = jQuery.parseJSON(stringified);
console.log('set_layer_status response=' + response);
} catch (err) {
alert('<?php etranslate('Error'); ?>: <?php etranslate('JSON error'); ?> - ' + err);
return;
}
if (response.error) {
alert('<?php etranslate('Error'); ?>: ' + response.message);
return;
}
// Reload users
load_users();
});
}
// Init tooltips
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
<?php echo print_trailer(); ?>