phpBMS

root/trunk/phpbms/include/print_class.php

Revision 729, 8.4 KB (checked in by brieb, 2 years ago)
  • code clean up
  • changed list display of table definitions
  • 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*/
39
40        class printer{
41                var $tableid;
42                var $theids;
43                var $reports;
44                var $maintable;
45                var $openwindows="";
46                var $savedSearches;
47                var $savedSorts;
48
49                var $db;
50
51                function printer($db,$tableid,$theids){
52
53                        $this->db = $db;
54                        $this->tableid = $tableid;
55                        $this->theids = $theids;
56
57                        $querystatement = "
58                                SELECT
59                                        `maintable`
60                                FROM
61                                        `tabledefs`
62                                WHERE
63                                        `uuid` = '".$this->tableid."'
64                                ";
65
66                        $queryresult = $this->db->query($querystatement);
67
68                        $therecord = $this->db->fetchArray($queryresult);
69
70                        $this->maintable = $therecord["maintable"];
71
72                        $securitywhere="";
73                        if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0){
74
75                                foreach($_SESSION["userinfo"]["roles"] as $roleUUID)
76                                        $securitywhere .= ",'".$roleUUID."'";
77
78                                $securitywhere=" AND( `roleid` IN (''".$securitywhere.") OR `roleid` IS NULL)";
79                        }
80
81                        $querystatement = "
82                                SELECT
83                                        `id`,
84                                        `name`,
85                                        `reportfile`,
86                                        `type`,
87                                        `description`,
88                                        `displayorder`
89                                FROM
90                                        `reports`
91                                WHERE
92                                        (
93                                                `tabledefid` = ''
94                                                OR
95                                                `tabledefid` = '".$this->tableid."'
96                                        ) ".$securitywhere."
97                                ORDER BY
98                                        `tabledefid` DESC,
99                                        `displayorder` DESC,
100                                        `name`
101                                ";
102
103                        $queryresult = $this->db->query($querystatement);
104                        if(!$queryresult) $error = new appError(500,"Error retrieving reports.");
105                        $this->reports = $queryresult;
106
107                        $this->savedSearches = $this->getSaved($_SESSION["userinfo"]["id"],"SCH");
108                        $this->savedSorts = $this->getSaved($_SESSION["userinfo"]["id"],"SRT");
109                }
110
111                function saveVariables(){
112                        $_SESSION["printing"]["tableid"]=$this->tableid;
113                        $_SESSION["printing"]["maintable"]=$this->maintable;
114                        $_SESSION["printing"]["theids"]=$this->theids;
115                }
116
117
118                function getSaved($userid,$type){
119
120                        $securitywhere="";
121                        if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0){
122
123                                foreach($_SESSION["userinfo"]["roles"] as $roleUUID)
124                                        $securitywhere .= ",'".$roleUUID."'";
125
126                                $securitywhere = substr($securitywhere, 1);
127
128                                $securitywhere=" AND roleid IN (".$securitywhere.")";
129                        }
130                        $querystring = "
131                                SELECT
132                                        `id`,
133                                        `name`,
134                                        `userid`
135                                FROM
136                                        `usersearches`
137                                WHERE
138                                        `tabledefid`='".$this->tableid."'
139                                        AND
140                                        type=\"".$type."\"
141                                        AND
142                                        (
143                                                (userid = '0' ".$securitywhere.")
144                                                OR
145                                                userid=\"".$userid."\"
146                                        )
147                                ORDER BY
148                                        `userid`,
149                                        `name`";
150
151                        $thequery = $this->db->query($querystring);
152                        return $thequery;
153                }//end function
154
155
156                function donePrinting($backurl){
157                        if(!$backurl)
158                                goURL("search.php?id=".$this->tableid);
159                        else
160                                goURL($backurl);
161                }
162
163
164                function showJavaScriptArray(){
165                        $thereturn = "";
166                        if($this->db->numRows($this->reports)){
167                                $this->db->seek($this->reports,0);
168
169                                while($therecord=$this->db->fetchArray($this->reports))
170                                        $thereturn .= "theReport[theReport.length]=new Array(".$therecord["id"].",\"".$therecord["reportfile"]."\",\"".addslashes($therecord["name"])."\",\"".$therecord["type"]."\",\"".addcslashes(addslashes($therecord["description"]),"\r\n")."\");";
171
172                        } else {
173                                $thereturn= "theReport[theReport.length]=new Array(0,\"\",\"No Reports Available\",\"\",\"\");";
174                        }
175
176                        return $thereturn;
177                }//end method
178
179                function displayReportList(){
180                        ?>
181                   <select name="choosereport[]" id="choosereport" size="12" multiple="multiple" onchange="switchReport(this)">
182                        <?php
183                                if($this->db->numRows($this->reports)){
184                                        $this->db->seek($this->reports,0);
185                                        $displayorder=-1;
186                                        while($therecord=$this->db->fetchArray($this->reports)){
187                                                if ($displayorder!=$therecord["displayorder"]){
188                                                        if($displayorder>0)
189                                                                echo "<option value=\"\">----------------------------------------------------------------</option>\n";
190                                                        $displayorder=$therecord["displayorder"];
191                                                }
192                                                echo "<option value=\"".$therecord["id"]."\">".$therecord["name"]."</option>\n";
193                                        }
194                                } else {?><option value="0">No Reports Available</option><?php }
195                   ?>
196                   </select>
197                   <?php
198                        $phpbms->bottomJS[] = "var thechoice=getObjectFromID(\"choosereport\");thechoice.focus();thechoice.options[0].selected=true;";
199                }
200
201
202        function showSaved($thequery,$selectname){
203                $numrows=$this->db->numRows($thequery);
204                ?>
205                <select name="<?php echo $selectname?>" id="<?php echo $selectname?>" <?php if ($numrows<1) echo "disabled=\"disabled\"" ?>>
206                        <?php if($numrows<1) {?>
207                                <option value="NA">None Saved</option>
208                        <?php
209                                } else {
210                                        $numglobal=0;
211                                        while($therecord=$this->db->fetchArray($thequery))
212                                                if($therecord["userid"]<1) $numglobal++;
213                                        $this->db->seek($thequery,0);
214                        ?>
215                                <?php if($numglobal>0){ ?>
216                                <option value="NA">----- global -----</option>
217                                <?php
218                                        }//end if
219                                        $userqueryline=true;
220                                        while($therecord=$this->db->fetchArray($thequery)){
221                                                if ($therecord["userid"]> 0 and $userqueryline) {
222                                                        $userqueryline=false;
223                                                        ?><option value="NA">----- user ------</option><?php
224                                                }
225                                                ?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php
226                                        }// end while
227                                }//end if
228                        ?>
229                </select>
230                <?php
231        }//end function
232
233        function showFieldSort(){
234
235                //Grab query for all columns (for sort purposes)
236                $querystatement="SELECT * FROM ".$this->maintable." LIMIT 1";
237                $queryresult = $this->db->query($querystatement);
238                if(!$queryresult) $error = new appError(500,"Cannot retrieve Table Information");
239                $numfields = $this->db->numFields($queryresult);
240                for ($i=0;$i<$numfields;$i++) $fieldlist[]=$this->db->fieldName($queryresult,$i);
241
242                ?>
243                <select id="singlefield" name="singlefield" onchange="checkForCustom(this.value)">
244                        <?php
245                                foreach($fieldlist as $field){
246                                        echo "<option value=\"".$field."\"";
247                                        if($field=="id") echo "selected=\"selected\"";
248                                        echo ">".$field."</option>\n";
249                                }
250                        ?>
251                        <option value="**CUSTOM**" class="important">custom SQL</option>
252                </select>
253
254                <?php
255        }
256
257}//end class
258
259?>
Note: See TracBrowser for help on using the browser.
Scanned by Orvant Copyright © 2010 Kreotek, LLC. All Rights reserved.