Jump to content



Latest News: (loading..)

- - - - -

HTTP 500 Internal Server Error when I try to edit an order


  • Please log in to reply
14 replies to this topic

#1   Azure Moon

Azure Moon
  • Members
  • 217 posts
  • Real Name:Dawn
  • Gender:Female
  • Location:USA

Posted 02 July 2012 - 01:06 AM

Hi everyone!

I recently had a developer upgrade my website to run on php 5.2.17 and install the newest USPS shipping module, but I haven't had to edit an order since the work was completed.  I have had the Order Editor contribution running on my site for years without issue - until now.  I hesitate to go back to the developer for help because he will NOT fix anything caused by the work he did without me paying him more money.  So here's the deal and I'm hoping someone here can help.

When I clicked on "edit" while in my admin for an order I received today (as well as when I click on edit for any order I received in the past) I receive a HTTP 500 Internal Server Error stating that "The website cannot display the page" and the "Most likely causes:

The website is under maintenance.
The website has a programming error."

Now my website is NOT under maintence, so clearly this has to do with whatever the developer did.  But again, he will not do any work without money upfront...even if something was working before he upgraded my site and now it's not.

So I'm hoping that one of the osC gurus can help me out so I can edit orders once again.  Any and all help will be greatly appreciated - just let me know what I need to provide.

Brightest Blessings,

Azure Moon

#2   MrPhil

MrPhil
  • Members
  • 4,119 posts
  • Real Name:Phil
  • Gender:Male

Posted 02 July 2012 - 01:42 AM

Check all your directories (folders) and PHP files for improper permissions, especially "world writable" 777 or 666. Many servers are set up to trigger 500 errors when they see that. Your programmer may have been lazy and forgotten to restore proper permissions, or they may not be aware. Directories should be 755 and files 644 (except 444 for configure.php) in normal cases, but for unusual server configurations some may need to be 775/664 to permit writes and edits, or even 777/666 if that doesn't work.

Look at the "last modified" dates of your files, and examine all recently modified PHP files to see if they were misedited and empty/blank lines left at the beginning or end of the files. Remove empty/blank lines and save the files. Look in the files to see if the lines look strange -- extra space between all lines, or lines run together, or only dropping down to start a new line (not starting at left margin). If you see any of that, the file was transferred incorrectly and is corrupted.

Finally, if none of that pans out, read http://http://www.catskilltech.com/freeSW/SMF/faqs/index.html#err500 for other causes of 500 errors.

Your programmer sucks if they will not at least help to see if they caused any of the problems (and fix such for free). If it's not their fault, they can demand payment up front.

#3   Azure Moon

Azure Moon
  • Members
  • 217 posts
  • Real Name:Dawn
  • Gender:Female
  • Location:USA

Posted 02 July 2012 - 09:19 PM

Hi Phil!

Thank you so much for getting back to me so quickly!  You had tried to help me back in the beginning of May with my Jewelry Care page throwing a 500 error...thank you again for your help with that!  And after much debate by you and other forum members the solution to that was:

<?php echo //tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?>

Needs to be:

<?php // echo tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?>

The code as it is on your site causes a "500 Internal Server Error" if I try it on my site.

That's the wrong way to "comment out" a line of code.


Now back to this 500 error.  

