forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombo.php
More file actions
1987 lines (1841 loc) · 66 KB
/
Copy pathcombo.php
File metadata and controls
1987 lines (1841 loc) · 66 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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This page handles displaying the Day/Week/Month/Year views in a single
* page with tabs. Content is loaded dynamically with AJAX.
* So, requests for previous & next will not force a page reload.
*
* TODO:
* - Week view
* - Task view
* - Print layout
* - Delete event (?)
* - Honor access_can_access_function ( ACCESS_WEEK/ACCESS_MONTH/ACCESS_DAY )
*
* Possibilities for later:
* - Include tab for unapproved events where users could approve from
* this page.
*
* Note: some of the icons for this page were downloaded from the following
* page. If you want to add more icons, check there first.
* http://rrze-icon-set.berlios.de/gallery.html
* License info (Creative Commons 3.0)
* http://rrze-icon-set.berlios.de/licence.html
*/
include_once 'includes/init.php';
// Load Doc classes for attachments and comments
include 'includes/classes/Doc.class';
include 'includes/classes/DocList.class';
include 'includes/classes/AttachmentList.class';
include 'includes/classes/CommentList.class';
//send_no_cache_header();
$LOADING = '<div style="height: 220px; padding-top: 190px;"><center><img src="images/loading_animation.gif" alt="" /></center></div>';
$SMALL_LOADING = '<img src="images/loading_animation_small.gif" alt="..." width="16" height="16" />';
if ( $CATEGORIES_ENABLED == 'Y' )
load_user_categories();
$date = getIntValue ( 'date' );
if ( empty ( $date ) )
$date = date ( 'Ymd' );
$thisyear = substr ( $date, 0, 4 );
$thismonth = substr ( $date, 4, 2 );
$thisday = substr ( $date, 6, 2 );
$next = mktime ( 0, 0, 0, $thismonth + 1, 1, $thisyear );
$nextYmd = date ( 'Ymd', $next );
$nextyear = substr ( $nextYmd, 0, 4 );
$nextmonth = substr ( $nextYmd, 4, 2 );
$prev = mktime ( 0, 0, 0, $thismonth - 1, 1, $thisyear );
$prevYmd = date ( 'Ymd', $prev );
$prevyear = substr ( $prevYmd, 0, 4 );
$prevmonth = substr ( $prevYmd, 4, 2 );
$user = getValue ( 'user', '[A-Za-z0-9_\.=@,\-]*', true );
if ( ! empty ( $user ) ) {
// Make sure this user has permission to view the other user's calendar
if ( ! access_user_calendar( 'view', $user ) ) {
// Not allowed.
$user = $login;
}
}
// Can the user see event participants?
$show_participants = ( $DISABLE_PARTICIPANTS_FIELD != 'Y' );
if ( $is_admin )
$show_participants = true;
if ( $PUBLIC_ACCESS == 'Y' && $login == '__public__' &&
( $PUBLIC_ACCESS_OTHERS != 'Y' || $PUBLIC_ACCESS_VIEW_PART == 'N' ) )
$show_participants = false;
// Get width/height settings for modal dialog used to view event.
$view_width = empty ( $VIEW_EVENT_DIALOG_WIDTH ) ? "350" :
$VIEW_EVENT_DIALOG_WIDTH;
$view_height = empty ( $VIEW_EVENT_DIALOG_HEIGHT ) ? "300" :
$VIEW_EVENT_DIALOG_HEIGHT;
// Get width/height settings for modal dialog used for "quick add"
$quick_add_width = empty ( $QUICK_ADD_DIALOG_WIDTH ) ? "550" :
$QUICK_ADD_DIALOG_WIDTH;
$quick_add_height = empty ( $QUICK_ADD_DIALOG_HEIGHT ) ? "200" :
$QUICK_ADD_DIALOG_HEIGHT;
$can_add = true;
if ( $readonly == 'Y' )
$can_add = false;
else if ( access_is_enabled() )
$can_add = access_can_access_function ( ACCESS_EVENT_EDIT );
else {
if ( $login == '__public__' )
$can_add = ( $GLOBALS['PUBLIC_ACCESS_CAN_ADD'] == 'Y' );
else if ( $is_nonuser )
$can_add = false;
}
$bodyExtras = 'onload="onLoadInit()"';
// Add ModalBox javascript/CSS & Tab code, Auto-complete
$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" />
<script type="text/javascript" src="includes/js/autocomplete.js"></script>
';
print_header(
array( 'js/popups.js/true', 'js/visible.php', 'js/datesel.php' ),
$headExtras, $bodyExtras );
?>
<div class="headerinfo">
<table>
<tr>
<?php
if ( $single_user == 'N' ) {
user_load_variables ( ! empty ( $user ) ? $user : $login, 'user_' );
echo "<td class=\"aligntop username\"><nobr>" .
htmlspecialchars ( $user_fullname ) . "</nobr></td>";
}
if ( $CATEGORIES_ENABLED == 'Y' ) {
?>
<td class="aligntop" id="categoryselection">Categories:</td>
<td class="aligntop" onmouseover="setCategoryVisibility(true)" onmouseout="setCategoryVisibility(false)">
<img id="catexpand" src="images/expand.gif" />
<span id="selectedcategories">All</span><br />
<div id="categorylist" style="display:none">
<?php
foreach ( $categories as $catId => $val ) {
$name = "cat-" . $catId;
if ( $catId > 0 ) {
?>
<nobr><input type="checkbox" id="<?php echo $name;?>" name="<?php echo $name;?>"
onclick="handleCategoryCheckboxChange()" value="Y" /><label for="<?php echo $name;?>">
<?php echo htmlspecialchars ( $categories[$catId]['cat_name'] ) ?>
</label></nobr>
<?php
//$catIconFile = 'icons/cat-' . $catId . '.gif';
//if ( file_exists ( $catIconFile ) )
}
}
?>
<br /><input style="font-size: 80%" type="button" value="<?php etranslate("Select All");?>" onclick="selectAllCategories()" />
<input style="font-size: 80%" type="button" value="<?php etranslate("Select None");?>" onclick="selectNoCategories()" />
<?php
?>
</div>
<?php
}
?>
</tr></table>
</div>
<ul id="viewtabs" class="shadetabs" style="margin-left: 10px;">
<li><a href="#" rel="contentDay" class="selected"><?php etranslate('Day');?></a></li>
<li><a href="#" rel="contentWeek"><?php etranslate('Week');?></a></li>
<li><a href="#" rel="contentMonth"><?php etranslate('Month')?></a></li>
<li><a href="#" rel="contentYear"><?php etranslate('Year')?></a></li>
<li><a href="#" rel="contentAgenda"><?php etranslate("Agenda");?></a></li>
<li><a href="#" rel="contentTasks"><?php etranslate('Tasks');?></a></li>
</ul>
<div style="border:1px solid gray; width:95%; margin-bottom: 1em; margin-left: 10px; margin-right: 10px; padding: 10px">
<div id="contentDay" class="tabcontent">
Day content goes here...
</div>
<div id="contentWeek" class="tabcontent">
Week content goes here...
</div>
<div id="contentMonth" class="tabcontent">
Month content goes here...
</div>
<div id="contentYear" class="tabcontent">
Year content goes here...
</div>
<div id="contentAgenda" class="tabcontent">
Agenda content goes here...
</div>
<div id="contentTasks" class="tabcontent">
<table id="tasktable">
</table>
<br/>
<span id="addtask" class="clickable fakebutton"
onclick="taskAddPopup()"/><?php etranslate('Add Task');?></span>
</div>
</div>
<div id="viewEventDiv" style="display: none;">
<table>
<tr><td colspan="2"><h3 id="name" class="eventName"> </h3></td></tr>
<tr><td class="aligntop bold"><?php etranslate("Description")?>:</td>
<td id="description"> </td></tr>
<tr><td class="aligntop bold"><?php etranslate("Date")?>:</td>
<td id="date"> </td></tr>
<tr><td class="aligntop bold"><?php etranslate("Time")?>:</td>
<td id="time"> </td></tr>
<?php if ( $DISABLE_PRIORITY_FIELD != 'Y' ) { ?>
<tr><td class="aligntop bold"><?php etranslate("Priority")?>:</td>
<td id="priority"> </td></tr>
<?php } ?>
<tr><td class="aligntop bold"><?php etranslate("Access")?>:</td>
<td id="access"> </td></tr>
<?php if ( $single_user == 'N' ) { ?>
<tr><td class="aligntop bold"><?php etranslate("Created by")?>:</td>
<td id="createdby"> </td></tr>
<?php } ?>
<tr><td class="aligntop bold"><?php etranslate("Updated")?>:</td>
<td id="updated"> </td></tr>
<?php if ( $show_participants ) { ?>
<tr><td class="aligntop bold"><?php etranslate("Participants")?>:</td>
<td id="participants"> </td></tr>
<?php } ?>
<?php if ( Doc::attachmentsEnabled() ) { ?>
<tr><td class="aligntop bold"><?php etranslate("Attachments")?>:</td>
<td id="attachments"> </td></tr>
<?php } ?>
<?php if ( Doc::commentsEnabled() ) { ?>
<tr><td class="aligntop bold"><?php etranslate("Comments")?>:</td>
<td id="comments"> </td></tr>
<?php } ?>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2" id="eventlink" class="aligncenter"> </td></tr>
</table>
</div>
<!-- Hidden div tag for Quick Add dialog -->
<div id="quickAddDiv" style="display: none;">
<input type="hidden" name="quickAddParticipants" id="quickAddParticipants" value="" />
<table>
<tr><td class="aligntop bold"><?php etranslate('Date');?>:</td>
<td><?php echo datesel_Print ( 'quickAddDate', $date );?>
</td></tr>
<tr><td class="aligntop bold"><?php etranslate('Brief Description');?>:</td>
<td><input id="quickAddName" name="quickAddName" onfocus="this.select();" /></td></tr>
<tr><td class="aligntop bold"><?php etranslate('Full Description');?>:</td>
<td><textarea id="quickAddDescription" name="quickAddDescription"
rows="4" cols="40" wrap="virtual"></textarea></td></tr>
<?php if ( $CATEGORIES_ENABLED == 'Y' ) { ?>
<tr><td class="aligntop bold"><?php etranslate('Category');?>:</td>
<td><select id="quickAddCategory" name="quickAddCategory">
<option value="-1"><?php etranslate('None');?></option>
<?php
foreach ( $categories as $K => $V ) {
if ( $K > 1 ) {
echo '<option value="' . $K . '">' .
htmlspecialchars ( $categories[$K]['cat_name'] ) . "</option>\n";
}
}
?>
</select></td></tr>
<?php } ?>
<tr><td class="aligntop bold"><?php etranslate('Participants');?>:</td>
<td><span id="quickAddParticipantList"></span>
<input type="text" id="quickAddNewParticipant" name="quickAddNewParticipant" size="20" /></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2"><input type="button" value="<?php etranslate('Save');?>" onclick="eventAddHandler()" /><br />
<span class="clickable" onclick="addEventDetail()"><?php etranslate("Add event detail");?></span>
</td></tr>
</table>
</div>
<!-- Hidden div tag for Add Task dialog -->
<div id="taskAddDiv" style="display: none;">
<form name="taskAddForm" id="taskAddForm">
<table>
<tr><td class="aligntop bold"><?php etranslate('Start Date');?>:</td>
<td><?php echo datesel_Print ( 'task_start_date', $date );?></td></tr>
<tr><td class="aligntop bold"><?php etranslate('Due Date');?>:</td>
<td><?php echo datesel_Print('task_due_date', $date); ?></td></tr>
<tr><td class="aligntop bold"><?php etranslate('Brief Description');?>:</td>
<td><input id="taskAddName" name="taskAddName" /></td></tr>
<tr><td class="aligntop bold"><?php etranslate('Full Description');?>:</td>
<td><textarea id="taskAddDescription" name="taskAddDescription"
rows="4" cols="40" wrap="virtual"></textarea></td></tr>
<?php if ( $CATEGORIES_ENABLED == 'Y' ) { ?>
<tr><td class="aligntop bold"><?php etranslate('Category');?>:</td>
<td><select id="taskAddCategory" name="taskAddCategory">
<option value="-1"><?php etranslate('None');?></option>
<?php
foreach ( $categories as $K => $V ) {
if ( $K > 1 ) {
echo '<option value="' . $K . '">' .
htmlspecialchars ( $categories[$K]['cat_name'] ) . "</option>\n";
}
}
?>
</select></td></tr>
<?php } ?>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2"><input type="button" value="<?php etranslate('Save');?>" onclick="taskAddHandler()" /><br />
<span class="clickable" onclick="taskAddDetail()"><?php etranslate("Add task detail");?></span>
</td></tr>
</table>
</form>
</div>
<script type="text/javascript">
// Called when page is loaded.
// Load events for the current month.
// Load all tasks.
function onLoadInit ()
{
ajax_get_events('<?php echo $thisyear;?>','<?php echo intval($thismonth);?>',
'<?php echo intval($thisday);?>');
ajax_get_tasks();
}
// Initialize tabs
var views=new ddtabcontent("viewtabs")
views.setpersist(true)
views.setselectedClassTarget("link") //"link" or "linkparent"
views.init()
// End init tabs
var login = '<?php echo $login;?>';
var user = '<?php echo $user;?>';
var currentYear = null, currentMonth = null, currentDay = null;
var switchingToDayView = false;
// Sort mode for task table
var SORT_BY_NAME = 0, SORT_BY_DUE_DATE = 1, SORT_BY_PRIORITY = 2,
SORT_BY_CATEGORY = 3;
var taskSortAsc = true;
var taskSortCol = SORT_BY_DUE_DATE;
var dateYmd = '';
<?php if ( $CATEGORIES_ENABLED == 'Y' ) { ?>
var allCatsSelected = true;
var selectedCats = [];
var categories = [];
<?php
// Create a javascript array of all categories this user can see that
// includes category name, owner, colors, global status, icon.
foreach ( $categories as $catId => $val ) {
if ( $catId > 0 ) {
echo 'categories[' . $catId . '] = ' .
'{ id : ' . $catId .
', state: 1' .
', owner: "' . $categories[$catId]['cat_owner'] . '"' .
', name: "' . $categories[$catId]['cat_name'] . '"' .
', color: "' . $categories[$catId]['cat_color'] . '"' .
', global: ' . ( $categories[$catId]['cat_global'] ? '0' : '1' );
$gifIconFile = 'icons/cat-' . $catId . '.gif';
$pngIconFile = 'icons/cat-' . $catId . '.png';
$jpgIconFile = 'icons/cat-' . $catId . '.jpg';
if ( file_exists ( $gifIconFile ) ) {
echo ', icon: "' . $gifIconFile . '"';
} else if ( file_exists ( $pngIconFile ) ) {
echo ', icon: "' . $pngIconFile . '"';
} else if ( file_exists ( $jpgIconFile ) ) {
echo ', icon: "' . $jpgIconFile . '"';
}
echo " };\n";
}
}
?>
<?php } ?>
var viewDialogIsVisible = false;
var quickAddDialogIsVisible = null;
var catsVisible = false;
var events = tasks = [];
// loadedMonths is used to keep track of which months we have loaded events
// for. This prevents us from re-loading a month's events that we
// previously loaded.
var loadedMonths = []; // Key will be format "200801" For Jan 2008
// loadedTasks set to true when tasks have been loaded. We don't load tasks
// based on date, so it is a single scalar variable rather than an array.
var loadedTasks = false;
var months = [
<?php
// Create javascript array of month names localized to the user's
// language preference.
for ( $i = 0; $i < 12; $i++ ) {
if ( $i ) echo ", ";
echo "'" . month_name ( $i ) . "'";
}
?>
];
var shortMonths = [
<?php
// Create javascript array of shortened month names localized to the user's
// language preference.
for ( $i = 0; $i < 12; $i++ ) {
if ( $i ) echo ", ";
echo "'" . month_name ( $i, 'M' ) . "'";
}
?>
];
var weekdays = [
<?php
// Create javascript array of weekday names localized to the user's
// language preference.
for ( $i = 0; $i < 7; $i++ ) {
if ( $i ) echo ", ";
echo "'" . weekday_name ( $i, 'l' ) . "'";
}
?>
];
var shortWeekdays = [
<?php
// Create javascript array of shortened weekday names localized to the
// user's language preference.
for ( $i = 0; $i < 7; $i++ ) {
if ( $i ) echo ", ";
echo "'" . weekday_name ( $i, 'D' ) . "'";
}
?>
];
var daysPerMonth = [ <?php echo implode ( ", ", $days_per_month ); ?> ];
var leapDaysPerMonth = [ <?php echo implode ( ", ", $ldays_per_month ); ?> ];
var userLogins = [];
var userNames = [];
var users = [];
<?php
// Create a javascript array of all users this user has access to see.
// Note: not using this yet in the javascript anywhere....
$users = user_get_users();
for ( $i = 0; $i < count ( $users ); $i++ ) {
$fname = $users[$i]['cal_fullname'];
if ( empty ( $fname ) )
$fname = $users[$i]['cal_login'];
$fname = str_replace ( "'", "", $fname );
echo 'userLogins[' . $i . '] = \'' . $users[$i]['cal_login'] . "';\n";
echo 'userNames[' . $i . '] = \'' . $fname . "';\n";
echo 'users["' . $users[$i]['cal_login'] . '"] = \'' . $fname . "';\n";
}
?>
// Callback for autocomplete on usernames. We return an object
// that includes matching user logins and names.
function autocompleteUserSearch ( q )
{
var suggestions = [];
var data = [];
var cnt = 0;
var words = q.toLowerCase().split ( ' ' );
for ( var i = 0; i < userLogins.length; i++ ) {
var match = 0;
for ( var j = 0; j < words.length && ! match; j++ ) {
var q1 = words[j];
if ( q1.length == 0 ) {
// ignore
} else if ( userLogins[i].toLowerCase().indexOf ( q1 ) >= 0 ) {
match = 1;
} else if ( userNames[i].toLowerCase().indexOf ( q1 ) >= 0 ) {
match = 1;
}
}
if ( match ) {
suggestions[cnt] = userNames[i];
data[cnt] = userLogins[i];
cnt++;
}
}
var resp = { suggestions: suggestions, data: data };
//alert('resp.suggestions=' + resp.suggestions + ", cnt=" + cnt );
return resp;
}
<?php if ( $CATEGORIES_ENABLED == 'Y' ) { ?>
function setCategoryVisibility (newIsVisible)
{
if ( newIsVisible ) {
$('categorylist').style.display = "block";
$('catexpand').src = "images/collapse.gif";
catsVisible = true;
} else {
$('categorylist').style.display = "none";
$('catexpand').src = "images/expand.gif";
catsVisible = false;
}
}
function selectAllCategories()
{
<?php
foreach ( $categories as $catId => $val ) {
if ( $catId > 0 ) {
$checkboxName = "cat-" . $catId;
echo " $('" . $checkboxName . "').checked = true;\n";
}
}
?>
handleCategoryCheckboxChange();
}
function selectNoCategories()
{
<?php
foreach ( $categories as $catId => $val ) {
if ( $catId > 0 ) {
$checkboxName = "cat-" . $catId;
echo " $('" . $checkboxName . "').checked = false;\n";
}
}
?>
handleCategoryCheckboxChange();
}
function handleCategoryCheckboxChange()
{
var newText = '';
var cnt = 0, cntOff = 0;
var all = false;
selectedCats = [];
<?php
foreach ( $categories as $catId => $val ) {
if ( $catId > 0 ) {
$checkboxName = "cat-" . $catId;
$varName = "cat" . $catId;
echo " var $varName = document.getElementById('$checkboxName');\n";
echo " if ( " . $varName . ' && ' . $varName . '.checked ) {' . "\n";
echo ' selectedCats[cnt] = ' . $catId . ';' . "\n";
echo " if ( cnt++ > 0 ) newText += ', ';\n";
echo " newText += \"" . $categories[$catId]['cat_name'] . "\";\n";
echo ' categories[' . $catId . '].state = 1;' . "\n";
echo ' } else { ' . "\n";
echo ' cntOff++;' . "\n";
echo ' categories[' . $catId . '].state = 0;' . "\n";
echo ' }' . "\n";
}
}
?>
if ( cnt == 0 || cntOff == 0 ) {
newText = '<?php etranslate('All');?>';
for ( var catId in categories ) {
categories[catId].state = 1;
}
allCatsSelected = true;
} else {
allCatsSelected = false;
}
$('selectedcategories').innerHTML = newText;
// Update display
update_display ( currentYear, currentMonth, currentDay );
}
<?php } ?>
// Load events for the specified month AND update ALL the event tabs
// (year, month, day, agenda). We pass in the day so we know
// which day of the month to put in the day view.
// NOTE: This does not affect the "Tasks" tab.
function ajax_get_events ( year, month, day )
{
var startdate = "" + year + ( month < 10 ? "0" : "" ) + month + "01";
// First, check to see if we already have loaded the content for
// the specified month.
var monthKey = "" + year + ( month < 10 ? "0" : "" ) + month;
if ( loadedMonths[monthKey] > 0 ) {
//alert ( "Already loaded " + monthKey );
update_display ( year, month, day );
return;
}
//alert ( "Loading startdate=" + startdate );
$('contentDay').innerHTML = '<?php echo $LOADING;?>';
$('contentWeek').innerHTML = '<?php echo $LOADING;?>';
$('contentMonth').innerHTML = '<?php echo $LOADING;?>';
$('contentYear').innerHTML = '<?php echo $LOADING;?>';
$('contentAgenda').innerHTML = '<?php echo $LOADING;?>';
new Ajax.Request('events_ajax.php',
{
method:'get',
parameters: { action: 'get', startdate: startdate, user: user },
onSuccess: function( transport ) {
if ( ! transport.responseText ) {
alert ( '<?php etranslate('Error');?>: <?php etranslate('no response from server');?>' + ': events_ajax.php?action=get' );
return;
}
//alert ( "Response:\n" + transport.responseText );
try {
var response = transport.responseText.evalJSON();
// Hmmm... The Prototype JSON above doesn't seem to work!
//var response = eval('(' + transport.responseText + ')');
} 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;
}
for ( var key in response.dates ) {
events[key] = response.dates[key];
}
loadedMonths[monthKey] = 1;
update_display ( year, month, day );
},
onFailure: function() { alert( '<?php etranslate( 'Error' );?>' ) }
});
switchingToDayView = false;
return true;
}
// Load all tasks and update the "Tasks" tab accordingly.
// Note: this does not affect the event tabs (year, month, day, agenda).
function ajax_get_tasks ()
{
if ( loadedTasks ) {
//alert ( "Already loaded " + monthKey );
update_task_display ();
return;
}
//$('contentTasks').innerHTML = '<?php echo $LOADING;?>';
new Ajax.Request('events_ajax.php',
{
method:'get',
parameters: { action: 'gett', user: user },
onSuccess: function( transport ) {
if ( ! transport.responseText ) {
alert ( '<?php etranslate('Error');?>: <?php etranslate('no response from server');?>' + ': events_ajax.php?action=gett' );
return;
}
//alert ( "Get Tasks Response:\n" + transport.responseText );
try {
var response = transport.responseText.evalJSON();
// Hmmm... The Prototype JSON above doesn't seem to work!
//var response = eval('(' + transport.responseText + ')');
} 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;
}
tasks = [];
var i = 0;
for ( var i = 0; i < response.tasks.length; i++ ) {
tasks[i] = response.tasks[i];
}
loadedTasks = true;
update_task_display ();
},
onFailure: function() { alert( '<?php etranslate( 'Error' );?>' ) }
});
return true;
}
// View the event
// key is the array index of the events[] object (which returns an array)
// location is the index in the array
function view_event ( key, location )
{
var myEvent = null;
var found = 0;
if ( events && events[key] ) {
var daysEvents = events[key];
if ( daysEvents && daysEvents[location] ) {
var myEvent = daysEvents[location];
found = 1;
}
}
if ( ! found ) {
alert ( "Argh! Event not found." );
return;
}
// Use the modal dialog to display the event.
// First update the <div> content with the information from this
// event.
function viewWindowClosed() {
viewDialogIsVisible = false;
}
Modalbox.show($('viewEventDiv'), {title: '<?php etranslate('View Event');?>', width: 450, onHide: viewWindowClosed, closeString: '<?php etranslate('Cancel');?>' });
//Modalbox.resizeToContent();
viewDialogIsVisible = true;
$('name').innerHTML = myEvent._name;
$('description').innerHTML = format_description ( myEvent._description );
$('date').innerHTML = format_date ( myEvent._localDate, true );
$('time').innerHTML = format_time ( myEvent._localTime, false );
$('updated').innerHTML = format_date ( myEvent._localDate, false ) + ' ' +
format_time ( myEvent._modtime, false ) + ' GMT';
$('createdby').innerHTML = users[myEvent._owner] ?
users[myEvent._owner] : myEvent._owner;
if ( myEvent._priority < 4 )
$('priority').innerHTML = '<?php etranslate('High');?>';
else if ( myEvent._priority < 7 )
$('priority').innerHTML = '<?php etranslate('Medium');?>';
else
$('priority').innerHTML = '<?php etranslate('Low');?>';
if ( myEvent._access == 'P' )
$('access').innerHTML = '<?php etranslate('Public');?>';
else if ( myEvent._access == 'C' )
$('access').innerHTML = '<?php etranslate('Confidential');?>';
else
$('access').innerHTML = '<?php etranslate('Private');?>';
<?php if ( $CATEGORIES_ENABLED == 'Y' ) { ?>
<?php } ?>
$('eventlink').innerHTML = '<a href="view_entry.php?id=' + myEvent._id +
<?php if ( ! empty ( $user ) && $login != $user ) { echo "'&user=$user' + "; } ?>
'" class="fakebutton"><?php etranslate('View Event')?></a>';
// For now, blank out participants.
$('participants').innerHTML = '<?php echo $SMALL_LOADING;?>';
<?php if ( Doc::attachmentsEnabled() ) { ?>
$('attachments').innerHTML = '<?php echo $SMALL_LOADING;?>';
<?php } ?>
<?php if ( Doc::commentsEnabled() ) { ?>
$('comments').innerHTML = '<?php echo $SMALL_LOADING;?>';
<?php } ?>
// Load participants via AJAX
new Ajax.Request('events_ajax.php',
{
method:'get',
parameters: { action: 'eventinfo', id: myEvent._id },
onSuccess: function( transport ) {
if ( ! transport.responseText ) {
alert ( '<?php etranslate('Error');?>: <?php etranslate('no response from server');?>' + ': events_ajax.php?action=eventinfo&id=' + myEvent._id );
return;
}
//alert ( "Response:\n" + transport.responseText );
try {
var response = transport.responseText.evalJSON();
// Hmmm... The Prototype JSON above doesn't seem to work!
//var response = eval('(' + transport.responseText + ')');
} 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 text = '';
for ( var i = 0; i < response.participants.length; i++ ) {
var participant = response.participants[i];
var login = participant.login;
var fullname = users[login] ? users[login] : login;
if ( text.length > 0 ) text += "<br />";
text += fullname;
if ( participant.status == 'W' )
text += ' (?)';
}
$('participants').innerHTML = text;
<?php if ( Doc::attachmentsEnabled() ) { ?>
text = '';
for ( var i = 0; i < response.attachments.length; i++ ) {
var attachment = response.attachments[i];
var summary = attachment.summary;
if ( text.length > 0 ) text += "<br />";
text += summary;
}
if ( response.attachments.length == 0 )
text = '<?php etranslate('None');?>';
$('attachments').innerHTML = text;
<?php } ?>
<?php if ( Doc::commentsEnabled() ) { ?>
text = '<dl style="margin-top: 0;">';
for ( var i = 0; i < response.comments.length; i++ ) {
var comment = response.comments[i];
text += "<dt>" + comment.description + "<br />" +
comment.owner + " @ " + comment.datetime + "</dt>" +
"<dd>" + comment.text + "</dd>";
}
text += "</dl>\n";
if ( response.comments.length == 0 )
text = '<?php etranslate('None');?>';
$('comments').innerHTML = text;
<?php } ?>
},
onFailure: function() { alert( '<?php etranslate( 'Error' );?>' ) }
});
}
// Update the day, week, month and agenda content (but not the tasks which
// are loaded by a different ajax call).
// This is called from ajax_get_events (which loads new event data) and
// the callbacks for selecting categories.
function update_display ( year, month, day )
{
currentYear = year;
currentMonth = month;
currentDay = day;
$('contentDay').innerHTML = build_day_view ( year, month, day );
// set scroll location to 8AM (50 pixels/hour)
$('daydiv').scrollTop = 400;
// TODO: save the position of the scrollbar so we can preserve on next/prev
// TODO: Use start work hour from preferences.
$('contentWeek').innerHTML = "Not yet implemented...";
$('contentMonth').innerHTML = build_month_view ( year, month );
$('contentYear').innerHTML = build_year_view ( year, month );
$('contentAgenda').innerHTML = build_agenda_view ( year, month );
var today = new Date ();
dateYmd = "" + year;
if ( month < 10 )
dateYmd += '0';
dateYmd += "" + month;
if ( day < 10 )
dateYmd += '0';
dateYmd += "" + day;
}
// Update the task display.
function update_task_display ()
{
build_task_view ();
}
function prev_day_link ( year, month, day )
{
day--;
if ( day == 0 ) {
month--;
if ( month == 0 ) {
year--;
month = 12;
}
day = ( year % 4 == 0 ) ? leapDaysPerMonth[month] :
daysPerMonth[month];
}
return "<span id=\"prevday\" class=\"clickable fakebutton noprint\" onclick=\"ajax_get_events(" +
year + "," + month + "," + day + ")\"><</span>";
}
function next_day_link ( year, month, day )
{
day++;
var daysInMonth = ( year % 4 == 0 ) ? leapDaysPerMonth[month] :
daysPerMonth[month];
if ( day > daysInMonth ) {
day = 1;
month++;
if ( month > 12 ) {
year++;
month = 1;
}
}
return "<span id=\"nextday\" class=\"clickable fakebutton noprint\" onclick=\"ajax_get_events(" +
year + "," + month + "," + day + ")\">></span>";
}
function prev_month_link_dayview ( year, month, day )
{
month--;
if ( month < 1 ) {
month = 12;
year--;
}
return "<span id=\"prevmonthdayview\" class=\"clickable fakebutton noprint\" onclick=\"ajax_get_events(" +
year + "," + month + "," + day + ")\"><<</span>";
}
function next_month_link_dayview ( year, month, day )
{
month++;
if ( month > 12 ) {
month = 1;
year++;
}
return "<span id=\"nextmonthdayview\" class=\"clickable fakebutton noprint\" onclick=\"ajax_get_events(" +
year + "," + month + "," + day + ")\">>></span>";
}
function prev_month_link ( year, month )
{
var m, y;
if ( month == 1 ) {
m = 12;
y = parseInt(year) - 1;
} else {
m = parseInt(month) - 1;
y = year;
}
return '<span id="prevmonth" class="clickable noprint" onclick="ajax_get_events(' +
y + ',' + m + ',1)"><img src="images/combo-prev.png" alt="' +
shortMonths[m-1] + '"/></span>';
}
function next_month_link ( year, month )
{
var m, y;
if ( month == 12 ) {
m = 1;
y = parseInt(year) + 1;
} else {
m = parseInt(month) + 1;
y = year;
}
return '<span id="nextmonth" class="clickable noprint" onclick="ajax_get_events(' +
y + ',' + m + ',1)"><img src="images/combo-next.png" alt="' + shortMonths[m-1] + '"/></span>';
}
// Build a table of quick links to all the months in the current
// year and a link to the next and previous years.
function month_view_nav_links ( year, month )
{
var ret, i;
ret = '<table class="noprint monthnavlinks">';
ret += '<tr><td rowspan="2" class="aligncenter clickable" onclick="ajax_get_events(' + (parseInt(year)-1) +
',' + month + ',1)">' +
'<img src="images/combo-prev.png"/><br/>' + (year-1) + '</td>';
for ( i = 1; i <= 6; i++ ) {
ret += '<td class="';
if ( i == month )
ret += 'currentMonthLink ';
ret += 'clickable" onclick="ajax_get_events(' + year +
',' + i + ',1)">' + shortMonths[i-1] + '</td>';
}
ret += '<td rowspan="2" class="aligncenter clickable" onclick="ajax_get_events(' + (parseInt(year)+1) +
',' + parseInt(month) + ',1)">' +
'<img src="images/combo-next.png"/><br/>' + (parseInt(year)+1) + '</td>';
// Add link to today
var today = new Date();
var d = today.getDate();
var m = today.getMonth() + 1;
var y = today.getYear() + 1900;
ret += '<td rowspan="2" class="aligncenter clickable" onclick="ajax_get_events(' +
y + ',' + m + ',' + d + ')">' +
'<img src="images/combo-today.png" style="vertical-align: middle;" />'
+ "<br/><?php etranslate('Today');?></td></tr>";
// Jul - Dec
for ( i = 7; i <= 12; i++ ) {
ret += '<td class="';
if ( i == month )
ret += 'currentMonthLink ';
ret += 'clickable" onclick="ajax_get_events(' + year +
',' + i + ',1)">' + shortMonths[i-1] + '</td>';
}
ret += '</table>';
return ret;
}
function prev_year_link ( year, month )
{
year = parseInt(year);
return "<span id=\"prevyear\" class=\"clickable fakebutton noprint\" onclick=\"ajax_get_events(" + ( year - 1 ) +
"," + month + ",1)\"><<" + ( year -1 ) + "</span>";
}
function next_year_link ( year, month )
{
year = parseInt(year);
return "<span id=\"nextyear\" class=\"clickable fakebutton noprint\" onclick=\"ajax_get_events(" + ( year + 1 ) +
"," + month + ",1)\">" + ( year + 1 ) + ">></span>";
}
function today_link()
{
var today = new Date();
var d = today.getDate();
var m = today.getMonth() + 1;
var y = today.getYear() + 1900;
return "<span class=\"clickable fakebutton noprint\" onclick=\"ajax_get_events(" +
y + "," + m + "," + d + ")\">" +
'<img src="images/combo-today.png" style="vertical-align: middle;" />'
+ " <?php etranslate('Today');?></span>";
}
// Callback for the user clicking on a cell in the month view, which
// will allow the user to create a new event.
function monthCellClickHandler ( dateYmd )
{
// Make sure user has not opened the view dialog. When a user clicks
// on an event to view it, we will still receive the onclick event for
// the td cell onclick handler below it.
if ( viewDialogIsVisible )
return;
// If user clicked on the day in the month view, we are switching to
// the day view, so ignore the click event.
if ( switchingToDayView )
return;
function addWindowClosed() {
quickAddDialogIsOpen = false;
}
// Display quick add popup
Modalbox.show($('quickAddDiv'), {title: '<?php etranslate('Add Entry');?>', width: <?php echo $quick_add_width;?>, transitions: false, onHide: addWindowClosed, closeString: '<?php etranslate('Cancel');?>' });
Modalbox.resizeToContent();
$('quickAddName').setAttribute ( 'value', "<?php etranslate('Unnamed Event');?>" );
$('quickAddName').select();
$('quickAddName').focus();