public function __construct($args, $request_remainder, $get = null, $post = null) { if (array_key_exists('csd_cache', $args)) { $csd_args = self::getCSDArgs($args['csd_cache']); I2CE_Util::merge_recursive($csd_args, $args); parent::__construct($csd_args, $request_remainder, $get, $post); } else { parent::__construct($args, $request_remainder, $get, $post); } }
public function __construct($page, $primaryObject, $options = array()) { $this->primaryObject = $primaryObject; $this->page = $page; $this->template = $this->page->getTemplate(); if (!is_array($options)) { $options = array(); } $def_options = $this->getDefaultOptions(); I2CE_Util::merge_recursive($def_options, $options); $this->options = $this->postProcessOptions($def_options); }
/** * 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; }
/** * Recursive method to rraverse the class hierarchy to get the meta data for the form magic data * @param string $class the form class * @param array &$data array */ protected function getAttributeData($class, &$attr) { if (!empty($class) && $class != 'I2CE_Form') { //suppose this form has inheritince: I2CE_FormB extends I2CE_FormA extends I2CE_Form //calling recusrively at the beginning means that for a field, $field //we start at I2CE_Form and look for field data for $field //next we look at I2CE_FormA and look for field data for $field and overwrite anything from I2CE_Form with merge recrusive //next we look at I2CE_FormB and look for field data for $field and overwrite anything from I2CE_Form and I2CE_FormA with merge recrusive $this->getAttributeData(get_parent_class($class), $attr); } $classAttr = array(); if (I2CE::getConfig()->setIfIsSet($classAttr, "/modules/forms/formClasses/{$class}/meta", true)) { I2CE_Util::merge_recursive($attr, $classAttr); } }
/** * Return the given value for the key in one of the request arrays. * @param mixed $key * @return mixed */ public function request($key = null) { if (!is_array($this->request_vars)) { $this->request_vars = $this->session_req(); I2CE_Util::merge_recursive($this->request_vars, $this->get()); I2CE_Util::merge_recursive($this->request_vars, $this->post()); } if ($key === null) { return $this->request_vars; } else { if (is_scalar($key)) { if (array_key_exists($key, $this->request_vars)) { return $this->request_vars[$key]; } else { return null; } } else { if (is_array($key)) { $vars = $this->request_vars; foreach ($key as $k) { if (!is_array($vars) || !array_key_exists($k, $vars)) { return null; } $vars = $vars[$k]; } return $vars; } } } }
/** * Gets the page assoicated with a module * @param string $module * @param string $page * @param array $request_remainder of string... anything that would be a part of the remainder of the URL * @param array $args an array of page arguments. Defaults to the empty array. Overwrites anything found in config for the page style or page */ public function getPage($module, $page, $request_remainder = array(), $args = array(), $get = null, $post = null) { $mod_factory = I2CE_ModuleFactory::instance(); if (!$mod_factory->exists($module)) { I2CE::raiseError("Cannot request the page {$page} for module {$module}. The module is not present", E_USER_ERROR); return; } if (!$mod_factory->isEnabled($module)) { I2CE::raiseError("Cannot request the page {$page} for module {$module}. The module is not enabled", E_USER_ERROR); return; } $storage = I2CE::getConfig(); if ($module == 'I2CE') { $storage = $storage->I2CE; } else { $storage = $storage->modules->{$module}; } if (!$this->command_line) { $pageType = 'page'; } else { $pageType = 'command_line'; } $pageStylesInfo = I2CE::getConfig()->traverse("/I2CE/template/{$pageType}_styles"); if (!isset($storage->{$pageType}) || !isset($storage->{$pageType}->{$page})) { //check to see if there is a default page registered: $default_page = ""; $storage->setIfIsSet($default_page, "{$pageType}_default"); if (empty($default_page) || !isset($storage->{$pageType}->{$default_page})) { I2CE::raiseError("The requested {$pageType} ({$page}) for the module {$module} is not present at: " . $storage->getPath(false), E_USER_ERROR); return; } $page = $default_page; } $pageInfo = $storage->{$pageType}->{$page}; $pageArgs = array(); $pageInfo->setIfIsSet($pageArgs, 'args', true); $pageClass = null; $pageInfo->setIfIsSet($pageClass, 'class'); $style = null; $pageInfo->setIfIsSet($style, 'style'); $checked = array(); $execParams = array(); $pageInfo->setIfIsSet($execParams, 'execution_parameters', true); while ($style) { //start from the top-level style for the page and //backtrack throuhg all the lowe levels styles getting any args for the page and //storing them in $pageArgs //the top-level styles should overwrite the lower lower styles. if (!$pageStylesInfo->is_parent($style)) { $style = ''; continue; } $styleInfo = $pageStylesInfo->traverse($style); if (!$pageClass) { $styleInfo->setIfIsSet($pageClass, 'class'); } $t_execParams = array(); if ($styleInfo->setIfIsSet($t_execParams, 'execution_parameters')) { I2CE_Util::merge_recursive($t_execParams, $pageArgs); $execParams = $t_execParams; } $t_args = array(); if ($styleInfo->setIfIsSet($t_args, 'args', true)) { //$t_Args are the lower level args. they need to be ovewritten by //what is in pageArgs I2CE_Util::merge_recursive($t_args, $pageArgs); $pageArgs = $t_args; } $style = ''; if ($styleInfo->setIfIsSet($style, 'style')) { if ($style && array_key_exists($style, $checked) && $checked[$style]) { $style = null; } } } if (!$pageClass) { I2CE::raiseError("Cannot find a class associated to the requested page {$page} for the module {$module}", E_USER_ERROR); return; } if (!class_exists($pageClass)) { I2CE::raiseError("Cannot find the class ({$pageClass}) for the requested page {$page} for the module {$module}", E_USER_ERROR); return; } foreach ($execParams as $key => $val) { ini_set($key, $val); } return new $pageClass($pageArgs, $request_remainder, $get, $post); }
protected function loadMDTemplate($doc, $transform = false, $erase = false) { //doc is either a file name or a DOMDocument if ($transform) { //transform if (is_string($doc)) { $file = $doc; $doc = new DOMDocument(); if (!($contents = file_get_contents($file))) { $this->userMessage("Could not load source file"); return false; } if (!$doc->loadXML($contents)) { $this->userMessage("Could not load file source contents"); return false; } } if (!$doc instanceof DOMDocument) { $this->userMessage("Could not load xml into document"); return false; } $proc = new XSLTProcessor(); $xslt_doc = new DOMDocument(); if (!$xslt_doc->loadXML($transform)) { $this->userMessage("Could not load transform: " . $_FILES['xsl']['name']); return false; } if (!$proc->importStylesheet($xslt_doc)) { $this->userMessage("Could not import style sheet"); return false; } $trans_doc = new DOMDocument('1.0', 'UTF-8'); $trans_doc->appendChild($trans_doc->importNode($doc->documentElement, true)); if (($trans_out = $proc->transformToXML($trans_doc)) === false) { $this->userMessage("Could not transform accoring to xsl"); return false; } } else { $trans_doc = $doc; } if ($trans_doc instanceof DOMDocument) { $temp_file = tempnam(sys_get_temp_dir(), 'MDN_UPLOAD'); if (!file_put_contents($temp_file, $trans_out)) { $this->userMessage("Could not save transformed files"); return false; } } else { $temp_file = $trans_doc; } $template = new I2CE_MagicDataTemplate(); $template->setVerboseErrors(true); if (!$template->loadRootFile($temp_file)) { I2CE::raiseError("Unable to load transformed file as Magic Data"); $this->userMessage("Unable to load transformed file as Magic Data"); return false; } if (!$template->validate()) { I2CE::raiseError("Unable to validate transformed file as Magic Data"); $this->userMessage("Unable to validate transformed file as Magic Data"); return false; } $store = new I2CE_MagicDataStorageMem(); $mem_config = I2CE_MagicData::instance("mdn_load"); $mem_config->addStorage($store); $nodeList = $template->query("/configurationGroup"); if (!$nodeList instanceof DOMNodeList || $nodeList->length == 0) { $nodeList = $template->query("/I2CEConfiguration/configurationGroup"); //perhaps we really need to do something more if this is a module } foreach ($nodeList as $configNode) { $locale = false; $status = $template->getDefaultStatus(); if ($configNode->hasAttribute('locale')) { $locale = $configNode->getAttribute('locale'); } $vers = '0'; if ($template->setConfigValues($configNode, $mem_config, $status, $vers) === false) { I2CE::raiseError("Could not load configuration values"); $this->userMessage("Could not load configuration values"); return false; } } //I2CE::raiseError(print_r($mem_config->getAsArray(),true)); if ($erase) { $this->config->eraseChildren(); } $merges = $template->getMerges(); foreach ($merges as $path => $merge) { if ($this->config->is_scalar($path)) { I2CE::raiseError("Trying to merge arrays into {$path} where target is scalar valued. Skipping"); continue; } if ($mem_config->is_scalar($path)) { I2CE::raiseError("Trying to merge arrays into {$path} where source is scalar valued. Skipping"); continue; } $old_arr = $this->config->getAsArray($path); $new_arr = $mem_config->getAsArray($path); $mem_config->__unset($path); if (!is_array($old_arr)) { //in case the target did not exist $old_arr = array(); } if (!is_array($new_arr)) { //in case no values were set for the source $new_arr = array(); } switch ($merge) { case 'uniquemerge': $new_arr = I2CE_Util::array_unique(array_merge($old_arr, $new_arr)); break; case 'merge': $new_arr = array_merge($old_arr, $new_arr); break; case 'mergerecursive': I2CE_Util::merge_recursive($old_arr, $new_arr); $new_arr = $old_arr; break; } $this->config->__unset($path); $this->config->{$path} = $new_arr; } //we took care of all array merges. anything that is left is an overwrite. foreach ($mem_config as $k => $v) { if (is_scalar($v) && $mem_config->is_translatable($k) && !$this->config->is_parent($k)) { $this->config->setTranslatable($k); $translations = $mem_config->traverse($k, true, false)->getTranslations(); foreach ($translations as $locale => $trans) { if (strlen($trans) == 0) { continue; } $this->config->setTranslation($locale, $trans, $k); } } else { $this->config->{$k}->setValue($v, null, false); } if ($this->config->{$k} instanceof I2CE_MagicDataNode) { //free up some memory. $this->config->{$k}->unpopulate(true); } } return true; }
/** * returns an array of the default display options. Default options are read and overriddenb * in the following order: * /modules/CustomReports/displays/$display/display_options * /modules/CustomReports/relationships/display_options/$display * /modules/CustomReports/reports/display_options/$display * /modules/CustomReports/reportViews/$view/display_options/$display * Finally any options that have a key in $get are replaced by that value * @param array $get * @param array $options. Default to the empty array. The options that we want to be already set before we start goinng through * @returns mixed array or false on failure */ protected function getDefaultOptions($get, $options = array()) { //make sure we can overide the following options which may come from the $get varaible. $make_exist = array('limit_paginated', 'limit_page', 'limit_per_page', 'limit_offset', 'limit_amount', 'sort_order', 'display_order', 'total', 'save_options_as_default_view'); foreach ($make_exist as $key) { if (!array_key_exists($key, $options)) { $options[$key] = null; } } $check = array("/modules/CustomReports/default_display_options" => I2CE::getConfig(), "/modules/CustomReports/displays/{$this->display}/display_options" => I2CE::getConfig(), 'default_display_options' => $this->relationshipConfig, "display_options/{$this->display}" => $this->relationshipConfig, 'default_display_options' => $this->reportConfig, "display_options/{$this->display}" => $this->reportConfig, 'default_display_options' => $this->config, "display_options/{$this->display}" => $this->config); // I don't know if this is the right way to do this or not. // I'm guessing probably not, but for a new report I added no other options were set // so maybe the edit needs to change to save the data elsewhere. $this->config->setIfIsSet($options['total'], "total"); foreach ($check as $k => $node) { $t_options = array(); if ($node->setIfIsSet($t_options, $k, true)) { I2CE_Util::merge_recursive($options, $t_options); } } //now look at the get variables I2CE_Util::merge_recursive($options, $get, true, false); //add new keys but not the empty ones //finally load some limiting stuff from get variables that not have been set in the default options above. //and convert it over to the nested if (!array_key_exists('nested_limits', $options) || !is_array($options['nested_limits'])) { $options['nested_limits'] = array(); } if (array_key_exists('limits', $get) && is_array($get['limits'])) { // Override the default limits if there are any in the POST // This is to fix issues with multiple selection boxes where // nothing is in the POST for those variables so it's impossible // to clear the defaults. $options['nested_limits'] = $get['limits']; /* foreach ( $get['limits'] as $field => $limit ) { $options['nested_limits'][$field] = $limit; } */ /* I2CE_Util::merge_recursive($options['nested_limits'],$get['limits'],true,false); //add new keys but not the empty ones */ } return $options; }
protected static function storeModuleMagicData($shortname, $old_vers, $new_vers, $mod_configurator, $imported) { $mod_storage = $mod_configurator->getStorage(); if (!$mod_storage instanceof I2CE_MagicDataNode) { I2CE::raiseError("Expecting magic data"); return false; } //processconfig data $storage = I2CE::getConfig(); $merges = $mod_configurator->getMerges(); foreach ($merges as $path => $merge) { if ($storage->is_scalar($path)) { I2CE::raiseError("Trying to merge arrays into {$path} where target is scalar valued. Skipping"); continue; } if ($mod_storage->is_scalar($path)) { I2CE::raiseError("Trying to merge arrays into {$path} where source is scalar valued. Skipping"); continue; } $old_arr = $storage->getAsArray($path); $new_arr = $mod_storage->getAsArray($path); $mod_storage->__unset($path); if (!is_array($old_arr)) { //in case the target did not exist $old_arr = array(); } if (!is_array($new_arr)) { //in case no values were set for the source $new_arr = array(); } switch ($merge) { case 'uniquemerge': $new_arr = I2CE_Util::array_unique(array_merge($old_arr, $new_arr)); break; case 'merge': $new_arr = array_merge($old_arr, $new_arr); break; case 'mergerecursive': I2CE_Util::merge_recursive($old_arr, $new_arr); $new_arr = $old_arr; break; } $storage->__unset($path); $storage->{$path} = $new_arr; } //we took care of all array merges. anything that is left is an overwrite. foreach ($mod_storage as $k => $v) { if ($k == 'config') { //don't update config info that might be here. It's handled below. continue; } if (is_scalar($v) && $mod_storage->is_translatable($k) && !$storage->is_parent($k)) { $storage->setTranslatable($k); $translations = $mod_storage->traverse($k, true, false)->getTranslations(); foreach ($translations as $locale => $trans) { if (strlen($trans) == 0) { continue; } $storage->setTranslation($locale, $trans, $k); } } else { $storage->{$k}->setValue($v, null, false); } if ($storage->{$k} instanceof I2CE_MagicDataNode) { //free up some memory. $storage->{$k}->unpopulate(true); } } $storage->config->status->config_processed->{$shortname} = $new_vers; //set the config data as processed if (isset($storage->config->status->initialized->{$shortname})) { $storage->config->status->initialized->{$shortname} = 1; //set the config data as processed } foreach ($imported as $locale => &$data) { unset($data['old_vers']); } $storage->config->status->localized->{$shortname} = $imported; return true; }
protected function call_service($form, $endpoint, $payload = false, $request_args = array()) { if (!$this->init_data($form)) { I2CE::raiseError("Could not initialize service data for {$form}"); return false; } $args = $this->services[$form][$endpoint]; $url = $args['url']; if (array_key_exists('request_args', $args) && is_array($args['request_args'])) { I2CE_Util::merge_recursive($request_args, $args['request_args']); } if (!$this->has_service($form, $endpoint)) { I2CE::raiseError("No service details defined for {$endpoint}:" . print_r($this->services, true)); return false; } //check to see if the repsponse is cached: $curl_opts = array(); if (array_key_exists('curl_opts', $args) && is_array($args['curl_opts'])) { $curl_opts = $args['curl_opts']; } if (is_array($request_args) && count($request_args) > 0 && ($append = http_build_query($request_args))) { if (strpos($url, '?') > 0) { $sep = '&'; } else { $sep = '?'; } $url .= $sep . $append; } $this->last_cache_key = false; $cache_time = 0; if (function_exists('apc_fetch')) { $this->last_cache_key = 'FS_Service_(' . $form . ')_' . get_class($this) . '_' . md5($url . $payload . print_r($curl_opts, true)); $success = false; $out = apc_fetch($this->last_cache_key, $success); if ($success) { I2CE::raiseError("Got cached {$endpoint} for {$form}:" . $out); return $out; } if (array_key_exists('cache_time', $this->services[$form][$endpoint])) { $cache_time = (int) $this->services[$form][$endpoint]['cache_time']; } } I2CE::raiseError("Service at {$url}"); if (!is_resource($ch = curl_init($url))) { I2CE::raiseError("Could not create curl resource"); return false; } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $excludes = array('RETURNTRANSFER', 'INFILE', 'FILE'); if ($payload) { $excludes[] = 'POSTFIELDS'; curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); I2CE::raiseError("Sending payload to {$url}:\n{$payload}"); } foreach ($curl_opts as $opt => $val) { $opt = strtoupper($opt); if (in_array($opt, $excludes) || ($opt_code = @constant('CURLOPT_' . $opt)) === null) { continue; } if (!curl_setopt($ch, $opt_code, $val)) { I2CE::raiseError("Could not set option {$opt}"); return false; } } $curl_out = curl_exec($ch); if ($err = curl_errno($ch)) { I2CE::raiseError("Curl response error ({$err}) on endpoint {$endpoint} of {$form}:\n" . curl_error($ch)); return false; } curl_close($ch); I2CE::raiseError("From {$url} Reveived:[" . $curl_out . "]"); if ($this->last_cache_key && $cache_time) { //already check above that apc is here. apc_store($this->last_cache_key, $curl_out, $cache_time); I2CE::raiseError("Caching {$endpoint} result of {$form} for {$cache_time}"); } return $curl_out; }
/** * Process values for a config node * @param DOMNode $configNode * @param I2CE_MagicDataNode $data * @param array $status. If null, it defaults to the array set by getDefaultStatus(). The current status (of parent node) * @param string $version . Defaults to '0' . The version of the currently loaded data in $storage responsible for this XML * @param array of string $paths -- the current path into the $storage that we are using. Defaults to the empty array(). * @returns boolean. true on sucess */ public function processValues($configNode, $storage, $status = null, $vers, $paths) { if (!$configNode instanceof DOMNode) { $this->raiseError("Did not receive configuration node"); return false; } //deal with any erase Information if (!$this->updatePaths($configNode, $paths)) { return false; } $this->processErasers($configNode, $paths); if ($status === null) { $status = $this->getDefaultStatus(); } if ($configNode->hasAttribute('path')) { //check to see if there is an explicit path set $path = $configNode->getAttribute('path'); $hasPath = true; } else { $path = $configNode->getAttribute('name'); $hasPath = false; } if (strlen($path) === 0) { $this->raiseError("configuration has empty path at " . $storage->getPath()); return false; } if ($configNode->hasAttribute('type')) { $valueType = strtolower(trim($configNode->getAttribute("type"))); } else { $valueType = 'string'; } if ($valueType == 'delimited') { // Delimited types really only make sense as many values $valueValues = 'many'; } elseif ($configNode->hasAttribute('values')) { $valueValues = strtolower(trim($configNode->getAttribute("values"))); } else { $valueValues = 'single'; } $uniquemerge = null; if (array_key_exists('uniquemerge', $status)) { $uniquemerge = $status['uniquemerge']; unset($status['uniquemerge']); } $valStatus = $this->processStatus($configNode, $status, $vers); if (array_key_exists('uniquemerge', $valStatus)) { //the uniquemerge status has been set on explicitly this node. //do nothing } else { //the unique merge status has not been set on this node. //if this node is a values='many' values='string' make it a default merge if ($valueValues == 'many' && $valueType == 'string') { $valStatus['uniquemerge'] = true; } else { if ($uniquemerge !== null) { $valStatus['uniquemerge'] = $uniquemerge; } } } if (!$valStatus['overwrite']) { return true; } $valueList = $this->query("./value", $configNode); if ($valueList->length == 0) { if ($valStatus['required'] === true) { $this->raiseError("Required value is not set at " . $this->getConfigPath($configNode)); return false; } else { //not required so let's return return true; } } $processor = 'processValues_' . $valueType . '_' . $valueValues; $vals = null; $encoding = null; if ($valueValues == 'single') { if ($valueList->item(0) instanceof DOMElement) { //item 0 should exist by the check/return above $vals = $this->{$processor}(trim($valueList->item(0)->textContent), $valStatus); } } else { $vals = array(); for ($k = 0; $k < $valueList->length; $k++) { if ($valueList->item($k) instanceof DOMElement) { $vals[$k] = trim($valueList->item($k)->textContent); } } $vals = $this->{$processor}($vals, $valStatus); if (!is_array($vals)) { $this->raiseError("Expected array to be returned from {$processor}() while evaluating " . $this->getConfigPath($configNode)); return false; } } if ($valStatus['required'] === true && ($valueValues == 'single' && $vals === null || $valueValues == 'many' && count($vals) == 0)) { $this->raiseError("Required value is not set at " . $this->getConfigPath($configNode) . ' in the module ' . $this->query("/I2CEConfiguration")->item(0)->getAttribute('name')); return false; } $validator = 'validateValues_' . $valueType . '_' . $valueValues; if ($this->_hasMethod($validator)) { $validate = $this->{$validator}($vals, $valStatus); if ($validate !== null) { $this->raiseError("Invalid data at " . $this->getConfigPath($configNode) . " + " . $validate); return false; } } $locale = null; if (array_key_exists('locale', $valStatus) && $valStatus['locale']) { //this node is translatable. $locale = $valStatus['locale']; } if ($valStatus['uniquemerge'] && $valueValues == 'many') { if ($storage->is_scalar($path)) { $this->raiseError("Trying to set non-scalar value at scalar valued (uniquemerge):\n" . $storage->getPath() . '/' . $path); return false; } $valStorage = $this->traversePaths($storage, $paths); if (!$valStorage instanceof I2CE_MagicDataNode) { return false; } $old_vals = $valStorage->getAsArray(null, $locale); $valStorage->eraseChildren($locale); $vals = I2CE_Util::array_unique(array_merge($old_vals, $vals)); } else { if ($valStatus['mergerecursive'] && $valueValues == 'many') { if ($storage->is_scalar($path)) { $this->raiseError("Trying to set non-scalar value at scalar valued (mergerecursive):\n" . $storage->getPath() . '/' . $path); return false; } $valStorage = $this->traversePaths($storage, $paths); if (!$valStorage instanceof I2CE_MagicDataNode) { return false; } $old_vals = $valStorage->getAsArray(null, $locale); $valStorage->eraseChildren($locale); I2CE_Util::merge_recursive($old_vals, $vals); $vals = $old_vals; } else { if ($valStatus['merge'] && $valueValues == 'many') { if ($storage->is_scalar($path)) { $this->raiseError("Trying to set non-scalar value at scalar valued (merge):\n" . $storage->getPath() . '/' . $path); return false; } $valStorage = $this->traversePaths($storage, $paths); if (!$valStorage instanceof I2CE_MagicDataNode) { return false; } $old_vals = $valStorage->getAsArray(null, $locale); $valStorage->eraseChildren($locale); $vals = array_merge($old_vals, $vals); } else { if (is_array($vals) && $storage->is_scalar($path)) { $this->raiseError("Trying to set non-scalar value at scalar valued:\n" . $storage->getPath() . '/' . $path); return false; } $valStorage = $this->traversePaths($storage, $paths); if (!$valStorage instanceof I2CE_MagicDataNode) { return false; } } } } $merges = array('merge', 'mergerecursive', 'uniquemerge'); foreach ($merges as $merge) { if (!array_key_exists($merge, $valStatus) || !$valStatus[$merge]) { continue; } $this->merges[$valStorage->getPath(false)] = $merge; } //only one merge status can be set, notice above that unqiuemerge takes presedence over mergerecursive which takes presidents over mergere $valStorage->setValue($vals, $locale, false); if (array_key_exists('binary', $valStatus)) { $this->setAttributeOnChildren('binary', $valStatus['binary'], $valStorage, $vals); } if (array_key_exists('encoding', $valStatus)) { $this->setAttributeOnChildren('encoding', $valStatus['encoding'], $valStorage, $vals); } return true; }
/** * Add a date picker to the page * @param mixed $obj. Either I2CE_Page or I2CE_Template * @param string $class. The html class to create the date picker on. * @param array $args. Defaults to the empty array. Array of options to pass to the datepicker object * */ public function addDatePicker($obj, $class, $args = array()) { if ($obj instanceof I2CE_Page) { $template = $obj->getTemplate(); } else { if ($obj instanceof I2CE_Template) { $template = $obj; } else { I2CE::raiseError("Unexpected"); return; } } if (!is_string($class) || strlen($class) == 0) { I2CE::raiseError("Invalid node id when adding date picker"); return; } //Date picker takes any mootools selector, but I want to enforce that it is an id $var_name = "DP_" . $class; $class = '.' . $class; if (!is_array($args)) { I2CE::raiseError("Invalid constructor arguments passed to the date picker"); $args = array(); } if (!is_array($options = I2CE::getConfig()->getAsArray("/modules/DatePicker/options"))) { $options = array(); } I2CE_Util::merge_recursive($options, $args, true, false); $onSelect = false; if (!array_key_exists('onSelect', $args) || !is_scalar($args['onSelect']) || !$args['onSelect']) { $onSelect = "function(d) { if (this.hasAttribute('onchange')) { eval(this.getAttribute('onchange'));}}"; unset($args['onSelect']); } else { $onSelect = $args['onSelect']; unset($args['onSelect']); } $onShow = false; if (!array_key_exists('onShow', $args) || !is_scalar($args['onShow']) || !$args['onShow']) { $onShow = "function(d) { if (this.hasAttribute('onclick')) { eval(this.getAttribute('onchange'));}}"; unset($args['onShow']); } else { $onShow = $args['onShow']; unset($args['onShow']); } $options = json_encode($args); if (($pos = strrpos($options, '}')) !== false) { $options = substr($options, 0, $pos); if ($onSelect) { $options .= ' , "onSelect": ' . $onSelect; } if ($onShow) { $options .= ' , "onShow": ' . $onShow; } $options .= '}'; } $this->date_pickers[$class] = $var_name . " = new DatePicker( '" . addslashes($class) . "'," . $options . ');'; }
public function getURLQueryString($additional = array(), $remove = array()) { $options = $this->stored_options; foreach ($remove as $rem) { $keys = explode(':', $rem); if (count($keys) === 0) { continue; } $t_options =& $options; $p_options = false; $p_key = false; foreach ($keys as $key) { if (!array_key_exists($key, $t_options)) { break 2; } if (!is_array($t_options)) { break 2; //trying to set array value on a a scalar node } $p_key = $key; $p_options =& $t_options; $t_options =& $t_options[$key]; } unset($p_options[$p_key]); } foreach ($additional as $add => $val) { $keys = explode(':', $add); if (count($keys) == 0) { continue; } $t_options =& $options; foreach ($keys as $key) { if (!is_array($t_options)) { break 2; //trying to set array value on a a scalar node } $t_options =& $t_options[$key]; } if (is_array($val)) { if (!is_array($t_options)) { $t_options = array(); } I2CE_Util::merge_recursive($t_options, $val); } else { $t_options = $val; } } if (is_scalar($options) || is_array($options) && count($options) > 0) { return '?i2ce_json[]=' . urlencode(json_encode(array('swissFactory' => array('options' => $options)))); } else { return ''; } }
/** * 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; }
public function paginateList($list, $qry_fields = array(), $jumper_id = 'select_list', $page_size = 50) { if ($this->page->module() == 'I2CE') { $url = $this->page->page(); } else { $url = $this->page->module() . '/' . $this->page->page(); } $url .= '/view'; $page_size = (int) $page_size; if ($page_size <= 0) { $page_size = 50; } $total_pages = max(1, ceil(count($list) / $page_size)); $pageVar = 'page'; if ($jumper_id != 'select_list') { $pageVar = $jumper_id . '_page'; } if ($total_pages > 1) { $page_no = (int) $this->page->request($pageVar); $page_no = min(max(1, $page_no), $total_pages); $offset = ($page_no - 1) * $page_size; $list = array_slice($list, $offset, $page_size, true); I2CE_Util::merge_recursive($qry_fields, $this->page->request()); foreach (array($pageVar) as $key) { if (array_key_exists($key, $qry_fields)) { unset($qry_fields[$key]); } } $this->page->makeJumper($jumper_id, $page_no, $total_pages, $url, $qry_fields, $pageVar); } return $list; }
/** * Sets up the flash chart options in $this->chart * @returns boolean. True on success */ protected function setupFlashChart(&$defaultOptions) { $type = $defaultOptions['displayFieldsType']; $displayFields = $defaultOptions['displayFields']; I2CE_Util::merge_recursive($defaultOptions['displayFields'], $defaultOptions['displayFieldsTypes'][$type]); $data = array(); $data['title']['text'] = $this->config->display_name; $data['elements'] = array(); $style = false; $style = $defaultOptions['style']; $this->chart = array(); if (array_key_exists('global_chart_options', $defaultOptions) && is_array($defaultOptions['global_chart_options'])) { $this->chart = $defaultOptions['global_chart_options']; } I2CE_Util::merge_recursive($this->chart, $defaultOptions['styles'][$style]['chart_options']); $this->displayedChartFields = array(); foreach ($defaultOptions['displayFields'] as $index => $data) { if (!is_numeric($index)) { continue; } if (array_key_exists('aggregate', $data) && $data['aggregate']) { $this->displayedChartFields[intval($index)] = $data['formfield'] . '+' . $data['aggregate']; } else { $this->displayedChartFields[intval($index)] = $data['formfield']; } } if (substr($type, 0, 7) == 'one_row') { $this->displayedChartFieldsIndex = array(); if (count($this->displayedChartFields) != 2 || !array_key_exists(0, $this->displayedChartFields) || !array_key_exists(1, $this->displayedChartFields)) { I2CE::raiseError("Innappropriate index (!=2) for charted fields. Slicing down to 2. Fix this better!: " . implode(',', array_keys($this->displayedChartFields))); $this->displayedChartFields = array_slice($this->displayedChartFields, 0, 2); } } else { if (substr($type, 0, 9) == 'multi_row') { $this->displayedChartFieldsIndex = array(0 => array(), 1 => array()); if (count($this->displayedChartFields) != 3 || !array_key_exists(0, $this->displayedChartFields) || !array_key_exists(1, $this->displayedChartFields) || !array_key_exists(2, $this->displayedChartFields)) { I2CE::raiseError("Innappropriate index (!=3) for charted fields. Slicing down to 3. Fix this better! :" . implode(',', array_keys($this->displayedChartFields))); $this->displayedChartFields = array_slice($this->displayedChartFields, 0, 3); } } else { I2CE::raiseError("Dont know how to display fields with type: {$type}"); return false; } } return true; }
/** * Adds the form data at the specified position on the current page. * @param int $left_x * @param int $top_y * @param array $formData of I2CE_Form * @param array $textProps * @returns boolean. True on success */ protected function addForm($left_x, $top_y, $formData, $textProps) { if (!$this->stdConfig->is_parent("elements")) { I2CE::raiseError("No elements in printed form"); return false; } $keys = $this->stdConfig->elements->getKeys(); sort($keys); foreach ($keys as $key) { if (!$this->stdConfig->elements->is_parent($key)) { I2CE::raiseError("bad key: {$key} at" . $this->stdConfig->elements->getPath(false)); continue; } $elementConfig = $this->stdConfig->elements->{$key}; $type = false; if ($elementConfig->setIfIsSet($type, "type") && $type && $elementConfig->is_parent("definition")) { $e_textProps = $textProps; if ($elementConfig->is_parent("text_properties")) { I2CE_Util::merge_recursive($e_textProps, $elementConfig->getAsArray("text_properties")); } $this->validateTextProps($e_textProps); $method = 'processElement_' . $type; if (!$this->_hasMethod($method)) { I2CE::raiseError("Do not know how to process {$type}"); return false; } if (!$this->{$method}($left_x, $top_y, $formData, $e_textProps, $elementConfig->definition)) { return false; } } } return true; }
/** * Sets up the visualization options * @param array &$defaultOptions * @return boolean */ protected function setupVisualization(&$defaultOptions) { $type = $defaultOptions['displayFieldsType']; $displayFields = $defaultOptions['displayFields']; I2CE_Util::merge_recursive($defaultOptions['displayFields'], $defaultOptions['displayFieldsTypes'][$type]); $style = $defaultOptions['style']; $tqx = array(); if ($this->page->request_exists('tqx')) { $tqx_req = $this->page->request('tqx'); $pairs = explode(';', $tqx_req); foreach ($pairs as $pair) { list($key, $val) = explode(':', $pair, 2); $tqx[$key] = $val; } } $this->data = array('version' => '0.6', 'reqId' => array_key_exists('reqId', $tqx) ? $tqx['reqId'] : '', 'sig' => array_key_exists('sig', $tqx) ? $tqx['sig'] : '', 'status' => 'ok', 'table' => array('cols' => array(), 'rows' => array(), 'p' => array())); $this->data['table']['p']['title'] = $this->config->display_name; $this->data['table']['p']['description'] = $this->config->description; $this->data['table']['p']['limit_text'] = $this->getReportLimitsDescription(); $this->visualizedFields = array(); foreach ($defaultOptions['displayFields'] as $index => $data) { if (!is_numeric($index)) { continue; } if (array_key_exists('aggregate', $data) && $data['aggregate']) { $this->visualizedFields[intval($index)] = $data['formfield'] . '+' . $data['aggregate']; } else { $this->visualizedFields[intval($index)] = $data['formfield']; } } return true; }