First off, I forgot to mention that my site is version 2.2-MS2…sorry.  Now per your suggestion I went through my folders and files and all my folders are set to 755, my files are set to 644 and configure files to 444.  EXCEPT I saw that under public_html/images that all of the files for the inventory pictures on my website are set to 755 (is that setting correct?), however the pictures for the last 39 items I added to my website were all set to 777 (that seems odd to me if everything should be 755 or 644, but again I don't know enough about all of this to say one way or another).  So I changed the permissions on all of those 777 pictures to 755, but I'm still getting the 500 error when I click on edit in my admin.  

Now I checked the last modified dates of my files like you suggested, but with me being very UN-versed in all of this and having no idea whatsoever as to what files the developer changed (he refuses to answer my request for a detailed list of the work he performed) I'm not sure what to look for.  I did NOT see any empty/blank lines at the beginning or ends of those recently modified files, but as for "lines that look strange"; again, I don't know what I'm looking for because I’m just not that familiar with the proper format.

I did click on the link you provided of  http://http://www.catskilltech.com/freeSW/SMF/faqs/index.html#err500 but it says the web page cannot be found, so no additional help there.

As for the developer/programmer, I completely agree with you.  If you recall, the developer refused to help me with the Jewelry Care page error unless I paid him.  But actually that had to do with that specific line of code and not necessarily what he did, so I had to give him a pass there, but he could have at least pointed me in the right direction instead of being rude.  And in addition to the Jewelry Care issue, I've encountered two more issues that did NOT exist prior to him doing any work on my web site, so I have attempted to contact him at least a dozen times by both email and telephone, but to no avail.  

I have asked him very politely, both by email and voice mail that since I paid him two separate payments to please provide me with two separate receipts for my accountant (he did two separate things on two separate days and nearly two weeks apart), to fix the issue I now have of extra lines/spaces on both the emails I receive when a customer places an order and the email I receive when someone submits a link and lastly, to provide me with a detailed list of the work he performed so I'd have it for my records, but he either doesn't answer the phone, or doesn't answer my emails.  

One would hope and I think it's safe to assume that someone who advertises on the forums and is also an osCommerce corporate sponsor that they would stand behind their work, but NO.  Clearly the powers that be do not check into these developers before listing their ads on this site.  So everyone BEWARE - just because someone pays osCommerce X amount of money per month to have their ad or listing on here doesn't mean that they're trustworthy!  Before you know it, your original quote will quickly turn into more and more money, with absolutely no guarantee or help afterwards unless you pay more.  

Sorry for venting, but I really shouldn't have these kinds of problems if this developer was truly a good developer.  So again, if you or anyone has any further suggestions as to what I should check, or if I need to copy and paste a file here, please let me know because I really need to be able to edit an order.  And if anyone can recommend a TRULY GOOD developer/programmer that actually stands behind their work, I'd appreciate that info too.

Brightest Blessings,

Azure Moon

#4   MrPhil

MrPhil
  • Members
  • 4,119 posts
  • Real Name:Phil
  • Gender:Male

Posted 03 July 2012 - 12:46 AM

Quote

The code as it is on your site causes a "500 Internal Server Error" if I try it on my site.

I have no idea what you're referring to. Did I copy some code from someone else's earlier post that contained an error?

Quote

I did click on the link you provided of http://http://ww...

I have no idea why it ended up with http://http://. Remove the first http:// and it will work.

Quote

but as for "lines that look strange"; again, I don't know what I'm looking for

At the end of one line (at a ; semicolon), the next line should start (one line down) at the far left, with no extra spacing. If it merely "drops down one line" to start the new one, or is all run together in one line, that's bad.

You'e also looking for files with blank or empty lines at the very beginning or very end. Your file editor or browser should number lines or at least clearly show distinct lines so you can spot if there are any apparently empty lines top or bottom.

Quote

all of the files for the inventory pictures on my website are set to 755

755 for files (such as images) is not harmful. 644 would be preferred, but you can leave 755 alone (no harm done).

Quote

the last 39 items I added to my website were all set to 777

That could cause a 500 error, but you say you changed them to 755 with no improvement. Did you double check that the permissions were actually successfully changed? If you changed them from an FTP client, your actions may have been ignored by the server.

Quote

Sorry for venting

You shouldn't have to put up with that kind of "service" from anyone, especially someone who gives the appearance of being endorsed by the official osC community. I don't know if there's any kind of feedback or complaints mechanism that you could use.

#5   Azure Moon

Azure Moon
  • Members
  • 217 posts
  • Real Name:Dawn
  • Gender:Female
  • Location:USA

Posted 03 July 2012 - 09:30 PM

Hi Phil!

Thanks for getting back to me once again and clarifying everything.  As for the code that I copied and pasted/posted, that was another members solution to the Jewelry Care 500 error that you helped with back in May and I thought that posting that might trigger your memory, but you can ignore that.

I will take a look again at those recently modified files and everything you suggested and hopefully something will turn up because I only get the 500 error when I'm in my admin and click on "edit" in any of the orders I have received.

As for the developer/programmer there really should be someone from osCommerce to contact with complaints about their advertisers/corporate sponsors, but I can't find anything.

Thanks again for explaining everything and I will be sure to let you know what happens.

Brightest Blessings,

Azure Moon

#6   Azure Moon

Azure Moon
  • Members
  • 217 posts
  • Real Name:Dawn
  • Gender:Female
  • Location:USA

Posted 04 July 2012 - 02:17 AM

Hi everyone!

Okay, I went over all the permissions again and they are all set to either 644 or 755, with configure files set to 444, and the images are all set to 755.  So I went through all of the recently modified files to check for blank/empty lines and also checked that the next line of code starts one line down after a semi colon and I didn't see anything, but then again after looking at all of those, I have to admit that I'm a bit cross eyed.

I don't know enough about all of this stuff, but I only get a 500 error when I'm in my admin and click on the edit button directly to the right of a customer's order when I'm in the main "orders" screen and also when I click on the upper right edit button when I'm actually viewing a particular order and it holds true for every order I've ever received.  So it would seem to me that this has something to do with the Order Editor somehow, but since I had a friend install that contribution for me back in 2007 I don't know exactly which files are involved.

Now when I was experiencing the previous 500 error issue back in May with my jewelry care page after the developer upgraded my site from PHP 4.4.9 to PHP 5.2.17 if I switched my site back to PHP 4 through my cPanel the page would display just fine - no 500 error.  That particular page only threw a 500 error after my site had been upgraded by the developer to run on PHP 5.2.17 - every other page worked/displayed fine.  So since he was unwilling to help me without paying him yet more money, I posted the file's content on here and one of the forum members looked at it and found the following and I quote:

<?php echo //tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?>

Needs to be:

<?php // echo tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?>

The code as it is on your site causes a "500 Internal Server Error" if I try it on my site.

That's the wrong way to "comment out" a line of code.




So now out of curiosity I just switched my site back to PHP 4 through my cPanel and instead of the page showing HTTP 500 Internal Server Error at the top of the page and the following on the page itself:

The website cannot display the page

Most likely causes:

The website is under maintenance.
The website has a programming error.


Now when I switch my site back to PHP 4 through my cPanel it has:

http://www.mysite.com/myadminname/edit_orders.php?oID and the order number

at the very top of the page, but the page itself is blank.

Again, my site is version 2.2-MS2 and is currently running PHP 5.2.17.  The developer I hired back in April could not install the newest USPS shipping module unless I had him upgrade my site from PHP 4.4.9 to 5.2.17, or else the module would not work.  So I'm guessing that this new 500 error is like the previous one and it has something to do with PHP 5.2.17 not being as lenient as PHP 4 and there is some amiss in some line of code somewhere, but I have no clue where to look.

So any and all help will be greatly appreciated.

Brightest Blessings,

Azure Moon

Edited by Azure Moon, 04 July 2012 - 02:19 AM.


#7   MrPhil

MrPhil
  • Members
  • 4,119 posts
  • Real Name:Phil
  • Gender:Male

Posted 04 July 2012 - 04:35 PM

I don't think that osC 2.2 MS2 is fully PHP 5 compliant. There are a number of things like register global variables and long array names that have been turned off in PHP 5. Whether (and how) you can turn them back on to limp through for a while, you can discuss with your host (php.ini file). Any add-ons and custom code on your site may have their own compatibility issues. The proper fix is to bring your site up to PHP 5.3 compliance (your host will be at PHP 5.3 before you know it, and that requires even more fixes than PHP 5.2). This involves many code changes to do properly (there are some add-ons that can help with it), which given your skill level, sounds like you're going to have to hire someone to do it for you. Even better would be to move to osC 2.3.1 (already PHP 5.3-ready), but depending on what add-ons you're making use of (as well as the nature of any custom code), that's potentially an even bigger job. It's a bit early, but hosts are starting to move to PHP 5.4, which requires some additional code changes (osC 2.4 is promised out "soon"). Sorry for the bad news, but that's the price of running a Web site.

#8   germ

germ
  • Members
  • 13,921 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 04 July 2012 - 08:12 PM

Go here read the posts by steve_s on how to get the site to make an error log file.

Be sure to add the code on the admin side and not the catalog side.

Then I'd switch the site back to php 5.2.17, try to edit an order, then chek the error log file.
If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."
- Me -

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >

#9   Azure Moon

Azure Moon
  • Members
  • 217 posts
  • Real Name:Dawn
  • Gender:Female
  • Location:USA

Posted 07 July 2012 - 10:25 PM

Hi everyone!

Okay, I spoke to my web host and after researching everything they said that the 500 error that I am receiving when trying to edit an order is in the file public_html/includes/modules/shipping/usps.php on line 343.

While I was on the telephone with my host they turned on the error reporting in my php.ini file and now I get the following error message when I click on edit in my admin:

Fatal error: Call to undefined function tep_round_up() in /home/username/public_html/includes/modules/shipping/usps.php on line 343


So I've posted said file's contents below and I'm hoping that one of the osCommerce gurus can examine it and let me know exactly what's wrong and what needs to be changed so I can get the Order Editor feature working again.  And hopefully making any changes won't mess something else up...fingers crossed.  At this point, if the error really is in this file, then I guess that I shouldn't be surprised that it goes back to whatever the self proclaimed "expert in osCommerce" developer that I hired did when he upgraded my site and installed the newest USPS shipping module. Sigh.  But I digress.

Again, any and all assistance with this will be greatly appreciated.

Brightest Blessings,

Azure Moon


Here is my public_html/includes/modules/shipping/usps.php file:


<?php
/*
  $Id: usps.php,v 1.47 2003/04/08 23:23:42 dgw_ Exp $
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright © 2003 osCommerce
  Released under the GNU General Public License
*/
  class usps {
    var $code, $title, $description, $icon, $enabled, $countries;
// class constructor
    function usps() {
  global $order;
  $this->code = 'usps';
  $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;
  $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;
  $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;
  $this->icon = DIR_WS_ICONS . 'shipping_usps.gif';
  $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;
  $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
  if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {
    $check_flag = false;
    $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");
    while ($check = tep_db_fetch_array($check_query)) {
  if ($check['zone_id'] < 1) {
    $check_flag = true;
    break;
  } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
    $check_flag = true;
    break;
  }
    }
    if ($check_flag == false) {
  $this->enabled = false;
    }
  }
  $this->types = array('Express' => 'Express Mail',
   'First Class' => 'First-Class Mail',
   'Priority' => 'Priority Mail',
   'Parcel' => 'Parcel Post');
if (MODULE_SHIPPING_USPS_PEONLY == 'True'){
    $this->types = array('Express' => 'Express Mail',
   'Priority' => 'Priority Mail');
}

  $this->intl_types = array('GXG Document' => 'Global Express Guaranteed Document Service',
    'GXG Non-Document' => 'Global Express Guaranteed Non-Document Service',
    'Express' => 'Global Express Mail (EMS)',
    'Priority Lg' => 'Global Priority Mail - Flat-rate Envelope (large)',
    'Priority Sm' => 'Global Priority Mail - Flat-rate Envelope (small)',
    'Priority Var' => 'Global Priority Mail - Variable Weight Envelope (single)',
    'Airmail Letter' => 'Airmail Letter Post',
    'Airmail Parcel' => 'Airmail Parcel Post',
    'Surface Letter' => 'Economy (Surface) Letter Post',
    'Surface Post' => 'Economy (Surface) Parcel Post');
  $this->countries = $this->country_list();
    }
// class methods
    function quote($method = '') {
  global $order, $shipping_weight, $shipping_num_boxes;
  if ( tep_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {
    $this->_setService($method);
  }
  $this->_setMachinable('False');
  $this->_setContainer('None');
  $this->_setSize('REGULAR');
// USA Insurance module by Michael May webmasters.winnfreenet.com
   $insurance = 0;
if ($order->delivery['country']['iso_code_2'] == 'US'){
   $insurance = MODULE_SHIPPING_USPS_INS1;
   if ($order->info['total'] > 49){
   $insurance = (MODULE_SHIPPING_USPS_INS1 + MODULE_SHIPPING_USPS_INS2);
   }
   if ($order->info['total'] > 99){
   $insurance2 = round($order->info['total'] / 100);
if ($insurance2 > round($order->info['total'] / 100,0)){
  $insurance2 = round($order->info['total'] / 100,0) + 1;
   }
   $insurance3 = ( MODULE_SHIPPING_USPS_INS3 * $insurance2);
   $insurance = (MODULE_SHIPPING_USPS_INS1 + MODULE_SHIPPING_USPS_INS2 + $insurance3);
   }
   }


// usps doesnt accept zero weight
  $shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight);
  $shipping_pounds = floor ($shipping_weight);
  $shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight)));
  $this->_setWeight($shipping_pounds, $shipping_ounces);
  $uspsQuote = $this->_getQuote();
  if (is_array($uspsQuote)) {
    if (isset($uspsQuote['error'])) {
  $this->quotes = array('module' => $this->title,
    'error' => $uspsQuote['error']);
    } else {
  $this->quotes = array('id' => $this->code,
    'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)');
  $methods = array();
  $size = sizeof($uspsQuote);
  for ($i=0; $i<$size; $i++) {
    list($type, $cost) = each($uspsQuote[$i]);
    $methods[] = array('id' => $type,
   'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),
   'cost' => ($cost + $insurance + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
  }
  $this->quotes['methods'] = $methods;
  if ($this->tax_class > 0) {
    $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  }
    }
  } else {
    $this->quotes = array('module' => $this->title,
  'error' => MODULE_SHIPPING_USPS_TEXT_ERROR);
  }
  if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
  return $this->quotes;
    }
    function check() {
  if (!isset($this->_check)) {
    $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'");
    $this->_check = tep_db_num_rows($check_query);
  }
  return $this->_check;
    }
    function install() {
  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())");
  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 ('Display', 'MODULE_SHIPPING_USPS_PEONLY', 'True', 'Priority and Express only?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  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())");
  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())");
  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())");
  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())");
  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())");
  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())");
  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())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Insurance Rate1', 'MODULE_SHIPPING_USPS_INS1', '1.3', 'Add to total up to $50', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Insurance Rate2', 'MODULE_SHIPPING_USPS_INS2', '.9', 'Add to totals $51-$99 ', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Insurance Rate3', 'MODULE_SHIPPING_USPS_INS3', '1', 'For ever $100 over $100 add', '6', '0', now())");
    }
    function remove() {
  tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
    function keys() {
  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_INS1', 'MODULE_SHIPPING_USPS_INS2', 'MODULE_SHIPPING_USPS_INS3','MODULE_SHIPPING_USPS_PEONLY');
    }
    function _setService($service) {
  $this->service = $service;
    }
    function _setWeight($pounds, $ounces=0) {
  $this->pounds = $pounds;
  $this->ounces = $ounces;
    }
    function _setContainer($container) {
  $this->container = $container;
    }
    function _setSize($size) {
  $this->size = $size;
    }
    function _setMachinable($machinable) {
  $this->machinable = $machinable;
    }
    function _getQuote() {
  global $order;
  if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
    $request  = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">';
    $services_count = 0;
    if (isset($this->service)) {
  $this->types = array($this->service => $this->types[$this->service]);
    }
    $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
    if ($order->delivery['country']['iso_code_2'] == 'US') $dest_zip = substr($dest_zip, 0, 5);
    reset($this->types);
    while (list($key, $value) = each($this->types)) {
  $request .= '<Package ID="' . $services_count . '">' .
  '<Service>' . $key . '</Service>' .
  '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' .
  '<ZipDestination>' . $dest_zip . '</ZipDestination>' .
  '<Pounds>' . $this->pounds . '</Pounds>' .
  '<Ounces>' . $this->ounces . '</Ounces>' .
  '<Container>' . $this->container . '</Container>' .
  '<Size>' . $this->size . '</Size>' .
  '<Machinable>' . $this->machinable . '</Machinable>' .
  '</Package>';
  $services_count++;
    }
    $request .= '</RateRequest>';
    $request = 'API=Rate&XML=' . urlencode($request);
  } else {
    $request  = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">' .
    '<Package ID="0">' .
    '<Pounds>' . $this->pounds . '</Pounds>' .
    '<Ounces>' . $this->ounces . '</Ounces>' .
    '<MailType>Package</MailType>' .
    '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' .
    '</Package>' .
    '</IntlRateRequest>';
    $request = 'API=IntlRate&XML=' . urlencode($request);
  }
  switch (MODULE_SHIPPING_USPS_SERVER) {
    case 'production': $usps_server = 'production.shippingapis.com';
   $api_dll = 'shippingapi.dll';
   break;
    case 'test':
    default:    $usps_server = 'testing.shippingapis.com';
   $api_dll = 'ShippingAPITest.dll';
   break;
  }
  $body = '';
  $http = new httpClient();
  if ($http->Connect($usps_server, 80)) {
    $http->addHeader('Host', $usps_server);
    $http->addHeader('User-Agent', 'osCommerce');
    $http->addHeader('Connection', 'Close');
    if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody();
    $http->Disconnect();
  } else {
    return false;
  }
  $response = array();
  while (true) {
    if ($start = strpos($body, '<Package ID=')) {
  $body = substr($body, $start);
  $end = strpos($body, '</Package>');
  $response[] = substr($body, 0, $end+10);
  $body = substr($body, $end+9);
    } else {
  break;
    }
  }
  $rates = array();
  if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
    if (sizeof($response) == '1') {
  if (ereg('<Error>', $response[0])) {
    $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
    $number = $regs[1];
    $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
    $description = $regs[1];
    return array('error' => $number . ' - ' . $description);
  }
    }
    $n = sizeof($response);
    for ($i=0; $i<$n; $i++) {
  if (strpos($response[$i], '<Postage>')) {
    $service = ereg('<Service>(.*)</Service>', $response[$i], $regs);
    $service = $regs[1];
    $postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs);
    $postage = $regs[1];
    $rates[] = array($service => $postage);
  }
    }
  } else {
    if (ereg('<Error>', $response[0])) {
  $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
  $number = $regs[1];
  $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
  $description = $regs[1];
  return array('error' => $number . ' - ' . $description);
    } else {
  $body = $response[0];
  $services = array();
  while (true) {
    if ($start = strpos($body, '<Service ID=')) {
  $body = substr($body, $start);
  $end = strpos($body, '</Service>');
  $services[] = substr($body, 0, $end+10);
  $body = substr($body, $end+9);
    } else {
  break;
    }
  }
  $size = sizeof($services);
  for ($i=0, $n=$size; $i<$n; $i++) {
    if (strpos($services[$i], '<Postage>')) {
  $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs);
  $service = $regs[1];
  $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);
  $postage = $regs[1];
  if (isset($this->service) && ($service != $this->service) ) {
    continue;
  }
  $rates[] = array($service => $postage);
    }
  }
    }
  }
  return ((sizeof($rates) > 0) ? $rates : false);
    }
    function country_list() {
  $list = array('AF' => 'Afghanistan',
    'AL' => 'Albania',
    'DZ' => 'Algeria',
    'AD' => 'Andorra',
    'AO' => 'Angola',
    'AI' => 'Anguilla',
    'AG' => 'Antigua and Barbuda',
    'AR' => 'Argentina',
    'AM' => 'Armenia',
    'AW' => 'Aruba',
    'AU' => 'Australia',
    'AT' => 'Austria',
    'AZ' => 'Azerbaijan',
    'BS' => 'Bahamas',
    'BH' => 'Bahrain',
    'BD' => 'Bangladesh',
    'BB' => 'Barbados',
    'BY' => 'Belarus',
    'BE' => 'Belgium',
    'BZ' => 'Belize',
    'BJ' => 'Benin',
    'BM' => 'Bermuda',
    'BT' => 'Bhutan',
    'BO' => 'Bolivia',
    'BA' => 'Bosnia-Herzegovina',
    'BW' => 'Botswana',
    'BR' => 'Brazil',
    'VG' => 'British Virgin Islands',
    'BN' => 'Brunei Darussalam',
    'BG' => 'Bulgaria',
    'BF' => 'Burkina Faso',
    'MM' => 'Burma',
    'BI' => 'Burundi',
    'KH' => 'Cambodia',
    'CM' => 'Cameroon',
    'CA' => 'Canada',
    'CV' => 'Cape Verde',
    'KY' => 'Cayman Islands',
    'CF' => 'Central African Republic',
    'TD' => 'Chad',
    'CL' => 'Chile',
    'CN' => 'China',
    'CX' => 'Christmas Island (Australia)',
    'CC' => 'Cocos Island (Australia)',
    'CO' => 'Colombia',
    'KM' => 'Comoros',
    'CG' => 'Congo (Brazzaville),Republic of the',
    'ZR' => 'Congo, Democratic Republic of the',
    'CK' => 'Cook Islands (New Zealand)',
    'CR' => 'Costa Rica',
    'CI' => 'Cote d\'Ivoire (Ivory Coast)',
    'HR' => 'Croatia',
    'CU' => 'Cuba',
    'CY' => 'Cyprus',
    'CZ' => 'Czech Republic',
    'DK' => 'Denmark',
    'DJ' => 'Djibouti',
    'DM' => 'Dominica',
    'DO' => 'Dominican Republic',
    'TP' => 'East Timor (Indonesia)',
    'EC' => 'Ecuador',
    'EG' => 'Egypt',
    'SV' => 'El Salvador',
    'GQ' => 'Equatorial Guinea',
    'ER' => 'Eritrea',
    'EE' => 'Estonia',
    'ET' => 'Ethiopia',
    'FK' => 'Falkland Islands',
    'FO' => 'Faroe Islands',
    'FJ' => 'Fiji',
    'FI' => 'Finland',
    'FR' => 'France',
    'GF' => 'French Guiana',
    'PF' => 'French Polynesia',
    'GA' => 'Gabon',
    'GM' => 'Gambia',
    'GE' => 'Georgia, Republic of',
    'DE' => 'Germany',
    'GH' => 'Ghana',
    'GI' => 'Gibraltar',
    'GB' => 'Great Britain and Northern Ireland',
    'GR' => 'Greece',
    'GL' => 'Greenland',
    'GD' => 'Grenada',
    'GP' => 'Guadeloupe',
    'GT' => 'Guatemala',
    'GN' => 'Guinea',
    'GW' => 'Guinea-Bissau',
    'GY' => 'Guyana',
    'HT' => 'Haiti',
    'HN' => 'Honduras',
    'HK' => 'Hong Kong',
    'HU' => 'Hungary',
    'IS' => 'Iceland',
    'IN' => 'India',
    'ID' => 'Indonesia',
    'IR' => 'Iran',
    'IQ' => 'Iraq',
    'IE' => 'Ireland',
    'IL' => 'Israel',
    'IT' => 'Italy',
    'JM' => 'Jamaica',
    'JP' => 'Japan',
    'JO' => 'Jordan',
    'KZ' => 'Kazakhstan',
    'KE' => 'Kenya',
    'KI' => 'Kiribati',
    'KW' => 'Kuwait',
    'KG' => 'Kyrgyzstan',
    'LA' => 'Laos',
    'LV' => 'Latvia',
    'LB' => 'Lebanon',
    'LS' => 'Lesotho',
    'LR' => 'Liberia',
    'LY' => 'Libya',
    'LI' => 'Liechtenstein',
    'LT' => 'Lithuania',
    'LU' => 'Luxembourg',
    'MO' => 'Macao',
    'MK' => 'Macedonia, Republic of',
    'MG' => 'Madagascar',
    'MW' => 'Malawi',
    'MY' => 'Malaysia',
    'MV' => 'Maldives',
    'ML' => 'Mali',
    'MT' => 'Malta',
    'MQ' => 'Martinique',
    'MR' => 'Mauritania',
    'MU' => 'Mauritius',
    'YT' => 'Mayotte (France)',
    'MX' => 'Mexico',
    'MD' => 'Moldova',
    'MC' => 'Monaco (France)',
    'MN' => 'Mongolia',
    'MS' => 'Montserrat',
    'MA' => 'Morocco',
    'MZ' => 'Mozambique',
    'NA' => 'Namibia',
    'NR' => 'Nauru',
    'NP' => 'Nepal',
    'NL' => 'Netherlands',
    'AN' => 'Netherlands Antilles',
    'NC' => 'New Caledonia',
    'NZ' => 'New Zealand',
    'NI' => 'Nicaragua',
    'NE' => 'Niger',
    'NG' => 'Nigeria',
    'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',
    'NO' => 'Norway',
    'OM' => 'Oman',
    'PK' => 'Pakistan',
    'PA' => 'Panama',
    'PG' => 'Papua New Guinea',
    'PY' => 'Paraguay',
    'PE' => 'Peru',
    'PH' => 'Philippines',
    'PN' => 'Pitcairn Island',
    'PL' => 'Poland',
    'PT' => 'Portugal',
    'QA' => 'Qatar',
    'RE' => 'Reunion',
    'RO' => 'Romania',
    'RU' => 'Russia',
    'RW' => 'Rwanda',
    'SH' => 'Saint Helena',
    'KN' => 'Saint Kitts (St. Christopher and Nevis)',
    'LC' => 'Saint Lucia',
    'PM' => 'Saint Pierre and Miquelon',
    'VC' => 'Saint Vincent and the Grenadines',
    'SM' => 'San Marino',
    'ST' => 'Sao Tome and Principe',
    'SA' => 'Saudi Arabia',
    'SN' => 'Senegal',
    'YU' => 'Serbia-Montenegro',
    'SC' => 'Seychelles',
    'SL' => 'Sierra Leone',
    'SG' => 'Singapore',
    'SK' => 'Slovak Republic',
    'SI' => 'Slovenia',
    'SB' => 'Solomon Islands',
    'SO' => 'Somalia',
    'ZA' => 'South Africa',
    'GS' => 'South Georgia (Falkland Islands)',
    'KR' => 'South Korea (Korea, Republic of)',
    'ES' => 'Spain',
    'LK' => 'Sri Lanka',
    'SD' => 'Sudan',
    'SR' => 'Suriname',
    'SZ' => 'Swaziland',
    'SE' => 'Sweden',
    'CH' => 'Switzerland',
    'SY' => 'Syrian Arab Republic',
    'TW' => 'Taiwan',
    'TJ' => 'Tajikistan',
    'TZ' => 'Tanzania',
    'TH' => 'Thailand',
    'TG' => 'Togo',
    'TK' => 'Tokelau (Union) Group (Western Samoa)',
    'TO' => 'Tonga',
    'TT' => 'Trinidad and Tobago',
    'TN' => 'Tunisia',
    'TR' => 'Turkey',
    'TM' => 'Turkmenistan',
    'TC' => 'Turks and Caicos Islands',
    'TV' => 'Tuvalu',
    'UG' => 'Uganda',
    'UA' => 'Ukraine',
    'AE' => 'United Arab Emirates',
    'UY' => 'Uruguay',
    'UZ' => 'Uzbekistan',
    'VU' => 'Vanuatu',
    'VA' => 'Vatican City',
    'VE' => 'Venezuela',
    'VN' => 'Vietnam',
    'WF' => 'Wallis and Futuna Islands',
    'WS' => 'Western Samoa',
    'YE' => 'Yemen',
    'ZM' => 'Zambia',
    'ZW' => 'Zimbabwe');
  return $list;
    }
  }
