18 require_once SQ_PACKAGES_PATH.
'/cms/form/form_section_action/form_section_action.inc';
19 require_once SQ_FUDGE_PATH.
'/general/text.inc';
20 require_once dirname(dirname(dirname(__FILE__))).
'/lib/soap_common.inc';
21 require_once dirname(dirname(dirname(__FILE__))).
'/lib/soap_form_based_common.inc';
45 parent::__construct();
59 <p
class=
"sq-backend-section-subheading">Connection Details</p>
61 <div
id=
"<?php echo $prefix ?>_connection_div" style=
"padding: 0.5em 0px 2em 30px;">
62 <table
class=
"sq-backend-table" >
64 <td width=
"120"><p>WSDL</p></td>
65 <td><p><?php text_box($prefix.
'_wsdl', array_get_index($settings,
'wsdl',
''), 120); ?></p></td>
68 <td><?php echo translate(
'login'); ?></td>
69 <td><p><?php text_box($prefix.
'_login', array_get_index($settings,
'login',
''), 35); ?><br />
73 <td><?php echo translate(
'password'); ?></td>
74 <td><p><?php password_box($prefix.
'_password', array_get_index($settings,
'password',
''), 35); ?></p></td>
77 <td colspan=
"2"><?php echo translate(
'use_http_authentication'); ?></td>
80 <td><?php echo translate(
'mute_exceptions'); ?></td>
81 <td><p><?php check_box($prefix.
'_mute_exceptions', 1, array_get_index($settings,
'mute_exceptions', 0)); ?></p></td>
86 <div
id=
"<?php echo $prefix ?>_https_div" style=
"padding: 0.5em 0px 2em 30px;">
87 <table
class=
"sq-backend-table" >
89 <td><p><?php echo translate(
'local_cert'); ?></p></td>
90 <td><p><?php asset_finder($prefix.
'_local_cert', array_get_index($settings,
'local_cert',
''), Array(
'file'=>
'D')); ?><br/>
93 <td><p><?php echo translate(
'passphrase'); ?></p></td>
94 <td><p><?php password_box($prefix.
'_passphrase', array_get_index($settings,
'passphrase',
''), 35); ?></p></td>
97 <td colspan=
"2"><?php echo translate(
'use_https'); ?></td>
102 <p
class=
"sq-backend-section-subheading">Test Response</p>
103 <div
id=
"<?php echo $prefix ?>_test_request_response" style=
"padding: 0.5em 0px 2em 30px;">
104 <table
class=
"sq-backend-table" >
106 <td width=
"120">Run Test</td>
109 $run_test = array_get_index($settings,
'run_test', 0);
110 check_box($prefix.
'_run_test', 1, $run_test);
115 <td colspan=
"2">The test will be based on the request content in the
"SOAP Request Message" below</td>
122 if ($run_test && !empty($settings[
'test_results'])) {
123 foreach($settings[
'test_results'] as $soap_func => $info) {
124 echo
"<b><u>$soap_func</u></b><br /><br />";
125 echo
"<b>Request:</b><br />";
126 echo (nl2br(str_replace(
' ',
' ', htmlentities($info[
'request']))));
128 echo
"<b>Response:</b><br />";
129 echo (nl2br(str_replace(
' ',
' ', htmlentities($info[
'response']))));
139 <?php
if(!isset($settings[
'actions']) || empty($settings[
'actions']))
return;?>
141 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'request_message'); ?></p>
143 <div
id=
"<?php echo $prefix ?>_action_selection" style=
"padding: 0.5em 0px 2em 30px;">
144 <table
class=
"sq-backend-table" >
146 <td><strong><?php echo translate(
'action');?></strong><br /><br /></td>
149 foreach ($settings[
'actions'] as $name => $detail) {
150 $action_list[$name] = $name;
152 combo_box($prefix.
'_action', $action_list, FALSE, array_get_index($settings,
'action',
''));
158 <td><span style=
"padding-top:10px;"><strong><?php echo translate(
'params');?></strong></span></td>
162 if(isset($settings[
'actions'][$settings[
'action']])) {
163 foreach ($settings[
'actions'][$settings[
'action']] as $parameter_xml) {
164 text_area($prefix.
'_'.$settings[
'action'].
'parameters'.$i, array_get_index($settings,$settings[
'action'].
'parameters'.$i, $parameter_xml), 80, 15);
174 <td colspan=
"2"><?php echo translate(
'question_keyword_example'); ?></td>
181 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_message'); ?></p>
183 <div
id=
"<?php echo $prefix ?>_response" style=
"padding: 0.5em 0px 2em 30px;">
184 <table
class=
"sq-backend-table" >
188 if(isset($settings[
'responses'][$settings[
'action']])) {
190 echo (nl2br(str_replace(
' ',
' ', htmlentities(str_replace(
'[ARRAY_ELEMENT]',
'', $settings[
'responses'][$settings[
'action']])))));
198 <?php echo translate(
'response_message_note'); ?>
206 <p
class=
"sq-backend-section-subheading">Check Response</p>
208 <div
id=
"<?php echo $prefix ?>_response_error" style=
"padding: 0.5em 0px 2em 30px;">
209 <table
class=
"sq-backend-table" >
213 $selected_fields = isset($settings[$settings[
'action'].
'_response_error_fields']) ? $settings[$settings[
'action'].
'_response_error_fields'] : Array();
214 if (empty($selected_fields)) {
215 echo
"No SOAP response fields selected";
218 <table
class=
"sq-backend-table">
220 <td
class=
"sq-backend-table-header"><?php echo translate(
'field_name'); ?></td>
221 <td
class=
"sq-backend-table-header"><?php echo translate(
'error_text'); ?></td>
222 <td
class=
"sq-backend-table-header"><?php echo translate(
'delete_question'); ?></td>
226 foreach ($selected_fields as $selected_field => $rule) {
227 $error_msg = array_get_index($rule,
'error_msg',
'');
228 $rule_value = array_get_index($rule,
'value',
'');
229 $rule_type = array_get_index($rule,
'type',
'must_contain');;
231 $sf_prefix = $prefix.
'_'.$settings[
'action'].
'_'.$selected_field;
234 <td
class=
"sq-backend-table-cell"><?php echo $selected_field; ?></td>
235 <td
class=
"sq-backend-table-cell">
240 combo_box($sf_prefix.
'_type', $rules, FALSE, $rule_type);
245 <td>Value</td><td><?php text_box($sf_prefix.
'_value', $rule_value, 40); ?></td>
248 <td>Error Message</td><td><?php text_box($sf_prefix.
'_error_msg', $error_msg, 110); ?></td>
253 <td
class=
"sq-backend-table-cell">
254 <?php check_box($sf_prefix.
'_delete_field['.$selected_field.
']'); ?>
266 echo translate(
'add_new_field');
267 $response_fields = Array(
'' =>
'-- Select Field --');
268 if (isset($settings[
'response_keywords'][$settings[
'action']])) {
269 $response_keywords = explode(
'<br/>', $settings[
'response_keywords'][$settings[
'action']]);
270 foreach($response_keywords as $val) {
271 $val = trim($val,
'%');
272 $val = substr_replace($val,
'', 0, strlen(
'globals_session_'.$form_section->id.
'_soap_'));
275 $response_fields[$val] = $val;
279 combo_box($prefix.
'_'.$settings[
'action'].
'_response_error_field', $response_fields, FALSE);
285 <td><?php translate(
'fail_validation_error_msg'); ?></td>
291 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_keywords'); ?></p>
293 <div
id=
"<?php echo $prefix ?>_response_keywords" style=
"padding: 0.5em 0px 2em 30px;">
294 <table
class=
"sq-backend-table" >
298 if(isset($settings[
'response_keywords'][$settings[
'action']])) {
300 echo ($settings[
'response_keywords'][$settings[
'action']]);
307 <td><?php echo translate(
'response_keyword_note'); ?></td>
310 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_to_download_as_file'); ?></p>
311 <table
class=
"sq-backend-table">
313 <td
class=
"sq-backend-table-header"><?php echo translate(
'field_keyword_tags'); ?></td>
316 $response_to_file = array_get_index($settings, $settings[
'action'].
'_file_response_to_save', Array());
317 $currently_configured = count($response_to_file);
319 foreach ($response_to_file as $i => $response) { ?>
323 text_box($prefix.
'_'.$settings[
'action'].
'_file_response_to_save['.$i.
']', $response, 50);
325 if (in_array($response, $settings[$settings[
'action'].
'_invalid_keywords_for_file'])) {
327 echo
"<span style=\"color:#FF0000\"><b> *invalid keyword</b></span>";
336 $count = $currently_configured++;
337 text_box($prefix.
'_'.$settings[
'action'].
'_file_response_to_save['.$count.
']',
'', 50);
342 <td><?php echo translate(
'response_to_download_as_file_note'); ?></td>
360 $settings[
'local_cert'] = isset($_POST[$prefix.
'_local_cert'][
'assetid']) ? $_POST[$prefix.
'_local_cert'][
'assetid']: NULL;
361 $settings[
'wsdl'] = array_get_index($_POST, $prefix.
'_wsdl', NULL);
362 $settings[
'login'] = array_get_index($_POST, $prefix.
'_login', NULL);
363 $settings[
'password'] = array_get_index($_POST, $prefix.
'_password', NULL);
364 $settings[
'mute_exceptions'] = array_get_index($_POST, $prefix.
'_mute_exceptions', NULL);
365 $settings[
'run_test'] = array_get_index($_POST, $prefix.
'_run_test', NULL);
366 $settings[
'passphrase'] = array_get_index($_POST, $prefix.
'_passphrase', NULL);
367 $settings[
'action'] = array_get_index($_POST, $prefix.
'_action', NULL);
370 $settings[
'before_submit'] = TRUE;
372 if(isset ($settings[
'wsdl']) && !empty($settings[
'wsdl'])) {
376 $client =
new SoapClient($settings[
'wsdl'], $options);
377 $functions = $client->__getFunctions();
378 $types = $client->__getTypes();
380 catch (Exception $e) {
381 trigger_error($e->getMessage());
385 if(!empty($functions)) {
386 foreach ($functions as $function) {
387 $function_name = preg_replace(
'/^\w+ (\w+)\(.*\)/',
'$1', $function);
388 $function_params = explode(
', ', preg_replace(
'/^\w+ \w+\((.*)\)/',
'$1', $function));
389 $function_response = preg_replace(
'/^(\w+) \w+\(.*\)/',
'$1', $function);
392 if(isset($function_list[$function_name]))
continue;
395 $parsed_params = Array();
396 foreach ($function_params as $param) {
397 if (!trim($param))
continue;
403 $function_list[$function_name] = $parsed_params;
407 if ($xml_response === TRUE || $xml_response === FALSE) {
409 $keywords =
'globals_session_'.$form_section->id.
'_soap'.($xml_response ?
'0' :
'');
415 $keywords_list[$function_name] = str_replace(
'[ARRAY_ELEMENT]',
'0', $keywords);
419 $settings[
'actions'] = $function_list;
420 $settings[
'responses'] = $response_list;
421 $settings[
'response_keywords'] = $keywords_list;
426 $current_selected_fields = isset($settings[$settings[
'action'].
'_response_error_fields']) ? $settings[$settings[
'action'].
'_response_error_fields'] : Array();
427 $field_rule = Array();
430 $keywords_string =
'';
431 if (isset($settings[
'response_keywords'])) {
432 $keywords_string = implode(
';',$settings[
'response_keywords']);
435 foreach ($current_selected_fields as $selected_field => $rule) {
436 $sf_prefix = $prefix.
'_'.$settings[
'action'].
'_'.$selected_field;
439 if ((!isset($_POST[$sf_prefix.
'_delete_field'][$selected_field]) || !$_POST[$sf_prefix.
'_delete_field'][$selected_field]) && strpos($keywords_string,
'%globals_session_'.$form_section->id.
'_soap_'.$selected_field.
'%') !== FALSE) {
440 if (isset($_POST[$sf_prefix.
'_error_msg'])) {
441 $field_rule[$selected_field] = Array(
442 'type' => $_POST[$sf_prefix.
'_type'],
443 'value' => $_POST[$sf_prefix.
'_value'],
444 'error_msg' => trim($_POST[$sf_prefix.
'_error_msg']),
447 $field_rule[$selected_field] = $rule;
453 if (isset($_POST[$prefix.
'_'.$settings[
'action'].
'_response_error_field']) && !empty($_POST[$prefix.
'_'.$settings[
'action'].
'_response_error_field'])) {
454 $new_field = $_POST[$prefix.
'_'.$settings[
'action'].
'_response_error_field'];
455 $field_rule[$new_field] = Array();
459 if(isset($settings[
'actions'][$settings[
'action']])) {
460 $settings[$settings[
'action'].
'_response_error_fields'] = $field_rule;
461 for($i = 0; $i < count($settings[
'actions'][$settings[
'action']]); $i++) {
462 if(isset($_POST[$prefix.
'_'.$settings[
'action'].
'parameters'.$i]))
463 $settings[$settings[
'action'].
'parameters'.$i] = $_POST[$prefix.
'_'.$settings[
'action'].
'parameters'.$i];
467 $settings[$settings[
'action'].
'_invalid_keywords_for_file'] = Array();
468 if (isset($settings[
'actions'][$settings[
'action']])) {
469 $save_file_response = array_get_index($_POST, $prefix.
'_'.$settings[
'action'].
'_file_response_to_save', Array());
470 foreach ($save_file_response as $index => $response_kwd) {
473 if (trim($response_kwd) ==
'') {
474 unset($save_file_response[$index]);
478 if (strpos($settings[
'response_keywords'][$settings[
'action']], $response_kwd) === FALSE) {
479 $settings[$settings[
'action'].
'_invalid_keywords_for_file'][] = $response_kwd;
482 $settings[$settings[
'action'].
'_file_response_to_save'] = $save_file_response;
486 $test_results = Array();
487 if ($settings[
'run_test']) {
488 foreach($functions as $function) {
489 $function_name = preg_replace(
'/^\w+ (\w+)\(.*\)/',
'$1', $function);
490 if($function_name != $settings[
'action'])
continue;
494 $settings[
'test_results'] = $test_results;
510 ?><table
class=
"no-borders">
517 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><strong><?php echo translate(
'action');?></strong></p></td>
518 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><?php
519 if (isset ($settings[
'action'])) {
520 echo $settings[
'action'];
522 ?><span
class=
"sq-backend-warning"><?php echo translate(
'no_soap_action');?></span><?php
525 if (!isset ($settings[$settings[
'action'].
'parameters0'])) {
526 ?><br/><span
class=
"sq-backend-warning"><?php echo translate(
'no_parameter');?></span><?php
547 if(!isset($form->submission_errors)) {
548 $form->submission_errors = Array();
551 if(!isset($settings[
'actions'][$settings[
'action']])) {
552 $form->submission_errors = array_merge($form->submission_errors, Array(translate(
'no_soap_action')));
555 if(!isset($settings[
'wsdl'])) {
556 $form->submission_errors = array_merge($form->submission_errors, Array(translate(
'no_wsdl')));
560 $function = $settings[
'action'];
561 $wsdl = $settings[
'wsdl'];
565 for($i = 0, $param = Array(); $i < count($settings[
'actions'][$settings[
'action']]); $i++) {
566 if(isset($settings[$settings[
'action'].
'parameters'.$i])) {
569 $object = @simplexml_load_string($soap_message,
'SimpleXMLElement' , LIBXML_NOCDATA);
571 if($object === FALSE) {
585 foreach ($param as $index => $object) {
586 $eval_string .= $index == 0 ?
'' :
', ';
587 $eval_string .=
'$param['.$index.
']';
591 $options[
'trace'] = 1;
594 if ($settings[
'mute_exceptions']) {
595 $options[
'exceptions'] = 0;
600 $client =
new SoapClient($wsdl, $options);
601 eval(
'$data = $client->$function('.$eval_string.
');');
603 catch (Exception $e) {
605 $form->submission_errors = array_merge($form->submission_errors, Array($e->getMessage()));
609 if ($settings[
'mute_exceptions'] && get_class($data) ==
'SoapFault') {
610 $soap_response = $client->__getLastResponse();
613 if (preg_match(
'|<([^:]+:)?Body>(.*)</([^:]+:)?Body>|msi', $soap_response, $match)) {
614 $data = simplexml_load_string($match[2]);
619 $soap_response_keywords = Array();
620 $file_saving_keywords = array_get_index($settings, $settings[
'action'].
'_file_response_to_save', Array());
624 if (empty($_SESSION[SQ_SESSION_SANDBOX_INDEX][$form_section->id.
'_soap_response_keywords'])) {
625 $_SESSION[SQ_SESSION_SANDBOX_INDEX][$form_section->id.
'_soap_response_keywords'] = Array();
628 $_SESSION[SQ_SESSION_SANDBOX_INDEX][$form_section->id.
'_soap_response_keywords'] = array_merge($_SESSION[SQ_SESSION_SANDBOX_INDEX][$form_section->id.
'_soap_response_keywords'], array_keys($soap_response_keywords));
632 foreach($soap_response_keywords as $key => $val) {
633 $soap_response_keywords[substr_replace($key,
'', 0, strlen($form_section->id.
'_soap_'))] = $val;
634 unset($soap_response_keywords[$key]);
637 if (!empty($settings[$settings[
'action'].
'_response_error_fields'])) {
638 foreach($settings[$settings[
'action'].
'_response_error_fields'] as $check_field => $rule) {
640 $form->submission_errors = array_merge($form->submission_errors, Array($rule[
'error_msg']));
664 if (!empty($_SESSION[SQ_SESSION_SANDBOX_INDEX][$form->id.
'_soap_response_keywords'])) {
665 $session_keywords = array_unique($_SESSION[SQ_SESSION_SANDBOX_INDEX][$form->id.
'_soap_response_keywords']);
666 foreach($session_keywords as $session_keyword) {
667 if (isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][$session_keyword])) {
668 unset($_SESSION[SQ_SESSION_SANDBOX_INDEX][$session_keyword]);
671 unset($_SESSION[SQ_SESSION_SANDBOX_INDEX][$form->id.
'_soap_response_keywords']);
672 unset($session_keywords);
687 if (empty($settings[
'wsdl'])) {
692 if (empty($settings[
'actions'])) {
697 if (!isset($settings[
'action'])) {
702 if (!isset ($settings[$settings[
'action'].
'parameters0'])) {