Source for file export.php
Documentation is available at export.php
* Export various views of the booking data in numerous formats
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* path (bumblebee root)/inc/actions/export.php
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'inc/bb/configreader.php';
require_once 'inc/formslib/checkbox.php';
/** CheckBoxTableList object */
require_once 'inc/formslib/checkboxtablelist.php';
/** Data reflector object */
require_once 'inc/formslib/datareflector.php';
require_once 'inc/actions/bufferedaction.php';
/** Export formatting codes */
require_once 'inc/exportcodes.php';
/** Export configuration and formatting */
require_once 'inc/export/exporttypes.php';
/** Export method object */
require_once 'inc/export/arrayexport.php';
/** Export method object */
require_once 'inc/export/htmlexport.php';
/** database interrogation object */
require_once 'inc/formslib/dblist.php';
require_once 'inc/formslib/anchortablelist.php';
require_once 'inc/bb/daterange.php';
require_once 'inc/formslib/radiolist.php';
* Export various views of the booking data in numerous formats
* A number of different data views can be created (see exporttypes.php)
* and the data can be exported in various formats (see htmlexport.php and arrayexport.php)
* This class is inherited by other exporters
* forces SQL errors to be fatal
* name of the export format to be used
* object containing export SQL and formatting instructions
* the specific ExportType to be used in this data export
var $_export; // ExportType format description
* The data range to be used for data export
* The original action word (verb!) that instantiated this class (not its descendants)
* Allows HTML links back to this class to be easily made.
* @param BumblebeeAuth $auth Authorisation object
* @param array $pdata extra state data from the call path
echo
$reflector->display($this->PD);
// preDump($this->typelist);
if (! isset
($this->PD['what'])) {
T_('Enter the dates over which you want to export data'));
#echo "don't have date range <br />";
#echo "don't have format<br />";
if (! isset
($this->PD['limitationselected'])) {
#echo "don't have instruments <br />";
parent::mungeInputData();
if (isset
($this->PD['outputformat'])) {
$this->format =
$this->PD['outputformat'];
* Generate HTML list for user to select which data export should be used
$reportlist[$type->name] =
$type->description;
$select->setValuesArray($reportlist, 'id', 'iv');
$select->hrefbase =
makeURL($this->_verb, array('what'=>
'__id__'));
$select->setFormat('id', '%s', array('iv'));
* Generate HTML list for user to select which data format should be used
if ($conf->value('export', 'enablePDF')) {
$select =
new RadioList('outputformat', T_('Select which data to export'), 1);
$select->setValuesArray($formatlist, 'id', 'iv');
$select->setFormat('id', '%s', array('iv'));
if (is_numeric($conf->value('export', 'defaultFormat'))) {
$select->setDefault($conf->value('export', 'defaultFormat'));
echo
'<div style="margin: 2em 0 2em 0;">'.
$select->display().
'</div>';
* Generate HTML form widget for user to control output.
* User can select which sub-view of the data to use
* and which specific parts of the data should be included (i.e. restrict by group)
for ($lim =
0; $lim <
count($export->limitation); $lim++
) {
$hidden =
new TextField($export->limitation[$lim]);
$select->addFollowHidden($hidden);
$chosen =
new CheckBox('selected', T_('Selected'));
$select->addCheckBox($chosen);
//$select->numSpareCols = 1;
if ($export->limitation[$lim] ==
'users') {
$select->connectDB($export->limitation[$lim], array('id', 'name', 'username'));
$select->setFormat('id', '%s', array('name'), " (%s)", array('username'));
$select->connectDB($export->limitation[$lim], array('id', 'name', 'longname'));
$select->setFormat('id', '%s', array('name'), " %50.50s", array('longname'));
$select->addSelectAllFooter(true);
echo
$select->display().
'<br/>';
foreach ($export->pivot as $k =>
$v) {
$views[$k] =
$v['description'];
$viewselect =
new RadioList('pivot', T_('Select which data view to export'), 1);
$viewselect->setValuesArray($views, 'id', 'iv');
$viewselect->setFormat('id', '%s', array('iv'));
$viewselect->setDefault(key($views));
echo
'<div style="margin: 0em 0 2em 0;">'.
$viewselect->display().
'</div>';
echo
'<input type="hidden" name="limitationselected" value="1" />';
* Common submit button for this class
echo
'<input type="submit" name="submit" value="'.
T_('Select').
'" />';
* Generate the data export and then send it to the user in the appropriate format
if (count($list->data) ==
0) {
// start rendering the data
$list->outputFormat =
$this->format;
$exportArray =
new ArrayExport($list, $list->breakfield);
$exportArray->author =
$this->auth->name;
$exportArray->makeExportArray();
//preDump($exportArray->export);
$htmlExport->makeHTMLBuffer();
//finally, direct the data towards its output
// construct the PDF from $htmlbuffer
$pdfExport->makePDFBuffer();
if ($pdfExport->writeToFile) {
// the data itself will be dumped later by the action driver (index.php)
.
$list->outputHeader().
"\n"
.
join($list->formatdata, "\n");
// the data itself will be dumped later by the action driver (index.php)
echo
$htmlExport->wrapHTMLBuffer();
echo
$htmlExport->export;
* Sets up the DBlist object so that it can query the db
* @return DBList query ready to run
$limitsOffset +=
count($export->limitation);
* From the export definition in the ExportType generate a DBList query
* @return void DBList ready for query
$where[] =
$export->timewhere[0].
qw($start->dateTimeString());
$where[] =
$export->timewhere[1].
qw($stop->dateTimeString());
// work out what view/pivot of the data we want to see
if (count($export->limitation) >
1 &&
is_array($export->pivot)) {
$pivot =
$export->pivot[$this->PD['pivot']];
$export->group =
$pivot['group'];
$export->omitFields =
array_flip($pivot['omitFields']);
$export->breakField =
$pivot['breakField'];
if (isset
($pivot['fieldOrder']) &&
is_array($pivot['fieldOrder'])) {
$export->fieldOrder =
$pivot['fieldOrder'];
if (isset
($pivot['extraFields']) &&
is_array($pivot['extraFields'])) {
$export->fields =
array_merge($export->fields, $pivot['extraFields']);
$list =
new DBList($export->basetable, $export->fields, join($where, ' AND '));
$list->group =
$export->group;
$list->manualGroup =
$export->manualGroup;
$list->manualSum =
$export->manualSum;
$list->order =
$export->order;
$list->distinct =
$export->distinct;
$list->fieldOrder =
$export->fieldOrder;
$list->breakfield =
$export->breakField;
$list->omitFields =
$export->omitFields;
* Determine what limitation should be applied to the broad query
* @todo //TODO: there are limitations in the IN() syntax.... replace this with lots of booleans?
* @return array SQL field IN (list...) syntax
for ($lim =
0; $lim <
count($fields); $lim++
) {
$fieldpattern =
'/^limitation\-(\d+)\-(\d+)\-'.
$fields[$lim].
'$/';
for ($j=
0; $j <
count($selected); $j++
) {
if (issetSet($this->PD,'limitation-'.
$ids[1].
'-'.
$ids[2].
'-selected') &&
$item !==
NULL) {
$limitation[] =
/*$export->limitation[$lim].'.id='.*/qw($item);
//echo $namebase.':'.$j.':'.$lim.':'.$fields[$lim].':'.$item.'<br/>';
if (count($limitation)) {
$sets[] =
$fields[$lim].
'.id IN ('.
join($limitation, ', ').
')';
$sets[$fields[$lim]] =
$limitation;
* Set the filename and mimetype for the data export
$type =
'text/tab-separated-values';
//$type = 'application/vnd-excel';
$type =
'application/pdf';
$type =
'application/octet-stream';
* Generate the PDF for return to the user
* @uses PDFExport but only loaded here so that optional library can be absent without compile errors
* @return string $pdf containing the PDF
require_once('inc/export/pdfexport.php');
* Generate the standard report header from the date range and the description in ExportType
* @return string the title to be used for this report
Documentation generated on Tue, 06 Mar 2007 10:01:25 +0000 by phpDocumentor 1.3.0