Révision feca1e4a
Ajouté par Assos Assos il y a presque 7 ans
drupal7/sites/all/modules/webform/includes/webform.report.inc | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* This file includes helper functions for creating reports for webform.module |
|
5 |
* This file includes helper functions for creating reports for webform.module.
|
|
6 | 6 |
* |
7 | 7 |
* @author Nathan Haug <nate@lullabot.com> |
8 | 8 |
*/ |
... | ... | |
19 | 19 |
// Determine whether views or hard-coded tables should be used for the |
20 | 20 |
// submissions table. |
21 | 21 |
if (!webform_variable_get('webform_table')) { |
22 |
// Load the submissions view |
|
22 |
// Load the submissions view.
|
|
23 | 23 |
$view = webform_get_view($node, 'webform_submissions'); |
24 | 24 |
if ($user_filter) { |
25 | 25 |
if ($user->uid) { |
... | ... | |
100 | 100 |
$element['table']['#rows'] = $rows; |
101 | 101 |
$element['table']['#operation_total'] = $operation_total; |
102 | 102 |
|
103 |
return drupal_render($element); |
|
104 |
|
|
103 |
return $element; |
|
105 | 104 |
} |
106 | 105 |
|
107 | 106 |
/** |
... | ... | |
115 | 114 |
* Loaded webform node. |
116 | 115 |
* @param string $view_id |
117 | 116 |
* machine_id of the view, such as webform_results or webform_submissions. |
118 |
* @return object|NULL |
|
117 |
* |
|
118 |
* @return object|null |
|
119 | 119 |
* The loaded view. |
120 | 120 |
*/ |
121 | 121 |
function webform_get_view($node, $view_id) { |
... | ... | |
200 | 200 |
} |
201 | 201 |
|
202 | 202 |
/** |
203 |
* Preprocess function for webform-results-submissions.tpl.php |
|
203 |
* Preprocess function for webform-results-submissions.tpl.php.
|
|
204 | 204 |
*/ |
205 | 205 |
function template_preprocess_webform_results_submissions(&$vars) { |
206 | 206 |
$vars['node'] = $vars['element']['#node']; |
... | ... | |
208 | 208 |
$vars['table'] = $vars['element']['table']; |
209 | 209 |
$vars['total_count'] = $vars['element']['#total_count']; |
210 | 210 |
$vars['pager_count'] = $vars['element']['#pager_count']; |
211 |
$vars['is_submissions'] = (arg(2) == 'submissions')? 1 : 0; |
|
211 |
$vars['is_submissions'] = (arg(2) == 'submissions') ? 1 : 0;
|
|
212 | 212 |
|
213 | 213 |
unset($vars['element']); |
214 | 214 |
} |
... | ... | |
221 | 221 |
// Determine whether views or hard-coded tables should be used for the |
222 | 222 |
// submissions table. |
223 | 223 |
if (!webform_variable_get('webform_table')) { |
224 |
// Load and preview the results view with a node id argument |
|
224 |
// Load and preview the results view with a node id argument.
|
|
225 | 225 |
$view = webform_get_view($node, 'webform_results'); |
226 | 226 |
return $view->preview('default', array($node->nid)); |
227 | 227 |
} |
228 | 228 |
|
229 |
// Get all the submissions for the node |
|
229 |
// Get all the submissions for the node.
|
|
230 | 230 |
if (isset($_GET['results']) && is_numeric($_GET['results'])) { |
231 | 231 |
$pager_count = $_GET['results']; |
232 | 232 |
} |
... | ... | |
236 | 236 |
$submissions = webform_get_submissions($node->nid, $header, $pager_count); |
237 | 237 |
$total_count = webform_get_submission_count($node->nid, NULL, NULL); |
238 | 238 |
|
239 |
$output = theme('webform_results_table', array('node' => $node, 'components' => $node->webform['components'], 'submissions' => $submissions, 'total_count' => $total_count, 'pager_count' => $pager_count)); |
|
239 |
$output[] = array( |
|
240 |
'#theme' => 'webform_results_table', |
|
241 |
'#node' => $node, |
|
242 |
'#components' => $node->webform['components'], |
|
243 |
'#submissions' => $submissions, |
|
244 |
'#total_count' => $total_count, |
|
245 |
'#pager_count' => $pager_count, |
|
246 |
); |
|
240 | 247 |
if ($pager_count) { |
241 |
$output .= theme('pager');
|
|
248 |
$output[] = array('#theme' => 'pager');
|
|
242 | 249 |
} |
243 | 250 |
return $output; |
244 | 251 |
} |
245 | 252 |
|
253 |
/** |
|
254 |
* |
|
255 |
*/ |
|
246 | 256 |
function theme_webform_results_table_header($variables) { |
247 | 257 |
return array( |
248 | 258 |
array('data' => t('#'), 'field' => 'sid', 'sort' => 'desc'), |
... | ... | |
273 | 283 |
drupal_add_library('webform', 'admin'); |
274 | 284 |
|
275 | 285 |
$node = $variables['node']; |
276 |
$components = $variables['components']; |
|
277 | 286 |
$submissions = $variables['submissions']; |
278 | 287 |
$total_count = $variables['total_count']; |
279 | 288 |
$pager_count = $variables['pager_count']; |
280 | 289 |
|
281 |
$header = array(); |
|
282 | 290 |
$rows = array(); |
283 | 291 |
$cell = array(); |
284 | 292 |
|
... | ... | |
316 | 324 |
$rows[] = array(array('data' => t('There are no submissions for this form. <a href="!url">View this form</a>.', array('!url' => url('node/' . $node->nid))), 'colspan' => 4)); |
317 | 325 |
} |
318 | 326 |
|
319 |
|
|
320 | 327 |
$output = ''; |
321 | 328 |
$output .= theme('webform_results_per_page', array('total_count' => $total_count, 'pager_count' => $pager_count)); |
322 | 329 |
$output .= theme('table', array('header' => $header, 'rows' => $rows)); |
... | ... | |
330 | 337 |
* The node id whose submissions will be deleted. |
331 | 338 |
* @param $batch_size |
332 | 339 |
* The number of submissions to be processed. NULL means all submissions. |
340 |
* |
|
333 | 341 |
* @return |
334 | 342 |
* The number of submissions processed. |
335 | 343 |
*/ |
... | ... | |
360 | 368 |
return confirm_form($form, $question, 'node/' . $node->nid . '/webform-results', NULL, t('Clear'), t('Cancel')); |
361 | 369 |
} |
362 | 370 |
|
371 |
/** |
|
372 |
* |
|
373 |
*/ |
|
363 | 374 |
function webform_results_clear_form_submit($form, &$form_state) { |
364 | 375 |
$nid = $form_state['values']['nid']; |
365 | 376 |
$node = node_load($nid); |
... | ... | |
400 | 411 |
$count = webform_results_clear($node->nid, $batch_size); |
401 | 412 |
$context['results']['count'] += $count; |
402 | 413 |
|
403 |
// Display status message |
|
414 |
// Display status message.
|
|
404 | 415 |
$context['message'] = t('Cleared @count of @total submissions...', array('@count' => $context['results']['count'], '@total' => $context['results']['total'])); |
405 | 416 |
$context['finished'] = $count > 0 |
406 | 417 |
? $context['results']['count'] / $context['results']['total'] |
... | ... | |
450 | 461 |
'#type' => 'container', |
451 | 462 |
'warning' => array( |
452 | 463 |
'#markup' => '<p>' . |
453 |
t('<strong>Warning:</strong> Opening delimited text files with spreadsheet applications may expose you to <a href="!link">formula injection</a> or other security vulnerabilities. When the submissions contain data from untrusted users and the downloaded file will be used with spreadsheets, use Microsoft Excel format.',
|
|
464 |
t('<strong>Warning:</strong> Opening delimited text files with spreadsheet applications may expose you to <a href="!link">formula injection</a> or other security vulnerabilities. When the submissions contain data from untrusted users and the downloaded file will be used with spreadsheets, use Microsoft Excel format.', |
|
454 | 465 |
array('!link' => url('https://www.google.com/search?q=spreadsheet+formula+injection'))) . |
455 |
'</p>',
|
|
466 |
'</p>', |
|
456 | 467 |
), |
457 | 468 |
'delimiter' => array( |
458 | 469 |
'#type' => 'select', |
... | ... | |
604 | 615 |
// programmatically submitting this form. |
605 | 616 |
$form['download'] = array( |
606 | 617 |
'#type' => 'value', |
607 |
'#default_value' => TRUE |
|
618 |
'#default_value' => TRUE,
|
|
608 | 619 |
); |
609 | 620 |
|
610 | 621 |
$form['actions'] = array('#type' => 'actions'); |
... | ... | |
637 | 648 |
} |
638 | 649 |
} |
639 | 650 |
break; |
651 |
|
|
640 | 652 |
case 'range_serial': |
641 | 653 |
// Download Start-End range of submissions. |
642 | 654 |
// Start submission number. |
... | ... | |
670 | 682 |
} |
671 | 683 |
} |
672 | 684 |
break; |
685 |
|
|
673 | 686 |
case 'range_date': |
674 | 687 |
// Download Start-end range of submissions. |
675 | 688 |
// Start submission time. |
... | ... | |
748 | 761 |
$element['range_type']['new']['#theme_wrappers'] = array('webform_inline_radio'); |
749 | 762 |
$element['range_type']['new']['#title'] .= ' (' . t('@count new since @date', array('@count' => $download_info['new'], '@date' => $requested_date)) . ')'; |
750 | 763 |
|
751 |
|
|
752 | 764 |
// Disable option if there are no new submissions. |
753 | 765 |
if ($download_info['new'] == 0) { |
754 | 766 |
$element['range_type']['new']['#attributes']['disabled'] = 'disabled'; |
... | ... | |
774 | 786 |
$element['range_type']['range_serial']['#title'] = t('Submissions by number from !start and optionally to: !end (Last downloaded: !serial)', |
775 | 787 |
array('!start' => drupal_render($element['start']), '!end' => drupal_render($element['end']), '!serial' => $last_serial)); |
776 | 788 |
|
777 |
// date range
|
|
789 |
// Date range.
|
|
778 | 790 |
$element['range_type']['range_date']['#theme_wrappers'] = array('webform_inline_radio'); |
779 | 791 |
$element['range_type']['range_date']['#title'] = t('Submissions by date from !start_date and optionally to: !end_date', array('!start_date' => drupal_render($element['start_date']), '!end_date' => drupal_render($element['end_date']))); |
780 | 792 |
|
... | ... | |
857 | 869 |
* |
858 | 870 |
* @param object $node |
859 | 871 |
* The webform node. |
860 |
* @return integer |
|
872 |
* |
|
873 |
* @return int |
|
861 | 874 |
* The number of submissions to be processed at once. |
862 | 875 |
*/ |
863 | 876 |
function webform_export_batch_size($node) { |
... | ... | |
1043 | 1056 |
// Allow modules to modify the component CSV header. |
1044 | 1057 |
drupal_alter('webform_csv_header', $component_header, $component); |
1045 | 1058 |
|
1046 |
// Merge component CSV header to overall CSV header |
|
1059 |
// Merge component CSV header to overall CSV header.
|
|
1047 | 1060 |
$header[0] = array_merge($header[0], (array) $component_header[0]); |
1048 | 1061 |
$header[1] = array_merge($header[1], (array) $component_header[1]); |
1049 | 1062 |
$header[2] = array_merge($header[2], (array) $component_header[2]); |
... | ... | |
1069 | 1082 |
* @param $last_sid |
1070 | 1083 |
* If set to a non-NULL value, the last sid will be returned. |
1071 | 1084 |
* |
1072 |
* @return array $rows
|
|
1085 |
* @return array |
|
1073 | 1086 |
* An array of rows built according to the provided $serial_start and |
1074 | 1087 |
* $pager_count variables. Note that the current page number is determined |
1075 | 1088 |
* by the super-global $_GET['page'] variable. |
... | ... | |
1108 | 1121 |
* @param array $submissions |
1109 | 1122 |
* An associative array of loaded submissions, indexed by sid. |
1110 | 1123 |
* |
1111 |
* @return array $rows
|
|
1124 |
* @return array |
|
1112 | 1125 |
* An array of rows built according to the provided $serial_start and |
1113 | 1126 |
* $pager_count variables. Note that the current page number is determined |
1114 | 1127 |
* by the super-global $_GET['page'] variable. |
... | ... | |
1214 | 1227 |
switch ($token) { |
1215 | 1228 |
case 'webform_serial': |
1216 | 1229 |
return $submission->serial; |
1230 |
|
|
1217 | 1231 |
case 'webform_sid': |
1218 | 1232 |
return $submission->sid; |
1233 |
|
|
1219 | 1234 |
case 'webform_time': |
1220 | 1235 |
// Return timestamp in local time (not UTC). |
1221 | 1236 |
if (!empty($options['iso8601_date'])) { |
... | ... | |
1245 | 1260 |
} |
1246 | 1261 |
case 'webform_draft': |
1247 | 1262 |
return $submission->is_draft; |
1263 |
|
|
1248 | 1264 |
case 'webform_ip_address': |
1249 | 1265 |
return $submission->remote_addr; |
1266 |
|
|
1250 | 1267 |
case 'webform_uid': |
1251 | 1268 |
return $submission->uid; |
1269 |
|
|
1252 | 1270 |
case 'webform_username': |
1253 | 1271 |
return $submission->name; |
1254 | 1272 |
} |
... | ... | |
1310 | 1328 |
else { |
1311 | 1329 |
$export_name = _webform_safe_name($node->title); |
1312 | 1330 |
if (!strlen($export_name)) { |
1313 |
$export_name = t('Untitled');
|
|
1331 |
$export_name = t('Untitled'); |
|
1314 | 1332 |
} |
1315 | 1333 |
$export_info['exporter']->set_headers($export_name); |
1316 | 1334 |
ob_clean(); |
1317 |
@readfile($export_info['file_name']); // The @ makes it silent. |
|
1318 |
@unlink($export_info['file_name']); // Clean up, the @ makes it silent. |
|
1335 |
// The @ makes it silent. |
|
1336 |
@readfile($export_info['file_name']); |
|
1337 |
// Clean up, the @ makes it silent. |
|
1338 |
@unlink($export_info['file_name']); |
|
1319 | 1339 |
} |
1320 | 1340 |
|
1321 | 1341 |
// Save the last exported sid for new-only exports. |
... | ... | |
1477 | 1497 |
|
1478 | 1498 |
@fclose($handle); |
1479 | 1499 |
|
1480 |
// Display status message |
|
1500 |
// Display status message.
|
|
1481 | 1501 |
$context['message'] = t('Exported @count of @total submissions...', array('@count' => $context['sandbox']['serial'], '@total' => $context['sandbox']['sid_count'])); |
1482 | 1502 |
$context['finished'] = $context['sandbox']['batch_number'] < $context['sandbox']['batch_max'] |
1483 | 1503 |
? $context['sandbox']['batch_number'] / $context['sandbox']['batch_max'] |
... | ... | |
1500 | 1520 |
if (!$handle) { |
1501 | 1521 |
return; |
1502 | 1522 |
} |
1503 |
fseek($handle, 0, SEEK_END); // Move pointer to the end of the file. |
|
1523 |
// Move pointer to the end of the file. |
|
1524 |
fseek($handle, 0, SEEK_END); |
|
1504 | 1525 |
$exporter->eof($handle, $context['results']['row_count'], $context['results']['col_count']); |
1505 | 1526 |
@fclose($handle); |
1506 | 1527 |
} |
... | ... | |
1581 | 1602 |
* relating specifically to that component's analysis, such as a list of |
1582 | 1603 |
* "Other" values within a select list. |
1583 | 1604 |
* |
1584 |
* @return string
|
|
1585 |
* Provides a simple analysis of all submissions to a webform.
|
|
1605 |
* @return array
|
|
1606 |
* Renderable array: A simple analysis of all submissions to a webform.
|
|
1586 | 1607 |
*/ |
1587 | 1608 |
function webform_results_analysis($node, $sids = array(), $analysis_component = NULL) { |
1588 | 1609 |
if (!is_array($sids)) { |
... | ... | |
1651 | 1672 |
} |
1652 | 1673 |
|
1653 | 1674 |
drupal_alter('webform_analysis', $analysis); |
1654 |
return drupal_render($analysis);
|
|
1675 |
return $analysis;
|
|
1655 | 1676 |
} |
1656 | 1677 |
|
1657 | 1678 |
/** |
... | ... | |
1712 | 1733 |
$data['table_rows'][] = $other_data; |
1713 | 1734 |
} |
1714 | 1735 |
else { |
1715 |
$data['table_rows'][] = array(array( |
|
1716 |
'colspan' => 2, |
|
1717 |
'data' => $other_data, |
|
1718 |
)); |
|
1736 |
$data['table_rows'][] = array( |
|
1737 |
array( |
|
1738 |
'colspan' => 2, |
|
1739 |
'data' => $other_data, |
|
1740 |
), |
|
1741 |
); |
|
1719 | 1742 |
} |
1720 | 1743 |
} |
1721 | 1744 |
} |
... | ... | |
1739 | 1762 |
* |
1740 | 1763 |
* @param $node |
1741 | 1764 |
* The node whose components' data is being analyzed. |
1765 |
* |
|
1742 | 1766 |
* @return array |
1743 | 1767 |
* An array of component IDs. |
1744 | 1768 |
*/ |
... | ... | |
1820 | 1844 |
function theme_webform_results_analysis($variables) { |
1821 | 1845 |
$node = $variables['node']; |
1822 | 1846 |
$data = $variables['data']; |
1823 |
$sids = $variables['sids']; |
|
1824 | 1847 |
$analysis_component = $variables['component']; |
1825 | 1848 |
|
1826 | 1849 |
$rows = array(); |
... | ... | |
1829 | 1852 |
|
1830 | 1853 |
$header = array( |
1831 | 1854 |
$single ? $analysis_component['name'] : t('Q'), |
1832 |
array('data' => $single ? ' ' : t('responses'), 'colspan' => '10') |
|
1855 |
array('data' => $single ? ' ' : t('responses'), 'colspan' => '10'),
|
|
1833 | 1856 |
); |
1834 | 1857 |
|
1835 | 1858 |
foreach ($data as $cid => $row_data) { |
... | ... | |
1858 | 1881 |
* |
1859 | 1882 |
* @deprecated This function is scheduled to be removed int webform 7.x-5.x. |
1860 | 1883 |
* Use webform_download_sids_query() instead. |
1861 |
* |
|
1862 | 1884 |
*/ |
1863 | 1885 |
function webform_download_sids($nid, $range_options, $uid = NULL) { |
1864 | 1886 |
return webform_download_sids_query($nid, $range_options, $uid) |
... | ... | |
1869 | 1891 |
|
1870 | 1892 |
/** |
1871 | 1893 |
* Retrieves a count the number of matching submissions. |
1872 |
* |
|
1873 | 1894 |
*/ |
1874 | 1895 |
function webform_download_sids_count($nid, $range_options, $uid = NULL) { |
1875 | 1896 |
return webform_download_sids_query($nid, $range_options, $uid) |
... | ... | |
1884 | 1905 |
* The query will have no fields as they should be added by the caller as |
1885 | 1906 |
* desired. |
1886 | 1907 |
* |
1887 |
* @param integer $nid
|
|
1908 |
* @param int $nid |
|
1888 | 1909 |
* The node id of the webform. |
1889 | 1910 |
* @param array $range_options |
1890 | 1911 |
* Associate array of range options. |
1891 |
* @param integer $uid
|
|
1912 |
* @param int $uid |
|
1892 | 1913 |
* The user id of the user whose last download information should be used, |
1893 | 1914 |
* or the current user if NULL. This is unrelated to which user submitted |
1894 | 1915 |
* the submissions. |
... | ... | |
1905 | 1926 |
// All Submissions. |
1906 | 1927 |
$query->orderBy('ws.sid', 'ASC'); |
1907 | 1928 |
break; |
1929 |
|
|
1908 | 1930 |
case 'new': |
1909 | 1931 |
// All Since Last Download. |
1910 | 1932 |
$download_info = webform_download_last_download_info($nid, $uid); |
... | ... | |
1913 | 1935 |
->condition('ws.sid', $last_sid, '>') |
1914 | 1936 |
->orderBy('ws.sid', 'ASC'); |
1915 | 1937 |
break; |
1938 |
|
|
1916 | 1939 |
case 'latest': |
1917 | 1940 |
// Last x Submissions. |
1918 | 1941 |
$start_sid = webform_download_latest_start_sid($nid, $range_options['latest'], $range_options['completion_type']); |
1919 | 1942 |
$query->condition('ws.sid', $start_sid, '>='); |
1920 | 1943 |
break; |
1944 |
|
|
1921 | 1945 |
case 'range': |
1922 | 1946 |
// Submissions Start-End. |
1923 | 1947 |
$query->condition('ws.sid', $range_options['start'], '>='); |
... | ... | |
1926 | 1950 |
} |
1927 | 1951 |
$query->orderBy('ws.sid', 'ASC'); |
1928 | 1952 |
break; |
1953 |
|
|
1929 | 1954 |
case 'range_serial': |
1930 | 1955 |
// Submissions Start-End, using serial numbers. |
1931 | 1956 |
$query->condition('ws.serial', $range_options['start'], '>='); |
... | ... | |
1934 | 1959 |
} |
1935 | 1960 |
$query->orderBy('ws.serial', 'ASC'); |
1936 | 1961 |
break; |
1962 |
|
|
1937 | 1963 |
case 'range_date': |
1938 | 1964 |
$date_field = $range_options['completion_type'] == 'finished' ? 'ws.completed' : 'ws.submitted'; |
1939 | 1965 |
$query->condition($date_field, strtotime($range_options['start_date']), '>='); |
1940 | 1966 |
if ($range_options['end_date'] != '' && ($end_time = strtotime($range_options['end_date'])) !== FALSE) { |
1941 | 1967 |
if ($end_time == strtotime('midnight', $end_time)) { |
1942 | 1968 |
// Full day specified |
1943 |
$end_time += 86399; // 86400 is a full day of seconds. |
|
1969 |
// 86400 is a full day of seconds. |
|
1970 |
$end_time += 86399; |
|
1944 | 1971 |
} |
1945 | 1972 |
$query->condition($date_field, $end_time, '<='); |
1946 |
} |
|
1947 |
; |
|
1973 |
}; |
|
1948 | 1974 |
$query->orderBy($date_field, 'ASC'); |
1949 | 1975 |
break; |
1950 | 1976 |
} |
... | ... | |
1973 | 1999 |
* The Webform NID. |
1974 | 2000 |
* @param $uid |
1975 | 2001 |
* The user account ID for which to retrieve download information. |
2002 |
* |
|
1976 | 2003 |
* @return |
1977 | 2004 |
* An array of download information or FALSE if this user has never downloaded |
1978 | 2005 |
* results for this particular node. |
... | ... | |
2002 | 2029 |
* The latest count on which the SID will be retrieved. |
2003 | 2030 |
* @param string $completion_type |
2004 | 2031 |
* The completion type, either "finished", "draft", or "all". |
2032 |
* |
|
2005 | 2033 |
* @return |
2006 | 2034 |
* The submission ID that starts the latest sequence of submissions. |
2007 | 2035 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules