View source
<?php
function fillpdf_token_values($type, $object = NULL, $options = array()) {
switch ($type) {
case 'webform':
$submission = $object;
$tokens['webform-meta-nid'] = $submission->nid;
$tokens['webform-meta-sid'] = $submission->sid;
$tokens['webform-meta-uid'] = $submission->uid;
$tokens['webform-meta-remote_addr'] = $submission->remote_addr;
$tokens['webform-meta-submitted'] = $submission->submitted;
$fields = array();
$q = db_query('SELECT cid, form_key, type, extra FROM {webform_component} WHERE nid = %d', $submission->nid);
while ($component = db_fetch_array($q)) {
if (!is_array($submission->data[$component['cid']])) {
$submission->data[$component['cid']] = array();
}
$submission->data[$component['cid']] += $component;
}
$tokens += _fillpdf_get_tokens_from_components($submission);
return $tokens;
}
}
function fillpdf_token_list($type = 'all') {
if ($type == 'webform' || $type == 'all') {
$tokens['webform']['webform-meta-nid'] = t("The webform's node id");
$tokens['webform']['webform-meta-sid'] = t("The webform's submission id");
$tokens['webform']['webform-meta-uid'] = t("The user's id who submitted the webform");
$tokens['webform']['webform-meta-remote_addr'] = t("The user's ip address who submitted the webform");
$tokens['webform']['webform-meta-submitted'] = t("The date the webform was submitted");
$fields = array();
$q = db_query('SELECT name, form_key FROM {webform_component}');
while ($component = db_fetch_array($q)) {
$tokens['webform']["webform-val-{$component['form_key']}"] = t("The value for webform component [{$component['name']}]");
}
return $tokens;
}
}
function _fillpdf_get_tokens_from_components($submission) {
$tokens = array();
foreach ($submission->data as $cid => $component) {
switch ($component['type']) {
case 'fieldset':
case 'pagebreak':
break;
default:
$fullvalue = false;
$options = false;
if (is_string($component['extra'])) {
$component['extra'] = unserialize($component['extra']);
if (is_string($component['extra']['items'])) {
$component['extra']['options'] = $component['extra']['items'];
}
if (is_string($component['extra']['options'])) {
foreach (preg_split('/[\\r\\n]+/', $component['extra']['options']) as $_) {
if (strpos($_, '|') !== false) {
$option = explode('|', $_, 2);
$options["{$option[0]}"] = $option[1];
}
else {
$options["{$_}"] = $_;
}
}
}
}
if ($options) {
$component['extra']['options'] = $options;
unset($options);
}
else {
$component['extra']['options'] = false;
}
}
if ($component['value']) {
switch ($component['type']) {
case 'date':
if ($component['value'][0]) {
$value = substr(format_date(strtotime($component['value'][0]), 'small'), 0, 10);
}
else {
$value = '';
}
break;
case 'select':
case 'grid':
$fullvalue = array();
foreach ($component['value'] as $value) {
if ($component['extra']['options'][$value]) {
$fullvalue[] = $component['extra']['options'][$value];
}
else {
$fullvalue[] = $value;
}
}
$fullvalue = implode(', ', $fullvalue);
default:
$value = implode(', ', $component['value']);
}
}
else {
$value = '';
}
$tokens['webform-val-' . $component['form_key']] = $value;
if ($fullvalue) {
$tokens['webform-fullval-' . $component['form_key']] = $fullvalue;
}
}
return $tokens;
}