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
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
|
<?php /** * All of WebCalendar's functions * * @author Craig Knudsen <cknudsen@cknudsen.com> * @copyright Craig Knudsen, <cknudsen@cknudsen.com>, http://www.k5n.us/cknudsen * @license http://www.gnu.org/licenses/gpl.html GNU GPL * @package WebCalendar */
if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER ) && ! empty ( $_SERVER['PHP_SELF'] ) ) { $PHP_SELF = $_SERVER['PHP_SELF']; } if ( ! empty ( $PHP_SELF ) && preg_match ( "/\/includes\//", $PHP_SELF ) ) { die ( "You can't access this file directly!" ); }
/**#@+ * Used for activity log * @global string */ $LOG_CREATE = "C"; $LOG_APPROVE = "A"; $LOG_REJECT = "X"; $LOG_UPDATE = "U"; $LOG_DELETE = "D"; $LOG_NOTIFICATION = "N"; $LOG_REMINDER = "R"; /**#@-*/
/** * Number of seconds in a day * * @global int $ONE_DAY */ $ONE_DAY = 86400;
/** * Array containing the number of days in each month in a non-leap year * * @global array $days_per_month */ $days_per_month = array ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
/** * Array containing the number of days in each month in a leap year * * @global array $ldays_per_month */ $ldays_per_month = array ( 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
/** * Array of global variables which are not allowed to by set via HTTP GET/POST * * This is a security precaution to prevent users from overriding any global * variables * * @global array $noSet */ $noSet = array ( "is_admin" => 1, "db_type" => 1, "db_host" => 1, "db_login" => 1, "db_password" => 1, "db_persistent" => 1, "PROGRAM_NAME" => 1, "PROGRAM_URL" => 1, "readonly" => 1, "single_user" => 1, "single_user_login" => 1, "use_http_auth" => 1, "user_inc" => 1, "includedir" => 1, "NONUSER_PREFIX" => 1, "languages" => 1, "browser_languages" => 1, "pub_acc_enabled" => 1, "user_can_update_password" => 1, "admin_can_add_user" => 1, "admin_can_delete_user" => 1, );
// This code is a temporary hack to make the application work when // register_globals is set to Off in php.ini (the default setting in // PHP 4.2.0 and after). if ( empty ( $HTTP_GET_VARS ) ) $HTTP_GET_VARS = $_GET; if ( ! empty ( $HTTP_GET_VARS ) ) { while (list($key, $val) = @each($HTTP_GET_VARS)) { // don't allow anything to have <script> in it... if ( ! is_array ( $val ) ) { if ( preg_match ( "/<\s*script/i", $val ) ) { echo "Security violation!"; exit; } } if ( $key == "login" ) { if ( strstr ( $PHP_SELF, "login.php" ) ) { //$GLOBALS[$key] = $val; $GLOBALS[$key] = $val; } } else { if ( empty ( $noSet[$key] ) ) { $GLOBALS[$key] = $val; //echo "XXX $key<br />\n"; } } //echo "GET var '$key' = '$val' <br />\n"; } reset ( $HTTP_GET_VARS ); }
if ( empty ( $HTTP_POST_VARS ) ) $HTTP_POST_VARS = $_POST; if ( ! empty ( $HTTP_POST_VARS ) ) { while (list($key, $val) = @each($HTTP_POST_VARS)) { // don't allow anything to have <script> in it... except 'template' if ( ! is_array ( $val ) && $key != 'template' ) { if ( preg_match ( "/<\s*script/i", $val ) ) { echo "Security violation!"; exit; } } if ( empty ( $noSet[$key] ) ) { $GLOBALS[$key] = $val; } } reset ( $HTTP_POST_VARS ); } //while (list($key, $val) = @each($HTTP_POST_FILES)) { // $GLOBALS[$key] = $val; //} //while (list($key, $val) = @each($HTTP_SESSION_VARS)) { // $GLOBALS[$key] = $val; //} if ( empty ( $HTTP_COOKIE_VARS ) ) $HTTP_COOKIE_VARS = $_COOKIE; if ( ! empty ( $HTTP_COOKIE_VARS ) ) { while (list($key, $val) = @each($HTTP_COOKIE_VARS)) { if ( empty ( $noSet[$key] ) && substr($key,0,12) == "webcalendar_" ) { $GLOBALS[$key] = $val; } //echo "COOKIE var '$key' = '$val' <br />\n"; } reset ( $HTTP_COOKIE_VARS ); }
// Don't allow a user to put "login=XXX" in the URL if they are not // coming from the login.php page. if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER['PHP_SELF'] ) ) $PHP_SELF = $_SERVER['PHP_SELF']; // backward compatibility if ( empty ( $PHP_SELF ) ) $PHP_SELF = ''; // this happens when running send_reminders.php from CL if ( ! strstr ( $PHP_SELF, "login.php" ) && ! empty ( $GLOBALS["login"] ) ) { $GLOBALS["login"] = ""; }
// Define an array to use to jumble up the key: $offsets // We define a unique key to scramble the cookie we generate. // We use the admin install password that the user set to make // the salt unique for each WebCalendar install. if ( ! empty ( $settings ) && ! empty ( $settings['install_password'] ) ) { $salt = $settings['install_password']; } else { $salt = md5 ( $db_login ); } $salt_len = strlen ( $salt );
if ( ! empty ( $db_password ) ) { $salt2 = md5 ( $db_password ); } else { $salt2 = md5 ( "oogabooga" ); } $salt2_len = strlen ( $salt2 );
$offsets = array (); for ( $i = 0; $i < $salt_len || $i < $salt2_len; $i++ ) { $offsets[$i] = 0; if ( $i < $salt_len ) $offsets[$i] += ord ( substr ( $salt, $i, 1 ) ); if ( $i < $salt2_len ) $offsets[$i] += ord ( substr ( $salt2, $i, 1 ) ); $offsets[$i] %= 128; } /* debugging code... for ( $i = 0; $i < count ( $offsets ); $i++ ) { echo "offset $i: $offsets[$i] <br />\n"; } */
/* * Functions start here. All non-function code should be above this * * Note to developers: * Documentation is generated from the function comments below. * When adding/updating functions, please follow the following conventions * seen below. Your cooperation in this matter is appreciated :-) * * If you want your documentation to link to the db documentation, * just make sure you mention the db table name followed by "table" * on the same line. Here's an example: * Retrieve preferences from the webcal_user_pref table. * */
/** * Gets the value resulting from an HTTP POST method. * * <b>Note:</b> The return value will be affected by the value of * <var>magic_quotes_gpc</var> in the php.ini file. * * @param string $name Name used in the HTML form * * @return string The value used in the HTML form * * @see getGetValue */ function getPostValue ( $name ) { global $HTTP_POST_VARS;
if ( isset ( $_POST ) && is_array ( $_POST ) && ! empty ( $_POST[$name] ) ) { $HTTP_POST_VARS[$name] = $_POST[$name]; return $_POST[$name]; } else if ( ! isset ( $HTTP_POST_VARS ) ) { return null; } else if ( ! isset ( $HTTP_POST_VARS[$name] ) ) { return null; } return ( $HTTP_POST_VARS[$name] ); }
/** * Gets the value resulting from an HTTP GET method. * * <b>Note:</b> The return value will be affected by the value of * <var>magic_quotes_gpc</var> in the php.ini file. * * If you need to enforce a specific input format (such as numeric input), then * use the {@link getValue()} function. * * @param string $name Name used in the HTML form or found in the URL * * @return string The value used in the HTML form (or URL) * * @see getPostValue */ function getGetValue ( $name ) { global $HTTP_GET_VARS;
if ( isset ( $_GET ) && is_array ( $_GET ) && ! empty ( $_GET[$name] ) ) { $HTTP_GET_VARS[$name] = $_GET[$name]; return $_GET[$name]; } else if ( ! isset ( $HTTP_GET_VARS ) ) { return null; } else if ( ! isset ( $HTTP_GET_VARS[$name] ) ) { return null; } return ( $HTTP_GET_VARS[$name] ); }
/** * Gets the value resulting from either HTTP GET method or HTTP POST method. * * <b>Note:</b> The return value will be affected by the value of * <var>magic_quotes_gpc</var> in the php.ini file. * * <b>Note:</b> If you need to get an integer value, yuou can use the * getIntValue function. * * @param string $name Name used in the HTML form or found in the URL * @param string $format A regular expression format that the input must match. * If the input does not match, an empty string is * returned and a warning is sent to the browser. If The * <var>$fatal</var> parameter is true, then execution * will also stop when the input does not match the * format. * @param bool $fatal Is it considered a fatal error requiring execution to * stop if the value retrieved does not match the format * regular expression? * * @return string The value used in the HTML form (or URL) * * @uses getGetValue * @uses getPostValue */ function getValue ( $name, $format="", $fatal=false ) { $val = getPostValue ( $name ); if ( ! isset ( $val ) ) $val = getGetValue ( $name ); // for older PHP versions... if ( ! isset ( $val ) && get_magic_quotes_gpc () == 1 && ! empty ( $GLOBALS[$name] ) ) $val = $GLOBALS[$name]; if ( ! isset ( $val ) ) return ""; if ( ! empty ( $format ) && ! preg_match ( "/^" . $format . "$/", $val ) ) { // does not match if ( $fatal ) { die_miserable_death ( "Fatal Error: Invalid data format for $name" ); } // ignore value return ""; } return $val; }
/** * Gets an integer value resulting from an HTTP GET or HTTP POST method. * * <b>Note:</b> The return value will be affected by the value of * <var>magic_quotes_gpc</var> in the php.ini file. * * @param string $name Name used in the HTML form or found in the URL * @param bool $fatal Is it considered a fatal error requiring execution to * stop if the value retrieved does not match the format * regular expression? * * @return string The value used in the HTML form (or URL) * * @uses getValue */ function getIntValue ( $name, $fatal=false ) { $val = getValue ( $name, "-?[0-9]+", $fatal ); return $val; }
/** * Loads default system settings (which can be updated via admin.php). * * System settings are stored in the webcal_config table. * * <b>Note:</b> If the setting for <var>server_url</var> is not set, the value * will be calculated and stored in the database. * * @global string User's login name * @global bool Readonly * @global string HTTP hostname * @global int Server's port number * @global string Request string * @global array Server variables */ function load_global_settings () { global $login, $readonly, $HTTP_HOST, $SERVER_PORT, $REQUEST_URI, $_SERVER;
// Note: when running from the command line (send_reminders.php), // these variables are (obviously) not set. // TODO: This type of checking should be moved to a central locationm // like init.php. if ( isset ( $_SERVER ) && is_array ( $_SERVER ) ) { if ( empty ( $HTTP_HOST ) && isset ( $_SERVER["HTTP_POST"] ) ) $HTTP_HOST = $_SERVER["HTTP_HOST"]; if ( empty ( $SERVER_PORT ) && isset ( $_SERVER["SERVER_PORT"] ) ) $SERVER_PORT = $_SERVER["SERVER_PORT"]; if ( empty ( $REQUEST_URI ) && isset ( $_SERVER["REQUEST_URI"] ) ) $REQUEST_URI = $_SERVER["REQUEST_URI"]; }
$res = dbi_query ( "SELECT cal_setting, cal_value FROM webcal_config" ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { $setting = $row[0]; $value = $row[1]; //echo "Setting '$setting' to '$value' <br />\n"; $GLOBALS[$setting] = $value; } dbi_free_result ( $res ); }
// If app name not set.... default to "Title". This gets translated // later since this function is typically called before translate.php // is included. // Note: We usually use translate($application_name) instead of // translate("Title"). if ( empty ( $GLOBALS["application_name"] ) ) $GLOBALS["application_name"] = "Title";
// If $server_url not set, then calculate one for them, then store it // in the database. if ( empty ( $GLOBALS["server_url"] ) ) { if ( ! empty ( $HTTP_HOST ) && ! empty ( $REQUEST_URI ) ) { $ptr = strrpos ( $REQUEST_URI, "/" ); if ( $ptr > 0 ) { $uri = substr ( $REQUEST_URI, 0, $ptr + 1 ); $server_url = "http://" . $HTTP_HOST; if ( ! empty ( $SERVER_PORT ) && $SERVER_PORT != 80 ) $server_url .= ":" . $SERVER_PORT; $server_url .= $uri;
dbi_query ( "INSERT INTO webcal_config ( cal_setting, cal_value ) ". "VALUES ( 'server_url', '$server_url' )" ); $GLOBALS["server_url"] = $server_url; } } }
// If no font settings, then set some if ( empty ( $GLOBALS["FONTS"] ) ) { if ( $GLOBALS["LANGUAGE"] == "Japanese" ) $GLOBALS["FONTS"] = "Osaka, Arial, Helvetica, sans-serif"; else $GLOBALS["FONTS"] = "Arial, Helvetica, sans-serif"; } }
/** * Gets the list of active plugins. * * Should be called after {@link load_global_settings()} and {@link load_user_preferences()}. * * @internal cek: ignored since I am not sure this will ever be used... * * @return array Active plugins * * @ignore */ function get_plugin_list ( $include_disabled=false ) { // first get list of available plugins $sql = "SELECT cal_setting FROM webcal_config " . "WHERE cal_setting LIKE '%.plugin_status'"; if ( ! $include_disabled ) $sql .= " AND cal_value = 'Y'"; $sql .= " ORDER BY cal_setting"; $res = dbi_query ( $sql ); $plugins = array (); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { $e = explode ( ".", $row[0] ); if ( $e[0] != "" ) { $plugins[] = $e[0]; } } dbi_free_result ( $res ); } else { echo translate("Database error") . ": " . dbi_error (); exit; } if ( count ( $plugins ) == 0 ) { $plugins[] = "webcalendar"; } return $plugins; }
/** * Get plugins available to the current user. * * Do this by getting a list of all plugins that are not disabled by the * administrator and make sure this user has not disabled any of them. * * It's done this was so that when an admin adds a new plugin, it shows up on * each users system automatically (until they disable it). * * @return array Plugins available to current user * * @ignore */ function get_user_plugin_list () { $ret = array (); $all_plugins = get_plugin_list (); for ( $i = 0; $i < count ( $all_plugins ); $i++ ) { if ( $GLOBALS[$all_plugins[$i] . ".disabled"] != "N" ) $ret[] = $all_plugins[$i]; } return $ret; }
/** * Identify user's browser. * * Returned value will be one of: * - "Mozilla/5" = Mozilla (open source Mozilla 5.0) * - "Mozilla/[3,4]" = Netscape (3.X, 4.X) * - "MSIE 4" = MSIE (4.X) * * @return string String identifying browser * * @ignore */ function get_web_browser () { if ( ereg ( "MSIE [0-9]", getenv ( "HTTP_USER_AGENT" ) ) ) return "MSIE"; if ( ereg ( "Mozilla/[234]", getenv ( "HTTP_USER_AGENT" ) ) ) return "Netscape"; if ( ereg ( "Mozilla/[5678]", getenv ( "HTTP_USER_AGENT" ) ) ) return "Mozilla"; return "Unknown"; }
/** * Logs a debug message. * * Generally, we do not leave calls to this function in the code. It is used * for debugging only. * * @param string $msg Text to be logged */ function do_debug ( $msg ) { // log to /tmp/webcal-debug.log //error_log ( date ( "Y-m-d H:i:s" ) . "> $msg\n", // 3, "/tmp/webcal-debug.log" ); //error_log ( date ( "Y-m-d H:i:s" ) . "> $msg\n", // 2, "sockieman:2000" ); }
/** * Gets user's preferred view. * * The user's preferred view is stored in the $STARTVIEW global variable. This * is loaded from the user preferences (or system settings if there are no user * prefererences.) * * @param string $indate Date to pass to preferred view in YYYYMMDD format * @param string $args Arguments to include in the URL (such as "user=joe") * * @return string URL of the user's preferred view */ function get_preferred_view ( $indate="", $args="" ) { global $STARTVIEW, $thisdate;
$url = empty ( $STARTVIEW ) ? "month.php" : $STARTVIEW; // We used to just store "month" in $STARTVIEW without the ".php" // This is just to prevent users from getting a "404 not found" if // they have not updated their preferences. if ( $url == "month" || $url == "day" || $url == "week" || $url == "year" ) $url .= ".php";
$url = str_replace ( '&', '&', $url ); $url = str_replace ( '&', '&', $url );
$xdate = empty ( $indate ) ? $thisdate : $indate; if ( ! empty ( $xdate ) ) { if ( strstr ( $url, "?" ) ) $url .= '&' . "date=$xdate"; else $url .= '?' . "date=$xdate"; }
if ( ! empty ( $args ) ) { if ( strstr ( $url, "?" ) ) $url .= '&' . $args; else $url .= '?' . $args; }
return $url; }
/** * Sends a redirect to the user's preferred view. * * The user's preferred view is stored in the $STARTVIEW global variable. This * is loaded from the user preferences (or system settings if there are no user * prefererences.) * * @param string $indate Date to pass to preferred view in YYYYMMDD format * @param string $args Arguments to include in the URL (such as "user=joe") */ function send_to_preferred_view ( $indate="", $args="" ) { $url = get_preferred_view ( $indate, $args ); do_redirect ( $url ); }
/** Sends a redirect to the specified page. * * The database connection is closed and execution terminates in this function. * * <b>Note:</b> MS IIS/PWS has a bug in which it does not allow us to send a * cookie and a redirect in the same HTTP header. When we detect that the web * server is IIS, we accomplish the redirect using meta-refresh. See the * following for more info on the IIS bug: * * {@link http://www.faqts.com/knowledge_base/view.phtml/aid/9316/fid/4} * * @param string $url The page to redirect to. In theory, this should be an * absolute URL, but all browsers accept relative URLs (like * "month.php"). * * @global string Type of webserver * @global array Server variables * @global resource Database connection */ function do_redirect ( $url ) { global $SERVER_SOFTWARE, $_SERVER, $c;
// Replace any '&' with '&' since we don't want that in the HTTP // header. $url = str_replace ( '&', '&', $url );
if ( empty ( $SERVER_SOFTWARE ) ) $SERVER_SOFTWARE = $_SERVER["SERVER_SOFTWARE"]; //echo "SERVER_SOFTWARE = $SERVER_SOFTWARE <br />\n"; exit; if ( ( substr ( $SERVER_SOFTWARE, 0, 5 ) == "Micro" ) || ( substr ( $SERVER_SOFTWARE, 0, 3 ) == "WN/" ) ) { echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"> <head>\n<title>Redirect</title>\n" . "<meta http-equiv=\"refresh\" content=\"0; url=$url\" />\n</head>\n<body>\n" . "Redirecting to.. <a href=\"" . $url . "\">here</a>.</body>\n</html>"; } else { Header ( "Location: $url" ); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"> <head>\n<title>Redirect</title>\n</head>\n<body>\n" . "Redirecting to ... <a href=\"" . $url . "\">here</a>.</body>\n</html>"; } dbi_close ( $c ); exit; }
/** * Sends an HTTP login request to the browser and stops execution. */ function send_http_login () { global $lang_file, $application_name;
if ( strlen ( $lang_file ) ) { Header ( "WWW-Authenticate: Basic realm=\"" . translate("Title") . "\""); Header ( "HTTP/1.0 401 Unauthorized" ); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"> <head>\n<title>Unauthorized</title>\n</head>\n<body>\n" . "<h2>" . translate("Title") . "</h2>\n" . translate("You are not authorized") . "\n</body>\n</html>"; } else { Header ( "WWW-Authenticate: Basic realm=\"WebCalendar\""); Header ( "HTTP/1.0 401 Unauthorized" ); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"> <head>\n<title>Unauthorized</title>\n</head>\n<body>\n" . "<h2>WebCalendar</h2>\n" . "You are not authorized" . "\n</body>\n</html>"; } exit; }
/** * Generates a cookie that saves the last calendar view. * * Cookie is based on the current <var>$REQUEST_URI</var>. * * We save this cookie so we can return to this same page after a user * edits/deletes/etc an event. * * @global string Request string */ function remember_this_view () { global $REQUEST_URI; if ( empty ( $REQUEST_URI ) ) $REQUEST_URI = $_SERVER["REQUEST_URI"];
// do not use anything with friendly in the URI if ( strstr ( $REQUEST_URI, "friendly=" ) ) return;
SetCookie ( "webcalendar_last_view", $REQUEST_URI ); }
/** * Gets the last page stored using {@link remember_this_view()}. * * @return string The URL of the last view or an empty string if it cannot be * determined. * * @global array Cookies */ function get_last_view () { global $HTTP_COOKIE_VARS; $val = '';
if ( isset ( $_COOKIE["webcalendar_last_view"] ) ) { $HTTP_COOKIE_VARS["webcalendar_last_view"] = $_COOKIE["webcalendar_last_view"]; $val = $_COOKIE["webcalendar_last_view"]; } else if ( isset ( $HTTP_COOKIE_VARS["webcalendar_last_view"] ) ) { $val = $HTTP_COOKIE_VARS["webcalendar_last_view"]; } $val = str_replace ( "&", "&", $val ); return $val; }
/** * Sends HTTP headers that tell the browser not to cache this page. * * Different browser use different mechanisms for this, so a series of HTTP * header directives are sent. * * <b>Note:</b> This function needs to be called before any HTML output is sent * to the browser. */ function send_no_cache_header () { header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" ); header ( "Cache-Control: no-store, no-cache, must-revalidate" ); header ( "Cache-Control: post-check=0, pre-check=0", false ); header ( "Pragma: no-cache" ); }
/** * Loads the current user's preferences as global variables from the webcal_user_pref table. * * Also loads the list of views for this user (not really a preference, but * this is a convenient place to put this...) * * <b>Notes:</b> * - If <var>$allow_color_customization</var> is set to 'N', then we ignore any * color preferences. * - Other default values will also be set if the user has not saved a * preference and no global value has been set by the administrator in the * system settings. */ function load_user_preferences () { global $login, $browser, $views, $prefarray, $is_assistant, $has_boss, $user, $is_nonuser_admin, $allow_color_customization; $lang_found = false; $colors = array ( "BGCOLOR" => 1, "H2COLOR" => 1, "THBG" => 1, "THFG" => 1, "CELLBG" => 1, "TODAYCELLBG" => 1, "WEEKENDBG" => 1, "POPUP_BG" => 1, "POPUP_FG" => 1, );
$browser = get_web_browser (); $browser_lang = get_browser_language (); $prefarray = array ();
// Note: default values are set in config.php $res = dbi_query ( "SELECT cal_setting, cal_value FROM webcal_user_pref " . "WHERE cal_login = '$login'" ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { $setting = $row[0]; $value = $row[1]; if ( $allow_color_customization == 'N' ) { if ( isset ( $colors[$setting] ) ) continue; } $sys_setting = "sys_" . $setting; // save system defaults if ( ! empty ( $GLOBALS[$setting] ) ) $GLOBALS["sys_" . $setting] = $GLOBALS[$setting]; $GLOBALS[$setting] = $value; $prefarray[$setting] = $value; if ( $setting == "LANGUAGE" ) $lang_found = true; } dbi_free_result ( $res ); } // get views for this user and global views $res = dbi_query ( "SELECT cal_view_id, cal_name, cal_view_type, cal_is_global " . "FROM webcal_view " . "WHERE cal_owner = '$login' OR cal_is_global = 'Y' " . "ORDER BY cal_name" ); if ( $res ) { $views = array (); while ( $row = dbi_fetch_row ( $res ) ) { if ( $row[2] == 'S' ) $url = "view_t.php?timeb=1&id=$row[0]"; else if ( $row[2] == 'T' ) $url = "view_t.php?timeb=0&id=$row[0]"; else $url = "view_" . strtolower ( $row[2] ) . ".php?id=$row[0]"; $v = array ( "cal_view_id" => $row[0], "cal_name" => $row[1], "cal_view_type" => $row[2], "cal_is_global" => $row[3], "url" => $url ); $views[] = $v; } dbi_free_result ( $res ); }
// If user has not set a language preference, then use their browser // settings to figure it out, and save it in the database for future // use (email reminders). if ( ! $lang_found && strlen ( $login ) && $login != "__public__" ) { $LANGUAGE = $browser_lang; dbi_query ( "INSERT INTO webcal_user_pref " . "( cal_login, cal_setting, cal_value ) VALUES " . "( '$login', 'LANGUAGE', '$LANGUAGE' )" ); }
if ( empty ( $GLOBALS["DATE_FORMAT_MY"] ) ) $GLOBALS["DATE_FORMAT_MY"] = "__month__ __yyyy__"; if ( empty ( $GLOBALS["DATE_FORMAT_MD"] ) ) $GLOBALS["DATE_FORMAT_MD"] = "__month__ __dd__"; $is_assistant = empty ( $user ) ? false : user_is_assistant ( $login, $user ); $has_boss = user_has_boss ( $login ); $is_nonuser_admin = ($user) ? user_is_nonuser_admin ( $login, $user ) : false; if ( $is_nonuser_admin ) load_nonuser_preferences ($user); }
/** * Gets the list of external users for an event from the webcal_entry_ext_user table in an HTML format. * * @param int $event_id Event ID * @param int $use_mailto When set to 1, email address will contain an href * link with a mailto URL. * * @return string The list of external users for an event formatte in HTML. */ function event_get_external_users ( $event_id, $use_mailto=0 ) { global $error; $ret = "";
$res = dbi_query ( "SELECT cal_fullname, cal_email " . "FROM webcal_entry_ext_user " . "WHERE cal_id = $event_id " . "ORDER by cal_fullname" ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { if ( strlen ( $ret ) ) $ret .= "\n"; // Remove [\d] if duplicate name $trow = trim( preg_replace( '/\[[\d]]/' , "", $row[0] ) ); $ret .= $trow; if ( strlen ( $row[1] ) ) { if ( $use_mailto ) { $ret .= " <a href=\"mailto:$row[1]\"><" . htmlentities ( $row[1] ) . "></a>"; } else { $ret .= " <". htmlentities ( $row[1] ) . ">"; } } } dbi_free_result ( $res ); } else { echo translate("Database error") .": " . dbi_error (); echo "<br />\nSQL:<br />\n$sql"; exit; } return $ret; }
/** * Adds something to the activity log for an event. * * The information will be saved to the webcal_entry_log table. * * @param int $event_id Event ID * @param string $user Username of user doing this * @param string $user_cal Username of user whose calendar is affected * @param string $type Type of activity we are logging: * - $LOG_CREATE * - $LOG_APPROVE * - $LOG_REJECT * - $LOG_UPDATE * - $LOG_DELETE * - $LOG_NOTIFICATION * - $LOG_REMINDER * @param string $text Text comment to add with activity log entry */ function activity_log ( $event_id, $user, $user_cal, $type, $text ) { $next_id = 1;
if ( empty ( $type ) ) { echo "Error: type not set for activity log!"; // but don't exit since we may be in mid-transaction return; }
$res = dbi_query ( "SELECT MAX(cal_log_id) FROM webcal_entry_log" ); if ( $res ) { if ( $row = dbi_fetch_row ( $res ) ) { $next_id = $row[0] + 1; } dbi_free_result ( $res ); }
$date = date ( "Ymd" ); $time = date ( "Gis" ); $sql_text = empty ( $text ) ? "NULL" : "'$text'"; $sql_user_cal = empty ( $user_cal ) ? "NULL" : "'$user_cal'";
$sql = "INSERT INTO webcal_entry_log ( " . "cal_log_id, cal_entry_id, cal_login, cal_user_cal, cal_type, " . "cal_date, cal_time, cal_text ) VALUES ( $next_id, $event_id, " . "'$user', $sql_user_cal, '$type', $date, $time, $sql_text )"; if ( ! dbi_query ( $sql ) ) { echo "Database error: " . dbi_error (); echo "<br />\nSQL:<br />\n$sql"; exit; } }
/** * Gets a list of users. * * If groups are enabled, this will restrict the list of users to only those * users who are in the same group(s) as the user (unless the user is an admin * user). We allow admin users to see all users because they can also edit * someone else's events (so they may need access to users who are not in the * same groups that they are in). * * @return array Array of users, where each element in the array is an array * with the following keys: * - cal_login * - cal_lastname * - cal_firstname * - cal_is_admin * - cal_is_admin * - cal_email * - cal_password * - cal_fullname */ function get_my_users () { global $login, $is_admin, $groups_enabled, $user_sees_only_his_groups;
if ( $groups_enabled == "Y" && $user_sees_only_his_groups == "Y" && ! $is_admin ) { // get groups that current user is in $res = dbi_query ( "SELECT cal_group_id FROM webcal_group_user " . "WHERE cal_login = '$login'" ); $groups = array (); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { $groups[] = $row[0]; } dbi_fetch_row ( $res ); } $u = user_get_users (); $u_byname = array (); for ( $i = 0; $i < count ( $u ); $i++ ) { $name = $u[$i]['cal_login']; $u_byname[$name] = $u[$i]; } $ret = array (); if ( count ( $groups ) == 0 ) { // Eek. User is in no groups... Return only themselves $ret[] = $u_byname[$login]; return $ret; } // get list of users in the same groups as current user $sql = "SELECT DISTINCT(webcal_group_user.cal_login), cal_lastname, cal_firstname from webcal_group_user " . "LEFT JOIN webcal_user ON webcal_group_user.cal_login = webcal_user.cal_login " . "WHERE cal_group_id "; if ( count ( $groups ) == 1 ) $sql .= "= " . $groups[0]; else { $sql .= "IN ( " . implode ( ", ", $groups ) . " )"; } $sql .= " ORDER BY cal_lastname, cal_firstname, webcal_group_user.cal_login"; //echo "SQL: $sql <br />\n"; $res = dbi_query ( $sql ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { $ret[] = $u_byname[$row[0]]; } dbi_free_result ( $res ); } return $ret; } else { // groups not enabled... return all users //echo "No groups. "; return user_get_users (); } }
/** * Gets a preference setting for the specified user. * * If no value is found in the database, then the system default setting will * be returned. * * @param string $user User login we are getting preference for * @param string $setting Name of the setting * * @return string The value found in the webcal_user_pref table for the * specified setting or the sytem default if no user settings * was found. */ function get_pref_setting ( $user, $setting ) { $ret = ''; // set default if ( ! isset ( $GLOBALS["sys_" .$setting] ) ) { // this could happen if the current user has not saved any pref. yet if ( ! empty ( $GLOBALS[$setting] ) ) $ret = $GLOBALS[$setting]; } else { $ret = $GLOBALS["sys_" .$setting]; }
$sql = "SELECT cal_value FROM webcal_user_pref " . "WHERE cal_login = '" . $user . "' AND " . "cal_setting = '" . $setting . "'"; //echo "SQL: $sql <br />\n"; $res = dbi_query ( $sql ); if ( $res ) { if ( $row = dbi_fetch_row ( $res ) ) $ret = $row[0]; dbi_free_result ( $res ); } return $ret; }
/** * Gets browser-specified language preference. * * @return string Preferred language * * @ignore */ function get_browser_language () { global $HTTP_ACCEPT_LANGUAGE, $browser_languages; $ret = ""; if ( empty ( $HTTP_ACCEPT_LANGUAGE ) && isset ( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ) $HTTP_ACCEPT_LANGUAGE = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; if ( empty ( $HTTP_ACCEPT_LANGUAGE ) ) { return "none"; } else { $langs = explode ( ",", $HTTP_ACCEPT_LANGUAGE ); for ( $i = 0; $i < count ( $langs ); $i++ ) { $l = strtolower ( trim ( ereg_replace(';.*', '', $langs[$i] ) ) ); $ret .= "\"$l\" "; if ( ! empty ( $browser_languages[$l] ) ) { return $browser_languages[$l]; } } } //if ( strlen ( $HTTP_ACCEPT_LANGUAGE ) ) // return "none ($HTTP_ACCEPT_LANGUAGE not supported)"; //else return "none"; }
/** * Loads current user's layer info into layer global variable. * * If the system setting <var>$allow_view_other</var> is not set to 'Y', then * we ignore all layer functionality. If <var>$force</var> is 0, we only load * layers if the current user preferences have layers turned on. * * @param string $user Username of user to load layers for * @param int $force If set to 1, then load layers for this user even if * user preferences have layers turned off. */ function load_user_layers ($user="",$force=0) { global $login; global $layers; global $LAYERS_STATUS, $allow_view_other;
if ( $user == "" ) $user = $login;
$layers = array ();
if ( empty ( $allow_view_other ) || $allow_view_other != 'Y' ) return; // not allowed to view others' calendars, so cannot use layers
if ( $force || ( ! empty ( $LAYERS_STATUS ) && $LAYERS_STATUS != "N" ) ) { $res = dbi_query ( "SELECT cal_layerid, cal_layeruser, cal_color, cal_dups " . "FROM webcal_user_layers " . "WHERE cal_login = '$user' ORDER BY cal_layerid" ); if ( $res ) { $count = 1; while ( $row = dbi_fetch_row ( $res ) ) { $layers[$row[0]] = array ( "cal_layerid" => $row[0], "cal_layeruser" => $row[1], "cal_color" => $row[2], "cal_dups" => $row[3] ); $count++; } dbi_free_result ( $res ); } } else { //echo "Not loading!"; } }
/** * Generates the HTML used in an event popup for the site_extras fields of an event. * * @param int $id Event ID * * @return string The HTML to be used within the event popup for any site_extra * fields found for the specified event */ function site_extras_for_popup ( $id ) { global $site_extras_in_popup, $site_extras; // These are needed in case the site_extras.php file was already // included. global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE, $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $EXTRA_SELECTLIST; global $EXTRA_REMINDER_WITH_DATE, $EXTRA_REMINDER_WITH_OFFSET, $EXTRA_REMINDER_DEFAULT_YES;
$ret = '';
if ( $site_extras_in_popup != 'Y' ) return '';
include_once 'includes/site_extras.php';
$extras = get_site_extra_fields ( $id ); for ( $i = 0; $i < count ( $site_extras ); $i++ ) { $extra_name = $site_extras[$i][0]; $extra_type = $site_extras[$i][2]; $extra_arg1 = $site_extras[$i][3]; $extra_arg2 = $site_extras[$i][4]; if ( ! empty ( $extras[$extra_name]['cal_name'] ) ) { $ret .= "<dt>" . translate ( $site_extras[$i][1] ) . ":</dt>\n<dd>"; if ( $extra_type == $EXTRA_DATE ) { if ( $extras[$extra_name]['cal_date'] > 0 ) $ret .= date_to_str ( $extras[$extra_name]['cal_date'] ); } else if ( $extra_type == $EXTRA_TEXT || $extra_type == $EXTRA_MULTILINETEXT ) { $ret .= nl2br ( $extras[$extra_name]['cal_data'] ); } else if ( $extra_type == $EXTRA_REMINDER ) { if ( $extras[$extra_name]['cal_remind'] <= 0 ) $ret .= translate ( "No" ); else { $ret .= translate ( "Yes" ); if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_DATE ) > 0 ) { $ret .= " - "; $ret .= date_to_str ( $extras[$extra_name]['cal_date'] ); } else if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET ) > 0 ) { $ret .= " - "; $minutes = $extras[$extra_name]['cal_data']; $d = (int) ( $minutes / ( 24 * 60 ) ); $minutes -= ( $d * 24 * 60 ); $h = (int) ( $minutes / 60 ); $minutes -= ( $h * 60 ); if ( $d > 0 ) $ret .= $d . " " . translate("days") . " "; if ( $h > 0 ) $ret .= $h . " " . translate("hours") . " "; if ( $minutes > 0 ) $ret .= $minutes . " " . translate("minutes"); $ret .= " " . translate("before event" ); } } } else { $ret .= $extras[$extra_name]['cal_data']; } $ret .= "</dd>\n"; } } return $ret; }
/** * Builds the HTML for the event popup. * * @param string $popupid CSS id to use for event popup * @param string $user Username of user the event pertains to * @param string $description Event description * @param string $time Time of the event (already formatted in a display format) * @param string $site_extras HTML for any site_extras for this event * * @return string The HTML for the event popup */ function build_event_popup ( $popupid, $user, $description, $time, $site_extras='' ) { global $login, $popup_fullnames, $popuptemp_fullname; $ret = "<dl id=\"$popupid\" class=\"popup\">\n";
if ( empty ( $popup_fullnames ) ) $popup_fullnames = array (); if ( $user != $login ) { if ( empty ( $popup_fullnames[$user] ) ) { user_load_variables ( $user, "popuptemp_" ); $popup_fullnames[$user] = $popuptemp_fullname; } $ret .= "<dt>" . translate ("User") . ":</dt>\n<dd>$popup_fullnames[$user]</dd>\n"; } if ( strlen ( $time ) ) $ret .= "<dt>" . translate ("Time") . ":</dt>\n<dd>$time</dd>\n"; $ret .= "<dt>" . translate ("Description") . ":</dt>\n<dd>"; if ( ! empty ( $GLOBALS['allow_html_description'] ) && $GLOBALS['allow_html_description'] == 'Y' ) { $str = str_replace ( "&", "&", $description ); $str = str_replace ( "&amp;", "&", $str ); // If there is no html found, then go ahead and replace // the line breaks ("\n") with the html break. if ( strstr ( $str, "<" ) && strstr ( $str, ">" ) ) { // found some html... $ret .= $str; } else { // no html, replace line breaks $ret .= nl2br ( $str ); } } else { // html not allowed in description, escape everything $ret .= nl2br ( htmlspecialchars ( $description ) ); } $ret .= "</dd>\n"; if ( ! empty ( $site_extras ) ) $ret .= $site_extras; $ret .= "</dl>\n"; return $ret; }
/** * Prints out a date selection box for use in a form. * * @param string $prefix Prefix to use in front of form element names * @param int $date Currently selected date (in YYYYMMDD format) * * @uses date_selection_html */ function print_date_selection ( $prefix, $date ) { print date_selection_html ( $prefix, $date ); }
/** * Generate HTML for a date selection for use in a form. * * @param string $prefix Prefix to use in front of form element names * @param int $date Currently selected date (in YYYYMMDD format) * * @return string HTML for the selection box */ function date_selection_html ( $prefix, $date ) { $ret = ""; $num_years = 20; if ( strlen ( $date ) != 8 ) $date = date ( "Ymd" ); $thisyear = $year = substr ( $date, 0, 4 ); $thismonth = $month = substr ( $date, 4, 2 ); $thisday = $day = substr ( $date, 6, 2 ); if ( $thisyear - date ( "Y" ) >= ( $num_years - 1 ) ) $num_years = $thisyear - date ( "Y" ) + 2; $ret .= "<select name=\"" . $prefix . "day\">\n"; for ( $i = 1; $i <= 31; $i++ ) $ret .= "<option value=\"$i\"" . ( $i == $thisday ? " selected=\"selected\"" : "" ) . ">$i</option>\n"; $ret .= "</select>\n<select name=\"" . $prefix . "month\">\n"; for ( $i = 1; $i <= 12; $i++ ) { $m = month_short_name ( $i - 1 ); $ret .= "<option value=\"$i\"" . ( $i == $thismonth ? " selected=\"selected\"" : "" ) . ">$m</option>\n"; } $ret .= "</select>\n<select name=\"" . $prefix . "year\">\n"; for ( $i = -10; $i < $num_years; $i++ ) { $y = $thisyear + $i; $ret .= "<option value=\"$y\"" . ( $y == $thisyear ? " selected=\"selected\"" : "" ) . ">$y</option>\n"; } $ret .= "</select>\n"; $ret .= "<input type=\"button\" onclick=\"selectDate( '" . $prefix . "day','" . $prefix . "month','" . $prefix . "year',$date, event)\" value=\"" . translate("Select") . "...\" />\n";
return $ret; }
/** * Prints out a minicalendar for a month. * * @todo Make day.php NOT be a special case * * @param int $thismonth Number of the month to print * @param int $thisyear Number of the year * @param bool $showyear Show the year in the calendar's title? * @param bool $show_weeknums Show week numbers to the left of each row? * @param string $minical_id id attribute for the minical table * @param string $month_link URL and query string for month link that should * come before the date specification (e.g. * month.php? or view_l.php?id=7&) */ function display_small_month ( $thismonth, $thisyear, $showyear, $show_weeknums=false, $minical_id='', $month_link='month.php?' ) { global $WEEK_START, $user, $login, $boldDays, $get_unapproved; global $DISPLAY_WEEKNUMBER; global $SCRIPT, $thisday; // Needed for day.php global $caturl, $today;
if ( $user != $login && ! empty ( $user ) ) { $u_url = "user=$user" . "&"; } else { $u_url = ''; }
//start the minical table for each month echo "\n<table class=\"minical\""; if ( $minical_id != '' ) { echo " id=\"$minical_id\""; } echo ">\n";
$monthstart = mktime(2,0,0,$thismonth,1,$thisyear); $monthend = mktime(2,0,0,$thismonth + 1,0,$thisyear);
if ( $SCRIPT == 'day.php' ) { $month_ago = date ( "Ymd", mktime ( 3, 0, 0, $thismonth - 1, $thisday, $thisyear ) ); $month_ahead = date ( "Ymd", mktime ( 3, 0, 0, $thismonth + 1, $thisday, $thisyear ) );
echo "<caption>$thisday</caption>\n"; echo "<thead>\n"; echo "<tr class=\"monthnav\"><th colspan=\"7\">\n"; echo "<a title=\"" . translate("Previous") . "\" class=\"prev\" href=\"day.php?" . $u_url . "date=$month_ago$caturl\"><img src=\"leftarrowsmall.gif\" alt=\"" . translate("Previous") . "\" /></a>\n"; echo "<a title=\"" . translate("Next") . "\" class=\"next\" href=\"day.php?" . $u_url . "date=$month_ahead$caturl\"><img src=\"rightarrowsmall.gif\" alt=\"" . translate("Next") . "\" /></a>\n"; echo month_name ( $thismonth - 1 ); if ( $showyear != '' ) { echo " $thisyear"; } echo "</th></tr>\n<tr>\n"; } else { //not day script //print the month name echo "<caption><a href=\"{$month_link}{$u_url}year=$thisyear&month=$thismonth\">"; echo month_name ( $thismonth - 1 ) . ( $showyear ? " $thisyear" : "" ); echo "</a></caption>\n";
echo "<thead>\n<tr>\n"; }
//determine if the week starts on sunday or monday if ( $WEEK_START == "1" ) { $wkstart = get_monday_before ( $thisyear, $thismonth, 1 ); } else { $wkstart = get_sunday_before ( $thisyear, $thismonth, 1 ); } //print the headers to display the day of the week (sun, mon, tues, etc.)
// if we're showing week numbers we need an extra column if ( $show_weeknums && $DISPLAY_WEEKNUMBER == 'Y' ) echo "<th class=\"empty\"> </th>\n"; //if the week doesn't start on monday, print the day if ( $WEEK_START == 0 ) echo "<th>" . weekday_short_name ( 0 ) . "</th>\n"; //cycle through each day of the week until gone for ( $i = 1; $i < 7; $i++ ) { echo "<th>" . weekday_short_name ( $i ) . "</th>\n"; } //if the week DOES start on monday, print sunday if ( $WEEK_START == 1 ) echo "<th>" . weekday_short_name ( 0 ) . "</th>\n"; //end the header row echo "</tr>\n</thead>\n<tbody>\n"; for ($i = $wkstart; date("Ymd",$i) <= date ("Ymd",$monthend); $i += (24 * 3600 * 7) ) { echo "<tr>\n"; if ( $show_weeknums && $DISPLAY_WEEKNUMBER == 'Y' ) { echo "<td class=\"weeknumber\"><a href=\"week.php?" . $u_url . "date=".date("Ymd", $i)."\">(" . week_number($i) . ")</a></td>\n"; } for ($j = 0; $j < 7; $j++) { $date = $i + ($j * 24 * 3600); $dateYmd = date ( "Ymd", $date ); $hasEvents = false; if ( $boldDays ) { $ev = get_entries ( $user, $dateYmd, $get_unapproved ); if ( count ( $ev ) > 0 ) { $hasEvents = true; } else { $rep = get_repeating_entries ( $user, $dateYmd, $get_unapproved ); if ( count ( $rep ) > 0 ) $hasEvents = true; } } if ( $dateYmd >= date ("Ymd",$monthstart) && $dateYmd <= date ("Ymd",$monthend) ) { echo "<td"; $wday = date ( 'w', $date ); $class = ''; //add class="weekend" if it's saturday or sunday if ( $wday == 0 || $wday == 6 ) { $class = "weekend"; } //if the day being viewed is today's date AND script = day.php if ( $dateYmd == $thisyear . $thismonth . $thisday && $SCRIPT == 'day.php' ) { //if it's also a weekend, add a space between class names to combine styles if ( $class != '' ) { $class .= ' '; } $class .= "selectedday"; } if ( $hasEvents ) { if ( $class != '' ) { $class .= ' '; } $class .= "hasevents"; } if ( $class != '' ) { echo " class=\"$class\""; } if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ){ echo " id=\"today\""; } echo "><a href=\"day.php?" .$u_url . "date=" . $dateYmd . "\">"; echo date ( "d", $date ) . "</a></td>\n"; } else { echo "<td class=\"empty\"> </td>\n"; } } // end for $j echo "</tr>\n"; } // end for $i echo "</tbody>\n</table>\n"; }
/** * Prints the HTML for one day's events in the month view. * * @param int $id Event ID * @param int $date Date of event (relevant in repeating events) in * YYYYMMDD format * @param int $time Time (in HHMMSS format) * @param int $duration Event duration in minutes * @param string $name Event name * @param string $description Long description of event * @param string $status Event status * @param int $pri Event priority * @param string $access Event access * @param string $event_owner Username of user associated with this event * @param int $event_cat Category of event for <var>$event_owner</var> * * @staticvar int Used to ensure all event popups have a unique id * * @uses build_event_popup */ function print_entry ( $id, $date, $time, $duration, $name, $description, $status, $pri, $access, $event_owner, $event_cat=-1 ) { global $eventinfo, $login, $user, $PHP_SELF, $TZ_OFFSET; static $key = 0; global $layers;
if ( $login != $event_owner && strlen ( $event_owner ) ) { $class = "layerentry"; } else { $class = "entry"; if ( $status == "W" ) $class = "unapprovedentry"; } // if we are looking at a view, then always use "entry" if ( strstr ( $PHP_SELF, "view_m.php" ) || strstr ( $PHP_SELF, "view_w.php" ) || strstr ( $PHP_SELF, "view_v.php" ) || strstr ( $PHP_SELF, "view_t.php" ) ) $class = "entry";
if ( $pri == 3 ) echo "<strong>"; $popupid = "eventinfo-$id-$key"; $key++; echo "<a title=\"" . translate("View this entry") . "\" class=\"$class\" href=\"view_entry.php?id=$id&date=$date"; if ( strlen ( $user ) > 0 ) echo "&user=" . $user; echo "\" onmouseover=\"window.status='" . translate("View this entry") . "'; show(event, '$popupid'); return true;\" onmouseout=\"window.status=''; hide('$popupid'); return true;\">"; $icon = "circle.gif"; $catIcon = ''; if ( $event_cat > 0 ) { $catIcon = "icons/cat-" . $event_cat . ".gif"; if ( ! file_exists ( $catIcon ) ) $catIcon = ''; }
if ( empty ( $catIcon ) ) { echo "<img src=\"$icon\" class=\"bullet\" alt=\"" . translate("View this entry") . "\" />"; } else { // Use category icon echo "<img src=\"$catIcon\" alt=\"" . translate("View this entry") . "\" /><br />"; }
if ( $login != $event_owner && strlen ( $event_owner ) ) { if ($layers) foreach ($layers as $layer) { if ($layer['cal_layeruser'] == $event_owner) { echo("<span style=\"color:" . $layer['cal_color'] . ";\">"); } } }
$timestr = ""; if ( $duration == ( 24 * 60 ) ) { $timestr = translate("All day event"); } else if ( $time != -1 ) { $timestr = display_time ( $time ); $time_short = preg_replace ("/(:00)/", '', $timestr); echo $time_short . "» "; if ( $duration > 0 ) { // calc end time $h = (int) ( $time / 10000 ); $m = ( $time / 100 ) % 100; $m += $duration; $d = $duration; while ( $m >= 60 ) { $h++; $m -= 60; } $end_time = sprintf ( "%02d%02d00", $h, $m ); $timestr .= " - " . display_time ( $end_time ); } } if ( $login != $user && $access == 'R' && strlen ( $user ) ) { echo "(" . translate("Private") . ")"; } else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) { echo "(" . translate("Private") . ")"; } else { echo htmlspecialchars ( $name ); }
if ( $login != $event_owner && strlen ( $event_owner ) ) { if ($layers) foreach ($layers as $layer) { if($layer['cal_layeruser'] == $event_owner) { echo "</span>"; } } } echo "</a>\n"; if ( $pri == 3 ) echo "</strong>\n"; //end font-weight span echo "<br />"; if ( $login != $user && $access == 'R' && strlen ( $user ) ) $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); else $eventinfo .= build_event_popup ( $popupid, $event_owner, $description, $timestr, site_extras_for_popup ( $id ) ); }
/** * Gets any site-specific fields for an entry that are stored in the database in the webcal_site_extras table. * * @param int $eventid Event ID * * @return array Array with the keys as follows: * - <var>cal_name</var> * - <var>cal_type</var> * - <var>cal_date</var> * - <var>cal_remind</var> * - <var>cal_data</var> */ function get_site_extra_fields ( $eventid ) { $sql = "SELECT cal_name, cal_type, cal_date, cal_remind, cal_data " . "FROM webcal_site_extras " . "WHERE cal_id = $eventid"; $res = dbi_query ( $sql ); $extras = array (); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { // save by cal_name (e.g. "URL") $extras[$row[0]] = array ( "cal_name" => $row[0], "cal_type" => $row[1], "cal_date" => $row[2], "cal_remind" => $row[3], "cal_data" => $row[4] ); } dbi_free_result ( $res ); } return $extras; }
/** * Reads all the events for a user for the specified range of dates. * * This is only called once per page request to improve performance. All the * events get loaded into the array <var>$events</var> sorted by time of day * (not date). * * @param string $user Username * @param string $startdate Start date range, inclusive (in YYYYMMDD format) * @param string $enddate End date range, inclusive (in YYYYMMDD format) * @param int $cat_id Category ID to filter on * * @return array Array of events * * @uses query_events */ function read_events ( $user, $startdate, $enddate, $cat_id = '' ) { global $login; global $layers; global $TZ_OFFSET;
$sy = substr ( $startdate, 0, 4 ); $sm = substr ( $startdate, 4, 2 ); $sd = substr ( $startdate, 6, 2 ); $ey = substr ( $enddate, 0, 4 ); $em = substr ( $enddate, 4, 2 ); $ed = substr ( $enddate, 6, 2 ); if ( $startdate == $enddate ) { if ( $TZ_OFFSET == 0 ) { $date_filter = " AND webcal_entry.cal_date = $startdate"; } else if ( $TZ_OFFSET > 0 ) { $prev_day = mktime ( 3, 0, 0, $sm, $sd - 1, $sy ); $cutoff = 24 - $TZ_OFFSET . "0000"; $date_filter = " AND ( ( webcal_entry.cal_date = $startdate AND " . "( webcal_entry.cal_time <= $cutoff OR " . "webcal_entry.cal_time = -1 ) ) OR " . "( webcal_entry.cal_date = " . date("Ymd", $prev_day ) . " AND webcal_entry.cal_time >= $cutoff ) )"; } else { $next_day = mktime ( 3, 0, 0, $sm, $sd + 1, $sy ); $cutoff = ( 0 - $TZ_OFFSET ) * 10000; $date_filter = " AND ( ( webcal_entry.cal_date = $startdate AND " . "( webcal_entry.cal_time > $cutoff OR " . "webcal_entry.cal_time = -1 ) ) OR " . "( webcal_entry.cal_date = " . date("Ymd", $next_day ) . " AND webcal_entry.cal_time <= $cutoff ) )"; } } else { if ( $TZ_OFFSET == 0 ) { $date_filter = " AND webcal_entry.cal_date >= $startdate " . "AND webcal_entry.cal_date <= $enddate"; } else if ( $TZ_OFFSET > 0 ) { $prev_day = date ( ( "Ymd" ), mktime ( 3, 0, 0, $sm, $sd - 1, $sy ) ); $enddate_minus1 = date ( ( "Ymd" ), mktime ( 3, 0, 0, $em, $ed - 1, $ey ) ); $cutoff = 24 - $TZ_OFFSET . "0000"; $date_filter = " AND ( ( webcal_entry.cal_date >= $startdate " . "AND webcal_entry.cal_date <= $enddate AND " . "webcal_entry.cal_time = -1 ) OR " . "( webcal_entry.cal_date = $prev_day AND " . "webcal_entry.cal_time >= $cutoff ) OR " . "( webcal_entry.cal_date = $enddate AND " . "webcal_entry.cal_time < $cutoff ) OR " . "( webcal_entry.cal_date >= $startdate AND " . "webcal_entry.cal_date <= $enddate_minus1 ) )"; } else { // TZ_OFFSET < 0 $next_day = date ( ( "Ymd" ), mktime ( 3, 0, 0, $sm, $sd + 1, $sy ) ); $enddate_plus1 = date ( ( "Ymd" ), mktime ( 3, 0, 0, $em, $ed + 1, $ey ) ); $cutoff = ( 0 - $TZ_OFFSET ) * 10000; $date_filter = " AND ( ( webcal_entry.cal_date >= $startdate " . "AND webcal_entry.cal_date <= $enddate AND " . "webcal_entry.cal_time = -1 ) OR " . "( webcal_entry.cal_date = $startdate AND " . "webcal_entry.cal_time > $cutoff ) OR " . "( webcal_entry.cal_date = $enddate_plus1 AND " . "webcal_entry.cal_time <= $cutoff ) OR " . "( webcal_entry.cal_date > $startdate AND " . "webcal_entry.cal_date < $enddate_plus1 ) )"; } } return query_events ( $user, false, $date_filter, $cat_id ); }
/** * Gets all the events for a specific date. * * Events are retreived from the array of pre-loaded events (which was loaded * all at once to improve performance). * * The returned events will be sorted by time of day. * * @param string $user Username * @param string $date Date to get events for in YYYYMMDD format * @param bool $get_unapproved Load unapproved events? * * @return array Array of events */ function get_entries ( $user, $date, $get_unapproved=true ) { global $events, $TZ_OFFSET; $n = 0; $ret = array ();
//echo "<br />\nChecking " . count ( $events ) . " events. TZ_OFFSET = $TZ_OFFSET, get_unapproved=" . $get_unapproved . "<br />\n";
//print_r ( $events );
for ( $i = 0; $i < count ( $events ); $i++ ) { // In case of data corruption (or some other bug...) if ( empty ( $events[$i] ) || empty ( $events[$i]['cal_id'] ) ) continue; if ( ( ! $get_unapproved ) && $events[$i]['cal_status'] == 'W' ) { // ignore this event //don't adjust anything if no TZ offset or ALL Day Event or Untimed } else if ( empty ( $TZ_OFFSET) || ( $events[$i]['cal_time'] <= 0 ) ) { if ( $events[$i]['cal_date'] == $date ) $ret[$n++] = $events[$i]; } else if ( $TZ_OFFSET > 0 ) { $cutoff = ( 24 - $TZ_OFFSET ) * 10000; //echo "<br /> cal_time " . $events[$i]['cal_time'] . "<br />\n"; $sy = substr ( $date, 0, 4 ); $sm = substr ( $date, 4, 2 ); $sd = substr ( $date, 6, 2 ); $prev_day = date ( ( "Ymd" ), mktime ( 3, 0, 0, $sm, $sd - 1, $sy ) ); //echo "prev_date = $prev_day <br />\n"; if ( $events[$i]['cal_date'] == $date && $events[$i]['cal_time'] == -1 ) { $ret[$n++] = $events[$i]; //echo "added event $events[$i][cal_id] <br />\n"; } else if ( $events[$i]['cal_date'] == $date && $events[$i]['cal_time'] < $cutoff ) { $ret[$n++] = $events[$i]; //echo "added event {$events[$i][cal_id]} <br />\n"; } else if ( $events[$i]['cal_date'] == $prev_day && $events[$i]['cal_time'] >= $cutoff ) { $ret[$n++] = $events[$i]; //echo "added event {$events[$i][cal_id]} <br />\n"; } } else { //TZ < 0 $cutoff = ( 0 - $TZ_OFFSET ) * 10000; //echo "<br />\ncal_time " . $events[$i]['cal_time'] . "<br />\n"; $sy = substr ( $date, 0, 4 ); $sm = substr ( $date, 4, 2 ); $sd = substr ( $date, 6, 2 ); $next_day = date ( ( "Ymd" ), mktime ( 3, 0, 0, $sm, $sd + 1, $sy ) ); //echo "next_date = $next_day <br />\n"; if ( $events[$i]['cal_time'] == -1 ) { if ( $events[$i]['cal_date'] == $date ) { $ret[$n++] = $events[$i]; //echo "added event $events[$i][cal_id] <br />\n"; } } else { if ( $events[$i]['cal_date'] == $date && $events[$i]['cal_time'] > $cutoff ) { $ret[$n++] = $events[$i]; //echo "added event $events[$i][cal_id] <br />\n"; } else if ( $events[$i]['cal_date'] == $next_day && $events[$i]['cal_time'] <= $cutoff ) { $ret[$n++] = $events[$i]; //echo "added event $events[$i][cal_id] <br />\n"; } } } } return $ret; }
/** * Reads events visible to a user. * * Includes layers and possibly public access if enabled * * @param string $user Username * @param bool $want_repeated Get repeating events? * @param string $date_filter SQL phrase starting with AND, to be appended to * the WHERE clause. May be empty string. * @param int $cat_id Category ID to filter on. May be empty. * * @return array Array of events sorted by time of day */ function query_events ( $user, $want_repeated, $date_filter, $cat_id = '' ) { global $login; global $layers, $public_access_default_visible; $result = array (); $layers_byuser = array ();
$sql = "SELECT webcal_entry.cal_name, webcal_entry.cal_description, " . "webcal_entry.cal_date, webcal_entry.cal_time, " . "webcal_entry.cal_id, webcal_entry.cal_ext_for_id, " . "webcal_entry.cal_priority, " . "webcal_entry.cal_access, webcal_entry.cal_duration, " . "webcal_entry_user.cal_status, " . "webcal_entry_user.cal_category, " . "webcal_entry_user.cal_login "; if ( $want_repeated ) { $sql .= ", " . "webcal_entry_repeats.cal_type, webcal_entry_repeats.cal_end, " . "webcal_entry_repeats.cal_frequency, webcal_entry_repeats.cal_days " . "FROM webcal_entry, webcal_entry_repeats, webcal_entry_user " . "WHERE webcal_entry.cal_id = webcal_entry_repeats.cal_id AND "; } else { $sql .= "FROM webcal_entry, webcal_entry_user WHERE "; } $sql .= "webcal_entry.cal_id = webcal_entry_user.cal_id " . "AND webcal_entry_user.cal_status IN ('A','W') ";
if ( $cat_id != '' ) $sql .= "AND webcal_entry_user.cal_category LIKE '$cat_id' ";
if ( strlen ( $user ) > 0 ) $sql .= "AND (webcal_entry_user.cal_login = '" . $user . "' ";
if ( $user == $login && strlen ( $user ) > 0 ) { if ($layers) foreach ($layers as $layer) { $layeruser = $layer['cal_layeruser'];
$sql .= "OR webcal_entry_user.cal_login = '" . $layeruser . "' ";
// while we are parsing the whole layers array, build ourselves // a new array that will help when we have to check for dups $layers_byuser["$layeruser"] = $layer['cal_dups']; } } if ( $user == $login && strlen ( $user ) && $public_access_default_visible == 'Y' ) { $sql .= "OR webcal_entry_user.cal_login = '__public__' "; } if ( strlen ( $user ) > 0 ) $sql .= ") "; $sql .= $date_filter;
// now order the results by time and by entry id. $sql .= " ORDER BY webcal_entry.cal_time, webcal_entry.cal_id";
//echo "<strong>SQL:</strong> $sql<br />\n"; $res = dbi_query ( $sql ); if ( $res ) { $i = 0; $checkdup_id = -1; $first_i_this_id = -1;
while ( $row = dbi_fetch_row ( $res ) ) {
if ($row[9] == 'R' || $row[9] == 'D') { continue; // don't show rejected/deleted ones } $item = array ( "cal_name" => $row[0], "cal_description" => $row[1], "cal_date" => $row[2], "cal_time" => $row[3], "cal_id" => $row[4], "cal_ext_for_id" => $row[5], "cal_priority" => $row[6], "cal_access" => $row[7], "cal_duration" => $row[8], "cal_status" => $row[9], "cal_category" => $row[10], "cal_login" => $row[11], "cal_exceptions" => array() ); if ( $want_repeated && ! empty ( $row[12] ) ) { $item['cal_type'] = empty ( $row[12] ) ? "" : $row[12]; $item['cal_end'] = empty ( $row[13] ) ? "" : $row[13]; $item['cal_frequency'] = empty ( $row[14] ) ? "" : $row[14]; $item['cal_days'] = empty ( $row[15] ) ? "" : $row[15]; }
if ( $item['cal_id'] != $checkdup_id ) { $checkdup_id = $item['cal_id']; $first_i_this_id = $i; }
if ( $item['cal_login'] == $user ) { // Insert this one before all other ones with this ID. my_array_splice ( $result, $first_i_this_id, 0, array($item) ); $i++;
if ($first_i_this_id + 1 < $i) { // There's another one with the same ID as the one we inserted. // Check for dup and if so, delete it. $other_item = $result[$first_i_this_id + 1]; if ($layers_byuser[$other_item['cal_login']] == 'N') { // NOTE: array_splice requires PHP4 my_array_splice ( $result, $first_i_this_id + 1, 1, "" ); $i--; } } } else { if ($i == $first_i_this_id || ( ! empty ( $layers_byuser[$item['cal_login']] ) && $layers_byuser[$item['cal_login']] != 'N' ) ) { // This item either is the first one with its ID, or allows dups. // Add it to the end of the array. $result [$i++] = $item; } } } dbi_free_result ( $res ); }
// Now load event exceptions and store as array in 'cal_exceptions' field if ( $want_repeated ) { for ( $i = 0; $i < count ( $result ); $i++ ) { if ( ! empty ( $result[$i]['cal_id'] ) ) { $res = dbi_query ( "SELECT cal_date FROM webcal_entry_repeats_not " . "WHERE cal_id = " . $result[$i]['cal_id'] ); while ( $row = dbi_fetch_row ( $res ) ) { $result[$i]['cal_exceptions'][] = $row[0]; } } } }
return $result; }
/** * Reads all the repeated events for a user. * * This is only called once per page request to improve performance. All the * events get loaded into the array <var>$repeated_events</var> sorted by time of day (not * date). * * This will load all the repeated events into memory. * * <b>Notes:</b> * - To get which events repeat on a specific date, use * {@link get_repeating_entries()}. * - To get all the dates that one specific event repeats on, call * {@link get_all_dates()}. * * @param string $user Username * @param int $cat_id Category ID to filter on (May be empty) * @param string $date Cutoff date for repeating event endtimes in YYYYMMDD * format (may be empty) * * @return Array of repeating events sorted by time of day * * @uses query_events */ function read_repeated_events ( $user, $cat_id = '', $date = '' ) { global $login; global $layers;
$filter = ($date != '') ? "AND (webcal_entry_repeats.cal_end >= $date OR webcal_entry_repeats.cal_end IS NULL) " : ''; return query_events ( $user, true, $filter, $cat_id ); }
/** * Returns all the dates a specific event will fall on accounting for the repeating. * * Any event with no end will be assigned one. * * @param string $date Initial date in raw format * @param string $rpt_type Repeating type as stored in the database * @param string $end End date * @param string $days Days events occurs on (for weekly) * @param array $ex_dates Array of exception dates for this event in YYYYMMDD format * @param int $freq Frequency of repetition * * @return array Array of dates (in UNIX time format) */ function get_all_dates ( $date, $rpt_type, $end, $days, $ex_days, $freq=1 ) { global $conflict_repeat_months, $days_per_month, $ldays_per_month; global $ONE_DAY; //echo "get_all_dates ( $date, '$rpt_type', $end, '$days', [array], $freq ) <br>\n"; $currentdate = floor($date/$ONE_DAY)*$ONE_DAY; $realend = floor($end/$ONE_DAY)*$ONE_DAY; $dateYmd = date ( "Ymd", $date ); if ($end=='NULL') { // Check for $conflict_repeat_months months into future for conflicts $thismonth = substr($dateYmd, 4, 2); $thisyear = substr($dateYmd, 0, 4); $thisday = substr($dateYmd, 6, 2); $thismonth += $conflict_repeat_months; if ($thismonth > 12) { $thisyear++; $thismonth -= 12; } $realend = mktime(3,0,0,$thismonth,$thisday,$thisyear); } $ret = array(); $ret[0] = $date; //do iterative checking here. //I floored the $realend so I check it against the floored date if ($rpt_type && $currentdate < $realend) { $cdate = $date; if (!$freq) $freq = 1; $n = 1; if ($rpt_type == 'daily') { //we do inclusive counting on end dates. $cdate += $ONE_DAY * $freq; while ($cdate <= $realend+$ONE_DAY) { if ( ! is_exception ( $cdate, $ex_days ) ) $ret[$n++]=$cdate; $cdate += $ONE_DAY * $freq; } } else if ($rpt_type == 'weekly') { $daysarray = array(); $r=0; $dow = date("w",$date); $cdate = $date - ($dow * $ONE_DAY); for ($i = 0; $i < 7; $i++) { $isDay = substr($days, $i, 1); if (strcmp($isDay,"y")==0) { $daysarray[$r++]=$i * $ONE_DAY; } } //we do inclusive counting on end dates. while ($cdate <= $realend+$ONE_DAY) { //add all of the days of the week. for ($j=0; $j<$r;$j++) { $td = $cdate + $daysarray[$j]; if ($td >= $date) { if ( ! is_exception ( $td, $ex_days ) ) $ret[$n++] = $td; } } //skip to the next week in question. $cdate += ( $ONE_DAY * 7 ) * $freq; } } else if ($rpt_type == 'monthlyByDay') { $dow = date('w', $date); $thismonth = substr($dateYmd, 4, 2); $thisyear = substr($dateYmd, 0, 4); $week = floor(date("d", $date)/7); $thismonth+=$freq; //dow1 is the weekday that the 1st of the month falls on $dow1 = date('w',mktime (3,0,0,$thismonth,1,$thisyear)); $t = $dow - $dow1; if ($t < 0) $t += 7; $day = 7*$week + $t + 1; $cdate = mktime (3,0,0,$thismonth,$day,$thisyear); while ($cdate <= $realend+$ONE_DAY) { if ( ! is_exception ( $cdate, $ex_days ) ) $ret[$n++] = $cdate; $thismonth+=$freq; //dow1 is the weekday that the 1st of the month falls on $dow1time = mktime ( 3, 0, 0, $thismonth, 1, $thisyear ); $dow1 = date ( 'w', $dow1time ); $t = $dow - $dow1; if ($t < 0) $t += 7; $day = 7*$week + $t + 1; $cdate = mktime (3,0,0,$thismonth,$day,$thisyear); } } else if ($rpt_type == 'monthlyByDayR') { // by weekday of month reversed (i.e., last Monday of month) $dow = date('w', $date); $thisday = substr($dateYmd, 6, 2); $thismonth = substr($dateYmd, 4, 2); $thisyear = substr($dateYmd, 0, 4); // get number of days in this month $daysthismonth = $thisyear % 4 == 0 ? $ldays_per_month[$thismonth] : $days_per_month[$thismonth]; // how many weekdays like this one remain in the month? // 0=last one, 1=one more after this one, etc. $whichWeek = floor ( ( $daysthismonth - $thisday ) / 7 ); // find first repeat date $thismonth += $freq; if ( $thismonth > 12 ) { $thisyear++; $thismonth -= 12; } // get weekday for last day of month $dowLast += date('w',mktime (3,0,0,$thismonth + 1, -1,$thisyear)); if ( $dowLast >= $dow ) { // last weekday is in last week of this month $day = $daysthismonth - ( $dowLast - $dow ) - ( 7 * $whichWeek ); } else { // last weekday is NOT in last week of this month $day = $daysthismonth - ( $dowLast - $dow ) - ( 7 * ( $whichWeek + 1 ) ); } $cdate = mktime (3,0,0,$thismonth,$day,$thisyear); while ($cdate <= $realend+$ONE_DAY) { if ( ! is_exception ( $cdate, $ex_days ) ) $ret[$n++] = $cdate; $thismonth += $freq; if ( $thismonth > 12 ) { $thisyear++; $thismonth -= 12; } // get weekday for last day of month $dowLast += date('w',mktime (3,0,0,$thismonth + 1, -1,$thisyear)); if ( $dowLast >= $dow ) { // last weekday is in last week of this month $day = $daysthismonth - ( $dowLast - $dow ) - ( 7 * $whichWeek ); } else { // last weekday is NOT in last week of this month $day = $daysthismonth - ( $dowLast - $dow ) - ( 7 * ( $whichWeek + 1 ) ); } $cdate = mktime (3,0,0,$thismonth,$day,$thisyear); } } else if ($rpt_type == 'monthlyByDate') { $thismonth = substr($dateYmd, 4, 2); $thisyear = substr($dateYmd, 0, 4); $thisday = substr($dateYmd, 6, 2); $hour = date('H',$date); $minute = date('i',$date);
$thismonth += $freq; $cdate = mktime (3,0,0,$thismonth,$thisday,$thisyear); while ($cdate <= $realend+$ONE_DAY) { if ( ! is_exception ( $cdate, $ex_days ) ) $ret[$n++] = $cdate; $thismonth += $freq; $cdate = mktime (3,0,0,$thismonth,$thisday,$thisyear); } } else if ($rpt_type == 'yearly') { $thismonth = substr($dateYmd, 4, 2); $thisyear = substr($dateYmd, 0, 4); $thisday = substr($dateYmd, 6, 2); $hour = date('H',$date); $minute = date('i',$date);
$thisyear += $freq; $cdate = mktime (3,0,0,$thismonth,$thisday,$thisyear); while ($cdate <= $realend+$ONE_DAY) { if ( ! is_exception ( $cdate, $ex_days ) ) $ret[$n++] = $cdate; $thisyear += $freq; $cdate = mktime (3,0,0,$thismonth,$thisday,$thisyear); } } } return $ret; }
/** * Gets all the repeating events for the specified date. * * <b>Note:</b> * The global variable <var>$repeated_events</var> needs to be * set by calling {@link read_repeated_events()} first. * * @param string $user Username * @param string $date Date to get events for in YYYYMMDD format * @param bool $get_unapproved Include unapproved events in results? * * @return mixed The query result resource on queries (which can then be * passed to {@link dbi_fetch_row()} to obtain the results), or * true/false on insert or delete queries. * * @global array Array of repeating events retreived using {@link read_repeated_events()} */ function get_repeating_entries ( $user, $dateYmd, $get_unapproved=true ) { global $repeated_events; $n = 0; $ret = array (); //echo count($repeated_events)."<br />\n"; for ( $i = 0; $i < count ( $repeated_events ); $i++ ) { if ( $repeated_events[$i]['cal_status'] == 'A' || $get_unapproved ) { if ( repeated_event_matches_date ( $repeated_events[$i], $dateYmd ) ) { // make sure this is not an exception date... $unixtime = date_to_epoch ( $dateYmd ); if ( ! is_exception ( $unixtime, $repeated_events[$i]['cal_exceptions'] ) ) $ret[$n++] = $repeated_events[$i]; } } } return $ret; }
/** * Determines whether the event passed in will fall on the date passed. * * @param array $event The event as an array * @param string $dateYmd Date to check in YYYYMMDD format * * @return bool Does <var>$event</var> occur on <var>$dateYmd</var>? */ function repeated_event_matches_date($event,$dateYmd) { global $days_per_month, $ldays_per_month, $ONE_DAY; // only repeat after the beginning, and if there is an end // before the end $date = date_to_epoch ( $dateYmd ); $thisyear = substr($dateYmd, 0, 4); $start = date_to_epoch ( $event['cal_date'] ); $end = date_to_epoch ( $event['cal_end'] ); $freq = $event['cal_frequency']; $thismonth = substr($dateYmd, 4, 2); if ($event['cal_end'] && $dateYmd > date("Ymd",$end) ) return false; if ( $dateYmd <= date("Ymd",$start) ) return false; $id = $event['cal_id'];
if ($event['cal_type'] == 'daily') { if ( (floor(($date - $start)/$ONE_DAY)%$freq) ) return false; return true; } else if ($event['cal_type'] == 'weekly') { $dow = date("w", $date); $dow1 = date("w", $start); $isDay = substr($event['cal_days'], $dow, 1); $wstart = $start - ($dow1 * $ONE_DAY); if (floor(($date - $wstart)/604800)%$freq) return false; return (strcmp($isDay,"y") == 0); } else if ($event['cal_type'] == 'monthlyByDay') { $dowS = date("w", $start); $dow = date("w", $date); // do this comparison first in hopes of best performance if ( $dowS != $dow ) return false; $mthS = date("m", $start); $yrS = date("Y", $start); $dayS = floor(date("d", $start)); $dowS1 = ( date ( "w", $start - ( $ONE_DAY * ( $dayS - 1 ) ) ) + 35 ) % 7; $days_in_first_weekS = ( 7 - $dowS1 ) % 7; $whichWeekS = floor ( ( $dayS - $days_in_first_weekS ) / 7 ); if ( $dowS >= $dowS1 && $days_in_first_weekS ) $whichWeekS++; //echo "dayS=$dayS;dowS=$dowS;dowS1=$dowS1;wWS=$whichWeekS<br />\n"; $mth = date("m", $date); $yr = date("Y", $date); $day = date("d", $date); $dow1 = ( date ( "w", $date - ( $ONE_DAY * ( $day - 1 ) ) ) + 35 ) % 7; $days_in_first_week = ( 7 - $dow1 ) % 7; $whichWeek = floor ( ( $day - $days_in_first_week ) / 7 ); if ( $dow >= $dow1 && $days_in_first_week ) $whichWeek++; //echo "day=$day;dow=$dow;dow1=$dow1;wW=$whichWeek<br />\n";
if ((($yr - $yrS)*12 + $mth - $mthS) % $freq) return false;
return ( $whichWeek == $whichWeekS ); } else if ($event['cal_type'] == 'monthlyByDayR') { $dowS = date("w", $start); $dow = date("w", $date); // do this comparison first in hopes of best performance if ( $dowS != $dow ) return false;
$dayS = ceil(date("d", $start)); $mthS = ceil(date("m", $start)); $yrS = date("Y", $start); $daysthismonthS = $mthS % 4 == 0 ? $ldays_per_month[$mthS] : $days_per_month[$mthS]; $whichWeekS = floor ( ( $daysthismonthS - $dayS ) / 7 );
$day = ceil(date("d", $date)); $mth = ceil(date("m", $date)); $yr = date("Y", $date); $daysthismonth = $mth % 4 == 0 ? $ldays_per_month[$mth] : $days_per_month[$mth]; $whichWeek = floor ( ( $daysthismonth - $day ) / 7 );
if ((($yr - $yrS)*12 + $mth - $mthS) % $freq) return false;
return ( $whichWeekS == $whichWeek ); } else if ($event['cal_type'] == 'monthlyByDate') { $mthS = date("m", $start); $yrS = date("Y", $start);
$mth = date("m", $date); $yr = date("Y", $date);
if ((($yr - $yrS)*12 + $mth - $mthS) % $freq) return false;
return (date("d", $date) == date("d", $start)); } else if ($event['cal_type'] == 'yearly') { $yrS = date("Y", $start); $yr = date("Y", $date);
if (($yr - $yrS)%$freq) return false;
return (date("dm", $date) == date("dm", $start)); } else { // unknown repeat type return false; } return false; }
/** * Converts a date to a timestamp. * * @param string $d Date in YYYYMMDD format * * @return int Timestamp representing 3:00 (or 4:00 if during Daylight Saving * Time) in the morning on that day */ function date_to_epoch ( $d ) { if ( $d == 0 ) return 0; $T = mktime ( 3, 0, 0, substr ( $d, 4, 2 ), substr ( $d, 6, 2 ), substr ( $d, 0, 4 ) ); $lt = localtime($T); if ($lt[8]) { return mktime ( 4, 0, 0, substr ( $d, 4, 2 ), substr ( $d, 6, 2 ), substr ( $d, 0, 4 ) ); } else { return $T; } }
/** * Checks if a date is an exception for an event. * * @param string $date Date in YYYYMMDD format * @param array $exdays Array of dates in YYYYMMDD format * * @ignore */ function is_exception ( $date, $ex_days ) { $size = count ( $ex_days ); $count = 0; $date = date ( "Ymd", $date ); //echo "Exception $date check.. count is $size <br />\n"; while ( $count < $size ) { //echo "Exception date: $ex_days[$count] <br />\n"; if ( $date == $ex_days[$count++] ) return true; } return false; }
/** * Gets the Sunday of the week that the specified date is in. * * If the date specified is a Sunday, then that date is returned. * * @param int $year Year * @param int $month Month (1-12) * @param int $day Day of the month * * @return int The date (in UNIX timestamp format) * * @see get_monday_before */ function get_sunday_before ( $year, $month, $day ) { $weekday = date ( "w", mktime ( 3, 0, 0, $month, $day, $year ) ); $newdate = mktime ( 3, 0, 0, $month, $day - $weekday, $year ); return $newdate; }
/** * Gets the Monday of the week that the specified date is in. * * If the date specified is a Monday, then that date is returned. * * @param int $year Year * @param int $month Month (1-12) * @param int $day Day of the month * * @return int The date (in UNIX timestamp format) * * @see get_sunday_before */ function get_monday_before ( $year, $month, $day ) { $weekday = date ( "w", mktime ( 3, 0, 0, $month, $day, $year ) ); if ( $weekday == 0 ) return mktime ( 3, 0, 0, $month, $day - 6, $year ); if ( $weekday == 1 ) return mktime ( 3, 0, 0, $month, $day, $year ); return mktime ( 3, 0, 0, $month, $day - ( $weekday - 1 ), $year ); }
/** * Returns the week number for specified date. * * Depends on week numbering settings. * * @param int $date Date in UNIX timestamp format * * @return string The week number of the specified date */ function week_number ( $date ) { $tmp = getdate($date); $iso = gregorianToISO($tmp['mday'], $tmp['mon'], $tmp['year']); $parts = explode('-',$iso); $week_number = intval($parts[1]); return sprintf("%02d",$week_number); }
/** * Generates the HTML for an add/edit/delete icon. * * This function is not yet used. Some of the places that will call it have to * be updated to also get the event owner so we know if the current user has * access to edit and delete. * * @param int $id Event ID * @param bool $can_edit Can this user edit this event? * @param bool $can_delete Can this user delete this event? * * @return HTML for add/edit/delete icon. * * @ignore */ function icon_text ( $id, $can_edit, $can_delete ) { global $readonly, $is_admin; $ret = "<a title=\"" . translate("View this entry") . "\" href=\"view_entry.php?id=$id\"><img src=\"view.gif\" alt=\"" . translate("View this entry") . "\" style=\"border-width:0px; width:10px; height:10px;\" /></a>"; if ( $can_edit && $readonly == "N" ) $ret .= "<a title=\"" . translate("Edit entry") . "\" href=\"edit_entry.php?id=$id\"><img src=\"edit.gif\" alt=\"" . translate("Edit entry") . "\" style=\"border-width:0px; width:10px; height:10px;\" /></a>"; if ( $can_delete && ( $readonly == "N" || $is_admin ) ) $ret .= "<a title=\"" . translate("Delete entry") . "\" href=\"del_entry.php?id=$id\" onclick=\"return confirm('" . translate("Are you sure you want to delete this entry?") . "\\n\\n" . translate("This will delete this entry for all users.") . "');\"><img src=\"delete.gif\" alt=\"" . translate("Delete entry") . "\" style=\"border-width:0px; width:10px; height:10px;\" /></a>"; return $ret; }
/** * Prints all the calendar entries for the specified user for the specified date. * * If we are displaying data from someone other than * the logged in user, then check the access permission of the entry. * * @param string $date Date in YYYYMMDD format * @param string $user Username * @param bool $ssi Is this being called from week_ssi.php? */ function print_date_entries ( $date, $user, $ssi ) { global $events, $readonly, $is_admin, $login, $public_access, $public_access_can_add, $cat_id; $cnt = 0; $get_unapproved = ( $GLOBALS["DISPLAY_UNAPPROVED"] == "Y" ); // public access events always must be approved before being displayed if ( $user == "__public__" ) $get_unapproved = false;
$year = substr ( $date, 0, 4 ); $month = substr ( $date, 4, 2 ); $day = substr ( $date, 6, 2 ); $dateu = mktime ( 3, 0, 0, $month, $day, $year ); $can_add = ( $readonly == "N" || $is_admin ); if ( $public_access == "Y" && $public_access_can_add != "Y" && $login == "__public__" ) $can_add = false; if ( $readonly == 'Y' ) $can_add = false; if ( ! $ssi && $can_add ) { print "<a title=\"" . translate("New Entry") . "\" href=\"edit_entry.php?"; if ( strcmp ( $user, $GLOBALS["login"] ) ) print "user=$user&"; if ( ! empty ( $cat_id ) ) print "cat_id=$cat_id&"; print "date=$date\"><img src=\"new.gif\" alt=\"" . translate("New Entry") . "\" class=\"new\" /></a>"; $cnt++; } if ( ! $ssi ) { echo "<a class=\"dayofmonth\" href=\"day.php?"; if ( strcmp ( $user, $GLOBALS["login"] ) ) echo "user=$user&"; if ( ! empty ( $cat_id ) ) echo "cat_id=$cat_id&"; echo "date=$date\">$day</a>"; if ( $GLOBALS["DISPLAY_WEEKNUMBER"] == "Y" && date ( "w", $dateu ) == $GLOBALS["WEEK_START"] ) { echo " <a title=\"" . translate("Week") . " " . week_number ( $dateu ) . "\" href=\"week.php?date=$date"; if ( strcmp ( $user, $GLOBALS["login"] ) ) echo "&user=$user"; if ( ! empty ( $cat_id ) ) echo "&cat_id=$cat_id"; echo "\" class=\"weeknumber\">"; echo "(" . translate("Week") . " " . week_number ( $dateu ) . ")</a>"; } print "<br />\n"; $cnt++; } // get all the repeating events for this date and store in array $rep $rep = get_repeating_entries ( $user, $date, $get_unapproved ); $cur_rep = 0;
// get all the non-repeating events for this date and store in $ev $ev = get_entries ( $user, $date, $get_unapproved );
for ( $i = 0; $i < count ( $ev ); $i++ ) { // print out any repeating events that are before this one... while ( $cur_rep < count ( $rep ) && $rep[$cur_rep]['cal_time'] < $ev[$i]['cal_time'] ) { if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) { if ( ! empty ( $rep[$cur_rep]['cal_ext_for_id'] ) ) { $viewid = $rep[$cur_rep]['cal_ext_for_id']; $viewname = $rep[$cur_rep]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $rep[$cur_rep]['cal_id']; $viewname = $rep[$cur_rep]['cal_name']; } print_entry ( $viewid, $date, $rep[$cur_rep]['cal_time'], $rep[$cur_rep]['cal_duration'], $viewname, $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] ); $cnt++; } $cur_rep++; } if ( $get_unapproved || $ev[$i]['cal_status'] == 'A' ) { if ( ! empty ( $ev[$i]['cal_ext_for_id'] ) ) { $viewid = $ev[$i]['cal_ext_for_id']; $viewname = $ev[$i]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $ev[$i]['cal_id']; $viewname = $ev[$i]['cal_name']; } print_entry ( $viewid, $date, $ev[$i]['cal_time'], $ev[$i]['cal_duration'], $viewname, $ev[$i]['cal_description'], $ev[$i]['cal_status'], $ev[$i]['cal_priority'], $ev[$i]['cal_access'], $ev[$i]['cal_login'], $ev[$i]['cal_category'] ); $cnt++; } } // print out any remaining repeating events while ( $cur_rep < count ( $rep ) ) { if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) { if ( ! empty ( $rep[$cur_rep]['cal_ext_for_id'] ) ) { $viewid = $rep[$cur_rep]['cal_ext_for_id']; $viewname = $rep[$cur_rep]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $rep[$cur_rep]['cal_id']; $viewname = $rep[$cur_rep]['cal_name']; } print_entry ( $viewid, $date, $rep[$cur_rep]['cal_time'], $rep[$cur_rep]['cal_duration'], $viewname, $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] ); $cnt++; } $cur_rep++; } if ( $cnt == 0 ) echo " "; // so the table cell has at least something }
/** * Checks to see if two events overlap. * * @param string $time1 Time 1 in HHMMSS format * @param int $duration1 Duration 1 in minutes * @param string $time2 Time 2 in HHMMSS format * @param int $duration2 Duration 2 in minutes * * @return bool True if the two times overlap, false if they do not */ function times_overlap ( $time1, $duration1, $time2, $duration2 ) { //echo "times_overlap ( $time1, $duration1, $time2, $duration2 )<br />\n"; $hour1 = (int) ( $time1 / 10000 ); $min1 = ( $time1 / 100 ) % 100; $hour2 = (int) ( $time2 / 10000 ); $min2 = ( $time2 / 100 ) % 100; // convert to minutes since midnight // remove 1 minute from duration so 9AM-10AM will not conflict with 10AM-11AM if ( $duration1 > 0 ) $duration1 -= 1; if ( $duration2 > 0 ) $duration2 -= 1; $tmins1start = $hour1 * 60 + $min1; $tmins1end = $tmins1start + $duration1; $tmins2start = $hour2 * 60 + $min2; $tmins2end = $tmins2start + $duration2; //echo "tmins1start=$tmins1start, tmins1end=$tmins1end, tmins2start=$tmins2start, tmins2end=$tmins2end<br />\n"; if ( ( $tmins1start >= $tmins2end ) || ( $tmins2start >= $tmins1end ) ) return false; return true; }
/** * Checks for conflicts. * * Find overlaps between an array of dates and the other dates in the database. * * Limits on number of appointments: if enabled in System Settings * (<var>$limit_appts</var> global variable), too many appointments can also * generate a scheduling conflict. * * @todo Update this to handle exceptions to repeating events * * @param array $dates Array of dates in YYYYMMDD format that is * checked for overlaps. * @param int $duration Event duration in minutes * @param int $hour Hour of event (0-23) * @param int $minute Minute of the event (0-59) * @param array $participants Array of users whose calendars are to be checked * @param string $login The current user name * @param int $id Current event id (this keeps overlaps from * wrongly checking an event against itself) * * @return Empty string for no conflicts or return the HTML of the * conflicts when one or more are found. */ function check_for_conflicts ( $dates, $duration, $hour, $minute, $participants, $login, $id ) { global $single_user_login, $single_user; global $repeated_events, $limit_appts, $limit_appts_number; if (!count($dates)) return false;
$evtcnt = array ();
$sql = "SELECT distinct webcal_entry_user.cal_login, webcal_entry.cal_time," . "webcal_entry.cal_duration, webcal_entry.cal_name, " . "webcal_entry.cal_id, webcal_entry.cal_ext_for_id, " . "webcal_entry.cal_access, " . "webcal_entry_user.cal_status, webcal_entry.cal_date " . "FROM webcal_entry, webcal_entry_user " . "WHERE webcal_entry.cal_id = webcal_entry_user.cal_id " . "AND ("; for ($x = 0; $x < count($dates); $x++) { if ($x != 0) $sql .= " OR "; $sql.="webcal_entry.cal_date = " . date ( "Ymd", $dates[$x] ); } $sql .= ") AND webcal_entry.cal_time >= 0 " . "AND webcal_entry_user.cal_status IN ('A','W') AND ( "; if ( $single_user == "Y" ) { $participants[0] = $single_user_login; } else if ( strlen ( $participants[0] ) == 0 ) { // likely called from a form with 1 user $participants[0] = $login; } for ( $i = 0; $i < count ( $participants ); $i++ ) { if ( $i > 0 ) $sql .= " OR "; $sql .= " webcal_entry_user.cal_login = '" . $participants[$i] . "'"; } $sql .= " )"; // make sure we don't get something past the end date of the // event we are saving. //echo "SQL: $sql<br />\n"; $conflicts = ""; $res = dbi_query ( $sql ); $found = array(); $count = 0; if ( $res ) { $time1 = sprintf ( "%d%02d00", $hour, $minute ); $duration1 = sprintf ( "%d", $duration ); while ( $row = dbi_fetch_row ( $res ) ) { //Add to an array to see if it has been found already for the next part. $found[$count++] = $row[4]; // see if either event overlaps one another if ( $row[4] != $id && ( empty ( $row[5] ) || $row[5] != $id ) ) { $time2 = $row[1]; $duration2 = $row[2]; $cntkey = $row[0] . "-" . $row[8]; if ( empty ( $evtcnt[$cntkey] ) ) $evtcnt[$cntkey] = 0; else $evtcnt[$cntkey]++; $over_limit = 0; if ( $limit_appts == "Y" && $limit_appts_number > 0 && $evtcnt[$cntkey] >= $limit_appts_number ) { $over_limit = 1; } if ( $over_limit || times_overlap ( $time1, $duration1, $time2, $duration2 ) ) { $conflicts .= "<li>"; if ( $single_user != "Y" ) $conflicts .= "$row[0]: "; if ( $row[6] == 'R' && $row[0] != $login ) $conflicts .= "(" . translate("Private") . ")"; else { $conflicts .= "<a href=\"view_entry.php?id=$row[4]"; if ( $row[0] != $login ) $conflicts .= "&user=$row[0]"; $conflicts .= "\">$row[3]</a>"; } if ( $duration2 == ( 24 * 60 ) ) { $conflicts .= " (" . translate("All day event") . ")"; } else { $conflicts .= " (" . display_time ( $time2 ); if ( $duration2 > 0 ) $conflicts .= "-" . display_time ( add_duration ( $time2, $duration2 ) ); $conflicts .= ")"; } $conflicts .= " on " . date_to_str( $row[8] ); if ( $over_limit ) { $tmp = translate ( "exceeds limit of XXX events per day" ); $tmp = str_replace ( "XXX", $limit_appts_number, $tmp ); $conflicts .= " (" . $tmp . ")"; } $conflicts .= "</li>\n"; } } } dbi_free_result ( $res ); } else { echo translate("Database error") . ": " . dbi_error (); exit; } //echo "<br />\nhello"; for ($q=0;$q<count($participants);$q++) { $time1 = sprintf ( "%d%02d00", $hour, $minute ); $duration1 = sprintf ( "%d", $duration ); //This date filter is not necessary for functional reasons, but it eliminates some of the //events that couldn't possibly match. This could be made much more complex to put more //of the searching work onto the database server, or it could be dropped all together to put //the searching work onto the client. $date_filter = "AND (webcal_entry.cal_date <= " . date("Ymd",$dates[count($dates)-1]); $date_filter .= " AND (webcal_entry_repeats.cal_end IS NULL OR webcal_entry_repeats.cal_end >= " . date("Ymd",$dates[0]) . "))"; //Read repeated events for the participants only once for a participant for //for performance reasons. $repeated_events=query_events($participants[$q],true,$date_filter); //for ($dd=0; $dd<count($repeated_events); $dd++) { // echo $repeated_events[$dd]['cal_id'] . "<br />"; //} for ($i=0; $i < count($dates); $i++) { $dateYmd = date ( "Ymd", $dates[$i] ); $list = get_repeating_entries($participants[$q],$dateYmd); $thisyear = substr($dateYmd, 0, 4); $thismonth = substr($dateYmd, 4, 2); for ($j=0; $j < count($list);$j++) { //okay we've narrowed it down to a day, now I just gotta check the time... //I hope this is right... $row = $list[$j]; if ( $row['cal_id'] != $id && ( empty ( $row['cal_ext_for_id'] ) || $row['cal_ext_for_id'] != $id ) ) { $time2 = $row['cal_time']; $duration2 = $row['cal_duration']; if ( times_overlap ( $time1, $duration1, $time2, $duration2 ) ) { $conflicts .= "<li>"; if ( $single_user != "Y" ) $conflicts .= $row['cal_login'] . ": "; if ( $row['cal_access'] == 'R' && $row['cal_login'] != $login ) $conflicts .= "(" . translate("Private") . ")"; else { $conflicts .= "<a href=\"view_entry.php?id=" . $row['cal_id']; if ( ! empty ( $user ) && $user != $login ) $conflicts .= "&user=$user"; $conflicts .= "\">" . $row['cal_name'] . "</a>"; } $conflicts .= " (" . display_time ( $time2 ); if ( $duration2 > 0 ) $conflicts .= "-" . display_time ( add_duration ( $time2, $duration2 ) ); $conflicts .= ")"; $conflicts .= " on " . date("l, F j, Y", $dates[$i]); $conflicts .= "</li>\n"; } } } } } return $conflicts; }
/** * Converts a time format HHMMSS (like 130000 for 1PM) into number of minutes past midnight. * * @param string $time Input time in HHMMSS format * * @return int The number of minutes since midnight */ function time_to_minutes ( $time ) { $h = (int) ( $time / 10000 ); $m = (int) ( $time / 100 ) % 100; $num = $h * 60 + $m; return $num; }
/** * Calculates which row/slot this time represents. * * This is used in day and week views where hours of the time are separeted * into different cells in a table. * * <b>Note:</b> the global variable <var>$TIME_SLOTS</var> is used to determine * how many time slots there are and how many minutes each is. This variable * is defined user preferences (or defaulted to admin system settings). * * @param string $time Input time in HHMMSS format * @param bool $round_down Should we change 1100 to 1059? * (This will make sure a 10AM-100AM appointment just * shows up in the 10AM slow and not in the 11AM slot * also.) * * @return int The time slot index */ function calc_time_slot ( $time, $round_down = false ) { global $TIME_SLOTS, $TZ_OFFSET;
$interval = ( 24 * 60 ) / $TIME_SLOTS; $mins_since_midnight = time_to_minutes ( $time ); $ret = (int) ( $mins_since_midnight / $interval ); if ( $round_down ) { if ( $ret * $interval == $mins_since_midnight ) $ret--; } //echo "$mins_since_midnight / $interval = $ret <br />\n"; if ( $ret > $TIME_SLOTS ) $ret = $TIME_SLOTS;
//echo "<br />\ncalc_time_slot($time) = $ret <br />\nTIME_SLOTS = $TIME_SLOTS<br />\n"; return $ret; }
/** * Generates the HTML for an icon to add a new event. * * @param string $date Date for new event in YYYYMMDD format * @param int $hour Hour of day (0-23) * @param int $minute Minute of the hour (0-59) * @param string $user Participant to initially select for new event * * @return string The HTML for the add event icon */ function html_for_add_icon ( $date=0,$hour="", $minute="", $user="" ) { global $TZ_OFFSET; global $login, $readonly, $cat_id; $u_url = '';
if ( $readonly == 'Y' ) return '';
if ( $minute < 0 ) { $minute = abs($minute); $hour = $hour -1; } if ( ! empty ( $user ) && $user != $login ) $u_url = "user=$user&"; if ( isset ( $hour ) && $hour != NULL ) $hour += $TZ_OFFSET; return "<a title=\"" . translate("New Entry") . "\" href=\"edit_entry.php?" . $u_url . "date=$date" . ( isset ( $hour ) && $hour != NULL && $hour >= 0 ? "&hour=$hour" : "" ) . ( $minute > 0 ? "&minute=$minute" : "" ) . ( empty ( $user ) ? "" : "&defusers=$user" ) . ( empty ( $cat_id ) ? "" : "&cat_id=$cat_id" ) . "\"><img src=\"new.gif\" class=\"new\" alt=\"" . translate("New Entry") . "\" /></a>\n"; }
/** * Generates the HTML for an event to be viewed in the week-at-glance (week.php). * * The HTML will be stored in an array (global variable $hour_arr) * indexed on the event's starting hour. * * @param int $id Event id * @param string $date Date of event in YYYYMMDD format * @param string $time Time of event in HHMM format * @param string $name Brief description of event * @param string $description Full description of event * @param string $status Status of event ('A', 'W') * @param int $pri Priority of event * @param string $access Access to event by others ('P', 'R') * @param int $duration Duration of event in minutes * @param string $event_owner User who created event * @param int $event_category Category id for event */ function html_for_event_week_at_a_glance ( $id, $date, $time, $name, $description, $status, $pri, $access, $duration, $event_owner, $event_category=-1 ) { global $first_slot, $last_slot, $hour_arr, $rowspan_arr, $rowspan, $eventinfo, $login, $user; static $key = 0; global $DISPLAY_ICONS, $PHP_SELF, $TIME_SLOTS; global $layers;
$popupid = "eventinfo-day-$id-$key"; $key++; // Figure out which time slot it goes in. if ( $time >= 0 && $duration != ( 24 * 60 ) ) { $ind = calc_time_slot ( $time ); if ( $ind < $first_slot ) $first_slot = $ind; if ( $ind > $last_slot ) $last_slot = $ind; } else $ind = 9999;
if ( $login != $event_owner && strlen ( $event_owner ) ) { $class = "layerentry"; } else { $class = "entry"; if ( $status == "W" ) $class = "unapprovedentry"; } // if we are looking at a view, then always use "entry" if ( strstr ( $PHP_SELF, "view_m.php" ) || strstr ( $PHP_SELF, "view_w.php" ) || strstr ( $PHP_SELF, "view_v.php" ) || strstr ( $PHP_SELF, "view_t.php" ) ) $class = "entry";
// avoid php warning for undefined array index if ( empty ( $hour_arr[$ind] ) ) $hour_arr[$ind] = "";
$catIcon = "icons/cat-" . $event_category . ".gif"; if ( $event_category > 0 && file_exists ( $catIcon ) ) { $hour_arr[$ind] .= "<img src=\"$catIcon\" alt=\"$catIcon\" />"; }
$hour_arr[$ind] .= "<a title=\"" . translate("View this entry") . "\" class=\"$class\" href=\"view_entry.php?id=$id&date=$date"; if ( strlen ( $GLOBALS["user"] ) > 0 ) $hour_arr[$ind] .= "&user=" . $GLOBALS["user"]; $hour_arr[$ind] .= "\" onmouseover=\"window.status='" . translate("View this entry") . "'; show(event, '$popupid'); return true;\" onmouseout=\"hide('$popupid'); return true;\">"; if ( $pri == 3 ) $hour_arr[$ind] .= "<strong>";
if ( $login != $event_owner && strlen ( $event_owner ) ) { if ($layers) foreach ($layers as $layer) { if ( $layer['cal_layeruser'] == $event_owner ) { $in_span = true; $hour_arr[$ind] .= "<span style=\"color:" . $layer['cal_color'] . ";\">"; } } } if ( $duration == ( 24 * 60 ) ) { $timestr = translate("All day event"); } else if ( $time >= 0 ) { $hour_arr[$ind] .= display_time ( $time ) . "» "; $timestr = display_time ( $time ); if ( $duration > 0 ) { // calc end time $h = (int) ( $time / 10000 ); $m = ( $time / 100 ) % 100; $m += $duration; $d = $duration; while ( $m >= 60 ) { $h++; $m -= 60; } $end_time = sprintf ( "%02d%02d00", $h, $m ); $timestr .= "-" . display_time ( $end_time ); } else { $end_time = 0; } if ( empty ( $rowspan_arr[$ind] ) ) $rowspan_arr[$ind] = 0; // avoid warning below // which slot is end time in? take one off so we don't // show 11:00-12:00 as taking up both 11 and 12 slots. $endind = calc_time_slot ( $end_time, true ); if ( $endind == $ind ) $rowspan = 0; else $rowspan = $endind - $ind + 1; if ( $rowspan > $rowspan_arr[$ind] && $rowspan > 1 ) $rowspan_arr[$ind] = $rowspan; } else { $timestr = ""; }
// avoid php warning of undefined index when using .= below if ( empty ( $hour_arr[$ind] ) ) $hour_arr[$ind] = "";
if ( $login != $user && $access == 'R' && strlen ( $user ) ) { $hour_arr[$ind] .= "(" . translate("Private") . ")"; } else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) { $hour_arr[$ind] .= "(" . translate("Private") . ")"; } else if ( $login != $event_owner && strlen ( $event_owner ) ) { $hour_arr[$ind] .= htmlspecialchars ( $name ); if ( ! empty ( $in_span ) ) $hour_arr[$ind] .= "</span>"; //end color span } else { $hour_arr[$ind] .= htmlspecialchars ( $name ); }
if ( $pri == 3 ) $hour_arr[$ind] .= "</strong>"; //end font-weight span $hour_arr[$ind] .= "</a>"; //if ( $DISPLAY_ICONS == "Y" ) { // $hour_arr[$ind] .= icon_text ( $id, true, true ); //} $hour_arr[$ind] .= "<br />\n"; if ( $login != $user && $access == 'R' && strlen ( $user ) ) { $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); } else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) { $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); } else { $eventinfo .= build_event_popup ( $popupid, $event_owner, $description, $timestr, site_extras_for_popup ( $id ) ); } }
/** * Generates the HTML for an event to be viewed in the day-at-glance (day.php). * * The HTML will be stored in an array (global variable $hour_arr) * indexed on the event's starting hour. * * @param int $id Event id * @param string $date Date of event in YYYYMMDD format * @param string $time Time of event in HHMM format * @param string $name Brief description of event * @param string $description Full description of event * @param string $status Status of event ('A', 'W') * @param int $pri Priority of event * @param string $access Access to event by others ('P', 'R') * @param int $duration Duration of event in minutes * @param string $event_owner User who created event * @param int $event_category Category id for event */ function html_for_event_day_at_a_glance ( $id, $date, $time, $name, $description, $status, $pri, $access, $duration, $event_owner, $event_category=-1 ) { global $first_slot, $last_slot, $hour_arr, $rowspan_arr, $rowspan, $eventinfo, $login, $user; static $key = 0; global $layers, $PHP_SELF, $TIME_SLOTS, $TZ_OFFSET;
$popupid = "eventinfo-day-$id-$key"; $key++;
if ( $login != $user && $access == 'R' && strlen ( $user ) ) $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); else $eventinfo .= build_event_popup ( $popupid, $event_owner, $description, "", site_extras_for_popup ( $id ) );
// calculate slot length in minutes $interval = ( 60 * 24 ) / $TIME_SLOTS;
// If TZ_OFFSET make this event before the start of the day or // after the end of the day, adjust the time slot accordingly. if ( $time >= 0 && $duration != ( 24 * 60 ) ) { if ( $time + ( $TZ_OFFSET * 10000 ) > 240000 ) $time -= 240000; else if ( $time + ( $TZ_OFFSET * 10000 ) < 0 ) $time += 240000; $ind = calc_time_slot ( $time ); if ( $ind < $first_slot ) $first_slot = $ind; if ( $ind > $last_slot ) $last_slot = $ind; } else $ind = 9999; //echo "time = $time <br />\nind = $ind <br />\nfirst_slot = $first_slot<br />\n";
if ( empty ( $hour_arr[$ind] ) ) $hour_arr[$ind] = "";
if ( $login != $event_owner && strlen ( $event_owner ) ) { $class = "layerentry"; } else { $class = "entry"; if ( $status == "W" ) $class = "unapprovedentry"; } // if we are looking at a view, then always use "entry" if ( strstr ( $PHP_SELF, "view_m.php" ) || strstr ( $PHP_SELF, "view_w.php" ) || strstr ( $PHP_SELF, "view_v.php" ) || strstr ( $PHP_SELF, "view_t.php" ) ) $class = "entry";
$catIcon = "icons/cat-" . $event_category . ".gif"; if ( $event_category > 0 && file_exists ( $catIcon ) ) { $hour_arr[$ind] .= "<img src=\"$catIcon\" alt=\"$catIcon\" />"; }
$hour_arr[$ind] .= "<a title=\"" . translate("View this entry") . "\" class=\"$class\" href=\"view_entry.php?id=$id&date=$date"; if ( strlen ( $GLOBALS["user"] ) > 0 ) $hour_arr[$ind] .= "&user=" . $GLOBALS["user"]; $hour_arr[$ind] .= "\" onmouseover=\"window.status='" . translate("View this entry") . "'; show(event, '$popupid'); return true;\" onmouseout=\"hide('$popupid'); return true;\">"; if ( $pri == 3 ) $hour_arr[$ind] .= "<strong>";
if ( $login != $event_owner && strlen ( $event_owner ) ) { if ($layers) foreach ($layers as $layer) { if ( $layer['cal_layeruser'] == $event_owner) { $in_span = true; $hour_arr[$ind] .= "<span style=\"color:" . $layer['cal_color'] . ";\">"; } } }
if ( $duration == ( 24 * 60 ) ) { $hour_arr[$ind] .= "[" . translate("All day event") . "] "; } else if ( $time >= 0 ) { $hour_arr[$ind] .= "[" . display_time ( $time ); if ( $duration > 0 ) { // calc end time $h = (int) ( $time / 10000 ); $m = ( $time / 100 ) % 100; $m += $duration; $d = $duration; while ( $m >= 60 ) { $h++; $m -= 60; } $end_time = sprintf ( "%02d%02d00", $h, $m ); $hour_arr[$ind] .= "-" . display_time ( $end_time ); // which slot is end time in? take one off so we don't // show 11:00-12:00 as taking up both 11 and 12 slots. $endind = calc_time_slot ( $end_time, true ); if ( $endind == $ind ) $rowspan = 0; else $rowspan = $endind - $ind + 1; if ( ! isset ( $rowspan_arr[$ind] ) ) $rowspan_arr[$ind] = 0; if ( $rowspan > $rowspan_arr[$ind] && $rowspan > 1 ) $rowspan_arr[$ind] = $rowspan; } $hour_arr[$ind] .= "] "; } if ( $login != $user && $access == 'R' && strlen ( $user ) ) $hour_arr[$ind] .= "(" . translate("Private") . ")"; else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) $hour_arr[$ind] .= "(" . translate("Private") . ")"; else if ( $login != $event_owner && strlen ( $event_owner ) ) { $hour_arr[$ind] .= htmlspecialchars ( $name ); if ( ! empty ( $in_span ) ) $hour_arr[$ind] .= "</span>"; //end color span }
else $hour_arr[$ind] .= htmlspecialchars ( $name ); if ( $pri == 3 ) $hour_arr[$ind] .= "</strong>"; //end font-weight span
$hour_arr[$ind] .= "</a>"; if ( $GLOBALS["DISPLAY_DESC_PRINT_DAY"] == "Y" ) { $hour_arr[$ind] .= "\n<dl class=\"desc\">\n"; $hour_arr[$ind] .= "<dt>Description:</dt>\n<dd>"; $hour_arr[$ind] .= htmlspecialchars ( $description ); $hour_arr[$ind] .= "</dd>\n</dl>\n"; }
$hour_arr[$ind] .= "<br />\n"; }
/** * Prints all the calendar entries for the specified user for the specified date in day-at-a-glance format. * * If we are displaying data from someone other than * the logged in user, then check the access permission of the entry. * * @param string $date Date in YYYYMMDD format * @param string $user Username of calendar */ function print_day_at_a_glance ( $date, $user, $can_add=0 ) { global $first_slot, $last_slot, $hour_arr, $rowspan_arr, $rowspan; global $TABLEBG, $CELLBG, $TODAYCELLBG, $THFG, $THBG, $TIME_SLOTS, $TZ_OFFSET; global $WORK_DAY_START_HOUR, $WORK_DAY_END_HOUR; global $repeated_events; $get_unapproved = ( $GLOBALS["DISPLAY_UNAPPROVED"] == "Y" ); if ( $user == "__public__" ) $get_unapproved = false; if ( empty ( $TIME_SLOTS ) ) { echo "Error: TIME_SLOTS undefined!<br />\n"; return; }
// $interval is number of minutes per slot $interval = ( 24 * 60 ) / $TIME_SLOTS; $rowspan_arr = array (); for ( $i = 0; $i < $TIME_SLOTS; $i++ ) { $rowspan_arr[$i] = 0; }
// get all the repeating events for this date and store in array $rep $rep = get_repeating_entries ( $user, $date ); $cur_rep = 0;
// Get static non-repeating events $ev = get_entries ( $user, $date, $get_unapproved ); $hour_arr = array (); $interval = ( 24 * 60 ) / $TIME_SLOTS; $first_slot = (int) ( ( ( $WORK_DAY_START_HOUR - $TZ_OFFSET ) * 60 ) / $interval ); $last_slot = (int) ( ( ( $WORK_DAY_END_HOUR - $TZ_OFFSET ) * 60 ) / $interval); //echo "first_slot = $first_slot<br />\nlast_slot = $last_slot<br />\ninterval = $interval<br />\nTIME_SLOTS = $TIME_SLOTS<br />\n"; $rowspan_arr = array (); $all_day = 0; for ( $i = 0; $i < count ( $ev ); $i++ ) { // print out any repeating events that are before this one... while ( $cur_rep < count ( $rep ) && $rep[$cur_rep]['cal_time'] < $ev[$i]['cal_time'] ) { if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) { if ( ! empty ( $rep[$cur_rep]['cal_ext_for_id'] ) ) { $viewid = $rep[$cur_rep]['cal_ext_for_id']; $viewname = $rep[$cur_rep]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $rep[$cur_rep]['cal_id']; $viewname = $rep[$cur_rep]['cal_name']; } if ( $rep[$cur_rep]['cal_duration'] == ( 24 * 60 ) ) $all_day = 1; html_for_event_day_at_a_glance ( $viewid, $date, $rep[$cur_rep]['cal_time'], $viewname, $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_duration'], $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] ); } $cur_rep++; } if ( $get_unapproved || $ev[$i]['cal_status'] == 'A' ) { if ( ! empty ( $ev[$i]['cal_ext_for_id'] ) ) { $viewid = $ev[$i]['cal_ext_for_id']; $viewname = $ev[$i]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $ev[$i]['cal_id']; $viewname = $ev[$i]['cal_name']; } if ( $ev[$i]['cal_duration'] == ( 24 * 60 ) ) $all_day = 1; html_for_event_day_at_a_glance ( $viewid, $date, $ev[$i]['cal_time'], $viewname, $ev[$i]['cal_description'], $ev[$i]['cal_status'], $ev[$i]['cal_priority'], $ev[$i]['cal_access'], $ev[$i]['cal_duration'], $ev[$i]['cal_login'], $ev[$i]['cal_category'] ); } } // print out any remaining repeating events while ( $cur_rep < count ( $rep ) ) { if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) { if ( ! empty ( $rep[$cur_rep]['cal_ext_for_id'] ) ) { $viewid = $rep[$cur_rep]['cal_ext_for_id']; $viewname = $rep[$cur_rep]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $rep[$cur_rep]['cal_id']; $viewname = $rep[$cur_rep]['cal_name']; } if ( $rep[$cur_rep]['cal_duration'] == ( 24 * 60 ) ) $all_day = 1; html_for_event_day_at_a_glance ( $viewid, $date, $rep[$cur_rep]['cal_time'], $viewname, $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_duration'], $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] ); } $cur_rep++; }
// squish events that use the same cell into the same cell. // For example, an event from 8:00-9:15 and another from 9:30-9:45 both // want to show up in the 8:00-9:59 cell. $rowspan = 0; $last_row = -1; //echo "First SLot: $first_slot; Last Slot: $last_slot<br />\n"; $i = 0; if ( $first_slot < 0 ) $i = $first_slot; for ( ; $i < $TIME_SLOTS; $i++ ) { if ( $rowspan > 1 ) { if ( ! empty ( $hour_arr[$i] ) ) { $diff_start_time = $i - $last_row; if ( $rowspan_arr[$i] > 1 ) { if ( $rowspan_arr[$i] + ( $diff_start_time ) > $rowspan_arr[$last_row] ) { $rowspan_arr[$last_row] = ( $rowspan_arr[$i] + ( $diff_start_time ) ); } $rowspan += ( $rowspan_arr[$i] - 1 ); } else { $rowspan_arr[$last_row] += $rowspan_arr[$i]; } // this will move entries apart that appear in one field, // yet start on different hours for ( $u = $diff_start_time ; $u > 0 ; $u-- ) { $hour_arr[$last_row] .= "<br />\n"; } $hour_arr[$last_row] .= $hour_arr[$i]; $hour_arr[$i] = ""; $rowspan_arr[$i] = 0; } $rowspan--; } else if ( ! empty ( $rowspan_arr[$i] ) && $rowspan_arr[$i] > 1 ) { $rowspan = $rowspan_arr[$i]; $last_row = $i; } } if ( ! empty ( $hour_arr[9999] ) ) { echo "<tr><th class=\"empty\"> </th>\n" . "<td class=\"hasevents\">$hour_arr[9999]</td></tr>\n"; } $rowspan = 0; //echo "first_slot = $first_slot<br />\nlast_slot = $last_slot<br />\ninterval = $interval<br />\n"; for ( $i = $first_slot; $i <= $last_slot; $i++ ) { $time_h = (int) ( ( $i * $interval ) / 60 ); $time_m = ( $i * $interval ) % 60; $time = display_time ( ( $time_h * 100 + $time_m ) * 100 ); echo "<tr>\n<th class=\"row\">" . $time . "</th>\n"; if ( $rowspan > 1 ) { // this might mean there's an overlap, or it could mean one event // ends at 11:15 and another starts at 11:30. if ( ! empty ( $hour_arr[$i] ) ) { echo "<td class=\"hasevents\">"; if ( $can_add ) echo html_for_add_icon ( $date, $time_h, $time_m, $user ); echo "$hour_arr[$i]</td>\n"; } $rowspan--; } else { if ( empty ( $hour_arr[$i] ) ) { echo "<td>"; if ( $can_add ) { echo html_for_add_icon ( $date, $time_h, $time_m, $user ) . "</td>"; } else { echo " </td>"; } echo "</tr>\n"; } else { if ( empty ( $rowspan_arr[$i] ) ) $rowspan = ''; else $rowspan = $rowspan_arr[$i]; if ( $rowspan > 1 ) { echo "<td rowspan=\"$rowspan\" class=\"hasevents\">"; if ( $can_add ) echo html_for_add_icon ( $date, $time_h, $time_m, $user ); echo "$hour_arr[$i]</td></tr>\n"; } else { echo "<td class=\"hasevents\">"; if ( $can_add ) echo html_for_add_icon ( $date, $time_h, $time_m, $user ); echo "$hour_arr[$i]</td></tr>\n"; } } } } }
/** * Checks for any unnaproved events. * * If any are found, display a link to the unapproved events (where they can be * approved). * * If the user is an admin user, also count up any public events. * If the user is a nonuser admin, count up events on the nonuser calendar. * * @param string $user Current user login */ function display_unapproved_events ( $user ) { global $public_access, $is_admin, $nonuser_enabled, $login;
// Don't do this for public access login, admin user must approve public // events if ( $user == "__public__" ) return;
$sql = "SELECT COUNT(webcal_entry_user.cal_id) " . "FROM webcal_entry_user, webcal_entry " . "WHERE webcal_entry_user.cal_id = webcal_entry.cal_id " . "AND webcal_entry_user.cal_status = 'W' " . "AND ( webcal_entry.cal_ext_for_id IS NULL " . "OR webcal_entry.cal_ext_for_id = 0 ) " . "AND ( webcal_entry_user.cal_login = '$user'"; if ( $public_access == "Y" && $is_admin ) { $sql .= " OR webcal_entry_user.cal_login = '__public__'"; } if ( $nonuser_enabled == 'Y' ) { $admincals = get_nonuser_cals ( $login ); for ( $i = 0; $i < count ( $admincals ); $i++ ) { $sql .= " OR webcal_entry_user.cal_login = '" . $admincals[$i]['cal_login'] . "'"; } } $sql .= " )"; //print "SQL: $sql<br />\n"; $res = dbi_query ( $sql ); if ( $res ) { if ( $row = dbi_fetch_row ( $res ) ) { if ( $row[0] > 0 ) { $str = translate ("You have XXX unapproved events"); $str = str_replace ( "XXX", $row[0], $str ); echo "<a class=\"nav\" href=\"list_unapproved.php"; if ( $user != $login ) echo "?user=$user\""; echo "\">" . $str . "</a><br />\n"; } } dbi_free_result ( $res ); } }
/** * Looks for URLs in the given text, and makes them into links. * * @param string $text Input text * * @return string The text altered to have HTML links for any web links * (http or https) */ function activate_urls ( $text ) { $str = eregi_replace ( "(http://[^[:space:]$]+)", "<a href=\"\\1\">\\1</a>", $text ); $str = eregi_replace ( "(https://[^[:space:]$]+)", "<a href=\"\\1\">\\1</a>", $str ); return $str; }
/** * Displays a time in either 12 or 24 hour format. * * The global variable $TZ_OFFSET is used to adjust the time. Note that this * is somewhat of a kludge for timezone support. If an event is set for 11PM * server time and the user is 2 hours ahead, it will show up as 1AM, but the * date will not be adjusted to the next day. * * @param string $time Input time in HHMMSS format * @param bool $ignore_offset If true, then do not use the timezone offset * * @return string The time in the user's timezone and preferred format * * @global int The user's timezone offset from the server */ function display_time ( $time, $ignore_offset=0 ) { global $TZ_OFFSET; $hour = (int) ( $time / 10000 ); if ( ! $ignore_offset ) $hour += $TZ_OFFSET; $min = abs( ( $time / 100 ) % 100 ); //Prevent goofy times like 8:00 9:30 9:00 10:30 10:00 if ( $time < 0 && $min > 0 ) $hour = $hour - 1; while ( $hour < 0 ) $hour += 24; while ( $hour > 23 ) $hour -= 24; if ( $GLOBALS["TIME_FORMAT"] == "12" ) { $ampm = ( $hour >= 12 ) ? translate("pm") : translate("am"); $hour %= 12; if ( $hour == 0 ) $hour = 12; $ret = sprintf ( "%d:%02d%s", $hour, $min, $ampm ); } else { $ret = sprintf ( "%d:%02d", $hour, $min ); } return $ret; }
/** * Returns the full name of the specified month. * * Use {@link month_short_name()} to get the abbreviated name of the month. * * @param int $m Number of the month (0-11) * * @return string The full name of the specified month * * @see month_short_name */ function month_name ( $m ) { switch ( $m ) { case 0: return translate("January"); case 1: return translate("February"); case 2: return translate("March"); case 3: return translate("April"); case 4: return translate("May_"); // needs to be different than "May" case 5: return translate("June"); case 6: return translate("July"); case 7: return translate("August"); case 8: return translate("September"); case 9: return translate("October"); case 10: return translate("November"); case 11: return translate("December"); } return "unknown-month($m)"; }
/** * Returns the abbreviated name of the specified month (such as "Jan"). * * Use {@link month_name()} to get the full name of the month. * * @param int $m Number of the month (0-11) * * @return string The abbreviated name of the specified month (example: "Jan") * * @see month_name */ function month_short_name ( $m ) { switch ( $m ) { case 0: return translate("Jan"); case 1: return translate("Feb"); case 2: return translate("Mar"); case 3: return translate("Apr"); case 4: return translate("May"); case 5: return translate("Jun"); case 6: return translate("Jul"); case 7: return translate("Aug"); case 8: return translate("Sep"); case 9: return translate("Oct"); case 10: return translate("Nov"); case 11: return translate("Dec"); } return "unknown-month($m)"; }
/** * Returns the full weekday name. * * Use {@link weekday_short_name()} to get the abbreviated weekday name. * * @param int $w Number of the day in the week (0=Sunday,...,6=Saturday) * * @return string The full weekday name ("Sunday") * * @see weekday_short_name */ function weekday_name ( $w ) { switch ( $w ) { case 0: return translate("Sunday"); case 1: return translate("Monday"); case 2: return translate("Tuesday"); case 3: return translate("Wednesday"); case 4: return translate("Thursday"); case 5: return translate("Friday"); case 6: return translate("Saturday"); } return "unknown-weekday($w)"; }
/** * Returns the abbreviated weekday name. * * Use {@link weekday_name()} to get the full weekday name. * * @param int $w Number of the day in the week (0=Sunday,...,6=Saturday) * * @return string The abbreviated weekday name ("Sun") */ function weekday_short_name ( $w ) { switch ( $w ) { case 0: return translate("Sun"); case 1: return translate("Mon"); case 2: return translate("Tue"); case 3: return translate("Wed"); case 4: return translate("Thu"); case 5: return translate("Fri"); case 6: return translate("Sat"); } return "unknown-weekday($w)"; }
/** * Converts a date in YYYYMMDD format into "Friday, December 31, 1999", * "Friday, 12-31-1999" or whatever format the user prefers. * * @param string $indate Date in YYYYMMDD format * @param string $format Format to use for date (default is "__month__ * __dd__, __yyyy__") * @param bool $show_weekday Should the day of week also be included? * @param bool $short_months Should the abbreviated month names be used * instead of the full month names? * @param int $server_time ??? * * @return string Date in the specified format * * @global string Preferred date format * @global int User's timezone offset from the server */ function date_to_str ( $indate, $format="", $show_weekday=true, $short_months=false, $server_time="" ) { global $DATE_FORMAT, $TZ_OFFSET;
if ( strlen ( $indate ) == 0 ) { $indate = date ( "Ymd" ); }
$newdate = $indate; if ( $server_time != "" && $server_time >= 0 ) { $y = substr ( $indate, 0, 4 ); $m = substr ( $indate, 4, 2 ); $d = substr ( $indate, 6, 2 ); if ( $server_time + $TZ_OFFSET * 10000 > 240000 ) { $newdate = date ( "Ymd", mktime ( 3, 0, 0, $m, $d + 1, $y ) ); } else if ( $server_time + $TZ_OFFSET * 10000 < 0 ) { $newdate = date ( "Ymd", mktime ( 3, 0, 0, $m, $d - 1, $y ) ); } }
// if they have not set a preference yet... if ( $DATE_FORMAT == "" ) $DATE_FORMAT = "__month__ __dd__, __yyyy__";
if ( empty ( $format ) ) $format = $DATE_FORMAT;
$y = (int) ( $newdate / 10000 ); $m = (int) ( $newdate / 100 ) % 100; $d = $newdate % 100; $date = mktime ( 3, 0, 0, $m, $d, $y ); $wday = strftime ( "%w", $date );
if ( $short_months ) { $weekday = weekday_short_name ( $wday ); $month = month_short_name ( $m - 1 ); } else { $weekday = weekday_name ( $wday ); $month = month_name ( $m - 1 ); } $yyyy = $y; $yy = sprintf ( "%02d", $y %= 100 );
$ret = $format; $ret = str_replace ( "__yyyy__", $yyyy, $ret ); $ret = str_replace ( "__yy__", $yy, $ret ); $ret = str_replace ( "__month__", $month, $ret ); $ret = str_replace ( "__mon__", $month, $ret ); $ret = str_replace ( "__dd__", $d, $ret ); $ret = str_replace ( "__mm__", $m, $ret );
if ( $show_weekday ) return "$weekday, $ret"; else return $ret; }
/** * Converts a hexadecimal digit to an integer. * * @param string $val Hexadecimal digit * * @return int Equivalent integer in base-10 * * @ignore */ function hextoint ( $val ) { if ( empty ( $val ) ) return 0; switch ( strtoupper ( $val ) ) { case "0": return 0; case "1": return 1; case "2": return 2; case "3": return 3; case "4": return 4; case "5": return 5; case "6": return 6; case "7": return 7; case "8": return 8; case "9": return 9; case "A": return 10; case "B": return 11; case "C": return 12; case "D": return 13; case "E": return 14; case "F": return 15; } return 0; }
/** * Extracts a user's name from a session id. * * This prevents users from begin able to edit their cookies.txt file and set * the username in plain text. * * @param string $instr A hex-encoded string. "Hello" would be "678ea786a5". * * @return string The decoded string * * @global array Array of offsets * * @see encode_string */ function decode_string ( $instr ) { global $offsets; //echo "<br />\nDECODE<br />\n"; $orig = ""; for ( $i = 0; $i < strlen ( $instr ); $i += 2 ) { //echo "<br />\n"; $ch1 = substr ( $instr, $i, 1 ); $ch2 = substr ( $instr, $i + 1, 1 ); $val = hextoint ( $ch1 ) * 16 + hextoint ( $ch2 ); //echo "decoding \"" . $ch1 . $ch2 . "\" = $val<br />\n"; $j = ( $i / 2 ) % count ( $offsets ); //echo "Using offsets $j = " . $offsets[$j] . "<br />\n"; $newval = $val - $offsets[$j] + 256; $newval %= 256; //echo " neval \"$newval\"<br />\n"; $dec_ch = chr ( $newval ); //echo " which is \"$dec_ch\"<br />\n"; $orig .= $dec_ch; } //echo "Decode string: '$orig' <br/>\n"; return $orig; }
/** * Takes an input string and encode it into a slightly encoded hexval that we * can use as a session cookie. * * @param string $instr Text to encode * * @return string The encoded text * * @global array Array of offsets * * @see decode_string */ function encode_string ( $instr ) { global $offsets; //echo "<br />\nENCODE<br />\n"; $ret = ""; for ( $i = 0; $i < strlen ( $instr ); $i++ ) { //echo "<br />\n"; $ch1 = substr ( $instr, $i, 1 ); $val = ord ( $ch1 ); //echo "val = $val for \"$ch1\"<br />\n"; $j = $i % count ( $offsets ); //echo "Using offsets $j = $offsets[$j]<br />\n"; $newval = $val + $offsets[$j]; $newval %= 256; //echo "newval = $newval for \"$ch1\"<br />\n"; $ret .= bin2hex ( chr ( $newval ) ); } return $ret; }
/** * An implementatin of array_splice() for PHP3. * * @param array $input Array to be spliced into * @param int $offset Where to begin the splice * @param int $length How long the splice should be * @param array $replacement What to splice in * * @ignore */ function my_array_splice(&$input,$offset,$length,$replacement) { if ( floor(phpversion()) < 4 ) { // if offset is negative, then it starts at the end of array if ( $offset < 0 ) $offset = count($input) + $offset;
for ($i=0;$i<$offset;$i++) { $new_array[] = $input[$i]; }
// if we have a replacement, insert it for ($i=0;$i<count($replacement);$i++) { $new_array[] = $replacement[$i]; }
// now tack on the rest of the original array for ($i=$offset+$length;$i<count($input);$i++) { $new_array[] = $input[$i]; }
$input = $new_array; } else { array_splice($input,$offset,$length,$replacement); } }
/** * Loads current user's category info and stuff it into category global * variable. * * @param string $ex_global Don't include global categories ('' or '1') */ function load_user_categories ($ex_global = '') { global $login, $user, $is_assistant; global $categories, $category_owners; global $categories_enabled, $is_admin;
$cat_owner = ( ( ! empty ( $user ) && strlen ( $user ) ) && ( $is_assistant || $is_admin ) ) ? $user : $login; $categories = array (); $category_owners = array (); if ( $categories_enabled == "Y" ) { $sql = "SELECT cat_id, cat_name, cat_owner FROM webcal_categories WHERE "; $sql .= ($ex_global == '') ? " (cat_owner = '$cat_owner') OR (cat_owner IS NULL) ORDER BY cat_owner, cat_name" : " cat_owner = '$cat_owner' ORDER BY cat_name";
$res = dbi_query ( $sql ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { $cat_id = $row[0]; $categories[$cat_id] = $row[1]; $category_owners[$cat_id] = $row[2]; } dbi_free_result ( $res ); } } else { //echo "Categories disabled."; } }
/** * Prints dropdown HTML for categories. * * @param string $form The page to submit data to (without .php) * @param string $date Date in YYYYMMDD format * @param int $cat_id Category id that should be pre-selected */ function print_category_menu ( $form, $date = '', $cat_id = '' ) { global $categories, $category_owners, $user, $login; echo "<form action=\"{$form}.php\" method=\"get\" name=\"SelectCategory\" class=\"categories\">\n"; if ( ! empty($date) ) echo "<input type=\"hidden\" name=\"date\" value=\"$date\" />\n"; if ( ! empty ( $user ) && $user != $login ) echo "<input type=\"hidden\" name=\"user\" value=\"$user\" />\n"; echo translate ("Category") . ": <select name=\"cat_id\" onchange=\"document.SelectCategory.submit()\">\n"; echo "<option value=\"\""; if ( $cat_id == '' ) echo " selected=\"selected\""; echo ">" . translate("All") . "</option>\n"; $cat_owner = ( ! empty ( $user ) && strlen ( $user ) ) ? $user : $login; if ( is_array ( $categories ) ) { foreach ( $categories as $K => $V ){ if ( $cat_owner || empty ( $category_owners[$K] ) ) { echo "<option value=\"$K\""; if ( $cat_id == $K ) echo " selected=\"selected\""; echo ">$V</option>\n"; } } } echo "</select>\n"; echo "</form>\n"; echo "<span id=\"cat\">" . translate ("Category") . ": "; echo ( strlen ( $cat_id ) ? $categories[$cat_id] : translate ('All') ) . "</span>\n"; }
/** * Converts HTML entities in 8bit. * * <b>Note:</b> Only supported for PHP4 (not PHP3). * * @param string $html HTML text * * @return string The converted text */ function html_to_8bits ( $html ) { if ( floor(phpversion()) < 4 ) { return $html; } else { return strtr ( $html, array_flip ( get_html_translation_table (HTML_ENTITIES) ) ); } }
// *********************************************************************** // Functions for getting information about boss and their assistant. // ***********************************************************************
/** * Gets a list of an assistant's boss from the webcal_asst table. * * @param string $assistant Login of assistant * * @return array Array of bosses, where each boss is an array with the following * fields: * - <var>cal_login</var> * - <var>cal_fullname</var> */ function user_get_boss_list ( $assistant ) { global $bosstemp_fullname;
$res = dbi_query ( "SELECT cal_boss " . "FROM webcal_asst " . "WHERE cal_assistant = '$assistant'" ); $count = 0; $ret = array (); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { user_load_variables ( $row[0], "bosstemp_" ); $ret[$count++] = array ( "cal_login" => $row[0], "cal_fullname" => $bosstemp_fullname ); } dbi_free_result ( $res ); } return $ret; }
/** * Is this user an assistant of this boss? * * @param string $assistant Login of potential assistant * @param string $boss Login of potential boss * * @return bool True or false */ function user_is_assistant ( $assistant, $boss ) { $ret = false;
if ( empty ( $boss ) ) return false; $res = dbi_query ( "SELECT * FROM webcal_asst " . "WHERE cal_assistant = '$assistant' AND cal_boss = '$boss'" ); if ( $res ) { if ( dbi_fetch_row ( $res ) ) $ret = true; dbi_free_result ( $res ); } return $ret; }
/** * Is this user an assistant? * * @param string $assistant Login for user * * @return bool true if the user is an assistant to one or more bosses */ function user_has_boss ( $assistant ) { $ret = false; $res = dbi_query ( "SELECT * FROM webcal_asst " . "WHERE cal_assistant = '$assistant'" ); if ( $res ) { if ( dbi_fetch_row ( $res ) ) $ret = true; dbi_free_result ( $res ); } return $ret; }
/** * Checks the boss user preferences to see if the boss wants to be notified via * email on changes to their calendar. * * @param string $assistant Assistant login * @param string $boss Boss login * * @return bool True if the boss wants email notifications */ function boss_must_be_notified ( $assistant, $boss ) { if (user_is_assistant ( $assistant, $boss ) ) return ( get_pref_setting ( $boss, "EMAIL_ASSISTANT_EVENTS" )=="Y" ? true : false ); return true; }
/** * Checks the boss user preferences to see if the boss must approve events * added to their calendar. * * @param string $assistant Assistant login * @param string $boss Boss login * * @return bool True if the boss must approve new events */ function boss_must_approve_event ( $assistant, $boss ) { if (user_is_assistant ( $assistant, $boss ) ) return ( get_pref_setting ( $boss, "APPROVE_ASSISTANT_EVENT" )=="Y" ? true : false ); return true; }
/** * Fakes an email for testing purposes. * * @param string $mailto Email address to send mail to * @param string $subj Subject of email * @param string $text Email body * @param string $hdrs Other email headers * * @ignore */ function fake_mail ( $mailto, $subj, $text, $hdrs ) { echo "To: $mailto <br />\n" . "Subject: $subj <br />\n" . nl2br ( $hdrs ) . "<br />\n" . nl2br ( $text ); }
/** * Prints all the entries in a time bar format for the specified user for the * specified date. * * If we are displaying data from someone other than the logged in user, then * check the access permission of the entry. * * @param string $date Date in YYYYMMDD format * @param string $user Username * @param bool $ssi Should we not include links to add new events? */ function print_date_entries_timebar ( $date, $user, $ssi ) { global $events, $readonly, $is_admin, $public_access, $public_access_can_add; $cnt = 0; $get_unapproved = ( $GLOBALS["DISPLAY_UNAPPROVED"] == "Y" ); // public access events always must be approved before being displayed if ( $GLOBALS["login"] == "__public__" ) $get_unapproved = false;
$year = substr ( $date, 0, 4 ); $month = substr ( $date, 4, 2 ); $day = substr ( $date, 6, 2 ); $dateu = mktime ( 3, 0, 0, $month, $day, $year );
$can_add = ( $readonly == "N" || $is_admin ); if ( $public_access == "Y" && $public_access_can_add != "Y" && $GLOBALS["login"] == "__public__" ) $can_add = false;
// get all the repeating events for this date and store in array $rep $rep = get_repeating_entries ( $user, $date ) ; $cur_rep = 0;
// get all the non-repeating events for this date and store in $ev $ev = get_entries ( $user, $date, $get_unapproved );
for ( $i = 0; $i < count ( $ev ); $i++ ) { // print out any repeating events that are before this one... while ( $cur_rep < count ( $rep ) && $rep[$cur_rep]['cal_time'] < $ev[$i]['cal_time'] ) { if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) { print_entry_timebar ( $rep[$cur_rep]['cal_id'], $date, $rep[$cur_rep]['cal_time'], $rep[$cur_rep]['cal_duration'], $rep[$cur_rep]['cal_name'], $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] ); $cnt++; } $cur_rep++; } if ( $get_unapproved || $ev[$i]['cal_status'] == 'A' ) { print_entry_timebar ( $ev[$i]['cal_id'], $date, $ev[$i]['cal_time'], $ev[$i]['cal_duration'], $ev[$i]['cal_name'], $ev[$i]['cal_description'], $ev[$i]['cal_status'], $ev[$i]['cal_priority'], $ev[$i]['cal_access'], $ev[$i]['cal_login'], $ev[$i]['cal_category'] ); $cnt++; } } // print out any remaining repeating events while ( $cur_rep < count ( $rep ) ) { if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) { print_entry_timebar ( $rep[$cur_rep]['cal_id'], $date, $rep[$cur_rep]['cal_time'], $rep[$cur_rep]['cal_duration'], $rep[$cur_rep]['cal_name'], $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] ); $cnt++; } $cur_rep++; } if ( $cnt == 0 ) echo " "; // so the table cell has at least something }
/** * Prints the HTML for an events with a timebar. * * @param int $id Event id * @param string $date Date of event in YYYYMMDD format * @param string $time Time of event in HHMM format * @param int $duration Duration of event in minutes * @param string $name Brief description of event * @param string $description Full description of event * @param string $status Status of event ('A', 'W') * @param int $pri Priority of event * @param string $access Access to event by others ('P', 'R') * @param string $event_owner User who created event * @param int $event_category Category id for event * * @staticvar int Used to ensure all event popups have a unique id */ function print_entry_timebar ( $id, $date, $time, $duration, $name, $description, $status, $pri, $access, $event_owner, $event_category=-1 ) { global $eventinfo, $login, $user, $PHP_SELF, $prefarray; static $key = 0; $insidespan = false; global $layers;
// compute time offsets in % of total table width $day_start=$prefarray["WORK_DAY_START_HOUR"] * 60; if ( $day_start == 0 ) $day_start = 9*60; $day_end=$prefarray["WORK_DAY_END_HOUR"] * 60; if ( $day_end == 0 ) $day_end = 19*60; if ( $day_end <= $day_start ) $day_end = $day_start + 60; //avoid exceptions
if ($time >= 0) { $bar_units= 100/(($day_end - $day_start)/60) ; // Percentage each hour occupies $ev_start = round((floor(($time/10000) - ($day_start/60)) + (($time/100)%100)/60) * $bar_units); }else{ $ev_start= 0; } if ($ev_start < 0) $ev_start = 0; if ($duration > 0) { $ev_duration = round(100 * $duration / ($day_end - $day_start)) ; if ($ev_start + $ev_duration > 100 ) { $ev_duration = 100 - $ev_start; } } else { if ($time >= 0) { $ev_duration = 1; } else { $ev_duration=100-$ev_start; } } $ev_padding = 100 - $ev_start - $ev_duration; // choose where to position the text (pos=0->before,pos=1->on,pos=2->after) if ($ev_duration > 20) { $pos = 1; } elseif ($ev_padding > 20) { $pos = 2; } else { $pos = 0; } echo "\n<!-- ENTRY BAR -->\n<table class=\"entrycont\" cellpadding=\"0\" cellspacing=\"0\">\n"; echo "<tr>\n"; echo ($ev_start > 0 ? "<td style=\"text-align:right; width:$ev_start%;\">" : "" ); if ( $pos > 0 ) { echo ($ev_start > 0 ? " </td>\n": "" ) ; echo "<td style=\"width:$ev_duration%;\">\n<table class=\"entrybar\">\n<tr>\n<td class=\"entry\">"; if ( $pos > 1 ) { echo ($ev_padding > 0 ? " </td>\n": "" ) . "</tr>\n</table></td>\n"; echo ($ev_padding > 0 ? "<td style=\"text-align:left; width:$ev_padding%;\">" : ""); } };
if ( $login != $event_owner && strlen ( $event_owner ) ) { $class = "layerentry"; } else { $class = "entry"; if ( $status == "W" ) $class = "unapprovedentry"; } // if we are looking at a view, then always use "entry" if ( strstr ( $PHP_SELF, "view_m.php" ) || strstr ( $PHP_SELF, "view_w.php" ) || strstr ( $PHP_SELF, "view_v.php" ) || strstr ( $PHP_SELF, "view_t.php" ) ) $class = "entry";
if ( $pri == 3 ) echo "<strong>"; $popupid = "eventinfo-$id-$key"; $key++; echo "<a class=\"$class\" href=\"view_entry.php?id=$id&date=$date"; if ( strlen ( $user ) > 0 ) echo "&user=" . $user; echo "\" onmouseover=\"window.status='" . translate("View this entry") . "'; show(event, '$popupid'); return true;\" onmouseout=\"hide('$popupid'); return true;\">";
if ( $login != $event_owner && strlen ( $event_owner ) ) { if ($layers) foreach ($layers as $layer) { if($layer['cal_layeruser'] == $event_owner) { $insidespan = true; echo("<span style=\"color:" . $layer['cal_color'] . ";\">"); } } }
echo "[$event_owner] "; $timestr = ""; if ( $duration == ( 24 * 60 ) ) { $timestr = translate("All day event"); } else if ( $time >= 0 ) { $timestr = display_time ( $time ); if ( $duration > 0 ) { // calc end time $h = (int) ( $time / 10000 ); $m = ( $time / 100 ) % 100; $m += $duration; $d = $duration; while ( $m >= 60 ) { $h++; $m -= 60; } $end_time = sprintf ( "%02d%02d00", $h, $m ); $timestr .= " - " . display_time ( $end_time ); } } if ( $login != $user && $access == 'R' && strlen ( $user ) ) echo "(" . translate("Private") . ")"; else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) echo "(" . translate("Private") . ")"; else if ( $login != $event_owner && strlen ( $event_owner ) ) { echo htmlspecialchars ( $name ); if ( $insidespan ) { echo ("</span>"); } //end color span } else echo htmlspecialchars ( $name ); echo "</a>"; if ( $pri == 3 ) echo "</strong>"; //end font-weight span echo "</td>\n"; if ( $pos < 2 ) { if ( $pos < 1 ) { echo "<td style=\"width:$ev_duration%;\"><table class=\"entrybar\">\n<tr>\n<td class=\"entry\"> </td>\n"; } echo "</tr>\n</table></td>\n"; echo ($ev_padding > 0 ? "<td style=\"text-align:left; width:$ev_padding%;\"> </td>\n" : "" ); } echo "</tr>\n</table>\n"; if ( $login != $user && $access == 'R' && strlen ( $user ) ) $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); else if ( $login != $event_owner && $access == 'R' && strlen ( $event_owner ) ) $eventinfo .= build_event_popup ( $popupid, $event_owner, translate("This event is confidential"), "" ); else $eventinfo .= build_event_popup ( $popupid, $event_owner, $description, $timestr, site_extras_for_popup ( $id ) ); }
/** * Prints the header for the timebar. * * @param int $start_hour Start hour * @param int $end_hour End hour */ function print_header_timebar($start_hour, $end_hour) { // sh+1 ... eh-1 // +------+----....----+------+ // | | | |
// print hours if ( ($end_hour - $start_hour) == 0 ) $offset = 0; else $offset = round(100/($end_hour - $start_hour)); echo "\n<!-- TIMEBAR -->\n<table class=\"timebar\">\n<tr><td style=\"width:$offset%;\"> </td>\n"; for ($i = $start_hour+1; $i < $end_hour; $i++) { // $prev_offset = $offset; // $offset = round(100/($end_hour - $start_hour)*($i - $start_hour + .5)); $offset = round(100/($end_hour - $start_hour)); $width = $offset; echo "<td style=\"width:$width%;text-align:left;\">$i</td>\n"; } // $width = 100 - $offset; // echo "<td style=\"width:$width%;\"> </td>\n"; echo "</tr>\n</table>\n<!-- /TIMEBAR -->\n"; // print yardstick echo "\n<!-- YARDSTICK -->\n<table class=\"yardstick\">\n<tr>\n"; $width = round(100/($end_hour - $start_hour)); for ($i = $start_hour; $i < $end_hour; $i++) { echo "<td style=\"width:$width%;\"> </td>\n"; } echo "</tr>\n</table>\n<!-- /YARDSTICK -->\n"; }
/** * Gets a list of nonuser calendars and return info in an array. * * @param string $user Login of admin of the nonuser calendars * * @return array Array of nonuser cals, where each is an array with the * following fields: * - <var>cal_login</var> * - <var>cal_lastname</var> * - <var>cal_firstname</var> * - <var>cal_admin</var> * - <var>cal_fullname</var> */ function get_nonuser_cals ($user = '') { $count = 0; $ret = array (); $sql = "SELECT cal_login, cal_lastname, cal_firstname, " . "cal_admin FROM webcal_nonuser_cals "; if ($user != '') $sql .= "WHERE cal_admin = '$user' "; $sql .= "ORDER BY cal_lastname, cal_firstname, cal_login"; $res = dbi_query ( $sql ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { if ( strlen ( $row[1] ) || strlen ( $row[2] ) ) $fullname = "$row[2] $row[1]"; else $fullname = $row[0]; $ret[$count++] = array ( "cal_login" => $row[0], "cal_lastname" => $row[1], "cal_firstname" => $row[2], "cal_admin" => $row[3], "cal_fullname" => $fullname ); } dbi_free_result ( $res ); } return $ret; }
/** * Loads nonuser variables (login, firstname, etc.). * * The following variables will be set: * - <var>login</var> * - <var>firstname</var> * - <var>lastname</var> * - <var>fullname</var> * - <var>admin</var> * - <var>email</var> * * @param string $login Login name of nonuser calendar * @param string $prefix Prefix to use for variables that will be set. * For example, if prefix is "temp", then the login will * be stored in the <var>$templogin</var> global variable. */ function nonuser_load_variables ( $login, $prefix ) { global $error,$nuloadtmp_email; $ret = false; $res = dbi_query ( "SELECT cal_login, cal_lastname, cal_firstname, " . "cal_admin FROM webcal_nonuser_cals WHERE cal_login = '$login'" ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { if ( strlen ( $row[1] ) || strlen ( $row[2] ) ) $fullname = "$row[2] $row[1]"; else $fullname = $row[0];
// We need the email address for the admin user_load_variables ( $row[3], 'nuloadtmp_' );
$GLOBALS[$prefix . "login"] = $row[0]; $GLOBALS[$prefix . "firstname"] = $row[2]; $GLOBALS[$prefix . "lastname"] = $row[1]; $GLOBALS[$prefix . "fullname"] = $fullname; $GLOBALS[$prefix . "admin"] = $row[3]; $GLOBALS[$prefix . "email"] = $nuloadtmp_email; $ret = true; } dbi_free_result ( $res ); } return $ret; }
/** * Checks the webcal_nonuser_cals table to determine if the user is the * administrator for the nonuser calendar. * * @param string $login Login of user that is the potential administrator * @param string $nonuser Login name for nonuser calendar * * @return bool True if the user is the administrator for the nonuser calendar */ function user_is_nonuser_admin ( $login, $nonuser ) { $ret = false;
$res = dbi_query ( "SELECT * FROM webcal_nonuser_cals " . "WHERE cal_login = '$nonuser' AND cal_admin = '$login'" ); if ( $res ) { if ( dbi_fetch_row ( $res ) ) $ret = true; dbi_free_result ( $res ); } return $ret; }
/** * Loads nonuser preferences from the webcal_user_pref table if on a nonuser * admin page. * * @param string $nonuser Login name for nonuser calendar */ function load_nonuser_preferences ($nonuser) { global $prefarray; $res = dbi_query ( "SELECT cal_setting, cal_value FROM webcal_user_pref " . "WHERE cal_login = '$nonuser'" ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { $setting = $row[0]; $value = $row[1]; $sys_setting = "sys_" . $setting; // save system defaults // ** don't override ones set by load_user_prefs if ( ! empty ( $GLOBALS[$setting] ) && empty ( $GLOBALS["sys_" . $setting] )) $GLOBALS["sys_" . $setting] = $GLOBALS[$setting]; $GLOBALS[$setting] = $value; $prefarray[$setting] = $value; } dbi_free_result ( $res ); } }
/** * Determines what the day is after the <var>$TZ_OFFSET</var> and sets it globally. * * The following global variables will be set: * - <var>$thisyear</var> * - <var>$thismonth</var> * - <var>$thisday</var> * - <var>$thisdate</var> * - <var>$today</var> * * @param string $date The date in YYYYMMDD format */ function set_today($date) { global $thisyear, $thisday, $thismonth, $thisdate, $today; global $TZ_OFFSET, $month, $day, $year, $thisday;
// Adjust for TimeZone $today = time() + ($TZ_OFFSET * 60 * 60);
if ( ! empty ( $date ) && ! empty ( $date ) ) { $thisyear = substr ( $date, 0, 4 ); $thismonth = substr ( $date, 4, 2 ); $thisday = substr ( $date, 6, 2 ); } else { if ( empty ( $month ) || $month == 0 ) $thismonth = date("m", $today); else $thismonth = $month; if ( empty ( $year ) || $year == 0 ) $thisyear = date("Y", $today); else $thisyear = $year; if ( empty ( $day ) || $day == 0 ) $thisday = date("d", $today); else $thisday = $day; } $thisdate = sprintf ( "%04d%02d%02d", $thisyear, $thismonth, $thisday ); }
/** * Converts from Gregorian Year-Month-Day to ISO YearNumber-WeekNumber-WeekDay. * * @internal JGH borrowed gregorianToISO from PEAR Date_Calc Class and added * $GLOBALS["WEEK_START"] (change noted) * * @param int $day Day of month * @param int $month Number of month * @param int $year Year * * @return string Date in ISO YearNumber-WeekNumber-WeekDay format * * @ignore */ function gregorianToISO($day,$month,$year) { $mnth = array (0,31,59,90,120,151,181,212,243,273,304,334); $y_isleap = isLeapYear($year); $y_1_isleap = isLeapYear($year - 1); $day_of_year_number = $day + $mnth[$month - 1]; if ($y_isleap && $month > 2) { $day_of_year_number++; } // find Jan 1 weekday (monday = 1, sunday = 7) $yy = ($year - 1) % 100; $c = ($year - 1) - $yy; $g = $yy + intval($yy/4); $jan1_weekday = 1 + intval((((($c / 100) % 4) * 5) + $g) % 7);
// JGH added next if/else to compensate for week begins on Sunday if (! $GLOBALS["WEEK_START"] && $jan1_weekday < 7) { $jan1_weekday++; } elseif (! $GLOBALS["WEEK_START"] && $jan1_weekday == 7) { $jan1_weekday=1; }
// weekday for year-month-day $h = $day_of_year_number + ($jan1_weekday - 1); $weekday = 1 + intval(($h - 1) % 7); // find if Y M D falls in YearNumber Y-1, WeekNumber 52 or if ($day_of_year_number <= (8 - $jan1_weekday) && $jan1_weekday > 4){ $yearnumber = $year - 1; if ($jan1_weekday == 5 || ($jan1_weekday == 6 && $y_1_isleap)) { $weeknumber = 53; } else { $weeknumber = 52; } } else { $yearnumber = $year; } // find if Y M D falls in YearNumber Y+1, WeekNumber 1 if ($yearnumber == $year) { if ($y_isleap) { $i = 366; } else { $i = 365; } if (($i - $day_of_year_number) < (4 - $weekday)) { $yearnumber++; $weeknumber = 1; } } // find if Y M D falls in YearNumber Y, WeekNumber 1 through 53 if ($yearnumber == $year) { $j = $day_of_year_number + (7 - $weekday) + ($jan1_weekday - 1); $weeknumber = intval($j / 7); if ($jan1_weekday > 4) { $weeknumber--; } } // put it all together if ($weeknumber < 10) $weeknumber = '0'.$weeknumber; return "{$yearnumber}-{$weeknumber}-{$weekday}"; }
/** * Is this a leap year? * * @internal JGH Borrowed isLeapYear from PEAR Date_Calc Class * * @param int $year Year * * @return bool True for a leap year, else false * * @ignore */ function isLeapYear($year='') { if (empty($year)) $year = strftime("%Y",time()); if (strlen($year) != 4) return false; if (preg_match('/\D/',$year)) return false; return (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0); }
/** * Replaces unsafe characters with HTML encoded equivalents. * * @param string $value Input text * * @return string The cleaned text */ function clean_html($value){ $value = htmlspecialchars($value, ENT_QUOTES); $value = strtr($value, array( '(' => '(', ')' => ')' )); return $value; }
/** * Removes non-word characters from the specified text. * * @param string $data Input text * * @return string The converted text */ function clean_word($data) { return preg_replace("/\W/", '', $data); }
/** * Removes non-digits from the specified text. * * @param string $data Input text * * @return string The converted text */ function clean_int($data) { return preg_replace("/\D/", '', $data); }
/** * Removes whitespace from the specified text. * * @param string $data Input text * * @return string The converted text */ function clean_whitespace($data) { return preg_replace("/\s/", '', $data); }
/** * Converts language names to their abbreviation. * * @param string $name Name of the language (such as "French") * * @return string The abbreviation ("fr" for "French") */ function languageToAbbrev ( $name ) { global $browser_languages; foreach ( $browser_languages as $abbrev => $langname ) { if ( $langname == $name ) return $abbrev; } return false; }
/** * Creates the CSS for using gradient.php, if the appropriate GD functions are * available. * * A one-pixel wide image will be used for the background image. * * <b>Note:</b> The gd library module needs to be available to use gradient * images. If it is not available, a single background color will be used * instead. * * @param string $color Base color * @param int $height Height of gradient image * @param int $percent How many percent lighter the top color should be * than the base color at the bottom of the image * * @return string The style sheet text to use */ function background_css ( $color, $height = '', $percent = '' ) { $ret = '';
if ( ( function_exists ( 'imagepng' ) || function_exists ( 'imagegif' ) ) && ( empty ( $GLOBALS['enable_gradients'] ) || $GLOBALS['enable_gradients'] == 'Y' ) ) { $ret = "background: $color url(\"gradient.php?base=" . substr ( $color, 1 );
if ( $height != '' ) { $ret .= "&height=$height"; }
if ( $percent != '' ) { $ret .= "&percent=$percent"; }
$ret .= "\") repeat-x;\n"; } else { $ret = "background-color: $color;\n"; }
return $ret; }
/** * Draws a daily outlook style availability grid showing events that are * approved and awaiting approval. * * @param string $date Date to show the grid for * @param array $participants Which users should be included in the grid * @param string $popup Not used */ function daily_matrix ( $date, $participants, $popup = '' ) { global $CELLBG, $TODAYCELLBG, $THFG, $THBG, $TABLEBG; global $user_fullname, $repeated_events, $events; global $WORK_DAY_START_HOUR, $WORK_DAY_END_HOUR, $TZ_OFFSET,$ignore_offset;
$increment = 15; $interval = 4; $participant_pct = '20%'; //use percentage
$first_hour = $WORK_DAY_START_HOUR; $last_hour = $WORK_DAY_END_HOUR; $hours = $last_hour - $first_hour; $cols = (($hours * $interval) + 1); $total_pct = '80%'; $cell_pct = 80 /($hours * $interval); $master = array();
// Build a master array containing all events for $participants for ( $i = 0; $i < count ( $participants ); $i++ ) {
/* Pre-Load the repeated events for quckier access */ $repeated_events = read_repeated_events ( $participants[$i], "", $date ); /* Pre-load the non-repeating events for quicker access */ $events = read_events ( $participants[$i], $date, $date );
// get all the repeating events for this date and store in array $rep $rep = get_repeating_entries ( $participants[$i], $date ); // get all the non-repeating events for this date and store in $ev $ev = get_entries ( $participants[$i], $date );
// combine into a single array for easy processing $ALL = array_merge ( $rep, $ev );
foreach ( $ALL as $E ) { if ($E['cal_time'] == 0) { $E['cal_time'] = $first_hour."0000"; $E['cal_duration'] = 60 * ( $last_hour - $first_hour ); } else { $E['cal_time'] = sprintf ( "%06d", $E['cal_time']); }
$hour = substr($E['cal_time'], 0, 2 ); $mins = substr($E['cal_time'], 2, 2 ); // Timezone Offset if ( ! $ignore_offset ) $hour += $TZ_OFFSET; while ( $hour < 0 ) $hour += 24; while ( $hour > 23 ) $hour -= 24;
// Make sure hour is 2 digits $hour = sprintf ( "%02d",$hour);
// convert cal_time to slot if ($mins < 15) { $slot = $hour.''; } elseif ($mins >= 15 && $mins < 30) { $slot = $hour.'.25'; } elseif ($mins >= 30 && $mins < 45) { $slot = $hour.'.5'; } elseif ($mins >= 45) { $slot = $hour.'.75'; }
// convert cal_duration to bars $bars = $E['cal_duration'] / $increment;
// never replace 'A' with 'W' for ($q = 0; $bars > $q; $q++) { $slot = sprintf ("%02.2f",$slot); if (strlen($slot) == 4) $slot = '0'.$slot; // add leading zeros $slot = $slot.''; // convert to a string if ( empty ( $master['_all_'][$slot] ) || $master['_all_'][$slot]['stat'] != 'A') { $master['_all_'][$slot]['stat'] = $E['cal_status']; } if ( empty ( $master[$participants[$i]][$slot] ) || $master[$participants[$i]][$slot]['stat'] != 'A' ) { $master[$participants[$i]][$slot]['stat'] = $E['cal_status']; $master[$participants[$i]][$slot]['ID'] = $E['cal_id']; } $slot = $slot + '0.25'; }
} } ?> <br /> <table align="center" class="matrixd" style="width:<?php echo $total_pct;?>;" cellspacing="0" cellpadding="0"> <tr><td class="matrix" colspan="<?php echo $cols;?>"></td></tr> <tr><th style="width:<?php echo $participant_pct;?>;"> <?php etranslate("Participants");?></th> <?php $str = ''; $MouseOut = "onmouseout=\"window.status=''; this.style.backgroundColor='".$THBG."';\""; $CC = 1; for($i=$first_hour;$i<$last_hour;$i++) { $hour = $i; if ( $GLOBALS["TIME_FORMAT"] == "12" ) { $hour %= 12; if ( $hour == 0 ) $hour = 12; }
for($j=0;$j<$interval;$j++) { $str .= ' <td id="C'.$CC.'" class="dailymatrix" '; $MouseDown = 'onmousedown="schedule_event('.$i.','.sprintf ("%02d",($increment * $j)).');"'; switch($j) { case 1: if($interval == 4) { $k = ($hour<=9?'0':substr($hour,0,1)); } $str .= 'style="width:'.$cell_pct.'%; text-align:right;" '.$MouseDown." onmouseover=\"window.status='Schedule a ".$hour.':'.($increment * $j<=9?'0':'').($increment * $j)." appointment.'; this.style.backgroundColor='#CCFFCC'; return true;\" ".$MouseOut." title=\"Schedule an appointment for ".$hour.':'.($increment * $j<=9?'0':'').($increment * $j).".\">"; $str .= $k."</td>\n"; break; case 2: if($interval == 4) { $k = ($hour<=9?substr($hour,0,1):substr($hour,1,2)); } $str .= 'style="width:'.$cell_pct.'%; text-align:left;" '.$MouseDown." onmouseover=\"window.status='Schedule a ".$hour.':'.($increment * $j)." appointment.'; this.style.backgroundColor='#CCFFCC'; return true;\" ".$MouseOut." title=\"Schedule an appointment for ".$hour.':'.($increment * $j<=9?'0':'').($increment * $j).".\">"; $str .= $k."</td>\n"; break; default: $str .= 'style="width:'.$cell_pct.'%;" '.$MouseDown." onmouseover=\"window.status='Schedule a ".$hour.':'.($increment * $j<=9?'0':'').($increment * $j)." appointment.'; this.style.backgroundColor='#CCFFCC'; return true;\" ".$MouseOut." title=\"Schedule an appointment for ".$hour.':'.($increment * $j<=9?'0':'').($increment * $j).".\">"; $str .= " </td>\n"; break; } $CC++; } } echo $str . "</tr>\n<tr><td class=\"matrix\" colspan=\"$cols\"></td></tr>\n";
// Add user _all_ to beginning of $participants array array_unshift($participants, '_all_');
// Javascript for cells $MouseOver = "onmouseover=\"this.style.backgroundColor='#CCFFCC';\""; $MouseOut = "onmouseout=\"this.style.backgroundColor='".$CELLBG."';\"";
// Display each participant for ( $i = 0; $i < count ( $participants ); $i++ ) { if ($participants[$i] != '_all_') { // Load full name of user user_load_variables ( $participants[$i], "user_" ); // exchange space for to keep from breaking $user_nospace = preg_replace ( '/\s/', ' ', $user_fullname ); } else { $user_nospace = translate("All Attendees"); $user_nospace = preg_replace ( '/\s/', ' ', $user_nospace ); }
echo "<tr>\n<th class=\"row\" style=\"width:{$participant_pct};\">".$user_nospace."</th>\n"; $col = 1; $viewMsg = translate ( "View this entry" );
// check each timebar for ( $j = $first_hour; $j < $last_hour; $j++ ) { for ( $k = 0; $k < $interval; $k++ ) { $border = ($k == '0') ? ' border-left: 1px solid #000000;' : ""; $MouseDown = 'onmousedown="schedule_event('.$j.','.sprintf ("%02d",($increment * $k)).');"'; $RC = $CELLBG; //$space = ''; $space = " ";
$r = sprintf ("%02d",$j) . '.' . sprintf ("%02d", (25 * $k)).''; if ( empty ( $master[$participants[$i]][$r] ) ) { // ignore this.. } else if ( empty ( $master[$participants[$i]][$r]['ID'] ) ) { // This is the first line for 'all' users. No event here. $space = "<span class=\"matrix\"><img src=\"pix.gif\" alt=\"\" style=\"height: 8px\" /></span>"; } else if ($master[$participants[$i]][$r]['stat'] == "A") { $space = "<a class=\"matrix\" href=\"view_entry.php?id={$master[$participants[$i]][$r]['ID']}\"><img src=\"pix.gif\" title=\"$viewMsg\" alt=\"$viewMsg\" /></a>"; } else if ($master[$participants[$i]][$r]['stat'] == "W") { $space = "<a class=\"matrix\" href=\"view_entry.php?id={$master[$participants[$i]][$r]['ID']}\"><img src=\"pixb.gif\" title=\"$viewMsg\" alt=\"$viewMsg\" /></a>"; }
echo "<td class=\"matrixappts\" style=\"width:{$cell_pct}%;$border\" "; if ($space == " ") echo "$MouseDown $MouseOver $MouseOut"; echo ">$space</td>\n"; $col++; } } echo "</tr><tr>\n<td class=\"matrix\" colspan=\"$cols\">" . "<img src=\"pix.gif\" alt=\"-\" /></td></tr>\n"; } // End foreach participant echo "</table><br />\n"; $busy = translate ("Busy"); $tentative = translate ("Tentative"); echo "<table align=\"center\"><tr><td class=\"matrixlegend\" >\n"; echo "<img src=\"pix.gif\" title=\"$busy\" alt=\"$busy\" /> $busy \n"; echo "<img src=\"pixb.gif\" title=\"$tentative\" alt=\"$tentative\" /> $tentative\n"; echo "</td></tr></table>\n"; }
/** * Return the time in HHMMSS format of input time + duration * * * <b>Note:</b> The gd library module needs to be available to use gradient * images. If it is not available, a single background color will be used * instead. * * @param string $time format "235900" * @param int $duration number of minutes * * @return string The time in HHMMSS format */ function add_duration ( $time, $duration ) { $hour = (int) ( $time / 10000 ); $min = ( $time / 100 ) % 100; $minutes = $hour * 60 + $min + $duration; $h = $minutes / 60; $m = $minutes % 60; $ret = sprintf ( "%d%02d00", $h, $m ); //echo "add_duration ( $time, $duration ) = $ret <br />\n"; return $ret; } ?>
|