?>

#10   germ

germ
  • Members
  • 13,921 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 07 July 2012 - 11:37 PM

Either they're wrong or you posted the wrong file.

No call to that function exists in the code you posted.
If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."
- Me -

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >

#11   germ

germ
  • Members
  • 13,921 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 08 July 2012 - 12:06 PM

Read this
If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."
- Me -

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >

#12   Azure Moon

Azure Moon
  • Members
  • 217 posts
  • Real Name:Dawn
  • Gender:Female
  • Location:USA

Posted 08 July 2012 - 10:13 PM

Hi Germ and everyone!

OMG...please don't shoot me, but I did post the wrong file.  I mistakenly posted the one from the root...sorry!  So let's try this again and as always, any and all help will be greatly appreciated.

Brightest Blessings,

Azure Moon

Here is my OTHER home/username/public_html/includes/modules/shipping/usps.php file:


<?php
/*
$Id: usps.php 5.2.1
+++++ Original contribution by Brad Waite and Fritz Clapp ++++
++++ Revisions and Modifications made by Greg Deeth, 2008 ++++
Copyright 2008 osCommerce
Released under the GNU General Public License
//VERSION: 5.2.1 ALPHA
//LAST UPDATED: January 23rd, 2011 by Fulluv Scents
*/
/////////////////////////////////////////
////////// Sets up USPS Class ///////////
/////////////////////////////////////////
class usps
{
/////////////////////////////////////////
///////////// Sets Variables ////////////
/////////////////////////////////////////

var $code, $title, $description, $icon, $enabled, $countries;

function usps()
  {
  if ( !function_exists('htmlspecialchars_decode') )
  {
    function htmlspecialchars_decode($text)
    {
   return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}
  }
  global $order;
  $this->code = 'usps';
  $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;
  $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;
  $this->icon = DIR_WS_ICONS . 'shipping_usps.gif';
  $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
   if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {
   $check_flag = false;
   $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");
   while ($check = tep_db_fetch_array($check_query)) {
   if ($check['zone_id'] < 1) {
   $check_flag = true;
   break;
   } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
   $check_flag = true;
   break;
   }
   }
   if ($check_flag == false) {
   $this->enabled = false;
   }
   }
  $this->countries = $this->country_list();
  $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;
  $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;
  $this->processing = MODULE_SHIPPING_USPS_PROCESSING;
  $this->dmstc_handling = explode( ", ", MODULE_SHIPPING_USPS_DMSTC_HANDLING);
  $this->intl_handling = explode( ", ", MODULE_SHIPPING_USPS_INTL_HANDLING);
  $this->sig_conf_thresh = MODULE_SHIPPING_USPS_SIG_THRESH;
  $this->types = array(
   'First-Class Mail regimark' => 'First-Class Mail regimark',
   'Media Mail regimark' => 'Media Mail regimark',
   'Parcel Post regimark' => 'Parcel Post regimark',
   'Priority Mail regimark' => 'Priority Mail regimark',
   'Priority Mail regimark Flat Rate Envelope' => 'Priority Mail regimark Flat Rate Envelope',
   'Priority Mail regimark Small Flat Rate Box' => 'Priority Mail regimark Small Flat Rate Box',
   'Priority Mail regimark Medium Flat Rate Box' => 'Priority Mail regimark Medium Flat Rate Box',
   'Priority Mail regimark Large Flat Rate Box' => 'Priority Mail regimark Large Flat Rate Box',
   'Express Mail regimark' => 'Express Mail regimark',
   'Express Mail regimark Flat Rate Envelope' => 'Express Mail regimark Flat Rate Envelope'
   );
  $this->intl_types = array(
   'Global Express' => 'Global Express Guaranteed regimark (GXG)**',
   'Global Express Non-Doc Rect' => 'Global Express Guaranteed regimark Non-Document Rectangular',
   'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed regimark Non-Document Non-Rectangular',
   'USPS GXG Envelopes' => 'USPS GXG tradmrk Envelopes**',
   'Express Mail Int' => 'Express Mail regimark International',
   'Express Mail Int Flat Rate Env' => 'Express Mail regimark International Flat Rate Envelope',
   'Priority Mail International' => 'Priority Mail regimark International',
   'Priority Mail Int Flat Rate Lrg Box' => 'Priority Mail regimark International Large Flat Rate Box',
   'Priority Mail Int Flat Rate Med Box' => 'Priority Mail regimark International Medium Flat Rate Box',
   'Priority Mail Int Flat Rate Small Box' => 'Priority Mail regimark International Small Flat Rate Box**',
   'Priority Mail Int Flat Rate Env' => 'Priority Mail regimark International Flat Rate Envelope**',
   'First-Class Mail Int Lrg Env' => 'First-Class Mail regimark International Large Envelope**',
   'First-Class Mail Int Package' => 'First-Class Mail regimark International Package**',
   'First-Class Mail Int Letter' => 'First-Class Mail regimark International Letter**'
   );
  }
