phpBMS

root/trunk/phpbms/modules/bms/invoices_lineitem_ajax.php

Revision 702, 4.9 KB (checked in by brieb, 2 years ago)

Updated copyrights to 2010

  • 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*/
39session_cache_limiter('private');
40
41include("../../include/session.php");
42
43class productLookup{
44
45        function productLookup($db){
46
47                $this->db = $db;
48
49        }//end method - init
50
51
52        function meetsPrereq($productid, $clientid){
53
54                // This method return true if the client/product
55                // combination return no prerequisites or
56                // if all prerequisites products have been
57                // at least ordered by the client.
58
59                $querystatement = "
60                        SELECT
61                                childid
62                        FROM
63                                prerequisites
64                        WHERE
65                                parentid = '".mysql_real_escape_string($productid)."'
66                ";
67
68                $queryresult = $this->db->query($querystatement);
69
70                if($this->db->numRows($queryresult)){
71
72                        $whereclause = "";
73                        while($therecord = $this->db->fetchArray($queryresult))
74                                $whereclause .= " OR lineitems.productid = '".$therecord["childid"]."'";
75
76                        $whereclause = substr($whereclause, 4);
77
78                        $checkstatement = "
79                                SELECT
80                                        invoices.id
81                                FROM
82                                        invoices INNER JOIN lineitems ON lineitems.invoiceid = invoices.id
83                                WHERE
84                                        invoices.clientid = '".mysql_real_escape_string($clientid)."'
85                                        AND invoices.type != 'Void'
86                                        AND invoices.type != 'Quote'
87                                        AND (".$whereclause.")
88                                ";
89
90                        if($this->db->numRows($this->db->query($checkstatement)) > 0 || $clientid == "");
91                                return false;
92
93                }//endif - numRows
94
95                return true;
96
97        }//end method - checkPrereq
98
99
100        function getInfo($productid){
101
102                $querystatement = "
103                        SELECT
104                                *
105                        FROM
106                                products
107                        WHERE
108                                uuid = '".mysql_real_escape_string($productid)."'
109                ";
110
111                return $this->db->fetchArray($this->db->query($querystatement));
112
113        }//end method - getInfo
114
115
116        function display($record){
117
118                $output = "{ prereqMet: ";
119                if($record){
120
121                        $record["memo"] = str_replace("\r", "", str_replace("\n", " ", $record["memo"]));
122                        $output .= "true, record: {";
123
124                        foreach($record as $key=>$value)
125                                $output .= $key.": '".str_replace("'","\\'",htmlQuotes($value))."',";
126
127                        $output = substr($output,0,-1)."}";
128
129                } else {
130
131                        $output .= "false";
132
133                }//endif - record
134
135                $output .= "}";
136
137                header("Content-type: text/plain");
138                echo $output;
139
140        }//end method display
141
142}//end class - productLookup
143
144
145//processing
146//=========================================================================
147if(isset($_GET["cid"]) && isset($_GET["id"])){
148
149        $lookup = new productLookup($db);
150
151        if($lookup->meetsPrereq($_GET["id"], $_GET["cid"]))
152                $therecord = $lookup->getInfo($_GET["id"]);
153        else
154                $therecord = false;
155
156        $lookup->display($therecord);
157
158}//end if
Note: See TracBrowser for help on using the browser.
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.