phpBMS

Show
Ignore:
Timestamp:
12/31/09 13:36:45 (2 years ago)
Author:
brieb
Message:
  • Introduced administratively changeable settings to indvidual reports
  • Modified all reports to work with new settings system
  • Altered invoice and line item total reports to accept parameters from reportsettings: You can now bypass the grouping/column dialog by providing the infrmation administratively
  • Altered all sales order PDF reports to accept parameters from reportsettings: You can now administratively change certain aspects of the print outs, including what parts of the top of the report to show, and what to title the report
  • Altered label reports to accept parameters from reportsettings: printed data as well

as label measurements and layout are now defined by administratively

  • Altered export and tableprint reports to accept parameters from reportsettings: You can specify individual columns and from table instead of just the defaults (all fields, main table only)
  • Added var_dump-esque 'debug' function for development purposes to common functions
  • Integrated FPDI functionality with sales order PDF reports: It is now possible to use a PDF saved in the files table as a background template for your invoices (e.g. watermarks)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/report/report_class.php

    r441 r693  
    3838*/ 
    3939 
    40         class phpbmsReport{ 
    41                  
    42                 var $db; 
    43                 var $whereclause =""; 
    44                 var $sortorder = ""; 
    45                 var $reportOutput = ""; 
    46                 var $groupBy = ""; 
    47                  
    48                 function phpBMSReport($db){ 
    49                  
    50                         $this->db = $db; 
    51                  
    52                 }//end method 
    53  
    54                  
    55                 function setupFromPrintScreen(){ 
    56                  
    57                         if(isset($_SESSION["printing"]["sortorder"])) 
    58                                 $this->sortorder = $_SESSION["printing"]["sortorder"]; 
    59                                  
    60                         if(isset($_SESSION["printing"]["whereclause"])){ 
    61                                  
    62                                 if(strpos($_SESSION["printing"]["whereclause"],"WHERE") === 0) 
    63                                         $this->whereclause = substr($this->whereclause, 5); 
    64                                          
    65                                 $this->whereclause = $_SESSION["printing"]["whereclause"]; 
    66                                  
    67                         }//endif 
    68                          
    69                         //backwards compatibility 
    70                         if(strpos($this->whereclause, "where ") === 0) 
    71                                 $this->whereclause = substr($this->whereclause, 6);                      
    72                  
    73                 }//end method 
    74  
    75                  
    76                 function assembleSQL($querystatement){ 
    77                          
    78                         if($this->whereclause) 
    79                                 $querystatement .= " 
    80                                         WHERE 
    81                                                 ".$this->whereclause; 
    82                          
    83                         if($this->groupBy) 
    84                                 $querystatement .= " 
    85                                         GROUP BY 
    86                                                 ".$this->groupBy;                        
    87                          
    88                         if($this->sortorder) 
    89                                 $querystatement .= " 
    90                                         ORDER BY 
    91                                                 ".$this->sortorder; 
    92  
    93                         return $querystatement; 
    94                          
    95                 }//end method 
    96                  
    97                 function _showNoRecords(){ 
    98                          
    99                         ?> 
    100                         <h1 id="noRecord">No Records</h1> 
    101                         <p>No valid records for this report.</p> 
    102                         <?php 
    103                          
    104                 }//end method --_showNoRecords-- 
    105          
    106         }//end class 
    107  
     40/** 
     41 * Basic reporting class 
     42 * 
     43 * The phpbmsReport class handles basic processing of reports and report type 
     44 * functions. It is designed to be extended by a specifc report. It provides 
     45 * functions for retrieving the where clause, sort order and group by fields 
     46 * as well as retrieving report settings 
     47 * @author Brian Rieb <brieb@kreotek.com> 
     48 */ 
     49class phpbmsReport{ 
     50 
     51    /** 
     52     * $db 
     53     * @var object the database object 
     54     */ 
     55    var $db; 
     56 
     57    /** 
     58     * $whereClasue 
     59     * @var string whereclause used to filter results 
     60     */ 
     61    var $whereClause = ""; 
     62 
     63    /** 
     64     * $sortOrder 
     65     * @var string sortorder for results 
     66     */ 
     67    var $sortOrder = ""; 
     68 
     69    /** 
     70     * $groupBy 
     71     * @var string sort order for result SQL 
     72     */ 
     73    var $groupBy = ""; 
     74 
     75    /** 
     76     * $reportOutput 
     77     * @var string output generated by report 
     78     */ 
     79    var $reportOutput = ""; 
     80 
     81    /** 
     82     * $settings 
     83     * @var array array of report settings 
     84     */ 
     85    var $settings = array(); 
     86 
     87    /** 
     88     * $reportUUID; 
     89     * @var string UUID of report record 
     90     */ 
     91    var $reportUUID = ""; 
     92 
     93    /** 
     94     * $tabledefUUID 
     95     * @var string UUID of table definition that initiated report 
     96     */ 
     97    var $tabledefUUID = ""; 
     98 
     99 
     100    /** 
     101     * function phpbmsReport 
     102     * 
     103     * Initialization Function 
     104     * 
     105     * @param object $db database object 
     106     * @param string $reportUUID UUID of report record 
     107     * @param string $tabledefUUID UUID of table definition that initiated report 
     108     */ 
     109    function phpBMSReport($db, $reportUUID, $tabledefUUID){ 
     110 
     111        $this->db = $db; 
     112 
     113        $this->reportUUID = mysql_real_escape_string($reportUUID); 
     114 
     115        $this->tabledefUUID = mysql_real_escape_string($tabledefUUID); 
     116 
     117        if($reportUUID) 
     118            $this->retrieveReportSettings(); 
     119 
     120    }//end function init 
     121 
     122 
     123    /** 
     124     * function retrieveReportSettings() 
     125     * 
     126     * Retrieves settings for specific report from database and stores them in 
     127     *  settings array. 
     128     */ 
     129    function retrieveReportSettings(){ 
     130 
     131        $querystatement = " 
     132            SELECT 
     133                `name`, 
     134                `value`, 
     135                `type` 
     136            FROM 
     137                reportsettings 
     138            WHERE 
     139                reportuuid = '".$this->reportUUID."'"; 
     140 
     141        $queryresult = $this->db->query($querystatement); 
     142 
     143        while($therecord = $this->db->fetchArray($queryresult)){ 
     144 
     145            switch($therecord["type"]){ 
     146 
     147                case "int": 
     148                    $therecord["value"] = (int) $therecord["value"]; 
     149                    break; 
     150 
     151                case "bool": 
     152                    $therecord["value"] = (bool) $therecord["value"]; 
     153                    break; 
     154 
     155                case "real": 
     156                    $therecord["value"] = (real) $therecord["value"]; 
     157                    break; 
     158 
     159            }//endswitch 
     160 
     161            $this->settings[$therecord["name"]] = $therecord["value"]; 
     162 
     163        }//endwhile 
     164 
     165    }//end function retrieveReportSettings 
     166 
     167    /** 
     168     * function setupFromPrintScreen 
     169     * 
     170     * Retrieves session information pertaining to printing as set by the print 
     171     * screen. 
     172     */ 
     173    function setupFromPrintScreen(){ 
     174 
     175        if(isset($_SESSION["printing"]["sortorder"])) 
     176            $this->sortOrder = $_SESSION["printing"]["sortorder"]; 
     177 
     178        if(isset($_SESSION["printing"]["whereclause"])){ 
     179 
     180            if(strpos($_SESSION["printing"]["whereclause"],"WHERE") === 0) 
     181                $this->whereClause = substr($this->whereClause, 5); 
     182 
     183            $this->whereClause = $_SESSION["printing"]["whereclause"]; 
     184 
     185        }//endif 
     186 
     187        //backwards compatibility 
     188        if(strpos($this->whereClause, "where ") === 0) 
     189            $this->whereClause = substr($this->whereClause, 6); 
     190 
     191    }//end function setupFromPrintScreen 
     192 
     193    /** 
     194     * function getTableDefInfo 
     195     * 
     196     * Retrieves pertinent table definition information 
     197     * @return array table definition record information 
     198     */ 
     199    function getTableDefInfo(){ 
     200 
     201        $querystatement = " 
     202            SELECT 
     203                * 
     204            FROM 
     205                tabledefs 
     206            WHERE 
     207                uuid = '".$this->tabledefUUID."'"; 
     208 
     209        $queryresult = $this->db->query($querystatement); 
     210 
     211        return $this->db->fetchArray($queryresult); 
     212 
     213    }//end function getTableDefInfo 
     214 
     215    /** 
     216     * function assembleSQL 
     217     * 
     218     * assembles record query 
     219     * 
     220     * @param string $querystatement SELECT and FROM clauses of SQL statement 
     221     * 
     222     * @return string Retruns full SQL statement 
     223     */ 
     224    function assembleSQL($querystatement){ 
     225 
     226        if($this->whereClause) 
     227            $querystatement .= " 
     228                WHERE 
     229                    ".$this->whereClause; 
     230 
     231        if($this->groupBy) 
     232            $querystatement .= " 
     233                GROUP BY 
     234                    ".$this->groupBy; 
     235 
     236        if($this->sortOrder) 
     237            $querystatement .= " 
     238                ORDER BY 
     239                    ".$this->sortOrder; 
     240            return $querystatement; 
     241 
     242    }//end function assembleSQL 
     243 
     244 
     245    /** 
     246     * function showNoRecords 
     247     * 
     248     * Outputs simple no records error 
     249     */ 
     250    function showNoRecords(){ 
     251 
     252        ?> 
     253        <h1 id="noRecord">No Records</h1> 
     254        <p>No valid records for this report.</p> 
     255        <?php 
     256 
     257    }//end function showNoRecords 
     258 
     259 
     260    /** 
     261     * function addingRecordDefaultSettings 
     262     * 
     263     * Creates an array of settings associative arrays for use by the system when 
     264     * a new report record is added that references the file containing this class 
     265     * 
     266     * @retrun array of settings. Each setting should itself be 
     267     * an associative array containing the following 
     268     * name: name of the setting 
     269     * defaultvalue: default value for setting 
     270     * type: (string, text, int, real, bool) type for value of setting 
     271     * required: (0,1) whether the setting is required or not 
     272     * description: brief description for what this setting is used for. 
     273     */ 
     274    function addingRecordDefaultSettings(){ 
     275 
     276        $settings[] = array( 
     277            "name"=>"reportTitle", 
     278            "defaultValue"=>"Report", 
     279            "type"=>"string", 
     280            "required"=>0, 
     281            "description"=>"Report Title" 
     282        ); 
     283 
     284        return $settings; 
     285 
     286    }//endfunction addingRecordDefaultSettings 
     287 
     288}//end class 
     289 
     290/** 
     291 * function checkForReportArguments 
     292 * 
     293 * used before class instatiation to make sure POST arguments are set correctly 
     294 */ 
     295function checkForReportArguments(){ 
     296 
     297    if(!isset($_GET["tid"])) 
     298            $error = new appError(200,"URL variable missing: tid"); 
     299 
     300    if(!isset($_GET["rid"])) 
     301            $error = new appError(200,"URL variable missing: rid"); 
     302 
     303}//end function checkForReportArguments 
    108304?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.