C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\heimam\tcpro\editcalendar.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
<?php
/**
 * editcalendar.php
 * 
 * Displays the edit calendar dialog
 * 
 * @package TeamCalPro
 * @version 3.3.001
 * @author George Lewe
 * @copyright Copyright (c) 2004-2010 by George Lewe
 * @link http://www.lewe.com
 * @license http://www.lewe.com/tcpro/doc/license.txt Extended GNU Public License
 */
    
//echo "<script type=\"text/javascript\">alert(\"Debug: \");</script>";
 
/**
 * Set parent flag to control access to child scripts 
 */
define'_VALID_TCPRO');

/**
 * Includes 
 */
require ("config.tcpro.php");
require_once (
"includes/functions.tcpro.php");
getOptions();
if (
strlen($CONF['options']['lang'])) require ("includes/lang/" $CONF['options']['lang'] . ".tcpro.php");
else                                  require (
"includes/lang/english.tcpro.php");

require_once( 
"includes/tcabsence.class.php" );
require_once( 
"includes/tcabsencegroup.class.php" );
require_once( 
"includes/tcconfig.class.php" );
require_once( 
"includes/tcdaynote.class.php" );
require_once( 
"includes/tcgroup.class.php" );
require_once( 
"includes/tcholiday.class.php" );
require_once( 
"includes/tclogin.class.php" );
require_once( 
"includes/tclog.class.php" );
require_once( 
"includes/tcmonth.class.php" );
require_once( 
"includes/tctemplate.class.php" );
require_once( 
"includes/tcuser.class.php" );
require_once( 
"includes/tcusergroup.class.php" );

$A   = new tcAbsence;
$AG  = new tcAbsenceGroup;
$C   = new tcConfig;
$G   = new tcGroup;
$H   = new tcHoliday;
$L   = new tcLogin;
$LOG = new tcLog;
$M   = new tcMonth;
$N   = new tcDaynote;
$T   = new tcTemplate;
$TT  = new tcTemplate// used for template user loop
$U   = new tcUser;
$UL  = new tcUser// User logged in
$UT  = new tcUser// used for template user loop
$UG  = new tcUserGroup;

if ( isset(
$_REQUEST['Year']) )   $Year=$_REQUEST['Year'];
if ( isset(
$_REQUEST['Month']) )  $Month=$_REQUEST['Month'];
if ( isset(
$_REQUEST['Member']) ) $Member=$_REQUEST['Member'];

/**
 * Backward button: Page back one month
 */
