webform.module
142 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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
<?php
/**
* This module provides a simple way to create forms and questionnaires.
*
* The initial development of this module was sponsered by ÅF Industri AB, Open
* Source City and Karlstad University Library. Continued development sponsored
* by Lullabot.
*
* @author Nathan Haug <nate@lullabot.com>
*/
/**
* Implements hook_help().
*/
function webform_help($section = 'admin/help#webform', $arg = NULL) {
$output = '';
switch ($section) {
case 'admin/config/content/webform':
module_load_include('inc', 'webform', 'includes/webform.admin');
$type_list = webform_admin_type_list();
$output = t('Webform enables nodes to have attached forms and questionnaires.');
if ($type_list) {
$output .= ' ' . t('To add one, create a !types piece of content.', array('!types' => $type_list));
}
else {
$output .= ' <strong>' . t('Webform is currently not enabled on any content types.') . '</strong> ' . t('To use Webform, please enable it on at least one content type on this page.');
}
$output = '<p>' . $output . '</p>';
break;
case 'admin/content/webform':
$output = '<p>' . t('This page lists all of the content on the site that may have a webform attached to it.') . '</p>';
break;
case 'admin/help#webform':
module_load_include('inc', 'webform', 'includes/webform.admin');
$types = webform_admin_type_list();
if (empty($types)) {
$types = t('Webform-enabled piece of content');
$types_message = t('Webform is currently not enabled on any content types.') . ' ' . t('Visit the <a href="!url">Webform settings</a> page and enable Webform on at least one content type.', array('!url' => url('admin/config/content/webform')));
}
else {
$types_message = t('Optional: Enable Webform on multiple types by visiting the <a href="!url">Webform settings</a> page.', array('!url' => url('admin/config/content/webform')));
}
$output = t("<p>This module lets you create forms or questionnaires and define their content. Submissions from these forms are stored in the database and optionally also sent by e-mail to a predefined address.</p>
<p>Here is how to create one:</p>
<ul>
<li>!webform-types-message</li>
<li>Go to <a href=\"!create-content\">Create content</a> and add a !types piece of content.</li>
<li>After saving the new content, you will be redirected to the main field list of the form that will be created. Add the fields you would like on your form.</li>
<li>Once finished adding fields, you may want to send e-mails to administrators or back to the user who filled out the form. Click on the <em>Emails</em> sub-tab underneath the <em>Webform</em> tab on the piece of content.</li>
<li>Finally, visit the <em>Form settings</em> sub-tab under the <em>Webform</em> tab to configure remaining configurations options for your form.
<ul>
<li>Add a confirmation message and/or redirect URL that is to be displayed after successful submission.</li>
<li>Set a submission limit.</li>
<li>Determine which roles may submit the form.</li>
<li>Advanced configuration options such as allowing drafts or show users a message indicating how they can edit their submissions.</li>
</ul>
</li>
<li>Your form is now ready for viewing. After receiving submissions, you can check the results users have submitted by visiting the <em>Results</em> tab on the piece of content.</li>
</ul>
<p>Help on adding and configuring the components will be shown after you add your first component.</p>
", array('!webform-types-message' => $types_message, '!create-content' => url('node/add'), '!types' => $types));
break;
case 'node/%/submission/%/resend':
$output .= '<p>' . t('This form may be used to resend e-mails configured for this webform. Check the e-mails that need to be sent and click <em>Resend e-mails</em> to send these e-mails again.') . '</p>';
break;
}
return $output;
}
/**
* Implements hook_menu().
*/
function webform_menu() {
$items = array();
// Submissions listing.
$items['admin/content/webform'] = array(
'title' => 'Webforms',
'page callback' => 'webform_admin_content',
'access callback' => 'user_access',
'access arguments' => array('access all webform results'),
'description' => 'View and edit all the available webforms on your site.',
'file' => 'includes/webform.admin.inc',
'type' => MENU_LOCAL_TASK,
);
// Admin Settings.
$items['admin/config/content/webform'] = array(
'title' => 'Webform settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_admin_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration'),
'description' => 'Global configuration of webform functionality.',
'file' => 'includes/webform.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
// Node page tabs.
$items['node/%webform_menu/done'] = array(
'title' => 'Webform confirmation',
'page callback' => '_webform_confirmation',
'page arguments' => array(1),
'access callback' => 'node_access',
'access arguments' => array('view', 1),
'type' => MENU_CALLBACK,
);
$items['node/%webform_menu/webform'] = array(
'title' => 'Webform',
'page callback' => 'webform_components_page',
'page arguments' => array(1),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.components.inc',
'weight' => 1,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items['node/%webform_menu/webform/components'] = array(
'title' => 'Form components',
'page callback' => 'webform_components_page',
'page arguments' => array(1),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.components.inc',
'weight' => 0,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['node/%webform_menu/webform/configure'] = array(
'title' => 'Form settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_configure_form', 1),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.pages.inc',
'weight' => 2,
'type' => MENU_LOCAL_TASK,
);
// Node e-mail forms.
$items['node/%webform_menu/webform/emails'] = array(
'title' => 'E-mails',
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_emails_form', 1),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.emails.inc',
'weight' => 1,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform/emails/%webform_menu_email'] = array(
'title' => 'Edit e-mail settings',
'load arguments' => array(1),
'page arguments' => array('webform_email_edit_form', 1, 4),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.emails.inc',
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform/emails/%webform_menu_email/delete'] = array(
'title' => 'Delete e-mail settings',
'load arguments' => array(1),
'page arguments' => array('webform_email_delete_form', 1, 4),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'type' => MENU_LOCAL_TASK,
);
// Node component forms.
$items['node/%webform_menu/webform/components/%webform_menu_component'] = array(
'load arguments' => array(1, 5),
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_component_edit_form', 1, 4, FALSE),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.components.inc',
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform/components/%webform_menu_component/clone'] = array(
'load arguments' => array(1, 5),
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_component_edit_form', 1, 4, TRUE),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.components.inc',
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform/components/%webform_menu_component/delete'] = array(
'load arguments' => array(1, 5),
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_component_delete_form', 1, 4),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.components.inc',
'type' => MENU_LOCAL_TASK,
);
// AJAX callback for loading select list options.
$items['webform/ajax/options/%webform_menu'] = array(
'load arguments' => array(3),
'page callback' => 'webform_select_options_ajax',
'access callback' => 'node_access',
'access arguments' => array('update', 3),
'file' => 'components/select.inc',
'type' => MENU_CALLBACK,
);
// Node webform results.
$items['node/%webform_menu/webform-results'] = array(
'title' => 'Results',
'page callback' => 'webform_results_submissions',
'page arguments' => array(1, FALSE, '50'),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => 'includes/webform.report.inc',
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items['node/%webform_menu/webform-results/submissions'] = array(
'title' => 'Submissions',
'page callback' => 'webform_results_submissions',
'page arguments' => array(1, FALSE, '50'),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => 'includes/webform.report.inc',
'weight' => 4,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/analysis'] = array(
'title' => 'Analysis',
'page callback' => 'webform_results_analysis',
'page arguments' => array(1),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => 'includes/webform.report.inc',
'weight' => 5,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/analysis/%webform_menu_component'] = array(
'title' => 'Analysis',
'load arguments' => array(1, 4),
'page callback' => 'webform_results_analysis',
'page arguments' => array(1, array(), 4),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => 'includes/webform.report.inc',
'type' => MENU_CALLBACK,
);
$items['node/%webform_menu/webform-results/table'] = array(
'title' => 'Table',
'page callback' => 'webform_results_table',
'page arguments' => array(1, '50'),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => 'includes/webform.report.inc',
'weight' => 6,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/download'] = array(
'title' => 'Download',
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_results_download_form', 1),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => 'includes/webform.report.inc',
'weight' => 7,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/clear'] = array(
'title' => 'Clear',
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_results_clear_form', 1),
'access callback' => 'webform_results_clear_access',
'access arguments' => array(1),
'file' => 'includes/webform.report.inc',
'weight' => 8,
'type' => MENU_LOCAL_TASK,
);
// Node submissions.
$items['node/%webform_menu/submissions'] = array(
'title' => 'Submissions',
'page callback' => 'webform_results_submissions',
'page arguments' => array(1, TRUE, '50'),
'access callback' => 'webform_submission_access',
'access arguments' => array(1, NULL, 'list'),
'file' => 'includes/webform.report.inc',
'type' => MENU_CALLBACK,
);
$items['node/%webform_menu/submission/%webform_menu_submission'] = array(
'title' => 'Webform submission',
'load arguments' => array(1),
'page callback' => 'webform_submission_page',
'page arguments' => array(1, 3, 'html'),
'title callback' => 'webform_submission_title',
'title arguments' => array(1, 3),
'access callback' => 'webform_submission_access',
'access arguments' => array(1, 3, 'view'),
'file' => 'includes/webform.submissions.inc',
'type' => MENU_CALLBACK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/view'] = array(
'title' => 'View',
'load arguments' => array(1),
'page callback' => 'webform_submission_page',
'page arguments' => array(1, 3, 'html'),
'access callback' => 'webform_submission_access',
'access arguments' => array(1, 3, 'view'),
'weight' => 0,
'file' => 'includes/webform.submissions.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/edit'] = array(
'title' => 'Edit',
'load arguments' => array(1),
'page callback' => 'webform_submission_page',
'page arguments' => array(1, 3, 'form'),
'access callback' => 'webform_submission_access',
'access arguments' => array(1, 3, 'edit'),
'weight' => 1,
'file' => 'includes/webform.submissions.inc',
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/delete'] = array(
'title' => 'Delete',
'load arguments' => array(1),
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_submission_delete_form', 1, 3),
'access callback' => 'webform_submission_access',
'access arguments' => array(1, 3, 'delete'),
'weight' => 2,
'file' => 'includes/webform.submissions.inc',
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/resend'] = array(
'title' => 'Resend e-mails',
'load arguments' => array(1),
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_submission_resend', 1, 3),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => 'includes/webform.submissions.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Menu loader callback. Load a webform node if the given nid is a webform.
*/
function webform_menu_load($nid) {
if (!is_numeric($nid)) {
return FALSE;
}
$node = node_load($nid);
if (!isset($node->type) || !in_array($node->type, webform_variable_get('webform_node_types'))) {
return FALSE;
}
return $node;
}
/**
* Menu loader callback. Load a webform submission if the given sid is a valid.
*/
function webform_menu_submission_load($sid, $nid) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
$submission = webform_get_submission($nid, $sid);
return empty($submission) ? FALSE : $submission;
}
/**
* Menu loader callback. Load a webform component if the given cid is a valid.
*/
function webform_menu_component_load($cid, $nid, $type) {
module_load_include('inc', 'webform', 'includes/webform.components');
if ($cid == 'new') {
$components = webform_components();
$component = in_array($type, array_keys($components)) ? array('type' => $type, 'nid' => $nid, 'name' => $_GET['name'], 'mandatory' => $_GET['mandatory'], 'pid' => $_GET['pid'], 'weight' => $_GET['weight']) : FALSE;
}
else {
$node = node_load($nid);
$component = isset($node->webform['components'][$cid]) ? $node->webform['components'][$cid] : FALSE;
}
if ($component) {
webform_component_defaults($component);
}
return $component;
}
/**
* Menu loader callback. Load a webform e-mail if the given eid is a valid.
*/
function webform_menu_email_load($eid, $nid) {
module_load_include('inc', 'webform', 'includes/webform.emails');
$node = node_load($nid);
$email = webform_email_load($eid, $nid);
if ($eid == 'new') {
if (isset($_GET['option']) && isset($_GET['email'])) {
$type = $_GET['option'];
if ($type == 'custom') {
$email['email'] = $_GET['email'];
}
elseif ($type == 'component' && isset($node->webform['components'][$_GET['email']])) {
$email['email'] = $_GET['email'];
}
}
}
return $email;
}
function webform_submission_access($node, $submission, $op = 'view', $account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
$access_all = user_access('access all webform results', $account);
$access_own_submission = isset($submission) && user_access('access own webform submissions', $account) && (($account->uid && $account->uid == $submission->uid) || isset($_SESSION['webform_submission'][$submission->sid]));
$access_node_submissions = user_access('access own webform results', $account) && $account->uid == $node->uid;
$general_access = $access_all || $access_own_submission || $access_node_submissions;
// Disable the page cache for anonymous users in this access callback,
// otherwise the "Access denied" page gets cached.
if (!$account->uid && user_access('access own webform submissions', $account)) {
webform_disable_page_cache();
}
$module_access = count(array_filter(module_invoke_all('webform_submission_access', $node, $submission, $op, $account))) > 0;
switch ($op) {
case 'view':
return $module_access || $general_access;
case 'edit':
return $module_access || ($general_access && (user_access('edit all webform submissions', $account) || (user_access('edit own webform submissions', $account) && $account->uid == $submission->uid)));
case 'delete':
return $module_access || ($general_access && (user_access('delete all webform submissions', $account) || (user_access('delete own webform submissions', $account) && $account->uid == $submission->uid)));
case 'list':
return $module_access || user_access('access all webform results', $account) || (user_access('access own webform submissions', $account) && ($account->uid || isset($_SESSION['webform_submission']))) || (user_access('access own webform results', $account) && $account->uid == $node->uid);
}
}
/**
* Menu access callback. Ensure a user both access and node 'view' permission.
*/
function webform_results_access($node, $account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
$module_access = count(array_filter(module_invoke_all('webform_results_access', $node, $account))) > 0;
return node_access('view', $node, $account) && ($module_access || user_access('access all webform results', $account) || (user_access('access own webform results', $account) && $account->uid == $node->uid));
}
function webform_results_clear_access($node, $account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
$module_access = count(array_filter(module_invoke_all('webform_results_clear_access', $node, $account))) > 0;
return webform_results_access($node, $account) && ($module_access || user_access('delete all webform submissions', $account));
}
/**
* Implements hook_admin_paths().
*/
function webform_admin_paths() {
if (variable_get('node_admin_theme')) {
return array(
'node/*/webform' => TRUE,
'node/*/webform/*' => TRUE,
'node/*/webform-results' => TRUE,
'node/*/webform-results/*' => TRUE,
'node/*/submission/*' => TRUE,
);
}
}
/**
* Implements hook_perm().
*/
function webform_permission() {
return array(
'access all webform results' => array(
'title' => t('Access all webform results'),
'description' => t('Grants access to the "Results" tab on all webform content. Generally an administrative permission.'),
),
'access own webform results' => array(
'title' => t('Access own webform results'),
'description' => t('Grants access to the "Results" tab to the author of webform content they have created.'),
),
'edit all webform submissions' => array(
'title' => t('Edit all webform submissions'),
'description' => t('Allows editing of any webform submission by any user. Generally an administrative permission.'),
),
'delete all webform submissions' => array(
'title' => t('Delete all webform submissions'),
'description' => t('Allows deleting of any webform submission by any user. Generally an administrative permission.'),
),
'access own webform submissions' => array(
'title' => t('Access own webform submissions'),
),
'edit own webform submissions' => array(
'title' => t('Edit own webform submissions'),
),
'delete own webform submissions' => array(
'title' => t('Delete own webform submissions'),
),
);
}
/**
* Implements hook_theme().
*/
function webform_theme() {
$theme = array(
// webform.module.
'webform_view' => array(
'render element' => 'webform',
),
'webform_view_messages' => array(
'variables' => array('node' => NULL, 'teaser' => NULL, 'page' => NULL, 'submission_count' => NULL, 'user_limit_exceeded' => NULL, 'total_limit_exceeded' => NULL, 'allowed_roles' => NULL, 'closed' => NULL, 'cached' => NULL),
),
'webform_form' => array(
'render element' => 'form',
'template' => 'templates/webform-form',
'pattern' => 'webform_form_[0-9]+',
),
'webform_confirmation' => array(
'variables' => array('node' => NULL, 'sid' => NULL),
'template' => 'templates/webform-confirmation',
'pattern' => 'webform_confirmation_[0-9]+',
),
'webform_element' => array(
'render element' => 'element',
),
'webform_element_text' => array(
'render element' => 'element',
),
'webform_inline_radio' => array(
'render element' => 'element',
),
'webform_mail_message' => array(
'variables' => array('node' => NULL, 'submission' => NULL, 'email' => NULL),
'template' => 'templates/webform-mail',
'pattern' => 'webform_mail(_[0-9]+)?',
),
'webform_mail_headers' => array(
'variables' => array('node' => NULL, 'submission' => NULL, 'email' => NULL),
'pattern' => 'webform_mail_headers_[0-9]+',
),
'webform_token_help' => array(
'variables' => array('groups' => array()),
),
// webform.admin.inc.
'webform_admin_settings' => array(
'render element' => 'form',
'file' => 'includes/webform.admin.inc',
),
'webform_admin_content' => array(
'variables' => array('nodes' => NULL),
'file' => 'includes/webform.admin.inc',
),
// webform.emails.inc.
'webform_emails_form' => array(
'render element' => 'form',
'file' => 'includes/webform.emails.inc',
),
'webform_email_add_form' => array(
'render element' => 'form',
'file' => 'includes/webform.emails.inc',
),
'webform_email_edit_form' => array(
'render element' => 'form',
'file' => 'includes/webform.emails.inc',
),
// webform.components.inc.
'webform_components_page' => array(
'variables' => array('node' => NULL, 'form' => NULL),
'file' => 'includes/webform.components.inc',
),
'webform_components_form' => array(
'render element' => 'form',
'file' => 'includes/webform.components.inc',
),
'webform_component_select' => array(
'render element' => 'element',
'file' => 'includes/webform.components.inc',
),
// webform.pages.inc.
'webform_advanced_redirection_form' => array(
'render element' => 'form',
'file' => 'includes/webform.pages.inc',
),
'webform_advanced_submit_limit_form' => array(
'render element' => 'form',
'file' => 'includes/webform.pages.inc',
),
'webform_advanced_total_submit_limit_form' => array(
'render element' => 'form',
'file' => 'includes/webform.pages.inc',
),
// webform.report.inc.
'webform_results_per_page' => array(
'variables' => array('total_count' => NULL, 'pager_count' => NULL),
'file' => 'includes/webform.report.inc',
),
'webform_results_submissions_header' => array(
'variables' => array('node' => NULL),
'file' => 'includes/webform.report.inc',
),
'webform_results_submissions' => array(
'render element' => 'element',
'template' => 'templates/webform-results-submissions',
'file' => 'includes/webform.report.inc',
),
'webform_results_table_header' => array(
'variables' => array('node' => NULL),
'file' => 'includes/webform.report.inc',
),
'webform_results_table' => array(
'variables' => array('node' => NULL, 'components' => NULL, 'submissions' => NULL, 'node' => NULL, 'total_count' => NULL, 'pager_count' => NULL),
'file' => 'includes/webform.report.inc',
),
'webform_results_download_range' => array(
'render element' => 'element',
'file' => 'includes/webform.report.inc',
),
'webform_results_download_select_format' => array(
'render element' => 'element',
'file' => 'includes/webform.report.inc',
),
'webform_results_analysis' => array(
'variables' => array('node' => NULL, 'data' => NULL, 'sids' => array(), 'component' => NULL),
'file' => 'includes/webform.report.inc',
),
// webform.submissions.inc
'webform_submission' => array(
'render element' => 'renderable',
'template' => 'templates/webform-submission',
'pattern' => 'webform_submission_[0-9]+',
'file' => 'includes/webform.submissions.inc',
),
'webform_submission_page' => array(
'variables' => array('node' => NULL, 'submission' => NULL, 'submission_content' => NULL, 'submission_navigation' => NULL, 'submission_information' => NULL, 'submission_actions' => NULL, 'mode' => NULL),
'template' => 'templates/webform-submission-page',
'file' => 'includes/webform.submissions.inc',
),
'webform_submission_information' => array(
'variables' => array('node' => NULL, 'submission' => NULL, 'mode' => 'display'),
'template' => 'templates/webform-submission-information',
'file' => 'includes/webform.submissions.inc',
),
'webform_submission_navigation' => array(
'variables' => array('node' => NULL, 'submission' => NULL, 'mode' => NULL),
'template' => 'templates/webform-submission-navigation',
'file' => 'includes/webform.submissions.inc',
),
'webform_submission_resend' => array(
'render element' => 'form',
'file' => 'includes/webform.submissions.inc',
),
);
// Theme functions in all components.
$components = webform_components(TRUE);
foreach ($components as $type => $component) {
if ($theme_additions = webform_component_invoke($type, 'theme')) {
$theme = array_merge($theme, $theme_additions);
}
}
return $theme;
}
/**
* Implements hook_library().
*/
function webform_library() {
$module_path = drupal_get_path('module', 'webform');
// Webform administration.
$libraries['admin'] = array(
'title' => 'Webform: Administration',
'website' => 'http://drupal.org/project/webform',
'version' => '1.0',
'js' => array(
$module_path . '/js/webform-admin.js' => array('group' => JS_DEFAULT),
),
'css' => array(
$module_path . '/css/webform-admin.css' => array('group' => CSS_DEFAULT, 'weight' => 1),
),
);
return $libraries;
}
/**
* Implements hook_element_info().
*/
function webform_element_info() {
// A few of our components need to be defined here because Drupal does not
// provide these components natively. Because this hook fires on every page
// load (even on non-webform pages), we don't put this in the component .inc
// files because of the unnecessary loading that it would require.
$elements['webform_time'] = array('#input' => 'TRUE');
$elements['webform_grid'] = array('#input' => 'TRUE');
$elements['webform_email'] = array(
'#input' => TRUE,
'#theme' => 'webform_email',
'#size' => 60,
);
$elements['webform_number'] = array(
'#input' => TRUE,
'#theme' => 'webform_number',
'#min' => NULL,
'#max' => NULL,
'#step' => NULL,
);
return $elements;
}
/**
* Implements hook_webform_component_info().
*/
function webform_webform_component_info() {
$component_info = array(
'date' => array(
'label' => t('Date'),
'description' => t('Presents month, day, and year fields.'),
'features' => array(
'conditional' => FALSE,
),
'file' => 'components/date.inc',
),
'email' => array(
'label' => t('E-mail'),
'description' => t('A special textfield that accepts e-mail addresses.'),
'file' => 'components/email.inc',
'features' => array(
'email_address' => TRUE,
'spam_analysis' => TRUE,
),
),
'fieldset' => array(
'label' => t('Fieldset'),
'description' => t('Fieldsets allow you to organize multiple fields into groups.'),
'features' => array(
'csv' => FALSE,
'default_value' => FALSE,
'required' => FALSE,
'conditional' => FALSE,
'group' => TRUE,
'title_inline' => FALSE,
),
'file' => 'components/fieldset.inc',
),
'grid' => array(
'label' => t('Grid'),
'description' => t('Allows creation of grid questions, denoted by radio buttons.'),
'features' => array(
'conditional' => FALSE,
'default_value' => FALSE,
'title_inline' => FALSE,
),
'file' => 'components/grid.inc',
),
'hidden' => array(
'label' => t('Hidden'),
'description' => t('A field which is not visible to the user, but is recorded with the submission.'),
'file' => 'components/hidden.inc',
'features' => array(
'required' => FALSE,
'description' => FALSE,
'email_address' => TRUE,
'email_name' => TRUE,
'title_display' => FALSE,
'private' => FALSE,
),
),
'markup' => array(
'label' => t('Markup'),
'description' => t('Displays text as HTML in the form; does not render a field.'),
'features' => array(
'csv' => FALSE,
'default_value' => FALSE,
'description' => FALSE,
'email' => FALSE,
'required' => FALSE,
'conditional' => FALSE,
'title_display' => FALSE,
'private' => FALSE,
),
'file' => 'components/markup.inc',
),
'number' => array(
'label' => t('Number'),
'description' => t('A numeric input field (either as textfield or select list).'),
'features' => array(
),
'file' => 'components/number.inc',
),
'pagebreak' => array(
'label' => t('Page break'),
'description' => t('Organize forms into multiple pages.'),
'features' => array(
'csv' => FALSE,
'default_value' => FALSE,
'description' => FALSE,
'private' => FALSE,
'required' => FALSE,
'title_display' => FALSE,
),
'file' => 'components/pagebreak.inc',
),
'select' => array(
'label' => t('Select options'),
'description' => t('Allows creation of checkboxes, radio buttons, or select menus.'),
'file' => 'components/select.inc',
'features' => array(
'default_value' => FALSE,
'email_address' => TRUE,
'email_name' => TRUE,
),
),
'textarea' => array(
'label' => t('Textarea'),
'description' => t('A large text area that allows for multiple lines of input.'),
'file' => 'components/textarea.inc',
'features' => array(
'spam_analysis' => TRUE,
'title_inline' => FALSE,
),
),
'textfield' => array(
'label' => t('Textfield'),
'description' => t('Basic textfield type.'),
'file' => 'components/textfield.inc',
'features' => array(
'email_name' => TRUE,
'spam_analysis' => TRUE,
),
),
'time' => array(
'label' => t('Time'),
'description' => t('Presents the user with hour and minute fields. Optional am/pm fields.'),
'features' => array(
'conditional' => FALSE,
),
'file' => 'components/time.inc',
),
);
if (module_exists('file')) {
$component_info['file'] = array(
'label' => t('File'),
'description' => t('Allow users to upload files of configurable types.'),
'features' => array(
'conditional' => FALSE,
'default_value' => FALSE,
'attachment' => TRUE,
),
'file' => 'components/file.inc',
);
}
return $component_info;
}
/**
* Implements hook_forms().
*
* All webform_client_form forms share the same form handler
*/
function webform_forms($form_id) {
$forms = array();
if (strpos($form_id, 'webform_client_form_') === 0) {
$forms[$form_id]['callback'] = 'webform_client_form';
}
return $forms;
}
/**
* Implements hook_webform_select_options_info().
*/
function webform_webform_select_options_info() {
module_load_include('inc', 'webform', 'includes/webform.options');
return _webform_options_info();
}
/**
* Implements hook_webform_webform_submission_actions().
*/
function webform_webform_submission_actions($node, $submission) {
$actions = array();
$destination = drupal_get_destination();
if (module_exists('print_pdf') && user_access('access PDF version')) {
$actions['printpdf'] = array(
'title' => t('Download PDF'),
'href' => 'printpdf/' . $node->nid . '/submission/' . $submission->sid,
'query' => $destination,
);
}
if (module_exists('print') && user_access('access print')) {
$actions['print'] = array(
'title' => t('Print'),
'href' => 'print/' . $node->nid . '/submission/' . $submission->sid,
);
}
if (webform_results_access($node) && count($node->webform['emails'])) {
$actions['resend'] = array(
'title' => t('Resend e-mails'),
'href' => 'node/' . $node->nid . '/submission/' . $submission->sid . '/resend',
'query' => drupal_get_destination(),
);
}
return $actions;
}
/**
* Implements hook_webform_submission_update().
*
* We implement our own hook here to facilitate the File component, which needs
* to clean up manage file usage records and delete files from submissions that
* have been edited if necessary.
*/
function webform_webform_submission_presave($node, &$submission) {
// Check if there are any file components in this submission and if any of
// them currently contain files.
$has_file_components = FALSE;
$new_fids = array();
$old_fids = array();
foreach ($node->webform['components'] as $cid => $component) {
if ($component['type'] == 'file') {
$has_file_components = TRUE;
if (!empty($submission->data[$cid]['value'])) {
foreach ($submission->data[$cid]['value'] as $key => $value) {
if (empty($value)) {
unset($submission->data[$cid]['value'][$key]);
}
}
$new_fids = array_merge($new_fids, $submission->data[$cid]['value']);
}
}
}
if ($has_file_components) {
// If we're updating a submission, build a list of previous files.
if (isset($submission->sid)) {
$old_submission = webform_get_submission($node->nid, $submission->sid, TRUE);
foreach ($node->webform['components'] as $cid => $component) {
if ($component['type'] == 'file') {
if (!empty($old_submission->data[$cid]['value'])) {
$old_fids = array_merge($old_fids, $old_submission->data[$cid]['value']);
}
}
}
}
// Save the list of added or removed files so we can add usage in
// hook_webform_submission_insert() or _update().
$submission->file_usage = array(
// Diff the old against new to determine what files were deleted.
'deleted_fids' => array_diff($old_fids, $new_fids),
// Diff the new files against old to determine new uploads.
'added_fids' => array_diff($new_fids, $old_fids)
);
}
}
/**
* Implements hook_webform_submission_insert().
*/
function webform_webform_submission_insert($node, $submission) {
if (isset($submission->file_usage)) {
webform_component_include('file');
webform_file_usage_adjust($submission);
}
}
/**
* Implements hook_webform_submission_update().
*/
function webform_webform_submission_update($node, $submission) {
if (isset($submission->file_usage)) {
webform_component_include('file');
webform_file_usage_adjust($submission);
}
}
/**
* Implements hook_webform_submission_render_alter().
*/
function webform_webform_submission_render_alter(&$renderable) {
// If displaying a submission to end-users who are viewing their own
// submissions (and not through an e-mail), do not show hidden values.
// This needs to be implemented at the level of the entire submission, since
// individual components do not get contextual information about where they
// are being displayed.
$node = $renderable['#node'];
$is_admin = webform_results_access($node);
if (empty($renderable['#email']) && !$is_admin) {
// Find and hide the display of all hidden components.
foreach ($node->webform['components'] as $cid => $component) {
if ($component['type'] == 'hidden') {
$parents = webform_component_parent_keys($node, $component);
$element = &$renderable;
foreach ($parents as $pid) {
$element = &$element[$pid];
}
$element['#access'] = FALSE;
}
}
}
}
/**
* Implements hook_file_download().
*
* Only allow users with view webform submissions to download files.
*/
function webform_file_download($uri) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
// Determine whether this file was a webform upload.
$row = db_query("SELECT fu.id as sid, f.fid FROM {file_managed} f LEFT JOIN {file_usage} fu ON f.fid = fu.fid AND fu.module = :webform AND fu.type = :submission WHERE f.uri = :uri", array('uri' => $uri, ':webform' => 'webform', ':submission' => 'submission'))->fetchObject();
if ($row) {
$file = file_load($row->fid);
}
if (!empty($row->sid)) {
$submissions = webform_get_submissions(array('sid' => $row->sid));
$submission = reset($submissions);
}
// Grant access based on access to the submission.
if (!empty($submission)) {
$node = node_load($submission->nid);
if (webform_submission_access($node, $submission)) {
return file_get_content_headers($file);
}
}
// Grant access to files uploaded by a user before the submission is saved.
elseif (!empty($file) && !empty($_SESSION['webform_files'][$file->fid])) {
return file_get_content_headers($file);
}
}
/**
* Implements hook_node_type().
*
* Not a real hook in Drupal 7. Re-used for consistency with the D6 version.
*/
function webform_node_type($op, $info) {
$webform_types = webform_variable_get('webform_node_types');
$affected_type = isset($info->old_type) ? $info->old_type : $info->type;
$key = array_search($affected_type, $webform_types);
if ($key !== FALSE) {
if ($op == 'update') {
$webform_types[$key] = $info->type;
}
if ($op == 'delete') {
unset($webform_types[$key]);
}
variable_set('webform_node_types', $webform_types);
}
}
/**
* Implements hook_node_type_update().
*/
function webform_node_type_update($info) {
webform_node_type('update', $info);
}
/**
* Implements hook_node_type_delete().
*/
function webform_node_type_delete($info) {
webform_node_type('delete', $info);
}
/**
* Implements hook_node_insert().
*/
function webform_node_insert($node) {
if (!in_array($node->type, webform_variable_get('webform_node_types'))) {
return;
}
// If added directly through node_save(), set defaults for the node.
if (!isset($node->webform)) {
$node->webform = webform_node_defaults();
}
// Do not make an entry if this node does not have any Webform settings.
if ($node->webform == webform_node_defaults() && !in_array($node->type, webform_variable_get('webform_node_types_primary'))) {
return;
}
module_load_include('inc', 'webform', 'includes/webform.components');
module_load_include('inc', 'webform', 'includes/webform.emails');
// Insert the webform.
$node->webform['nid'] = $node->nid;
$node->webform['record_exists'] = (bool) drupal_write_record('webform', $node->webform);
// Insert the components into the database. Used with clone.module.
if (isset($node->webform['components']) && !empty($node->webform['components'])) {
foreach ($node->webform['components'] as $cid => $component) {
$component['nid'] = $node->nid; // Required for clone.module.
webform_component_insert($component);
}
}
// Insert emails. Also used with clone.module.
if (isset($node->webform['emails']) && !empty($node->webform['emails'])) {
foreach ($node->webform['emails'] as $eid => $email) {
$email['nid'] = $node->nid;
webform_email_insert($email);
}
}
// Set the per-role submission access control.
foreach (array_filter($node->webform['roles']) as $rid) {
db_insert('webform_roles')->fields(array('nid' => $node->nid, 'rid' => $rid))->execute();
}
// Flush the block cache if creating a block.
if ($node->webform['block']) {
block_flush_caches();
}
}
/**
* Implements hook_node_update().
*/
function webform_node_update($node) {
if (!in_array($node->type, webform_variable_get('webform_node_types'))) {
return;
}
// Check if this node needs a webform record at all. If it matches the
// defaults, any existing record will be deleted.
webform_check_record($node);
// If a webform row doesn't even exist, we can assume it needs to be inserted.
// If the the webform matches the defaults, no row will be inserted.
if (!$node->webform['record_exists']) {
webform_node_insert($node);
return;
}
// Update the webform entry.
$node->webform['nid'] = $node->nid;
drupal_write_record('webform', $node->webform, array('nid'));
// Compare the webform components and don't do anything if it's not needed.
// The internal cache needs to be reset here so that the cached node entity
// does not get loaded and invalidate the comparisons.
$original = node_load($node->nid, NULL, TRUE);
if ($original->webform['components'] != $node->webform['components']) {
module_load_include('inc', 'webform', 'includes/webform.components');
$original_cids = array_keys($original->webform['components']);
$current_cids = array_keys($node->webform['components']);
$all_cids = array_unique(array_merge($original_cids, $current_cids));
$deleted_cids = array_diff($original_cids, $current_cids);
$inserted_cids = array_diff($current_cids, $original_cids);
foreach ($all_cids as $cid) {
if (in_array($cid, $inserted_cids)) {
webform_component_insert($node->webform['components'][$cid]);
}
elseif (in_array($cid, $deleted_cids)) {
webform_component_delete($node, $original->webform['components'][$cid]);
}
elseif ($node->webform['components'][$cid] != $original->webform['components'][$cid]) {
$node->webform['components'][$cid]['nid'] = $node->nid;
webform_component_update($node->webform['components'][$cid]);
}
}
}
// Compare the webform e-mails and don't do anything if it's not needed.
if ($original->webform['emails'] != $node->webform['emails']) {
module_load_include('inc', 'webform', 'includes/webform.emails');
$original_eids = array_keys($original->webform['emails']);
$current_eids = array_keys($node->webform['emails']);
$all_eids = array_unique(array_merge($original_eids, $current_eids));
$deleted_eids = array_diff($original_eids, $current_eids);
$inserted_eids = array_diff($current_eids, $original_eids);
foreach ($all_eids as $eid) {
if (in_array($eid, $inserted_eids)) {
webform_email_insert($node->webform['emails'][$eid]);
}
elseif (in_array($eid, $deleted_eids)) {
webform_email_delete($node, $original->webform['emails'][$eid]);
}
elseif ($node->webform['emails'][$eid] != $original->webform['emails'][$eid]) {
$node->webform['emails'][$eid]['nid'] = $node->nid;
webform_email_update($node->webform['emails'][$eid]);
}
}
}
// Just delete and re-insert roles if they've changed.
if ($original->webform['roles'] != $node->webform['roles']) {
db_delete('webform_roles')->condition('nid', $node->nid)->execute();
foreach (array_filter($node->webform['roles']) as $rid) {
db_insert('webform_roles')->fields(array('nid' => $node->nid, 'rid' => $rid))->execute();
}
}
// Flush the block cache if block settings have been changed.
if ($node->webform['block'] != $original->webform['block']) {
block_flush_caches();
}
}
/**
* Implements hook_delete().
*/
function webform_node_delete($node) {
if (!in_array($node->type, webform_variable_get('webform_node_types'))) {
return;
}
// Allow components clean up extra data, such as uploaded files.
module_load_include('inc', 'webform', 'includes/webform.components');
foreach ($node->webform['components'] as $cid => $component) {
webform_component_delete($node, $component);
}
// Remove any trace of webform data from the database.
db_delete('webform')->condition('nid', $node->nid)->execute();
db_delete('webform_component')->condition('nid', $node->nid)->execute();
db_delete('webform_emails')->condition('nid', $node->nid)->execute();
db_delete('webform_roles')->condition('nid', $node->nid)->execute();
db_delete('webform_submissions')->condition('nid', $node->nid)->execute();
db_delete('webform_submitted_data')->condition('nid', $node->nid)->execute();
db_delete('webform_last_download')->condition('nid', $node->nid)->execute();
}
/**
* Default settings for a newly created webform node.
*/
function webform_node_defaults() {
$defaults = array(
'confirmation' => '',
'confirmation_format' => NULL,
'redirect_url' => '<confirmation>',
'teaser' => '0',
'block' => '0',
'allow_draft' => '0',
'auto_save' => '0',
'submit_notice' => '1',
'submit_text' => '',
'submit_limit' => '-1',
'submit_interval' => '-1',
'total_submit_limit' => '-1',
'total_submit_interval' => '-1',
'status' => '1',
'record_exists' => FALSE,
'roles' => array('1', '2'),
'emails' => array(),
'components' => array(),
);
drupal_alter('webform_node_defaults', $defaults);
return $defaults;
}
/**
* Implements hook_node_prepare().
*/
function webform_node_prepare($node) {
$webform_types = webform_variable_get('webform_node_types');
if (in_array($node->type, $webform_types) && !isset($node->webform)) {
$node->webform = webform_node_defaults();
}
}
/**
* Implements hook_node_load().
*/
function webform_node_load($nodes, $types) {
// Quick check to see if we need to do anything at all for these nodes.
$webform_types = webform_variable_get('webform_node_types');
if (count(array_intersect($types, $webform_types)) == 0) {
return;
}
module_load_include('inc', 'webform', 'includes/webform.components');
// Select all webforms that match these node IDs.
$result = db_select('webform')
->fields('webform')
->condition('nid', array_keys($nodes), 'IN')
->execute()
->fetchAllAssoc('nid', PDO::FETCH_ASSOC);
foreach ($result as $nid => $webform) {
// Load the basic information for each node.
$nodes[$nid]->webform = $webform;
$nodes[$nid]->webform['record_exists'] = TRUE;
}
// Load the components, emails, and defaults for all webform-enabled nodes.
// TODO: Increase efficiency here by pulling in all information all at once
// instead of individual queries.
foreach ($nodes as $nid => $node) {
if (!in_array($node->type, $webform_types)) {
continue;
}
// If a webform record doesn't exist, just return the defaults.
if (!isset($nodes[$nid]->webform)) {
$nodes[$nid]->webform = webform_node_defaults();
continue;
}
$nodes[$nid]->webform['roles'] = db_select('webform_roles')
->fields('webform_roles', array('rid'))
->condition('nid', $nid)
->execute()
->fetchCol();
$nodes[$nid]->webform['emails'] = db_select('webform_emails')
->fields('webform_emails')
->condition('nid', $nid)
->execute()
->fetchAllAssoc('eid', PDO::FETCH_ASSOC);
// Unserialize the exclude component list for e-mails.
foreach ($nodes[$nid]->webform['emails'] as $eid => $email) {
$nodes[$nid]->webform['emails'][$eid]['excluded_components'] = array_filter(explode(',', $email['excluded_components']));
if (variable_get('webform_format_override', 0)) {
$nodes[$nid]->webform['emails'][$eid]['html'] = variable_get('webform_default_format', 0);
}
}
// Load components for each node.
$nodes[$nid]->webform['components'] = db_select('webform_component')
->fields('webform_component')
->condition('nid', $nid)
->orderBy('weight')
->orderBy('name')
->execute()
->fetchAllAssoc('cid', PDO::FETCH_ASSOC);
// Do a little cleanup on each component.
foreach ($nodes[$nid]->webform['components'] as $cid => $component) {
$nodes[$nid]->webform['components'][$cid]['nid'] = $nid;
$nodes[$nid]->webform['components'][$cid]['extra'] = unserialize($component['extra']);
webform_component_defaults($nodes[$nid]->webform['components'][$cid]);
}
// Organize the components into a fieldset-based order.
if (!empty($nodes[$nid]->webform['components'])) {
$component_tree = array();
$page_count = 1;
_webform_components_tree_build($nodes[$nid]->webform['components'], $component_tree, 0, $page_count);
$nodes[$nid]->webform['components'] = _webform_components_tree_flatten($component_tree['children']);
}
}
}
/**
* Implements hook_form_alter().
*/
function webform_form_alter(&$form, $form_state, $form_id) {
$matches = array();
if (isset($form['#node']->type) && $form_id == $form['#node']->type . '_node_form' && in_array($form['#node']->type, webform_variable_get('webform_node_types'))) {
$node = $form['#node'];
// Preserve all Webform options currently set on the node.
$form['webform'] = array(
'#type' => 'value',
'#value' => $node->webform,
);
// If a new node, redirect the user to the components form after save.
if (empty($node->nid) && in_array($node->type, webform_variable_get('webform_node_types_primary'))) {
$form['actions']['submit']['#submit'][] = 'webform_form_submit';
}
}
}
/**
* Submit handler for the webform node form.
*
* Redirect the user to the components form on new node inserts. Note that this
* fires after the hook_submit() function above.
*/
function webform_form_submit($form, &$form_state) {
drupal_set_message(t('The new webform %title has been created. Add new fields to your webform with the form below.', array('%title' => $form_state['values']['title'])));
$form_state['redirect'] = 'node/' . $form_state['nid'] . '/webform/components';
}
/**
* Implements hook_node_view().
*/
function webform_node_view($node, $view_mode) {
global $user;
if (!in_array($node->type, webform_variable_get('webform_node_types'))) {
return;
}
// Set teaser and page variables a la Drupal 6.
$teaser = $view_mode == 'teaser';
$page = arg(0) == 'node' && arg(1) == $node->nid;
// If empty, a teaser, or a new node (during preview) do not display.
if (empty($node->webform['components']) || ($teaser && !$node->webform['teaser']) || empty($node->nid)) {
return;
}
// Do not include the form in the search index if indexing is disabled.
if (module_exists('search') && $view_mode == 'search_index' && !variable_get('webform_search_index', 1)) {
return;
}
$info = array();
$submission = array();
$submission_count = 0;
$enabled = TRUE;
$logging_in = FALSE;
$total_limit_exceeded = FALSE;
$user_limit_exceeded = FALSE;
$closed = FALSE;
$allowed_roles = array();
// If a teaser, tell the form to load subsequent pages on the node page.
if ($teaser && !isset($node->webform['action'])) {
$query = array_diff_key($_GET, array('q' => ''));
$node->webform['action'] = url('node/' . $node->nid, array('query' => $query));
}
// When logging in using a form on the same page as a webform node, suppress
// output messages so that they don't show up after the user has logged in.
// See http://drupal.org/node/239343.
if (isset($_POST['op']) && isset($_POST['name']) && isset($_POST['pass'])) {
$logging_in = TRUE;
}
if ($node->webform['status'] == 0) {
$closed = TRUE;
$enabled = FALSE;
}
else {
// Check if the user's role can submit this webform.
if (variable_get('webform_submission_access_control', 1)) {
foreach ($node->webform['roles'] as $rid) {
$allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
}
if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
$enabled = FALSE;
}
}
else {
// If not using Webform submission access control, allow for all roles.
$allowed_roles = array_keys(user_roles());
}
}
// Get a count of previous submissions by this user. Note that the
// webform_submission_access() function may disable the page cache for
// anonymous users if they are allowed to edit their own submissions!
if ($page && webform_submission_access($node, NULL, 'list')) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
$submission_count = webform_get_submission_count($node->nid, $user->uid);
}
// Check if this page is cached or not.
$cached = $user->uid == 0 && (variable_get('cache', 0) || drupal_page_is_cacheable() === FALSE);
// Check if the user can add another submission.
if ($node->webform['submit_limit'] != -1) { // -1: Submissions are never throttled.
module_load_include('inc', 'webform', 'includes/webform.submissions');
// Disable the form if the limit is exceeded and page cache is not active.
if (($user_limit_exceeded = _webform_submission_user_limit_check($node)) && !$cached) {
$enabled = FALSE;
}
}
// Check if the user can add another submission if there is a limit on total
// submissions.
if ($node->webform['total_submit_limit'] != -1) { // -1: Submissions are never throttled.
module_load_include('inc', 'webform', 'includes/webform.submissions');
// Disable the form if the limit is exceeded and page cache is not active.
if (($total_limit_exceeded = _webform_submission_total_limit_check($node)) && !$cached) {
$enabled = FALSE;
}
}
// Check if this user has a draft for this webform.
$is_draft = FALSE;
if (($node->webform['allow_draft'] || $node->webform['auto_save']) && $user->uid != 0) {
// Draft found - display form with draft data for further editing.
if ($draft_sid = _webform_fetch_draft_sid($node->nid, $user->uid)) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
$submission = webform_get_submission($node->nid, $draft_sid);
$enabled = TRUE;
$is_draft = TRUE;
}
}
// Render the form and generate the output.
$form = !empty($node->webform['components']) ? drupal_get_form('webform_client_form_' . $node->nid, $node, $submission, $is_draft) : '';
// Remove the surrounding <form> tag if this is a preview.
if (!empty($node->in_preview)) {
$form['#type'] = 'markup';
}
// Print out messages for the webform.
if (empty($node->in_preview) && !isset($node->webform_block) && !$logging_in) {
theme('webform_view_messages', array('node' => $node, 'teaser' => $teaser, 'page' => $page, 'submission_count' => $submission_count, 'user_limit_exceeded' => $user_limit_exceeded, 'total_limit_exceeded' => $total_limit_exceeded, 'allowed_roles' => $allowed_roles, 'closed' => $closed, 'cached' => $cached));
}
// Add the output to the node.
$node->content['webform'] = array(
'#theme' => 'webform_view',
'#node' => $node,
'#teaser' => $teaser,
'#page' => $page,
'#form' => $form,
'#enabled' => $enabled,
'#weight' => 10,
);
}
/**
* Output the Webform into the node content.
*
* @param $node
* The webform node object.
* @param $teaser
* If this webform is being displayed as the teaser view of the node.
* @param $page
* If this webform node is being viewed as the main content of the page.
* @param $form
* The rendered form.
* @param $enabled
* If the form allowed to be completed by the current user.
*/
function theme_webform_view($variables) {
// Only show the form if this user is allowed access.
if ($variables['webform']['#enabled']) {
return drupal_render($variables['webform']['#form']);
}
}
/**
* Display a message to a user if they are not allowed to fill out a form.
*
* @param $node
* The webform node object.
* @param $teaser
* If this webform is being displayed as the teaser view of the node.
* @param $page
* If this webform node is being viewed as the main content of the page.
* @param $submission_count
* The number of submissions this user has already submitted. Not calculated
* for anonymous users.
* @param $user_limit_exceeded
* Boolean value if the submission limit for this user has been exceeded.
* @param $total_limit_exceeded
* Boolean value if the total submission limit has been exceeded.
* @param $allowed_roles
* A list of user roles that are allowed to submit this webform.
* @param $closed
* Boolean value if submissions are closed.
*/
function theme_webform_view_messages($variables) {
global $user;
$node = $variables['node'];
$teaser = $variables['teaser'];
$page = $variables['page'];
$submission_count = $variables['submission_count'];
$user_limit_exceeded = $variables['user_limit_exceeded'];
$total_limit_exceeded = $variables['total_limit_exceeded'];
$allowed_roles = $variables['allowed_roles'];
$closed = $variables['closed'];
$cached = $variables['cached'];
$type = 'status';
if ($closed) {
$message = t('Submissions for this form are closed.');
}
// If open and not allowed to submit the form, give an explanation.
elseif (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
if (empty($allowed_roles)) {
// No roles are allowed to submit the form.
$message = t('Submissions for this form are closed.');
}
elseif (isset($allowed_roles[2])) {
// The "authenticated user" role is allowed to submit and the user is currently logged-out.
$login = url('user/login', array('query' => drupal_get_destination()));
$register = url('user/register', array('query' => drupal_get_destination()));
if (variable_get('user_register', 1) == 0) {
$message = t('You must <a href="!login">login</a> to view this form.', array('!login' => $login));
}
else {
$message = t('You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.', array('!login' => $login, '!register' => $register));
}
}
else {
// The user must be some other role to submit.
$message = t('You do not have permission to view this form.');
$type = 'error';
}
}
// If the user has exceeded the limit of submissions, explain the limit.
elseif ($user_limit_exceeded && !$cached) {
if ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] > 1) {
$message = t('You have submitted this form the maximum number of times (@count).', array('@count' => $node->webform['submit_limit']));
}
elseif ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] == 1) {
$message = t('You have already submitted this form.');
}
else {
$message = t('You may not submit another entry at this time.');
}
$type = 'error';
}
elseif ($total_limit_exceeded && !$cached) {
if ($node->webform['total_submit_interval'] == -1 && $node->webform['total_submit_limit'] > 1) {
$message = t('This form has received the maximum number of entries.');
}
else {
$message = t('You may not submit another entry at this time.');
}
}
// If the user has submitted before, give them a link to their submissions.
if ($submission_count > 0 && $node->webform['submit_notice'] == 1 && !$cached) {
if (empty($message)) {
$message = t('You have already submitted this form.') . ' ' . t('<a href="!url">View your previous submissions</a>.', array('!url' => url('node/' . $node->nid . '/submissions')));
}
else {
$message .= ' ' . t('<a href="!url">View your previous submissions</a>.', array('!url' => url('node/' . $node->nid . '/submissions')));
}
}
if ($page && isset($message)) {
drupal_set_message($message, $type, FALSE);
}
}
/**
* Implements hook_mail().
*/
function webform_mail($key, &$message, $params) {
$message['headers'] = array_merge($message['headers'], $params['headers']);
$message['subject'] = $params['subject'];
$message['body'][] = $params['message'];
}
/**
* Implements hook_block_info().
*/
function webform_block_info() {
$blocks = array();
$webform_node_types = webform_variable_get('webform_node_types');
if (!empty($webform_node_types)) {
$query = db_select('webform', 'w')->fields('w')->fields('n', array('title'));
$query->leftJoin('node', 'n', 'w.nid = n.nid');
$query->condition('w.block', 1);
$query->condition('n.type', $webform_node_types, 'IN');
$result = $query->execute();
foreach ($result as $data) {
$blocks['client-block-' . $data->nid] = array(
'info' => t('Webform: !title', array('!title' => $data->title)),
'cache' => DRUPAL_NO_CACHE,
);
}
}
return $blocks;
}
/**
* Implements hook_block_view().
*/
function webform_block_view($delta = '') {
global $user;
// Load the block-specific configuration settings.
$webform_blocks = variable_get('webform_blocks', array());
$settings = isset($webform_blocks[$delta]) ? $webform_blocks[$delta] : array();
$settings += array(
'display' => 'form',
'pages_block' => 0,
);
// Get the node ID from delta.
$nid = drupal_substr($delta, strrpos($delta, '-') + 1);
// Load node in current language.
if (module_exists('translation')) {
global $language;
if (($translations = translation_node_get_translations($nid)) && (isset($translations[$language->language]))) {
$nid = $translations[$language->language]->nid;
}
}
// The webform node to display in the block.
$node = node_load($nid);
// Return if user has no access to the webform node.
if (!node_access('view', $node)) {
return;
}
// This is a webform node block.
$node->webform_block = TRUE;
// Use the node title for the block title.
$subject = $node->title;
// If not displaying pages in the block, set the #action property on the form.
if ($settings['pages_block']) {
$node->webform['action'] = FALSE;
}
else {
$query = array_diff_key($_GET, array('q' => ''));
$node->webform['action'] = url('node/' . $node->nid, array('query' => $query));
}
// Generate the content of the block based on display settings.
if ($settings['display'] == 'form') {
webform_node_view($node, 'full');
$content = isset($node->content['webform']) ? $node->content['webform'] : array();
}
else {
$teaser = ($settings['display'] == 'teaser') ? 'teaser' : 'full';
$content = node_view($node, $teaser);
}
// Add contextual links for the webform node if they aren't already there.
if (!isset($content['#contextual_links']['node'])) {
$content['#contextual_links']['node'] = array('node', array($node->nid));
}
// Create the block.
// Note that we render the content immediately here rather than passing back
// a renderable so that if the block is empty it is hidden.
$block = array(
'subject' => $subject,
'content' => drupal_render($content),
);
return $block;
}
/**
* Implements hook_block_configure().
*/
function webform_block_configure($delta = '') {
// Load the block-specific configuration settings.
$webform_blocks = variable_get('webform_blocks', array());
$settings = isset($webform_blocks[$delta]) ? $webform_blocks[$delta] : array();
$settings += array(
'display' => 'form',
'pages_block' => 0,
);
$form = array();
$form['display'] = array(
'#type' => 'radios',
'#title' => t('Display mode'),
'#default_value' => $settings['display'],
'#options' => array(
'form' => t('Form only'),
'full' => t('Full node'),
'teaser' => t('Teaser'),
),
'#description' => t('The display mode determines how much of the webform to show within the block.'),
);
$form['pages_block'] = array(
'#type' => 'checkbox',
'#title' => t('Show all webform pages in block'),
'#default_value' => $settings['pages_block'],
'#description' => t('By default multi-page webforms redirect to the node page for all pages after the first one. If checked, all pages will be shown in the block instead.'),
);
return $form;
}
/**
* Implements hook_block_save().
*/
function webform_block_save($delta = '', $edit = array()) {
// Load the previously defined block-specific configuration settings.
$settings = variable_get('webform_blocks', array());
// Build the settings array.
$new_settings[$delta] = array(
'display' => $edit['display'],
'pages_block' => $edit['pages_block'],
);
// We store settings for multiple blocks in just one variable
// so we merge the existing settings with the new ones before save.
variable_set('webform_blocks', array_merge($settings, $new_settings));
}
/**
* Client form generation function. If this is displaying an existing
* submission, pass in the $submission variable with the contents of the
* submission to be displayed.
*
* @param $form
* The current form array (always empty).
* @param $form_state
* The current form values of a submission, used in multipage webforms.
* @param $node
* The current webform node.
* @param $submission
* An object containing information about the form submission if we're
* displaying a result.
* @param $is_draft
* Optional. Set to TRUE if displaying a draft.
* @param $filter
* Whether or not to filter the contents of descriptions and values when
* building the form. Values need to be unfiltered to be editable by
* Form Builder.
*/
function webform_client_form($form, &$form_state, $node, $submission, $is_draft = FALSE, $filter = TRUE) {
global $user;
// Attach necessary JavaScript and CSS.
$form['#attached'] = array(
'css' => array(drupal_get_path('module', 'webform') . '/css/webform.css'),
'js' => array(drupal_get_path('module', 'webform') . '/js/webform.js'),
);
form_load_include($form_state, 'inc', 'webform', 'includes/webform.components');
form_load_include($form_state, 'inc', 'webform', 'includes/webform.submissions');
$form['#process'] = array(
'webform_client_form_includes',
);
// If in a multi-step form, a submission ID may be specified in form state.
// Load this submission. This allows anonymous users to use auto-save.
if (empty($submission) && !empty($form_state['values']['details']['sid'])) {
$submission = webform_get_submission($node->nid, $form_state['values']['details']['sid']);
$is_draft = $submission->is_draft;
}
// Bind arguments to $form to make them available in theming and form_alter.
$form['#node'] = $node;
$form['#submission'] = $submission;
$form['#is_draft'] = $is_draft;
$form['#filter'] = $filter;
// Add a theme function for this form.
$form['#theme'] = array('webform_form_' . $node->nid, 'webform_form');
// Add a css class for all client forms.
$form['#attributes'] = array('class' => array('webform-client-form'));
// Set the encoding type (necessary for file uploads).
$form['#attributes']['enctype'] = 'multipart/form-data';
// Sometimes when displaying a webform as a teaser or block, a custom action
// property is set to direct the user to the node page.
if (!empty($node->webform['action'])) {
$form['#action'] = $node->webform['action'];
}
$form['#submit'] = array('webform_client_form_pages', 'webform_client_form_submit');
$form['#validate'] = array('webform_client_form_validate');
if (is_array($node->webform['components']) && !empty($node->webform['components'])) {
// Prepare a new form array.
$form['submitted'] = array(
'#tree' => TRUE
);
$form['details'] = array(
'#tree' => TRUE,
);
// Put the components into a tree structure.
if (!isset($form_state['storage']['component_tree'])) {
$form_state['webform']['component_tree'] = array();
$form_state['webform']['page_count'] = 1;
$form_state['webform']['page_num'] = 1;
_webform_components_tree_build($node->webform['components'], $form_state['webform']['component_tree'], 0, $form_state['webform']['page_count']);
}
else {
$form_state['webform']['component_tree'] = $form_state['storage']['component_tree'];
$form_state['webform']['page_count'] = $form_state['storage']['page_count'];
$form_state['webform']['page_num'] = $form_state['storage']['page_num'];
}
// Shorten up our variable names.
$component_tree = $form_state['webform']['component_tree'];
$page_count = $form_state['webform']['page_count'];
$page_num = $form_state['webform']['page_num'];
if ($page_count > 1) {
$next_page_labels = array();
$prev_page_labels = array();
}
// Recursively add components to the form. The unfiltered version of the
// form (typically used in Form Builder), includes all components.
foreach ($component_tree['children'] as $cid => $component) {
$component_value = isset($form_state['values']['submitted'][$cid]) ? $form_state['values']['submitted'][$cid] : NULL;
if ($filter == FALSE || _webform_client_form_rule_check($node, $component, $page_num, $form_state)) {
if ($component['type'] == 'pagebreak') {
$next_page_labels[$component['page_num'] - 1] = !empty($component['extra']['next_page_label']) ? t($component['extra']['next_page_label']) : t('Next Page >');
$prev_page_labels[$component['page_num']] = !empty($component['extra']['prev_page_label']) ? t($component['extra']['prev_page_label']) : t('< Previous Page');
}
_webform_client_form_add_component($node, $component, $component_value, $form['submitted'], $form, $form_state, $submission, 'form', $page_num, $filter);
}
}
// These form details help managing data upon submission.
$form['details']['nid'] = array(
'#type' => 'value',
'#value' => $node->nid,
);
$form['details']['sid'] = array(
'#type' => 'hidden',
'#value' => isset($submission->sid) ? $submission->sid : NULL,
);
$form['details']['uid'] = array(
'#type' => 'value',
'#value' => isset($submission->uid) ? $submission->uid : $user->uid,
);
$form['details']['page_num'] = array(
'#type' => 'hidden',
'#value' => $page_num,
);
$form['details']['page_count'] = array(
'#type' => 'hidden',
'#value' => $page_count,
);
$form['details']['finished'] = array(
'#type' => 'hidden',
'#value' => isset($submission->is_draft) ? (!$submission->is_draft) : 0,
);
// Add buttons for pages, drafts, and submissions.
$form['actions'] = array(
'#type' => 'actions',
'#weight' => 1000,
);
// Add the draft button.
if ($node->webform['allow_draft'] && (empty($submission) || $submission->is_draft) && $user->uid != 0) {
$form['actions']['draft'] = array(
'#type' => 'submit',
'#value' => t('Save Draft'),
'#weight' => -2,
'#validate' => array(),
'#attributes' => array('formnovalidate' => 'formnovalidate'),
);
}
if ($page_count > 1) {
// Add the submit button(s).
if ($page_num > 1) {
$form['actions']['previous'] = array(
'#type' => 'submit',
'#value' => $prev_page_labels[$page_num],
'#weight' => 5,
'#validate' => array(),
'#attributes' => array('formnovalidate' => 'formnovalidate'),
);
}
if ($page_num == $page_count) {
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => empty($node->webform['submit_text']) ? t('Submit') : t($node->webform['submit_text']),
'#weight' => 10,
);
}
elseif ($page_num < $page_count) {
$form['actions']['next'] = array(
'#type' => 'submit',
'#value' => $next_page_labels[$page_num],
'#weight' => 10,
);
}
}
else {
// Add the submit button.
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => empty($node->webform['submit_text']) ? t('Submit') : t($node->webform['submit_text']),
'#weight' => 10,
);
}
}
return $form;
}
/**
* Process function for webform_client_form().
*
* Include all the enabled components for this form to ensure availability.
*/
function webform_client_form_includes($form, $form_state) {
$components = webform_components();
foreach ($components as $component_type => $component) {
webform_component_include($component_type);
}
return $form;
}
/**
* Check if a component should be displayed on the current page.
*/
function _webform_client_form_rule_check($node, $component, $page_num, $form_state = NULL, $submission = NULL) {
$conditional_values = isset($component['extra']['conditional_values']) ? $component['extra']['conditional_values'] : NULL;
$conditional_component = isset($component['extra']['conditional_component']) && isset($node->webform['components'][$component['extra']['conditional_component']]) ? $node->webform['components'][$component['extra']['conditional_component']] : NULL;
$conditional_cid = $conditional_component['cid'];
// Check the rules for this entire page. Note individual page breaks are
// checked down below in the individual component rule checks.
$show_page = TRUE;
if ($component['page_num'] > 1 && $component['type'] != 'pagebreak') {
foreach ($node->webform['components'] as $cid => $page_component) {
if ($page_component['type'] == 'pagebreak' && $page_component['page_num'] == $page_num) {
$show_page = _webform_client_form_rule_check($node, $page_component, $page_num, $form_state, $submission);
break;
}
}
}
// Check any parents' visibility rules.
$show_parent = $show_page;
if ($show_parent && $component['pid'] && isset($node->webform['components'][$component['pid']])) {
$parent_component = $node->webform['components'][$component['pid']];
$show_parent = _webform_client_form_rule_check($node, $parent_component, $page_num, $form_state, $submission);
}
// Check the individual component rules.
$show_component = $show_parent;
if ($show_component && ($page_num == 0 || $component['page_num'] == $page_num) && $conditional_component && strlen(trim($conditional_values))) {
$input_values = array();
if (isset($form_state)) {
$input_value = isset($form_state['values']['submitted'][$conditional_cid]) ? $form_state['values']['submitted'][$conditional_cid] : NULL;
$input_values = is_array($input_value) ? $input_value : array($input_value);
}
elseif (isset($submission)) {
$input_values = isset($submission->data[$conditional_cid]['value']) ? $submission->data[$conditional_cid]['value'] : array();
}
$test_values = array_map('trim', explode("\n", $conditional_values));
if (empty($input_values) && !empty($test_values)) {
$show_component = FALSE;
}
else {
foreach ($input_values as $input_value) {
if ($show_component = in_array($input_value, $test_values)) {
break;
}
}
}
if ($component['extra']['conditional_operator'] == '!=') {
$show_component = !$show_component;
}
}
// Private component?
if ($component['extra']['private']) {
$show_component = webform_results_access($node);
}
return $show_component;
}
/**
* Add a component to a renderable array. Called recursively for fieldsets.
*
* This function assists in the building of the client form, as well as the
* display of results, and the text of e-mails.
*
* @param $component
* The component to be added to the form.
* @param $component_value
* The components current value if known.
* @param $parent_fieldset
* The fieldset to which this element will be added.
* @param $form
* The entire form array.
* @param $form_state
* The form state.
* @param $submission
* The Webform submission as retrieved from the database.
* @param $format
* The format the form should be displayed as. May be one of the following:
* - form: Show as an editable form.
* - html: Show as HTML results.
* - text: Show as plain text.
* @param $filter
* Whether the form element properties should be filtered. Only set to FALSE
* if needing the raw properties for editing.
*
* @see webform_client_form()
* @see webform_submission_render()
*/
function _webform_client_form_add_component($node, $component, $component_value, &$parent_fieldset, &$form, $form_state, $submission, $format = 'form', $page_num = 0, $filter = TRUE) {
$cid = $component['cid'];
// Load with submission information if necessary.
if ($format != 'form') {
// This component is display only.
$data = empty($submission->data[$cid]['value']) ? NULL : $submission->data[$cid]['value'];
if ($display_element = webform_component_invoke($component['type'], 'display', $component, $data, $format)) {
// Ensure the component is added as a property.
$display_element['#webform_component'] = $component;
// Allow modules to modify a "display only" webform component.
drupal_alter('webform_component_display', $display_element, $component);
// The form_builder() function usually adds #parents and #id for us, but
// because these are not marked for #input, we need to add them manually.
if (!isset($display_element['#parents'])) {
$parents = isset($parent_fieldset['#parents']) ? $parent_fieldset['#parents'] : array('submitted');
$parents[] = $component['form_key'];
$display_element['#parents'] = $parents;
}
if (!isset($display_element['#id'])) {
$display_element['#id'] = drupal_clean_css_identifier('edit-' . implode('-', $display_element['#parents']));
}
// Add the element into the proper parent in the display.
$parent_fieldset[$component['form_key']] = $display_element;
}
}
// Show the component only on its form page, or if building an unfiltered
// version of the form (such as for Form Builder).
elseif ($component['page_num'] == $page_num || $filter == FALSE) {
// Add this user-defined field to the form (with all the values that are always available).
$data = isset($submission->data[$cid]['value']) ? $submission->data[$cid]['value'] : NULL;
if ($element = webform_component_invoke($component['type'], 'render', $component, $data, $filter)) {
// Ensure the component is added as a property.
$element['#webform_component'] = $component;
// The 'private' option is in most components, but it's not a real
// property. Add it for Form Builder compatibility.
if (webform_component_feature($component['type'], 'private')) {
$element['#webform_private'] = $component['extra']['private'];
}
// Allow modules to modify a webform component that is going to be render in a form.
drupal_alter('webform_component_render', $element, $component);
// Add the element into the proper parent in the form.
$parent_fieldset[$component['form_key']] = $element;
// Override the value if one already exists in the form state.
if (isset($component_value)) {
$parent_fieldset[$component['form_key']]['#default_value'] = $component_value;
if (is_array($component_value)) {
foreach ($component_value as $key => $value) {
if (isset($parent_fieldset[$component['form_key']][$key])) {
$parent_fieldset[$component['form_key']][$key]['#default_value'] = $value;
}
}
}
}
}
else {
drupal_set_message(t('The webform component @type is not able to be displayed', array('@type' => $component['type'])));
}
}
// Disable validation initially on all elements. We manually validate
// all webform elements in webform_client_form_validate().
if (isset($parent_fieldset[$component['form_key']])) {
$parent_fieldset[$component['form_key']]['#validated'] = TRUE;
$parent_fieldset[$component['form_key']]['#webform_validated'] = FALSE;
}
if (isset($component['children']) && is_array($component['children'])) {
foreach ($component['children'] as $scid => $subcomponent) {
$subcomponent_value = isset($form_state['values']['submitted'][$scid]) ? $form_state['values']['submitted'][$scid] : NULL;
if (_webform_client_form_rule_check($node, $subcomponent, $page_num, $form_state, $submission)) {
_webform_client_form_add_component($node, $subcomponent, $subcomponent_value, $parent_fieldset[$component['form_key']], $form, $form_state, $submission, $format, $page_num, $filter);
}
}
}
}
function webform_client_form_validate($form, &$form_state) {
$node = node_load($form_state['values']['details']['nid']);
$finished = $form_state['values']['details']['finished'];
// Check that the submissions have not exceeded the total submission limit.
if ($node->webform['total_submit_limit'] != -1) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
// Check if the total number of entries was reached before the user submitted
// the form.
if (!$finished && $total_limit_exceeded = _webform_submission_total_limit_check($node)) {
// Show the user the limit has exceeded.
theme('webform_view_messages', array('node' => $node, 'teaser' => 0, 'page' => 1, 'submission_count' => 0, 'total_limit_exceeded' => $total_limit_exceeded, 'allowed_roles' => array_keys(user_roles()), 'closed' => FALSE, 'cached' => FALSE));
form_set_error('', NULL);
return;
}
}
// Check that the user has not exceeded the submission limit.
// This usually will only apply to anonymous users when the page cache is
// enabled, because they may submit the form even if they do not have access.
if ($node->webform['submit_limit'] != -1) { // -1: Submissions are never throttled.
module_load_include('inc', 'webform', 'includes/webform.submissions');
if (!$finished && $user_limit_exceeded = _webform_submission_user_limit_check($node)) {
// Assume that webform_view_messages will print out the necessary message,
// then stop the processing of the form with an empty form error.
theme('webform_view_messages', array('node' => $node, 'teaser' => 0, 'page' => 1, 'submission_count' => 0, 'user_limit_exceeded' => $user_limit_exceeded, 'allowed_roles' => array_keys(user_roles()), 'closed' => FALSE, 'cached' => FALSE));
form_set_error('', NULL);
return;
}
}
// Run all #element_validate and #required checks. These are skipped initially
// by setting #validated = TRUE on all components when they are added.
_webform_client_form_validate($form, $form_state);
}
/**
* Recursive validation function to trigger normal Drupal validation.
*
* This function imitates _form_validate in Drupal's form.inc, only it sets
* a different property to ensure that validation has occurred.
*/
function _webform_client_form_validate($elements, &$form_state, $first_run = TRUE) {
static $form;
if ($first_run) {
$form = $elements;
}
// Recurse through all children.
foreach (element_children($elements) as $key) {
if (isset($elements[$key]) && $elements[$key]) {
_webform_client_form_validate($elements[$key], $form_state, FALSE);
}
}
// Validate the current input.
if (isset($elements['#webform_validated']) && $elements['#webform_validated'] == FALSE) {
if (isset($elements['#needs_validation'])) {
// Make sure a value is passed when the field is required.
// A simple call to empty() will not cut it here as some fields, like
// checkboxes, can return a valid value of '0'. Instead, check the
// length if it's a string, and the item count if it's an array. For
// radios, FALSE means that no value was submitted, so check that too.
if ($elements['#required'] && (!count($elements['#value']) || (is_string($elements['#value']) && strlen(trim($elements['#value'])) == 0) || $elements['#value'] === FALSE)) {
form_error($elements, t('!name field is required.', array('!name' => $elements['#title'])));
}
// Verify that the value is not longer than #maxlength.
if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
form_error($elements, t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));
}
if (isset($elements['#options']) && isset($elements['#value'])) {
if ($elements['#type'] == 'select') {
$options = form_options_flatten($elements['#options']);
}
else {
$options = $elements['#options'];
}
if (is_array($elements['#value'])) {
$value = $elements['#type'] == 'checkboxes' ? array_keys(array_filter($elements['#value'])) : $elements['#value'];
foreach ($value as $v) {
if (!isset($options[$v])) {
form_error($elements, t('An illegal choice has been detected. Please contact the site administrator.'));
watchdog('form', 'Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
}
}
}
elseif ($elements['#value'] !== '' && !isset($options[$elements['#value']])) {
form_error($elements, t('An illegal choice has been detected. Please contact the site administrator.'));
watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
}
}
}
// Call any element-specific validators. These must act on the element
// #value data.
if (isset($elements['#element_validate'])) {
foreach ($elements['#element_validate'] as $function) {
if (function_exists($function)) {
$function($elements, $form_state, $form);
}
}
}
$elements['#webform_validated'] = TRUE;
}
}
/**
* Handle the processing of pages and conditional logic.
*/
function webform_client_form_pages($form, &$form_state) {
$node = node_load($form_state['values']['details']['nid']);
// Multistep forms may not have any components on the first page.
if (!isset($form_state['values']['submitted'])) {
$form_state['values']['submitted'] = array();
}
// Move special settings to storage.
if (isset($form_state['webform']['component_tree'])) {
$form_state['storage']['component_tree'] = $form_state['webform']['component_tree'];
$form_state['storage']['page_count'] = $form_state['webform']['page_count'];
$form_state['storage']['page_num'] = $form_state['webform']['page_num'];
}
// Perform post processing by components.
_webform_client_form_submit_process($node, $form_state['values']['submitted']);
// Flatten trees within the submission.
$form_state['values']['submitted_tree'] = $form_state['values']['submitted'];
$form_state['values']['submitted'] = _webform_client_form_submit_flatten($node, $form_state['values']['submitted']);
// Assume the form is completed unless the page logic says otherwise.
$form_state['webform_completed'] = TRUE;
// Check for a multi-page form that is not yet complete.
$submit_op = !empty($form['actions']['submit']['#value']) ? $form['actions']['submit']['#value'] : t('Submit');
$draft_op = !empty($form['actions']['draft']['#value']) ? $form['actions']['draft']['#value'] : t('Save Draft');
if (!in_array($form_state['values']['op'], array($submit_op, $draft_op))) {
// Store values from the current page in the form state storage.
if (is_array($form_state['values']['submitted'])) {
foreach ($form_state['values']['submitted'] as $key => $val) {
$form_state['storage']['submitted'][$key] = $val;
}
}
// Update form state values with those from storage.
if (isset($form_state['storage']['submitted'])) {
foreach ($form_state['storage']['submitted'] as $key => $val) {
$form_state['values']['submitted'][$key] = $val;
}
}
// Set the page number.
if (!isset($form_state['storage']['page_num'])) {
$form_state['storage']['page_num'] = 1;
}
if (end($form_state['clicked_button']['#parents']) == 'next') {
$direction = 1;
}
else {
$direction = 0;
}
// If the next page has no components that need to be displayed, skip it.
if (isset($direction)) {
$components = $direction ? $node->webform['components'] : array_reverse($node->webform['components'], TRUE);
$last_component = end($node->webform['components']);
foreach ($components as $component) {
if ($component['type'] == 'pagebreak' && (
$direction == 1 && $component['page_num'] > $form_state['storage']['page_num'] ||
$direction == 0 && $component['page_num'] <= $form_state['storage']['page_num'])) {
$previous_pagebreak = $component;
continue;
}
if (isset($previous_pagebreak)) {
$page_num = $previous_pagebreak['page_num'] + $direction - 1;
// If we've found an component on this page, advance to that page.
if ($component['page_num'] == $page_num && _webform_client_form_rule_check($node, $component, $page_num, $form_state)) {
$form_state['storage']['page_num'] = $page_num;
break;
}
// If we've gotten to the end of the form without finding any more
// components, set the page number more than the max, ending the form.
elseif ($direction && $component['cid'] == $last_component['cid']) {
$form_state['storage']['page_num'] = $page_num + 1;
}
}
}
}
// The form is done if the page number is greater than the page count.
$form_state['webform_completed'] = $form_state['storage']['page_num'] > $form_state['storage']['page_count'];
}
// Merge any stored submission data for multistep forms.
if (isset($form_state['storage']['submitted'])) {
$original_values = is_array($form_state['values']['submitted']) ? $form_state['values']['submitted'] : array();
unset($form_state['values']['submitted']);
foreach ($form_state['storage']['submitted'] as $key => $val) {
$form_state['values']['submitted'][$key] = $val;
}
foreach ($original_values as $key => $val) {
$form_state['values']['submitted'][$key] = $val;
}
// Remove the variable so it doesn't show up in the additional processing.
unset($original_values);
}
// Inform the submit handlers that a draft will be saved.
$form_state['save_draft'] = $form_state['values']['op'] == $draft_op || ($node->webform['auto_save'] && !$form_state['webform_completed']);
// Determine what we need to do on the next page.
if (!empty($form_state['save_draft']) || !$form_state['webform_completed']) {
// Rebuild the form and display the current (on drafts) or next page.
$form_state['rebuild'] = TRUE;
}
else {
// Remove the form state storage now that we're done with the pages.
$form_state['rebuild'] = FALSE;
unset($form_state['storage']);
}
}
/**
* Submit handler for saving the form values and sending e-mails.
*/
function webform_client_form_submit($form, &$form_state) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
module_load_include('inc', 'webform', 'includes/webform.components');
global $user;
if (empty($form_state['save_draft']) && empty($form_state['webform_completed'])) {
return;
}
$node = $form['#node'];
$sid = $form_state['values']['details']['sid'] ? (int) $form_state['values']['details']['sid'] : NULL;
// Check if user is submitting as a draft.
$is_draft = (int) !empty($form_state['save_draft']);
if (!$sid) {
// Create a new submission object.
$submission = (object) array(
'nid' => $node->nid,
'uid' => $form_state['values']['details']['uid'],
'submitted' => REQUEST_TIME,
'remote_addr' => ip_address(),
'is_draft' => $is_draft,
'data' => webform_submission_data($node, $form_state['values']['submitted']),
);
}
else {
// To maintain time and user information, load the existing submission.
$submission = webform_get_submission($node->webform['nid'], $sid);
$submission->is_draft = $is_draft;
// Merge with new submission data. The + operator maintains numeric keys.
// This maintains existing data with just-submitted data when a user resumes
// a submission previously saved as a draft.
$new_data = webform_submission_data($node, $form_state['values']['submitted']);
$submission->data = $new_data + $submission->data;
}
// If there is no data to be saved (such as on a multipage form with no fields
// on the first page), process no further. Submissions with no data cannot
// be loaded from the database as efficiently, so we don't save them at all.
if (empty($submission->data)) {
return;
}
// Save the submission to the database.
if (!$sid) {
// No sid was found thus insert it in the dataabase.
$form_state['values']['details']['sid'] = $sid = webform_submission_insert($node, $submission);
$form_state['values']['details']['is_new'] = TRUE;
// Set a cookie including the server's submission time.
// The cookie expires in the length of the interval plus a day to compensate for different timezones.
if (variable_get('webform_use_cookies', 0)) {
$cookie_name = 'webform-' . $node->nid;
$time = REQUEST_TIME;
$params = session_get_cookie_params();
setcookie($cookie_name . '[' . $time . ']', $time, $time + $node->webform['submit_interval'] + 86400, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
// Save session information about this submission for anonymous users,
// allowing them to access or edit their submissions.
if (!$user->uid && user_access('access own webform submissions')) {
$_SESSION['webform_submission'][$form_state['values']['details']['sid']] = $node->nid;
}
}
else {
// Sid was found thus update the existing sid in the database.
webform_submission_update($node, $submission);
$form_state['values']['details']['is_new'] = FALSE;
}
// Check if this form is sending an email.
if (!$is_draft && !$form_state['values']['details']['finished']) {
$submission = webform_get_submission($node->webform['nid'], $sid, TRUE);
webform_submission_send_mail($node, $submission);
}
// Strip out empty tags added by WYSIWYG editors if needed.
$confirmation = strlen(trim(strip_tags($node->webform['confirmation']))) ? $node->webform['confirmation'] : '';
// Clean up the redirect URL and filter it for webform tokens.
$redirect_url = trim($node->webform['redirect_url']);
$redirect_url = _webform_filter_values($redirect_url, $node, $submission, NULL, FALSE, TRUE);
// Remove the domain name from the redirect.
$redirect_url = preg_replace('/^' . preg_quote($GLOBALS['base_url'], '/') . '\//', '', $redirect_url);
// Check confirmation and redirect_url fields.
$message = NULL;
$redirect = NULL;
$external_url = FALSE;
if (isset($form['actions']['draft']['#value']) && $form_state['values']['op'] == $form['actions']['draft']['#value']) {
$message = t('Submission saved. You may return to this form later and it will restore the current values.');
}
elseif ($is_draft) {
$redirect = NULL;
}
elseif (!empty($form_state['values']['details']['finished'])) {
$message = t('Submission updated.');
}
elseif ($redirect_url == '<none>') {
$redirect = NULL;
}
elseif ($redirect_url == '<confirmation>') {
$redirect = array('node/' . $node->nid . '/done', array('query' => array('sid' => $sid)));
}
elseif (valid_url($redirect_url, TRUE)) {
$redirect = $redirect_url;
$external_url = TRUE;
}
elseif ($redirect_url && strpos($redirect_url, 'http') !== 0) {
$parts = drupal_parse_url($redirect_url);
$parts['query'] ? ($parts['query']['sid'] = $sid) : ($parts['query'] = array('sid' => $sid));
$query = $parts['query'];
$redirect = array($parts['path'], array('query' => $query, 'fragment' => $parts['fragment']));
}
// Show a message if manually set.
if (isset($message)) {
drupal_set_message($message);
}
// If redirecting and we have a confirmation message, show it as a message.
elseif (!$is_draft && !$external_url && (!empty($redirect_url) && $redirect_url != '<confirmation>') && !empty($confirmation)) {
drupal_set_message(check_markup($confirmation, $node->webform['confirmation_format'], '', TRUE));
}
$form_state['redirect'] = $redirect;
}
/**
* Post processes the submission tree with any updates from components.
*
* @param $node
* The full webform node.
* @param $form_values
* The form values for the form.
* @param $types
* Optional. Specific types to perform processing.
* @param $parent
* Internal use. The current parent CID whose children are being processed.
*/
function _webform_client_form_submit_process($node, &$form_values, $types = NULL, $parent = 0) {
if (is_array($form_values)) {
foreach ($form_values as $form_key => $value) {
$cid = webform_get_cid($node, $form_key, $parent);
if (is_array($value) && isset($node->webform['components'][$cid]['type']) && webform_component_feature($node->webform['components'][$cid]['type'], 'group')) {
_webform_client_form_submit_process($node, $form_values[$form_key], $types, $cid);
}
if (isset($node->webform['components'][$cid])) {
// Call the component process submission function.
$component = $node->webform['components'][$cid];
if ((!isset($types) || in_array($component['type'], $types)) && webform_component_implements($component['type'], 'submit')) {
$form_values[$component['form_key']] = webform_component_invoke($component['type'], 'submit', $component, $form_values[$component['form_key']]);
}
}
}
}
}
/**
* Flattens a submitted form back into a single array representation (rather than nested fields)
*/
function _webform_client_form_submit_flatten($node, $fieldset, $parent = 0) {
$values = array();
if (is_array($fieldset)) {
foreach ($fieldset as $form_key => $value) {
$cid = webform_get_cid($node, $form_key, $parent);
if (is_array($value) && webform_component_feature($node->webform['components'][$cid]['type'], 'group')) {
$values += _webform_client_form_submit_flatten($node, $value, $cid);
}
else {
$values[$cid] = $value;
}
}
}
return $values;
}
/**
* Prints the confirmation message after a successful submission.
*/
function _webform_confirmation($node) {
drupal_set_title($node->title);
webform_set_breadcrumb($node);
$sid = isset($_GET['sid']) ? $_GET['sid'] : NULL;
return theme(array('webform_confirmation_' . $node->nid, 'webform_confirmation'), array('node' => $node, 'sid' => $sid));
}
/**
* Prepare for theming of the webform form.
*/
function template_preprocess_webform_form(&$vars) {
if (isset($vars['form']['details']['nid']['#value'])) {
$vars['nid'] = $vars['form']['details']['nid']['#value'];
}
elseif (isset($vars['form']['submission']['#value'])) {
$vars['nid'] = $vars['form']['submission']['#value']->nid;
}
}
/**
* Prepare for theming of the webform submission confirmation.
*/
function template_preprocess_webform_confirmation(&$vars) {
$confirmation = check_markup($vars['node']->webform['confirmation'], $vars['node']->webform['confirmation_format'], '', TRUE);
// Strip out empty tags added by WYSIWYG editors if needed.
$vars['confirmation_message'] = strlen(trim(strip_tags($confirmation))) ? $confirmation : '';
}
/**
* Prepare to theme the contents of e-mails sent by webform.
*/
function template_preprocess_webform_mail_message(&$vars) {
global $user;
$vars['user'] = $user;
$vars['ip_address'] = ip_address();
}
/**
* A Form API #pre_render function. Sets display based on #title_display.
*
* This function is used regularly in D6 for all elements, but specifically for
* fieldsets in D7, which don't support #title_display natively.
*/
function webform_element_title_display($element) {
if (isset($element['#title_display']) && strcmp($element['#title_display'], 'none') === 0) {
$element['#title'] = NULL;
}
return $element;
}
/**
* Replacement for theme_form_element().
*/
function theme_webform_element($variables) {
// Ensure defaults.
$variables['element'] += array(
'#title_display' => 'before',
);
$element = $variables['element'];
// All elements using this for display only are given the "display" type.
if (isset($element['#format']) && $element['#format'] == 'html') {
$type = 'display';
}
else {
$type = (isset($element['#type']) && !in_array($element['#type'], array('markup', 'textfield', 'webform_email', 'webform_number'))) ? $element['#type'] : $element['#webform_component']['type'];
}
// Convert the parents array into a string, excluding the "submitted" wrapper.
$nested_level = $element['#parents'][0] == 'submitted' ? 1 : 0;
$parents = str_replace('_', '-', implode('--', array_slice($element['#parents'], $nested_level)));
$wrapper_classes = array(
'form-item',
'webform-component',
'webform-component-' . $type,
);
if (isset($element['#title_display']) && strcmp($element['#title_display'], 'inline') === 0) {
$wrapper_classes[] = 'webform-container-inline';
}
$output = '<div class="' . implode(' ', $wrapper_classes) . '" id="webform-component-' . $parents . '">' . "\n";
// If #title is not set, we don't display any label or required marker.
if (!isset($element['#title'])) {
$element['#title_display'] = 'none';
}
$prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . _webform_filter_xss($element['#field_prefix']) . '</span> ' : '';
$suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . _webform_filter_xss($element['#field_suffix']) . '</span>' : '';
switch ($element['#title_display']) {
case 'inline':
case 'before':
case 'invisible':
$output .= ' ' . theme('form_element_label', $variables);
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
case 'after':
$output .= ' ' . $prefix . $element['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
break;
case 'none':
case 'attribute':
// Output no label and no required marker, only the children.
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
}
if (!empty($element['#description'])) {
$output .= ' <div class="description">' . $element['#description'] . "</div>\n";
}
$output .= "</div>\n";
return $output;
}
/**
* Output a form element in plain text format.
*/
function theme_webform_element_text($variables) {
$element = $variables['element'];
$value = $variables['element']['#children'];
$output = '';
$is_group = webform_component_feature($element['#webform_component']['type'], 'group');
// Output the element title.
if (isset($element['#title'])) {
if ($is_group) {
$output .= '--' . $element['#title'] . '--';
}
elseif (!in_array(drupal_substr($element['#title'], -1), array('?', ':', '!', '%', ';', '@'))) {
$output .= $element['#title'] . ':';
}
else {
$output .= $element['#title'];
}
}
// Wrap long values at 65 characters, allowing for a few fieldset indents.
// It's common courtesy to wrap at 75 characters in e-mails.
if ($is_group && drupal_strlen($value) > 65) {
$value = wordwrap($value, 65, "\n");
$lines = explode("\n", $value);
foreach ($lines as $key => $line) {
$lines[$key] = ' ' . $line;
}
$value = implode("\n", $lines);
}
// Add the value to the output. Add a newline before the response if needed.
$output .= (strpos($value, "\n") === FALSE ? ' ' : "\n") . $value;
// Indent fieldsets.
if ($is_group) {
$lines = explode("\n", $output);
foreach ($lines as $number => $line) {
if (strlen($line)) {
$lines[$number] = ' ' . $line;
}
}
$output = implode("\n", $lines);
$output .= "\n";
}
if ($output) {
$output .= "\n";
}
return $output;
}
/**
* Theme a radio button and another element together.
*
* This is used in the e-mail configuration to show a radio button and a text
* field or select list on the same line.
*/
function theme_webform_inline_radio($variables) {
$element = $variables['element'];
// Add element's #type and #name as class to aid with JS/CSS selectors.
$class = array('form-item');
if (!empty($element['#type'])) {
$class[] = 'form-type-' . strtr($element['#type'], '_', '-');
}
if (!empty($element['#name'])) {
$class[] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
}
// Add container-inline to all elements.
$class[] = 'webform-container-inline';
if (isset($element['#inline_element']) && isset($variables['element']['#title'])) {
$variables['element']['#title'] .= ': ';
}
$output = '<div class="' . implode(' ', $class) . '">' . "\n";
$output .= ' ' . $element['#children'];
if (!empty($element['#title'])) {
$output .= ' ' . theme('form_element_label', $variables) . "\n";
}
if (isset($element['#inline_element'])) {
$output .= ' ' . $element['#inline_element'] . "\n";
}
if (!empty($element['#description'])) {
$output .= ' <div class="description">' . $element['#description'] . "</div>\n";
}
$output .= "</div>\n";
return $output;
}
/**
* Theme the headers when sending an email from webform.
*
* @param $node
* The complete node object for the webform.
* @param $submission
* The webform submission of the user.
* @param $email
* If you desire to make different e-mail headers depending on the recipient,
* you can check the $email['email'] property to output different content.
* This will be the ID of the component that is a conditional e-mail
* recipient. For the normal e-mails, it will have the value of 'default'.
* @return
* An array of headers to be used when sending a webform email. If headers
* for "From", "To", or "Subject" are set, they will take precedence over
* the values set in the webform configuration.
*/
function theme_webform_mail_headers($variables) {
$headers = array(
'X-Mailer' => 'Drupal Webform (PHP/' . phpversion() . ')',
);
return $headers;
}
/**
* Check if current user has a draft of this webform, and return the sid.
*/
function _webform_fetch_draft_sid($nid, $uid) {
return db_select('webform_submissions')
->fields('webform_submissions', array('sid'))
->condition('nid', $nid)
->condition('uid', $uid)
->condition('is_draft', 1)
->orderBy('submitted', 'DESC')
->execute()
->fetchField();
}
/**
* Filters all special tokens provided by webform, such as %post and %profile.
*
* @param $string
* The string to have its tokens replaced.
* @param $node
* If replacing node-level tokens, the node for which tokens will be created.
* @param $submission
* If replacing submission-level tokens, the submission for which tokens will
* be created.
* @param $email
* If replacing tokens within the context of an e-mail, the Webform e-mail
* settings array.
* @param $strict
* Boolean value indicating if the results should be run through check_plain.
* This is used any time the values will be output as HTML, but not in
* default values or e-mails.
* @param $allow_anonymous
* Boolean value indicating if all tokens should be replaced for anonymous
* users, even if they contain sensitive user information such as %session or
* %ip_address. This is disabled by default to prevent user data from being
* preserved in the anonymous page cache and should only be used in
* non-cached situations, such as e-mails.
*/
function _webform_filter_values($string, $node = NULL, $submission = NULL, $email = NULL, $strict = TRUE, $allow_anonymous = FALSE) {
global $user;
$replacements = &drupal_static(__FUNCTION__);
// Don't do any filtering if the string is empty.
if (strlen(trim($string)) == 0) {
return $string;
}
// Setup default token replacements.
if (!isset($replacements)) {
$replacements['unsafe'] = array();
$replacements['safe']['%site'] = variable_get('site_name', 'drupal');
$replacements['safe']['%date'] = format_date(REQUEST_TIME, 'long');
}
// Node replacements.
if (isset($node) && !array_key_exists('%nid', $replacements['safe'])) {
$replacements['safe']['%nid'] = $node->nid;
$replacements['safe']['%title'] = $node->title;
}
// Determine the display format.
$format = isset($email['html']) && $email['html'] ? 'html' : 'text';
// Submission replacements.
if (isset($submission) && (!isset($replacements['email'][$format]) || (isset($replacements['unsafe']['%sid']) && $replacements['unsafe']['%sid'] != $submission->sid))) {
module_load_include('inc', 'webform', 'includes/webform.components');
// Set the submission ID.
$replacements['unsafe']['%sid'] = $submission->sid;
// E-mails may be sent in two formats, keep tokens separate for each one.
$replacements['email'][$format] = array();
// Populate token values for each component.
foreach ($submission->data as $cid => $value) {
$component = $node->webform['components'][$cid];
// Find by form key.
$parents = webform_component_parent_keys($node, $component);
$form_key = implode('][', $parents);
$display_element = webform_component_invoke($component['type'], 'display', $component, $value['value'], $format);
// Ensure the component is added as a property.
$display_element['#webform_component'] = $component;
if (empty($display_element['#parents'])) {
$display_element['#parents'] = array_merge(array('submitted'), $parents);
}
if (empty($display_element['#id'])) {
$display_element['#id'] = drupal_html_id('edit-' . implode('-', $display_element['#parents']));
}
$replacements['email'][$format]['%email[' . $form_key . ']'] = render($display_element);
$display_element['#theme_wrappers'] = array(); // Remove label and wrappers.
$replacements['email'][$format]['%value[' . $form_key . ']'] = render($display_element);
}
// Provide blanks for components in the webform but not in the submission.
$missing_components = array_diff_key($node->webform['components'], $submission->data);
foreach ($missing_components as $component) {
$parents = webform_component_parent_keys($node, $component);
$form_key = implode('][', $parents);
$replacements['email'][$format]['%email[' . $form_key . ']'] = '';
$replacements['email'][$format]['%value[' . $form_key . ']'] = '';
}
// Submission edit URL.
$replacements['unsafe']['%submission_url'] = url('node/' . $node->nid . '/submission/' . $submission->sid, array('absolute' => TRUE));
}
// Token for the entire form tree for e-mails.
if (isset($submission) && isset($email)) {
$replacements['email'][$format]['%email_values'] = webform_submission_render($node, $submission, $email, $format);
}
// Provide a list of candidates for token replacement.
$special_tokens = array(
'safe' => array(
'%get' => $_GET,
'%post' => $_POST,
),
'unsafe' => array(
'%cookie' => isset($_COOKIE) ? $_COOKIE : array(),
'%session' => isset($_SESSION) ? $_SESSION : array(),
'%request' => $_REQUEST,
'%server' => $_SERVER,
'%profile' => (array) $user,
),
);
// Replacements of global variable tokens.
if (!isset($replacements['specials_set'])) {
$replacements['specials_set'] = TRUE;
// Load profile information if available.
if ($user->uid) {
$account = user_load($user->uid);
$special_tokens['unsafe']['%profile'] = (array) $account;
}
// User replacements.
if (!array_key_exists('%uid', $replacements['unsafe'])) {
$replacements['unsafe']['%uid'] = !empty($user->uid) ? $user->uid : '';
$replacements['unsafe']['%username'] = isset($user->name) ? $user->name : '';
$replacements['unsafe']['%useremail'] = isset($user->mail) ? $user->mail : '';
$replacements['unsafe']['%ip_address'] = ip_address();
}
// Populate the replacements array with special variables.
foreach ($special_tokens as $safe_state => $tokens) {
foreach ($tokens as $token => $variable) {
// Safety check in case $_POST or some other global has been removed
// by a naughty module, in which case $variable may be NULL.
if (!is_array($variable)) {
continue;
}
foreach ($variable as $key => $value) {
// This special case for profile module dates.
if ($token == '%profile' && is_array($value) && isset($value['year'])) {
$replacement = webform_strtodate(webform_date_format(), $value['month'] . '/' . $value['day'] . '/' . $value['year'], 'UTC');
}
else {
// Checking for complex types (arrays and objects) fails here with
// incomplete objects (see http://php.net/is_object), so we check
// for simple types instead.
$replacement = (is_string($value) || is_bool($value) || is_numeric($value)) ? $value : '';
}
$replacements[$safe_state][$token . '[' . $key . ']'] = $replacement;
}
}
}
}
// Make a copy of the replacements so we don't affect the static version.
$safe_replacements = $replacements['safe'];
// Restrict replacements for anonymous users. Not all tokens can be used
// because they may expose session or other private data to other users when
// anonymous page caching is enabled.
if ($user->uid || $allow_anonymous) {
$safe_replacements += $replacements['unsafe'];
if (isset($replacements['email'][$format])) {
$safe_replacements += $replacements['email'][$format];
}
}
else {
foreach ($replacements['unsafe'] as $key => $value) {
$safe_replacements[$key] = '';
}
}
$find = array_keys($safe_replacements);
$replace = array_values($safe_replacements);
$string = str_replace($find, $replace, $string);
// Clean up any unused tokens.
foreach ($special_tokens as $safe_state => $tokens) {
foreach (array_keys($tokens) as $token) {
$string = preg_replace('/\\' . $token . '\[\w+\]/', '', $string);
}
}
return $strict ? _webform_filter_xss($string) : $string;
}
/**
* Filters all special tokens provided by webform, and allows basic layout in descriptions.
*/
function _webform_filter_descriptions($string, $node = NULL, $submission = NULL) {
return strlen($string) == 0 ? '' : _webform_filter_xss(_webform_filter_values($string, $node, $submission, NULL, FALSE));
}
/**
* Filter labels for display by running through XSS checks.
*/
function _webform_filter_xss($string) {
static $allowed_tags;
$allowed_tags = isset($allowed_tags) ? $allowed_tags : webform_variable_get('webform_allowed_tags');
return filter_xss($string, $allowed_tags);
}
/**
* Utility function to ensure that a webform record exists in the database.
*
* @param $node
* The node object to check if a database entry exists.
* @return
* This function should always return TRUE if no errors were encountered,
* ensuring that a webform table row has been created. Will return FALSE if
* a record does not exist and a new one could not be created.
*/
function webform_ensure_record(&$node) {
if (!$node->webform['record_exists']) {
// Even though webform_node_insert() would set this property to TRUE,
// we set record_exists to trigger a difference from the defaults.
$node->webform['record_exists'] = TRUE;
webform_node_insert($node);
}
return $node->webform['record_exists'];
}
/**
* Utility function to check if a webform record is necessary in the database.
*
* If the node is no longer using any webform settings, this function will
* delete the settings from the webform table. Note that this function will NOT
* delete rows from the webform table if the node-type is exclusively used for
* webforms (per the "webform_node_types_primary" variable).
*
* @param $node
* The node object to check if a database entry is still required.
* @return
* Returns TRUE if the webform still has a record in the database. Returns
* FALSE if the webform does not have a record or if the previously existing
* record was just deleted.
*/
function webform_check_record(&$node) {
$webform = $node->webform;
$webform['record_exists'] = FALSE;
unset($webform['nid']);
// Don't include empty values in the comparison, this makes it so modules that
// extend Webform with empty defaults won't affect cleanup of rows.
$webform = array_filter($webform);
$defaults = array_filter(webform_node_defaults());
if ($webform == $defaults && !in_array($node->type, webform_variable_get('webform_node_types_primary'))) {
webform_node_delete($node);
$node->webform = webform_node_defaults();
}
return $node->webform['record_exists'];
}
/**
* Given a form_key and a list of form_key parents, determine the cid.
*
* @param $node
* A fully loaded node object.
* @param $form_key
* The form key for which we're finding a cid.
* @param $parent
* The cid of the parent component.
*/
function webform_get_cid(&$node, $form_key, $pid) {
foreach ($node->webform['components'] as $cid => $component) {
if ($component['form_key'] == $form_key && $component['pid'] == $pid) {
return $cid;
}
}
}
/**
* Retreive a Drupal variable with the appropriate default value.
*/
function webform_variable_get($variable) {
switch ($variable) {
case 'webform_allowed_tags':
$result = variable_get('webform_allowed_tags', array('a', 'em', 'strong', 'code', 'img'));
break;
case 'webform_default_from_name':
$result = variable_get('webform_default_from_name', variable_get('site_name', ''));
break;
case 'webform_default_from_address':
$result = variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from')));
break;
case 'webform_default_subject':
$result = variable_get('webform_default_subject', t('Form submission from: %title'));
break;
case 'webform_node_types':
$result = variable_get('webform_node_types', array('webform'));
break;
case 'webform_node_types_primary':
$result = variable_get('webform_node_types_primary', array('webform'));
break;
}
return $result;
}
function theme_webform_token_help($variables) {
$groups = $variables['groups'];
$groups = empty($groups) ? array('basic', 'node', 'special') : $groups;
static $tokens = array();
if (empty($tokens)) {
$tokens['basic'] = array(
'title' => t('Basic tokens'),
'tokens' => array(
'%username' => t('The name of the user if logged in. Blank for anonymous users.'),
'%useremail' => t('The e-mail address of the user if logged in. Blank for anonymous users.'),
'%ip_address' => t('The IP address of the user.'),
'%site' => t('The name of the site (i.e. %site_name)', array('%site_name' => variable_get('site_name', ''))),
'%date' => t('The current date, formatted according to the site settings.'),
),
);
$tokens['node'] = array(
'title' => t('Node tokens'),
'tokens' => array(
'%nid' => t('The node ID.'),
'%title' => t('The node title.'),
),
);
$tokens['special'] = array(
'title' => t('Special tokens'),
'tokens' => array(
'%profile[' . t('key') . ']' => t('Any user profile field or value, such as %profile[name] or %profile[profile_first_name]'),
'%get[' . t('key') . ']' => t('Tokens may be populated from the URL by creating URLs of the form http://example.com/my-form?foo=bar. Using the token %get[foo] would print "bar".'),
'%post[' . t('key') . ']' => t('Tokens may also be populated from POST values that are submitted by forms.'),
),
'description' => t('In addition to %get and %post, the following super tokens may be used, though only with logged-in users: %server, %cookie, and %request. For example %server[HTTP_USER_AGENT] or %session[id].'),
);
$tokens['email'] = array(
'title' => t('E-mail tokens'),
'tokens' => array(
'%email_values' => t('All included components in a hierarchical structure.'),
'%email[' . t('key') . '] ' => t('A formatted value and field label. Elements may be accessed such as <em>%email[fieldset_a][key_b]</em>. Do not include quotes.'),
'%submission_url' => t('The URL for viewing the completed submission.'),
),
);
$tokens['submission'] = array(
'title' => t('Submission tokens'),
'tokens' => array(
'%sid' => t('The unique submission ID.'),
'%value[key]' => t('A value without additional formatting. Elements may be accessed such as <em>%value[fieldset_a][key_b]</em>. Do not include quotes.'),
),
);
}
$output = '';
$output .= '<p>' . t('You may use special tokens in this field that will be replaced with dynamic values.') . '</p>';
foreach ($tokens as $group_name => $group) {
if (!is_array($groups) || in_array($group_name, $groups)) {
$items = array();
foreach ($group['tokens'] as $token => $token_description) {
$items[] = $token . ' - ' . $token_description;
}
$output .= theme('item_list', array('items' => $items, 'title' => $group['title']));
$output .= isset($group['description']) ? '<p>' . $group['description'] . '</p>' : '';
}
}
$fieldset = array(
'#title' => t('Token values'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#children' => '<div>' . $output . '</div>',
'#attributes' => array('class' => array('collapsible', 'collapsed')),
);
return theme('fieldset', array('element' => $fieldset));
}
function _webform_safe_name($name) {
$new = trim($name);
// If transliteration is available, use it to convert names to ASCII.
if (function_exists('transliteration_get')) {
$new = transliteration_get($new, '');
$new = str_replace(array(' ', '-', '/'), array('_', '_', '_'), $new);
}
else {
$new = str_replace(
array(' ', '-', '/', '€', 'ƒ', 'Š', 'Ž', 'š', 'ž', 'Ÿ', '¢', '¥', 'µ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Œ', 'œ', 'Æ', 'Ð', 'Þ', 'ß', 'æ', 'ð', 'þ'),
array('_', '_', '_', 'E', 'f', 'S', 'Z', 's', 'z', 'Y', 'c', 'Y', 'u', 'A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'),
$new);
}
$new = drupal_strtolower($new);
$new = preg_replace('/[^a-z0-9_]/', '', $new);
return $new;
}
/**
* Given an email address and a name, format an e-mail address.
*
* @param $address
* The e-mail address.
* @param $name
* The name to be used in the formatted address.
* @param $node
* The webform node if replacements will be done.
* @param $submission
* The webform submission values if replacements will be done.
* @param $encode
* Encode the text for use in an e-mail.
* @param $single
* Force a single value to be returned, even if a component expands to
* multiple addresses. This is useful to ensure a single e-mail will be
* returned for the "From" address.
* @param $format
* The e-mail format, defaults to the site-wide setting. May be either "short"
* or "long".
*/
function webform_format_email_address($address, $name, $node = NULL, $submission = NULL, $encode = TRUE, $single = TRUE, $format = NULL) {
if (!isset($format)) {
$format = variable_get('webform_email_address_format', 'long');
}
if ($name == 'default') {
$name = webform_variable_get('webform_default_from_name');
}
elseif (is_numeric($name) && isset($node->webform['components'][$name])) {
if (isset($submission->data[$name]['value'])) {
$name = $submission->data[$name]['value'];
}
else {
$name = t('Value of !component', array('!component' => $node->webform['components'][$name]['name']));
}
}
if ($address == 'default') {
$address = webform_variable_get('webform_default_from_address');
}
elseif (is_numeric($address) && isset($node->webform['components'][$address])) {
if (isset($submission->data[$address]['value'])) {
$values = $submission->data[$address]['value'];;
$address = array();
foreach ($values as $value) {
$address = array_merge($address, explode(',', $value));
}
}
else {
$address = t('Value of "!component"', array('!component' => $node->webform['components'][$address]['name']));
}
}
// Convert arrays into a single value for From values.
if ($single) {
$address = is_array($address) ? reset($address) : $address;
$name = is_array($name) ? reset($name) : $name;
}
// Address may be an array if a component value was used on checkboxes.
if (is_array($address)) {
foreach ($address as $key => $individual_address) {
$address[$key] = _webform_filter_values($individual_address, $node, $submission, NULL, FALSE, TRUE);
}
}
else {
$address = _webform_filter_values($address, $node, $submission, NULL, FALSE, TRUE);
}
if ($format == 'long' && !empty($name)) {
$name = _webform_filter_values($name, $node, $submission, NULL, FALSE, TRUE);
if ($encode) {
$name = mime_header_encode($name);
}
return '"' . $name . '" <' . $address . '>';
}
else {
return $address;
}
}
/**
* Given an email subject, format it with any needed replacements.
*/
function webform_format_email_subject($subject, $node = NULL, $submission = NULL) {
if ($subject == 'default') {
$subject = webform_variable_get('webform_default_subject');
}
elseif (is_numeric($subject) && isset($node->webform['components'][$subject])) {
$component = $node->webform['components'][$subject];
if (isset($submission->data[$subject]['value'])) {
$display_function = '_webform_display_' . $component['type'];
$value = $submission->data[$subject]['value'];
// Convert the value to a clean text representation if possible.
if (function_exists($display_function)) {
$display = $display_function($component, $value, 'text');
$display['#theme_wrappers'] = array();
$display['#webform_component'] = $component;
$subject = str_replace("\n", ' ', drupal_render($display));
}
else {
$subject = $value;
}
}
else {
$subject = t('Value of "!component"', array('!component' => $component['name']));
}
}
// Convert arrays to strings (may happen if checkboxes are used as the value).
if (is_array($subject)) {
$subject = reset($subject);
}
return _webform_filter_values($subject, $node, $submission, NULL, FALSE, TRUE);
}
/**
* Convert an array of components into a tree
*/
function _webform_components_tree_build($src, &$tree, $parent, &$page_count) {
foreach ($src as $cid => $component) {
if ($component['pid'] == $parent) {
_webform_components_tree_build($src, $component, $cid, $page_count);
if ($component['type'] == 'pagebreak') {
$page_count++;
}
$tree['children'][$cid] = $component;
$tree['children'][$cid]['page_num'] = $page_count;
}
}
return $tree;
}
/**
* Flatten a component tree into a flat list.
*/
function _webform_components_tree_flatten($tree) {
$components = array();
foreach ($tree as $cid => $component) {
if (isset($component['children'])) {
unset($component['children']);
$components[$cid] = $component;
// array_merge() can't be used here because the keys are numeric.
$children = _webform_components_tree_flatten($tree[$cid]['children']);
foreach ($children as $ccid => $ccomponent) {
$components[$ccid] = $ccomponent;
}
}
else {
$components[$cid] = $component;
}
}
return $components;
}
/**
* Helper for the uasort in webform_tree_sort()
*/
function _webform_components_sort($a, $b) {
if ($a['weight'] == $b['weight']) {
return strcasecmp($a['name'], $b['name']);
}
return ($a['weight'] < $b['weight']) ? -1 : 1;
}
/**
* Sort each level of a component tree by weight and name
*/
function _webform_components_tree_sort($tree) {
if (isset($tree['children']) && is_array($tree['children'])) {
$children = array();
uasort($tree['children'], '_webform_components_sort');
foreach ($tree['children'] as $cid => $component) {
$children[$cid] = _webform_components_tree_sort($component);
}
$tree['children'] = $children;
}
return $tree;
}
/**
* Get a list of all available component definitions.
*/
function webform_components($include_disabled = FALSE, $reset = FALSE) {
static $components, $disabled;
if (!isset($components) || $reset) {
$components = array();
$disabled = array_flip(variable_get('webform_disabled_components', array()));
foreach (module_implements('webform_component_info') as $module) {
$module_components = module_invoke($module, 'webform_component_info');
foreach ($module_components as $type => $info) {
$module_components[$type]['module'] = $module;
$module_components[$type]['enabled'] = !array_key_exists($type, $disabled);
}
$components += $module_components;
}
drupal_alter('webform_component_info', $components);
ksort($components);
}
return $include_disabled ? $components : array_diff_key($components, $disabled);
}
/**
* Build a list of components suitable for use as select list options.
*/
function webform_component_options($include_disabled = FALSE) {
$component_info = webform_components($include_disabled);
$options = array();
foreach ($component_info as $type => $info) {
$options[$type] = $info['label'];
}
return $options;
}
/**
* Load a component file into memory.
*
* @param $component_type
* The string machine name of a component.
*/
function webform_component_include($component_type) {
static $included = array();
// No need to load components that have already been added once.
if (!isset($included[$component_type])) {
$components = webform_components(TRUE);
$included[$component_type] = TRUE;
if (($info = $components[$component_type]) && isset($info['file'])) {
$pathinfo = pathinfo($info['file']);
$basename = basename($pathinfo['basename'], '.' . $pathinfo['extension']);
$path = (!empty($pathinfo['dirname']) ? $pathinfo['dirname'] . '/' : '') . $basename;
module_load_include($pathinfo['extension'], $info['module'], $path);
}
}
}
/**
* Invoke a component callback.
*
* @param $type
* The component type as a string.
* @param $callback
* The callback to execute.
* @param ...
* Any additional parameters required by the $callback.
*/
function webform_component_invoke($type, $callback) {
$args = func_get_args();
$type = array_shift($args);
$callback = array_shift($args);
$function = '_webform_' . $callback . '_' . $type;
webform_component_include($type);
if (function_exists($function)) {
return call_user_func_array($function, $args);
}
}
/**
* Check if a component implements a particular hook.
*
* @param $type
* The component type as a string.
* @param $callback
* The callback to check.
*/
function webform_component_implements($type, $callback) {
$function = '_webform_' . $callback . '_' . $type;
webform_component_include($type);
return function_exists($function);
}
/**
* Disable the Drupal page cache.
*/
function webform_disable_page_cache() {
drupal_page_is_cacheable(FALSE);
}
/**
* Set the necessary breadcrumb for the page we are on.
*/
function webform_set_breadcrumb($node, $submission = NULL) {
$breadcrumb = drupal_get_breadcrumb();
if (isset($node)) {
$webform_breadcrumb = array();
$webform_breadcrumb[] = empty($breadcrumb) ? l(t('Home'), '<front>') : array_shift($breadcrumb);
$webform_breadcrumb[] = l($node->title, 'node/' . $node->nid);
if (isset($submission)) {
$last_link = array_shift($breadcrumb);
if (webform_results_access($node)) {
$webform_breadcrumb[] = l(t('Webform results'), 'node/' . $node->nid . '/webform-results');
}
elseif (user_access('access own webform results')) {
$webform_breadcrumb[] = l(t('Submissions'), 'node/' . $node->nid . '/submissions');
}
if (isset($last_link)) {
$webform_breadcrumb[] = $last_link;
}
}
$breadcrumb = $webform_breadcrumb;
}
drupal_set_breadcrumb($breadcrumb);
}
/**
* Convert an ISO 8601 date or time into an array.
*
* This converts full format dates or times. Either a date or time may be
* provided, in which case only those portions will be returned. Dashes and
* colons must be used, never implied.
*
* Formats:
* Dates: YYYY-MM-DD
* Times: HH:MM:SS
* Datetimes: YYYY-MM-DDTHH:MM:SS
*
* @param $string
* An ISO 8601 date, time, or datetime.
* @param $type
* If wanting only specific fields back, specify either "date" or "time".
* Leaving empty will return an array with both date and time keys, even if
* some are empty. Returns an array with the following keys:
* - year
* - month
* - day
* - hour (in 24hr notation)
* - minute
* - second
*/
function webform_date_array($string, $type = NULL) {
$pattern = '/((\d{4}?)-(\d{2}?)-(\d{2}?))?(T?(\d{2}?):(\d{2}?):(\d{2}?))?/';
$matches = array();
preg_match($pattern, $string, $matches);
$matches += array_fill(0, 9, '');
$return = array();
// Check for a date string.
if ($type == 'date' || !isset($type)) {
$return['year'] = $matches[2] !== '' ? (int) $matches[2] : '';
$return['month'] = $matches[3] !== '' ? (int) $matches[3] : '';
$return['day'] = $matches[4] !== '' ? (int) $matches[4] : '';
}
// Check for a time string.
if ($type == 'time' || !isset($type)) {
$return['hour'] = $matches[6] !== '' ? (int) $matches[6] : '';
$return['minute'] = $matches[7] !== '' ? (int) $matches[7] : '';
$return['second'] = $matches[8] !== '' ? (int) $matches[8] : '';
}
return $return;
}
/**
* Convert an array of a date or time into an ISO 8601 compatible string.
*
* @param $array
* The array to convert to a date or time string.
* @param $type
* If wanting a specific string format back specify either "date" or "time".
* Otherwise a full ISO 8601 date and time string will be returned.
*/
function webform_date_string($array, $type = NULL) {
$string = '';
if ($type == 'date' || !isset($type)) {
$string .= empty($array['year']) ? '0000' : sprintf('%04d', $array['year']);
$string .= '-';
$string .= empty($array['month']) ? '00' : sprintf('%02d', $array['month']);
$string .= '-';
$string .= empty($array['day']) ? '00' : sprintf('%02d', $array['day']);
}
if (!isset($type)) {
$string .= 'T';
}
if ($type == 'time' || !isset($type)) {
$string .= empty($array['hour']) ? '00' : sprintf('%02d', $array['hour']);
$string .= ':';
$string .= empty($array['minute']) ? '00' : sprintf('%02d', $array['minute']);
$string .= ':';
$string .= empty($array['second']) ? '00' : sprintf('%02d', $array['second']);
}
return $string;
}
/**
* Get a date format according to the site settings.
*
* @param $size
* A choice of 'short', 'medium', or 'long' date formats.
*/
function webform_date_format($size = 'medium') {
// Format date according to site's given format.
$format = variable_get('date_format_' . $size, 'D, m/d/Y - H:i');
$time = 'aABgGhHisueIOPTZ';
$day_of_week = 'Dlw';
$special = ',-: ';
$date_format = trim($format, $time . $day_of_week . $special);
// Ensure that a day, month, and year value are present. Use a default
// format if all the values are not found.
if (!preg_match('/[dj]/', $date_format) || !preg_match('/[FmMn]/', $date_format) || !preg_match('/[oYy]/', $date_format)) {
$date_format = 'm/d/Y';
}
return $date_format;
}
/**
* Return a date in the desired format taking into consideration user timezones.
*/
function webform_strtodate($format, $string, $timezone_name = NULL) {
global $user;
// Adjust the time based on the user or site timezone.
if (variable_get('configurable_timezones', 1) && $timezone_name == 'user' && $user->uid) {
$timezone_name = isset($GLOBALS['user']->timezone) ? $GLOBALS['user']->timezone : 'UTC';
}
// If the timezone is still empty or not set, use the site timezone.
if (empty($timezone_name) || $timezone_name == 'user') {
$timezone_name = variable_get('date_default_timezone', 'UTC');
}
if (!empty($timezone_name) && class_exists('DateTimeZone')) {
// Suppress errors if encountered during string conversion. Exceptions are
// only supported for DateTime in PHP 5.3 and higher.
try {
@$timezone = new DateTimeZone($timezone_name);
@$datetime = new DateTime($string, $timezone);
return @$datetime->format($format);
}
catch (Exception $e) {
return '';
}
}
else {
return date($format, strtotime($string));
}
}
/**
* Get a timestamp in GMT time, ensuring timezone accuracy.
*/
function webform_strtotime($date) {
$current_tz = date_default_timezone_get();
date_default_timezone_set('UTC');
$timestamp = strtotime($date);
date_default_timezone_set($current_tz);
return $timestamp;
}
/**
* Wrapper function for i18n_string() if i18nstrings enabled.
*/
function webform_tt($name, $string, $langcode = NULL, $update = FALSE) {
if (function_exists('i18n_string')) {
$options = array(
'langcode' => $langcode,
'update' => $update,
);
return i18n_string($name, $string, $options);
}
else {
return $string;
}
}
/**
* Check if any available HTML mail handlers are available for Webform to use.
*/
function webform_email_html_capable() {
// TODO: Right now we only support MIME Mail and HTML Mail. Support others
// if available through a hook?
if (module_exists('mimemail')) {
$mail_systems = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
$enable = (!isset($mail_systems['webform']) || $mail_systems['webform'] == 'MimeMailSystem') ? 'MimeMailSystem' : FALSE;
}
elseif (module_exists('htmlmail')) {
$mail_systems = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
$enable = (!isset($mail_systems['webform']) || $mail_systems['webform'] == 'HTMLMailSystem') ? 'HTMLMailSystem' : FALSE;
}
if (!empty($enable)) {
// We assume that if a solution exists even if it's not specified we should
// use it. Webform will specify if e-mails sent with the system are plain-
// text or not when sending each e-mail.
$GLOBALS['conf']['mail_system']['webform'] = $enable;
return TRUE;
}
return FALSE;
}
/**
* Implements hook_views_api().
*/
function webform_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'webform') . '/views',
);
}
/**
* Implements hook_field_extra_fields().
*/
function webform_field_extra_fields() {
$extra = array();
foreach (webform_variable_get('webform_node_types') as $type) {
$extra['node'][$type]['display']['webform'] = array(
'label' => t('Webform'),
'description' => t('Webform client form.'),
'weight' => 10,
);
}
return $extra;
}
/**
* Implements hook_mollom_form_list().
*/
function webform_mollom_form_list() {
$forms = array();
$webform_types = webform_variable_get('webform_node_types');
if (empty($webform_types)) {
return $forms;
}
$query = db_select('webform', 'w');
$query->innerJoin('node', 'n', 'n.nid = w.nid');
$query->fields('n', array('nid', 'title'));
$query->condition('n.type', $webform_types, 'IN');
$result = $query->execute();
foreach ($result as $node) {
$form_id = 'webform_client_form_' . $node->nid;
$forms[$form_id] = array(
'title' => t('@name form', array('@name' => $node->title)),
'entity' => 'webform',
'delete form' => 'webform_submission_delete_form',
);
}
return $forms;
}
/**
* Implements hook_mollom_form_info().
*/
function webform_mollom_form_info($form_id) {
module_load_include('inc', 'webform', 'includes/webform.components');
$nid = drupal_substr($form_id, 20);
$node = node_load($nid);
$form_info = array(
'title' => t('@name form', array('@name' => $node->title)),
'mode' => MOLLOM_MODE_ANALYSIS,
'bypass access' => array('edit all webform submissions', 'edit any webform content'),
'entity' => 'webform',
'elements' => array(),
'mapping' => array(
'post_id' => 'details][sid',
'author_id' => 'details][uid',
),
);
// Add components as elements.
// These components can be enabled for textual analysis (when not using a
// CAPTCHA-only protection) in Mollom's form configuration.
foreach ($node->webform['components'] as $cid => $component) {
if (webform_component_feature($component['type'], 'spam_analysis')) {
$parents = implode('][', webform_component_parent_keys($node, $component));
$form_info['elements']['submitted][' . $parents] = check_plain(t($component['name']));
}
}
// Assign field mappings based on webform configuration.
// Since multiple emails can be configured, we iterate over all and take
// over the assigned component for the field mapping in any email, unless
// we already assigned one. We are not interested in administratively
// configured static strings, only user-submitted values.
foreach ($node->webform['emails'] as $email) {
// Subject (post_title).
if (!isset($form_info['mapping']['post_title'])) {
$cid = $email['subject'];
if (is_numeric($cid)) {
$parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
$form_info['mapping']['post_title'] = 'submitted][' . $parents;
}
}
// From name (author_name).
if (!isset($form_info['mapping']['author_name'])) {
$cid = $email['from_name'];
if (is_numeric($cid)) {
$parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
$form_info['mapping']['author_name'] = 'submitted][' . $parents;
}
}
// From address (author_mail).
if (!isset($form_info['mapping']['author_mail'])) {
$cid = $email['from_address'];
if (is_numeric($cid)) {
$parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
$form_info['mapping']['author_mail'] = 'submitted][' . $parents;
}
}
}
return $form_info;
}