phpBMS

root/trunk/phpbms/report/general_sql.php

Revision 703, 6.4 KB (checked in by brieb, 2 years ago)
  • Rearranged payment processing routine to be more flexible. It now needs to save the sales order first
  • Added payment processing template so developers have a guide when putting together their payment scripts
  • It seems their might be some unintentional touching of other files in this commit;
Line 
1<?php
2/*
3 $Rev: 258 $ | $LastChangedBy: brieb $
4 $LastChangedDate: 2007-08-08 21:59:28 -0600 (Wed, 08 Aug 2007) $
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*/
39if(!class_exists("phpbmsReport"))
40    include("report_class.php");
41
42/**
43 * Handles creation of SQL insert records
44 *
45 * This class handles the file creation of SQL Insert records that
46 * correspond to the table definition main table that intializes a print of this
47 * report
48 */
49class sqlExport 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     * function generalTablePrint
59     *
60     * Initialization function
61     *
62     * @param object $db database object
63     * @param string $reportUUID UUID of report record
64     * @param string $tabledefUUID UUID of table definition intializing print
65     */
66    function sqlExport($db, $reportUUID, $tabledefUUID){
67
68        parent::phpbmsReport($db, $reportUUID, $tabledefUUID);
69
70        $therecord = $this->getTableDefInfo();
71
72        $this->maintable = $therecord["maintable"];
73
74    }//end function init
75
76
77    /**
78     * function generate
79     *
80     * Generates the SQL Insert statements for each record
81     */
82    function generate(){
83
84        $querystatement = "
85            SELECT
86                *
87            FROM
88                ".$this->maintable;
89
90        $querystatement = $this->assembleSQL($querystatement);
91
92        $queryresult = $this->db->query($querystatement);
93
94        $num_fields = $this->db->numFields($queryresult);
95
96        $statementstart = "INSERT INTO `".$this->maintable."` (";
97
98        for($i=0; $i<$num_fields ;$i++)
99             $statementstart .= "`".$this->db->fieldName($queryresult,$i)."`, ";
100
101        $statementstart = substr($statementstart,0,strlen($statementstart)-2).") VALUES (";
102
103        while($therecord = $this->db->fetchArray($queryresult)){
104
105            $insertstatement = $statementstart;
106
107            foreach($therecord as $name => $field){
108
109                if($field === NULL)
110                     $addfield = "NULL, ";
111                else
112                     $addfield = "'".mysql_real_escape_string($field)."', ";
113
114                //this is in temp for intallation exporting
115                if(hasRights("Admin")){
116
117                    switch($name){
118
119                        case "createdby":
120                        case "modifiedby":
121                            $addfield = "1, ";
122                            break;
123
124                        case "creationdate":
125                        case "modifieddate":
126                            $addfield = "NOW(), ";
127                            break;
128
129                    }//end switch
130
131                }//endif
132
133                $insertstatement .= $addfield;
134
135            }//endforeach
136
137            $insertstatement = substr($insertstatement,0,strlen($insertstatement)-2).");\n";
138
139            $this->reportOutput .= $insertstatement;
140
141        }//endwhile
142
143    }//end function generate
144
145    /**
146     * function show
147     *
148     * outputs the report to a .sql file
149     */
150    function show(){
151
152        if(!isset($this->settings["filename"]))
153           $this->settings["filename"] = $this->maintable."-export.sql";
154
155        header("Content-type: text/plain");
156        header('Content-Disposition: attachment; filename="'.$this->settings["filename"].'"');
157
158        echo $this->reportOutput;
159
160    }//end function show
161
162}//end class sqlExport
163
164
165/**
166 * PROCESSING
167 * =============================================================================
168 */
169if(!isset($noOutput)){
170
171    session_cache_limiter('private');
172
173    require_once("../include/session.php");
174
175    checkForReportArguments();
176
177    $report = new sqlExport($db, $_GET["rid"],$_GET["tid"]);
178    $report->setupFromPrintScreen();
179    $report->generate();
180    $report->show();
181
182}//end if
183
184/**
185 * When adding a new report record, the add/edit needs to know what the class
186 * name is so that it can instantiate it, and grab it's default settings.
187 */
188if(isset($addingReportRecord))
189    $reportClass ="pdfLabels";
190
191?>
Note: See TracBrowser for help on using the browser.
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.