if ( isset($_POST['btn_bwd']) ) 
{
   
$mytime $_POST['Month'] . " 1," $Year;
   
$myts strtotime($mytime);
   
$mydate getdate($myts);
   
$monthno intval($mydate['mon']);
   if (
$monthno>1$Month=$CONF['monthnames'][$monthno-1];
   else {
      
$Year=intval($_POST['Year'])-1;
      
$Month=$CONF['monthnames'][12];
   }   
   
$Member=$_POST['Member'];
}

/**
 * Forward button: Page forward one month
 */
if ( isset($_POST['btn_fwd']) ) 
{
   
$mytime $_POST['Month'] . " 1," $Year;
   
$myts strtotime($mytime);
   
$mydate getdate($myts);
   
$monthno intval($mydate['mon']);
   if (
$monthno<12) { 
      
$Month=$CONF['monthnames'][$monthno+1];
   } else {
      
$Year=intval($_POST['Year'])+1;
      
$Month=$CONF['monthnames'][1];
   }   
   
$Member=$_POST['Member'];
}

$error=false;
$warning=false;
 
/**
 * Check authorization 
 */
if ( !checkAuth("editCalendar",$Member) ) 
{
   
$error=true;
   
$err_short=$LANG['err_not_authorized_short'];
   
$err_long=$LANG['err_not_authorized_long'];
   
$err_module="editcalendar.php";

else 
{
   
/**
    * Get the user that is logged in
    */
   
$user=$L->checkLogin();
   
$UL->findByName($user);

   if ( 
$UL->checkUserType($CONF['UTADMIN']) ) $isAdmin TRUE; else $isAdmin FALSE;
   if ( 
$UL->checkUserType($CONF['UTDIRECTOR']) ) $isDirector TRUE; else $isDirector FALSE;
   if ( 
$UL->checkUserType($CONF['UTMANAGER']) ) $isManager TRUE; else $isManager FALSE;
   
   
$weekdays $LANG['weekdays'];
   
/**
    * First create a timestamp
    */
   
$mytime $Month " 1," $Year;
   
$myts strtotime($mytime);
   
/**
    * Get number of days in month
    */
   
$nofdays date("t",$myts);
   
/**
    * Get first weekday of the month
    */
   
$mydate getdate($myts);
   
$weekday1 $mydate['wday'];
   
$monthno sprintf("%02d",intval($mydate['mon']));
   if (
$weekday1=="0"$weekday1="7";
   
$dayofweek intval($weekday1);
   
   
/**
    * Read Month Template
    */
   
$region $CONF['options']['region'];
   
$found $M->findByName($region$Year.$monthno);
   if ( !
$found ) {
      
/**
       * Seems there is no default template for this month yet. 
       * Let's create a default one.
       */
      
$M->region $region;
      
$M->yearmonth $Year.$monthno;
      
$M->template createMonthTemplate($Year,$Month);
      
$M->create();
   } else if ( empty(
$M->template) ) {
      
/**
       * Seems there is an empty default template. That can't be.
       * Let's create a default one.
       */
      
$M->template createMonthTemplate($Year,$Month);
      
$M->update($region$Year.$monthno);
   }
   
   
/**
    * What do we know about the user already
    */
   
$U->findByName($Member);
   
$notify $U->notify;
   
$notifygroup $U->notify_group;
   
   
/**
    * Try to find this users template for this month
    */
   
$found $T->findTemplate($U->username,$Year,$monthno);
   if (!
$found) {
      
/**
       * No template found for this user and month yet.
       * Create a default one.
       */
      
$T->username $U->username;
      
$T->year $Year;
      
$T->month $monthno;
      
$T->template "";
      for (
$i=0$i<intval($nofdays); $i++ ) {
         
$T->template .= $CONF['present'];
      }
      
$T->create();
      
/**
       * Log this event
       */
      
$LOG->log("logUser",$L->checkLogin(),"User default template created: ".$T->year.$T->month);
   }
 
   if (isset(
$_POST['btn_apply'])) {
      
/**
       * Create blank new template and get the users' current template
       * for comparison. If no current template is available copy the
       * new template.
       */
      
$newtemplate "";
      for (
$i=0$i<intval($nofdays); $i++ ) {
         
$newtemplate .= $CONF['present'];
      }
      if (!
$T->findTemplate($U->username,$Year,$monthno)) {
         
$T->template $newtemplate;
      }
      else {
         
/**
          * If this is a regular user we have to make sure that we take over all absences from
          * his current template that are "manager only". Otherwise they would be overwritten with
          * 'present'. 
          */   
         
if ( !$isAdmin AND !$isDirector AND !$isManager 
         {
            for (
$i=0$i<intval($nofdays); $i++ ) {
               
$A->findBySymbol($T->template[$i]);               
               if (
$A->checkOptions($CONF['A_MGR_ONLY'])) $newtemplate[$i] = $T->template[$i];
            }
         }
      }
      
      
/**
       * Create an array of all requested absences
       */
      
$absarray = array();         
      foreach(
$_POST as $key=>$value
      {
         
/**
          * First get the absence check marks in the upper portion
          */
         
if ( $key!="btn_apply" && $key!="rangeabs" && $key!="rangefrom" && $key!="rangeto" && 
              
$key!="recurrabs" && $key!="monday" && $key!="tuesday" && $key!="wednesday" && 
              
$key!="thursday" && $key!="friday" && $key!="saturday" && $key!="sunday" && $key!="workdays" && $key!="weekend" && 
              
$key!="txtReason" && $key!="Month" && $key!="Year" && $key!="Member")
            
$absarray[] = $key;
         
         
/**
          * Then get the range input 2007-01-01
          */
         
if ( $key=="rangeabs" && strlen($_POST['rangefrom']) && strlen($_POST['rangeto']) )
         {
               
$yearfrom substr($_POST['rangefrom'],0,4);
               
$monthfrom substr($_POST['rangefrom'],5,2);
               
$dayfrom substr($_POST['rangefrom'],8,2);
               
$yearto substr($_POST['rangeto'],0,4);
               
$monthto substr($_POST['rangeto'],5,2);
               
$dayto substr($_POST['rangeto'],8,2);
            
//echo "<script type=\"text/javascript\">alert(\"$yearfrom|$monthfrom|$dayfrom  \");</script>";
            
if ( $yearfrom!=$Year || $monthfrom!=$monthno || $yearto!=$Year || $monthto!=$monthno ) {
               echo 
"<script type=\"text/javascript\">alert(\"".$LANG['cal_range_within']."\");</script>";
            }
            else if ( 
$_POST['rangefrom']>$_POST['rangeto']) {
               echo 
"<script type=\"text/javascript\">alert(\"".$LANG['cal_range_start']."\");</script>";
            }
            else {
               for (
$i=intval($dayfrom);$i<=intval($dayto);$i++) {
                  
$absarray[]=$_POST['rangeabs'].sprintf("%02d",$i);
               }
            }
         }
         
         
/**
          * Then get the recurring input
          */
         
if ( $key=="monday" ) {
             
$x intval($weekday1);
             for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x==$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
                if(
$x<=6$x+=1; else $x 1;
             }
         }
         if ( 
$key=="tuesday" ) {
             
$x intval($weekday1);
             for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x==$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
                if(
$x<=6$x+=1; else $x 1;
             }
         }
         if ( 
$key=="wednesday" ) {
             
$x intval($weekday1);
             for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x==$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
                if(
$x<=6$x+=1; else $x 1;
             }
         }
         if ( 
$key=="thursday" ) {
             
$x intval($weekday1);
             for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x==$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
                if(
$x<=6$x+=1; else $x 1;
             }
         }
         if ( 
$key=="friday" ) {
             
$x intval($weekday1);
             for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x==$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
                if(
$x<=6$x+=1; else $x 1;
             }
         }
         if ( 
$key=="saturday" ) {
             
$x intval($weekday1);
             for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x==$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
                if(
$x<=6$x+=1; else $x 1;
             }
         }
         if ( 
$key=="sunday" ) {
             
$x intval($weekday1);
             for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x==$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
                if(
$x<=6$x+=1; else $x 1;
             }
         }
         if ( 
$key=="workdays" ) {
            
$x intval($weekday1);
            for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x>=AND $x<=$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
               if(
$x<=6$x+=1; else $x 1;
            }
         }
         if ( 
$key=="weekend" ) {
            
$x intval($weekday1);
            for (
$i=1$i<=$nofdays$i=$i+1) {
               if ( 
$x>=AND $x<=$absarray[]=$_POST['recurrabs'].sprintf("%02d",$i);
               if(
$x<=6$x+=1; else $x 1;
            }
         }
      }         
      
      
/**
       * Go through each requested absence
       */
      
$declination_email FALSE;
      
$approval_email FALSE
      
$error_decl FALSE
      
$error_decl_group FALSE
      
$error_decl_all FALSE
      
$error_decl_date FALSE
      
$error_decl_period FALSE
      
$error_decl_approval FALSE
      
      foreach(
$absarray as $key)
      {
         
$type substr($key0strlen($key)-2);
         
$ixx intval(substr($keystrlen($key)-22));
         
$accept=true;
         
         
/**
          * If 
          * - DECLINE is on AND
          * - user is not Admin AND
          * - user is not already absent on this day
          * ... we have to check wether this request has to be declined
          */
         
if ( $C->readConfig("declAbsence") AND !$isAdmin AND $T->template[$ixx-1]==$CONF['present'] )
         {
            
$allThresholdReached=false;
            
$groupThresholdReached=false;
            if (
$C->readConfig("declBase")=="group"
            {
               
/**
                * There is a declination threshold for groups. 
                * We have to go through each group of this user and see
                * wether the threshold would be violated by this request.
                */
               
$query  "SELECT groupname FROM `".$UG->table."` WHERE username='".$U->username."'";
               
$result $UG->db->db_query($query);
               
$groups "";
               while (
$row=$UG->db->db_fetch_array($result,MYSQL_NUM) ) 
               {
                  if (
declineThresholdReached($Year,$monthno,$ixx,"group",$row[0])) 
                  {
                     
/**
                      * Only decline if logged in user is not the group manager
                      * of the current group in this loop
                      */
                     
if ( !$UG->isGroupManagerOfGroup($UL->username,$row[0]) )
                     {
                        
$groupThresholdReached=true;
                        
$groups $groups.$row[0].", ";
                        
$accept=false;
                     }
                  }
               } 
               if (
strlen($groups)) $groups substr($groups,0,strlen($groups)-2);
            }
            else {
               if (
declineThresholdReached($Year,$monthno,$ixx,"all")) {
                  
$allThresholdReached=true;
                  
$accept=false;
               } 
            }
         }
         
         
/**
          * If min_present or max_absent is set and reached for the group(s) of this person -> decline
          * Only check if user isn't Admin and user isn't already absent on this day.
          */
         
if ( !$isAdmin AND $T->template[$ixx-1]==$CONF['present'] )
         {
            
$minPresentReached=false;
            
$maxAbsentReached=false;
            
            
$query  "SELECT groupname FROM `".$UG->table."` WHERE username='".$U->username."'";
            
$result $UG->db->db_query($query);
            while (
$row=$UG->db->db_fetch_array($result,MYSQL_NUM) ) 
            {
               
$G->findByName($row[0]);
               if (
$G->checkOptions($CONF['G_MIN_PRESENT'])) 
               {
                  if (
declineThresholdReached($Year,$monthno,$ixx,"min_present",$row[0])) 
                  {
                     
/**
                      * Only decline if logged in user is not the group manager
                      * of the current group in this loop
                      */
                     
if ( !$UG->isGroupManagerOfGroup($UL->username,$row[0]) )
                     {
                        
$minPresentReached=true;
                        
$groups $groups.$row[0].", ";
                        
$accept=false;
                     }
                  }
               }
               if (
$G->checkOptions($CONF['G_MAX_ABSENT'])) 
               {
                  if (
declineThresholdReached($Year,$monthno,$ixx,"max_absent",$row[0])) 
                  {
                     
/**
                      * Only decline if logged in user is not the group manager
                      * of the current group in this loop
                      */
                     
if ( !$UG->isGroupManagerOfGroup($UL->username,$row[0]) )
                     {
                        
$maxAbsentReached=true;
                        
$groups $groups.$row[0].", ";
                        
$accept=false;
                     }
                  }
               }
            }
         }
         
         
/**
          * If changes not allowed before this date -> decline
          */
         
if ( $C->readConfig("declBefore") ) {
            
            
$loopDate intval($Year.$monthno.sprintf("%02d",$ixx));
            
$todayDate=date("Ymd"time());
            
$yesterdayDate=date("Ymd"time()-86400);
            
            if ( 
$C->readConfig("declBeforeToday") ) $blockBeforeDate intval($todayDate);
            else                                     
$blockBeforeDate intval($C->readConfig("declBeforeDate"));
               
            if ( 
$blockBeforeDate 
            {
               
/**
                * A specific BeforeDate has been set
                * Check wether the current day is still set to present.
                * We don't wanna delete absences that have already been entered.
                */
               
if ( $loopDate<$blockBeforeDate && $T->template[$ixx-1]==$CONF['present'] ) 
               {
                  if  ( !
$isAdmin AND !$isDirector AND !$isManager 
                  {
                     
$blockBeforeReached=true;
                     
$accept=false;
                  }
                  else {
                     
$blockBeforeReached=false;
                     
$accept=true;
                  }
               }
            }
         }
         
         
/**
          * If this request lies in a declination period
          */
         
if ( $C->readConfig("declPeriod") ) 
         {
            
$requestDate intval($Year.$monthno.sprintf("%02d",$ixx));
            
$startDate intval($C->readConfig("declPeriodStart"));
            
$endDate intval($C->readConfig("declPeriodEnd"));
            
            
$declPeriodReached false;
            if ( 
$requestDate >= $startDate && $requestDate <= $endDate  && $T->template[$ixx-1]==$CONF['present'] ) 
            {
               
/**
                * This is a new absence request (day is still set to present) and it is in a declination period.
                * Only allow if logged in user is Admin, Director or Manager
                */
               
if  ( $isAdmin || $isDirector 
               {
                  
$declPeriodReached false;
                  
$accept=true;
               } 
               else if ( 
$isManager 
               {
                  
$declPeriodReached true;
                  
$accept=false;
                  
$query  "SELECT groupname FROM `".$UG->table."` WHERE username='".$U->username."'";
                  
$result $UG->db->db_query($query);
                  while (
$row=$UG->db->db_fetch_array($result,MYSQL_NUM) ) {
                     if (
$UG->isGroupManagerOfGroup($UL->username,$row[0])) {
                        
$declPeriodReached false;
                        
$accept=true;
                     }
                  }  
               }
               else 
               {
                  
$declPeriodReached true;
                  
$accept=false;
               }
            }
            
//echo "<script type=\"text/javascript\">alert(\"Debug: ".$requestDate." | ".$todayDate." | ".$startDate." | ".$endDate."\");</script>";
         
}
         
         
/**
          * If this absence type requires approval
          */
         
$approvalNeeded=false;
         
$A->findByName($type);               
         if ( 
$A->checkOptions($CONF['A_APPROVAL']) ) 
         {
            
$approvalNeeded=true;               
            
/**
             * Check wether this user is a regular user and still
             * present on this day. If so, decline.
             */
            
if  ( !$isAdmin AND !$isDirector AND !$isManager AND $T->template[$ixx-1]==$CONF['present'] ) 
            {
               
$accept=false;
            }
            else {
               
$approvalNeeded=false;               
               
$accept=true;
            }
         }
         
         if (
$accept
         {
            
/**
             * The requested absence is accepted. Enter it in the new template.
             */
            
$query  "SELECT cfgsym FROM `".$A->table."` WHERE cfgname='".$type."'";
            
$result $A->db->db_query($query);
            if (
$A->db->db_numrows($result)==1
            {
               
$row $A->db->db_fetch_array($result,MYSQL_NUM);
               
$newtemplate[$ixx-1] = $row[0];
            }
            else 
            {
               
$newtemplate[$ixx-1] = $CONF['present'];
            }
         }
         else 
         {
            
/**
             * The request was not accepted:
             * - build error message and display it to the user
             * - build notification message and send it to the appropriate receivers
             */
            
$query  "SELECT dspname FROM `".$A->table."` WHERE cfgname='".$type."'";
            
$result $A->db->db_query($query);
            
$row $A->db->db_fetch_array($result,MYSQL_NUM);
            
            
$error_decl TRUE;
            
            if (
$groupThresholdReached || $minPresentReached || $maxAbsentReached
            {
               
$error_decl_group TRUE;
               
               
//
               // Log this event
               //
               
$LOG->log("logUser",$L->checkLogin(),"Absence request declined (group threshold): ".$U->username." ".$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)." ".$row[0]);
               
               
//
               // Build the notification mail body
               //
               
if (!$declination_email)
               {
                  
$notification =$LANG['notification_greeting'];
                  
$subject $LANG['notification_subject_approval'];
                  
$notification.=$LANG['notification_decl_msg'];
                  
$notification.=$LANG['notification_decl_user'].$U->firstname." ".$U->lastname."\n\n";
                  
$declination_email TRUE;
               }
               
$notification.=$LANG['notification_decl_date'].$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)."\n";
               
$notification.=$LANG['notification_decl_absence'].$row[0]."\n";
               
$notification.=$LANG['notification_decl_reason'].$_POST['txtReason']."\n\n\n";
               
               if (
$groupThresholdReached) {
                  
$notification.=$LANG['notification_decl_threshold'].$C->readConfig("declThreshold")." ".$LANG['notification_decl_ofgroup']." ".$groups;
               }
               else if (
$minPresentReached) {
                  
$notification.=$LANG['notification_decl_minpresent'].$G->min_present.$LANG['notification_decl_minpresent1'].$G->groupname.$LANG['notification_decl_minpresent2'];
               }
               else if (
$maxAbsentReached) {
                  
$notification.=$LANG['notification_decl_maxabsent'].$G->min_present.$LANG['notification_decl_maxabsent1'].$G->groupname.$LANG['notification_decl_maxabsent2'];
               }
               
            }
            
            else if (
$allThresholdReached
            {
               
$error_decl_all TRUE;
               
               
//
               // Log this event
               //
               
$LOG->log("logUser",$L->checkLogin(),"Absence request declined (all threshold): ".$U->username." ".$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)." ".$row[0]);
               
               
//
               // Build notification email
               //
               
if (!$declination_email)
               {
                  
$notification =$LANG['notification_greeting'];
                  
$subject $LANG['notification_subject_approval'];
                  
$notification.=$LANG['notification_decl_msg'];
                  
$notification.=$LANG['notification_decl_user'].$U->firstname." ".$U->lastname."\n\n";
                  
$declination_email TRUE;
               }
               
$notification.=$LANG['notification_decl_date'].$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)."\n";
               
$notification.=$LANG['notification_decl_absence'].$row[0]."\n";
               
$notification.=$LANG['notification_decl_reason'].$_POST['txtReason']."\n";
               
$notification.=$LANG['notification_decl_threshold'].$C->readConfig("declThreshold")." ".$LANG['notification_decl_ofall']."\n\n\n";
               
            }
            
            else if (
$blockBeforeReached
            {
               
$error_decl_date TRUE;
               
               
//
               // Log this event
               //
               
$LOG->log("logUser",$L->checkLogin(),"Absence request declined (block before): ".$U->username." ".$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)." ".$row[0]);
            }
            else if (
$declPeriodReached
            {
               
$error_decl_period TRUE;
               
               
//
               // Log this event
               //
               
$LOG->log("logUser",$L->checkLogin(),"Absence request declined (block period): ".$U->username." ".$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)." ".$row[0]);
            }
            else if (
$approvalNeeded
            {
               
$error_decl_approval TRUE;
               
               
//
               // Log this event
               //
               
$LOG->log("logUser",$L->checkLogin(),"Absence request declined (approval): ".$U->username." ".$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)." ".$row[0]);
               
               
//
               // Build approval email
               //
               
if (!$approval_email)
               {
                  
$anotification =$LANG['notification_greeting'];
                  
$asubject $LANG['notification_subject_approval'];
                  
$anotification.=$LANG['notification_decl_msg_2'];
                  
$anotification.=$LANG['notification_decl_user'].$U->firstname." ".$U->lastname."\n\n";
                  
$approval_email TRUE;
               }
               
$anotification.=$LANG['notification_decl_date'].$Year.sprintf("%02d",$monthno).sprintf("%02d",$ixx)."\n";
               
$anotification.=$LANG['notification_decl_absence'].$row[0]."\n";
               
$anotification.=$LANG['notification_decl_reason'].$_POST['txtReason']."\n\n\n";
            }
         }
      } 
// End foreach $_POSTkey

      //
      // Show error message to user
      //
      
if ($error_decl
      {
         
$errmsg=$LANG['err_decline_title'];
         
$errmsg.="\\n\\n";

         if (
$error_decl_group)
         { 
            
$errmsg.=$LANG['err_decline_threshold'];
            
$errmsg.=$LANG['err_decline_group_1'];
            
$errmsg.=$C->readConfig("declThreshold");
            
$errmsg.=$LANG['err_decline_group_2'];
            
$errmsg.="\\n";
            
$errmsg.=$LANG['err_decline_group_3'];
            
$errmsg.=$groups;
         }

         if (
$error_decl_all)
         { 
            
$errmsg.=$LANG['err_decline_threshold'];
            
$errmsg.=$LANG['err_decline_all_1'];
            
$errmsg.=$C->readConfig("declThreshold");
            
$errmsg.=$LANG['err_decline_all_2'];
         }

         if (
$error_decl_date)
         { 
            
$errmsg.=$LANG['err_decline_date_1'];
            
$errmsg.=$blockBeforeDate;
            
$errmsg.=$LANG['err_decline_date_2'];
         }

         if (
$error_decl_period)
         { 
            
$errmsg.=$LANG['err_decline_period_1'];
            
$errmsg.=$startDate;
            
$errmsg.=$LANG['err_decline_period_2'];
            
$errmsg.=$endDate;
         }
         
         if (
$error_decl_approval)
         {
            
$errmsg.=$LANG['err_decline_approval'];
         }
         
         
$errmsg.="\\n\\n";
         
$errmsg.=$LANG['err_decline_email'];
         
$errmsg.="\\n\\n";
         echo 
"<script type=\"text/javascript\">alert(\"".$errmsg."\");</script>";
      }
       
      
//
      // Send the declination email for this request if emailNotifications are on
      //
      
if ($declination_email AND $C->readConfig("emailNotifications")) 
      { 
         
$notification.=$LANG['notification_decl_sign'];
         
$headers "From: " $C->readConfig("mailFrom") . "\r\n" "Reply-To: " $C->readConfig("mailReply") . "\r\n";
         
         
//
         // Send email to requesting user if configured so in Declination Management
         //
         
if ( $C->readConfig("declNotifyUser") ) 
         {
            
$to $U->email;
            
mail($tostripslashes($subject), stripslashes($notification), $headers);
         }
         
         
//
         // Send email to group manager of requesting user if configured so in Declination Management
         //
         
if ( $C->readConfig("declNotifyManager") ) 
         {
            
$grps=explode(",",$groups);
            foreach(
$grps as $grp
            {
               
$query  "SELECT DISTINCT ".$U->table.".email FROM ".$U->table.",".$UG->table." " .
                         
"WHERE ".$U->table.".username=".$UG->table.".username " .
                         
"AND ".$UG->table.".groupname='".trim($grp)."' " .
                         
"AND ".$UG->table.".type='manager'";
               
$result $UG->db->db_query($query);
               while (
$row=$UG->db->db_fetch_array($result,MYSQL_NUM) ) 
               {
                  
$to $row[0];
                  
mail($tostripslashes($subject), stripslashes($notification), $headers);
               }
            }
         }
         
         
//
         // Send email to director if configured so in Declination Management
         //
         
if ( $C->readConfig("declNotifyDirector") ) 
         {
            
$query  "SELECT username FROM `".$U->table."`";
            
$result $U->db->db_query($query);
            while (
$row=$U->db->db_fetch_array($result,MYSQL_NUM) ) 
            {
               
$U->findByName($row[0]);
               if (
$U->checkUserType($CONF['UTDIRECTOR'])) 
               {
                  
$to $U->email;
                  
mail($tostripslashes($subject), stripslashes($notification), $headers);
               }
            }
         }
         
         
//
         // Send email to admin if configured so in Declination Management
         //
         
if ( $C->readConfig("declNotifyAdmin") ) 
         {
            
$query  "SELECT username FROM `".$U->table."`";
            
$result $U->db->db_query($query);
            while (
$row=$U->db->db_fetch_array($result,MYSQL_NUM) ) 
            {
               
$U->findByName($row[0]);
               if (
$U->checkUserType($CONF['UTADMIN'])) 
               {
                  
$to $U->email;
                  
mail($tostripslashes($subject), stripslashes($notification), $headers);
               }
            }
         }
      }

      
//
      // Send the approval email for this request if emailNotifications are on
      //
      
if ($approval_email AND $C->readConfig("emailNotifications")) 
      { 
         
$anotification.=$LANG['notification_decl_sign'];
               
         
$aheaders  "From: " $C->readConfig("mailFrom") . "\r\n";
         
$aheaders .= "Cc: " $U->email "\r\n";
         
$aheaders .= "Reply-To: " $C->readConfig("mailReply") . "\r\n";
         
         
//
         // Go through all groups of this user
         // Then send a mail to the group manager of each of his groups
         //
         
$query1  "SELECT groupname FROM `".$UG->table."` WHERE username='".$U->username."'";
         
$result1 $UG->db->db_query($query1);
         while (
$row1=$UG->db->db_fetch_array($result1,MYSQL_NUM) ) 
         {
            
$query2  "SELECT DISTINCT ".$U->table.".email FROM ".$U->table.",".$UG->table." " .
                      
"WHERE ".$U->table.".username=".$UG->table.".username " .
                      
"AND ".$UG->table.".groupname='".$row1[0]."' " .
                      
"AND ".$UG->table.".type='manager'";
            
$result2 $UG->db->db_query($query2);
            while (
$row2=$UG->db->db_fetch_array($result2,MYSQL_NUM) ) 
            {
               
$to $row2[0];
               
mail($tostripslashes($asubject), stripslashes($anotification), $aheaders);
            }
         }
      }
      
      
      if (
$T->template!=$newtemplate) { 
         
         if ( 
$U->checkUserType($CONF['UTTEMPLATE']) ) 
         {
            
/**
             * This is a template user. We must not overwrite his old template yet.
             * We need to compare it with the new template to find the differences.
             * Then we have to go through the templates of all other users in the same
             * group and adjust accordingly.
             * 
             */
            
$query  "SELECT groupname FROM `".$UG->table."` WHERE username='".$U->username."'";
            
$result $UG->db->db_query($query);
            while (
$row=$UG->db->db_fetch_array($result,MYSQL_ASSOC) ) 
            {
               
/**
                * Go through all users of the same group
                */   
               
$groupfilter $row['groupname'];
               
$query2 "SELECT DISTINCT ".$CONF['db_table_users'].".*" .
                        
" FROM ".$CONF['db_table_users'].",".$CONF['db_table_user_group'].",".$CONF['db_table_groups'].
                        
" WHERE (".$CONF['db_table_users'].".username!='admin'" .
                        
" AND ".$CONF['db_table_users'].".username=".$CONF['db_table_user_group'].".username".
                        
" AND ".$CONF['db_table_users'].".username!='".$U->username."'".
                        
" AND ".$CONF['db_table_user_group'].".groupname = '".$groupfilter."'" .
                        
" AND ".$CONF['db_table_groups'].".groupname=".$CONF['db_table_user_group'].".groupname".
                        
" AND (".$CONF['db_table_groups'].".options&1)=0 )";
               
$result2 $UT->db->db_query($query2);
               while ( 
$row2 $UT->db->db_fetch_array($result2,MYSQL_ASSOC) )
               {
                  
$UT->findByName($row2['username']);
                  
/**
                   * Find the template for the current loop user, otherwise create a fresh one
                   */   
                  
if (!$rc=$TT->findTemplate($UT->username,$Year,$monthno)) 
                  {
                     
$freshtemplate "";
                     for (
$i=0$i<intval($nofdays); $i++ ) 
                     {
                        
$freshtemplate .= $CONF['present'];
                     }
                     
$TT->template $freshtemplate;
                  }
                  
/**
                   * Loop through each day and compare the templates. Set new value from template
                   * based on rules. 
                   * $T->template = old template of the template user
                   * $newtemplate = new template of the template user
                   * $TT->template = template of the current user in the loop
                   * 
                   * Template User Old | Template User New | Current User | Action to Regular User
                   * -----------------------------------------------------------------------------
                   * absence x         | present           | absence x    | set present
                   * present           | absence x         | present      | set absence x
                   * absence x         | absence x         | present      | set absence x
                   * absence x         | absence y         | present      | set absence y
                   * absence x         | absence y         | absence x    | set absence y
                   * 
                   */
                  
for ($it=0$it<strlen($newtemplate); $it++) 
                  {
                     if ( 
$newtemplate[$it]==$CONF['present'] && $T->template[$it]==$TT->template[$it] ) 
                     {
                        
$TT->template[$it] = $newtemplate[$it];
                     }   
                     else if ( 
$newtemplate[$it]!=$CONF['present'] && $TT->template[$it]==$CONF['present'] ) 
                     {
                        
$TT->template[$it] = $newtemplate[$it];   
                     }
                     else if ( 
$newtemplate[$it]!=$CONF['present'] && $T->template[$it]!=$CONF['present'] &&
                               
$newtemplate[$it]!=$T->template[$it] && $TT->template[$it]==$T->template[$it] ) 
                     {
                        
$TT->template[$it] = $newtemplate[$it];   
                     }
                  }
                  
/**
                   * Now update the current user's template
                   */
                  
$TT->update($UT->username,$Year,$monthno);
               }
            
            }
         }
         
         
         
/**
          * Template was changed. Update it.
          * Send notification e-Mails.
          * Then log the event.
          */
         
$T->template=$newtemplate;
         
$T->update($U->username,$Year,$monthno);
         
         
/**
          * Since the database symbols of the absence types may not be the same
          * as the display symbols (e.g. due to an absence type update) we need 
          * to replace them in the template string that is sent out per mail.
          */
         
$mailtemplate="";
         for (
$i=0$i<strlen($T->template); $i++) 
         {
            if (
$T->template[$i]<>$CONF['present']) 
            {
               
$A->findBySymbol($T->template[$i]);
               
$mailtemplate.=$A->dspsym;
            }
            else 
            {
               
$mailtemplate.=$CONF['present'];
            }
         }
         
$query  "SELECT groupname FROM `".$UG->table."` WHERE username='".$U->username."'";
         
$result $UG->db->db_query($query);
         while (
$row=$UG->db->db_fetch_array($result,MYSQL_NUM) ) 
         {
            
sendNotification("usercalchange",$U->firstname." ".$U->lastname$row[0],$T->year.$T->month." ".$mailtemplate);
         }
         
/**
          * Log this event
          */
         
$LOG->log("logUser",$L->checkLogin(),"User template changed: ".$U->username." ".$T->year.$T->month." ".$mailtemplate);
      }
      
   }
   else if (isset(
$_POST['btn_clear'])) 
   {
      
/**
       * First create default template
       */
      
$T->template "";
      for (
$i=0$i<intval($nofdays); $i++ ) 
      {
         
$T->template .= $CONF['present'];
      }
      
/**
       * Update his template for this month
       */
      
$T->update($U->username,$Year,$monthno);
      
$query  "SELECT groupname FROM `".$UG->table."` WHERE username='".$U->username."'";
      
$result $UG->db->db_query($query);
      while (
$row=$UG->db->db_fetch_array($result,MYSQL_NUM) )
      {
         
sendNotification("usercalchange",$U->firstname." ".$U->lastname$row[0],$T->year.$T->month." ".$T->template);
      }
      
/**
       * Log this event
       */
      
$LOG->log("logUser",$L->checkLogin(),"User template cleared: ".$U->username." ".$T->year.$T->month." ".$T->template);
   }
}
 
$currlang $CONF['options']['lang'];
require(
"includes/header.html.inc.php");
$CONF['options']['lang']=$currlang;

if (
$error
{
   include (
"error.php");
}
else


?> 
<body>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
   <form  name="monthform" method="POST" action="<?=($_SERVER['PHP_SELF']."?Year=".$Year."&amp;Month=".$Month."&amp;Member=".$Member."&amp;lang=".$CONF['options']['lang'])?>">
   <table class="dlg">
      <tr>
         <td class="dlg-header">
            <?php printDialogTop($LANG['member_edit']." ".$U->firstname." ".$U->lastname." (".$LANG['month_region'].": ".$region.")","user_calendar.html","ico_calendar.png"); ?>
         </td>
      </tr>
      <tr>
         <td class="dlg-body">
         
         <?php
         
/**
          * Month frame: Day of month 
          */
         
echo "<br />
         <table class=\"month\" cellspacing=\"0\">
            <tr>
               <td class=\"month\">"
.$LANG['monthnames'][intval($monthno)]."&nbsp;".trim($Year)."</td>
               <td class=\"month-button\">&nbsp;</td>"
;
         for (
$i=1$i<=$nofdays$i=$i+1) {
            if ( 
$H->findBySymbol($M->template[$i-1]) ) {
               if ( 
$H->cfgname=='busi' ) {
                  
/**
                   * A business day has a special bgcolor in this dayofmonth row
                   */
                  
echo "<td class=\"daynum\">".$i."</td>";
               }else{
                  echo 
"<td class=\"daynum-".$H->cfgname."\">".$i."</td>";
               }
            }else{
               echo 
"<td class=\"daynum\">".$i."</td>";
            }
         }
            
         
/**
          * Month frame: Weekday
          */
         
$x intval($weekday1);
         
?>
      </tr>
      <tr>
         <td class="title" style="font-size: 8pt;">
            <input name="btn_bwd" type="submit" class="button" value="&lt;&lt;" onmouseover="this.className='button-over';" onmouseout="this.className='button';">
            <input name="btn_fwd" type="submit" class="button" value="&gt;&gt;" onmouseover="this.className='button-over';" onmouseout="this.className='button';">
            <input type="hidden" name="Month" value="<?=$Month?>">
            <input type="hidden" name="Year" value="<?=$Year?>">
            <input type="hidden" name="Member" value="<?=$Member?>">
         </td>
         <td class="title-button">&nbsp;</td>
         <?php
         
for ($i=1$i<=$nofdays$i=$i+1) {
            if ( 
$H->findBySymbol($M->template[$i-1]) ) {
               if ( 
$H->cfgname=='busi' ) {
                  
/*
                   * A business day has a special bgcolor in this dayofweek row
                   */
                  
echo "<td class=\"weekday\">".$weekdays[$x]."</td>";
               }else{
                  echo 
"<td class=\"weekday-".$H->cfgname."\">".$weekdays[$x]."</td>";
               }
            }else{
               echo 
"<td class=\"weekday\">".$weekdays[$x]."</td>";
            }
            if(
$x<=6$x+=1; else $x 1;
         }
         echo 
"</tr>";
                
         
/**
          * Month frame: Daynote
          */
         
if ($user $L->checkLogin()) $UL->findByName($user);
         if ( !
intval($C->readConfig("hideDaynotes")) || 
              (
$UL->checkUserType($CONF['UTADMIN']) || $UL->checkUserType($CONF['UTDIRECTOR']) || $UL->checkUserType($CONF['UTMANAGER']) )
            ) {
            
$x intval($weekday1);
            echo 
"
            <tr>
               <td class=\"name\">"
.$LANG['month_daynote']."</td>
               <td class=\"name-button\">&nbsp;</td>"
;
            for (
$i=1$i<=$nofdays$i=$i+1) {
               if (
$i<10$dd="0".strval($i); else $dd=strval($i);
               if ( 
$H->findBySymbol($M->template[$i-1]) ) {
                  if ( 
$H->cfgname=='busi' ) {
                     if ( 
$N->findByDay($Year.$monthno.$dd,$U->username) ) $style="weekday-note"; else $style="weekday";
                  }else{
                     if ( 
$N->findByDay($Year.$monthno.$dd,$U->username) ) $style="weekday-".$H->cfgname."-note"; else $style="weekday-".$H->cfgname;
                  }
                }else{
                   if ( 
$N->findByDay($Year.$monthno.$dd,$U->username) ) $style="weekday-note"; else $style="weekday";
                }
               echo 
"
                   <td class=\""
.$style."\">
                       <a href=\"javascript:this.blur();openPopup('daynote.php?lang="
.$CONF['options']['lang']."&amp;date=".$Year.$monthno.$dd."&amp;daynotefor=".$U->username."&amp;region=default&amp;datestring=".$dd."%20".$LANG['monthnames'][intval($monthno)]."%20".$Year."','daynote','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,titlebar=0,resizable=0,dependent=1,width=600,height=340');\">
                           <img src=\"themes/"
.$theme."/img/ico_daynote.png\" alt=\"\" title=\"".$LANG['month_daynote_tooltip']."\" border=\"0\">
                       </a>
                   </td>\n"
;
               if(
$x<=6$x+=1; else $x 1;
            }
            echo 
"
            </tr>"
;
         }
         
         
/**
          * Absence type loop
          */
         
$approvalNeeded=false;               
         
$query  "SELECT * FROM `".$A->table."` ORDER BY `cfgsym`;";
         
$result $A->db->db_query($query);
         while ( 
$row $A->db->db_fetch_array($result,MYSQL_ASSOC) ) {
            
/**
             * Make sure this absence type is allowed for this group
             */
            
$A->findBySymbol($row['cfgsym']);               
            
$showthisabsence=false;
            
$showdisabled=false;
            
$Gquery  "SELECT * FROM `".$G->table."` ORDER BY `groupname`;";
            
$Gresult $G->db->db_query($Gquery);
            while ( 
$Grow=$G->db->db_fetch_array($Gresult,MYSQL_ASSOC) ) {
               if (
$UG->isMemberOfGroup($U->username,$Grow['groupname']) &&
                   
$AG->isAssigned($row['cfgsym'],$Grow['groupname'])
                  ) {
                  
$showthisabsence=true;
                  if (
$A->checkOptions($CONF['A_MGR_ONLY'])) {
                     if ( (
$UL->checkUserType($CONF['UTADMIN']) || $UL->checkUserType($CONF['UTDIRECTOR'])) || ($UL->checkUserType($CONF['UTMANAGER']) && $UG->isMemberOfGroup($UL->username,$Grow['groupname'])) ) {
                        
$showdisabled=false;
                     }
                     else {
                        
$showdisabled=true;
                     }
                  }
                  if ( 
$A->checkOptions($CONF['A_APPROVAL']) ) $approvalNeeded=true;               
               }
            }
            
            
/**
             * Show the absence line
             */
            
if ($showthisabsence) {
               if (
$row['cfgname'] != "present" ) {
                  echo 
"
                  <tr>
                     <td class=\"name\">"
.str_replace(" ","&nbsp;",$row['dspname'])."</td>
                     <td class=\"name-button\">&nbsp;</td>"
;
                  
$count=0;
                  
/**
                   * Show a line for this absence type covering each day of the month
                   */
                  
for($idx=0$idx<strlen($M->template); $idx++) {
                     if ( (
$count+1)<10 $strcount "0".strval($count+1); else $strcount strval($count+1);
                     if ( 
$T->template[$idx] == $row['cfgsym'] ) {
                        echo 
"
                        <td class=\""
.$row['cfgname']."\">
                           <input name=\""
.$row['cfgname'].$strcount."\" type=\"checkbox\" id=\"".$row['cfgname'].$strcount."\" value=\"".$row['cfgname'].$strcount."\" CHECKED ".($showdisabled?'DISABLED':'').">";
                     }else{
                        if ( 
$H->findBySymbol($M->template[$count]) ) {
                           echo 
"<td class=\"day-".$H->cfgname."\">";
                        }else{
                           echo 
"<td class=\"day\">";
                        }
                        echo 
"<input name=\"".$row['cfgname'].$strcount."\" type=\"checkbox\" id=\"".$row['cfgname'].$strcount."\" value=\"".$row['cfgname'].$strcount."\" ".($showdisabled?'DISABLED':'').">";
                     }
                     
$count+=1;
                     echo 
"</td>";
                  }
                  echo 
"</tr>\n";
               }
            }
         }
         
?>
            </table>
            <table width="100%">
               <tr>
                  <td width="50%" style="vertical-align: top;">
                     <?php printDialogFrameTop($LANG['cal_range_title'],"0"); ?>
                     <table>
                        <tr>
                           <td><?=$LANG['cal_range_type']?></td>
                           <td><?=$LANG['cal_range_from']?></td>
                           <td><?=$LANG['cal_range_to']?></td>
                           <td>&nbsp;</td>
                        </tr>
                        <tr>
                           <td style="padding-right: 4px;">
                              <select name="rangeabs" id="rangeabs" class="select">
                              <?php
                              $result 
$A->db->db_query($query);
                              while ( 
$row $A->db->db_fetch_array($result,MYSQL_ASSOC) ){
                                 
/**
                                  * Make sure this users calendar only contains those absence types
                                  * that his group(s) is(are) entitled for
                                  */
                                 
$showthisabsence=false;
                                 
$Gquery  "SELECT * FROM `".$G->table."` ORDER BY `groupname`;";
                                 
$Gresult $G->db->db_query($Gquery);
                                 while ( 
$Grow=$G->db->db_fetch_array($Gresult,MYSQL_ASSOC) ) {
                                    if (
$UG->isMemberOfGroup($U->username,$Grow['groupname']) &&
                                        
$AG->isAssigned($row['cfgsym'],$Grow['groupname'])
                                       ) {
                                       
$showthisabsence=true;   
                                       
$A->findByName($row['cfgsym']);               
                                       if ( 
$A->checkOptions($CONF['A_APPROVAL']) ) $approvalNeeded=true;               
                                    }
                                 }
                                 if (
$showthisabsence && $row['cfgname']!="present") {
                                    echo 
"            <option class=\"option\" value=\"".$row['cfgname']."\">".$row['dspname']."</option>\n";
                                 }
                              }
                              
?>
                              </select>
                           </td>
                           <td style="padding-right: 4px;">
                              <input name="rangefrom" id="rangefrom" size="10" maxlength="10" type="text" class="text" value="">
                              <img src="themes/<?=$theme?>/img/ico_calendar.png" id="datepicker0" title="<?=$LANG['date_picker']?>" alt="<?=$LANG['date_picker']?>" align="top" onmouseover="return overlib('<?=$LANG['date_picker_tt']?>',<?=$CONF['ovl_tt_settings']?>);" onmouseout="return nd();">
                              <script type="text/javascript">
                                 <!--
                                 Calendar.setup({
                                    inputField  : "rangefrom",      // id of the input field
                                    ifFormat    : "%Y-%m-%d",       // format of the input field
                                    date        : "<?php echo $Year."-".$monthno."-01"?>",
                                    button      : "datepicker0",   // trigger for the calendar (button ID)
                                    align       : "Tr",           // alignment (defaults to "Bl")
                                    firstDay    : 1               // First day of week: 1=Monday
                                 });
                                 -->
                              </script>
                           </td>
                           <td style="padding-right: 4px;">
                              <input name="rangeto" id="rangeto" size="10" maxlength="10" type="text" class="text" value="">
                              <img src="themes/<?=$theme?>/img/ico_calendar.png" id="datepicker1" title="<?=$LANG['date_picker']?>" alt="<?=$LANG['date_picker']?>" align="top" onmouseover="return overlib('<?=$LANG['date_picker_tt']?>',<?=$CONF['ovl_tt_settings']?>);" onmouseout="return nd();">
                              <script type="text/javascript">
                                 <!--
                                 Calendar.setup({
                                    inputField  : "rangeto",      // id of the input field
                                    ifFormat    : "%Y-%m-%d",       // format of the input field
                                    date        : "<?php echo $Year."-".$monthno."-".$nofdays?>",
                                    button      : "datepicker1",   // trigger for the calendar (button ID)
                                    align       : "Tr",           // alignment (defaults to "Bl")
                                    firstDay    : 1               // First day of week: 1=Monday
                                 });
                                  -->
                              </script>
                           </td>
                           <td>&nbsp;</td>
                        </tr>
                        <tr>
                           <td colspan="4"><?=$LANG['cal_range_hint']?><br>&nbsp;</td>
                        </tr>
                     </table>
                     <?php printDialogFrameBottom(); ?>
                  </td>
                  <td width="50%" style="vertical-align: top;">
                     <?php printDialogFrameTop($LANG['cal_recurring_title'],"0"); ?>
                        <table>
                           <tr>
                              <td><input name="monday" type="checkbox" id="monday" value="monday"></td>
                              <td><?=$LANG['weekdays_long'][1]?></td>
                              <td><input name="thursday" type="checkbox" id="thursday" value="thursday"></td>
                              <td><?=$LANG['weekdays_long'][4]?></td>
                              <td><input name="sunday" type="checkbox" id="sunday" value="sunday"></td>
                              <td><?=$LANG['weekdays_long'][7]?></td>
                              <td style="padding-left: 10px; vertical-align: top;"><?=$LANG['cal_range_type']?></td>
                           </tr>
                           <tr>
                              <td><input name="tuesday" type="checkbox" id="tuesday" value="tuesday"></td>
                              <td><?=$LANG['weekdays_long'][2]?></td>
                              <td><input name="friday" type="checkbox" id="friday" value="friday"></td>
                              <td><?=$LANG['weekdays_long'][5]?></td>
                              <td><input name="workdays" type="checkbox" id="workdays" value="workdays"></td>
                              <td><?=$LANG['cal_recurring_workdays']?></td>
                              <td rowspan="2" style="padding-left: 10px; vertical-align: top;">
                                 <select name="recurrabs" id="recurrabs" class="select">
                                 <?php
                                 $result 
$A->db->db_query($query);
                                 while ( 
$row $A->db->db_fetch_array($result,MYSQL_ASSOC) ){
                                    
/*
                                     * Make sure this users calendar only contains those absence types
                                     * that his group(s) is(are) entitled for
                                     */
                                    
$showthisabsence=false;
                                    
$Gquery  "SELECT * FROM `".$G->table."` ORDER BY `groupname`;";
                                    
$Gresult $G->db->db_query($Gquery);
                                    while ( 
$Grow=$G->db->db_fetch_array($Gresult,MYSQL_ASSOC) ) {
                                       if (
$UG->isMemberOfGroup($U->username,$Grow['groupname']) &&
                                           
$AG->isAssigned($row['cfgsym'],$Grow['groupname'])
                                          ) {
                                          
$showthisabsence=true;   
                                          
$A->findByName($row['cfgsym']);               
                                          if ( 
$A->checkOptions($CONF['A_APPROVAL']) ) $approvalNeeded=true;               
                                       }
                                    }
                                    if (
$showthisabsence && $row['cfgname']!="present") {
                                       echo 
"            <option class=\"option\" value=\"".$row['cfgname']."\">".$row['dspname']."</option>\n";
                                    }
                                 }
                                 
?>
                                 </select>
                              </td>
                           </tr>
                           <tr>
                              <td><input name="wednesday" type="checkbox" id="wednesday" value="wednesday"></td>
                              <td><?=$LANG['weekdays_long'][3]?></td>
                              <td><input name="saturday" type="checkbox" id="saturday" value="saturday"></td>
                              <td><?=$LANG['weekdays_long'][6]?></td>
                              <td><input name="weekend" type="checkbox" id="weekend" value="weekend"></td>
                              <td><?=$LANG['cal_recurring_weekend']?></td>
                           </tr>
                        </table>
                     <?php printDialogFrameBottom(); ?>
                  </td>
               </tr>
               <tr>
                  <td style="vertical-align: top; width: 100%;" colspan="2">
                     <?php printDialogFrameTop($LANG['cal_reason_title'],"0"); ?>
                     <input name="txtReason" id="txtReason" type="text" size="130" maxlength="130" value="<?=$LANG['cal_reason_dummy']?>">
                     <?php printDialogFrameBottom(); ?>
                  </td>
               </tr>
            </table>
         </td>
      </tr>
      <tr>
         <td class="dlg-menu">
            <input name="btn_clear" type="submit" class="button" value="<?=$LANG['btn_clear']?>" onmouseover="this.className='button-over';" onmouseout="this.className='button';" onclick="return confirmSubmit('<?=$LANG['cal_clear_confirm']?>')">
            <input name="btn_apply" type="submit" class="button" value="<?=$LANG['btn_apply']?>" onmouseover="this.className='button-over';" onmouseout="this.className='button';">
            <input name="btn_help" type="button" class="button" onclick="javascript:this.blur(); openPopup('help/<?=$CONF['options']['helplang']?>/html/index.html?user_calendar.html','help','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,titlebar=0,resizable=0,dependent=1,width=750,height=500');" value="<?=$LANG['btn_help']?>" onmouseover="this.className='button-over';" onmouseout="this.className='button';">
            <input name="btn_close" type="button" class="button" onclick="javascript:window.close();" value="<?=$LANG['btn_close']?>" onmouseover="this.className='button-over';" onmouseout="this.className='button';">
            <input name="btn_done"  type="button" class="button" onclick="javascript:closeme();" value="<?=$LANG['btn_done']?>" onmouseover="this.className='button-over';" onmouseout="this.className='button';">
         </td>
      </tr>
   </table>
   </form>

<?php
   
require( "includes/footer.html.inc.php" );
}
?>