phpBMS

root/trunk/phpbms/print.php

Revision 745, 11.1 KB (checked in by brieb, 2 years ago)
  • implemented patch from #398 (small typos and bugs)
  • reinstated debug mode now that release is (almost) done
  • Property svn:keywords set to LastChangedBy LastChangedDate LastChangedRevision
Line 
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*/
39require_once("include/session.php");
40require_once("include/print_class.php");
41
42if(!isset($_GET["backurl"])) $_GET["backurl"]="";
43if(isset($_POST["backurl"])) $_GET["backurl"]=$_POST["backurl"];
44
45$tablePrinter= new printer($db,$_SESSION["printing"]["tableid"],$_SESSION["printing"]["theids"]);
46
47$tablePrinter->saveVariables();
48
49if (isset($_POST["command"])){
50        switch($_POST["command"]){
51                case "done":
52                        $tablePrinter->donePrinting($_GET["backurl"]);
53                break;
54                case "print":
55                        //let's build the whereclause
56                        $whereclause="";
57                        $dataprint="";
58                        switch($_POST["therecords"]){
59                                case "all":
60                                        $dataprint="All Records";
61                                break;
62                                case "savedsearch":
63                                        if($_POST["savedsearches"]!="" and $_POST["savedsearches"]!="NA")       {
64                                                $querystatement="SELECT name,sqlclause FROM usersearches WHERE id=".$_POST["savedsearches"];
65                                                $queryresult=$db->query($querystatement);
66                                                If(!$queryresult) $error = new appError(500,"Could not retrieve saved search. ".$querystatement);
67                                                $therecord=$db->fetchArray($queryresult);
68                                                $whereclause="WHERE ".$therecord["sqlclause"];
69                                                $dataprint=$therecord["name"];
70                                        }
71                                break;
72                                case "selected":
73                                        foreach($tablePrinter->theids as $theid){
74                                                $whereclause.=" or ".$tablePrinter->maintable.".id=".$theid;
75                                        }
76                                        $whereclause="where ".substr($whereclause,3);
77                                        $dataprint="Selected Records";
78                                break;
79                        }
80                        $_SESSION["printing"]["whereclause"]=$whereclause;
81                        $_SESSION["printing"]["dataprint"]=$dataprint;
82
83                        //next let's do the sort
84                        $sortorder="";
85                        switch($_POST["thesort"]){
86                                case "single":
87                                        $sortorder=" ORDER BY ".$tablePrinter->maintable.".".$_POST["singlefield"]." ".$_POST["order"];
88                                break;
89                                case "savedsort":
90                                        if($_POST["savedsorts"]!="" and $_POST["savedsorts"]!="NA")     {
91                                                $querystatement="SELECT sqlclause FROM usersearches WHERE id=".$_POST["savedsorts"];
92                                                $queryresult=$db->query($querystatement);
93                                                If(!$queryresult) $error = new appError(500,"Could not retrieve saved search. ".$querystatement);
94                                                $therecord=$db->fetchArray($queryresult);
95                                                $sortorder=" ORDER BY ".$therecord["sqlclause"];
96                                        }
97                                break;
98                        }
99                        $_SESSION["printing"]["sortorder"]=$sortorder;
100
101                        if(isset($_POST["choosereport"])){
102
103                                $tablePrinter->openwindows="";
104
105                                for($i=0;$i<count($_POST["choosereport"]);$i++){
106
107                                        if($_POST["choosereport"][$i]){
108
109                                                $querystatement = "
110                                                    SELECT
111                                                        `uuid`,
112                                                        `reportfile`,
113                                                        `type`
114                                                    FROM
115                                                        `reports`
116                                                    WHERE
117                                                        id = ".$_POST["choosereport"][$i];
118
119                                                $queryresult = $db->query($querystatement);
120
121                                                if(!$queryresult)
122                                                    $error = new appError(100,"Could not Retrieve Report Information");
123
124                                                $reportrecord = $db->fetchArray($queryresult);
125
126                                                $fakeExtForIE="";
127
128                                                if($reportrecord["type"] == "PDF Report")
129                                                        $fakeExtForIE = "' + String.fromCharCode(38) + ' &amp;ext=.pdf";
130
131                                                // make the url unique to avoid using browser cache
132                                                $dateTimeStamp = "' + String.fromCharCode(38) + 'ts=".time();
133
134                                                //javascript open each report in new window
135                                                $tablePrinter->openwindows .= "window.open('".APP_PATH.$reportrecord["reportfile"]."?rid=".urlencode($reportrecord["uuid"])."' + String.fromCharCode(38) + 'tid=".urlencode($tablePrinter->tableid).$dateTimeStamp.$fakeExtForIE."','print".$i."');\n";
136
137                                        }//endif
138
139                                }//endfor
140
141                        }//endif
142
143                break;
144        }
145}
146
147$pageTitle="Print/Export";
148
149$phpbms->showMenu = false;
150
151$phpbms->cssIncludes[] = "pages/print.css";
152
153$phpbms->jsIncludes[] = "common/javascript/print.js";
154
155$phpbms->topJS[] = $tablePrinter->showJavaScriptArray();
156
157if($tablePrinter->openwindows) $phpbms->bottomJS[] = $tablePrinter->openwindows;
158
159include("header.php");
160?>
161<div >
162<div class="bodyline" id="mainbody">
163        <h1><?php echo $pageTitle ?><a name="top"></a></h1>
164
165<form action="print.php" method="post" name="print">
166        <input type="hidden" name="backurl" value="<?php echo $_GET["backurl"]?>" />
167
168        <fieldset id="fsReportInformation" >
169                <legend>report information</legend>
170                <?php
171                        if ($db->numRows($tablePrinter->reports)){
172                                $db->seek($tablePrinter->reports,0);
173                                $therecord=$db->fetchArray($tablePrinter->reports);
174                        } else {
175                                $therecord["id"]=0;
176                                $therecord["reportfile"]="";
177                                $therecord["name"]="";
178                                $therecord["type"]="";
179                                $therecord["description"]="";
180                        }
181                ?>
182                <p>
183                        name<br />
184                        <input name="reportid" type="hidden" value="<?php echo $therecord["id"] ?>" />
185                        <input name="reportfile" type="hidden" value="<?php echo htmlQuotes($therecord["reportfile"]) ?>" />
186                        <input name="name" type="text" class="uneditable important" id="name" value="<?php echo htmlQuotes($therecord["name"]) ?>" size="32" maxlength="64" readonly="readonly" />
187                </p>
188
189                <p>
190                        type<br />
191                        <input name="type" type="text" class="uneditable" id="type" value="<?php echo $therecord["type"] ?>" size="20" maxlength="64" readonly="readonly" />
192                </p>
193                <p>
194                        description<br />
195                        <textarea name="description" cols="45" rows="3" readonly="readonly" id="description" class="uneditable"><?php echo stripcslashes($therecord["description"]) ?></textarea>
196                </p>
197        </fieldset>
198
199        <div id="selectReportsDiv">
200        <fieldset>
201                <legend>select report(s)</legend>
202                <p>available reports<br />
203                        <?php $tablePrinter->displayReportList()?>
204                </p>
205        </fieldset>
206        </div>
207
208        <p><button id="showoptions" class="graphicButtons buttonDown" type="button"><span>more options</span></button></p>
209
210        <div id="moreoptions">
211                <fieldset>
212                        <legend>data</legend>
213                        <p id="showsavedsearches">
214                                <label for="savedsearches">load saved search...</label><br />
215                                <?php $tablePrinter->showSaved($tablePrinter->savedSearches,"savedsearches");?>
216                        </p>
217
218                        <p>
219                                <label class="important" for="therecords">from</label><br />
220                                <select id="therecords" name="therecords" onchange="showSavedSearches(this);">
221                                        <option value="selected">selected records (<?php echo count($tablePrinter->theids) ?> record<?php if(count($tablePrinter->theids)>1) echo "s"?>)</option>
222                                        <option value="savedsearch">saved search...</option>
223                                        <?php if($_SESSION["userinfo"]["admin"]==1){?><option value="all">all records in table</option><?php }?>
224                                </select>
225                        </p>
226                </fieldset>
227
228                <fieldset>
229                        <legend>sort</legend>
230
231                        <p id="savedsortdiv">
232                                <label for="savedsorts">saved sort...</label><br />
233                                <?php $tablePrinter->showSaved($tablePrinter->savedSorts,"savedsorts");?>
234                        </p>
235
236                        <p id="singlesortdiv">
237                                <label for="singlefield">field</label><br />
238                                <?php $tablePrinter->showFieldSort()?>
239                                <select name="order">
240                                        <option value="ASC" selected="selected">Ascending</option>
241                                        <option value="DESC">Descending</option>
242                                </select>
243                        </p>
244                        <p class="important">
245                                <label for="thesort">by</label><br />
246                                <select id="thesort" name="thesort" onchange="showSortOptions(this)">
247                                        <option value="default" selected="selected">report default</option>
248                                        <option value="single">single field</option>
249                                        <option value="savedsort">saved sort...</option>
250                                </select>
251                        </p>
252                </fieldset>
253                <fieldset>
254                        <legend>customizing reports</legend>
255                        <p class="notes">
256                        Many reports feature a logo and your company information.  This information can be set administratively in the configuration area
257                        </p>
258                        <p class="notes">
259                        Need more reports, or want to customize an existing report to meet your specific needs? <br />
260                        if you are unfamiliar with PHP, or programming phpBMS, you can try visiting the
261                        <a href="http://www.phpbms.org">phpBMS project site</a>, or visit <a href="http://kreotek.com">Kreotek's website</a> for more information.
262                        </p>
263                </fieldset>
264        </div>
265        <fieldset class="small">
266                <legend>Pop-Up Windows</legend>
267                <p class="notes">
268                        Each report will display in its own window. If you have disabled
269                        pop-ups within your browser's options or are running a third-party pop-up blocker, the report may not show.
270                </p>
271        </fieldset>
272
273        <p id="printFooter">
274                <input name="command" type="submit" class="Buttons" id="printButton" value="print" accesskey="p" title="print (alt+p)" />
275                <input name="command" type="submit" class="Buttons" id="cancel" value="done" accesskey="d" title="done (alt+d)" />
276        </p>
277   </form>
278</div>
279</div>
280<?php include("footer.php")?>
Note: See TracBrowser for help on using the browser.
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.