18 require_once SQ_PACKAGES_PATH.
'/cms/form/form_action/form_action.inc';
43 parent::__construct();
55 if (!isset($settings[
'save_xml'])) {
56 $xml_settings = Array();
58 $xml_settings = $settings[
'save_xml'];
63 <table
class=
"no-borders" style=
"width:auto">
65 <td><?php echo translate(
'location');?></td>
68 $location = array_get_index($xml_settings,
'location',
'');
69 text_box($prefix.
'_location', $location, 50);
70 if (empty($location) || !is_dir($location) || !is_writable($location)) {
72 <span
class=
"sq-backend-warning"><?php echo translate(
'location_warning'); ?></span>
79 <td><?php echo translate(
'xml_detail');?></td>
82 $detail = array_get_index($xml_settings,
'detail',
'simple');
85 'complex' =>
'Complex',
87 combo_box($prefix.
'_detail', $options, FALSE, $detail);
92 <td><?php echo translate(
'xml_key');?></td>
95 $key = array_get_index($xml_settings,
'key',
'value');
100 combo_box($prefix.
'_key', $options, FALSE, $key);
117 if (!isset($settings[
'save_xml'])) {
118 $xml_settings = Array();
120 $xml_settings = $settings[
'save_xml'];
123 $xml_settings[
'location'] = array_get_index($_POST, $prefix.
'_location',
'');
124 $xml_settings[
'detail'] = array_get_index($_POST, $prefix.
'_detail',
'simple');
125 $xml_settings[
'key'] = array_get_index($_POST, $prefix.
'_key',
'value');
127 $settings[
'save_xml'] = $xml_settings;
141 if (!isset($settings[
'save_xml'])) {
142 $xml_settings = Array();
144 $xml_settings = $settings[
'save_xml'];
146 self::_fillDefaultValues($xml_settings);
148 ?><table
class=
"no-borders">
155 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><strong>Location:</strong></p></td>
156 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><?php
157 if (!empty($xml_settings[
'location'])) {
158 echo ellipsisize($xml_settings[
'location'], 512);
160 ?><span
class=
"sq-backend-warning">No Location specified.</span><?php
176 $xml_settings = $settings[
'save_xml'];
179 $check = self::isValid($form, $settings);
180 if (!$check)
return FALSE;
183 $location = $xml_settings[
'location'];
184 $detail = ($xml_settings[
'detail'] ==
'complex') ? TRUE : FALSE;
185 $use_keys = ($xml_settings[
'key'] ==
'key') ? TRUE : FALSE;
188 $complete = $submission->attr(
'complete');
189 $attributes = $submission->attr(
'attributes');
190 $answers = array_get_index($attributes,
'answers', Array());
191 $file = $location.
'/submission-'.$submission->id.
'-'.date(
'YmdHis', $submission->created).
'.xml';
194 if ($complete && !empty($answers)) {
196 $sxml =
new SimpleXMLElement(
'<submission></submission>');
197 $sxml->addAttribute(
'id', $submission->id);
198 $sxml->addAttribute(
'form', $form->id);
199 $sxml->addAttribute(
'time', date(
'YmdHis', $submission->created));
202 if (isset($attributes[
'misc'][
'ip'])) {
203 $sxml->addAttribute(
'ip', $attributes[
'misc'][
'ip']);
205 if (!empty($submission->updated_userid)) {
206 $sxml->addAttribute(
'user', $submission->created_userid);
211 foreach ($answers as $question_id => $answer) {
213 if (isset($questions[$question_id])) {
214 $type = str_replace(
'form_question_type_',
'', $questions[$question_id][
'question_type_code']);
215 $question_name = $questions[$question_id][
'attributes'][
'name'];
222 $value = $answer[
'answer'];
227 case 'tickbox_table':
228 $repsonses = Array();
230 if (isset($questions[$question_id])) {
231 $ttable = @unserialize($questions[$question_id][
'attributes'][
'question_contents']);
232 $waste = array_shift($ttable);
233 foreach ($ttable as $id => $options) {
235 $another_waste = array_shift($options);
236 $ttable[$id] = $options;
239 foreach ($value as $qid => $response) {
240 foreach ($response as $ra => $stuff) {
241 if (isset($ttable[$qid][$ra])) {
242 $responses[] = htmlspecialchars($ttable[$qid][$ra]);
253 if (is_array($value)) {
254 if (isset($questions[$question_id][
'attributes'][
'options']) && !$use_keys) {
255 $list_options = @unserialize($questions[$question_id][
'attributes'][
'options']);
256 foreach ($value as $id => $name) {
257 if (isset($list_options[$name])) {
259 $value[$id] = htmlspecialchars($list_options[$name]);
264 if (isset($questions[$question_id][
'attributes'][
'options']) && !$use_keys) {
265 $list_options = @unserialize($questions[$question_id][
'attributes'][
'options']);
266 if (isset($list_options[$value])) {
267 $value = htmlspecialchars($list_options[$value]);
273 require_once SQ_FUDGE_PATH.
'/standards_lists/countries.inc';
274 global $standards_lists_countries;
275 if (is_array($value)) {
276 foreach ($value as $id => $name) {
277 if (isset($standards_lists_countries[$name]) && !$use_keys) {
279 $value[$id] = htmlspecialchars($standards_lists_countries[$name]);
283 if (isset($standards_lists_countries[$value]) && !$use_keys) {
284 $value = htmlspecialchars($standards_lists_countries[$value]);
293 if (isset($answer[
'extra_data'][
'new_file_assetid']) && !empty($answer[
'extra_data'][
'new_file_assetid'])) {
294 $assetid = $answer[
'extra_data'][
'new_file_assetid'];
296 if (isset($answer[
'extra_data'][
'existing_file_assetid']) && !empty($answer[
'extra_data'][
'existing_file_assetid'])) {
297 $assetid = $answer[
'extra_data'][
'existing_file_assetid'];
300 if (!empty($assetid)) {
301 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
302 if (!is_null($asset)) {
303 $file_details = $asset->getExistingFile();
304 $file_to_process = $file_details[
'path'];
305 $filename = $file_details[
'filename'];
306 if (file_exists($file_to_process)) {
307 $fhandle = fopen($file_to_process,
'r');
308 $file_content = fread($fhandle, filesize($file_to_process));
310 $value = chunk_split(base64_encode($file_content));
318 $timestamp = iso8601_ts($value);
319 if ($timestamp !== FALSE) {
320 $value = date(
'Ymd', $timestamp);
327 if (is_array($value)) {
328 if (!empty($value)) {
329 $value = implode(
'|', $value);
336 $response = $sxml->addChild(
'response', utf8_encode($value));
337 if (!empty($question_name)) {
338 $response->addAttribute(
'name', utf8_encode($question_name));
341 $response->addAttribute(
'type', $type);
342 if ($type ==
'file_upload' && !empty($filename)) {
343 $response->addAttribute(
'filename', $filename);
344 if (isset($fileid) && !empty($fileid)) {
345 $response->addAttribute(
'assetid', $fileid);
350 $response->addAttribute(
'id', $question_id);
355 $xml = $sxml->asXML();
357 $result = file_put_contents($file, $xml);
373 if (!isset($settings[
'save_xml'])) {
374 $xml_settings = Array();
376 $xml_settings = $settings[
'save_xml'];
378 self::_fillDefaultValues($xml_settings);
381 if (!isset($xml_settings[
'location']) || empty($xml_settings[
'location'])) {
385 if (!is_dir($xml_settings[
'location']) || !is_writable($xml_settings[
'location'])) {
401 private static function _fillDefaultValues(&$xml_format) {
402 if (!isset($xml_format[
'location'])) {
403 $xml_format[
'location'] =
'';
405 if (!isset($xml_format[
'detail'])) {
406 $xml_format[
'detail'] =
'simple';
407 }
else if (empty($xml_format[
'detail'])) {
408 $xml_format[
'detail'] =
'simple';