18 require_once SQ_PACKAGES_PATH.
'/cms/form/form_action/form_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';
46 parent::__construct();
60 <p
class=
"sq-backend-section-subheading">Connection Details</p>
62 <div
id=
"<?php echo $prefix ?>_connection_div" style=
"padding: 0.5em 0px 2em 30px;">
63 <table
class=
"sq-backend-table" >
65 <td width=
"120"><p>WSDL</p></td>
66 <td><p><?php text_box($prefix.
'_wsdl', array_get_index($settings,
'wsdl',
''), 120); ?></p></td>
69 <td><?php echo translate(
'login'); ?></td>
70 <td><p><?php text_box($prefix.
'_login', array_get_index($settings,
'login',
''), 35); ?><br />
74 <td><?php echo translate(
'password'); ?></td>
75 <td><p><?php password_box($prefix.
'_password', array_get_index($settings,
'password',
''), 35); ?></p></td>
78 <td colspan=
"2"><?php echo translate(
'use_http_authentication'); ?></td>
81 <td><?php echo translate(
'mute_exceptions'); ?></td>
82 <td><p><?php check_box($prefix.
'_mute_exceptions', 1, array_get_index($settings,
'mute_exceptions', 0)); ?></p></td>
87 <div
id=
"<?php echo $prefix ?>_https_div" style=
"padding: 0.5em 0px 2em 30px;">
88 <table
class=
"sq-backend-table" >
90 <td><p><?php echo translate(
'local_cert'); ?></p></td>
91 <td><p><?php asset_finder($prefix.
'_local_cert', array_get_index($settings,
'local_cert',
''), Array(
'file'=>
'D')); ?><br/>
94 <td><p><?php echo translate(
'passphrase'); ?></p></td>
95 <td><p><?php password_box($prefix.
'_passphrase', array_get_index($settings,
'passphrase',
''), 35); ?></p></td>
98 <td colspan=
"2"><?php echo translate(
'use_https'); ?></td>
103 <p
class=
"sq-backend-section-subheading">Test Response</p>
104 <div
id=
"<?php echo $prefix ?>_test_request_response" style=
"padding: 0.5em 0px 2em 30px;">
105 <table
class=
"sq-backend-table" >
107 <td width=
"120">Run Test</td>
110 $run_test = array_get_index($settings,
'run_test', 0);
111 check_box($prefix.
'_run_test', 1, $run_test);
116 <td colspan=
"2">The test will be based on the request content in the
"SOAP Request Message" below</td>
123 if ($run_test && !empty($settings[
'test_results'])) {
124 foreach($settings[
'test_results'] as $soap_func => $info) {
125 echo
"<b><u>$soap_func</u></b><br /><br />";
126 echo
"<b>Request:</b><br />";
127 echo (nl2br(str_replace(
' ',
' ', htmlentities($info[
'request']))));
129 echo
"<b>Response:</b><br />";
130 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>
179 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_message'); ?></p>
181 <div
id=
"<?php echo $prefix ?>_response" style=
"padding: 0.5em 0px 2em 30px;">
182 <table
class=
"sq-backend-table" >
187 if(isset($settings[
'responses'][$settings[
'action']])) {
189 echo (nl2br(str_replace(
' ',
' ', htmlentities(str_replace(
'[ARRAY_ELEMENT]',
'', $settings[
'responses'][$settings[
'action']])))));
197 <?php echo translate(
'response_message_note'); ?>
205 <p
class=
"sq-backend-section-subheading">Check Response</p>
207 <div
id=
"<?php echo $prefix ?>_response_error" style=
"padding: 0.5em 0px 2em 30px;">
208 <table
class=
"sq-backend-table" >
212 $selected_fields = isset($settings[$settings[
'action'].
'_response_error_fields']) ? $settings[$settings[
'action'].
'_response_error_fields'] : Array();
213 if (empty($selected_fields)) {
214 echo
"No SOAP response fields selected";
217 <table
class=
"sq-backend-table">
219 <td
class=
"sq-backend-table-header"><?php echo translate(
'field_name'); ?></td>
220 <td
class=
"sq-backend-table-header"><?php echo translate(
'error_text'); ?></td>
221 <td
class=
"sq-backend-table-header"><?php echo translate(
'delete_question'); ?></td>
225 foreach ($selected_fields as $selected_field => $rule) {
226 $error_msg = array_get_index($rule,
'error_msg',
'');
227 $rule_value = array_get_index($rule,
'value',
'');
228 $rule_type = array_get_index($rule,
'type',
'must_contain');;
230 $sf_prefix = $prefix.
'_'.$settings[
'action'].
'_'.$selected_field;
233 <td
class=
"sq-backend-table-cell"><?php echo $selected_field; ?></td>
234 <td
class=
"sq-backend-table-cell">
239 combo_box($sf_prefix.
'_type', $rules, FALSE, $rule_type);
244 <td>Value</td><td><?php text_box($sf_prefix.
'_value', $rule_value, 40); ?></td>
247 <td>Error Message</td><td><?php text_box($sf_prefix.
'_error_msg', $error_msg, 110); ?></td>
252 <td
class=
"sq-backend-table-cell">
253 <?php check_box($sf_prefix.
'_delete_field['.$selected_field.
']'); ?>
265 echo translate(
'add_new_field');
266 $response_fields = Array(
'' =>
'-- Select Field --');
267 if (isset($settings[
'response_keywords'][$settings[
'action']])) {
268 $response_keywords = explode(
'<br/>', $settings[
'response_keywords'][$settings[
'action']]);
269 foreach($response_keywords as $val) {
270 $val = trim($val,
'%');
271 $val = substr_replace($val,
'', 0, strlen(
'globals_session_soap_'));
274 $response_fields[$val] = $val;
278 combo_box($prefix.
'_'.$settings[
'action'].
'_response_error_field', $response_fields, FALSE);
284 <td><?php translate(
'fail_validation_error_msg'); ?></td>
289 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_keywords'); ?></p>
291 <div
id=
"<?php echo $prefix ?>_response_keywords" style=
"padding: 0.5em 0px 2em 30px;">
292 <table
class=
"sq-backend-table" >
296 if(isset($settings[
'response_keywords'][$settings[
'action']])) {
298 echo ($settings[
'response_keywords'][$settings[
'action']]);
305 <td><?php echo translate(
'response_keyword_note'); ?></td>
308 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'response_to_download_as_file'); ?></p>
309 <table
class=
"sq-backend-table">
311 <td
class=
"sq-backend-table-header"><?php echo translate(
'field_keyword_tags'); ?></td>
314 $response_to_file = array_get_index($settings, $settings[
'action'].
'_file_response_to_save', Array());
315 $currently_configured = count($response_to_file);
317 foreach ($response_to_file as $i => $response) { ?>
321 text_box($prefix.
'_'.$settings[
'action'].
'_file_response_to_save['.$i.
']', $response, 50);
323 if (in_array($response, $settings[$settings[
'action'].
'_invalid_keywords_for_file'])) {
325 echo
"<span style=\"color:#FF0000\"><b> *invalid keyword</b></span>";
334 $count = $currently_configured++;
335 text_box($prefix.
'_'.$settings[
'action'].
'_file_response_to_save['.$count.
']',
'', 50);
340 <td><?php echo translate(
'response_to_download_as_file_note'); ?></td>
358 $settings[
'local_cert'] = isset($_POST[$prefix.
'_local_cert'][
'assetid']) ? $_POST[$prefix.
'_local_cert'][
'assetid']: NULL;
359 $settings[
'wsdl'] = array_get_index($_POST, $prefix.
'_wsdl', NULL);
360 $settings[
'login'] = array_get_index($_POST, $prefix.
'_login', NULL);
361 $settings[
'password'] = array_get_index($_POST, $prefix.
'_password', NULL);
362 $settings[
'mute_exceptions'] = array_get_index($_POST, $prefix.
'_mute_exceptions', NULL);
363 $settings[
'run_test'] = array_get_index($_POST, $prefix.
'_run_test', NULL);
364 $settings[
'passphrase'] = array_get_index($_POST, $prefix.
'_passphrase', NULL);
365 $settings[
'action'] = array_get_index($_POST, $prefix.
'_action', NULL);
369 $settings[
'before_submit'] = TRUE;
371 if(isset ($settings[
'wsdl']) && !empty($settings[
'wsdl'])) {
375 $client =
new SoapClient($settings[
'wsdl'], $options);
376 $functions = $client->__getFunctions();
377 $types = $client->__getTypes();
379 catch (Exception $e) {
380 trigger_error($e->getMessage());
383 if(!empty($functions)) {
384 foreach ($functions as $function) {
385 $function_name = preg_replace(
'/^\w+ (\w+)\(.*\)/',
'$1', $function);
386 $function_params = explode(
', ', preg_replace(
'/^\w+ \w+\((.*)\)/',
'$1', $function));
387 $function_response = preg_replace(
'/^(\w+) \w+\(.*\)/',
'$1', $function);
390 if(isset($function_list[$function_name]))
continue;
393 $parsed_params = Array();
394 foreach ($function_params as $param) {
395 if (!trim($param))
continue;
401 $function_list[$function_name] = $parsed_params;
405 if ($xml_response === TRUE || $xml_response === FALSE) {
407 $keywords =
'globals_session_soap'.($xml_response ?
'0' :
'');
413 $keywords_list[$function_name] = str_replace(
'[ARRAY_ELEMENT]',
'0', $keywords);
415 $settings[
'actions'] = $function_list;
416 $settings[
'responses'] = $response_list;
417 $settings[
'response_keywords'] = $keywords_list;
422 $current_selected_fields = isset($settings[$settings[
'action'].
'_response_error_fields']) ? $settings[$settings[
'action'].
'_response_error_fields'] : Array();
423 $field_rule = Array();
426 $keywords_string =
'';
427 if (isset($settings[
'response_keywords'])) {
428 $keywords_string = implode(
';',$settings[
'response_keywords']);
431 foreach ($current_selected_fields as $selected_field => $error_msg) {
432 $sf_prefix = $prefix.
'_'.$settings[
'action'].
'_'.$selected_field;
435 if ((!isset($_POST[$sf_prefix.
'_delete_field'][$selected_field]) || !$_POST[$sf_prefix.
'_delete_field'][$selected_field]) && strpos($keywords_string,
'%globals_session_soap_'.$selected_field.
'%') !== FALSE) {
436 if (isset($_POST[$sf_prefix.
'_error_msg'])) {
437 $field_rule[$selected_field] = Array(
438 'type' => $_POST[$sf_prefix.
'_type'],
439 'value' => $_POST[$sf_prefix.
'_value'],
440 'error_msg' => trim($_POST[$sf_prefix.
'_error_msg']),
443 $field_rule[$selected_field] = $rule;
449 if (isset($_POST[$prefix.
'_'.$settings[
'action'].
'_response_error_field']) && !empty($_POST[$prefix.
'_'.$settings[
'action'].
'_response_error_field'])) {
450 $new_field = $_POST[$prefix.
'_'.$settings[
'action'].
'_response_error_field'];
451 $field_rule[$new_field] = Array();
455 if(isset($settings[
'actions'][$settings[
'action']])) {
456 $settings[$settings[
'action'].
'_response_error_fields'] = $field_rule;
457 for($i = 0; $i < count($settings[
'actions'][$settings[
'action']]); $i++) {
458 if(isset($_POST[$prefix.
'_'.$settings[
'action'].
'parameters'.$i]))
459 $settings[$settings[
'action'].
'parameters'.$i] = $_POST[$prefix.
'_'.$settings[
'action'].
'parameters'.$i];
463 $settings[$settings[
'action'].
'_invalid_keywords_for_file'] = Array();
464 if (isset($settings[
'actions'][$settings[
'action']])) {
465 $save_file_response = array_get_index($_POST, $prefix.
'_'.$settings[
'action'].
'_file_response_to_save', Array());
466 foreach ($save_file_response as $index => $response_kwd) {
469 if (trim($response_kwd) ==
'') {
470 unset($save_file_response[$index]);
474 if (strpos($settings[
'response_keywords'][$settings[
'action']], $response_kwd) === FALSE) {
475 $settings[$settings[
'action'].
'_invalid_keywords_for_file'][] = $response_kwd;
478 $settings[$settings[
'action'].
'_file_response_to_save'] = $save_file_response;
482 $test_results = Array();
483 if ($settings[
'run_test']) {
484 foreach($functions as $function) {
485 $function_name = preg_replace(
'/^\w+ (\w+)\(.*\)/',
'$1', $function);
486 if($function_name != $settings[
'action'])
continue;
490 $settings[
'test_results'] = $test_results;
506 ?><table
class=
"no-borders">
513 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><strong><?php echo translate(
'action');?></strong></p></td>
514 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><?php
515 if (isset ($settings[
'action'])) {
516 echo $settings[
'action'];
518 ?><span
class=
"sq-backend-warning"><?php echo translate(
'no_soap_action');?></span><?php
521 if (!isset ($settings[$settings[
'action'].
'parameters0'])) {
522 ?><br/><span
class=
"sq-backend-warning"><?php echo translate(
'no_parameter');?></span><?php
546 if(!isset($form->submission_errors)) {
547 $form->submission_errors = Array();
550 if(!isset($settings[
'actions'][$settings[
'action']])) {
551 $form->submission_errors = array_merge($form->submission_errors, Array(translate(
'no_soap_action')));
554 if(!isset($settings[
'wsdl'])) {
555 $form->submission_errors = array_merge($form->submission_errors, Array(translate(
'no_wsdl')));
559 $function = $settings[
'action'];
560 $wsdl = $settings[
'wsdl'];
564 for($i = 0, $param = Array(); $i < count($settings[
'actions'][$settings[
'action']]); $i++) {
565 if(isset($settings[$settings[
'action'].
'parameters'.$i])) {
568 $object = @simplexml_load_string($soap_message,
'SimpleXMLElement', LIBXML_NOCDATA);
570 if($object === FALSE) {
584 foreach ($param as $index => $object) {
585 $eval_string .= $index == 0 ?
'' :
', ';
586 $eval_string .=
'$param['.$index.
']';
590 $options[
'trace'] = 1;
593 if ($settings[
'mute_exceptions']) {
594 $options[
'exceptions'] = 0;
599 $client =
new SoapClient($wsdl, $options);
600 eval(
'$data = $client->$function('.$eval_string.
');');
602 catch (Exception $e) {
604 $form->submission_errors = array_merge($form->submission_errors, Array($e->getMessage()));
608 if ($settings[
'mute_exceptions'] && get_class($data) ==
'SoapFault') {
609 $soap_response = $client->__getLastResponse();
612 if (preg_match(
'|<([^:]+:)?Body>(.*)</([^:]+:)?Body>|msi', $soap_response, $match)) {
613 $data = simplexml_load_string($match[2]);
618 $soap_response_keywords = Array();
619 $file_saving_keywords = array_get_index($settings, $settings[
'action'].
'_file_response_to_save', Array());
623 foreach($soap_response_keywords as $key => $val) {
624 $soap_response_keywords[substr_replace($key,
'', 0, 5)] = $val;
625 unset($soap_response_keywords[$key]);
628 if (!empty($settings[$settings[
'action'].
'_response_error_fields'])) {
629 foreach($settings[$settings[
'action'].
'_response_error_fields'] as $check_field => $rule) {
631 $form->submission_errors = array_merge($form->submission_errors, Array($rule[
'error_msg']));
651 if (empty($settings[
'wsdl'])) {
656 if (empty($settings[
'actions'])) {
661 if (!isset($settings[
'action'])) {
666 if (!isset ($settings[$settings[
'action'].
'parameters0'])) {