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/modules/base/include/reports.php

    r583 r693  
    3838*/ 
    3939if(class_exists("phpbmsTable")) { 
    40         class reports extends phpbmsTable{ 
    41  
    42                 var $_availableTabledefUUIDs = NULL; 
    43                 var $_availableRoleUUIDs = NULL; 
    44  
    45                 function getDefaults(){ 
    46                         $therecord = parent::getDefaults(); 
    47  
    48                         $therecord["type"]="report"; 
    49                         $therecord["uuid"] = uuid("reports:"); 
    50  
    51                         return $therecord; 
    52  
    53                 } 
    54  
    55  
    56                 function verifyVariables($variables){ 
    57  
    58                         //cannot be table default ("") 
    59                         if(isset($variables["reportfile"])){ 
    60                                 if($variables["reportfile"] === "" || $variables["reportfile"] === NULL) 
    61                                         $this->verifyErrors[] = "The `reportfile` field must not be blank."; 
    62                         }else 
    63                                 $this->verifyErrors[] = "The `reportfile` field must be set."; 
    64  
    65                         //Table default (NULL) OK 
    66                         if(isset($variables["type"])) 
    67                                 if($variables["type"] !== "")//don't care if it's "" 
    68                                         switch($variables["type"]){ 
    69                                                 case "report": 
    70                                                 case "PDF Report": 
    71                                                 case "export": 
    72                                                         break; 
    73  
    74                                                 default: 
    75                                                         $this->verifyErrors[] = "The `type` field is not an accepted value.  It must be 'report', 'PDF Report', or 'export."; 
    76                                                 break; 
    77  
    78                                         }//end switch 
    79  
    80                         //Table Default ('') ok becuase it means report is globally available to any table 
    81                         if(isset($variables["tabledefid"])){ 
    82  
    83                                 if($this->_availableTabledefUUIDs === NULL){ 
    84                                         $this->_availableTabledefUUIDs = $this->_loadUUIDList("tabledefs"); 
    85                                         //add the global option 
    86                                         $this->_availableTabledefUUIDs[] = ""; 
    87                                 }//end if 
    88  
    89                                 if( !in_array((string)$variables["tabledefid"], $this->_availableTabledefUUIDs) ) 
    90                                         $this->verifyErrors[] = "The `tabledefid` field does not give an existing/acceptable table definition uuid."; 
    91  
    92                         }//end if 
    93  
    94                         //Table Default ('') ok becuase it means report is globally available to any user 
    95                         if(isset($variables["roleid"])){ 
    96  
    97                                 if($this->_availableRoleUUIDs === NULL){ 
    98                                         $this->_availableRoleUUIDs = $this->_loadUUIDList("roles"); 
    99                                         $this->_availableRoleUUIDs[] = ""; // for no role restrictions 
    100                                         $this->_availableRoleUUIDs[] = "Admin"; //for the Admin restriction 
    101                                 }//end if 
    102  
    103                                 if( !in_array((string)$variables["roleid"], $this->_availableRoleUUIDs) ) 
    104                                         $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable to role id number."; 
    105  
    106                         }//end if 
    107  
    108                         return parent::verifyVariables($variables); 
    109  
    110                 }//end method 
    111  
    112  
    113                 function displayTables($fieldname,$selectedid){ 
    114  
    115                         $querystatement="SELECT uuid, displayname FROM tabledefs ORDER BY displayname"; 
    116                         $thequery=$this->db->query($querystatement); 
    117  
    118                         echo "<select id=\"".$fieldname."\" name=\"".$fieldname."\">\n"; 
    119  
    120                         echo "<option value=\"\" "; 
    121                         if ($selectedid=="") echo "selected=\"selected\""; 
    122                         echo " style=\"font-weight:bold\">global</option>\n"; 
    123  
    124                         while($therecord=$this->db->fetchArray($thequery)){ 
    125                                 echo "  <option value=\"".$therecord["uuid"]."\""; 
    126                                         if($selectedid==$therecord["uuid"]) echo " selected=\"selected\""; 
    127                                 echo ">".$therecord["displayname"]."</option>\n"; 
    128                         } 
    129  
    130                         echo "</select>\n"; 
    131                 }//end method 
    132  
    133         }//end class 
     40    class reports extends phpbmsTable{ 
     41 
     42        var $_availableTabledefUUIDs = NULL; 
     43        var $_availableRoleUUIDs = NULL; 
     44 
     45        function getDefaults(){ 
     46 
     47            $therecord = parent::getDefaults(); 
     48 
     49            $therecord["type"] = "report"; 
     50 
     51            return $therecord; 
     52 
     53        }//end function getDefaults 
     54 
     55 
     56        function verifyVariables($variables){ 
     57 
     58            //cannot be table default ("") 
     59            if(isset($variables["reportfile"])){ 
     60                if($variables["reportfile"] === "" || $variables["reportfile"] === NULL) 
     61                    $this->verifyErrors[] = "The `reportfile` field must not be blank."; 
     62            }else 
     63                $this->verifyErrors[] = "The `reportfile` field must be set."; 
     64 
     65            //Table default (NULL) OK 
     66            if(isset($variables["type"])) 
     67                if($variables["type"] !== "")//don't care if it's "" 
     68                    switch($variables["type"]){ 
     69 
     70                            case "report": 
     71                            case "PDF Report": 
     72                            case "export": 
     73                                break; 
     74 
     75                            default: 
     76                                $this->verifyErrors[] = "The `type` field is not an accepted value.  It must be 'report', 'PDF Report', or 'export."; 
     77                            break; 
     78 
     79                    }//end switch 
     80 
     81            //Table Default ('') ok becuase it means report is globally available to any table 
     82            if(isset($variables["tabledefid"])){ 
     83 
     84                if($this->_availableTabledefUUIDs === NULL){ 
     85 
     86                    $this->_availableTabledefUUIDs = $this->_loadUUIDList("tabledefs"); 
     87 
     88                    //add the global option 
     89                    $this->_availableTabledefUUIDs[] = ""; 
     90 
     91                }//end if 
     92 
     93                if( !in_array((string)$variables["tabledefid"], $this->_availableTabledefUUIDs) ) 
     94                    $this->verifyErrors[] = "The `tabledefid` field does not give an existing/acceptable table definition uuid."; 
     95 
     96            }//end if 
     97 
     98            //Table Default ('') ok becuase it means report is globally available to any user 
     99            if(isset($variables["roleid"])){ 
     100 
     101                if($this->_availableRoleUUIDs === NULL){ 
     102 
     103                    $this->_availableRoleUUIDs = $this->_loadUUIDList("roles"); 
     104                    $this->_availableRoleUUIDs[] = ""; // for no role restrictions 
     105                    $this->_availableRoleUUIDs[] = "Admin"; //for the Admin restriction 
     106 
     107                }//end if 
     108 
     109                if( !in_array((string)$variables["roleid"], $this->_availableRoleUUIDs) ) 
     110                    $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable to role id number."; 
     111 
     112            }//end if 
     113 
     114            return parent::verifyVariables($variables); 
     115 
     116        }//end method 
     117 
     118 
     119        function insertRecord($variables, $createdby = NULL, $overrideID = false, $replace = false, $useUuid = false){ 
     120 
     121            $newid = parent::insertRecord($variables, $createdby, $overrideID, $replace, $useUuid); 
     122 
     123            $reportSettings = new reportSettings($this->db, $variables["uuid"]); 
     124            $reportSettings->createFromDefaults($variables["reportfile"]); 
     125 
     126            return $newid; 
     127 
     128        }//end method 
     129 
     130 
     131        function updateRecord($variables, $modifiedby = NULL, $useUuid = false){ 
     132 
     133            parent::updateRecord($variables, $modifiedby, $useUuid); 
     134 
     135            $reportSettings = new reportSettings($this->db, $variables["uuid"]); 
     136            $reportSettings->save($variables["rsDelList"], $variables["rsUpdates"], $variables["rsAdds"]); 
     137 
     138        }//end method updateRecord 
     139 
     140 
     141        function displayTables($fieldname,$selectedid){ 
     142 
     143            $querystatement="SELECT uuid, displayname FROM tabledefs ORDER BY displayname"; 
     144            $thequery=$this->db->query($querystatement); 
     145 
     146            echo "<select id=\"".$fieldname."\" name=\"".$fieldname."\">\n"; 
     147 
     148            echo "<option value=\"\" "; 
     149            if ($selectedid=="") echo "selected=\"selected\""; 
     150            echo " style=\"font-weight:bold\">global</option>\n"; 
     151 
     152            while($therecord=$this->db->fetchArray($thequery)){ 
     153                    echo "      <option value=\"".$therecord["uuid"]."\""; 
     154                            if($selectedid==$therecord["uuid"]) echo " selected=\"selected\""; 
     155                    echo ">".$therecord["displayname"]."</option>\n"; 
     156            } 
     157 
     158            echo "</select>\n"; 
     159 
     160        }//end method 
     161 
     162 
     163        /** 
     164         * function displayFiles 
     165         * 
     166         * Displays a list of possible report filenames.  This includes 
     167         * all PHP files in the main report folder, as well as in the report 
     168         * folder of any loaded module 
     169         */ 
     170        function displayRerportFiles(){ 
     171 
     172            $files = array(); 
     173 
     174            $curDir = getcwd(); 
     175 
     176            chdir("../.."); 
     177 
     178            /** 
     179             * Load core reports 
     180             */ 
     181            if(file_exists("report") && is_dir("report")){ 
     182 
     183                $thedir = @ opendir("report"); 
     184 
     185                    while($entry = @ readdir($thedir)) 
     186                        if(@ strtolower(substr($entry, -4)) == ".php") 
     187                            $files[] = "report/".$entry; 
     188 
     189            }//endif 
     190 
     191            chdir("modules"); 
     192 
     193            /** 
     194             * Get loaded modules 
     195             */ 
     196            $querystatement = " 
     197                SELECT 
     198                    `name` 
     199                FROM 
     200                    `modules`"; 
     201 
     202            $queryresult = $this->db->query($querystatement); 
     203 
     204            while($therecord = $this->db->fetchArray($queryresult)){ 
     205 
     206                chdir($therecord["name"]); 
     207 
     208                $thedir = @ opendir("report"); 
     209 
     210                    while($entry = @ readdir($thedir)) 
     211                        if(@ strtolower(substr($entry, -4)) == ".php") 
     212                            $files[] = "modules/".$therecord["name"]."/report/".$entry; 
     213 
     214                chdir(".."); 
     215 
     216            }//endwhile 
     217 
     218            chdir($curDir); 
     219 
     220            ?><label for="reportfile">report file</label><br /> 
     221            <select id="reportfile" name="reportfile"> 
     222                <?php foreach($files as $filename){?> 
     223                    <option value="<?php echo $filename; ?>"><?php echo $filename; ?></option> 
     224                <?php }//endforeach?> 
     225            </select><?php 
     226 
     227        }//end function displayReportFiles 
     228 
     229    }//end class 
     230 
     231 
     232 
     233    /** 
     234     * handles retrieval, display and saving of report settings records 
     235     */ 
     236    class reportSettings{ 
     237 
     238        /** 
     239         * $db 
     240         * @var object the database object 
     241         */ 
     242        var $db; 
     243 
     244        /** 
     245         * $reportUUID 
     246         * @var string report UUID 
     247         */ 
     248        var $reportUUID; 
     249 
     250        /** 
     251         * $settingsQueryResult 
     252         * @var int query result reference 
     253         */ 
     254        var $settingsQueryResult; 
     255 
     256 
     257        /** 
     258         * function reportSettings 
     259         * 
     260         * Class initializer 
     261         * 
     262         * @param object $db database object 
     263         * @param string $reportUUID associated report's UUID 
     264         */ 
     265        function reportSettings($db, $reportUUID){ 
     266 
     267            $this->db = $db; 
     268            $this->reportUUID = $reportUUID; 
     269 
     270        }//end function reportSettings (init) 
     271 
     272 
     273        /** 
     274         * function get 
     275         * 
     276         * retrieves query result for all report settings asociated with report 
     277         */ 
     278        function get(){ 
     279 
     280            $querystatement = " 
     281                SELECT 
     282                    `id`, 
     283                    `name`, 
     284                    `value`, 
     285                    `type`, 
     286                    `required`, 
     287                    `description` 
     288                FROM 
     289                    `reportsettings` 
     290                WHERE 
     291                    `reportuuid` = '".$this->reportUUID."'"; 
     292 
     293            $this->settingsQueryResult = $this->db->query($querystatement); 
     294 
     295        }//end function get 
     296 
     297 
     298        /** 
     299         * function display 
     300         * 
     301         * Display all settings records one TR for each 
     302         */ 
     303        function display(){ 
     304 
     305            if($this->db->numRows($this->settingsQueryResult) == 0){ 
     306 
     307                ?><tr class="norecords" id="noSettings"><td colspan="5">No Settings</td></tr><?php 
     308 
     309                return; 
     310 
     311            }//endif 
     312 
     313            $row = 1; 
     314 
     315            while($therecord = $this->db->fetchArray($this->settingsQueryResult)){ 
     316 
     317                ?> 
     318                <tr class="qr<?php echo $row; ?> rsRows" id="rsExRow<?php echo $therecord["id"] ?>"> 
     319                    <td align="right"> 
     320                        <strong><?php echo formatVariable($therecord["name"]) ?></strong> 
     321                        <input class="rsNames" id="rsName<?php echo $therecord["id"]?>" type="hidden" value="<?php echo formatVariable($therecord["name"]) ?>" /> 
     322                    </td> 
     323                    <td> 
     324                        <?php if($therecord["type"] != "text") {?> 
     325                        <input class="rsValues" id="rsValue<?php echo $therecord["id"] ?>" type="text" size="32" value="<?php echo formatVariable(addcslashes($therecord["value"],"\\\n\t\r")) ?>" /> 
     326                        <?php } else { 
     327                            ?> 
     328                            <textarea class="rsValues" id="rsValue<?php echo $therecord["id"] ?>" rows="2" cols="29"><?php echo formatVariable(addcslashes($therecord["value"],"\\\n\t\r")) ?></textarea> 
     329                            <?php 
     330                        }?> 
     331                    </td> 
     332                    <td><?php echo formatVariable($therecord["type"]) ?></td> 
     333                    <td><?php echo formatVariable($therecord["description"]) ?></td> 
     334                    <td><?php 
     335                        if($therecord["required"] != 1){ 
     336 
     337                            ?><button type="button" id="rsDelButton<?php echo $therecord["id"]?>" class="graphicButtons buttonMinus rsDelButtons" title="Remove Setting"><span>-</span></button><?php 
     338 
     339                        }//endif 
     340                    ?></td> 
     341                </tr> 
     342                <?php 
     343 
     344                $row = ($row==1) ? 2 : 1; 
     345 
     346            }//endwhile 
     347 
     348        }//end function display 
     349 
     350 
     351        /** 
     352         * function save 
     353         * 
     354         * saves report settings changes 
     355         * 
     356         * @param string $delList JSON string of ids to be deleted 
     357         * @param string $updateList JSON string of updates to be made 
     358         * @param string $addList JSON string of name/value pairs to be added 
     359         */ 
     360        function save($delList, $updateList, $addList){ 
     361 
     362            $delList = json_decode(stripslashes($delList)); 
     363            if(count($delList)){ 
     364 
     365                $inClause = ""; 
     366 
     367                foreach($delList as $id){ 
     368 
     369                    $inClause .= ", ".$id; 
     370 
     371                }//endforeach 
     372 
     373                $deletestatement = " 
     374                    DELETE FROM 
     375                        `reportsettings` 
     376                    WHERE 
     377                        `id` IN (".substr($inClause, 1).")"; 
     378 
     379                $this->db->query($deletestatement); 
     380 
     381            }//endif 
     382 
     383            $updateList = str_replace("\n", "\\\\n", $updateList); 
     384            $updateList = str_replace("\r", "", $updateList); 
     385            $updateList = json_decode(stripslashes($updateList)); 
     386 
     387            foreach($updateList as $updateObj){ 
     388 
     389                $updatestatement = ' 
     390                    UPDATE 
     391                        `reportsettings` 
     392                    SET 
     393                        `value` = "'.mysql_real_escape_string($updateObj->value).'" 
     394                    WHERE 
     395                        `id` = '.((int) $updateObj->id); 
     396 
     397                $this->db->query($updatestatement); 
     398 
     399            }//endforeach 
     400 
     401 
     402            $addList = str_replace("\n", "\\\\n", $addList); 
     403            $addList = str_replace("\r", "", $addList); 
     404            $addList = json_decode(stripslashes($addList)); 
     405 
     406            foreach($addList as $addObj){ 
     407 
     408                $insertstatement = ' 
     409                    INSERT INTO 
     410                        `reportsettings` 
     411                    ( 
     412                        `reportuuid`, 
     413                        `name`, 
     414                         `value` 
     415                    ) VALUES ( 
     416                        "'.$this->reportUUID.'", 
     417                        "'.mysql_real_escape_string($addObj->name).'", 
     418                        "'.mysql_real_escape_string($addObj->value).'" 
     419                    )'; 
     420 
     421                $this->db->query($insertstatement); 
     422 
     423            }//endforeach 
     424 
     425        }//end function save 
     426 
     427 
     428        /** 
     429         * function createFromDefaults 
     430         * 
     431         * Creates reportsettings records for report based on defaults from the class 
     432         * instanciated by filename 
     433         * 
     434         * @param string $filename file name of report file to retrieve class from 
     435         */ 
     436        function createFromDefaults($filename){ 
     437 
     438            $addingReportRecord = true; 
     439            $noOutput = true; 
     440 
     441            include_once("report/report_class.php"); 
     442 
     443            include($filename); 
     444 
     445            if(!isset($reportClass)) 
     446                $error = new appError(200, "Report file is missing reportClass definition", "Report File Error"); 
     447            else 
     448                $report = new $reportClass($this->db, $this->reportUUID, "tbld:d595ef42-db9d-2233-1b9b-11dfd0db9cbb"); 
     449 
     450            $settings = $report->addingRecordDefaultSettings(); 
     451 
     452            $startInsertStatement = " 
     453                    INSERT INTO 
     454                        `reportsettings` 
     455                    ( 
     456                        `reportuuid`, 
     457                        `name`, 
     458                        `value`, 
     459                        `type`, 
     460                        `required`, 
     461                        `defaultvalue`, 
     462                        `description` 
     463                    ) VALUES ( 
     464                        '".$this->reportUUID."',"; 
     465 
     466            foreach($settings as $setting){ 
     467 
     468                $insertstatement = $startInsertStatement; 
     469                $insertstatement .= "'".$setting["name"]."', " ; 
     470                $insertstatement .= "'".$setting["defaultValue"]."', " ; 
     471                $insertstatement .= "'".$setting["type"]."', " ; 
     472                $insertstatement .= ((int) $setting["required"]).", " ; 
     473                $insertstatement .= "'".$setting["defaultValue"]."', " ; 
     474                $insertstatement .= "'".$setting["description"]."')" ; 
     475 
     476                $this->db->query($insertstatement); 
     477 
     478            }//endforeach 
     479 
     480        }//end function createFromDefaults 
     481 
     482    }//end class 
     483 
     484}//end if 
     485 
     486if(class_exists("searchFunctions")){ 
     487 
     488    class tabledefsSearchFunctions extends searchFunctions{ 
     489 
     490        function delete_record($useUUID = false){ 
     491 
     492            if(!$useUUID){ 
     493 
     494                $whereclause = $this->buildWhereClause(); 
     495                //support tables link to tabledefs using uuids not ids, so we must make sure that they are uuids. 
     496                $this->idsArray = getUuidArray($this->db, "tbld:d595ef42-db9d-2233-1b9b-11dfd0db9cbb", $this->idsArray); 
     497 
     498            }else 
     499                $whereclause = $this->buildWhereClause($this->maintable.".uuid"); 
     500 
     501            $linkedwhereclause = $this->buildWhereClause("reportuuid"); 
     502 
     503            $querystatement = "DELETE FROM reportsettings WHERE ".$linkedwhereclause.";"; 
     504            $queryresult = $this->db->query($querystatement); 
     505 
     506            $querystatement = "DELETE FROM reports WHERE ".$whereclause.";"; 
     507            $queryresult = $this->db->query($querystatement); 
     508 
     509            $message = $this->buildStatusMessage(); 
     510            $message.=" deleted."; 
     511            return $message; 
     512 
     513        }//end function delete_record 
     514 
     515    }//end class 
     516 
    134517}//end if 
    135518?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.