/////////////////////////////////////////
///////////// Ends Variables ////////////
/////////////////////////////////////////

/////////////////////////////////////////
/////////// Sets Country List ///////////
/////////////////////////////////////////
function country_list()
  {
  $list = array(
   'AF' => 'Afghanistan',
   'AL' => 'Albania',
   'DZ' => 'Algeria',
   'AD' => 'Andorra',
   'AO' => 'Angola',
   'AI' => 'Anguilla',
   'AG' => 'Antigua and Barbuda',
   'AR' => 'Argentina',
   'AM' => 'Armenia',
   'AW' => 'Aruba',
   'AU' => 'Australia',
   'AT' => 'Austria',
   'AZ' => 'Azerbaijan',
   'BS' => 'Bahamas',
   'BH' => 'Bahrain',
   'BD' => 'Bangladesh',
   'BB' => 'Barbados',
   'BY' => 'Belarus',
   'BE' => 'Belgium',
   'BZ' => 'Belize',
   'BJ' => 'Benin',
   'BM' => 'Bermuda',
   'BT' => 'Bhutan',
   'BO' => 'Bolivia',
   'BA' => 'Bosnia-Herzegovina',
   'BW' => 'Botswana',
   'BR' => 'Brazil',
   'VG' => 'British Virgin Islands',
   'BN' => 'Brunei Darussalam',
   'BG' => 'Bulgaria',
   'BF' => 'Burkina Faso',
   'MM' => 'Burma',
   'BI' => 'Burundi',
   'KH' => 'Cambodia',
   'CM' => 'Cameroon',
   'CA' => 'Canada',
   'CV' => 'Cape Verde',
   'KY' => 'Cayman Islands',
   'CF' => 'Central African Republic',
   'TD' => 'Chad',
   'CL' => 'Chile',
   'CN' => 'China',
   'CX' => 'Christmas Island (Australia)',
   'CC' => 'Cocos Island (Australia)',
   'CO' => 'Colombia',
   'KM' => 'Comoros',
   'CG' => 'Congo (Brazzaville),Republic of the',
   'ZR' => 'Congo, Democratic Republic of the',
   'CK' => 'Cook Islands (New Zealand)',
   'CR' => 'Costa Rica',
   'CI' => 'Cote d\'Ivoire (Ivory Coast)',
   'HR' => 'Croatia',
   'CU' => 'Cuba',
   'CY' => 'Cyprus',
   'CZ' => 'Czech Republic',
   'DK' => 'Denmark',
   'DJ' => 'Djibouti',
   'DM' => 'Dominica',
   'DO' => 'Dominican Republic',
   'TP' => 'East Timor (Indonesia)',
   'EC' => 'Ecuador',
   'EG' => 'Egypt',
   'SV' => 'El Salvador',
   'GQ' => 'Equatorial Guinea',
   'ER' => 'Eritrea',
   'EE' => 'Estonia',
   'ET' => 'Ethiopia',
   'FK' => 'Falkland Islands',
   'FO' => 'Faroe Islands',
   'FJ' => 'Fiji',
   'FI' => 'Finland',
   'FR' => 'France',
   'GF' => 'French Guiana',
   'PF' => 'French Polynesia',
   'GA' => 'Gabon',
   'GM' => 'Gambia',
   'GE' => 'Georgia, Republic of',
   'DE' => 'Germany',
   'GH' => 'Ghana',
   'GI' => 'Gibraltar',
   'GB' => 'Great Britain and Northern Ireland',
   'GR' => 'Greece',
   'GL' => 'Greenland',
   'GD' => 'Grenada',
   'GP' => 'Guadeloupe',
   'GT' => 'Guatemala',
   'GN' => 'Guinea',
   'GW' => 'Guinea-Bissau',
   'GY' => 'Guyana',
   'HT' => 'Haiti',
   'HN' => 'Honduras',
   'HK' => 'Hong Kong',
   'HU' => 'Hungary',
   'IS' => 'Iceland',
   'IN' => 'India',
   'ID' => 'Indonesia',
   'IR' => 'Iran',
   'IQ' => 'Iraq',
   'IE' => 'Ireland',
   'IL' => 'Israel',
   'IT' => 'Italy',
   'JM' => 'Jamaica',
   'JP' => 'Japan',
   'JO' => 'Jordan',
   'KZ' => 'Kazakhstan',
   'KE' => 'Kenya',
   'KI' => 'Kiribati',
   'KW' => 'Kuwait',
   'KG' => 'Kyrgyzstan',
   'LA' => 'Laos',
   'LV' => 'Latvia',
   'LB' => 'Lebanon',
   'LS' => 'Lesotho',
   'LR' => 'Liberia',
   'LY' => 'Libya',
   'LI' => 'Liechtenstein',
   'LT' => 'Lithuania',
   'LU' => 'Luxembourg',
   'MO' => 'Macao',
   'MK' => 'Macedonia, Republic of',
   'MG' => 'Madagascar',
   'MW' => 'Malawi',
   'MY' => 'Malaysia',
   'MV' => 'Maldives',
   'ML' => 'Mali',
   'MT' => 'Malta',
   'MQ' => 'Martinique',
   'MR' => 'Mauritania',
   'MU' => 'Mauritius',
   'YT' => 'Mayotte (France)',
   'MX' => 'Mexico',
   'MD' => 'Moldova',
   'MC' => 'Monaco (France)',
   'MN' => 'Mongolia',
   'MS' => 'Montserrat',
   'MA' => 'Morocco',
   'MZ' => 'Mozambique',
   'NA' => 'Namibia',
   'NR' => 'Nauru',
   'NP' => 'Nepal',
   'NL' => 'Netherlands',
   'AN' => 'Netherlands Antilles',
   'NC' => 'New Caledonia',
   'NZ' => 'New Zealand',
   'NI' => 'Nicaragua',
   'NE' => 'Niger',
   'NG' => 'Nigeria',
   'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',
   'NO' => 'Norway',
   'OM' => 'Oman',
   'PK' => 'Pakistan',
   'PA' => 'Panama',
   'PG' => 'Papua New Guinea',
   'PY' => 'Paraguay',
   'PE' => 'Peru',
   'PH' => 'Philippines',
   'PN' => 'Pitcairn Island',
   'PL' => 'Poland',
   'PT' => 'Portugal',
   'QA' => 'Qatar',
   'RE' => 'Reunion',
   'RO' => 'Romania',
   'RU' => 'Russia',
   'RW' => 'Rwanda',
   'SH' => 'Saint Helena',
   'KN' => 'Saint Kitts (St. Christopher and Nevis)',
   'LC' => 'Saint Lucia',
   'PM' => 'Saint Pierre and Miquelon',
   'VC' => 'Saint Vincent and the Grenadines',
   'SM' => 'San Marino',
   'ST' => 'Sao Tome and Principe',
   'SA' => 'Saudi Arabia',
   'SN' => 'Senegal',
   'YU' => 'Serbia-Montenegro',
   'SC' => 'Seychelles',
   'SL' => 'Sierra Leone',
   'SG' => 'Singapore',
   'SK' => 'Slovak Republic',
   'SI' => 'Slovenia',
   'SB' => 'Solomon Islands',
   'SO' => 'Somalia',
   'ZA' => 'South Africa',
   'GS' => 'South Georgia (Falkland Islands)',
   'KR' => 'South Korea (Korea, Republic of)',
   'ES' => 'Spain',
   'LK' => 'Sri Lanka',
   'SD' => 'Sudan',
   'SR' => 'Suriname',
   'SZ' => 'Swaziland',
   'SE' => 'Sweden',
   'CH' => 'Switzerland',
   'SY' => 'Syrian Arab Republic',
   'TW' => 'Taiwan',
   'TJ' => 'Tajikistan',
   'TZ' => 'Tanzania',
   'TH' => 'Thailand',
   'TG' => 'Togo',
   'TK' => 'Tokelau (Union) Group (Western Samoa)',
   'TO' => 'Tonga',
   'TT' => 'Trinidad and Tobago',
   'TN' => 'Tunisia',
   'TR' => 'Turkey',
   'TM' => 'Turkmenistan',
   'TC' => 'Turks and Caicos Islands',
   'TV' => 'Tuvalu',
   'UG' => 'Uganda',
   'UA' => 'Ukraine',
   'AE' => 'United Arab Emirates',
   'UY' => 'Uruguay',
   'UZ' => 'Uzbekistan',
   'VU' => 'Vanuatu',
   'VA' => 'Vatican City',
   'VE' => 'Venezuela',
   'VN' => 'Vietnam',
   'WF' => 'Wallis and Futuna Islands',
   'WS' => 'Western Samoa',
   'YE' => 'Yemen',
   'ZM' => 'Zambia',
   'ZW' => 'Zimbabwe');
   return $list;
  }

