| 2 | | /* |
| 3 | | $Rev: 265 $ | $LastChangedBy: brieb $ |
| 4 | | $LastChangedDate: 2007-08-13 21:33:23 -0600 (Mon, 13 Aug 2007) $ |
| 5 | | +-------------------------------------------------------------------------+ |
| 6 | | | Copyright (c) 2004 - 2007, 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 | | error_reporting(E_ALL); |
| 40 | | define("APP_DEBUG",false); |
| 41 | | define("noStartup",true); |
| | 2 | // The update proceess is typically simple, but if you have some complex |
| | 3 | // update procedures (like the BMS module) not covered by the updateModuleAjax |
| | 4 | // (located in the main install/installajax.php file) You can override the class. |
| | 5 | // |
| | 6 | // Just make sure your class has an 'update' method, and spits back JSON paired |
| | 7 | // results |
| 65 | | while($ver["version"] != $newVersion){ |
| 66 | | switch($ver["version"]){ |
| 67 | | // ================================================================================================ |
| 68 | | case "0.5": |
| 69 | | $thereturn.="Updating BMS Module to 0.51\n"; |
| 70 | | |
| 71 | | //Updating Module Table |
| 72 | | $querystatement="UPDATE modules SET version=\"0.51\" WHERE name=\"bms\";"; |
| 73 | | $queryresult=$db->query($querystatement); |
| 74 | | $thereturn.=" - modified bms record in modules table\n"; |
| 75 | | |
| 76 | | $thereturn.="Update to 0.51 Finished\n\n"; |
| 77 | | |
| 78 | | $ver["version"]="0.51"; |
| 79 | | break; |
| 80 | | // ================================================================================================ |
| 81 | | case "0.51": |
| 82 | | $thereturn.="Updating BMS Module to 0.6\n"; |
| 83 | | |
| 84 | | $thereturn.=processSQLfile($db,"updatev0.6.sql"); |
| 85 | | |
| 86 | | $thereturn.=importData($db,"choices"); |
| 87 | | $thereturn.=importData($db,"menu"); |
| 88 | | $thereturn.=importData($db,"reports"); |
| 89 | | $thereturn.=importData($db,"tablecolumns"); |
| 90 | | $thereturn.=importData($db,"tabledefs"); |
| 91 | | $thereturn.=importData($db,"tablefindoptions"); |
| 92 | | $thereturn.=importData($db,"tableoptions"); |
| 93 | | $thereturn.=importData($db,"tablesearchablefields"); |
| 94 | | |
| 95 | | $querystatement="SELECT clients.id,DATE_FORMAT(clients.creationdate,\"%Y-%m-%d\") as creationdate,max(invoices.orderdate) as orderdate |
| 96 | | FROM `clients` LEFT JOIN invoices on clients.id=invoices.clientid |
| 97 | | WHERE clients.type=\"client\" GROUP BY clients.id;"; |
| 98 | | $queryresult=$db->query($querystatement); |
| 99 | | |
| 100 | | while($therecord=$db->fetchArray($queryresult,$dblink)){ |
| 101 | | $querystatement="UPDATE clients set becameclient=\""; |
| 102 | | if($therecord["orderdate"]) |
| 103 | | $querystatement.=$therecord["orderdate"]; |
| 104 | | else |
| 105 | | $querystatement.=$therecord["creationdate"]; |
| 106 | | $querystatement.="\" WHERE id=".$therecord["id"]; |
| 107 | | $updateresult=$db->query($querystatement); |
| 108 | | } |
| 109 | | $thereturn.=" - set intitial client becamclient field\n"; |
| 110 | | |
| 111 | | |
| 112 | | //Updating Module Table |
| 113 | | $querystatement="UPDATE modules SET version=\"0.6\" WHERE name=\"bms\";"; |
| 114 | | $updateresult=$db->query($querystatement); |
| 115 | | $thereturn.=" - modified bms record in modules table\n"; |
| 116 | | |
| 117 | | $thereturn.="Update to 0.6 Finished\n\n"; |
| 118 | | |
| 119 | | $ver["version"]="0.6"; |
| 120 | | break; |
| 121 | | // ================================================================================================ |
| 122 | | case "0.6"; |
| 123 | | $thereturn.="Updating BMS Module to 0.601\n"; |
| 124 | | |
| 125 | | $querystatement="SELECT invoices.id,tax.percentage FROM invoices INNER JOIN tax on invoices.taxareaid=tax.id"; |
| 126 | | $queryresult=$db->query($querystatement); |
| 127 | | |
| 128 | | |
| 129 | | while($therecord=$db->fetchArray($queryresult)){ |
| 130 | | $querystatement="UPDATE invoices SET taxpercentage=".$therecord["percentage"]."WHERE id=".$therecord["id"]; |
| 131 | | $updateresult=$db->query($querystatement); |
| 132 | | } |
| 133 | | $thereturn.=" - set taxpercentage on invoices\n"; |
| 134 | | |
| 135 | | //Updating Module Table |
| 136 | | $querystatement="UPDATE modules SET version=\"0.601\" WHERE name=\"bms\";"; |
| 137 | | $updateresult=$db->query($querystatement); |
| 138 | | $thereturn.=" - modified bms record in modules table\n"; |
| 139 | | |
| 140 | | |
| 141 | | $thereturn.="Update to 0.601 Finished\n\n"; |
| 142 | | |
| 143 | | $ver["version"]="0.601"; |
| 144 | | |
| 145 | | break; |
| 146 | | // ================================================================================================ |
| 147 | | case "0.601"; |
| 148 | | $thereturn.="Updating BMS Module to 0.602\n"; |
| 149 | | |
| 150 | | //Updating Module Table |
| 151 | | $querystatement="UPDATE modules SET version=\"0.602\" WHERE name=\"bms\";"; |
| 152 | | $updateresult=$db->query($querystatement); |
| 153 | | $thereturn.=" - modified bms record in modules table\n"; |
| 154 | | |
| 155 | | $thereturn.="Update to 0.602 Finished\n\n"; |
| 156 | | |
| 157 | | $ver["version"]="0.602"; |
| 158 | | // ================================================================================================ |
| 159 | | case "0.602"; |
| 160 | | $thereturn.="Updating BMS Module to 0.61\n"; |
| 161 | | |
| 162 | | $thereturn.=processSQLfile($db,"updatev0.61.sql"); |
| 163 | | |
| 164 | | //Updating Module Table |
| 165 | | $querystatement="UPDATE modules SET version=\"0.61\" WHERE name=\"bms\";"; |
| 166 | | $updateresult=$db->query($querystatement); |
| 167 | | $thereturn.=" - modified bms record in modules table\n"; |
| 168 | | |
| 169 | | $thereturn.="Update to 0.61 Finished\n\n"; |
| 170 | | |
| 171 | | $ver["version"]="0.61"; |
| 172 | | break; |
| 173 | | // ================================================================================================ |
| 174 | | case "0.61"; |
| 175 | | $thereturn.="Updating BMS Module to 0.62\n"; |
| 176 | | |
| 177 | | $thereturn.=processSQLfile($db,"updatev0.62.sql"); |
| 178 | | |
| 179 | | //Updating Module Table |
| 180 | | $querystatement="UPDATE modules SET version=\"0.62\" WHERE name=\"bms\";"; |
| 181 | | $updateresult=$db->query($querystatement); |
| 182 | | $thereturn.=" - modified bms record in modules table\n"; |
| 183 | | |
| 184 | | $thereturn.="Update to 0.62 Finished\n\n"; |
| 185 | | |
| 186 | | $ver["version"]="0.62"; |
| 187 | | break; |
| 188 | | // ================================================================================================ |
| 189 | | case "0.62"; |
| 190 | | $thereturn.="Updating BMS Module to 0.7\n"; |
| 191 | | |
| 192 | | $thereturn.=processSQLfile($db,"updatev0.70.sql"); |
| 193 | | |
| 194 | | //update to new status system |
| 195 | | $result=updateInvoiceStatus($db); |
| 196 | | if($result===true) |
| 197 | | $thereturn.=" - Updated to new invoice status system\n"; |
| 198 | | else |
| 199 | | $thereturn.=" - Failed to updated to new invoice status system\n".$result."\n\n"; |
| 200 | | |
| 201 | | //Update shipping from invoices |
| 202 | | $result=moveShipping($db); |
| 203 | | if($result===true) |
| 204 | | $thereturn.=" - Created default Shipping Methods\n"; |
| 205 | | else |
| 206 | | $thereturn.=" - Failed to create default shipping methods\n".$result."\n\n"; |
| 207 | | |
| 208 | | //update payment From invoices |
| 209 | | $result=movePayments($db); |
| 210 | | if($result===true) |
| 211 | | $thereturn.=" - Created default payment methods\n"; |
| 212 | | else |
| 213 | | $thereturn.=" - Failed to create default payment Methods\n".$result."\n\n"; |
| 214 | | |
| 215 | | //Updating Module Table |
| 216 | | $querystatement="UPDATE modules SET version=\"0.7\" WHERE name=\"bms\";"; |
| 217 | | $updateresult=$db->query($querystatement); |
| 218 | | $thereturn.=" - Updated bms module record with new version\n"; |
| 219 | | |
| 220 | | $thereturn.="Update to 0.7 Finished\n\n"; |
| 221 | | |
| 222 | | $ver["version"]="0.7"; |
| 223 | | break; |
| 224 | | |
| 225 | | // ================================================================================================ |
| 226 | | case "0.7"; |
| 227 | | |
| 228 | | $thereturn.= processSQLfile($db,"updatev0.8.sql"); |
| 229 | | |
| 230 | | //Updating Module Table |
| 231 | | $querystatement="UPDATE modules SET version=\"0.8\" WHERE name=\"bms\";"; |
| 232 | | $updateresult=$db->query($querystatement); |
| 233 | | |
| 234 | | $thereturn.="Update of Business Management System Module to 0.8 Finished\n\n"; |
| 235 | | $ver["version"]="0.8"; |
| 236 | | break; |
| 237 | | }//end switch |
| 238 | | }//end while |
| 239 | | return $thereturn; |
| 240 | | |
| 241 | | }//end update |
| 242 | | |
| 243 | | function moveShipping($db){ |
| 244 | | $querystatement="SELECT DISTINCT shippingmethod FROM invoices WHERE shippingmethod!=\"\" ORDER BY shippingmethod"; |
| 245 | | $queryresult=$db->query($querystatement); |
| 246 | | |
| 247 | | while($therecord=$db->fetchArray($queryresult)){ |
| 248 | | $querystatement="INSERT INTO `shippingmethods` (name,createdby,creationdate) VALUES (\"".$therecord["shippingmethod"]."\",1,NOW())"; |
| 249 | | $updatequery=$db->query($querystatement); |
| 250 | | } |
| 251 | | |
| 252 | | $querystatement="SELECT id,name FROM shippingmethods"; |
| 253 | | $queryresult=$db->query($querystatement); |
| 254 | | |
| 255 | | while($therecord=$db->fetchArray($queryresult)){ |
| 256 | | $querystatement="UPDATE invoices SET shippingmethodid=".$therecord["id"]." |
| 257 | | WHERE shippingmethod=\"".$therecord["name"]."\""; |
| 258 | | $updatequery=$db->query($querystatement); |
| 259 | | } |
| 260 | | $querystatement="ALTER TABLE invoices DROP shippingmethod"; |
| 261 | | $updatequery=$db->query($querystatement); |
| 262 | | |
| 263 | | return true; |
| 264 | | } |
| 265 | | |
| 266 | | function movePayments($db){ |
| 267 | | $querystatement="SELECT DISTINCT paymentmethod FROM invoices WHERE paymentmethod!=\"\" ORDER BY paymentmethod"; |
| 268 | | $queryresult=$db->query($querystatement); |
| 269 | | |
| 270 | | while($therecord=$db->fetchArray($queryresult)){ |
| 271 | | switch($therecord["paymentmethod"]){ |
| 272 | | case "VISA": |
| 273 | | case "VISA - Debit": |
| 274 | | case "American Express": |
| 275 | | case "Master Card": |
| 276 | | case "MasterCard": |
| 277 | | case "Discover Card": |
| 278 | | $type="\"charge\""; |
| 279 | | break; |
| 280 | | |
| 281 | | case "Personal Check": |
| 282 | | case "Check": |
| 283 | | case "Cashiers Check": |
| 284 | | case "check": |
| 285 | | $type="\"draft\""; |
| 286 | | break; |
| 287 | | |
| 288 | | default: |
| 289 | | $type="NULL"; |
| 290 | | break; |
| 291 | | } |
| 292 | | |
| 293 | | $querystatement="INSERT INTO `paymentmethods` (name,`type`,createdby,creationdate) VALUES (\"".$therecord["paymentmethod"]."\",".$type.",1,NOW())"; |
| 294 | | $updatequery=$db->query($querystatement); |
| 295 | | } |
| 296 | | |
| 297 | | $querystatement="SELECT id,name FROM paymentmethods"; |
| 298 | | $queryresult=$db->query($querystatement); |
| 299 | | while($therecord=$db->fetchArray($queryresult)){ |
| 300 | | $querystatement="UPDATE invoices SET paymentmethodid=".$therecord["id"]." |
| 301 | | WHERE paymentmethod=\"".$therecord["name"]."\""; |
| 302 | | $updatequery=$db->query($querystatement); |
| 303 | | } |
| 304 | | $querystatement="ALTER TABLE invoices DROP paymentmethod"; |
| 305 | | $updatequery=$db->query($querystatement); |
| 306 | | |
| 307 | | return true; |
| 308 | | } |
| 309 | | |
| 310 | | function updateInvoiceStatus($db){ |
| 311 | | $querystatement="SELECT id,status,statusdate,orderdate,invoicedate,type FROM invoices"; |
| 312 | | $queryresult=$db->query($querystatement); |
| 313 | | |
| 314 | | while($therecord=$db->fetchArray($queryresult)){ |
| 315 | | $newstatus=1; |
| 316 | | switch($therecord["status"]){ |
| 317 | | case "Open": |
| 318 | | $newstatus=1; |
| 319 | | $statusdate=$therecord["orderdate"]; |
| 320 | | break; |
| 321 | | case "Committed": |
| 322 | | $newstatus=2; |
| 323 | | $statusdate=$therecord["orderdate"]; |
| 324 | | break; |
| 325 | | case "Packed": |
| 326 | | $newstatus=3; |
| 327 | | break; |
| 328 | | case "Shipped": |
| 329 | | $newstatus=4; |
| 330 | | if($therecord["statusdate"]) |
| 331 | | $statusdate=$therecord["statusdate"]; |
| 332 | | elseif($therecord["invoicedate"]) |
| 333 | | $statusdate=$therecord["invoicedate"]; |
| 334 | | else |
| 335 | | $statusdate=$therecord["orderdate"]; |
| 336 | | break; |
| 337 | | if($therecord["type"]=="Invoice") |
| 338 | | $statusdate=$therecord["invoicedate"]; |
| 339 | | } |
| 340 | | $querystatement="UPDATE invoices SET statusid=".$newstatus.", statusdate=\"".$statusdate."\" WHERE id=".$therecord["id"]; |
| 341 | | $updatequery=$db->query($querystatement); |
| 342 | | |
| 343 | | //now create the history |
| 344 | | $querystatement="INSERT INTO invoicestatushistory (invoiceid,invoicestatusid,statusdate)VALUES(".$therecord["id"].",".$newstatus.",\"".$statusdate."\")"; |
| 345 | | $insertquery=$db->query($querystatement); |
| 346 | | |
| 347 | | } |
| 348 | | $querystatement="ALTER TABLE `invoices` DROP COLUMN `status`"; |
| 349 | | $dropcolumnquery=$db->query($querystatement); |
| 350 | | |
| 351 | | return true; |
| 352 | | }//end funtion |
| 353 | | |
| 354 | | |
| 355 | | $phpbmsSession = new phpbmsSession; |
| 356 | | $success = $phpbmsSession->loadDBSettings(false); |
| 357 | | |
| 358 | | include_once("include/db.php"); |
| 359 | | $db = new db(false); |
| 360 | | $db->stopOnError = false; |
| 361 | | $db->showError = false; |
| 362 | | $db->logError = false; |
| 363 | | |
| 364 | | if($success !== false){ |
| 365 | | |
| 366 | | if(!$db->connect()) |
| 367 | | $thereturn = "Could Not Establish Connection To MySQL Server: Check server, user name, and password."; |
| 368 | | else { |
| 369 | | if(!$db->selectSchema()) |
| 370 | | $thereturn = "Database (schema) ".MYSQL_DATABASE." could not be selected"; |
| 371 | | else { |
| 372 | | |
| 373 | | $phpbmsSession->db = $db; |
| 374 | | $phpbmsSession->loadSettings(); |
| 375 | | |
| 376 | | $thereturn=doUpdate($db); |
| 377 | | |
| 378 | | } |
| 379 | | } |
| 380 | | } else |
| 381 | | $thereturn = "Could not access settings.php"; |
| 382 | | |
| 383 | | |
| 384 | | |
| 385 | | header('Content-Type: text/xml'); |
| 386 | | ?><?php echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'; ?> |
| 387 | | <response><?php echo $thereturn?></response> |
| | 27 | ?> |