[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: usps.php 3 2006-05-27 04:59:07Z user $ 4 ++++ modified as USPS Methods 2.7 03/26/04 by Brad Waite and Fritz Clapp ++++ 5 ++++ incorporating USPS revisions to service names ++++ 6 osCMax Power E-Commerce 7 http://oscdox.com 8 9 Copyright 2006 osCMax 10 11 Released under the GNU General Public License 12 */ 13 14 class usps { 15 var $code, $title, $description, $icon, $enabled, $countries; 16 17 // class constructor 18 function usps() { 19 global $order; 20 21 $this->code = 'usps'; 22 $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE; 23 $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION; 24 $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER; 25 $this->icon = DIR_WS_ICONS . 'shipping_usps.gif'; 26 $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS; 27 $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false); 28 29 if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) { 30 $check_flag = false; 31 $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); 32 while ($check = tep_db_fetch_array($check_query)) { 33 if ($check['zone_id'] < 1) { 34 $check_flag = true; 35 break; 36 } elseif ($check['zone_id'] == $order->delivery['zone_id']) { 37 $check_flag = true; 38 break; 39 } 40 } 41 42 if ($check_flag == false) { 43 $this->enabled = false; 44 } 45 } 46 47 $this->types = array('Express' => 'EXPRESS', 'First Class' => 'First-Class Mail', 'Priority' => 'Priority', 'Parcel' => 'Parcel', 'BPM' => 'Bound Printed Material', 'Library' => 'Library', 'Media' => 'Media Mail'); 48 49 $this->intl_types = array('GXG Document' => 'Global Express Guaranteed Document Service', 50 'GXG Non-Document' => 'Global Express Guaranteed Non-Document Service', 51 'Express' => 'Global Express Mail (EMS)', 52 'Priority Lg' => 'Global Priority Mail - Flat-rate Envelope (Large)', 53 'Priority Sm' => 'Global Priority Mail - Flat-rate Envelope (Small)', 54 'Priority Var' => 'Global Priority Mail - Variable Weight (Single)', 55 'Airmail Letter' => 'Airmail Letter-post', 56 'Airmail Parcel' => 'Airmail Parcel Post', 57 'Surface Letter' => 'Economy (Surface) Letter-post', 58 'Surface Post' => 'Economy (Surface) Parcel Post'); 59 60 $this->countries = $this->country_list(); 61 $this->countryinsure = $this->country_maxinsure(); 62 } 63 64 // class methods 65 function quote($method = '') { 66 global $order, $shipping_weight, $shipping_num_boxes, $transittime; 67 68 if ( tep_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) { 69 $this->_setService($method); 70 } 71 72 $this->_setMachinable('False'); 73 $this->_setContainer('None'); 74 $this->_setSize('REGULAR'); 75 // Insurance module by Kevin Shelton 76 77 // divide the value of the order among the packages based on the order total or subtotal depending on whether or not you have configured to insure tax 78 79 if (MODULE_SHIPPING_USPS_INSURE_TAX == 'True') { 80 $costperpkg = $order->info['total'] / $shipping_num_boxes;} 81 else { 82 $costperpkg = $order->info['subtotal'] / $shipping_num_boxes;} 83 84 // retrieve the maximum allowed insurance for the destination country and if the package value exceeds it then set package value to the maximum allowed 85 86 $maxins = $this->countryinsure[$order->delivery['country']['iso_code_2']]; 87 if ($costperpkg > $maxins) $costperpkg = $maxins; 88 89 // if insurance not allowed for destination or insurance is turned off add nothing to shipping cost 90 91 if (($maxins == 0) || (MODULE_SHIPPING_USPS_INSURE == 'False')) { 92 $insurance = 0; } 93 94 // US and Canada share the same insurance calculation (though not the same maximum) 95 96 else if (($order->delivery['country']['iso_code_2'] == 'US') || ($order->delivery['country']['iso_code_2'] == 'CA')){ 97 if ($costperpkg<=50) { 98 $insurance=MODULE_SHIPPING_USPS_INS1;} 99 else if ($costperpkg<=100) { 100 $insurance=MODULE_SHIPPING_USPS_INS2;} 101 else { 102 $insurance = MODULE_SHIPPING_USPS_INS2 + ((ceil($costperpkg/100) - 1) * MODULE_SHIPPING_USPS_INS3); } 103 } 104 105 // if insurance allowed and is not US or Canada then calculate international insurance 106 107 else { 108 if ($costperpkg<=50) { 109 $insurance=MODULE_SHIPPING_USPS_INS4;} 110 else if ($costperpkg<=100) { 111 $insurance=MODULE_SHIPPING_USPS_INS5;} 112 else { 113 $insurance = MODULE_SHIPPING_USPS_INS5 + ((ceil($costperpkg/100) - 1) * MODULE_SHIPPING_USPS_INS6); } 114 } 115 // usps doesnt accept zero weight 116 $shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight); 117 $shipping_pounds = floor ($shipping_weight); 118 $shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight))); 119 $this->_setWeight($shipping_pounds, $shipping_ounces); 120 // Added by Kevin Chen ([email protected]); Fixes the Parcel Post Bug July 1, 2004 121 // Refer to http://www.usps.com/webtools/htm/Domestic-Rates.htm documentation 122 // Thanks Ryan 123 if($shipping_pounds > 35 || $shipping_ounces < 6){ 124 $this->_setMachinable('False'); 125 } 126 else{ 127 $this->_setMachinable('True'); 128 } 129 // End Kevin Chen July 1, 2004 130 131 if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) { 132 $shiptitle = ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)'; 133 } else { 134 $shiptitle = ''; 135 } 136 137 $uspsQuote = $this->_getQuote(); 138 139 if (is_array($uspsQuote)) { 140 if (isset($uspsQuote['error'])) { 141 $this->quotes = array('module' => $this->title, 142 'error' => $uspsQuote['error']); 143 } else { 144 $this->quotes = array('id' => $this->code, 145 'module' => $this->title . $shiptitle); 146 147 $methods = array(); 148 $size = sizeof($uspsQuote); 149 for ($i=0; $i<$size; $i++) { 150 list($type, $cost) = each($uspsQuote[$i]); 151 152 $title = ((isset($this->types[$type])) ? $this->types[$type] : $type); 153 if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) $title .= $transittime[$type]; 154 155 $methods[] = array('id' => $type, 156 'title' => $title, 157 'cost' => ($cost + $insurance + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes); 158 } 159 160 $this->quotes['methods'] = $methods; 161 162 if ($this->tax_class > 0) { 163 $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 164 } 165 } 166 } else { 167 $this->quotes = array('module' => $this->title, 168 'error' => MODULE_SHIPPING_USPS_TEXT_ERROR); 169 } 170 171 if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); 172 173 return $this->quotes; 174 } 175 176 function check() { 177 if (!isset($this->_check)) { 178 $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'"); 179 $this->_check = tep_db_num_rows($check_query); 180 } 181 return $this->_check; 182 } 183 184 function install() { 185 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 186 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you.', '6', '0', now())"); 187 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS Password', 'MODULE_SHIPPING_USPS_PASSWORD', 'NONE', 'See USERID, above.', '6', '0', now())"); 188 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Which server to use', 'MODULE_SHIPPING_USPS_SERVER', 'production', 'An account at USPS is needed to use the Production server', '6', '0', 'tep_cfg_select_option(array(\'test\', \'production\'), ', now())"); 189 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_USPS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())"); 190 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())"); 191 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); 192 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); 193 tep_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Domestic Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES', 'Express, Priority, First Class, Parcel, BPM, Library, Media,', 'Select the domestic services to be offered:', '6', '14', 'tep_cfg_select_multioption(array(\'Express\', \'Priority\', \'First Class\', \'Parcel\',\'BPM\',\'Library\',\'Media\'), ', now())"); 194 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Int\'l Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_INTL', 'GXG Document, GXG Non-Document, Express, Priority Lg, Priority Sm, Priority Var, Airmail Letter, Airmail Parcel, Surface Letter, Surface Post', 'Select the international services to be offered:', '6', '15', 'tep_cfg_select_multioption(array(\'GXG Document\', \'GXG Non-Document\', \'Express\', \'Priority Lg\', \'Priority Sm\', \'Priority Var\', \'Airmail Letter\', \'Airmail Parcel\', \'Surface Letter\', \'Surface Post\'), ', now())"); 195 tep_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('USPS Options', 'MODULE_SHIPPING_USPS_OPTIONS', 'Display weight, Display transit time', 'Select from the following the USPS options.', '6', '16', 'tep_cfg_select_multioption(array(\'Display weight\', \'Display transit time\'), ', now())"); 196 //configuration values for insurance 197 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('US/Canada to $50', 'MODULE_SHIPPING_USPS_INS1', '1.30', 'US/Canada insurance total up to $50', '6', '0', now())"); 198 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('US/Canada $50-100', 'MODULE_SHIPPING_USPS_INS2', '2.20', 'US/Canada insurance for totals $50.01-$100', '6', '0', now())"); 199 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('US/Canada per $100', 'MODULE_SHIPPING_USPS_INS3', '1.00', 'US/Canada for every $100 over $100 add $', '6', '0', now())"); 200 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('International to $50', 'MODULE_SHIPPING_USPS_INS4', '1.85', 'International insurance total up to $50', '6', '0', now())"); 201 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('International $50-100', 'MODULE_SHIPPING_USPS_INS5', '2.60', 'International insurance for totals $50.01-$100', '6', '0', now())"); 202 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('International per $100', 'MODULE_SHIPPING_USPS_INS6', '1.00', 'International for every $100 over $100 add $', '6', '0', now())"); 203 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Insure Packages', 'MODULE_SHIPPING_USPS_INSURE', 'True', 'Insure packages shipped by USPS?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 204 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Insure Tax', 'MODULE_SHIPPING_USPS_INSURE_TAX', 'True', 'Insure tax on packages shipped by USPS?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 205 } 206 207 function remove() { 208 tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); 209 } 210 211 function keys() { 212 return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_PASSWORD', 'MODULE_SHIPPING_USPS_SERVER', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_TYPES', 'MODULE_SHIPPING_USPS_TYPES_INTL', 'MODULE_SHIPPING_USPS_INS1', 'MODULE_SHIPPING_USPS_INS2', 'MODULE_SHIPPING_USPS_INS3','MODULE_SHIPPING_USPS_INS4', 'MODULE_SHIPPING_USPS_INS5', 'MODULE_SHIPPING_USPS_INS6','MODULE_SHIPPING_USPS_INSURE','MODULE_SHIPPING_USPS_INSURE_TAX'); 213 } 214 215 function _setService($service) { 216 $this->service = $service; 217 } 218 219 function _setWeight($pounds, $ounces=0) { 220 $this->pounds = $pounds; 221 $this->ounces = $ounces; 222 } 223 224 function _setContainer($container) { 225 $this->container = $container; 226 } 227 228 function _setSize($size) { 229 $this->size = $size; 230 } 231 232 function _setMachinable($machinable) { 233 $this->machinable = $machinable; 234 } 235 236 function _getQuote() { 237 global $order, $transittime; 238 239 if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) $transit = TRUE; 240 241 if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { 242 $request = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">'; 243 $services_count = 0; 244 245 if (isset($this->service)) { 246 $this->types = array($this->service => $this->types[$this->service]); 247 } 248 249 $dest_zip = str_replace(' ', '', $order->delivery['postcode']); 250 if ($order->delivery['country']['iso_code_2'] == 'US') $dest_zip = substr($dest_zip, 0, 5); 251 252 reset($this->types); 253 $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES); 254 255 while (list($key, $value) = each($this->types)) { 256 257 if ( !in_array($key, $allowed_types) ) continue; 258 259 $request .= '<Package ID="' . $services_count . '">' . 260 '<Service>' . $key . '</Service>' . 261 '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . 262 '<ZipDestination>' . $dest_zip . '</ZipDestination>' . 263 '<Pounds>' . $this->pounds . '</Pounds>' . 264 '<Ounces>' . $this->ounces . '</Ounces>' . 265 '<Container>' . $this->container . '</Container>' . 266 '<Size>' . $this->size . '</Size>' . 267 '<Machinable>' . $this->machinable . '</Machinable>' . 268 '</Package>'; 269 270 if($transit){ 271 $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID . 272 '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">' . 273 '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' . 274 '<DestinationZip>' . $dest_zip . '</DestinationZip>'; 275 276 switch ($key) { 277 case 'Express': $transreq[$key] = 'API=ExpressMail&XML=' . 278 urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>'); 279 break; 280 case 'Priority': $transreq[$key] = 'API=PriorityMail&XML=' . 281 urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); 282 break; 283 case 'Parcel': $transreq[$key] = 'API=StandardB&XML=' . 284 urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>'); 285 break; 286 default: $transreq[$key] = ''; 287 break; 288 } 289 } 290 291 $services_count++; 292 } 293 $request .= '</RateRequest>'; 294 295 $request = 'API=Rate&XML=' . urlencode($request); 296 } else { 297 $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">' . 298 '<Package ID="0">' . 299 '<Pounds>' . $this->pounds . '</Pounds>' . 300 '<Ounces>' . $this->ounces . '</Ounces>' . 301 '<MailType>Package</MailType>' . 302 '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . 303 '</Package>' . 304 '</IntlRateRequest>'; 305 306 $request = 'API=IntlRate&XML=' . urlencode($request); 307 } 308 309 switch (MODULE_SHIPPING_USPS_SERVER) { 310 case 'production': $usps_server = 'production.shippingapis.com'; 311 $api_dll = 'shippingapi.dll'; 312 break; 313 case 'test': 314 default: $usps_server = 'testing.shippingapis.com'; 315 $api_dll = 'ShippingAPITest.dll'; 316 break; 317 } 318 319 $body = ''; 320 321 $http = new httpClient(); 322 if ($http->Connect($usps_server, 80)) { 323 $http->addHeader('Host', $usps_server); 324 $http->addHeader('User-Agent', 'osCommerce'); 325 $http->addHeader('Connection', 'Close'); 326 327 if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody(); 328 // mail('[email protected]','USPS rate quote response',$body,'From: <[email protected]>'); 329 if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) { 330 while (list($key, $value) = each($transreq)) { 331 if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody(); 332 } 333 } 334 335 $http->Disconnect(); 336 337 } else { 338 return false; 339 } 340 341 $response = array(); 342 while (true) { 343 if ($start = strpos($body, '<Package ID=')) { 344 $body = substr($body, $start); 345 $end = strpos($body, '</Package>'); 346 $response[] = substr($body, 0, $end+10); 347 $body = substr($body, $end+9); 348 } else { 349 break; 350 } 351 } 352 353 $rates = array(); 354 if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { 355 if (sizeof($response) == '1') { 356 if (ereg('<Error>', $response[0])) { 357 $number = ereg('<Number>(.*)</Number>', $response[0], $regs); 358 $number = $regs[1]; 359 $description = ereg('<Description>(.*)</Description>', $response[0], $regs); 360 $description = $regs[1]; 361 362 return array('error' => $number . ' - ' . $description); 363 } 364 } 365 366 $n = sizeof($response); 367 for ($i=0; $i<$n; $i++) { 368 if (strpos($response[$i], '<Postage>')) { 369 $service = ereg('<Service>(.*)</Service>', $response[$i], $regs); 370 $service = $regs[1]; 371 $postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs); 372 $postage = $regs[1]; 373 374 $rates[] = array($service => $postage); 375 376 if ($transit) { 377 switch ($service) { 378 case 'Express': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs); 379 $time = $tregs[1]; 380 if ($time == '' || $time == 'No Data') { 381 $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; 382 } else { 383 $time = 'Tomorrow by ' . $time; 384 } 385 break; 386 case 'Priority': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); 387 $time = $tregs[1]; 388 if ($time == '' || $time == 'No Data') { 389 $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; 390 } elseif ($time == '1') { 391 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; 392 } else { 393 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; 394 } 395 break; 396 case 'Parcel': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); 397 $time = $tregs[1]; 398 if ($time == '' || $time == 'No Data') { 399 $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; 400 } elseif ($time == '1') { 401 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; 402 } else { 403 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; 404 } 405 break; 406 case 'First Class': $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; 407 break; 408 default: $time = ''; 409 break; 410 } 411 if ($time != '') $transittime[$service] = ' (' . $time . ')'; 412 } 413 } 414 } 415 } else { 416 if (ereg('<Error>', $response[0])) { 417 $number = ereg('<Number>(.*)</Number>', $response[0], $regs); 418 $number = $regs[1]; 419 $description = ereg('<Description>(.*)</Description>', $response[0], $regs); 420 $description = $regs[1]; 421 422 return array('error' => $number . ' - ' . $description); 423 } else { 424 $body = $response[0]; 425 $services = array(); 426 while (true) { 427 if ($start = strpos($body, '<Service ID=')) { 428 $body = substr($body, $start); 429 $end = strpos($body, '</Service>'); 430 $services[] = substr($body, 0, $end+10); 431 $body = substr($body, $end+9); 432 } else { 433 break; 434 } 435 } 436 $allowed_types = array(); 437 foreach( explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value ) $allowed_types[$value] = $this->intl_types[$value]; 438 439 $size = sizeof($services); 440 for ($i=0, $n=$size; $i<$n; $i++) { 441 if (strpos($services[$i], '<Postage>')) { 442 $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs); 443 $service = $regs[1]; 444 $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); 445 $postage = $regs[1]; 446 $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs); 447 $time = $tregs[1]; 448 $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time); 449 $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time); 450 $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time); 451 452 if( !in_array($service, $allowed_types) ) continue; 453 if (isset($this->service) && ($service != $this->service) ) { 454 continue; 455 } 456 457 $rates[] = array($service => $postage); 458 if ($time != '') $transittime[$service] = ' (' . $time . ')'; 459 } 460 } 461 } 462 } 463 464 return ((sizeof($rates) > 0) ? $rates : false); 465 } 466 467 function country_list() { 468 $list = array('AF' => 'Afghanistan', 469 'AL' => 'Albania', 470 'DZ' => 'Algeria', 471 'AD' => 'Andorra', 472 'AO' => 'Angola', 473 'AI' => 'Anguilla', 474 'AG' => 'Antigua and Barbuda', 475 'AR' => 'Argentina', 476 'AM' => 'Armenia', 477 'AW' => 'Aruba', 478 'AU' => 'Australia', 479 'AT' => 'Austria', 480 'AZ' => 'Azerbaijan', 481 'BS' => 'Bahamas', 482 'BH' => 'Bahrain', 483 'BD' => 'Bangladesh', 484 'BB' => 'Barbados', 485 'BY' => 'Belarus', 486 'BE' => 'Belgium', 487 'BZ' => 'Belize', 488 'BJ' => 'Benin', 489 'BM' => 'Bermuda', 490 'BT' => 'Bhutan', 491 'BO' => 'Bolivia', 492 'BA' => 'Bosnia-Herzegovina', 493 'BW' => 'Botswana', 494 'BR' => 'Brazil', 495 'VG' => 'British Virgin Islands', 496 'BN' => 'Brunei Darussalam', 497 'BG' => 'Bulgaria', 498 'BF' => 'Burkina Faso', 499 'MM' => 'Burma', 500 'BI' => 'Burundi', 501 'KH' => 'Cambodia', 502 'CM' => 'Cameroon', 503 'CA' => 'Canada', 504 'CV' => 'Cape Verde', 505 'KY' => 'Cayman Islands', 506 'CF' => 'Central African Republic', 507 'TD' => 'Chad', 508 'CL' => 'Chile', 509 'CN' => 'China', 510 'CX' => 'Christmas Island (Australia)', 511 'CC' => 'Cocos Island (Australia)', 512 'CO' => 'Colombia', 513 'KM' => 'Comoros', 514 'CG' => 'Congo (Brazzaville),Republic of the', 515 'ZR' => 'Congo, Democratic Republic of the', 516 'CK' => 'Cook Islands (New Zealand)', 517 'CR' => 'Costa Rica', 518 'CI' => 'Cote d\'Ivoire (Ivory Coast)', 519 'HR' => 'Croatia', 520 'CU' => 'Cuba', 521 'CY' => 'Cyprus', 522 'CZ' => 'Czech Republic', 523 'DK' => 'Denmark', 524 'DJ' => 'Djibouti', 525 'DM' => 'Dominica', 526 'DO' => 'Dominican Republic', 527 'TP' => 'East Timor (Indonesia)', 528 'EC' => 'Ecuador', 529 'EG' => 'Egypt', 530 'SV' => 'El Salvador', 531 'GQ' => 'Equatorial Guinea', 532 'ER' => 'Eritrea', 533 'EE' => 'Estonia', 534 'ET' => 'Ethiopia', 535 'FK' => 'Falkland Islands', 536 'FO' => 'Faroe Islands', 537 'FJ' => 'Fiji', 538 'FI' => 'Finland', 539 'FR' => 'France', 540 'GF' => 'French Guiana', 541 'PF' => 'French Polynesia', 542 'GA' => 'Gabon', 543 'GM' => 'Gambia', 544 'GE' => 'Georgia, Republic of', 545 'DE' => 'Germany', 546 'GH' => 'Ghana', 547 'GI' => 'Gibraltar', 548 'GB' => 'Great Britain and Northern Ireland', 549 'GR' => 'Greece', 550 'GL' => 'Greenland', 551 'GD' => 'Grenada', 552 'GP' => 'Guadeloupe', 553 'GT' => 'Guatemala', 554 'GN' => 'Guinea', 555 'GW' => 'Guinea-Bissau', 556 'GY' => 'Guyana', 557 'HT' => 'Haiti', 558 'HN' => 'Honduras', 559 'HK' => 'Hong Kong', 560 'HU' => 'Hungary', 561 'IS' => 'Iceland', 562 'IN' => 'India', 563 'ID' => 'Indonesia', 564 'IR' => 'Iran', 565 'IQ' => 'Iraq', 566 'IE' => 'Ireland', 567 'IL' => 'Israel', 568 'IT' => 'Italy', 569 'JM' => 'Jamaica', 570 'JP' => 'Japan', 571 'JO' => 'Jordan', 572 'KZ' => 'Kazakhstan', 573 'KE' => 'Kenya', 574 'KI' => 'Kiribati', 575 'KW' => 'Kuwait', 576 'KG' => 'Kyrgyzstan', 577 'LA' => 'Laos', 578 'LV' => 'Latvia', 579 'LB' => 'Lebanon', 580 'LS' => 'Lesotho', 581 'LR' => 'Liberia', 582 'LY' => 'Libya', 583 'LI' => 'Liechtenstein', 584 'LT' => 'Lithuania', 585 'LU' => 'Luxembourg', 586 'MO' => 'Macao', 587 'MK' => 'Macedonia, Republic of', 588 'MG' => 'Madagascar', 589 'MW' => 'Malawi', 590 'MY' => 'Malaysia', 591 'MV' => 'Maldives', 592 'ML' => 'Mali', 593 'MT' => 'Malta', 594 'MQ' => 'Martinique', 595 'MR' => 'Mauritania', 596 'MU' => 'Mauritius', 597 'YT' => 'Mayotte (France)', 598 'MX' => 'Mexico', 599 'MD' => 'Moldova', 600 'MC' => 'Monaco (France)', 601 'MN' => 'Mongolia', 602 'MS' => 'Montserrat', 603 'MA' => 'Morocco', 604 'MZ' => 'Mozambique', 605 'NA' => 'Namibia', 606 'NR' => 'Nauru', 607 'NP' => 'Nepal', 608 'NL' => 'Netherlands', 609 'AN' => 'Netherlands Antilles', 610 'NC' => 'New Caledonia', 611 'NZ' => 'New Zealand', 612 'NI' => 'Nicaragua', 613 'NE' => 'Niger', 614 'NG' => 'Nigeria', 615 'KP' => 'North Korea (Korea, Democratic People\'s Republic of)', 616 'NO' => 'Norway', 617 'OM' => 'Oman', 618 'PK' => 'Pakistan', 619 'PA' => 'Panama', 620 'PG' => 'Papua New Guinea', 621 'PY' => 'Paraguay', 622 'PE' => 'Peru', 623 'PH' => 'Philippines', 624 'PN' => 'Pitcairn Island', 625 'PL' => 'Poland', 626 'PT' => 'Portugal', 627 'QA' => 'Qatar', 628 'RE' => 'Reunion', 629 'RO' => 'Romania', 630 'RU' => 'Russia', 631 'RW' => 'Rwanda', 632 'SH' => 'Saint Helena', 633 'KN' => 'Saint Kitts (St. Christopher and Nevis)', 634 'LC' => 'Saint Lucia', 635 'PM' => 'Saint Pierre and Miquelon', 636 'VC' => 'Saint Vincent and the Grenadines', 637 'SM' => 'San Marino', 638 'ST' => 'Sao Tome and Principe', 639 'SA' => 'Saudi Arabia', 640 'SN' => 'Senegal', 641 'YU' => 'Serbia-Montenegro', 642 'SC' => 'Seychelles', 643 'SL' => 'Sierra Leone', 644 'SG' => 'Singapore', 645 'SK' => 'Slovak Republic', 646 'SI' => 'Slovenia', 647 'SB' => 'Solomon Islands', 648 'SO' => 'Somalia', 649 'ZA' => 'South Africa', 650 'GS' => 'South Georgia (Falkland Islands)', 651 'KR' => 'South Korea (Korea, Republic of)', 652 'ES' => 'Spain', 653 'LK' => 'Sri Lanka', 654 'SD' => 'Sudan', 655 'SR' => 'Suriname', 656 'SZ' => 'Swaziland', 657 'SE' => 'Sweden', 658 'CH' => 'Switzerland', 659 'SY' => 'Syrian Arab Republic', 660 'TW' => 'Taiwan', 661 'TJ' => 'Tajikistan', 662 'TZ' => 'Tanzania', 663 'TH' => 'Thailand', 664 'TG' => 'Togo', 665 'TK' => 'Tokelau (Union) Group (Western Samoa)', 666 'TO' => 'Tonga', 667 'TT' => 'Trinidad and Tobago', 668 'TN' => 'Tunisia', 669 'TR' => 'Turkey', 670 'TM' => 'Turkmenistan', 671 'TC' => 'Turks and Caicos Islands', 672 'TV' => 'Tuvalu', 673 'UG' => 'Uganda', 674 'UA' => 'Ukraine', 675 'AE' => 'United Arab Emirates', 676 'UY' => 'Uruguay', 677 'UZ' => 'Uzbekistan', 678 'VU' => 'Vanuatu', 679 'VA' => 'Vatican City', 680 'VE' => 'Venezuela', 681 'VN' => 'Vietnam', 682 'WF' => 'Wallis and Futuna Islands', 683 'WS' => 'Western Samoa', 684 'YE' => 'Yemen', 685 'ZM' => 'Zambia', 686 'ZW' => 'Zimbabwe'); 687 688 return $list; 689 } 690 // Set up list of maximum allowed insurance values 691 692 function country_maxinsure() { 693 $list = array('AF' => 0, 694 'AL' => 0, 695 'DZ' => 2185, 696 'AD' => 5000, 697 'AO' => 0, 698 'AI' => 415, 699 'AG' => 60, 700 'AR' => 5000, 701 'AM' => 1350, 702 'AW' => 830, 703 'AU' => 3370, 704 'AT' => 5000, 705 'AZ' => 5000, 706 'BS' => 2795, 707 'BH' => 0, 708 'BD' => 5000, 709 'BB' => 220, 710 'BY' => 1323, 711 'BE' => 5000, 712 'BZ' => 1600, 713 'BJ' => 170, 714 'BM' => 440, 715 'BT' => 440, 716 'BO' => 0, 717 'BA' => 5000, 718 'BW' => 145, 719 'BR' => 5000, 720 'VG' => 165, 721 'BN' => 4405, 722 'BG' => 1030, 723 'BF' => 530, 724 'MM' => 4045, 725 'BI' => 790, 726 'KH' => 0, 727 'CM' => 5000, 728 'CA' => 675, 729 'CV' => 0, 730 'KY' => 0, 731 'CF' => 4405, 732 'TD' => 440, 733 'CL' => 0, 734 'CN' => 1130, 735 'CX' => 3370, 736 'CC' => 3370, 737 'CO' => 0, 738 'KM' => 690, 739 'CG' => 1685, 740 'ZR' => 0, 741 'CK' => 980, 742 'CR' => 0, 743 'CI' => 5000, 744 'HR' => 5000, 745 'CU' => 0, 746 'CY' => 5000, 747 'CZ' => 5000, 748 'DK' => 5000, 749 'DJ' => 880, 750 'DM' => 0, 751 'DO' => 0, 752 'TP' => 0, 753 'EC' => 0, 754 'EG' => 1685, 755 'SV' => 0, 756 'GQ' => 0, 757 'ER' => 0, 758 'EE' => 2020, 759 'ET' => 1000, 760 'FK' => 510, 761 'FO' => 5000, 762 'FJ' => 600, 763 'FI' => 5000, 764 'FR' => 5000, 765 'GF' => 5000, 766 'PF' => 1015, 767 'GA' => 485, 768 'GM' => 2575, 769 'GE' => 1350, 770 'DE' => 5000, 771 'GH' => 5000, 772 'GI' => 5000, 773 'GB' => 857, 774 'GR' => 5000, 775 'GL' => 5000, 776 'GD' => 350, 777 'GP' => 5000, 778 'GT' => 0, 779 'GN' => 875, 780 'GW' => 21, 781 'GY' => 10, 782 'HT' => 0, 783 'HN' => 0, 784 'HK' => 5000, 785 'HU' => 5000, 786 'IS' => 5000, 787 'IN' => 2265, 788 'ID' => 0, 789 'IR' => 0, 790 'IQ' => 0, 791 'IE' => 5000, 792 'IL' => 0, 793 'IT' => 5000, 794 'JM' => 0, 795 'JP' => 5000, 796 'JO' => 0, 797 'KZ' => 5000, 798 'KE' => 815, 799 'KI' => 0, 800 'KW' => 1765, 801 'KG' => 1350, 802 'LA' => 0, 803 'LV' => 1350, 804 'LB' => 440, 805 'LS' => 440, 806 'LR' => 440, 807 'LY' => 0, 808 'LI' => 5000, 809 'LT' => 5000, 810 'LU' => 5000, 811 'MO' => 4262, 812 'MK' => 2200, 813 'MG' => 675, 814 'MW' => 50, 815 'MY' => 1320, 816 'MV' => 0, 817 'ML' => 950, 818 'MT' => 5000, 819 'MQ' => 5000, 820 'MR' => 635, 821 'MU' => 270, 822 'YT' => 5000, 823 'MX' => 0, 824 'MD' => 1350, 825 'MC' => 5000, 826 'MN' => 440, 827 'MS' => 2200, 828 'MA' => 5000, 829 'MZ' => 0, 830 'NA' => 4405, 831 'NR' => 220, 832 'NP' => 0, 833 'NL' => 5000, 834 'AN' => 830, 835 'NC' => 1615, 836 'NZ' => 980, 837 'NI' => 440, 838 'NE' => 810, 839 'NG' => 205, 840 'KP' => 0, 841 'NO' => 0, 842 'OM' => 575, 843 'PK' => 270, 844 'PA' => 0, 845 'PG' => 445, 846 'PY' => 0, 847 'PE' => 0, 848 'PH' => 270, 849 'PN' => 0, 850 'PL' => 1350, 851 'PT' => 5000, 852 'QA' => 2515, 853 'RE' => 5000, 854 'RO' => 5000, 855 'RU' => 5000, 856 'RW' => 0, 857 'SH' => 170, 858 'KN' => 210, 859 'LC' => 400, 860 'PM' => 5000, 861 'VC' => 130, 862 'SM' => 5000, 863 'ST' => 440, 864 'SA' => 0, 865 'SN' => 865, 866 'YU' => 5000, 867 'SC' => 0, 868 'SL' => 0, 869 'SG' => 4580, 870 'SK' => 5000, 871 'SI' => 4400, 872 'SB' => 0, 873 'SO' => 440, 874 'ZA' => 1760, 875 'GS' => 510, 876 'KR' => 5000, 877 'ES' => 5000, 878 'LK' => 35, 879 'SD' => 0, 880 'SR' => 535, 881 'SZ' => 560, 882 'SE' => 5000, 883 'CH' => 5000, 884 'SY' => 3080, 885 'TW' => 1350, 886 'TJ' => 1350, 887 'TZ' => 230, 888 'TH' => 1350, 889 'TG' => 2190, 890 'TK' => 295, 891 'TO' => 515, 892 'TT' => 930, 893 'TN' => 2200, 894 'TR' => 880, 895 'TM' => 675, 896 'TC' => 0, 897 'TV' => 4715, 898 'UG' => 0, 899 'UA' => 5000, 900 'AE' => 5000, 901 'UY' => 0, 902 'UZ' => 5000, 903 'VU' => 0, 904 'VA' => 5000, 905 'VE' => 0, 906 'VN' => 0, 907 'WF' => 1615, 908 'WS' => 295, 909 'YE' => 0, 910 'ZM' => 540, 911 'ZW' => 600, 912 'US' => 5000); 913 914 return $list; 915 } 916 } 917 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |