-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
index.php
1586 lines (1423 loc) · 73.1 KB
/
index.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
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
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Eric Seigne <erics@rycks.com>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/comm/action/index.php
* \ingroup agenda
* \brief Home page of calendar events
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
if (! empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
}
if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5;
$MAXAGENDA=$conf->global->AGENDA_EXT_NB;
$filter = GETPOST("filter",'',3);
$filtert = GETPOST("filtert","int",3);
$usergroup = GETPOST("usergroup","int",3);
$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
// If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
{
$filtert=$user->id;
}
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page","int");
if ($page == -1) { $page = 0; }
$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
$offset = $limit * $page;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="a.datec";
// Security check
$socid = GETPOST("socid","int");
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'agenda', 0, '', 'myactions');
if ($socid < 0) $socid='';
$canedit=1;
if (! $user->rights->agenda->myactions->read) accessforbidden();
if (! $user->rights->agenda->allactions->read) $canedit=0;
if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no permission to see all, we show only affected to me
{
$filtert=$user->id;
}
$action=GETPOST('action','alpha');
$resourceid=GETPOST("resourceid","int");
$year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
$month=GETPOST("month","int")?GETPOST("month","int"):date("m");
$week=GETPOST("week","int")?GETPOST("week","int"):date("W");
$day=GETPOST("day","int")?GETPOST("day","int"):0;
$pid=GETPOST("projectid","int",3);
$status=GETPOST("status");
$type=GETPOST("type");
$maxprint=(isset($_GET["maxprint"])?GETPOST("maxprint"):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
if (GETPOST('actioncode','array'))
{
$actioncode=GETPOST('actioncode','array',3);
if (! count($actioncode)) $actioncode='0';
}
else
{
$actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE));
}
if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE);
if ($status == '' && ! isset($_GET['status']) && ! isset($_POST['status'])) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS);
if (empty($action) && ! isset($_GET['action']) && ! isset($_POST['action'])) $action=(empty($conf->global->AGENDA_DEFAULT_VIEW)?'show_month':$conf->global->AGENDA_DEFAULT_VIEW);
if (GETPOST('viewcal') && $action != 'show_day' && $action != 'show_week') {
$action='show_month'; $day='';
} // View by month
if (GETPOST('viewweek') || $action == 'show_week') {
$action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d"));
} // View by week
if (GETPOST('viewday') || $action == 'show_day') {
$action='show_day'; $day=($day?$day:date("d"));
} // View by day
$langs->load("agenda");
$langs->load("other");
$langs->load("commercial");
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('agenda'));
/*
* Actions
*/
if (GETPOST("viewlist") || $action == 'show_list')
{
$param='';
foreach($_POST as $key => $val)
{
if ($key=='token') continue;
$param.='&'.$key.'='.urlencode($val);
}
//print $param;
header("Location: ".DOL_URL_ROOT.'/comm/action/listactions.php?'.$param);
exit;
}
if (GETPOST("viewperuser") || $action == 'show_peruser')
{
$param='';
foreach($_POST as $key => $val)
{
if ($key=='token') continue;
$param.='&'.$key.'='.urlencode($val);
}
//print $param;
header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param);
exit;
}
if ($action =='delete_action')
{
$event = new ActionComm($db);
$event->fetch($actionid);
$result=$event->delete();
}
/*
* View
*/
$help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
llxHeader('',$langs->trans("Agenda"),$help_url);
$form=new Form($db);
$companystatic=new Societe($db);
$contactstatic=new Contact($db);
$now=dol_now();
$nowarray=dol_getdate($now);
$nowyear=$nowarray['year'];
$nowmonth=$nowarray['mon'];
$nowday=$nowarray['mday'];
$listofextcals=array();
// Define list of external calendars (global admin setup)
if (empty($conf->global->AGENDA_DISABLE_EXT))
{
$i=0;
while($i < $MAXAGENDA)
{
$i++;
$source='AGENDA_EXT_SRC'.$i;
$name='AGENDA_EXT_NAME'.$i;
$offsettz='AGENDA_EXT_OFFSETTZ'.$i;
$color='AGENDA_EXT_COLOR'.$i;
$buggedfile='AGENDA_EXT_BUGGEDFILE'.$i;
if (! empty($conf->global->$source) && ! empty($conf->global->$name))
{
// Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
$listofextcals[]=array('src'=>$conf->global->$source,'name'=>$conf->global->$name,'offsettz'=>$conf->global->$offsettz,'color'=>$conf->global->$color,'buggedfile'=>(isset($conf->global->buggedfile)?$conf->global->buggedfile:0));
}
}
}
// Define list of external calendars (user setup)
if (empty($user->conf->AGENDA_DISABLE_EXT))
{
$i=0;
while($i < $MAXAGENDA)
{
$i++;
$source='AGENDA_EXT_SRC_'.$user->id.'_'.$i;
$name='AGENDA_EXT_NAME_'.$user->id.'_'.$i;
$offsettz='AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
$color='AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
$enabled='AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
$buggedfile='AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
if (! empty($user->conf->$source) && ! empty($user->conf->$name))
{
// Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
$listofextcals[]=array('src'=>$user->conf->$source,'name'=>$user->conf->$name,'offsettz'=>$user->conf->$offsettz,'color'=>$user->conf->$color,'buggedfile'=>(isset($user->conf->buggedfile)?$user->conf->buggedfile:0));
}
}
}
if (empty($action) || $action=='show_month')
{
$prev = dol_get_prev_month($month, $year);
$prev_year = $prev['year'];
$prev_month = $prev['month'];
$next = dol_get_next_month($month, $year);
$next_year = $next['year'];
$next_month = $next['month'];
$max_day_in_prev_month = date("t",dol_mktime(0,0,0,$prev_month,1,$prev_year)); // Nb of days in previous month
$max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year)); // Nb of days in next month
// tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
$tmpday = -date("w",dol_mktime(12,0,0,$month,1,$year,true))+2; // date('w') is 0 fo sunday
$tmpday+=((isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)-1);
if ($tmpday >= 1) $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
$firstdaytoshow=dol_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$tmpday,$prev_year);
$next_day=7 - ($max_day_in_month+1-$tmpday) % 7;
if ($next_day < 6) $next_day+=7;
$lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
}
if ($action=='show_week')
{
$prev = dol_get_first_day_week($day, $month, $year);
$prev_year = $prev['prev_year'];
$prev_month = $prev['prev_month'];
$prev_day = $prev['prev_day'];
$first_day = $prev['first_day'];
$first_month= $prev['first_month'];
$first_year = $prev['first_year'];
$week = $prev['week'];
$day = (int) $day;
$next = dol_get_next_week($first_day, $week, $first_month, $first_year);
$next_year = $next['year'];
$next_month = $next['month'];
$next_day = $next['day'];
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
$firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
$lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
$max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year));
$tmpday = $first_day;
}
if ($action == 'show_day')
{
$prev = dol_get_prev_day($day, $month, $year);
$prev_year = $prev['year'];
$prev_month = $prev['month'];
$prev_day = $prev['day'];
$next = dol_get_next_day($day, $month, $year);
$next_year = $next['year'];
$next_month = $next['month'];
$next_day = $next['day'];
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
$firstdaytoshow=dol_mktime(0,0,0,$prev_month,$prev_day,$prev_year);
$lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
}
//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
//print dol_print_date($firstdaytoshow,'day');
//print dol_print_date($lastdaytoshow,'day');
$title=$langs->trans("DoneAndToDoActions");
if ($status == 'done') $title=$langs->trans("DoneActions");
if ($status == 'todo') $title=$langs->trans("ToDoActions");
$param='';
if ($actioncode || isset($_GET['actioncode']) || isset($_POST['actioncode'])) $param.="&actioncode=".$actioncode;
if ($resourceid > 0) $param.="&resourceid=".$resourceid;
if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status;
if ($filter) $param.="&filter=".$filter;
if ($filtert) $param.="&filtert=".$filtert;
if ($socid) $param.="&socid=".$socid;
if ($showbirthday) $param.="&showbirthday=1";
if ($pid) $param.="&projectid=".$pid;
if ($type) $param.="&type=".$type;
if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month') $param.='&action='.$action;
$param.="&maxprint=".$maxprint;
// Show navigation bar
if (empty($action) || $action=='show_month')
{
$nav ="<a href=\"?year=".$prev_year."&month=".$prev_month.$param."\"><i class=\"fa fa-chevron-left\"></i></a> \n";
$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%b %Y");
$nav.=" </span>\n";
$nav.=" <a href=\"?year=".$next_year."&month=".$next_month.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
$nav.=" (<a href=\"?year=".$nowyear."&month=".$nowmonth.$param."\">".$langs->trans("Today")."</a>)";
$picto='calendar';
}
if ($action=='show_week')
{
$nav ="<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\" title=\"".dol_escape_htmltag($langs->trans("Previous"))."\"></i></a> \n";
$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week;
$nav.=" </span>\n";
$nav.=" <a href=\"?year=".$next_year."&month=".$next_month."&day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\" title=\"".dol_escape_htmltag($langs->trans("Next"))."\"></i></a>\n";
$nav.=" (<a href=\"?year=".$nowyear."&month=".$nowmonth."&day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
$picto='calendarweek';
}
if ($action=='show_day')
{
$nav ="<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\"></i></a> \n";
$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,$day,$year),"daytextshort");
$nav.=" </span>\n";
$nav.=" <a href=\"?year=".$next_year."&month=".$next_month."&day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
$nav.=" (<a href=\"?year=".$nowyear."&month=".$nowmonth."&day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
$picto='calendarday';
}
// Must be after the nav definition
$param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
//print 'x'.$param;
$tabactive='';
if ($action == 'show_month') $tabactive='cardmonth';
if ($action == 'show_week') $tabactive='cardweek';
if ($action == 'show_day') $tabactive='cardday';
if ($action == 'show_list') $tabactive='cardlist';
$paramnoaction=preg_replace('/action=[a-z_]+/','',$param);
$head = calendars_prepare_head($paramnoaction);
dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup,'', $resourceid);
dol_fiche_end();
// Define the legend/list of calendard to show
$s=''; $link='';
$showextcals=$listofextcals;
if (! empty($conf->use_javascript_ajax)) // If javascript on
{
$s.='<!-- Div to calendars selectors -->'."\n";
$s.='<script type="text/javascript">' . "\n";
$s.='jQuery(document).ready(function () {' . "\n";
$s.='jQuery("#check_birthday").click(function() { console.log("Toggle birthday"); jQuery(".family_birthday").toggle(); });' . "\n";
$s.='jQuery(".family_birthday").toggle();' . "\n";
if ($action=="show_week" || $action=="show_month" || empty($action))
{
// Code to enable drag and drop
$s.='jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {';
// Code to submit form
$s.='console.log("submit form to record new event");';
//$s.='console.log(event.target);';
$s.='var newval = jQuery(event.target).closest("div.dayevent").attr("id");';
$s.='console.log("found parent div.dayevent with id = "+newval);';
$s.='var frm=jQuery("#move_event"); frm.attr("action",ui.item.find("a.cal_event").attr("href")).children("#newdate").val(newval);frm.submit();}';
$s.='});'."\n";
}
$s.='});' . "\n";
$s.='</script>' . "\n";
// Local calendar
$s.='<div class="nowrap clear float minheight20"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs->trans("LocalAgenda").' </div>';
// External calendars
if (is_array($showextcals) && count($showextcals) > 0)
{
$s.='<script type="text/javascript">' . "\n";
$s.='jQuery(document).ready(function () {
jQuery("table input[name^=\"check_ext\"]").click(function() {
var name = $(this).attr("name");
jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
});
});' . "\n";
$s.='</script>' . "\n";
foreach ($showextcals as $val)
{
$htmlname = md5($val['name']);
$s.='<div class="nowrap float"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val['name'] . ' </div>';
}
}
// Birthdays
$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' </div>';
// Calendars from hooks
$parameters=array(); $object=null;
$reshook=$hookmanager->executeHooks('addCalendarChoice',$parameters,$object,$action);
if (empty($reshook))
{
$s.= $hookmanager->resPrint;
}
elseif ($reshook > 1)
{
$s = $hookmanager->resPrint;
}
}
else // If javascript off
{
$newparam=$param; // newparam is for birthday links
$newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam);
if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1';
$link='<a href="'.$_SERVER['PHP_SELF'];
$link.='?'.$newparam;
$link.='">';
if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents");
else $link.=$langs->trans("AgendaHideBirthdayEvents");
$link.='</a>';
}
print load_fiche_titre($s, $link.' '.$nav, '', 0, 0, 'tablelistofcalendars');
// Load events from database into $eventarray
$eventarray=array();
$sql = 'SELECT ';
if ($usergroup > 0) $sql.=" DISTINCT";
$sql.= ' a.id, a.label,';
$sql.= ' a.datep,';
$sql.= ' a.datep2,';
$sql.= ' a.percent,';
$sql.= ' a.fk_user_author,a.fk_user_action,';
$sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,';
$sql.= ' a.fk_soc, a.fk_contact,';
$sql.= ' a.fk_element, a.elementtype,';
$sql.= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color';
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
// We must filter on resource table
if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r";
// We must filter on assignement table
if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
$sql.= ' WHERE a.fk_action = ca.id';
$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')';
// Condition on actioncode
if (! empty($actioncode))
{
if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
{
if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
else
{
if ($actioncode == 'AC_OTH') $sql.= " AND ca.type != 'systemauto'";
if ($actioncode == 'AC_OTH_AUTO') $sql.= " AND ca.type = 'systemauto'";
}
}
else
{
if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
else
{
$sql.=" AND ca.code IN ('".implode("','", explode(',',$actioncode))."')";
}
}
}
if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
if ($socid > 0) $sql.= ' AND a.fk_soc = '.$socid;
// We must filter on assignement table
if ($filtert > 0 || $usergroup > 0) $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
if ($action == 'show_day')
{
$sql.= " AND (";
$sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
$sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
$sql.= " OR ";
$sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
$sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
$sql.= " OR ";
$sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
$sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
$sql.= ')';
}
else
{
// To limit array
$sql.= " AND (";
$sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'"; // Start 7 days before
$sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')"; // End 7 days after + 3 to go from 28 to 31
$sql.= " OR ";
$sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
$sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
$sql.= " OR ";
$sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
$sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
$sql.= ')';
}
if ($type) $sql.= " AND ca.id = ".$type;
if ($status == '0') { $sql.= " AND a.percent = 0"; }
if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable
if ($status == '50') { $sql.= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; }
if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; }
// We must filter on assignement table
if ($filtert > 0 || $usergroup > 0)
{
$sql.= " AND (";
if ($filtert > 0) $sql.= "ar.fk_element = ".$filtert;
if ($usergroup > 0) $sql.= ($filtert>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup;
$sql.= ")";
}
// Sort on date
$sql.= ' ORDER BY datep';
//print $sql;
dol_syslog("comm/action/index.php", LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
// Discard auto action if option is on
if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO')
{
$i++;
continue;
}
// Create a new object action
$event=new ActionComm($db);
$event->id=$obj->id;
$event->datep=$db->jdate($obj->datep); // datep and datef are GMT date. Example: 1970-01-01 01:00:00, jdate will return 0 if TZ of PHP server is Europe/Berlin
$event->datef=$db->jdate($obj->datep2);
//var_dump($obj->datep);
//var_dump($event->datep);
$event->type_code=$obj->type_code;
$event->type_label=$obj->type_label;
$event->type_color=$obj->type_color;
$event->libelle=$obj->label;
$event->percentage=$obj->percent;
$event->authorid=$obj->fk_user_author; // user id of creator
$event->userownerid=$obj->fk_user_action; // user id of owner
$event->fetch_userassigned(); // This load $event->userassigned
$event->priority=$obj->priority;
$event->fulldayevent=$obj->fulldayevent;
$event->location=$obj->location;
$event->transparency=$obj->transparency;
$event->fk_element=$obj->fk_element;
$event->elementtype=$obj->elementtype;
$event->societe->id=$obj->fk_soc;
$event->contact->id=$obj->fk_contact;
// Defined date_start_in_calendar and date_end_in_calendar property
// They are date start and end of action but modified to not be outside calendar view.
if ($event->percentage <= 0)
{
$event->date_start_in_calendar=$event->datep;
if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
else $event->date_end_in_calendar=$event->datep;
}
else
{
$event->date_start_in_calendar=$event->datep;
if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
else $event->date_end_in_calendar=$event->datep;
}
// Define ponctual property
if ($event->date_start_in_calendar == $event->date_end_in_calendar)
{
$event->ponctuel=1;
}
// Check values
if ($event->date_end_in_calendar < $firstdaytoshow ||
$event->date_start_in_calendar >= $lastdaytoshow)
{
// This record is out of visible range
}
else
{
if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
// Add an entry in actionarray for each day
$daycursor=$event->date_start_in_calendar;
$annee = date('Y',$daycursor);
$mois = date('m',$daycursor);
$jour = date('d',$daycursor);
// Loop on each day covered by action to prepare an index to show on calendar
$loop=true; $j=0;
$daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
do
{
//if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
$eventarray[$daykey][]=$event;
$j++;
$daykey+=60*60*24;
if ($daykey > $event->date_end_in_calendar) $loop=false;
}
while ($loop);
//print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
//print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
}
$i++;
}
}
else
{
dol_print_error($db);
}
// Complete $eventarray with birthdates
if ($showbirthday)
{
// Add events in array
$sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
$sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
$sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
$sql.= " AND sp.entity IN (".getEntity('societe', 1).")";
if ($action == 'show_day')
{
$sql.= ' AND MONTH(birthday) = '.$month;
$sql.= ' AND DAY(birthday) = '.$day;
}
else
{
$sql.= ' AND MONTH(birthday) = '.$month;
}
$sql.= ' ORDER BY birthday';
dol_syslog("comm/action/index.php", LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$event=new ActionComm($db);
$event->id=$obj->rowid; // We put contact id in action id for birthdays events
$datebirth=dol_stringtotime($obj->birthday,1);
//print 'ee'.$obj->birthday.'-'.$datebirth;
$datearray=dol_getdate($datebirth,true);
$event->datep=dol_mktime(0,0,0,$datearray['mon'],$datearray['mday'],$year,true); // For full day events, date are also GMT but they wont but converted during output
$event->datef=$event->datep;
$event->type_code='BIRTHDAY';
$event->libelle=$langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname,$obj->lastname);
$event->percentage=100;
$event->fulldayevent=true;
$event->date_start_in_calendar=$event->datep;
$event->date_end_in_calendar=$event->datef;
$event->ponctuel=0;
// Add an entry in actionarray for each day
$daycursor=$event->date_start_in_calendar;
$annee = date('Y',$daycursor);
$mois = date('m',$daycursor);
$jour = date('d',$daycursor);
$loop=true;
$daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
do
{
$eventarray[$daykey][]=$event;
$daykey+=60*60*24;
if ($daykey > $event->date_end_in_calendar) $loop=false;
}
while ($loop);
$i++;
}
}
else
{
dol_print_error($db);
}
}
// Complete $eventarray with external import Ical
if (count($listofextcals))
{
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
foreach($listofextcals as $extcal)
{
$url=$extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
$namecal = $extcal['name'];
$offsettz = $extcal['offsettz'];
$colorcal = $extcal['color'];
$buggedfile = $extcal['buggedfile'];
//print "url=".$url." namecal=".$namecal." colorcal=".$colorcal." buggedfile=".$buggedfile;
$ical=new ICal();
$ical->parse($url);
// After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
//var_dump($ical->cal); exit;
$icalevents=array();
if (is_array($ical->get_event_list())) $icalevents=array_merge($icalevents,$ical->get_event_list()); // Add $ical->cal['VEVENT']
if (is_array($ical->get_freebusy_list())) $icalevents=array_merge($icalevents,$ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
if (count($icalevents)>0)
{
// Duplicate all repeatable events into new entries
$moreicalevents=array();
foreach($icalevents as $icalevent)
{
if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) //repeatable event
{
//if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
//if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
if ($icalevent['DTSTART;VALUE=DATE']) //fullday event
{
$datecurstart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
$datecurend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
}
else if (is_array($icalevent['DTSTART']) && ! empty($icalevent['DTSTART']['unixtime']))
{
$datecurstart=$icalevent['DTSTART']['unixtime'];
$datecurend=$icalevent['DTEND']['unixtime'];
if (! empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart)
{
//var_dump($ical->cal);
$tmpcurstart=$datecurstart;
$tmpcurend=$datecurend;
$tmpdaylightstart=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
$tmpdaylightend=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['STANDARD']['DTSTART'];
//var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
// Edit datecurstart and datecurend
if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurstart-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
else $datecurstart-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurend-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
else $datecurend-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
}
// datecurstart and datecurend are now GMT date
//var_dump($datecurstart); var_dump($datecurend); exit;
}
else
{
// Not a recongized record
dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
continue;
}
//print 'xx'.$datecurstart;exit;
$interval=(empty($icalevent['RRULE']['INTERVAL'])?1:$icalevent['RRULE']['INTERVAL']);
$until=empty($icalevent['RRULE']['UNTIL'])?0:dol_stringtotime($icalevent['RRULE']['UNTIL'],1);
$maxrepeat=empty($icalevent['RRULE']['COUNT'])?0:$icalevent['RRULE']['COUNT'];
if ($until && ($until+($datecurend-$datecurstart)) < $firstdaytoshow) continue; // We discard repeatable event that end before start date to show
if ($datecurstart >= $lastdaytoshow) continue; // We discard repeatable event that start after end date to show
$numofevent=0;
while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)))
{
if ($datecurend >= $firstdaytoshow) // We add event
{
$newevent=$icalevent;
unset($newevent['RRULE']);
if ($icalevent['DTSTART;VALUE=DATE'])
{
$newevent['DTSTART;VALUE=DATE']=dol_print_date($datecurstart,'%Y%m%d');
$newevent['DTEND;VALUE=DATE']=dol_print_date($datecurend+1,'%Y%m%d');
}
else
{
$newevent['DTSTART']=$datecurstart;
$newevent['DTEND']=$datecurend;
}
$moreicalevents[]=$newevent;
}
// Jump on next occurence
$numofevent++;
$savdatecurstart=$datecurstart;
if ($icalevent['RRULE']['FREQ']=='DAILY')
{
$datecurstart=dol_time_plus_duree($datecurstart, $interval, 'd');
$datecurend=dol_time_plus_duree($datecurend, $interval, 'd');
}
if ($icalevent['RRULE']['FREQ']=='WEEKLY')
{
$datecurstart=dol_time_plus_duree($datecurstart, $interval, 'w');
$datecurend=dol_time_plus_duree($datecurend, $interval, 'w');
}
elseif ($icalevent['RRULE']['FREQ']=='MONTHLY')
{
$datecurstart=dol_time_plus_duree($datecurstart, $interval, 'm');
$datecurend=dol_time_plus_duree($datecurend, $interval, 'm');
}
elseif ($icalevent['RRULE']['FREQ']=='YEARLY')
{
$datecurstart=dol_time_plus_duree($datecurstart, $interval, 'y');
$datecurend=dol_time_plus_duree($datecurend, $interval, 'y');
}
// Test to avoid infinite loop ($datecurstart must increase)
if ($savdatecurstart >= $datecurstart)
{
dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
$datecurstart+=3600*24*7;
$datecurend+=3600*24*7;
}
}
}
}
$icalevents=array_merge($icalevents,$moreicalevents);
// Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
foreach($icalevents as $icalevent)
{
//var_dump($icalevent);
//print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
if (! empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
// Create a new object action
$event=new ActionComm($db);
$addevent = false;
if (isset($icalevent['DTSTART;VALUE=DATE'])) // fullday event
{
// For full day events, date are also GMT but they wont but converted using tz during output
$datestart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
$dateend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
//print 'x'.$datestart.'-'.$dateend;exit;
//print dol_print_date($dateend,'dayhour','gmt');
$event->fulldayevent=true;
$addevent=true;
}
elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
{
$datestart=$icalevent['DTSTART'];
$dateend=$icalevent['DTEND'];
$datestart+=+($offsettz * 3600);
$dateend+=+($offsettz * 3600);
$addevent=true;
//var_dump($offsettz);
//var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
}
elseif (isset($icalevent['DTSTART']['unixtime'])) // File contains a local timezone + a TZ (for example when using bluemind)
{
$datestart=$icalevent['DTSTART']['unixtime'];
$dateend=$icalevent['DTEND']['unixtime'];
$datestart+=+($offsettz * 3600);
$dateend+=+($offsettz * 3600);
// $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
if ($buggedfile === 'uselocalandtznodaylight') // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
{
// TODO
}
// $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
if ($buggedfile === 'uselocalandtzdaylight') // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
{
$localtzs = new DateTimeZone(preg_replace('/"/','',$icalevent['DTSTART']['TZID']));
$localtze = new DateTimeZone(preg_replace('/"/','',$icalevent['DTEND']['TZID']));
$localdts = new DateTime(dol_print_date($datestart,'dayrfc','gmt'), $localtzs);
$localdte = new DateTime(dol_print_date($dateend,'dayrfc','gmt'), $localtze);
$tmps=-1*$localtzs->getOffset($localdts);
$tmpe=-1*$localtze->getOffset($localdte);
$datestart+=$tmps;
$dateend+=$tmpe;
//var_dump($datestart);
}
$addevent=true;
}
if ($addevent)
{
$event->id=$icalevent['UID'];
$event->icalname=$namecal;
$event->icalcolor=$colorcal;
$usertime=0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
$event->datep=$datestart+$usertime;
$event->datef=$dateend+$usertime;
$event->type_code="ICALEVENT";
if($icalevent['SUMMARY']) $event->libelle=$icalevent['SUMMARY'];
elseif($icalevent['DESCRIPTION']) $event->libelle=dol_nl2br($icalevent['DESCRIPTION'],1);
else $event->libelle = $langs->trans("ExtSiteNoLabel");
$event->date_start_in_calendar=$event->datep;
if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
else $event->date_end_in_calendar=$event->datep;
// Define ponctual property
if ($event->date_start_in_calendar == $event->date_end_in_calendar)
{
$event->ponctuel=1;
//print 'x'.$datestart.'-'.$dateend;exit;
}
// Add event into $eventarray if date range are ok.
if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow)
{
//print 'x'.$datestart.'-'.$dateend;exit;
//print 'x'.$datestart.'-'.$dateend;exit;
//print 'x'.$datestart.'-'.$dateend;exit;
// This record is out of visible range
}
else
{
if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow - 1);
// Add an entry in actionarray for each day
$daycursor=$event->date_start_in_calendar;
$annee = date('Y',$daycursor);
$mois = date('m',$daycursor);
$jour = date('d',$daycursor);
// Loop on each day covered by action to prepare an index to show on calendar
$loop=true; $j=0;
// daykey must be date that represent day box in calendar so must be a user time
$daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
$daykeygmt=dol_mktime(0,0,0,$mois,$jour,$annee,true,0);
do
{
//if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
$eventarray[$daykey][]=$event;
$daykey+=60*60*24; $daykeygmt+=60*60*24; // Add one day
if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) $loop=false;
}
while ($loop);
}
}
}
}
}
}
// Complete $eventarray with events coming from external module
$parameters=array(); $object=null;
$reshook=$hookmanager->executeHooks('getCalendarEvents',$parameters,$object,$action);
if (! empty($hookmanager->resArray['eventarray'])) {
foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
if (!isset($eventarray[$keyDate])) {
$eventarray[$keyDate]=array();
}
$eventarray[$keyDate]=array_merge($eventarray[$keyDate], $events);
}
}
$maxnbofchar=0;
$cachethirdparties=array();
$cachecontacts=array();
$cacheusers=array();
// Define theme_datacolor array
$color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
if (is_readable($color_file))
{
include_once $color_file;
}
if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), array(200,160,180), array(190,190,220));
if (empty($action) || $action == 'show_month') // View by month
{
$newparam=$param; // newparam is for birthday links
$newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
$newparam=preg_replace('/action=show_month&?/i','',$newparam);
$newparam=preg_replace('/action=show_week&?/i','',$newparam);