/**
  * method to intialize temporary upload table
  * @returns boolean
  */
 protected function createTempUploadTable()
 {
     if (!I2CE_Util::runSQLScript('initialize_temp_upload.sql')) {
         I2CE::raiseError("Could not initialize tempoary upload table");
         return false;
     }
     return true;
 }
 /**
  * Method called when the module is enabled for the first time.
  * @param boolean -- returns true on success. false on error.
  */
 public function action_initialize()
 {
     I2CE::raiseError("Initializing UUID Map Tables");
     if (!I2CE_Util::runSQLScript('init_uuid_table.sql')) {
         I2CE::raiseError("Could not initialize uuid table");
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 public function action_initialize()
 {
     I2CE::raiseError("Initializing Form Tables");
     if (!I2CE_Util::runSQLScript('initialize_importexport.sql')) {
         I2CE::raiseError("Could not initialize I2CE import_export table");
         return false;
     }
     return true;
 }
 /**
  * Method called when the module is enabled for the first time.
  * @param boolean -- returns true on success. false on error.
  */
 public function action_initialize()
 {
     I2CE::raiseError("Initializing Provider Cache Table");
     if (!I2CE_Util::runSQLScript('initialize_csd_cache.sql')) {
         I2CE::raiseError("Could not initialize I2CE form tables");
         return false;
     }
     return true;
 }
 /**
  * Method called when the module is enabled for the first time.
  * @param boolean -- returns true on success. false on error.
  */
 public function action_initialize()
 {
     //load the data right now because the site isn't ready to run background processes
     I2CE::raiseError("Loading Sample Data");
     if (!I2CE_Util::runSQLScript('TrainSampleData.sql')) {
         I2CE::raiseError("Could not initialize Train Sample Data tables");
         return false;
     }
     return true;
 }
 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);
     }
 }
 private function addBlobValue()
 {
     $db = MDB2::singleton();
     $rows = $db->queryAll("SHOW FULL COLUMNS FROM entry WHERE Field='blob_value'");
     if (count($rows)) {
         I2CE::raiseError("entry table already has blob_value");
         return true;
     }
     I2CE::raiseError("Adding blob_value to entry tables");
     return I2CE_Util::runSQLScript('add_blob_fields.sql');
 }
 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);
 }
