| 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 | session_cache_limiter('private'); |
|---|
| 41 | |
|---|
| 42 | include("../../include/session.php"); |
|---|
| 43 | |
|---|
| 44 | class clientInfo{ |
|---|
| 45 | |
|---|
| 46 | function clientInfo($db){ |
|---|
| 47 | |
|---|
| 48 | $this->db = $db; |
|---|
| 49 | |
|---|
| 50 | }//end method - init |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | function get($uuid){ |
|---|
| 54 | |
|---|
| 55 | $uuid = mysql_real_escape_string($uuid); |
|---|
| 56 | |
|---|
| 57 | $return = $this->_getClient($uuid); |
|---|
| 58 | |
|---|
| 59 | $return["billingaddress"] = $this->_getAddress($uuid, "primary"); |
|---|
| 60 | |
|---|
| 61 | $return["shiptoaddress"] = $this->_getAddress($uuid, "defaultshipto"); |
|---|
| 62 | |
|---|
| 63 | if($return["hascredit"]) |
|---|
| 64 | $return["creditleft"] = $this->_getCreditLeft($uuid, $return["creditlimit"]); |
|---|
| 65 | |
|---|
| 66 | return $return; |
|---|
| 67 | |
|---|
| 68 | }//end method - get |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | function _getClient($uuid){ |
|---|
| 73 | |
|---|
| 74 | $returnArray = array( |
|---|
| 75 | "id" => 0, |
|---|
| 76 | "hascredit" => 0, |
|---|
| 77 | "creditlimit" => 0, |
|---|
| 78 | "creditleft" => 0, |
|---|
| 79 | "type" => "client", |
|---|
| 80 | "paymentmethodid" => "", |
|---|
| 81 | "shippingmethodid" => "", |
|---|
| 82 | "discountid" => "", |
|---|
| 83 | "taxareaid" => "" |
|---|
| 84 | ); |
|---|
| 85 | |
|---|
| 86 | $querystatement = " |
|---|
| 87 | SELECT |
|---|
| 88 | * |
|---|
| 89 | FROM |
|---|
| 90 | clients |
|---|
| 91 | WHERE |
|---|
| 92 | `uuid` = '".$uuid."' |
|---|
| 93 | "; |
|---|
| 94 | |
|---|
| 95 | $therecord = $this->db->fetchArray($this->db->query($querystatement)); |
|---|
| 96 | |
|---|
| 97 | if($therecord){ |
|---|
| 98 | foreach($returnArray as $key =>$value) |
|---|
| 99 | if($key != "creditleft") |
|---|
| 100 | $returnArray[$key] = $therecord[$key]; |
|---|
| 101 | }//endif |
|---|
| 102 | |
|---|
| 103 | return $returnArray; |
|---|
| 104 | |
|---|
| 105 | }//end method - _getClient |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | function _getAddress($clientID, $type){ |
|---|
| 109 | |
|---|
| 110 | $returnArray = array( |
|---|
| 111 | "id" => "", |
|---|
| 112 | "uuid" => "", |
|---|
| 113 | "address1" => "", |
|---|
| 114 | "address2" => "", |
|---|
| 115 | "city" => "", |
|---|
| 116 | "state" => "", |
|---|
| 117 | "postalcode" => "", |
|---|
| 118 | "country" => "", |
|---|
| 119 | "shiptoname" => "", |
|---|
| 120 | ); |
|---|
| 121 | |
|---|
| 122 | $querystatement = " |
|---|
| 123 | SELECT |
|---|
| 124 | addresses.* |
|---|
| 125 | FROM |
|---|
| 126 | addresstorecord INNER JOIN addresses ON addresstorecord.addressid = addresses.uuid |
|---|
| 127 | WHERE |
|---|
| 128 | addresstorecord.tabledefid = 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083' |
|---|
| 129 | AND addresstorecord.recordid = '".$clientID."' |
|---|
| 130 | AND addresstorecord.".$type." = 1"; |
|---|
| 131 | |
|---|
| 132 | $therecord = $this->db->fetchArray($this->db->query($querystatement)); |
|---|
| 133 | |
|---|
| 134 | if($therecord) |
|---|
| 135 | foreach($returnArray as $key =>$value) |
|---|
| 136 | $returnArray[$key] = $therecord[$key]; |
|---|
| 137 | |
|---|
| 138 | return $returnArray; |
|---|
| 139 | |
|---|
| 140 | }//end method - _getAddress |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | function _getCreditLeft($clientID, $creditlimit){ |
|---|
| 144 | |
|---|
| 145 | $querystatement = " |
|---|
| 146 | SELECT |
|---|
| 147 | SUM(`amount` - `paid`) AS amtopen |
|---|
| 148 | FROM |
|---|
| 149 | aritems |
|---|
| 150 | WHERE |
|---|
| 151 | `status` = 'open' |
|---|
| 152 | AND clientid='".$clientID."' |
|---|
| 153 | AND posted=1"; |
|---|
| 154 | |
|---|
| 155 | $arrecord = $this->db->fetchArray($this->db->query($querystatement)); |
|---|
| 156 | |
|---|
| 157 | return ((real) $creditlimit) - ((real) $arrecord["amtopen"]); |
|---|
| 158 | |
|---|
| 159 | }//end method - _getCreditLeft |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | function display($record){ |
|---|
| 164 | |
|---|
| 165 | $output = "{"; |
|---|
| 166 | |
|---|
| 167 | foreach($record as $key=>$value){ |
|---|
| 168 | |
|---|
| 169 | if(!is_array($value)){ |
|---|
| 170 | |
|---|
| 171 | $output.= $key.":'".str_replace("'", "\'", formatVariable($value))."',"; |
|---|
| 172 | |
|---|
| 173 | } else { |
|---|
| 174 | |
|---|
| 175 | $output .= $key.":{"; |
|---|
| 176 | |
|---|
| 177 | foreach($value as $skey => $svalue) |
|---|
| 178 | $output.= $skey.":'".str_replace("'", "\'", formatVariable($svalue))."',"; |
|---|
| 179 | |
|---|
| 180 | $output = substr($output, 0, strlen($output)-1); |
|---|
| 181 | |
|---|
| 182 | $output .= "},"; |
|---|
| 183 | |
|---|
| 184 | }//endif is_array |
|---|
| 185 | |
|---|
| 186 | }//endforeach - record |
|---|
| 187 | |
|---|
| 188 | $output = substr($output, 0, strlen($output)-1); |
|---|
| 189 | |
|---|
| 190 | $output .= "}"; |
|---|
| 191 | |
|---|
| 192 | header("Content-type: text/plain"); |
|---|
| 193 | echo $output; |
|---|
| 194 | |
|---|
| 195 | }//end method - display |
|---|
| 196 | |
|---|
| 197 | }//end class |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | //processing |
|---|
| 201 | //========================================================================= |
|---|
| 202 | if(isset($_GET["id"])){ |
|---|
| 203 | |
|---|
| 204 | $clientInfo = new clientInfo($db); |
|---|
| 205 | |
|---|
| 206 | $clientRecord = $clientInfo->get($_GET["id"]); |
|---|
| 207 | |
|---|
| 208 | $clientInfo->display($clientRecord); |
|---|
| 209 | |
|---|
| 210 | }//end if |
|---|
| 211 | ?> |
|---|