| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev$ | $LastChangedBy$ |
|---|
| 4 | $LastChangedDate$ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2010, Kreotek LLC | |
|---|
| 7 | | All rights reserved. | |
|---|
| 8 | +-------------------------------------------------------------------------+ |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions are | |
|---|
| 12 | | met: | |
|---|
| 13 | | | |
|---|
| 14 | | - Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | | |
|---|
| 17 | | - Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution. | |
|---|
| 20 | | | |
|---|
| 21 | | - Neither the name of Kreotek LLC nor the names of its contributore may | |
|---|
| 22 | | be used to endorse or promote products derived from this software | |
|---|
| 23 | | without specific prior written permission. | |
|---|
| 24 | | | |
|---|
| 25 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 26 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 27 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
|---|
| 28 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 29 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 30 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 31 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 32 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 33 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 34 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 35 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 36 | | | |
|---|
| 37 | +-------------------------------------------------------------------------+ |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | if(!class_exists("phpbmsReport")) |
|---|
| 41 | include("report_class.php"); |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * Record Reporting in HTML table format |
|---|
| 45 | * |
|---|
| 46 | * This class implements a report used for printing out general table information |
|---|
| 47 | * in HTML table format |
|---|
| 48 | */ |
|---|
| 49 | class generalTablePrint extends phpbmsReport { |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * $maintable |
|---|
| 53 | * @var string the SQL name of the main table to print. |
|---|
| 54 | */ |
|---|
| 55 | var $maintable = ""; |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * $displayname |
|---|
| 59 | * @var string display name of table definition |
|---|
| 60 | */ |
|---|
| 61 | var $displayname = ""; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * function generalTablePrint |
|---|
| 66 | * |
|---|
| 67 | * Initialization function |
|---|
| 68 | * |
|---|
| 69 | * @param object $db database object |
|---|
| 70 | * @param string $reportUUID UUID of report record |
|---|
| 71 | * @param string $tabledefUUID UUID of table definition intializing print |
|---|
| 72 | */ |
|---|
| 73 | function generalTablePrint($db, $reportUUID, $tabledefUUID){ |
|---|
| 74 | |
|---|
| 75 | parent::phpbmsReport($db, $reportUUID, $tabledefUUID); |
|---|
| 76 | |
|---|
| 77 | $therecord = $this->getTableDefInfo(); |
|---|
| 78 | |
|---|
| 79 | $this->maintable = $therecord["maintable"]; |
|---|
| 80 | $this->displayname = $therecord["displayname"]; |
|---|
| 81 | |
|---|
| 82 | }//end function init |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | * function generate |
|---|
| 87 | * |
|---|
| 88 | * Creates the main part of the report (table) |
|---|
| 89 | */ |
|---|
| 90 | function generate(){ |
|---|
| 91 | |
|---|
| 92 | $fromFields = "*"; |
|---|
| 93 | |
|---|
| 94 | $columns = array(); |
|---|
| 95 | foreach($this->settings as $key=>$value){ |
|---|
| 96 | |
|---|
| 97 | if(strpos($key, "column") === 0){ |
|---|
| 98 | |
|---|
| 99 | $pos = substr($key,6)-1; |
|---|
| 100 | $columns[$pos]["field"] = $value; |
|---|
| 101 | |
|---|
| 102 | if(isset($this->settings["titleColumn".($pos + 1)])) |
|---|
| 103 | $columns[$pos]["title"] = $this->settings["titleColumn".($pos +1)]; |
|---|
| 104 | else |
|---|
| 105 | $columns[$pos]["title"] = ""; |
|---|
| 106 | |
|---|
| 107 | }//endif |
|---|
| 108 | |
|---|
| 109 | }//endforeach |
|---|
| 110 | |
|---|
| 111 | if(count($columns)){ |
|---|
| 112 | |
|---|
| 113 | ksort($columns); |
|---|
| 114 | $columns = array_reverse($columns); |
|---|
| 115 | |
|---|
| 116 | $fromFields = ""; |
|---|
| 117 | foreach($columns as $column){ |
|---|
| 118 | |
|---|
| 119 | $fromFields .= ", ".$column["field"]; |
|---|
| 120 | if($column["title"]) |
|---|
| 121 | $fromFields .= " AS `".$column["title"]."`"; |
|---|
| 122 | |
|---|
| 123 | $fromFields.="\n"; |
|---|
| 124 | |
|---|
| 125 | }//endforeach |
|---|
| 126 | |
|---|
| 127 | $fromFields = substr($fromFields, 1); |
|---|
| 128 | |
|---|
| 129 | }//endif |
|---|
| 130 | |
|---|
| 131 | if(isset($this->settings["fromTable"])) |
|---|
| 132 | $querytable = $this->settings["fromTable"]; |
|---|
| 133 | else |
|---|
| 134 | $querytable = $this->maintable; |
|---|
| 135 | |
|---|
| 136 | $querystatement = " |
|---|
| 137 | SELECT |
|---|
| 138 | ".$fromFields." |
|---|
| 139 | FROM |
|---|
| 140 | ".$querytable; |
|---|
| 141 | |
|---|
| 142 | $querystatement = $this->assembleSQL($querystatement); |
|---|
| 143 | |
|---|
| 144 | $queryresult = $this->db->query($querystatement); |
|---|
| 145 | |
|---|
| 146 | $num_fields = $this->db->numFields($queryresult); |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | if(!isset($this->settings["reportTitle"])) |
|---|
| 150 | $this->settings["reportTitle"] = $this->displayname; |
|---|
| 151 | |
|---|
| 152 | ob_start(); |
|---|
| 153 | |
|---|
| 154 | ?> |
|---|
| 155 | <div id="container"> |
|---|
| 156 | <h1><?php echo formatVariable($this->settings["reportTitle"])?></h1> |
|---|
| 157 | <table id="results"> |
|---|
| 158 | <thead> |
|---|
| 159 | <tr> |
|---|
| 160 | <?php |
|---|
| 161 | |
|---|
| 162 | for($i=0;$i<$num_fields;$i++){ |
|---|
| 163 | |
|---|
| 164 | ?> |
|---|
| 165 | <th <?php if($i == $num_fields-1) echo 'id="lastHeader"' ?>><?php echo $this->db->fieldName($queryresult, $i); ?></th> |
|---|
| 166 | <?php |
|---|
| 167 | |
|---|
| 168 | }//end for |
|---|
| 169 | |
|---|
| 170 | ?> |
|---|
| 171 | </tr> |
|---|
| 172 | </thead> |
|---|
| 173 | |
|---|
| 174 | <tbody> |
|---|
| 175 | <?php |
|---|
| 176 | |
|---|
| 177 | while($therecord = $this->db->fetchArray($queryresult)){ |
|---|
| 178 | |
|---|
| 179 | ?><tr><?php |
|---|
| 180 | |
|---|
| 181 | foreach($therecord as $value){ |
|---|
| 182 | |
|---|
| 183 | ?><td><?php echo formatVariable($value)?></td><?php |
|---|
| 184 | |
|---|
| 185 | }//end foreach |
|---|
| 186 | |
|---|
| 187 | ?></tr><?php |
|---|
| 188 | |
|---|
| 189 | }//endwhile |
|---|
| 190 | |
|---|
| 191 | ?> |
|---|
| 192 | </tbody> |
|---|
| 193 | </table> |
|---|
| 194 | </div> |
|---|
| 195 | <?php |
|---|
| 196 | |
|---|
| 197 | $this->reportOutput = ob_get_contents(); |
|---|
| 198 | ob_end_clean(); |
|---|
| 199 | |
|---|
| 200 | }//end function generate |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | /** |
|---|
| 204 | * function show |
|---|
| 205 | * |
|---|
| 206 | * outputs HTML report |
|---|
| 207 | */ |
|---|
| 208 | function show(){ |
|---|
| 209 | |
|---|
| 210 | global $phpbms; |
|---|
| 211 | $db = &$this->db; |
|---|
| 212 | |
|---|
| 213 | $phpbms->cssIncludes[] = "reports.css"; |
|---|
| 214 | $phpbms->cssIncludes[] = "pages/generaltableprint.css"; |
|---|
| 215 | |
|---|
| 216 | $phpbms->showMenu = false; |
|---|
| 217 | $phpbms->showFooter = false; |
|---|
| 218 | |
|---|
| 219 | include("header.php"); |
|---|
| 220 | |
|---|
| 221 | echo $this->reportOutput; |
|---|
| 222 | |
|---|
| 223 | include("footer.php"); |
|---|
| 224 | |
|---|
| 225 | }//end method |
|---|
| 226 | |
|---|
| 227 | }//end class |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | /** |
|---|
| 231 | * PROCESSING |
|---|
| 232 | * ============================================================================= |
|---|
| 233 | */ |
|---|
| 234 | if(!isset($noOutput)){ |
|---|
| 235 | |
|---|
| 236 | session_cache_limiter('private'); |
|---|
| 237 | |
|---|
| 238 | require_once("../include/session.php"); |
|---|
| 239 | |
|---|
| 240 | checkForReportArguments(); |
|---|
| 241 | |
|---|
| 242 | $report = new generalTablePrint($db, $_GET["rid"], $_GET["tid"]); |
|---|
| 243 | $report->setupFromPrintScreen(); |
|---|
| 244 | $report->generate(); |
|---|
| 245 | $report->show(); |
|---|
| 246 | |
|---|
| 247 | }//end if |
|---|
| 248 | |
|---|
| 249 | /** |
|---|
| 250 | * When adding a new report record, the add/edit needs to know what the class |
|---|
| 251 | * name is so that it can instantiate it, and grab it's default settings. |
|---|
| 252 | */ |
|---|
| 253 | if(isset($addingReportRecord)) |
|---|
| 254 | $reportClass ="generalTablePrint"; |
|---|
| 255 | |
|---|
| 256 | ?> |
|---|