phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/bms/install/update.php

    r419 r485  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39 error_reporting(E_ALL); 
    40 define("APP_DEBUG",false); 
    41 define("noStartup",true); 
    42  
    43 include("../../../install/install_include.php"); 
    44 include("../../../include/session.php"); 
    45  
    46         function doUpdate($db) { 
    47                 $thereturn="Updating Business Management System Module\n"; 
    48                  
    49                 if(!verifyAdminLogin($db,$_GET["u"],$_GET["p"])){ 
    50                         $thereturn="Update Requires Administrative Access.\n\n"; 
    51                         return $thereturn; 
    52                 } 
    53                                  
    54                 $newVersion = $_GET["v"]; 
    55                  
    56                 $querystatement="SELECT version FROM modules WHERE name=\"bms\""; 
    57                 $queryresult=$db->query($querystatement); 
    58                 if(!$queryresult) { 
    59                         $thereturn="Error Accessing module table in database.\n\n"; 
    60                         return $thereturn; 
    61                 } 
    62                  
    63                 $ver=$db->fetchArray($queryresult); 
    64  
    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                                         //Updating Module Table 
    178                                         $querystatement="UPDATE modules SET version=\"0.62\" WHERE name=\"bms\";"; 
    179                                         $updateresult=$db->query($querystatement); 
    180                                         $thereturn.=" - modified bms record in modules table\n"; 
    181  
    182                                         $thereturn.="Update to 0.62 Finished\n\n"; 
    183                          
    184                                         $ver["version"]="0.62"; 
    185                                 break; 
    186                                 // ================================================================================================ 
    187                                 case "0.62"; 
    188                                         $thereturn.="Updating BMS Module to 0.7\n"; 
    189                                          
    190                                         $thereturn.=processSQLfile($db,"updatev0.70.sql"); 
    191                                          
    192                                         //update to new status system 
    193                                         $result=updateInvoiceStatus($db); 
    194                                         if($result===true) 
    195                                                 $thereturn.=" - Updated to new invoice status system\n"; 
    196                                         else 
    197                                                 $thereturn.=" - Failed to updated to new invoice status system\n".$result."\n\n";                                        
    198                                          
    199                                         //Update shipping from invoices 
    200                                         $result=moveShipping($db); 
    201                                         if($result===true) 
    202                                                 $thereturn.=" - Created default Shipping Methods\n"; 
    203                                         else 
    204                                                 $thereturn.=" - Failed to create default shipping methods\n".$result."\n\n"; 
    205                                          
    206                                         //update payment From invoices 
    207                                         $result=movePayments($db); 
    208                                         if($result===true) 
    209                                                 $thereturn.=" - Created default payment methods\n"; 
    210                                         else 
    211                                                 $thereturn.=" - Failed to create default payment Methods\n".$result."\n\n"; 
    212                                          
    213                                         //Updating Module Table 
    214                                         $querystatement="UPDATE modules SET version=\"0.7\" WHERE name=\"bms\";"; 
    215                                         $updateresult=$db->query($querystatement); 
    216                                         $thereturn.=" - Updated bms module record with new version\n"; 
    217  
    218                                         $thereturn.="Update to 0.7 Finished\n\n"; 
    219                          
    220                                         $ver["version"]="0.7"; 
    221                                 break; 
    222  
    223                                 // ================================================================================================ 
    224                                 case "0.7"; 
    225  
    226                                         $thereturn.= processSQLfile($db,"updatev0.80.sql"); 
    227  
    228                                         //Updating Module Table 
    229                                         $querystatement="UPDATE modules SET version=\"0.8\" WHERE name=\"bms\";"; 
    230                                         $updateresult=$db->query($querystatement); 
    231  
    232                                         $thereturn.="Update of Business Management System Module to 0.8 Finished\n\n"; 
    233                                         $ver["version"]="0.8"; 
    234                                 break; 
    235  
    236                                 // ================================================================================================ 
    237                                 case "0.8"; 
    238  
    239                                         $thereturn.= processSQLfile($db,"updatev0.90.sql"); 
    240  
    241                                         //Updating Module Table 
    242                                         $querystatement = " 
    243                                                 UPDATE  
    244                                                         modules  
    245                                                 SET  
    246                                                         version='0.9'  
    247                                                 WHERE  
    248                                                         name='bms';"; 
    249  
    250                                         $updateresult = $db->query($querystatement); 
    251  
    252                                         $thereturn .= "Update of Business Management System Module to 0.9 Finished\n\n"; 
    253  
    254                                         $ver["version"] = "0.9"; 
    255  
    256                                         break; 
    257                                          
    258                                 // ================================================================================================ 
    259                                 case "0.9"; 
    260  
    261                                         $thereturn.= processSQLfile($db,"updatev0.92.sql"); 
    262  
    263                                         //Updating Module Table 
    264                                         $updatestatement = " 
    265                                                 UPDATE  
    266                                                         modules  
    267                                                 SET  
    268                                                         version='0.92'  
    269                                                 WHERE  
    270                                                         name='bms';"; 
    271  
    272                                         $db->query($updatestatement); 
    273  
    274                                         $thereturn .= "Update of Business Management System Module to 0.92 Finished\n\n"; 
    275  
    276                                         $ver["version"] = "0.92"; 
    277  
    278                                         break; 
    279  
    280                                 // ================================================================================================ 
    281                                 case "0.92"; 
    282  
    283                                         $thereturn.= processSQLfile($db,"updatev0.94.sql"); 
    284  
    285                                         //Updating Module Table 
    286                                         $updatestatement = " 
    287                                                 UPDATE  
    288                                                         modules  
    289                                                 SET  
    290                                                         version='0.94'  
    291                                                 WHERE  
    292                                                         name='bms';"; 
    293  
    294                                         $db->query($updatestatement); 
    295  
    296                                         $thereturn .= "Update of Business Management System Module to 0.94 Finished\n\n"; 
    297  
    298                                         $ver["version"] = "0.94"; 
    299  
    300                                         break; 
    301  
    302                                 // ================================================================================================ 
    303                                 case "0.94"; 
    304  
    305                                         $thereturn.= processSQLfile($db,"updatev0.96.sql"); 
    306                                          
    307                                         if(v096updateInvoiceAddresses($db)) 
    308                                                 $thereturn .= "Updating invoice addresses.\n\n";                                         
    309  
    310                                         if(v096transferClientAddresses($db)) 
    311                                                 $thereturn .= "Transfer client addresses.\n\n";                                  
    312  
    313                                         //Updating Module Table 
    314                                         $updatestatement = " 
    315                                                 UPDATE  
    316                                                         modules  
    317                                                 SET  
    318                                                         version='0.96'  
    319                                                 WHERE  
    320                                                         name='bms';"; 
    321  
    322                                         $db->query($updatestatement); 
    323  
    324                                         $thereturn .= "Update of Business Management System Module to 0.96 Finished\n\n"; 
    325  
    326                                         $ver["version"] = "0.96"; 
    327  
    328                                         break; 
    329                                  
    330                                 // ================================================================================================ 
    331                                 case "0.96"; 
    332  
    333                                         $thereturn.= processSQLfile($db,"updatev0.98.sql"); 
    334                                          
    335                                         //Updating Module Table 
    336                                         $updatestatement = " 
    337                                                 UPDATE  
    338                                                         modules  
    339                                                 SET  
    340                                                         version='0.98'  
    341                                                 WHERE  
    342                                                         name='bms';"; 
    343  
    344                                         $db->query($updatestatement); 
    345  
    346                                         $thereturn .= "Update of Business Management System Module to 0.98 Finished\n\n"; 
    347  
    348                                         $ver["version"] = "0.98"; 
    349  
    350                                         break; 
    351  
    352                         }//end switch 
    353                 }//end while 
    354                 return $thereturn; 
    355  
    356         }//end update 
    357  
    358  
    359         function moveShipping($db){ 
    360                 $querystatement="SELECT DISTINCT shippingmethod FROM invoices WHERE shippingmethod!=\"\" ORDER BY shippingmethod"; 
    361                 $queryresult=$db->query($querystatement); 
    362                  
    363                 while($therecord=$db->fetchArray($queryresult)){ 
    364                         $querystatement="INSERT INTO `shippingmethods` (name,createdby,creationdate) VALUES (\"".$therecord["shippingmethod"]."\",1,NOW())"; 
    365                         $updatequery=$db->query($querystatement); 
    366                 } 
    367  
    368                 $querystatement="SELECT id,name FROM shippingmethods"; 
    369                 $queryresult=$db->query($querystatement); 
    370  
    371                 while($therecord=$db->fetchArray($queryresult)){ 
    372                         $querystatement="UPDATE invoices SET shippingmethodid=".$therecord["id"]." 
    373                                                         WHERE shippingmethod=\"".$therecord["name"]."\""; 
    374                         $updatequery=$db->query($querystatement); 
    375                 } 
    376                 $querystatement="ALTER TABLE invoices DROP shippingmethod"; 
    377                 $updatequery=$db->query($querystatement); 
    378                  
    379                 return true;              
    380         } 
    381  
    382  
    383         function movePayments($db){ 
    384                 $querystatement="SELECT DISTINCT paymentmethod FROM invoices WHERE paymentmethod!=\"\" ORDER BY paymentmethod"; 
    385                 $queryresult=$db->query($querystatement); 
    386  
    387                 while($therecord=$db->fetchArray($queryresult)){ 
    388                         switch($therecord["paymentmethod"]){ 
    389                                 case "VISA": 
    390                                 case "VISA - Debit":  
    391                                 case "American Express": 
    392                                 case "Master Card": 
    393                                 case "MasterCard": 
    394                                 case "Discover Card": 
    395                                         $type="\"charge\""; 
    396                                 break; 
    397                                  
    398                                 case "Personal Check": 
    399                                 case "Check": 
    400                                 case "Cashiers Check": 
    401                                 case "check": 
    402                                         $type="\"draft\""; 
    403                                 break;                           
    404                                  
    405                                 default: 
    406                                         $type="NULL"; 
    407                                 break; 
    408                         } 
    409                          
    410                         $querystatement="INSERT INTO `paymentmethods` (name,`type`,createdby,creationdate) VALUES (\"".$therecord["paymentmethod"]."\",".$type.",1,NOW())"; 
    411                         $updatequery=$db->query($querystatement); 
    412                 } 
    413  
    414                 $querystatement="SELECT id,name FROM paymentmethods"; 
    415                 $queryresult=$db->query($querystatement); 
    416                 while($therecord=$db->fetchArray($queryresult)){ 
    417                         $querystatement="UPDATE invoices SET paymentmethodid=".$therecord["id"]." 
    418                                                         WHERE paymentmethod=\"".$therecord["name"]."\""; 
    419                         $updatequery=$db->query($querystatement); 
    420                 } 
    421                 $querystatement="ALTER TABLE invoices DROP paymentmethod"; 
    422                 $updatequery=$db->query($querystatement); 
    423                  
    424                 return true; 
    425         } 
    426  
    427         function updateInvoiceStatus($db){ 
    428                 $querystatement="SELECT id,status,statusdate,orderdate,invoicedate,type FROM invoices"; 
    429                 $queryresult=$db->query($querystatement); 
    430                  
    431                 while($therecord=$db->fetchArray($queryresult)){ 
    432                                  
    433                         $newstatus=1;                    
    434                         switch($therecord["status"]){ 
    435                                 case "Open": 
    436                                         $newstatus=1; 
    437                                         $statusdate=$therecord["orderdate"]; 
    438                                 break; 
    439                                 case "Committed": 
    440                                         $newstatus=2; 
    441                                         $statusdate=$therecord["orderdate"];                                     
    442                                 break; 
    443                                 case "Packed": 
    444                                         $newstatus=3; 
    445                                         $statusdate=$therecord["orderdate"];                                     
    446                                 break; 
    447                                 case "Shipped": 
    448                                         $newstatus=4; 
    449                                         if($therecord["statusdate"]) 
    450                                                 $statusdate=$therecord["statusdate"]; 
    451                                         elseif($therecord["invoicedate"]) 
    452                                                 $statusdate=$therecord["invoicedate"]; 
    453                                         else 
    454                                                 $statusdate=$therecord["orderdate"]; 
    455                                 break; 
    456                         }//end switch                    
    457  
    458                         if($therecord["type"]=="Invoice") 
    459                                 $statusdate=$therecord["invoicedate"]; 
    460                          
    461                         $querystatement="UPDATE invoices SET statusid=".$newstatus.", statusdate=\"".$statusdate."\" WHERE id=".$therecord["id"]; 
    462                         $updatequery=$db->query($querystatement); 
    463  
    464                         //now create the history 
    465                         $querystatement="INSERT INTO invoicestatushistory (invoiceid,invoicestatusid,statusdate)VALUES(".$therecord["id"].",".$newstatus.",\"".$statusdate."\")"; 
    466                         $insertquery=$db->query($querystatement); 
    467                          
    468                 } 
    469                 $querystatement="ALTER TABLE `invoices` DROP COLUMN `status`"; 
    470                 $dropcolumnquery=$db->query($querystatement); 
    471                  
    472                 return true; 
    473         }//end funtion 
    474  
    475  
    476         function v096updateInvoiceAddresses($db){ 
    477          
     39 
     40// Need custom class for upgrade because 
     41// some BMS upgrades require more than just 
     42// version SQL file processing 
     43class updateBMS extends updateModuleAjax{ 
     44 
     45        function updateBMS($db, $phpbmsSession, $moduleName, $pathToModule){ 
     46 
     47                $this->updateModuleAjax($db, $phpbmsSession, $moduleName, $pathToModule); 
     48 
     49        }//end function init 
     50 
     51        //override function for custom upgrading 
     52        function update(){ 
     53 
     54                if(!$this->db->connect()) 
     55                        return $this->returnJSON(false, "Could not connect to database ".$this->db->getError()); 
     56 
     57                if(!$this->db->selectSchema()) 
     58                        return $this->returnJSON(false, "Could not open database schema '".MYSQL_DATABASE."'"); 
     59 
     60                $updater = new installer($this->db); 
     61 
     62                include("../modules/bms/version.php"); 
     63                $newVersion = $modules["bms"]["version"]; 
     64                $currentVersion = $this->currentVersion; 
     65 
     66                //next we loop through each upgrade process 
     67                while($currentVersion != $newVersion){ 
     68 
     69                        switch($currentVersion){ 
     70 
     71                                // ================================================================================================ 
     72                                case 0.8: 
     73 
     74                                        $version = 0.9; 
     75                                        //Processing Data Structure Changes 
     76                                        $thereturn = $updater->processSQLfile("../modules/bms/install/updatev".$version.".sql"); 
     77                                        if($thereturn !== true) 
     78                                                return $this->returnJSON(false, $thereturn); 
     79 
     80                                        //Updating Module Table 
     81                                        $thereturn = $this->updateModuleVersion("bms", $version); 
     82                                        if($thereturn !== true) 
     83                                                return $this->returnJSON(false, $thereturn); 
     84 
     85                                        $currentVersion = $version; 
     86 
     87                                        break; 
     88 
     89                                // ================================================================================================ 
     90                                case 0.9: 
     91 
     92                                        $version = 0.92; 
     93                                        //Processing Data Structure Changes 
     94                                        $thereturn = $updater->processSQLfile("../modules/bms/install/updatev".$version.".sql"); 
     95                                        if($thereturn !== true) 
     96                                                return $this->returnJSON(false, $thereturn); 
     97 
     98                                        //Updating Module Table 
     99                                        $thereturn = $this->updateModuleVersion("bms", $version); 
     100                                        if($thereturn !== true) 
     101                                                return $this->returnJSON(false, $thereturn); 
     102 
     103                                        $currentVersion = $version; 
     104 
     105                                        break; 
     106 
     107                                // ================================================================================================ 
     108                                case 0.92: 
     109 
     110                                        $version = 0.94; 
     111                                        //Processing Data Structure Changes 
     112                                        $thereturn = $updater->processSQLfile("../modules/bms/install/updatev".$version.".sql"); 
     113                                        if($thereturn !== true) 
     114                                                return $this->returnJSON(false, $thereturn); 
     115 
     116                                        //Updating Module Table 
     117                                        $thereturn = $this->updateModuleVersion("bms", $version); 
     118                                        if($thereturn !== true) 
     119                                                return $this->returnJSON(false, $thereturn); 
     120 
     121                                        $currentVersion = $version; 
     122 
     123                                        break; 
     124 
     125                                // ================================================================================================ 
     126                                case 0.94: 
     127 
     128                                        $version = 0.96; 
     129                                        //Processing Data Structure Changes 
     130                                        $thereturn = $updater->processSQLfile("../modules/bms/install/updatev".$version.".sql"); 
     131                                        if($thereturn !== true) 
     132                                                return $this->returnJSON(false, $thereturn); 
     133 
     134                                        if(!$this->v096updateInvoiceAddresses()) 
     135                                                return $this->returnJSON(false, "v0.96 Invoice Addresses Movement Failed"); 
     136 
     137                                        if(!$this->v096transferClientAddresses()) 
     138                                                return $this->returnJSON(false, "v0.96 Client Addresses Movement Failed"); 
     139 
     140                                        //Updating Module Table 
     141                                        $thereturn = $this->updateModuleVersion("bms", $version); 
     142                                        if($thereturn !== true) 
     143                                                return $this->returnJSON(false, $thereturn); 
     144 
     145                                        $currentVersion = $version; 
     146 
     147                                        break; 
     148 
     149                                // ================================================================================================ 
     150                                case 0.96: 
     151 
     152                                        $version = 0.98; 
     153                                        //Processing Data Structure Changes 
     154                                        $thereturn = $updater->processSQLfile("../modules/bms/install/updatev".$version.".sql"); 
     155                                        if($thereturn !== true) 
     156                                                return $this->returnJSON(false, $thereturn); 
     157 
     158                                        //Updating Module Table 
     159                                        $thereturn = $this->updateModuleVersion("bms", $version); 
     160                                        if($thereturn !== true) 
     161                                                return $this->returnJSON(false, $thereturn); 
     162 
     163                                        $currentVersion = $version; 
     164 
     165                                        break; 
     166 
     167                        }//endswitch currentVersion 
     168 
     169                }//endwhile currentversion/newversion 
     170 
     171 
     172                return $this->returnJSON(true, "Module '".$this->moduleName."' Updated"); 
     173 
     174        }//end function update 
     175 
     176 
     177//==== v0.96 Specific Function ================================================= 
     178 
     179        function v096updateInvoiceAddresses(){ 
     180 
    478181                $querystatement = " 
    479182                        SELECT 
     
    487190                        FROM 
    488191                                invoices INNER JOIN clients ON invoices.clientid = clients.id"; 
    489                                  
    490                 $queryresult = $db->query($querystatement); 
    491                  
    492                 while($therecord = $db->fetchArray($queryresult)){ 
    493                  
     192 
     193                $queryresult = $this->db->query($querystatement); 
     194 
     195                while($therecord = $this->db->fetchArray($queryresult)){ 
     196 
    494197                        $updatestatement = " 
    495198                                UPDATE 
     
    511214                                        id = ".$therecord["id"]; 
    512215 
    513                                 $db->query($updatestatement); 
    514                  
     216                                $this->db->query($updatestatement); 
     217 
    515218                }//endwhile - record 
    516          
     219 
    517220                return true; 
    518          
     221 
    519222        }//end function - v096updateInvoiceAddresses 
    520223 
    521224 
    522         function v096transferClientAddresses($db){ 
    523          
     225        function v096transferClientAddresses(){ 
     226 
    524227                //retrieve all client records with ship to addresses 
    525228                $querystatement = " 
     
    540243                        FROM 
    541244                                clients"; 
    542                  
    543                 $queryresult = $db->query($querystatement); 
    544                  
    545                 while($therecord = $db->fetchArray($queryresult)){ 
    546                  
     245 
     246                $queryresult = $this->db->query($querystatement); 
     247 
     248                while($therecord = $this->db->fetchArray($queryresult)){ 
     249 
    547250                        // for each client with a ship to, we need to create 
    548251                        // an address record (and addresstorecord record) 
    549                          
     252 
    550253                        // Create the address record 
    551254                        $address["title"] = "Primary"; 
     
    556259                        $address["postalcode"] = $therecord["postalcode"]; 
    557260                        $address["country"] = $therecord["country"]; 
    558                          
    559                         $newid = insertAddress($db, $address);                   
    560                          
     261 
     262                        $newid = $this->v096insertAddress($address); 
     263 
    561264                        $a2r["clientid"] = $therecord["id"]; 
    562265                        $a2r["addressid"] = $newid; 
    563266                        $a2r["primary"] = 1; 
    564                          
     267 
    565268                        if($therecord["shiptoaddress1"]){ 
    566                          
     269 
    567270                                $a2r["defaultshipto"] = 0; 
    568                                 insertA2R($db, $a2r); 
    569                          
     271                                $this->v096insertA2R($a2r); 
     272 
    570273                                $address["title"] = "Shipping"; 
    571274                                $address["address1"] = $therecord["shiptoaddress1"]; 
     
    575278                                $address["postalcode"] = $therecord["shiptopostalcode"]; 
    576279                                $address["country"] = $therecord["shiptocountry"]; 
    577                                  
    578                                 $newid = insertAddress($db, $address);                   
    579                                  
     280 
     281                                $newid = insertAddress($db, $address); 
     282 
    580283                                $a2r["addressid"] = $newid; 
    581284                                $a2r["primary"] = 0; 
    582285                                $a2r["defaultshipto"] = 1; 
    583                          
     286 
    584287                        } else { 
    585                          
     288 
    586289                                $a2r["defaultshipto"] = 1; 
    587                                  
     290 
    588291                        }//endif - shiptoaddress1 
    589292 
    590                         insertA2R($db, $a2r);            
    591                          
     293                        $this->v096insertA2R($db, $a2r); 
     294 
    592295                }//endwhile 
    593                  
     296 
    594297                //Lastly, we need to remove the shipto fields 
    595298                $alterstatement = " 
    596                         ALTER TABLE `clients`  
     299                        ALTER TABLE `clients` 
    597300                                DROP COLUMN `address1`, 
    598301                                DROP COLUMN `address2`, 
     
    606309                                DROP COLUMN `shiptostate`, 
    607310                                DROP COLUMN `shiptopostalcode`, 
    608                                 DROP COLUMN `shiptocountry`";    
    609  
    610                 $db->query($alterstatement); 
    611          
     311                                DROP COLUMN `shiptocountry`"; 
     312 
     313                $this->db->query($alterstatement); 
     314 
    612315        }//end function 
    613          
    614          
    615         function insertA2R($db, $variables){ 
    616          
     316 
     317 
     318        function v096insertA2R($variables){ 
     319 
    617320                // Create the relation record 
    618321                $insertstatement = " 
     
    640343                                NOW() 
    641344                        )"; 
    642                  
    643                 $db->query($insertstatement);    
    644                          
     345 
     346                $this->db->query($insertstatement); 
     347 
    645348        }//end function - insertA2R 
    646          
    647          
    648         function insertAddress($db, $variables){ 
    649          
     349 
     350 
     351        function v096insertAddress($variables){ 
     352 
    650353                        $insertaddress = " 
    651354                                INSERT INTO 
    652                                         addresses  
     355                                        addresses 
    653356                                ( 
    654357                                        title, 
     
    677380                                ) 
    678381                        "; 
    679                          
    680                         $db->query($insertaddress); 
    681                          
     382 
     383                        $this->db->query($insertaddress); 
     384 
    682385                        //make sure to get the new address id 
    683                         return $db->insertId();          
    684          
     386                        return $this->db->insertId(); 
     387 
    685388        }//end function - insertAddress 
    686                  
    687          
    688  
    689  
    690         //========================================================= 
    691         // Processor 
    692         //========================================================= 
    693         $phpbmsSession = new phpbmsSession; 
    694         $success = $phpbmsSession->loadDBSettings(false); 
    695  
    696         include_once("include/db.php"); 
    697         $db = new db(false); 
    698         $db->stopOnError = false; 
    699         $db->showError = false; 
    700         $db->logError = false; 
    701  
    702         if($success !== false){ 
    703                  
    704                 if(!$db->connect()) 
    705                         $thereturn = "Could Not Establish Connection To MySQL Server: Check server, user name, and password.";                   
    706                 else { 
    707                         if(!$db->selectSchema()) 
    708                                 $thereturn = "Database (schema) ".MYSQL_DATABASE." could not be selected";                       
    709                         else { 
    710  
    711                                 $phpbmsSession->db = $db; 
    712                                 $phpbmsSession->loadSettings(); 
    713                                  
    714                                 $thereturn=doUpdate($db);        
    715  
    716                         }                
    717                 } 
    718         } else 
    719                 $thereturn = "Could not access settings.php";    
    720                                  
    721  
    722  
    723                 header('Content-Type: text/xml'); 
    724                 ?><?php echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'; ?> 
    725 <response><?php echo $thereturn?></response> 
     389 
     390}//end class updateBMS 
     391 
     392// Processor 
     393//========================================================= 
     394$theModule = new updateBMS($this->db, $this->phpbmsSession, "bms", "../modules/bms/install/"); 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.