Location: PHPKode > projects > FiForms Framework > FiForms/FiForms-includes/FiReports_FiReport.inc.php
<?php
/*
*******************************************************************************
    
    FiReportXML -- Rapid XML Report Generator
    Copyright (C) 2004  Daniel McFeeters

    included with
    
    FiForms -- A collection of PHP classes designed 
    to facilitate rapid development of web-database software

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    The original author of this library can be contacted at the following 
    address:

    Daniel McFeeters
    182 Baker Rd.
    Faubush, KY 42544-6526
    email:databases [at] fiforms [dot] org
    http://www.fiforms.org/


Project Started January 20, 2004
*******************************************************************************
FiForms_FiReport.inc.php

Abstract class for generating a report from a query or tree of queries

*******************************************************************************
*/

if(!isset($FIFORMS_CONFIG))
{
        die('No Configuration found. Did you perhaps call an include file' .
                        ' directly instead of calling it as part of the FiForms' .
                        ' application?'); 
}
require_once("FiReports_XMLDefLoader.inc.php");
require_once($FIFORMS_CONFIG['AUTH_MODULE']);

/* ?><code><?php */


class FiReportField
{
        public $name;
        public $alias;
        public $summary;
        public $format;
        public $formatopts;
        public $layout;
}

class FiReport
{
    public $connections;   // array of connections to database server(s)
                        // Each element in the array contains server, user, 
                        // passwd, link
    //var $parameters;    // array of parameter names
    public $queryset;      // array (tree) of queries
    protected $dynParams;     // array of dynamic parameters (used for sub queries)
    public $reportDefXML;  // the report definition in XML format (without header)
    protected $docString;     // contents of the document to be sent to client
    public $mimetype;      // Mime type of output
    public $user;               // User this report is a member of
    public $group;              // Group this report is a member of
    public $usersAllowed;  // Array of user names allowed
    public $groupsAllowed; // Array of group names allowed
    protected $dynVars;
    public $auth;          // Authentication Module
    public $errorMsg; // Error Messages
    public $fieldInfo;    // Array of FiReportField objects
    public $paramArray;

    function FiReport()
    // Class Constructor
    {
        $this->mimetype = "text/plain";
        $this->auth = new FiFormsAuth();
        $this->dynVars = array(
                        "TODAY" => date("Y-m-d"),
                        "YESTERDAY"=> date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y"))),
                        "YEAR" => date("Y"),
                        "MONTH" => date("m"),
                        "DAY" => date("d"),
                        "USER" => $this->auth->username
                );
        $this->paramArray = array();
        if(is_array($_GET) && is_array($_POST))
        {
            $this->paramArray = array_merge($_GET,$_POST);
        }
        elseif(is_array($_GET))
        {
            $this->paramArray = $_GET;
        }
        elseif(is_array($_POST))
        {
            $this->paramArray = $_POST;
        }
        foreach($this->paramArray as $name => $param)
        {
            if(!get_magic_quotes_gpc())
            {
                $this->paramArray[$name] = addslashes($param);
            }
        } // foreach
        $this->dynParams = array();
    }

    function makeConnections()
    // initialize all connections to the MySQL database
    {
        foreach($this->connections as $connectKey => $cData)
            {
            if($GLOBALS['FIFORMS_CONFIG']['ALLOWED_SERVERS'] == '_ANY_' ||
                in_array($cData->server,
                explode(',',$GLOBALS['FIFORMS_CONFIG']['ALLOWED_SERVERS'])))
                {
                $this->connections[$connectKey]->link = 
                    mysql_connect($cData->server, 
                        $cData->user, $cData->passwd);
            if(!$this->connections[$connectKey]->link)
            {
                $this->errorMsg .= "Error Connecting to ".$cData->server.": ".mysql_error();
            }
                @mysql_select_db(
                    $cData->database,
                        $this->connections[$connectKey]->link 
                        );
                }
            else
            {
                $this->errorMsg .= "Server ".$cData->server." is not allowed in ".$GLOBALS['FIFORMS_CONFIG']['ALLOWED_SERVERS'];
            }
            } 
    }

    function loadDefinition($defString)
    // Load report definition from XML String
    {
        $defLoader = new XMLDefLoader();
        $defLoader->getDefinition($this,$defString);
            unset($defLoader);
    }
    
    function loadDefinitionFromFile($filename)
    // Load report definition from XML String
    {
        $defString = file_get_contents($filename);
        $defLoader = new XMLDefLoader();
        $defLoader->includePath = dirname($filename);
        $defLoader->getDefinition($this,$defString);
            unset($defLoader);
    }

    function parQuery($query)
    // Fill in the parameters in $query and return a valid SQL statement
    {
        $allParams = array_merge($this->paramArray,$this->dynParams,$this->dynVars);
        //$filledQuery = fillVars($this->paramArray,$query);
        //$filledQuery = fillVars($this->dynParams,$filledQuery);
        //$filledQuery = fillVars($this->dynVars,$filledQuery);
        return fillVars($allParams,$query);
    }

    function getDocString()
    // generates the output of the report and stores it in $this->docString
    {
        $this->docString = "Please use one of the child classes of FiReport";
    } // function returnXML

    function generateReport()
    // generates the reports and outputs it to the client
    {
        header("Content-type: ".$this->mimetype."\nContent-Disposition: inline; 
                filename=report.csv");
        $this->getDocString();
            echo $this->docString;
    }

} // class FiReportXML 

/* ?></code><?php */


?>
Return current item: FiForms Framework