/** * @param DOMNode $node * @param I2CE_Template $template * @param DOMNode $form_node * */ public function processDOMEditable_reportSelect($node, $template, $form_node) { $mf = I2CE_ModuleFactory::instance(); if (!$mf->isEnabled('CustomReports-Selector')) { return false; } $template->addHeaderLink("mootools-more.js"); $template->addHeaderLink("getElementsByClassName-1.0.1.js"); $template->addHeaderLink("I2CE_ClassValues.js"); $template->addHeaderLink("I2CE_Window.js"); $template->addHeaderLink("I2CE_ToggableWindow.js"); $template->addHeaderLink("I2CE_TreeSelect.js"); $template->addHeaderLink('Observer.js'); $template->addHeaderLink('Autocompleter.js'); $template->addHeaderLink('Autocompleter.css'); $template->addHeaderLink('I2CE_TreeSelectAutoCompleter.js'); $template->addHeaderLink("Tree.css"); $style = 'default'; if ($form_node->hasAttribute('show')) { $style = $this->ensureEditStyle($form_node->getAttribute('show')); } $styles = array($style); if ($style != 'default') { $styles[] = 'default'; } foreach ($styles as $style) { $edit_path = "meta/reportSelect/{$style}"; $report_path = "{$edit_path}/reportView"; if (!$this->optionsHasPath($edit_path) || !is_array($options = $this->getOptionsByPath($edit_path))) { continue; } if (!$this->optionsHasPath($report_path) || !is_scalar($reportView = $this->getOptionsByPath($report_path))) { continue; } $report = false; $relationship = false; $form = false; I2CE::getConfig()->setIfIsSet($report, "/modules/CustomReports/reportViews/{$reportView}/report"); if (!$report) { continue; } I2CE::getConfig()->setIfIsSet($relationship, "/modules/CustomReports/reports/{$report}/relationship"); if (!$relationship) { continue; } $form = false; $reportform_path = "meta/reportSelect/{$style}/reportform"; $reportform = 'primary_form'; if ($this->optionsHasPath($reportform_path)) { //we are not using the primary form in the relationship, instead we are using a named form. $reportform = $this->getOptionsByPath($reportform_path); if ($reportform == 'primary_form') { I2CE::getConfig()->setIfIsSet($form, "/modules/CustomReports/relationships/{$relationship}/form"); } else { try { $relObj = new I2CE_FormRelationship($relationship); } catch (Exception $e) { continue; } $form = $relObj->getForm($reportform); } } else { //we use the primary form I2CE::getConfig()->setIfIsSet($form, "/modules/CustomReports/relationships/{$relationship}/form"); } if (!$form) { continue; } if (!$this->canSelectAnyForm()) { $form_path = "meta/form"; if (!$this->optionsHasPath($form_path) || !is_array($forms = $this->getOptionsByPath($form_path))) { continue; } if (!in_array($form, $forms)) { continue; } } $printf_path = "meta/display/{$form}/{$style}/printf"; $printfargs_path = "meta/display/{$form}/{$style}/printf_args"; if (!$this->optionsHasPath($printf_path) || !is_string($printf = $this->getOptionsByPath($printf_path))) { continue; } if (!$this->optionsHasPath($printfargs_path) || !is_array($printfargs = $this->getOptionsByPath($printfargs_path))) { continue; } if (strlen($printf) == 0) { continue; } if (count($printfargs) == 0) { continue; } ksort($printfargs); $disp = $this->_getDisplayValue(null, $style); $node->setAttribute('id', $this->getHTMLName()); $options = array('reportview' => $reportView, 'printf' => $printf, 'printfargs' => $printfargs, 'display' => $disp, 'value' => $this->getDBValue(), 'reportform' => $reportform); $no_limits_path = "meta/display/{$form}/{$style}/no_limits"; if ($this->optionsHasPath($no_limits_path) && $this->getOptionsByPath($no_limits_path)) { $options['contentid'] = 'report_results'; } else { $options['contentid'] = 'report_results_with_limits'; } $options['multi_select'] = 1; if ($template->addReportSelector($node, $options)) { return true; } } return false; }
public function streamRaw($ids = false, $last_modified = -1, $headers = false, $pre = '', $post = '', $wrap = true) { $ff = I2CE_FormFactory::instance(); $form_name = $this->relObj->getPrimaryForm(); I2CE::raiseError("Primary form = {$form_name}"); if (!is_array($ids)) { $ids = $ff->getRecords($form_name, $last_modified); } else { $t_ids = $ids; $ids = array(); foreach ($t_ids as $id) { list($form, $fid) = array_pad(explode("|", $id, 2), 2, ''); if ($fid != '' and $fid != '0') { $ids[] = $fid; } } } try { $formRelationship = new I2CE_FormRelationship($this->relationship); } catch (Exception $e) { I2CE::raiseError("Could not create form relationship : " . $this->args['relationship']); return false; } $formRelationship->useRawFields(); $formfields = array(); foreach ($formRelationship->getFormNames() as $formName) { if (!($form = $formRelationship->getForm($formName)) || !($formObj = $ff->createContainer(array($form, 0))) instanceof I2CE_Form) { continue; } $formfields[$formName] = array(); foreach ($formObj->getFieldNames() as $fieldName) { if (!($fieldObj = $formObj->getField($fieldName)) instanceof I2CE_FormField || !$fieldObj->isInDB()) { continue; } $formfields[$formName][] = $fieldName; } $cachefields = array("created", "last_modified", "parent"); foreach ($cachefields as $cachedfieldName) { $formfields[$formName][] = $cachedfieldName; } } I2CE::longExecution(array("max_execution_time" => 1800)); $results = $this->getCache($ids, $last_modified); if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) { I2CE::raiseError("Got errors:\n{$errors}"); } if (array_key_exists('HTTP_HOST', $_SERVER)) { if (!is_array($headers)) { $headers = array('Content-Type: text/xml'); } foreach ($headers as $header) { header($header); } } echo "<?xml version='1.0'?>\n"; flush(); if ($pre) { echo $pre; flush(); } echo "<!-- Contains " . count($ids) . " records -->\n"; flush(); if ($wrap) { echo "<relationshipCollection name='" . $formRelationship->getPrimaryFormName() . "'>\n"; flush(); } $rec = 0; foreach ($ids as $id) { I2CE::longExecution(array("max_execution_time" => 1800)); $doc = new DOMDocument(); $doc->loadXML("<relationship/>"); $node = $doc->documentElement; $formRelationship->getFormData($form_name, $id, $formfields, array(), $node); echo "<!-- Record #: " . $rec . "-->"; echo $doc->saveXML($doc->documentElement) . "\n"; flush(); $rec++; } if ($wrap) { echo "</relationshipCollection>"; flush(); } if ($post) { echo $post; flush(); } flush(); }
protected function getLimitVars() { $limit_vars = array(); //$this->defaultOptions['nested_limits'][$field] = array($limit_styles=>$limit_values) { if (array_key_exists('nested_limits', $this->defaultOptions) && is_array($this->defaultOptions['nested_limits'])) { $limitValues = $this->defaultOptions['nested_limits']; } else { $limitValues = array(); } try { $relObj = new I2CE_FormRelationship($this->reportConfig->relationship); } catch (Exception $e) { I2CE::raiseError("Invalid relationship {$relationship}"); return false; } $reportform_ids = array(); $l_values = array(); foreach ($this->reportConfig->reporting_forms as $reportform => $formConfig) { if (!$formConfig instanceof I2CE_MagicDataNode) { continue; } $l_values[$reportform] = array(); foreach ($formConfig->fields as $field => $fieldConfig) { if (!$fieldConfig instanceof I2CE_MagicDataNode) { continue; } $enabled = false; $fieldConfig->setIfIsSet($enabled, "limits/equals/enabled"); if (!$enabled) { continue; } $rff = "{$reportform}+{$field}"; if (!array_key_exists($rff, $limitValues) || !is_array($limitValues[$rff]) || !array_key_exists('equals', $limitValues[$rff]) || !is_array($limitValues[$rff]['equals']) || !array_key_exists('value', $limitValues[$rff]['equals']) || !$limitValues[$rff]['equals']['value'] || $limitValues[$rff]['equals']['value'] == '|') { $l_values[$reportform][$field] = false; } else { $l_values[$reportform][$field] = $limitValues[$rff]['equals']['value']; } //example is $reportform_ids['position]['facility'] = 'facility|22'; } } $ff = I2CE_FormFactory::instance(); foreach ($l_values as $reportform => $fields) { if (!($form = $relObj->getForm($reportform))) { continue; } if (!($formObj = $ff->createContainer($form)) instanceof I2CE_Form) { continue; } foreach ($fields as $field => $value) { if (!($mapField = $formObj->getField($field)) instanceof I2CE_FormField_MAP) { continue; } if ($value) { $mapField->setFromDB($value); if (!($mFormObj = $mapField->getMappedFormObject()) instanceof I2CE_Form) { continue; } foreach ($mFormObj->getFieldNames() as $name) { if (!($fieldObj = $mFormObj->getField($name)) instanceof I2CE_FormField) { continue; } $limit_vars["++limit+" . $reportform . "+" . $field . '+' . $name] = $fieldObj->getDisplayValue(); //++limit+position+facility+name or //++limit+position+facility+facility_type } $limit_vars["++limit+" . $reportform . "+" . $field] = $mFormObj->name(); } else { //no value was set... try to blank out values. $sforms = $mapField->getSelectableForms(); if (count($sforms) != 1) { continue; } reset($sforms); $sform = current($sforms); if (!($sformObj = $ff->createContainer($sform)) instanceof I2CE_Form) { continue; } $limit_vars["++limit+" . $reportform . "+" . $field] = ''; foreach ($sformObj->getFieldNames() as $name) { $limit_vars["++limit+" . $reportform . "+" . $field . '+' . $name] = ''; } } //format is ++limit+scheduled_training_course+id+training_course for each of the 'equals' limits. for now this is only on formfields //now we add in the mapped field values (just to be nice) } } I2CE::raiseError(print_r($limit_vars, true)); return $limit_vars; }