/////////////////////////////////////////
/////////// Ends Country List ///////////
/////////////////////////////////////////
/////////////////////////////////////////
////////// Sets Quote ///////////////////
/////////////////////////////////////////
function quote($method = '')
{
global $order, $shipping_weight, $shipping_num_boxes, $transittime, $dispinsure;
if ( tep_not_null($method) && (in_array($method, $this->types) || in_array($method, $this->intl_types)) ) {
$this->_setService($method);
}
if ($shipping_weight <= 0) {$shipping_weight = 0;}
$shipping_weight = ($shipping_weight < 0.0625 ? 0.0625 : $shipping_weight);
$shipping_pounds = floor ($shipping_weight);
$shipping_ounces = tep_round_up((16 * ($shipping_weight - floor($shipping_weight))), 2);
$this->_setWeight($shipping_pounds, $shipping_ounces, $shipping_weight);
if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
$shiptitle = $shipping_pounds . ' lbs, ' . $shipping_ounces . ' oz';
} else {
$shiptitle = '';
}
$uspsQuote = $this->_getQuote();
if (is_array($uspsQuote)) {
if (isset($uspsQuote['error'])) {
$this->quotes = array('module' => $this->title,
'error' => $uspsQuote['error']);
} else {
$this->quotes = array('id' => $this->code,
'module' => $this->title . $shiptitle);
$methods = array();
$size = sizeof($uspsQuote);
for ($i=0; $i<$size; $i++) {
list($type, $cost) = each($uspsQuote[$i]);
$title = ((isset($this->types[$type])) ? $this->types[$type] : $type);
$title .= $transittime[$type] . $dispinsure[$type];
if (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True') {
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost + $insurance + $handling_cost[0]) * $shipping_num_boxes);
} else {
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost + $handling_cost[0]) * $shipping_num_boxes);
}
}
$this->quotes['methods'] = $methods;
if ($this->tax_class > 0) {
$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}
}
} else {
$this->quotes = array('module' => $this->title,
'error' => MODULE_SHIPPING_USPS_TEXT_ERROR);
}
if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
return $this->quotes;
}
function check() {
if (!isset($this->_check)) {
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'");
$this->_check = tep_db_num_rows($check_query);
}
return $this->_check;
}

