/** * Init form storage options * @param string $form */ protected function init_data($form) { if (in_array($form, $this->init_status)) { //already done return true; } if (!parent::init_data($form)) { return false; } if (!array_key_exists('svs', $this->namespaces[$form])) { $this->namespaces[$form]['svs'] = "svs:urn:ihe:iti:svs:2008"; } $options = $this->getStorageOptions($form); if (!$options instanceof I2CE_MagicDataNode) { I2CE::raiseError("Invalid storage options for {$form}"); return false; } $url = false; if (is_array($this->global_options) && array_key_exists('url', $this->global_options) && is_string($this->global_options['url']) && strlen($this->global_options['url']) > 0) { $url = $this->global_options['url']; } $options->setIfIsSet($url, "url", true); $curl_opts = array('HEADER' => 0); $cache_time = 0; if (is_array($this->global_options) && array_key_exists('cache_time', $this->global_options) && is_scalar($this->global_options['cache_time'])) { $cache_time = (int) $this->global_options['cache_time']; } $options->setIfIsSet($cache_time, "cache_time"); $cache_time = (int) $cache_time; $request_args = array(); if (array_key_exists('request_args', $this->global_options) && is_array($this->global_options['request_args'])) { $request_args = $this->global_options['request_args']; } $options->setIfIsSet($request_args, "request_args", true); $services = array('getRecords' => array('results' => '//svs:Concept/@id', 'url' => $url, 'request_args' => $request_args, 'cache_time' => $cache_time, 'transforms' => array('out' => '0')), 'getAllRecordData' => array('url' => $url, 'request_args' => $request_args, 'cache_time' => $cache_time, 'transforms' => array('out' => '0'))); foreach (array_keys($services) as $endpoint) { if (!array_key_exists($endpoint, $this->services[$form])) { $this->services[$form][$endpoint] = array(); } } foreach ($this->services[$form] as $endpoint => &$data) { if (!array_key_exists($endpoint, $services)) { continue; } I2CE_Util::merge_recursive($services[$endpoint], $data); $data = $services[$endpoint]; } unset($data); return true; }
/** * Init form storage options * @param string $form */ protected function init_data($form) { if (in_array($form, $this->init_status)) { //already done return true; } if (!parent::init_data($form)) { return false; } $options = $this->getStorageOptions($form); if (!$options instanceof I2CE_MagicDataNode) { I2CE::raiseError("Invalid storage options for {$form}"); return false; } $options = $this->getStorageOptions($form); if (!$options instanceof I2CE_MagicDataNode) { I2CE::raiseError("Invalid storage options for {$form}"); return false; } $directory = false; if (!$options->setIfIsSet($directory, 'csd_directory') || !in_array($directory, array('provider', 'service', 'facility', 'organization'))) { I2CE::raiseError("No valid defined for {$form}"); return false; } if (!is_array($remote_services = I2CE::getConfig()->getAsArray("/modules/forms/storage_options/CSD/remote_services")) || !array_key_exists($directory, $remote_services) || !is_scalar($selected = $remote_services[$directory])) { I2CE::raiseError("No remote service directory selected in global CSD options"); return false; } list($t_form, $id) = array_pad(explode('|', $selected, 2), 2, ''); if ($t_form != 'csd_info_manager' || $id == '0' || !is_array($urls = I2CE_FormStorage::lookupField('csd_info_manager', $id, array('url'), false)) || !array_key_exists('url', $urls) || !$urls['url']) { I2CE::raiseError("Invalid connection details from selected service: {$selected}"); } if (!array_key_exists('csd', $this->namespaces[$form])) { $this->namespaces[$form]['csd'] = "urn:ihe:iti:csd:2013"; } $cache_time = 0; if (is_array($this->global_options) && array_key_exists('cache_time', $this->global_options) && is_scalar($this->global_options['cache_time'])) { $cache_time = (int) $this->global_options['cache_time']; } $options->setIfIsSet($cache_time, "cache_time"); $cache_time = (int) $cache_time; if (!array_key_exists('populate', $this->services[$form])) { $this->services[$form]['populate'] = array(); } $populate = array('url' => $urls['url'], 'curl_opts' => array('HEADER' => 0, 'POST' => 1, 'HTTPHEADER' => array('content-type' => 'content-type: text/xml')), 'cache_time' => $cache_time); I2CE_Util::merge_recursive($this->services[$form]['populate'], $populate); return true; }
/** * Init form storage options * @param string $form */ protected function init_data($form) { if (in_array($form, $this->init_status)) { //already done return true; } if (!parent::init_data($form)) { return false; } if (!array_key_exists('csd', $this->namespaces[$form])) { $this->namespaces[$form]['csd'] = "urn:ihe:iti:csd:2013"; } $options = $this->getStorageOptions($form); if (!$options instanceof I2CE_MagicDataNode) { I2CE::raiseError("Invalid storage options for {$form}"); return false; } $directory = false; if (!$options->setIfIsSet($directory, 'csd_directory') || !in_array($directory, array('provider', 'service', 'facility', 'organization'))) { I2CE::raiseError("No valid defined for {$form}"); return false; } if (!is_array($this->global_options) || !array_key_exists('remote_services', $this->global_options) || !is_array($remote_services = $this->global_options['remote_services']) || !array_key_exists($directory, $remote_services) || !is_scalar($selected = $remote_services[$directory])) { I2CE::raiseError("No remote service directory selected in global CSD options"); return false; } list($t_form, $id) = array_pad(explode('|', $selected, 2), 2, ''); if ($t_form != 'csd_info_manager' || $id == '0' || !is_array($urls = I2CE_FormStorage::lookupField('csd_info_manager', $id, array('url', 'url_updating'), false)) || !array_key_exists('url', $urls) || !$urls['url'] || !array_key_exists('url_updating', $urls)) { I2CE::raiseError("Invalid connection details from selected service: {$selected}"); } $curl_opts = array('HEADER' => 0, 'POST' => 1, 'HTTPHEADER' => array('content-type' => 'content-type: text/xml')); if (is_array($auth = I2CE_FormStorage::lookupField('csd_info_manager', $id, array('user', 'password'), false)) && array_key_exists('user', $auth) && $auth['user']) { $curl_opts['USERPWD'] = $auth['password']; $curl_opts['USERAGENT'] = $auth['user']; } if (is_array($ssl = I2CE_FormStorage::lookupField('csd_info_manager', $id, array('ssl_version'), false)) && array_key_exists('ssl_version', $ssl) && $ssl['ssl_version']) { $curl_opts['SSLVERSION'] = $ssl['ssl_version']; $curl_opts['SSL_VERIFYPEER'] = false; $curl_opts['SSL_VERIFYHOST'] = false; //or 2? } $cache_time = 0; if (is_array($this->global_options) && array_key_exists('cache_time', $this->global_options) && is_scalar($this->global_options['cache_time'])) { $cache_time = (int) $this->global_options['cache_time']; } $options->setIfIsSet($cache_time, "cache_time"); $cache_time = (int) $cache_time; $updating = array('delete', 'create', 'update'); $reading = array('getRecords', 'populate'); foreach ($reading as $endpoint) { if (!array_key_exists($endpoint, $this->services[$form])) { $this->services[$form][$endpoint] = array(); } } if ($urls['url_updating']) { foreach ($updating as $endpoint) { if (!array_key_exists($endpoint, $this->services[$form])) { $this->services[$form][$endpoint] = array(); } } } foreach ($this->services[$form] as $endpoint => &$data) { if (in_array($endpoint, $updating)) { if ($urls['url_updating']) { $data['url'] = $urls['url_updating']; } } else { if ($urls['url']) { $data['url'] = $urls['url']; } } I2CE_Util::merge_recursive($data['curl_opts'], $curl_opts); if ($cache_time && in_array($endpoint, $reading) && !array_key_exists('cache_time', $data)) { $data['cache_time'] = $cache_time; } } return true; }