public function save() { $flash = Flash::Instance(); // this is going to be a prodomintely (sp?) ajax save... effectively we're // not moving away from the page if we have an error... this is the best way // to preserve such a delicate form like this // set a few vars $normal_field_exists = FALSE; // ensure we have some fields if (!isset($this->_data['Report']['options']) or empty($this->_data['Report']['options'])) { echo $this->returnResponse(FALSE, array('message' => '<li>No fields specified</li>')); exit; } // loop through fields, check if any are of NORMAL type foreach ($this->_data['Report']['options'] as $field => $options) { // remember, if the field type doesn't exist it's default is 'normal' if (!isset($options['field_type']) or $options['field_type']) { $normal_field_exists = TRUE; break; // no point in continuing } } // if the normal fields exists status hasn't changed, throw the error if ($normal_field_exists === FALSE) { echo $this->returnResponse(FALSE, array('message' => '<li>No normal fields specified</li>')); exit; } // serialise the report options back to itself $this->_data['Report']['options'] = serialize($this->_data['Report']['options']); // remove the id if we want to save as a copy, a new id (and thus the record) will be generated if (strtolower($this->_data['save']) == 'save copy') { unset($this->_data['Report']['id']); } // Set the rpeort definition id, unless Default was selected if ($this->_data['report_def'] != 'Default') { $def = new ReportDefinition(); $rdef = $def->getDefinition($this->_data['report_def']); $this->_data['Report']['report_definition'] = $rdef->_data['id']; } // fire up the db $db = DB::Instance(); $db->StartTrans(); // post data, output status if (parent::save($this->modeltype)) { $db->CompleteTrans(); $link = sprintf('/?module=%s&controller=%s&action=%s&id=%s', $this->module, $this->name, 'view', $this->saved_model->id); echo $this->returnResponse(TRUE, array('redirect' => $link)); exit; } else { $db->FailTrans(); $db->CompleteTrans(); // get the errors $flash->save(); $errors = $flash->__get('errors'); $flash->clear(); $message = '<li>Failed to save Report</li>'; if (!empty($errors)) { foreach ($errors as $error) { $message .= "<li>" . $error . "</li>"; } } echo $this->returnResponse(FALSE, array('message' => $message)); exit; } }
public function build_custom_xsl($collection, $definition_name, $title, $col_headers, $col_widths, $options = array()) { // $collection is not used: why do we need it? // get the XSL $xsl = ReportDefinition::getDefinition($definition_name)->definition; if (!empty($xsl)) { // define / generate the various xsl vars that are to be replaced $xslVars['REPORT_TITLE'] = $title; $column_definitions = '<fo:table-column column-width="proportional-column-width(%s)"/>'; $column_headings = '<fo:table-cell padding="1mm" border-width="1pt" border-style="solid" text-align="%s" >' . "\r\n"; $column_headings .= ' <fo:block >%s</fo:block>' . "\r\n"; $column_headings .= '</fo:table-cell>'; $row_cells = '<fo:table-cell padding="1mm" border-style="solid" border-width="1pt" >' . "\r\n"; $row_cells .= ' <!-- check if we\'re dealing with a total row -->' . "\r\n"; $row_cells .= ' <xsl:if test="%s/@negative_number=\'true\'">' . "\r\n"; $row_cells .= ' <xsl:attribute name="color">red</xsl:attribute>' . "\r\n"; $row_cells .= ' </xsl:if>' . "\r\n"; $row_cells .= ' <xsl:if test="%s/@text-align=\'right\'">' . "\r\n"; $row_cells .= ' <xsl:attribute name="text-align">right</xsl:attribute>' . "\r\n"; $row_cells .= ' </xsl:if>' . "\r\n"; $row_cells .= ' <fo:block>' . "\r\n"; $row_cells .= ' <xsl:value-of select="%s"/>' . "\r\n"; $row_cells .= ' </fo:block>' . "\r\n"; $row_cells .= '</fo:table-cell>'; $column_widths = array(); // echo 'getMinColWidths '.microtime(TRUE).'<pre>'.print_r($collection->getMinColWidths($col_headers), true).'</pre>'.microtime(TRUE).'<br>'; if (isset($this->_data['col_widths']) && !empty($this->_data['col_widths'])) { // parse the column widths into an array $column_widths = $this->parse_column_widths($this->_data['col_widths']); // echo 'parse_column_widths<pre>'.print_r($column_widths, true).'</pre><br>'; // calculate an average width, just in case a column width isn't specified // an average of the specified ones should be fine $total_widths = 0; $average_width = 50; // failsafe foreach ($column_widths as $width) { $total_widths += $width; } $failsafe_width = $total_widths / count($column_widths); } else { $failsafe_width = 50; } foreach ($col_headers as $key => $value) { if (isset($column_widths[$key])) { $column_width = $column_widths[$key]; } else { $column_width = $failsafe_width; } $text_align = "left"; if ($options[$key]['normal_enable_formatting'] == 'true' && isset($options[$key]['normal_justify'])) { $text_align = $options[$key]['normal_justify']; } $xslVars['REPORT_COLUMN_DEFINITIONS'] .= sprintf($column_definitions, $column_width) . "\r\n"; $xslVars['REPORT_COLUMN_HEADINGS'] .= sprintf($column_headings, $text_align, $value) . "\r\n"; $xslVars['REPORT_ROW_CELLS'] .= sprintf($row_cells, $key, $key, $key) . "\r\n"; } $xslVars['COLLECTION_NAME'] = $collection->getModelName(); // process xsl $xsl = $this->process_xsl($xsl, $xslVars); } else { $xsl = FALSE; } return $xsl; }