/////////////////////////////////////////
////////// Ends Quote ///////////////////
/////////////////////////////////////////
/////////////////////////////////////////
//////////// Install Module /////////////
/////////////////////////////////////////
function install()
  {
  tep_db_query("ALTER TABLE `configuration` CHANGE `configuration_value` `configuration_value` TEXT NOT NULL, CHANGE `set_function` `set_function` TEXT NULL DEFAULT NULL");
  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())");
  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 ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you. <u>You must contact USPS to have them switch you to the Production server.</u>  Otherwise this module will not work!', '6', '3', 'tep_cfg_multiinput_list(array(\'\'), ', now())");
  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())");
  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())");
  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())");
  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 ('Display Options', 'MODULE_SHIPPING_USPS_OPTIONS', 'Display weight, Display transit time, Display insurance', 'Select display options', '6', '0', 'tep_cfg_select_multioption(array(\'Display weight\', \'Display transit time\', \'Display insurance\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Processing Time', 'MODULE_SHIPPING_USPS_PROCESSING', '1', 'Days to Process Order', '6', '0', now())");
  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_DMSTC_TYPES', 'First-Class Mail regimark, Media Mail regimark, Parcel Post regimark, Priority Mail regimark, Priority Mail regimark Flat Rate Envelope, Priority Mail regimark Small Flat Rate Box, Priority Mail regimark Medium Flat Rate Box, Priority Mail regimark Large Flat Rate Box, Express Mail regimark, Express Mail regimark Flat Rate Envelope', 'Select the domestic services to be offered:', '6', '4', 'tep_cfg_select_multioption(array(\'First-Class Mail regimark\', \'Media Mail regimark\', \'Parcel Post regimark\', \'Priority Mail regimark\', \'Priority Mail regimark Flat Rate Envelope\', \'Priority Mail regimark Small Flat Rate Box\', \'Priority Mail regimark Medium Flat Rate Box\', \'Priority Mail regimark Large Flat Rate Box\', \'Express Mail regimark\', \'Express Mail regimark Flat Rate Envelope\'), ', now())");
  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 Rates', 'MODULE_SHIPPING_USPS_DMSTC_RATE', 'Retail', 'Charge retail pricing or internet pricing?', '6', '0', 'tep_cfg_select_option(array(\'Retail\', \'Internet\'), ', now())");
  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 Delivery Confirmation', 'MODULE_SHIPPING_USPS_DMST_DEL_CONF', 'True', 'Automatically charge Delivery Confirmation for first class and parcel ($0.19)?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  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 Signature Confirmation', 'MODULE_SHIPPING_USPS_DMST_SIG_CONF', 'True', 'Automatically charge Signature Confirmation when available ($1.95)?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Signature Confirmation Threshold', 'MODULE_SHIPPING_USPS_SIG_THRESH', '100', 'Order total required before Signature Confirmation is triggered?', '6', '0', now())");
  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 Insurance Options', 'MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION', 'False', 'Force USPS Calculated Domestic Insurance?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  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 Flat Handling Fees', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING', '0, 0, 0, 0, 0, 0, 0, 0, 0, 0', 'Add a different handling fee for each shipping type.', '6', '0', 'tep_cfg_multiinput_list(array(\'First-Class\', \'Media\', \'Parcel\', \'Priority\', \'Priority Flat Env\', \'Priority Sm Flat Box\', \'Priority Med Flat Box\', \'Priority Lg Flat Box\', \'Express\', \'Express Flat Env\'), ', now())");
  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 First-Class Threshold', 'MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD', '0, 3.5, 3.5, 10, 10, 13', '<u>Maximums:</u><br>Letters 3.5oz<br>Large envelopes and parcels 13oz', '6', '0', 'tep_cfg_multiinput_duallist_oz(array(\'Letter\', \'Lg Env\', \'Package\'), ', now())");
  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 Other Mail Threshold', 'MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD', '0, 3, 0, 3, 3, 11, 11, 15, 0, 70, 0, 3, 0, 70, 0, 70, 0, 70', '<u>Maximums:</u><br>70 lb', '6', '0', 'tep_cfg_multiinput_duallist_lb(array(\'Flat Rate Envelope\', \'Sm Flat Rate Box\', \'Md Flat Rate Box\', \'Lg Flat Rate Box\', \'Standard Priority\', \'Express FltRt Env\', \'Express Standard\', \'Parcel Pst\', \'Media Mail\'), ', now())");
  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_INTL_TYPES', 'Global Express, Global Express Non-Doc Rect, Global Express Non-Doc Non-Rect, USPS GXG Envelopes, Express Mail Int, Express Mail Int Flat Rate Env, Priority Mail International, Priority Mail Int Flat Rate Env, Priority Mail Int Flat Rate Small Box, Priority Mail Int Flat Rate Med Box, Priority Mail Int Flat Rate Lrg Box, First-Class Mail Int Lrg Env, First-Class Mail Int Package, First-Class Mail Int Letter', 'Select the international services to be offered:', '6', '0', 'tep_cfg_select_multioption(array(\'Global Express\', \'Global Express Non-Doc Rect\', \'Global Express Non-Doc Non-Rect\', \'USPS GXG Envelopes\', \'Express Mail Int\', \'Express Mail Int Flat Rate Env\', \'Priority Mail International\', \'Priority Mail Int Flat Rate Env\', \'Priority Mail Int Flat Rate Small Box\', \'Priority Mail Int Flat Rate Med Box\', \'Priority Mail Int Flat Rate Lrg Box\', \'First-Class Mail Int Lrg Env\', \'First-Class Mail Int Package\', \'First-Class Mail Int Letter\'), ', now())");
  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 Rates', 'MODULE_SHIPPING_USPS_INTL_RATE', 'Retail', 'Charge retail pricing or internet pricing?', '6', '0', 'tep_cfg_select_option(array(\'Retail\', \'Internet\'), ', now())");
  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 Insurance Options', 'MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION', 'False', 'Force USPS Calculated International Insurance?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  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 Flat Handling Fees', 'MODULE_SHIPPING_USPS_INTL_HANDLING', '0', 'Add a flat fee international shipping.', '6', '0', 'tep_cfg_multiinput_list(array(\'\'), ', now())");
  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 Package Sizes', 'MODULE_SHIPPING_USPS_INTL_SIZE', '1, 1, 1, 0', 'Standard package dimensions required by USPS for international rates', '6', '0', 'tep_cfg_multiinput_list(array(\'Width\', \'Length\', \'Height\', \'Girth\'), ', now())");
  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 ('Non USPS Insurance - Domestic and international', 'MODULE_SHIPPING_USPS_INSURE', 'False', 'Would you like to charge insurance for packages independent of USPS, i.e, merchant provided, Stamps.com, Endicia?  If used in conjunction with USPS calculated insurance, the higher of the two will apply.', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS1', '1.75', 'Totals $.01-$50.00', '6', '0', 'currencies->format', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS2', '2.25', 'Totals $50.01-$100', '6', '0', 'currencies->format', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS3', '2.75', 'Totals $100.01-$200', '6', '0', 'currencies->format', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS4', '4.70', 'Totals $200.01-$300', '6', '0', 'currencies->format', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS5', '1.00', 'For every $100 over $300 (add)', '6', '0', 'currencies->format', now())");
  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', 'False', 'Would you like to insure sales tax paid by the customer?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  }

function keys() {
return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_PROCESSING', 'MODULE_SHIPPING_USPS_DMSTC_TYPES', 'MODULE_SHIPPING_USPS_DMSTC_RATE', 'MODULE_SHIPPING_USPS_DMST_DEL_CONF', 'MODULE_SHIPPING_USPS_DMST_SIG_CONF', 'MODULE_SHIPPING_USPS_SIG_THRESH', 'MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING', 'MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD', 'MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD', 'MODULE_SHIPPING_USPS_INTL_TYPES', 'MODULE_SHIPPING_USPS_INTL_RATE', 'MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_INTL_HANDLING', 'MODULE_SHIPPING_USPS_INTL_SIZE', 'MODULE_SHIPPING_USPS_INSURE', 'MODULE_SHIPPING_USPS_INS1', 'MODULE_SHIPPING_USPS_INS2', 'MODULE_SHIPPING_USPS_INS3','MODULE_SHIPPING_USPS_INS4', 'MODULE_SHIPPING_USPS_INS5', 'MODULE_SHIPPING_USPS_INSURE_TAX');
}

/////////////////////////////////////////
///////// End Install Module ////////////
/////////////////////////////////////////
/////////////////////////////////////////
///////////// Remove Module /////////////
/////////////////////////////////////////
function remove()
  {
  tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  }

/////////////////////////////////////////
////////// End Remove Module ////////////
/////////////////////////////////////////
/////////////////////////////////////////
//////////// SET DEFAULTS ///////////////
/////////////////////////////////////////
function _setService($service) {
$this->service = $service;
}

function _setWeight($pounds, $ounces=0, $weight) {
$this->pounds = $pounds;
$this->ounces = $ounces;
$this->weight = $weight;
}

function _setMachinable($machinable) {
$this->machinable = $machinable;
}
/////////////////////////////////////////
//////////// END DEFAULTS ///////////////
/////////////////////////////////////////

/////////////////////////////////////////
/////////// START RATE REQUEST //////////
/////////////////////////////////////////
function _getQuote()
{
global $order, $transittime, $dispinsure;
if (MODULE_SHIPPING_USPS_INSURE_TAX) {$insurable = $order->info['subtotal'] + $order->info['tax'];}
else {$insurable = $order->info['subtotal'];}
$transit = (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS)));
$dispinsurance = (in_array('Display insurance', explode(', ', MODULE_SHIPPING_USPS_OPTIONS)));
$Authentication = explode( ", ", MODULE_SHIPPING_USPS_USERID);
if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY)

  /////////////////////////////////////////
  ////// START USPS DOMESTIC REQUEST //////
  /////////////////////////////////////////
  
  {
  $request  = '<RateV4Request USERID="' . $Authentication[0] . '">' .
'<Revision>2</Revision>';
  $services_count = 0;
  if (isset($this->service)) {
  $this->types = array($this->service => $this->types[$this->service]);
  }
  $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
  if ($order->delivery['country']['iso_code_2'] == 'US') $dest_zip = substr($dest_zip, 0, 5);
  reset($this->types);

   /////////////////////////////////////////
   //// REQUEST IF WITHIN ALLOWED LIST /////
   /////////////////////////////////////////
   $allowed_types = explode(", ", MODULE_SHIPPING_USPS_DMSTC_TYPES);
   while (list($key, $value) = each($this->types)) {
   if ( !in_array($key, $allowed_types) ) continue;

/////////////////////////////////////////
// REQUEST IF WITHIN WEIGHT THRESHOLDS //
/////////////////////////////////////////

$FMT = explode(", ", MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD);
if ($key == 'First-Class Mail regimark'){
$transid = $key;
$key = 'First-Class Mail';
if($this->pounds == 0) {
if($FMT[0] < $this->ounces && $this->ounces <= $FMT[1]) {
$transid = 'First-Class Mail regimark Letter';
$this->FirstClassMailType = 'LETTER';
$this->machinable = 'TRUE';
$this->size = 'REGULAR';
$this->container = 'VARIABLE';
} else if($FMT[2] < $this->ounces && $this->ounces <= $FMT[3]) {
$transid = 'First-Class Mail regimark Large Envelope';
$this->FirstClassMailType = 'FLAT';
$this->machinable = 'TRUE';
$this->size = 'REGULAR';
$this->container = 'VARIABLE';
} else if($FMT[4] < $this->ounces && $this->ounces <= $FMT[5]) {
$transid = 'First-Class Mail regimark Package';
$this->FirstClassMailType = 'PARCEL';
$this->machinable = 'TRUE';
$this->size = 'REGULAR';
$this->container = 'VARIABLE';
} else {
$key = 'none';
}
}
}
$OMT = explode(", ", MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD);
if ($key == 'Priority Mail regimark'){
$transid = $key;
if ($OMT[8] < $this->weight && $this->weight <= $OMT[9]) {
$key = 'Priority Commercial';
$this->container = '';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
if ($key == 'Priority Mail regimark Flat Rate Envelope'){
$transid = $key;
if ($OMT[0] < $this->weight && $this->weight <= $OMT[1]) {
$key = 'Priority Commercial';
$this->container = 'FLAT RATE ENVELOPE';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
if ($key == 'Priority Mail regimark Small Flat Rate Box'){
$transid = $key;
if ($OMT[2] < $this->weight && $this->weight <= $OMT[3]) {
$key = 'Priority Commercial';
$this->container = 'SM FLAT RATE BOX';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
if ($key == 'Priority Mail regimark Medium Flat Rate Box'){
$transid = $key;
if ($OMT[4] < $this->weight && $this->weight <= $OMT[5]) {
$key = 'Priority Commercial';
$this->container = 'MD FLAT RATE BOX';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
if ($key == 'Priority Mail regimark Large Flat Rate Box'){
$transid = $key;
if ($OMT[6] < $this->weight && $this->weight <= $OMT[7]) {
$key = 'Priority Commercial';
$this->container = 'LG FLAT RATE BOX';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
if ($key == 'Express Mail regimark'){
$transid = $key;
if ($OMT[12] < $this->weight && $this->weight <= $OMT[13]) {
$this->container = '';
$key = 'Express Commercial';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
if ($key == 'Express Mail regimark Flat Rate Envelope'){
$transid = $key;
if ($OMT[10] < $this->weight && $this->weight <= $OMT[11]) {
$key = 'Express Commercial';
$this->container = 'FLAT RATE ENVELOPE';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
if ($key == 'Parcel Post regimark'){
$transid = $key;
$key = 'Parcel Post';
if ($OMT[14] < $this->weight && $this->weight <= $OMT[15]){
$this->machinable = 'TRUE';
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}

if ($key == 'Media Mail regimark'){
$transid = $key;
$key = 'Media Mail';
if ($OMT[16] < $this->weight && $this->weight <= $OMT[17]){
$this->size = 'REGULAR';
} else {
$key = 'none';
}
}
/////////////////////////////////////////////
// END REQUEST IF WITHIN WEIGHT THRESHOLDS //
/////////////////////////////////////////////
   $request .=
  '<Package ID="' . $services_count . '">' .
  '<Service>' . $key . '</Service>' .
  '<FirstClassMailType>' . $this->FirstClassMailType . '</FirstClassMailType>' .
  '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' .
  '<ZipDestination>' . $dest_zip . '</ZipDestination>' .
  '<Pounds>' . $this->pounds . '</Pounds>' .
  '<Ounces>' . $this->ounces . '</Ounces>' .
  '<Container>' . $this->container . '</Container>' .
  '<Size>' . $this->size . '</Size>' .
  '<Value>' . $insurable . '</Value>' .
  '<Machinable>' . $this->machinable . '</Machinable>' .
  '<ShipDate>' . date('d-M-Y') . '</ShipDate>' .
  '</Package>';

/////////////////////////////////////////
////// START USPS TRANSIT REQUEST ///////
/////////////////////////////////////////

if($transit)
{
$transitreq  = 'USERID="' . $Authentication[0] . '">' .
'<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' .
'<DestinationZip>' . $dest_zip . '</DestinationZip>';
switch ($key)
{
case 'First-Class Mail':   $transreq[$transid] = 'API=PriorityMail&XML=' .
  urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');
break;
case 'Media Mail':   $transreq[$transid] = 'API=StandardB&XML=' .
  urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>');
break;
case 'Parcel Post':   $transreq[$transid] = 'API=StandardB&XML=' .
  urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>');
break;
case 'Priority Commercial': $transreq[$transid] = 'API=PriorityMail&XML=' .
  urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');
break;
default: $transreq[$transid] = '';
break;
}
}
  
/////////////////////////////////////////
//////// END USPS TRANSIT REQUEST ///////
/////////////////////////////////////////
   $services_count++;
   }
   /////////////////////////////////////////
   ////// END IF WITHIN ALLOWED LIST ///////
   /////////////////////////////////////////
  $request .= '</RateV4Request>';
  $request =  'API=RateV4&XML=' . urlencode($request);
  }
  
  /////////////////////////////////////////
  /////// END USPS DOMESTIC REQUEST ///////
  /////////////////////////////////////////
   else

  /////////////////////////////////////////
  //// START USPS INTERNATIONAL REQUEST ///
  /////////////////////////////////////////
  
  {
  $request =  '<IntlRateV2Request USERID="' . $Authentication[0] . '">' .
'<Revision>2</Revision>' .
'<Package ID="0">' .
'<Pounds>' . $this->pounds . '</Pounds>' .
'<Ounces>' . $this->ounces . '</Ounces>' .
'<Machinable>True</Machinable>' .
'<MailType>All</MailType>' .
'<GXG>' .
  '<POBoxFlag>N</POBoxFlag>' .
  '<GiftFlag>N</GiftFlag>' .
'</GXG>' .
'<ValueOfContents>' . $insurable . '</ValueOfContents>' .
'<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' .
'<Container>RECTANGULAR</Container>' .
'<Size>REGULAR</Size>' ;
  $IPS = explode(", ", MODULE_SHIPPING_USPS_INTL_SIZE);
  $request .= '<Width>' . $IPS[0] . '</Width>' .
'<Length>' . $IPS[1] . '</Length>' .
'<Height>' . $IPS[2] . '</Height>' .
'<Girth>' . $IPS[3] . '</Girth>' .
'<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' .
'<CommercialFlag>Y</CommercialFlag>' .
'<ExtraServices>' .
  '<ExtraService>1</ExtraService>' .
  '<ExtraService>2</ExtraService>' .
'</ExtraServices>' .
'</Package>' .
'</IntlRateV2Request>';
  $request =  'API=IntlRateV2&XML=' . urlencode($request);
  }
  
  /////////////////////////////////////////
  //// END USPS INTERNATIONAL REQUEST /////
  /////////////////////////////////////////
  /////////////////////////////////////////
  /////// USPS HTTP COMMUNICATION /////////
  /////////////////////////////////////////
  
  $usps_server = 'production.shippingapis.com';
  $api_dll = 'shippingAPI.dll';
  $body = '';
  if (!class_exists('httpClient')) {
  include('includes/classes/http_client.php');
  }
  $http = new httpClient();
  if ($http->Connect($usps_server, 80)) {
  $http->addHeader('Host', $usps_server);
  $http->addHeader('User-Agent', 'osCommerce');
  $http->addHeader('Connection', 'Close');
  if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody();
  //  mail([email=""]'user@localhost.com','USPS[/email] Rate Quote response',$body,'From: <[email="user@localhost.com>"]user@localhost.com>'[/email]);
  if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {
  while (list($key, $value) = each($transreq)) {
  if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody();
  //  mail([email=""]'user@localhost.com','USPS[/email] Transit Response',$transresp[$key],'From: <[email="user@localhost.com>"]user@localhost.com>'[/email]);
  }
  }
  $http->Disconnect();
  } else {
  return false;
  }
  $body = htmlspecialchars_decode($body);
  $body = preg_replace('/\&lt;sup\&gt;\&amp;reg;\&lt;\/sup\&gt;/', ' regimark', $body);
  $body = preg_replace('/\&lt;sup\&gt;\&amp;trade;\&lt;\/sup\&gt;/', ' tradmrk', $body);
  /////////////////////////////////////////
  /////END USPS HTTP COMMUNICATION ////////
  /////////////////////////////////////////
  /////////////////////////////////////////
  /////////// START RATE RESPONSE /////////
  /////////////////////////////////////////
  $response = array();
  while (true) {
  if ($start = strpos($body, '<Package ID=')) {
  $body = substr($body, $start);
  $end = strpos($body, '</Package>');
  $response[] = substr($body, 0, $end+10);
  $body = substr($body, $end+9);
  } else {
  break;
  }
  }
  $rates = array();
  $rates_sorter = array();
  if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
   /////////////////////////////////////////
   ///////// START DOMESTIC RESPONSE ///////
   /////////////////////////////////////////
  
   if (sizeof($response) == '1') {
   if (ereg('<Error>', $response[0])) {
   $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
   $number = $regs[1];
   $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
   $description = $regs[1];
   return array('error' => $number . ' - ' . $description);
   }
   }
   $n = sizeof($response);
   for ($i=0; $i<$n; $i++) {
   if (strpos($response[$i], '<Rate>'))
   {
$service = ereg('<MailService>(.*)</MailService>', $response[$i], $regs);
$service = $regs[1];
if ((MODULE_SHIPPING_USPS_DMSTC_RATE == 'Internet') && preg_match('/CommercialRate/', $response[$i]))
{ $postage = ereg('<CommercialRate>(.*)</CommercialRate>', $response[$i], $regs);
  $postage = $regs[1];}
else
    { $postage = ereg('<Rate>(.*)</Rate>', $response[$i], $regs);
  $postage = $regs[1];}
if (preg_match('/Insurance<\/ServiceName><Available>true<\/Available><AvailableOnline>true/', $response[$i]))
{ $insurance = ereg('Insurance</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>(.*)</Price>', $response[$i], $regs);
  $insurance = $regs[1];}
elseif (preg_match('/Insurance<\/ServiceName><Available>true<\/Available><AvailableOnline>false/', $response[$i]))
  { $insurance = ereg('Insurance</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>(.*)</Price>', $response[$i], $regs);
   $insurance = $regs[1];}
else { $insurance = 0; }
if ($insurable<=50)  {$uinsurance=MODULE_SHIPPING_USPS_INS1;}
else if ($insurable<=100) {$uinsurance=MODULE_SHIPPING_USPS_INS2;}
  else if ($insurable<=200) {$uinsurance=MODULE_SHIPPING_USPS_INS3;}
else if ($insurable<=300) {$uinsurance=MODULE_SHIPPING_USPS_INS4;}
else {$uinsurance = MODULE_SHIPPING_USPS_INS4 + ((ceil($insurable/100) -3) * MODULE_SHIPPING_USPS_INS5);}
if (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && MODULE_SHIPPING_USPS_INSURE == 'True')
{$postage = $postage + max($insurance, $uinsurance);}
elseif (MODULE_SHIPPING_USPS_INSURE == 'True')
{$postage = $postage + $uinsurance;}
elseif (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && $insurance > 0)
{$postage = $postage + $insurance;}
if ((MODULE_SHIPPING_USPS_DMST_DEL_CONF == 'True') && (preg_match('/Delivery Confirmation tradmrk<\/ServiceName><Available>true<\/Available>/', $response[$i])))
{
if (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Retail')
{ $del_conf = preg_match('/Delivery Confirmation tradmrk<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>(.*)<\/Price>/', $response[$i], $regs);}
elseif (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Internet')
{
  if (preg_match('/Delivery Confirmation tradmrk<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>0.70<\/Price>/', $response[$i]))
  {$del_conf = preg_match('/Delivery Confirmation tradmrk<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>0.70<\/Price><PriceOnline>(.*)<\/PriceOnline>/', $response[$i], $regs);}
  elseif (preg_match('/Delivery Confirmation tradmrk<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>0.80<\/Price>/', $response[$i]))
  {$del_conf = preg_match('/Delivery Confirmation tradmrk<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>0.80<\/Price><PriceOnline>(.*)<\/PriceOnline>/', $response[$i], $regs);}
}
$del_conf = $regs[1];
$postage = $postage + $del_conf;
}
if ((MODULE_SHIPPING_USPS_DMST_SIG_CONF == 'True') && ($this->sig_conf_thresh <= $order->info['subtotal']) && (preg_match('/Signature Confirmation tradmrk<\/ServiceName><Available>true<\/Available>/', $response[$i])))
{
if (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Retail')
{$sig_conf = preg_match('/Signature Confirmation tradmrk<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>(.*)<\/Price>/', $response[$i], $regs);}
elseif (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Internet')
{$sig_conf = preg_match('/Signature Confirmation tradmrk<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>2.35<\/Price><PriceOnline>(.*)<\/PriceOnline>/', $response[$i], $regs);}
$sig_conf = $regs[1];
$postage = $postage + $sig_conf;
}
   switch ($service)
   {
case 'First-Class Mail regimark':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[0];
break;
case 'First-Class Mail regimark Letter':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[0];
break;
case 'First-Class Mail regimark Large Envelope':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[0];
break;
case 'First-Class Mail regimark Package':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[0];
break;
case 'Media Mail regimark':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[1];
break;
case 'Parcel Post regimark':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[2];
break;
case 'Priority Mail regimark':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[3];
break;
case 'Priority Mail regimark Flat Rate Envelope':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[4];
break;
case 'Priority Mail regimark Small Flat Rate Box':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[5];
break;
case 'Priority Mail regimark Medium Flat Rate Box':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[6];
break;
case 'Priority Mail regimark Large Flat Rate Box':
$time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
$time = $tregs[1];
if ($time == 'Military Mail') {$time = $time;}
else {if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);}
    else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
     if ($time == '1') {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAY;
    } else {
    $time .= MODULE_SHIPPING_USPS_TEXT_DAYS;
    }
}
$message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess);
$message = $mess[1];
if ($message != '') {$time .= ' - ' . $message;}
$postage = $postage + $this->dmstc_handling[7];
break;
case 'Express Mail regimark':
$time = ereg('<CommitmentDate>(.*)</CommitmentDate>', $response[$i], $regs);
$time = $regs[1];
if ($time == 'Overnight to many areas' && $this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($this->processing + 1) . MODULE_SHIPPING_USPS_TEXT_DAYS;;}
elseif ($time == 'Overnight to many areas') {$time = '---' . $time;}
else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
if ($time == '1') {$time .= MODULE_SHIPPING_USPS_TEXT_DAY;}
elseif ($time > '2' && $time <= '9') {$time .= MODULE_SHIPPING_USPS_TEXT_DAYS;}
$postage = $postage + $this->dmstc_handling[8];
break;
case 'Express Mail regimark Flat Rate Envelope':
$time = ereg('<CommitmentDate>(.*)</CommitmentDate>', $response[$i], $regs);
$time = $regs[1];
if ($time == 'Overnight to many areas' && $this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($this->processing + 1) . MODULE_SHIPPING_USPS_TEXT_DAYS;;}
elseif ($time == 'Overnight to many areas') {$time = '---' . $time;}
else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;}
if ($time == '1') {$time .= MODULE_SHIPPING_USPS_TEXT_DAY;}
elseif ($time > '2' && $time <= '9') {$time .= MODULE_SHIPPING_USPS_TEXT_DAYS;}
$postage = $postage + $this->dmstc_handling[8];
break;
   }
   if (($dispinsurance) && ((MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && $insurance > 0) || (MODULE_SHIPPING_USPS_INSURE == 'True' && $uinsurance > 0)))
   {$dispinsure[$service] = '<br>' . MODULE_SHIPPING_USPS_TEXT_INSURED . '$' . tep_round_up($insurable, 2);}
   else {$dispinsure[$service] = '';}  
   if (($transit) && ($time != ''))
   {$transittime[$service] = '<br>' . $time;}
   else {$transittime[$service] = '';}  
   $rates[] = array($service => $postage);
   $rates_sorter[] = $postage;
   }
   }
   }
   /////////////////////////////////////////
   ////////// END DOMESTIC RESPONSE ////////
   /////////////////////////////////////////
  
   else
  
   /////////////////////////////////////////
   ////// START INTERNATIONAL RESPONSE /////
   /////////////////////////////////////////
   {
   if (ereg('<Error>', $response[0])) {
   $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
   $number = $regs[1];
   $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
   $description = $regs[1];
   return array('error' => $number . ' - ' . $description);
   } else {
   $body = $response[0];
   $services = array();
   while (true) {
   if ($start = strpos($body, '<Service ID=')) {
   $body = substr($body, $start);
   $end = strpos($body, '</Service>');
   $services[] = substr($body, 0, $end+10);
   $body = substr($body, $end+9);
   } else {
   break;
   }
   }
   $allowed_types = array();
   foreach( explode(", ", MODULE_SHIPPING_USPS_INTL_TYPES) as $value ) $allowed_types[$value] = $this->intl_types[$value];
   $size = sizeof($services);
   for ($i=0, $n=$size; $i<$n; $i++) {
   if (strpos($services[$i], '<Postage>')) {
   $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs);
   $service = $regs[1];
   $CMP = ereg('<CommercialPostage>(.*)</CommercialPostage>', $services[$i], $regs);
   $CMP = $regs[1];
   if ($CMP == 0)
   {
   $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);
   $postage = $regs[1];
   }
   else{
   switch (MODULE_SHIPPING_USPS_INTL_RATE) {
   case 'Internet':
   if (preg_match('/<CommercialPostage>/', $services[$i]))
   {
   $postage = ereg('<CommercialPostage>(.*)</CommercialPostage>', $services[$i], $regs);
   $postage = $regs[1];
   }
   else
      {
   $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);
   $postage = $regs[1];
   }
   break;
   case 'Retail':
   $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);
   $postage = $regs[1];
   break;
   }
   }
   $postage = $postage + $this->intl_handling[0];
   if (preg_match('/Insurance<\/ServiceName><Available>True/', $services[$i]))
{ $iinsurance = ereg('Insurance</ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs);
$iinsurance = $regs[1];}
else {$iinsurance = 0;}  
   if ($insurable<=50)  {$iuinsurance=MODULE_SHIPPING_USPS_INS1;}
    else if ($insurable<=100) {$iuinsurance=MODULE_SHIPPING_USPS_INS2;}
     else if ($insurable<=200) {$iuinsurance=MODULE_SHIPPING_USPS_INS3;}
    else if ($insurable<=300) {$iuinsurance=MODULE_SHIPPING_USPS_INS4;}
    else {$iuinsurance = MODULE_SHIPPING_USPS_INS4 + ((ceil($insurable/100) -3) * MODULE_SHIPPING_USPS_INS5);}
   if (MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True' && MODULE_SHIPPING_USPS_INSURE == 'True')
{$postage = $postage + max($iinsurance, $iuinsurance);}
elseif (MODULE_SHIPPING_USPS_INSURE == 'True')
{$postage = $postage + $iuinsurance;}
elseif (MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True')
{$postage = $postage + $iinsurance;}
   $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs);
   $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $tregs[1];
   $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);
   $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);
   $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);
   if( !in_array($service, $allowed_types) ) continue;
   if (isset($this->service) && ($service != $this->service) ) {
   continue;
   }
   if (($dispinsurance) && ((MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True' && $iinsurance > 0) || (MODULE_SHIPPING_USPS_INSURE == 'True' && $iuinsurance > 0)))
   {$dispinsure[$service] = '<br>' . MODULE_SHIPPING_USPS_TEXT_INSURED . '$' . tep_round_up($insurable, 2);}
   else {$dispinsure[$service] = '';}  
   if (($transit) && ($time != ''))
   {$transittime[$service] = '<br>' . $time;}
   else {$transittime[$service] = '';}  
   $rates[] = array($service => $postage);
   $rates_sorter[] = $postage;
   }
   }
   }
   }
   asort($rates_sorter);
   $sorted_rates = array();
   foreach (array_keys($rates_sorter) as $key){
   $sorted_rates[] = $rates[$key];
   }
  
   /////////////////////////////////////////
   /////// END INTERNATIONAL RESPONSE //////
   /////////////////////////////////////////
return ((sizeof($sorted_rates) > 0) ? $sorted_rates : false);
}
/////////////////////////////////////////
/////////// END RATE RESPONSE////////////
/////////////////////////////////////////

}

/////////////////////////////////////////
////////// Ends USPS Class ///////////
/////////////////////////////////////////
?>

#13   germ

germ
  • Members
  • 13,921 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 08 July 2012 - 10:20 PM

View Postgerm, on 08 July 2012 - 12:06 PM, said:

Read this

Make sure the function is in both sides of the site, the admin and the catalog file.
If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."
- Me -

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >

#14   Azure Moon

Azure Moon
  • Members
  • 217 posts
  • Real Name:Dawn
  • Gender:Female
  • Location:USA

Posted 12 July 2012 - 08:53 PM

Hi Germ!

Thanks for getting back to me once again.  As I explained previously, I'm pretty much UN-versed in all of this, especially PHP, so please excuse my ignorance, but exactly what am I looking for and in which files specifically?

Brightest Blessings,

Azure Moon

#15   germ

germ
  • Members
  • 13,921 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 12 July 2012 - 09:00 PM

View Postkentstroker, on 27 August 2009 - 03:51 AM, said:

And sure enough; look to the code - follow the errors and there is an answer.

Solution to the problem.

When installing the USPS Method 4.3.1, the catalog/includes/functions/general.php requires the following edit to be made right after the tep_round definition:

////
// Round up function for non whole numbers by GREG DEETH
// The value for the precision variable determines how many digits after the decimal and rounds the last digit up to the next value
// Precision = 0 -> xx.xxxx = x+
// Precision = 1 -> xx.xxxx = xx.+
// Precision = 2 -> xx.xxxx = xx.x+
  function tep_round_up($number, $precision) {
$number_whole = '';
$num_left_dec = 0;
$num_right_dec = 0;
$num_digits = strlen($number);
$number_out = '';
$i = 0;
while ($i + 1 <= strlen($number))
{
$current_digit = substr($number, $i, ($i + 1) - $num_digits);
if ($current_digit == '.') {
$i = $num_digits + 1;
$num_left_dec = strlen($number_whole);
$num_right_dec = ($num_left_dec + 1) - $num_digits;
} else {
$number_whole = $number_whole . $current_digit;
$i = $i + 1;
}
}
if ($num_digits > 3 && $precision < ($num_digits - $num_left_dec - 1) && $precision >= 0) {
$i = $precision;
$addable = 1;
while ($i > 0) {
$addable = $addable * .1;
$i = $i - 1;
}
$number_out = substr($number, 0, $num_right_dec + $precision) + $addable;
} else {
$number_out = $number;
}
return $number_out;
  }

////

However, this code insertion is *NOT* required by USPS Methods for the catalog/admin/includes/functions/general.php.

Open up the above file, find the tep_round and insert the above code.  In another words; do the same code insertion to BOTH general.php filers and the problem is solved.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."
- Me -

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >