-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebform.module
4104 lines (3716 loc) · 147 KB
/
webform.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This 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>
*/
/**
* Constants used in conditional logic.
*/
define('WEBFORM_CONDITIONAL_EXCLUDE', 0);
define('WEBFORM_CONDITIONAL_INCLUDE', 1);
define('WEBFORM_CONDITIONAL_SAME_PAGE', 2);
/**
* 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/%/webform/components':
$output .= '<p>' . t('This page displays all the components currently configured for this webform node. You may add any number of components to the form, even multiple of the same type. To add a new component, fill in a name and select a type from the fields at the bottom of the table. Submit the form to create the new component or update any changed form values.') . '</p>';
$output .= '<p>' . t('Click on any existing component\'s name to edit its settings.') . '</p>';
break;
case 'node/%/webform/conditionals':
$output .= '<p>' . t('Conditionals may be used to hide or show certain components (or entire pages!) based on the value of other components.') . '</p>';
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,
);
// Autocomplete used in Views integration.
$items['webform/autocomplete'] = array(
'title' => 'Webforms',
'page callback' => 'webform_views_autocomplete',
'access arguments' => 'administer views',
'file' => 'views/webform.views.inc',
'type' => MENU_CALLBACK,
);
// Node page tabs.
$items['node/%webform_menu/done'] = array(
'title' => 'Webform confirmation',
'page callback' => '_webform_confirmation',
'page arguments' => array(1),
'access callback' => 'webform_confirmation_page_access',
'access arguments' => array(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/conditionals'] = array(
'title' => 'Conditionals',
'page callback' => 'drupal_get_form',
'page arguments' => array('webform_conditionals_form', 1),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform.conditionals.inc',
'weight' => 1,
'type' => MENU_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' => 5,
'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' => 4,
'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_CALLBACK,
);
$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_CALLBACK,
);
// 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;
}
/**
* Access function for confirmation pages.
*
* @param $node
* The webform node object.
*
* @return
* Boolean whether the user has access to the confirmation page.
*/
function webform_confirmation_page_access($node) {
global $user;
// Make sure SID is a positive integer.
$sid = (!empty($_GET['sid']) && (int) $_GET['sid'] > 0) ? (int) $_GET['sid'] : NULL;
if ($sid) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
$submission = webform_get_submission($node->nid, $sid);
}
else {
$submission = NULL;
}
if ($submission) {
// Logged-in users.
if ($user->uid) {
// User's own submission.
if ($submission->uid === $user->uid && node_access('view', $node)) {
return TRUE;
}
// User has results access to this submission.
elseif (webform_submission_access($node, $submission)) {
return TRUE;
}
}
// Anonymous user for their own submission. Hash of submission data must
// match the hash in the query string.
elseif ((int) $user->uid === 0 && (int) $submission->uid === 0) {
$hash_query = !empty($_GET['token']) ? $_GET['token'] : NULL;
$hash = md5($submission->submitted . $submission->sid . drupal_get_private_key());
if ($hash_query === $hash) {
return TRUE;
}
}
}
return FALSE;
}
/**
* Access function for Webform submissions.
*
* @param $node
* The webform node object.
* @param $submission
* The webform submission object.
* @param $op
* The operation to perform. Must be one of view, edit, delete, list.
* @param $account
* Optional. A user object or NULL to use the currently logged-in user.
*
* @return
* Boolean whether the user has access to a webform submission.
*/
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('node')),
),
// 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.conditionals.inc.
'webform_conditional_groups' => array(
'render element' => 'element',
'file' => 'includes/webform.conditionals.inc',
),
'webform_conditional' => array(
'render element' => 'element',
'file' => 'includes/webform.conditionals.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,
);
$elements['webform_conditional'] = array(
'#input' => TRUE,
'#theme' => 'webform_conditional',
'#default_value' => NULL,
'#process' => array('webform_conditional_expand'),
);
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(
'views_range' => TRUE,
),
'file' => 'components/date.inc',
'conditional_type' => 'date',
),
'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',
'conditional_type' => 'numeric',
),
'pagebreak' => array(
'label' => t('Page break'),
'description' => t('Organize forms into multiple pages.'),
'features' => array(
'conditional' => FALSE,
'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,
),
'conditional_type' => 'select',
),
'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(
'views_range' => TRUE,
),
'file' => 'components/time.inc',
'conditional_type' => 'time',
),
);
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_webform_conditional_operator_info().
*/
function webform_webform_conditional_operator_info() {
module_load_include('inc', 'webform', 'includes/webform.conditionals');
return _webform_conditional_operator_info();
}