-
Notifications
You must be signed in to change notification settings - Fork 0
/
webform2html.module
166 lines (139 loc) · 4.62 KB
/
webform2html.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
<?php
/**
* This menu appears only if 'Generate HTML' option is enabled
*/
function webform2html_enabled_html_access() {
$param = func_get_args();
$node = array_shift($param);
$call = array_shift($param);
$row = db_select('webform2html', 'w2h')
->fields('w2h', array('enabled'))
->condition('nid', $node->nid, '=')
->condition('enabled', 1, '=')
->execute()
->fetchAssoc();
return ($row['enabled'] && call_user_func_array($call, $param));
} // function webform2html_enabled_html_access()
/**
* Implements hook_menu().
*/
function webform2html_menu() {
$items = array();
$items['node/%webform_menu/webform/webform2html'] = array(
'title' => 'HTML Show',
'page callback' => 'drupal_get_form',
'page arguments' => array('webform2html_edit_form', 1),
'access callback' => 'node_access',
'access arguments' => array('update', 1),
'file' => 'includes/webform2html.settings.inc',
'weight' => 4,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/html'] = array(
'title' => 'HTML Show',
'load arguments' => array(1),
'page callback' => 'webform2html_submission_htmlshow',
'page arguments' => array(1, 3),
'access callback' => true,
'access arguments' => array(1, 'webform_submission_access', 1, 3, 'view'),
'file' => 'includes/webform2html.show.inc',
'weight' => 6,
'type' => MENU_LOCAL_TASK,
);
return $items;
} // function webform2html_menu()
/**
* Implements hook_theme().
*/
function webform2html_theme() {
return array(
'webform2html_content' => array(
'variables' => array('node' => NULL, 'submission' => NULL, 'template' => NULL),
'file' => 'includes/webform2html.theme.inc',
),
);
} // function webform2html_theme()
/**
* Implements hook_help().
*/
function webform2html_help($path, $arg) {
global $base_url;
switch ($path) {
case 'node/%/submission/%/html':
return $output = '<p>' . t('A HTML document will be generated from the marked results.') . '</p>';
break;
}
} // function webform2html_help()
/**
* Adds a HTML download link to the webform submission page.
*/
function webform2html_preprocess_webform_results_submissions(&$vars) {
$rows =& $vars['table']['#rows'];
$i = 0;
$table_row_keys = array_keys($vars['table']['#rows']);
foreach ($vars['submissions'] as $sid => $submission) {
if (webform2html_enabled_html_access($vars['node'], 'webform_submission_access', $vars['node'], $submission, 'view')) {
$rows[$table_row_keys[$i]][] = l(t('HTML'), 'node/' . $submission->nid . '/submission/' . $submission->sid . '/html');
}
else {
$rows[$table_row_keys[$i]][] = '';
}
$i++;
}
$header_keys = array_keys($vars['table']['#header']);
$last_header_key = array_pop($header_keys);
$vars['table']['#operation_total'] += 1;
$vars['table']['#header'][$last_header_key]['colspan'] += 1;
}
/*
* _webform2html_get_template: returns the HTML settings of the given webform
*/
function _webform2html_get_template($nid) {
$setting = webform2html_get_setting($nid);
if (isset($setting['hs_body']['value'])) {
$setting['hs_body']['value'] = check_markup($setting['hs_body']['value'], $setting['hs_body']['format'], FALSE);
}
return $setting;
} // function _webform2html_get_template()
/**
* Get webform2html setting.
*/
function webform2html_get_setting($nid) {
$default = db_select('webform2html', 'w2h')
->fields('w2h')
->condition('nid', $nid, '=')
->execute()
->fetchAssoc();
if ($default) {
$data = unserialize($default['data']);
unset($default['data']);
return array_merge($default, $data);
}
return array();
} // function webform2html_enabled_html_access()
function webform2html_node_view($node, $view_mode, $langcode) {
global $user;
module_load_include('inc', 'webform', 'includes/webform.submissions');
$wp = array('nid' => $node->nid, 'uid' => $user->uid);
$usersubmit = webform_get_submissions($wp);
if (!empty($usersubmit)){
$links = array(
'wp_me' => array( 'title' => t('打印已提交表单'), 'href' => '/node/'.$node->nid.'/submission/'.end($usersubmit)->sid.'/html' ),
// 'wp_all' => array( 'title' => t('浏览'), 'href' => 'node/'.$node->nid.'/webform-results'),
);
$node->content['links']['webform_print'] = array(
'#theme' => 'links',
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
}
}
/**
* Implements hook_views_api().
*/
function webform2html_views_api() {
return array(
'api' => 3.0,
'path' => drupal_get_path('module', 'webform2html') . '/views',
);
}