2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Displays complex reports based on the list of tables and fields provided to
|
|
|
|
* the object.
|
2008-10-16 15:44:20 +02:00
|
|
|
* @deprecated 2.3 Use TableListField
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-reports
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class ReportField extends FormField{
|
|
|
|
|
|
|
|
protected $tables;
|
|
|
|
protected $primaryKeys;
|
|
|
|
protected $fields;
|
|
|
|
protected $filter;
|
|
|
|
protected $primaryClass;
|
|
|
|
protected $sort;
|
|
|
|
protected $export = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a report field.
|
|
|
|
*
|
|
|
|
* @param name Name of the report field
|
|
|
|
* @param title Title of the report field as displayed in the CMS.
|
|
|
|
* @param tables Array of primary keys indexed by the names of the tables.
|
|
|
|
* @param fields Array of fields indexed by the name of the table.
|
|
|
|
*/
|
|
|
|
function __construct($name, $title, $tables, $fields, $hideByDefault = null, $defaultSort = null, $form = null) {
|
|
|
|
|
|
|
|
parent::__construct( $name, $title, "", $form );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( !is_array( $tables ) )
|
|
|
|
user_error( "Third parameter must be an array. Table Name => Primary Key Column", E_USER_ERROR );
|
|
|
|
else {
|
|
|
|
$this->tables = array_keys( $tables );
|
|
|
|
$this->primaryKeys = $tables;
|
2007-09-16 03:50:07 +02:00
|
|
|
$this->primaryClass = $this->tables[0];
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( !is_array( $fields ) )
|
|
|
|
$this->fields = array( $fields );
|
|
|
|
else
|
|
|
|
$this->fields = $this->expandWildcards( $fields );
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
public function setExport($export){
|
|
|
|
$this->export = $export;
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected function expandWildcards( $fields ) {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$newFields = array();
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $fields as $field )
|
|
|
|
if( preg_match( '/.*\.\*/', $field ) )
|
|
|
|
$newFields = $newFields + $this->expandWildcard( $field );
|
|
|
|
else
|
|
|
|
$newFields[] = $field;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
return $newFields;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected function expandWildcard( $field ) {
|
|
|
|
list( $table, $column ) = $this->parseField( $field );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $this->getColumnsInTable( $table ) as $newColumn )
|
|
|
|
$columns[] = $table.'.'.$newColumn;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
return $columns;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function exportToCSV( $fileName ) {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$fileData = $this->columnheaders( 'csvRow', 'csvCell' ) . $this->datacells( 'csvRow', 'csvCell' );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
header("Content-Type: text/csv; name=\"" . addslashes($fileName) . "\"");
|
|
|
|
header("Content-Disposition: attachment; filename=\"" . addslashes($fileName) . "\"");
|
|
|
|
header("Content-length: " . strlen($fileData));
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
echo $fileData;
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function FieldHolder() {
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/ReportField.js");
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$headerHTML = $this->columnheaders();
|
|
|
|
$dataCellHTML = $this->datacells();
|
|
|
|
$id = $this->id() . '_exportToCSV';
|
|
|
|
if($this->export){
|
|
|
|
$exportButton =<<<HTML
|
|
|
|
<input name="$id" type="submit" id="$id" class="ReportField_ExportToCSVButton" value="Export to CSV" />
|
|
|
|
HTML
|
|
|
|
;
|
|
|
|
}else{
|
|
|
|
$exportButton = "";
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// display the table of results
|
|
|
|
$html = <<<HTML
|
|
|
|
<div style="width: 98%; overflow: auto">
|
|
|
|
$exportButton
|
|
|
|
<table class="ReportField" summary="">
|
|
|
|
<thead>
|
|
|
|
$headerHTML
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
$dataCellHTML
|
|
|
|
</tbody>
|
2007-09-16 03:50:07 +02:00
|
|
|
</table>
|
2007-07-19 12:40:28 +02:00
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
return $html;
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the HTML for the data cells for the current report.
|
|
|
|
* This can be used externally via ajax as the report might be filtered per column.
|
|
|
|
* It is also used internally to display the data cells.
|
|
|
|
*/
|
|
|
|
public function datacells( $rowCallBack = 'htmlTableRow', $cellCallBack = 'htmlTableCell' ) {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// get the primary records in the database, sorted according to the current sort
|
|
|
|
// this will need to be corrected later on
|
|
|
|
$primaryRecords = $this->getRecords();
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/*echo "ERROR:";
|
|
|
|
Debug::show( $primaryRecords );
|
|
|
|
die();*/
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$html = "";
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $primaryRecords as $record ) {
|
|
|
|
$rowOutput = "";
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $this->fields as $field ) {
|
|
|
|
if( $field{0} == '!' ) $field = substr( $field, 1 );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
list( $table, $column ) = $this->parseField( $field );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( $this->filter && !$this->filter->showColumn( $table, $column ) )
|
|
|
|
continue;
|
|
|
|
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$rowOutput .= $this->$cellCallBack( $record[$field], $table, $column );
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$html .= $this->$rowCallBack( $rowOutput, $table, null );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $html;
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the HTML for the headers of the columns.
|
|
|
|
* Can also be called via ajax to reload the headers.
|
|
|
|
*/
|
|
|
|
public function columnheaders( $rowCallBack = 'htmlTableRow', $cellCallBack = 'htmlHeaderCell' ) {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $this->fields as $field ) {
|
|
|
|
list( $table, $column ) = $this->parseField( $field );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( $this->filter && !$this->filter->showColumn( $table, $column ) )
|
|
|
|
continue; // replace this with some code to show a 'hidden' column
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/*if( $column == '*' )
|
|
|
|
foreach( $this->getColumnsInTable( $table ) as $extraColumn )
|
2007-09-16 03:50:07 +02:00
|
|
|
$html .= $this->$cellCallBack( $extraColumn, $table, $extraColumn );
|
2007-07-19 12:40:28 +02:00
|
|
|
else */
|
|
|
|
$html .= $this->$cellCallBack( $column, $table, $column );
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
return $this->$rowCallBack( $html, null, null );
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected function getColumnsInTable( $table ) {
|
2008-11-23 01:31:06 +01:00
|
|
|
$result = DB::query( "SELECT * FROM \"$table\" LIMIT 1" );
|
2007-07-19 12:40:28 +02:00
|
|
|
return array_keys( $result->next() );
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected function parseField( $field ) {
|
|
|
|
if( $field{0} == '!' )
|
|
|
|
$field = substr( $field, 1 );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( strpos( $field, '.' ) !== FALSE )
|
|
|
|
return explode( '.', $field );
|
|
|
|
else
|
|
|
|
return $field;
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Joins the given record together with the extra information in the other tables.
|
|
|
|
* This is only used in a situation in which the database can't do the join and I'll
|
|
|
|
* correct it when I figure out how to use buildSQL
|
|
|
|
*/
|
|
|
|
protected function joinRecord( $object ) {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $object;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// split the list of fields into table, column and group by table.
|
|
|
|
/*$tableColumns = array();
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $this->fields as $field ) {
|
|
|
|
list( $table, $column ) = $this->parseField( $field );
|
|
|
|
$tableColumns[$table][] = $column;
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$primaryKey = $this->primaryKeys[$object->class];
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( !$primaryKey ) foreach( ClassInfo::ancestry( $object->class ) as $baseClass )
|
|
|
|
$primaryKey = $this->primaryKeys[$baseClass];
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$primaryKeyValue = $object->$primaryKey;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// get the fields from the object
|
|
|
|
$completeRecord = $this->joinFields( $object, $tableColumn[$this->primaryClass] );
|
|
|
|
|
|
|
|
foreach( $tableColumns as $className => $classFields ) {
|
|
|
|
$joinKey = $this->primaryKeys[$className];
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// get the all the extra fields.
|
2008-11-23 01:31:06 +01:00
|
|
|
$recordObj = DataObject::get_one( $className, "\"$className\".\"$joinKey\"='$primaryKeyValue'" );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$completeRecord = $completeRecord + $this->joinFields( $recordObj, $fields );
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $completeRecord;*/
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected function joinFields( $object, $fields ) {
|
|
|
|
$partialRecord = array();
|
|
|
|
foreach( $fields as $field )
|
|
|
|
$partialRecord[$object->class.'.'.$field] = $object->$field;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $partialRecord;
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-16 03:50:07 +02:00
|
|
|
* Sort the data in the cells
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
public function sortdata() {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Get the primary set of records for the cells. This returns a data object set.
|
|
|
|
*/
|
|
|
|
protected function getRecords() {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// $_REQUEST['showqueries'] = 1;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$tableColumns = array();
|
|
|
|
$selectFields = array();
|
2008-11-23 01:31:06 +01:00
|
|
|
$joins = array( "\"{$this->primaryClass}\"" );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $this->fields as $field ) {
|
|
|
|
if( $field{0} == '!' )
|
|
|
|
continue;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
list( $table, $column ) = $this->parseField( $field );
|
|
|
|
$tableColumns[$table][] = $column;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( $column == '*' )
|
2008-11-23 01:31:06 +01:00
|
|
|
$selectFields[] = "\"$table\".*";
|
2007-07-19 12:40:28 +02:00
|
|
|
else
|
2008-11-23 01:31:06 +01:00
|
|
|
$selectFields[] = "\"$table\".\"$column\" AS '$table.$column'";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( array_keys( $tableColumns ) as $table ) {
|
|
|
|
$tableKey = $this->primaryKeys[$table];
|
|
|
|
$primaryKey = $this->primaryKeys[$this->primaryClass];
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( $table != $this->primaryClass )
|
2008-11-23 01:31:06 +01:00
|
|
|
$joins[] = "LEFT JOIN \"$table\" ON \"$table\".\"$tableKey\"=\"{$this->primaryClass}\".\"$primaryKey\"";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$query = new SQLQuery( $selectFields, $joins );
|
|
|
|
return $query->execute();
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function htmlHeaderCell( $value, $table, $column ) {
|
|
|
|
return "<th>" . htmlentities( $value ) . "</th>";
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function htmlTableCell( $value, $table, $column ) {
|
2007-09-16 03:50:07 +02:00
|
|
|
return "<td>" . htmlentities( $value ) . "</td>";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function htmlTableRow( $value, $table, $column ) {
|
|
|
|
return "<tr>" . $value . "</tr>";
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function csvCell( $value, $table, $column ) {
|
|
|
|
return '"' . str_replace( '"', '""', $value ) . '",';
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function csvRow( $value, $table, $column ) {
|
|
|
|
return substr( $value, 0, strlen( $value ) - 1 )."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Assisting class. Determines whether or not a column is hidden.
|
|
|
|
* Not so helpful here, but we could overload it in other classes.
|
2008-10-16 15:44:20 +02:00
|
|
|
* @deprecated 2.3 Use TableListField
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-reports
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class ReportField_SimpleFilter extends Object {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $hiddenFields;
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function __construct( $hiddenColumns ) {
|
|
|
|
$this->hiddenFields = $hiddenColumns;
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function columnIsVisible( $table, $column ) {
|
|
|
|
return !isset( $this->hiddenFields[$table.'.'.$column] );
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function showColumn( $table, $column ) {
|
|
|
|
unset( $this->hiddenFields[$table.'.'.$column] );
|
2007-09-16 03:50:07 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function hideColumn( $table, $column ) {
|
|
|
|
$this->hiddenFields[$table.'.'.$column] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* This class instantiates an instance of the report field and receives ajax requests
|
|
|
|
* to the report field.
|
2008-10-16 15:44:20 +02:00
|
|
|
* @deprecated 2.3 Use TableListField
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-reports
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class ReportField_Controller extends Controller {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function exporttocsv() {
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( $this->urlParams['Type'] != 'ReportField' && ClassInfo::exists( $this->urlParams['Type'].'_Controller' ) ) {
|
|
|
|
$type = $this->urlParams['Type'].'_Controller';
|
|
|
|
$controller = new $type();
|
|
|
|
return $controller->exporttocsv( $this->urlParams['ID'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
$pageID = $this->urlParams['ID'];
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( !$pageID )
|
|
|
|
return "ERROR:Page does not exist";
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$page = DataObject::get_by_id( 'SiteTree', $pageID );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if( !$page )
|
|
|
|
return "ERROR:Page does not exist";
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
$formName = substr( $this->urlParams['OtherID'], 0, -4 );
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$reportField = $page->getReportField( $formName );
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// apply filters
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$fileName = $page->URLSegment . "-report.csv";
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$reportField->exportToCSV( $fileName );
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function Link() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2007-09-16 03:50:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
?>
|