/** * Display the report * @param DOMNode $contentNode The DOM node we wish to display into * @param boolean $processResults Defaults to true meaning we run through the results * @param mixed $controls. If null (default), we display all the report controsl. If string or an array of string, we only display the indicated controls * @returns boolean. true on sucess */ public function display($contentNode, $processResults = true, $controls = null) { I2CE::longExecution(array("max_execution_time" => 1800)); $this->saveDefaultView(); $template = $this->defaultOptions['odt_template']; $template_upload = false; $template_file = null; if ($this->config->setIfIsSet($template_upload, "printed_forms/{$template}/template_upload", true) && array_key_exists('content', $template_upload) && $template_upload['content'] && array_key_exists('name', $template_upload) && $template_upload['name']) { $template_file = $template_upload['name']; $pos = strrpos($template_file, '.'); if ($pos !== false) { $name = substr($template_file, 0, $pos); } else { $name = $template_file; } $template_loc = tempnam(sys_get_temp_dir(), basename($name . '_')) . '.odt'; file_put_contents($template_loc, $template_upload['content']); } else { $this->config->setIfIsSet($template_file, "printed_forms/{$template}/template"); $template_loc = I2CE::getFileSearch()->search('ODT_TEMPLATES', $template_file); if (!$template_loc) { I2CE::raiseError("No template file found from {$template_file}"); return false; } } $this->header_vars = array(); foreach ($this->getDisplayFieldsData() as $formfield => $data) { $this->header_vars["++header+{$formfield}"] = $data['header']; list($formObj, $fieldObj) = $this->getFormFieldObjects($formfield); $this->image_objs[$formfield] = $fieldObj instanceof I2CE_FormField_IMAGE; $this->extra[$formfield] = array(); } $this->limit_vars = $this->getLimitVars(); $odf_config = array('DELIMITER_LEFT' => '{{{', 'DELIMITER_RIGHT' => '}}}', 'ZIP_PROXY' => 'PhpZipProxy'); $this->odf = new I2CE_Odf($template_loc, $odf_config); try { $this->odf->setVars('++report_title', $this->config->display_name, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setStyleVars('++report_title', $this->config->display_name, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setVars('++report_description', $this->config->description, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setStyleVars('++report_description', $this->config->description, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } foreach ($this->header_vars as $key => $val) { try { $this->odf->setVars($key, $val, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setStyleVars($key, $val, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } } foreach ($this->limit_vars as $key => $val) { try { $this->odf->setVars($key, $val, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setStyleVars($key, $val, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } } $user = new I2CE_User(); $name = $user->firstname . ' ' . $user->lastname; try { $this->odf->setVars('++user_name', $name, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setStyleVars('++user_name', $name, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } $time = strftime("%c"); try { $this->odf->setVars('++time', $time, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setStyleVars('++time', $time, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } $limitsDesc = $this->getReportLimitsDescription(); try { $this->odf->setVars('++report_limit', $limitsDesc, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf->setStyleVars('++report_limit', $limitsDesc, $this->encoding, $this->charset); } catch (OdfException $e) { //It's ok if it's not there so don't do anything. } try { $this->odf_row = $this->odf->setSegment('report_row'); } catch (OdfException $e) { I2CE::raiseError("Couldn't find report_row in ODT template {$template_loc}."); return false; } $keys = $this->odf_row->getKeys(); foreach ($this->odf_row->getKeys() as $key) { if (!is_string($key) || strlen($key) < 1) { continue; } if ($key[0] == '+') { continue; } list($namedform, $field, $t_extra) = array_pad(explode("+", $key, 3), 3, ''); $extra = array(); if (is_string($t_extra) && strlen($t_extra) > 0) { $t_extra = explode(',', $t_extra); foreach ($t_extra as $ex) { list($ex_k, $ex_v) = array_pad(explode('=', $ex, 2), 2, ''); if (!$ex_k || !$ex_v) { continue; } $extra[$ex_k] = $ex_v; } } $namedform = trim($namedform); $field = trim($field); $this->extra[$namedform . '+' . $field] = $extra; $this->full_keys[$namedform . '+' . $field] = $key; } $data = $this->getResults(); if (!$this->processResults($data, $contentNode)) { I2CE::raiseError("Could not get results"); return false; } $this->odf->mergeSegment($this->odf_row); if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) { I2CE::raiseError("Errors:\n" . $errors); } $this->odf->exportAsAttachedFile($template_file); exit; // we want to make sure there is no further output or that the $this->page->display() method is not called }