Ejemplo n.º 9
0
 /**
  * Upgrade module method
  * @param string $old_vers
  * @param string $new_vers
  */
 public function upgrade($old_vers, $new_vers)
 {
     if (I2CE_Validate::checkVersion($old_vers, '<', '4.0.11.1')) {
         if (!I2CE_Util::runSQLScript('initialize_form_store.sql')) {
             I2CE::raiseError("Could not initialize I2CE form history storage tables");
             return false;
         }
     }
     if (I2CE_Validate::checkVersion($old_vers, '<', '4.1.4.1') && !$this->upgradeFormStore()) {
         I2CE::raiseError("Could not upgrade I2CE form history storage tables");
         return false;
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  *called from the command line as
  *   --page=BackgroundPage/$script"
  * Or:
  *  --page=BackgroundPage/$db/$script
  *Where $db is the database the script is to run on.  Make sure $db is not backticked!
  *
  */
 protected function actionCommandLine($args, $req)
 {
     $req = $this->request_remainder;
     if (count($req) == 1) {
         //the first (and only) request remaineder is the script
         I2CE_Util::runSQLScript($req[0]);
     } else {
         if (count($req) == 2) {
             //the first request remainder is the DB to use the second is the script
             I2CE_Util::runSQLScript($req[1], $req[0]);
         } else {
             I2CE::raiseError("Invalid request to run sql script");
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Method called when the module is enabled for the first time.
  * @param boolean -- returns true on success. false on error.
  */
 public function action_initialize()
 {
     /*
     $site_module = "";
     I2CE::getConfig()->setIfIsSet( $site_module, "config/site/module" );
     $mod_factory = I2CE_ModuleFactory::instance();
     if ( $mod_factory->isEnabled( $site_module ) ) {
         //launch background import of data.
         $this->launchBackgroundPage("/BackgroundProcess/SQL/ManageSampleData.sql");
     } else {
     */
     //load the data right now because the site isn't ready to run background processes
     I2CE::raiseError("Loading Sample Data");
     if (!I2CE_Util::runSQLScript('ManageSampleData.sql')) {
         I2CE::raiseError("Could not initialize Manage Sample Data tables");
         return false;
     }
     /*
     }
     */
     return true;
 }
Ejemplo n.º 14
0
 /**
  * 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;
 }
Ejemplo n.º 15
0
 /**
  * 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);
     }
 }
 public function checkLimit_DB_STRING_startswith($fieldObj, $vals)
 {
     if (!is_array($vals) || !array_key_exists('value', $vals)) {
         return false;
     }
     $vals['value'] = '' . $vals['value'];
     if (strlen($vals['value']) == 0) {
         return true;
     }
     $regexp = '/^' . I2CE_Util::convertLikeToRegExp(strtolower($vals['value']) . '%') . '$/i';
     return preg_match($regexp, $fieldObj->getDBValue()) > 0;
 }
Ejemplo n.º 17
0
 protected function setupDisplay($swiss, $action, $contentNode)
 {
     if ($action !== 'edit') {
         return true;
     }
     if (count($this->stored_options) > 0) {
         $flat_options = array();
         I2CE_Util::flattenVariables($this->stored_options, $flat_options, false, true, 'swissFactory:options');
         foreach ($flat_options as $k => $v) {
             if (is_scalar($v)) {
                 $v = array($v);
             } else {
                 if (is_array($v)) {
                     $k .= '[]';
                 } else {
                     continue;
                 }
             }
             foreach ($v as $vv) {
                 if (!is_scalar($vv)) {
                     continue;
                 }
                 $contentNode->appendChild($this->template->createElement('input', array('type' => 'hidden', 'name' => $k, 'value' => $vv)));
             }
         }
     }
     $updateLink = $this->getURLRoot('update') . $swiss->getPath() . $swiss->getURLQueryString();
     $this->template->setDisplayDataImmediate('swiss_form', $updateLink, $contentNode);
     $update = $this->template->getElementById('swiss_update_button', $contentNode);
     if (!$update instanceof DOMElement) {
         return false;
     }
     $update->setAttribute('action', $updateLink);
     $this->page->addFormWorm('swiss_form');
     return true;
 }
 /**
  * Display the headers for this report.
  * @param DOMNode $contentNode 
  */
 protected function doCrossTabHeaders($contentNode)
 {
     $page_root = $this->getPageRoot();
     $postfix = '?';
     $qry_fields = $this->page->request();
     if (array_key_exists('sort_order', $this->defaultOptions)) {
         if ($this->defaultOptions['sort_order'] == 'none') {
             $sortFields = array();
         } else {
             $sortFields = explode(',', $this->defaultOptions['sort_order']);
         }
         unset($qry_fields['sort_order']);
     } else {
         $sortFields = array();
     }
     if (count($qry_fields) > 0) {
         $flat = array();
         $qry_fields = I2CE_Util::flattenVariables($qry_fields, $flat);
         $fields = array();
         foreach ($flat as $key => $val) {
             if (is_array($val)) {
                 foreach ($val as $v) {
                     array_push($fields, urlencode($key) . "[]=" . $v);
                 }
             } else {
                 array_push($fields, urlencode($key) . '=' . $val);
             }
         }
         $page_root .= '?' . implode('&', $fields);
         $postfix = '&';
     }
     if ($this->page->hasAjax()) {
         $this->page->getTemplate()->addHeaderLink("mootools-core.js");
     }
     $sort_order = array();
     if ($this->displayedFields == null) {
         $this->displayedFields = $this->getDisplayFieldsData();
     }
     $sort_descriptions = array();
     $t_sortFields = array();
     $decreasing = 'Decreasing';
     $increasing = 'Increasing';
     I2CE::getConfig()->setIfIsSet($decreasing, "/modules/CustomReports/text/Decreasing");
     I2CE::getConfig()->setIfIsSet($increasing, "/modules/CustomReports/text/Increasing");
     foreach ($sortFields as $i => $s) {
         if (strlen($s) == 0) {
             continue;
         }
         if ($s[0] == '-') {
             $s = substr($s, 1);
             if (!array_key_exists($s, $this->displayedFields)) {
                 continue;
             }
             if (!$this->displayedFields[$s]) {
                 continue;
             }
             $sort_descriptions[] = $this->displayedFields[$s]['header'] . ' (Decreasing)';
             $t_sortFields[$s] = true;
             $sort_order[$s] = '-';
         } else {
             if (!array_key_exists($s, $this->displayedFields)) {
                 continue;
             }
             if (!$this->displayedFields[$s]) {
                 continue;
             }
             $sort_descriptions[] = $this->displayedFields[$s]['header'] . ' (Increasing)';
             $t_sortFields[$s] = true;
             $sort_order[$s] = '';
         }
     }
     $sortFields = array_keys($t_sortFields);
     $sort_description = '';
     if (count($sort_descriptions) > 0) {
         $sort_description = implode(',', $sort_descriptions);
     }
     $this->template->setDisplayDataImmediate('sort_description', $sort_description, $contentNode);
     $color_grad = 0;
     if (count($sortFields) > 0) {
         $color_grad = (int) floor((0xff - 0xcc) / count($sortFields));
     }
     foreach ($this->headers as $formfield => $headinfo) {
         if (!$headinfo) {
             continue;
         }
         $show_sort = false;
         if (is_array($headinfo)) {
             $header = $this->displayedFields[$formfield]['header'];
             $head_count = count($headinfo);
             $head = $this->template->appendFileByName("customReports_table_head_cell.html", "th", "report_header_one", 0, $contentNode);
             if (!$head instanceof DOMNode) {
                 I2CE::raiseError("Could not add head cell to table");
                 return false;
             }
             $head->setAttribute("colspan", $head_count);
             $this->template->appendElementByNode($head, "span", array('id' => "report_column_header_{$formfield}"), $header);
             $idx = 0;
             foreach ($headinfo as $header => $enabled) {
                 if (!$enabled) {
                     continue;
                 }
                 if ($header == '') {
                     $header = '??';
                 }
                 $head = $this->template->appendFileByName("customReports_table_head_cell.html", "th", "report_header_two", 0, $contentNode);
                 if (!$head instanceof DOMNode) {
                     I2CE::raiseError("Could not add head cell to table");
                     return false;
                 }
                 $this->template->appendElementByNode($head, "span", array('id' => "report_column_header_{$formfield}_{$idx}"), $header);
                 $idx++;
             }
         } else {
             $header = $this->displayedFields[$formfield]['header'];
             $head = $this->template->appendFileByName("customReports_table_head_cell.html", "th", "report_header_one", 0, $contentNode);
             if (!$head instanceof DOMNode) {
                 I2CE::raiseError("Could not add head cell to table");
                 return false;
             }
             $head->setAttribute("rowspan", "2");
             if (count($sortFields) > 0 && $formfield == $sortFields[count($sortFields) - 1]) {
                 $this->template->setNodeAttribute("class", "selected", $head);
             } else {
                 $position = array_search($formfield, $sortFields);
                 if ($position !== false) {
                     $this->template->setNodeAttribute("class", "secondary_selected", $head);
                     $bgcolor = dechex((count($sortFields) - $position - 1) * $color_grad + 0xcc);
                     $bgcolor = hexdec($bgcolor . $bgcolor . $bgcolor) - 0x219;
                     $bgcolor = '#' . dechex($bgcolor);
                     $this->template->setNodeAttribute("style", "background-color:{$bgcolor}", $head);
                 }
             }
             $t_sortFields = $sortFields;
             $t_sort_order = $sort_order;
             $key = array_search($formfield, $t_sortFields);
             if ($key !== false) {
                 //the field is already in the sort order
                 unset($t_sortFields[$key]);
                 if ($key == count($sortFields) - 1) {
                     //the field was the first on the list
                     //so switch it's sort order
                     if ($t_sort_order[$formfield] == '') {
                         //make increasing decreasing
                         $t_sort_order[$formfield] = '-';
                         $t_sortFields[] = $formfield;
                         //put the field at the end of the list
                     } else {
                         //remove decreasing from the list (don't need to do anything)
                         unset($t_sort_order[$formfield]);
                     }
                 } else {
                     //sort it by ascending
                     $t_sort_order[$formfield] = '';
                     $t_sortFields[] = $formfield;
                     //put the field at the end of the list
                 }
             } else {
                 $t_sort_order[$formfield] = '';
                 $t_sortFields[] = $formfield;
                 //put the field at the end of the list
             }
             foreach ($t_sortFields as $i => $s) {
                 $t_sortFields[$i] = $t_sort_order[$s] . $s;
             }
             if (count($t_sortFields) > 0) {
                 $link = $page_root . $postfix . 'sort_order=' . urlencode(implode(',', $t_sortFields));
             } else {
                 $link = $page_root . $postfix . 'sort_order=none';
             }
             $this->template->appendElementByNode($head, "a", array("href" => $link, 'id' => "report_column_header_{$formfield}"), $header);
             if ($this->page->hasAjax()) {
                 $this->page->addAjaxUpdate($this->getReportPrefix() . 'report_results', "report_column_header_{$formfield}", 'click', $link, $this->getReportPrefix() . 'report_results');
             }
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * Method called when the module is enabled for the first time.
  * @param boolean -- returns true on success. false on error.
  */
 public function action_initialize()
 {
     if (!I2CE_Util::runSQLScript('CREATE_formfield_mult_map_componentize.sql', null, false)) {
         //don;t use a transaction
         I2CE::raiseError("Could not install remapping SQL  function");
         return false;
     }
     return true;
 }
 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;
 }
 /**
  * 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;
 }
 /**
  * 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 . ');';
 }
 /**
  * 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;
 }
Ejemplo n.º 24
0
 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;
 }
 /**
  * Cache the user statistics pseudo report.
  * @param boolean $drop_first
  * @param boolean $force
  * @return boolean
  */
 public function cacheUserStatistics($drop_first = false, $force = false)
 {
     if (!self::setupDB(false)) {
         return false;
     }
     $config = I2CE::getConfig()->modules->UserStatistics->cache;
     $config->volatile(true);
     $start = 0;
     $end = 0;
     $failed = 0;
     $config->setIfIsSet($start, "start");
     $config->setIfIsSet($end, "end");
     $config->setIfIsSet($failed, "failed");
     if ($force || $start == 0 || $end != 0 && $end >= $start || $failed != 0 && $failed >= $start) {
         $config->start = time();
         $res = self::$db->getOne("SHOW TABLES LIKE 'zebra__user_statistics'");
         if (!$res) {
             if (!I2CE_Util::runSQLScript('initialize_user_statistics.sql')) {
                 I2CE::raiseError("Could not initialize user statistics cache table.");
                 return false;
             }
         }
         if ($drop_first) {
             $res = self::$db->query("truncate table zebra__user_statistics");
             if (I2CE::pearError($res, "Unable to truncate user statistics cache table.")) {
                 $cache->failed = time();
                 return false;
             }
         }
         $res = self::$db->query("INSERT INTO zebra__user_statistics SELECT entry.change_type AS `change_type`, entry.date AS `date`, (SELECT CONCAT(parent_form,'|',parent_id) FROM record WHERE id = entry.record) AS `parent_id`, entry.record AS `record`, (SELECT name FROM form WHERE id = (SELECT form FROM form_field WHERE id = entry.form_field)) AS `form`, (SELECT name FROM field WHERE id = (SELECT field FROM form_field WHERE id = entry.form_field)) AS `field`, entry.string_value, entry.integer_value, entry.date_value, entry.text_value, entry.blob_value, IF(entry.who = 0, 'I2CE Admin', (SELECT CONCAT_WS( ' ', user.firstname, user.lastname ) FROM user WHERE id = entry.who)) AS `user`, IF(entry.who = 0, 'i2ce_admin', (SELECT user.username FROM user WHERE id = entry.who)) AS `username` FROM entry WHERE date > IFNULL((SELECT MAX(date) FROM zebra__user_statistics ),'0000-00-00 00:00:00')");
         if (I2CE::pearError($res, "Unable to populate user statistics cache table.")) {
             $cache->failed = time();
             return false;
         }
         $config->end = time();
         I2CE::raiseError("Updated User Statistics report at " . date('r', $config->end));
     }
     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;
 }
Ejemplo n.º 28
0
 /**
  *  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);
 }
 /**
  * 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;
 }
Ejemplo n.º 30
0
 /**
  * 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;
             }
         }
     }
 }