示例#1
0
 /**
  * calls the unfuddle api to get the latest svn revision and compares it to the rev
  * listed in this class
  */
 function checkRevision()
 {
     $this->_error = '';
     $this->_msg = '';
     if (!function_exists('curl_init')) {
         $this->_error = JText::_("SORRY YOU NEED CURL INSTALLED TO CHECK REVISION");
         return false;
     }
     $this->config = array('port' => 80, 'version' => 1, 'account' => 'account_identifier', 'response_type' => 'application/xml', 'username' => 'anonymous', 'password' => 'anonymous', 'project' => 17220, 'default_assignee' => 8527, 'default_milestone' => 0);
     $headers = array('Content-Type: application/xml', 'Accept: application/xml');
     $headers = $this->construct_headers('');
     $url = "http://fabrik.unfuddle.com/api/v1/projects/17220/changesets/latest";
     $this->connection = curl_init($url);
     $xml_string = '';
     $curl_options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1, CURLOPT_VERBOSE => 1, CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_USERPWD => 'anonymous:anonymous');
     foreach ($curl_options as $key => $value) {
         curl_setopt($this->connection, $key, $value);
     }
     $xml = $this->handle_response(curl_exec($this->connection));
     require_once COM_FABRIK_BASE . DS . "includes" . DS . "domit" . DS . "xml_domit_lite_parser.php";
     $xmlDoc = new DOMIT_Lite_Document();
     $ok = $xmlDoc->parseXML($xml);
     if ($ok) {
         $this->_msg .= "<p style='color:green'>Version info obtained from SNV server</p>";
         $rev = $xmlDoc->getElementsByTagName('revision');
         $rev = $rev->item(0);
         $lastestRev = $rev->getText();
         if ($this->SVNREV != $lastestRev) {
             $this->_msg .= "An update is available from the SVN<br>";
             $msg = $xmlDoc->getElementsByTagName('message');
             $msg = $msg->item(0);
             $date = $xmlDoc->getElementsByTagName('created-at');
             $date = $date->item(0);
             $this->_msg .= "<br />message:" . $msg->getText() . "<br>date:" . $date->getText() . "<br><br>";
         } else {
             $this->_msg .= "<p>YOU ARE UP TO DATE!</p>";
         }
         $this->_msg .= "This release versions revision = '{$this->REV}' <br>\n\t\t  This installations current SVN revision = '{$this->SVNREV}' <br>\n\t\t    Latest available SVN rev = '{$lastestRev}'<br />";
     } else {
         $this->_error = JText::_("UNABLE TO PARSE RESPONSE");
     }
 }
示例#2
0
 /**
  * Initializes the global currency converter array
  *
  * @return mixed
  */
 function init()
 {
     global $mosConfig_cachepath, $mosConfig_absolute_path, $vendor_currency, $vmLogger;
     if (!is_array($GLOBALS['converter_array']) && $GLOBALS['converter_array'] !== -1) {
         setlocale(LC_TIME, "en-GB");
         $now = time() + 3600;
         // Time in ECB (Germany) is GMT + 1 hour (3600 seconds)
         if (date("I")) {
             $now += 3600;
             // Adjust for daylight saving time
         }
         $weekday_now_local = gmdate('w', $now);
         // week day, important: week starts with sunday (= 0) !!
         $date_now_local = gmdate('Ymd', $now);
         $time_now_local = gmdate('Hi', $now);
         $time_ecb_update = '1415';
         if (is_writable($mosConfig_cachepath)) {
             $store_path = $mosConfig_cachepath;
         } else {
             $store_path = $mosConfig_absolute_path . "/media";
         }
         $archivefile_name = $store_path . '/daily.xml';
         $ecb_filename = $this->document_address;
         $val = '';
         if (file_exists($archivefile_name) && filesize($archivefile_name) > 0) {
             // timestamp for the Filename
             $file_datestamp = date('Ymd', filemtime($archivefile_name));
             // check if today is a weekday - no updates on weekends
             if (date('w') > 0 && date('w') < 6 && $file_datestamp != $date_now_local && $time_now_local > $time_ecb_update) {
                 $curr_filename = $ecb_filename;
             } else {
                 $curr_filename = $archivefile_name;
                 $this->last_updated = $file_datestamp;
                 $this->archive = false;
             }
         } else {
             $curr_filename = $ecb_filename;
         }
         if (!is_writable($store_path)) {
             $this->archive = false;
             $vmLogger->debug("The file {$archivefile_name} can't be created. The directory {$store_path} is not writable");
         }
         if ($curr_filename == $ecb_filename) {
             // Fetch the file from the internet
             require_once CLASSPATH . 'connectionTools.class.php';
             $contents = vmConnector::handleCommunication($curr_filename);
             $this->last_updated = date('Ymd');
         } else {
             $contents = @file_get_contents($curr_filename);
         }
         if ($contents) {
             // if archivefile does not exist
             if ($this->archive) {
                 // now write new file
                 file_put_contents($archivefile_name, $contents);
             }
             $contents = str_replace("<Cube currency='USD'", " <Cube currency='EUR' rate='1'/> <Cube currency='USD'", $contents);
             /* XML Parsing */
             require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
             $xmlDoc = new DOMIT_Lite_Document();
             if (!$xmlDoc->parseXML($contents, false, true)) {
                 $vmLogger->err('Failed to parse the Currency Converter XML document.');
                 $_SESSION['product_currency'] = $GLOBALS['product_currency'] = $vendor_currency;
                 return false;
             }
             $currency_list = $xmlDoc->getElementsByTagName("Cube");
             // Loop through the Currency List
             for ($i = 0; $i < $currency_list->getLength(); $i++) {
                 $currNode =& $currency_list->item($i);
                 $currency[$currNode->getAttribute("currency")] = $currNode->getAttribute("rate");
                 unset($currNode);
             }
             $GLOBALS['converter_array'] = $currency;
         } else {
             $GLOBALS['converter_array'] = -1;
             $vmLogger->err('Failed to retrieve the Currency Converter XML document.');
             $_SESSION['product_currency'] = $GLOBALS['product_currency'] = $vendor_currency;
             return false;
         }
     }
     return true;
 }
 /**
  * Start parsing an XML document
  *
  * Parses an XML document. The handlers for the configured events are called as many times as necessary.
  *
  * @param  string $data to parse
  */
 function _parse($data = '')
 {
     if ($this->_parser === null) {
         $xml = new DOMIT_Lite_Document();
         $success = $xml->parseXML($data);
         if ($success) {
             //gets a reference to the root element of the cd collection
             $myDocumentElement =& $xml->documentElement;
             $this->_domitParse($myDocumentElement);
             $this->document = $this->document[0];
         }
     } else {
         if (xml_parse($this->_parser, $data)) {
             $this->document = $this->document[0];
         } else {
             //Error handling
             $this->_handleError(xml_get_error_code($this->_parser), xml_get_current_line_number($this->_parser), xml_get_current_column_number($this->_parser));
         }
         xml_parser_free($this->_parser);
     }
 }
示例#4
0
文件: dhl.php 项目: noikiy/owaspbwa
 function get_signature($order_id, $delivery_date)
 {
     global $vmLogger;
     global $VM_LANG, $mosConfig_absolute_path;
     /* Retrieve waybill information from database */
     $dbl = new ps_DB();
     $q = "SELECT tracking_number, label_is_generated, is_international, ";
     $q .= "have_signature ";
     $q .= "FROM #__{vm}_shipping_label ";
     $q .= "WHERE order_id = '" . $order_id . "'";
     $dbl->query($q);
     if (!$dbl->next_record() || !$dbl->f("label_is_generated")) {
         return "couldn't find label info for order #" . $order_id;
     }
     if ($dbl->f('have_signature')) {
         return true;
     }
     $tracking_number = $dbl->f('tracking_number');
     require_once CLASSPATH . "shipping/" . __CLASS__ . ".cfg.php";
     $dhl_url = "https://eCommerce.airborne.com/";
     if (DHL_TEST_MODE == 'TRUE') {
         $dhl_url .= "ApiLandingTest.asp";
     } else {
         $dhl_url .= "ApiLanding.asp";
     }
     require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
     $xmlReq = new DOMIT_Lite_Document();
     $xmlReq->setXMLDeclaration('<?xml version="1.0"?>');
     $root =& $xmlReq->createElement('eCommerce');
     $root->setAttribute('action', 'Request');
     $root->setAttribute('version', '1.1');
     $xmlReq->setDocumentElement($root);
     $requestor =& $xmlReq->createElement('Requestor');
     $id =& $xmlReq->createElement('ID');
     $id->setText(DHL_ID);
     $requestor->appendChild($id);
     $password =& $xmlReq->createElement('Password');
     $password->setText(DHL_PASSWORD);
     $requestor->appendChild($password);
     $root->appendChild($requestor);
     /* Signature Request */
     $signature =& $xmlReq->createElement('Signature');
     $signature->setAttribute('action', 'Get');
     $signature->setAttribute('version', '1.0');
     $shipment =& $xmlReq->createElement('Shipment');
     $nbr =& $xmlReq->createElement('TrackingNbr');
     $nbr->setText($tracking_number);
     $shipment->appendChild($nbr);
     $delivery =& $xmlReq->createElement('Delivery');
     $date =& $xmlReq->createElement('Date');
     $start =& $xmlReq->createElement('Start');
     $start->setText($delivery_date);
     $date->appendChild($start);
     $end =& $xmlReq->createElement('End');
     $end->setText($delivery_date);
     $date->appendChild($end);
     $delivery->appendChild($date);
     $shipment->appendChild($delivery);
     $signature->appendChild($shipment);
     $root->appendChild($signature);
     //		$vmLogger->err($xmlReq->toNormalizedString());
     if (function_exists("curl_init")) {
         $CR = curl_init();
         curl_setopt($CR, CURLOPT_URL, $dhl_url);
         curl_setopt($CR, CURLOPT_POST, 1);
         curl_setopt($CR, CURLOPT_FAILONERROR, true);
         curl_setopt($CR, CURLOPT_POSTFIELDS, $xmlReq->toString());
         curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
         $xmlResult = curl_exec($CR);
         $error = curl_error($CR);
         curl_close($CR);
         if (!empty($error)) {
             return false;
         }
     }
     // XML Parsing
     $xmlResp = new DOMIT_Lite_Document();
     if (!$xmlResp->parseXML($xmlResult, false, true)) {
         return false;
     }
     //		$vmLogger->err($xmlResp->toNormalizedString());
     // Check for success or failure.
     $result_code_list =& $xmlResp->getElementsByPath('//Result/Code');
     $result_code =& $result_code_list->item(0);
     $result_desc_list =& $xmlResp->getElementsByPath('//Result/Desc');
     $result_desc =& $result_desc_list->item(0);
     if ($result_code == NULL) {
         $vmLogger->debug($VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_MISSING_RESULT') . "\n" . $xmlResp->toNormalizedString());
         return false;
     }
     /* 0 is the code for success with viewing a signature. */
     if ($result_code->getText() != 0) {
         $err_msg = '<br /><span class="message">' . $result_desc->getText() . ' [code ' . $result_code->getText() . ']' . '</span>';
         // display an error line for each fault
         $fault_node_list =& $xmlResp->getElementsByPath('//Faults/Fault');
         if ($fault_node_list->getLength() > 0) {
             $err_msg .= '<ul>';
         }
         for ($i = 0; $i < $fault_node_list->getLength(); $i++) {
             $fault_node =& $fault_node_list->item($i);
             $fault_code_node_list =& $fault_node->getElementsByTagName('Code');
             $fault_desc_node_list =& $fault_node->getElementsByTagName('Desc');
             $fault_code_node =& $fault_code_node_list->item(0);
             $fault_desc_node =& $fault_desc_node_list->item(0);
             $err_msg .= '<li>' . $fault_desc_node->getText() . ' [code ' . $fault_code_node->getText() . ']</li>';
         }
         if ($fault_node_list->getLength() > 0) {
             $err_msg .= '</ul>';
         }
         //			echo $err_msg;
         return false;
     }
     $signature_image_node_list =& $xmlResp->getElementsByPath('//Signature/Image');
     $signature_image_node =& $signature_image_node_list->item(0);
     if ($signature_image_node == NULL) {
         return false;
     }
     $signature_image = $signature_image_node->getText();
     /*
      * insert signature image into database and mark that the signature
      * has been retrieved.
      */
     $q = "UPDATE #__{vm}_shipping_label ";
     $q .= "SET ";
     $q .= "have_signature='1', ";
     $q .= "signature_image='" . $signature_image . "' ";
     $q .= "WHERE order_id = '" . $order_id . "'";
     $dbnl = new ps_DB();
     $dbnl->query($q);
     $dbnl->next_record();
     return true;
 }
示例#5
0
文件: usps.php 项目: noikiy/owaspbwa
 function list_rates(&$d)
 {
     global $VM_LANG, $CURRENCY_DISPLAY, $mosConfig_absolute_path;
     $db = new ps_DB();
     $dbv = new ps_DB();
     $dbc = new ps_DB();
     /** Read current Configuration ***/
     require_once CLASSPATH . "shipping/" . __CLASS__ . ".cfg.php";
     $q = "SELECT * FROM `#__{vm}_user_info`, `#__{vm}_country` WHERE user_info_id='" . $db->getEscaped($d["ship_to_info_id"]) . "' AND ( country=country_2_code OR country=country_3_code)";
     $db->query($q);
     $db->next_record();
     $q = "SELECT * FROM #__{vm}_vendor WHERE vendor_id='" . $_SESSION['ps_vendor_id'] . "'";
     $dbv->query($q);
     $dbv->next_record();
     $order_weight = $d['weight'];
     if ($order_weight > 0) {
         //USPS Username
         $usps_username = USPS_USERNAME;
         //USPS Password
         $usps_password = USPS_PASSWORD;
         //USPS Server
         $usps_server = USPS_SERVER;
         //USPS Path
         $usps_path = USPS_PATH;
         //USPS package size
         $usps_packagesize = USPS_PACKAGESIZE;
         //USPS Package ID
         $usps_packageid = 0;
         //USPS International Per Pound Rate
         $usps_intllbrate = USPS_INTLLBRATE;
         //USPS International handling fee
         $usps_intlhandlingfee = USPS_INTLHANDLINGFEE;
         //Pad the shipping weight to allow weight for shipping materials
         $usps_padding = USPS_PADDING;
         $usps_padding = $usps_padding * 0.01;
         $order_weight = $order_weight * $usps_padding + $order_weight;
         //USPS Machinable for Parcel Post
         $usps_machinable = USPS_MACHINABLE;
         if ($usps_machinable == '1') {
             $usps_machinable = 'TRUE';
         } else {
             $usps_machinable = 'FALSE';
         }
         //USPS Shipping Options to display
         $usps_ship[0] = USPS_SHIP0;
         $usps_ship[1] = USPS_SHIP1;
         $usps_ship[2] = USPS_SHIP2;
         $usps_ship[3] = USPS_SHIP3;
         $usps_ship[4] = USPS_SHIP4;
         $usps_ship[5] = USPS_SHIP5;
         $usps_ship[6] = USPS_SHIP6;
         $usps_ship[7] = USPS_SHIP7;
         $usps_ship[8] = USPS_SHIP8;
         $usps_ship[9] = USPS_SHIP9;
         $usps_ship[10] = USPS_SHIP10;
         foreach ($usps_ship as $key => $value) {
             if ($value == '1') {
                 $usps_ship[$key] = 'TRUE';
             } else {
                 $usps_ship[$key] = 'FALSE';
             }
         }
         $usps_intl[0] = USPS_INTL0;
         $usps_intl[1] = USPS_INTL1;
         $usps_intl[2] = USPS_INTL2;
         $usps_intl[3] = USPS_INTL3;
         $usps_intl[4] = USPS_INTL4;
         $usps_intl[5] = USPS_INTL5;
         $usps_intl[6] = USPS_INTL6;
         $usps_intl[7] = USPS_INTL7;
         $usps_intl[8] = USPS_INTL8;
         // $usps_intl[9] = USPS_INTL9;
         foreach ($usps_intl as $key => $value) {
             if ($value == '1') {
                 $usps_intl[$key] = 'TRUE';
             } else {
                 $usps_intl[$key] = 'FALSE';
             }
         }
         //Title for your request
         $request_title = "Shipping Estimate";
         //The zip that you are shipping from
         $source_zip = substr($dbv->f("vendor_zip"), 0, 5);
         $shpService = 'All';
         //"Priority";
         //The zip that you are shipping to
         $dest_country = $db->f("country_2_code");
         if ($dest_country == "GB") {
             $q = "SELECT state_name FROM #__{vm}_state WHERE state_2_code='" . $db->f("state") . "'";
             $dbc->query($q);
             $dbc->next_record();
             $dest_country_name = $dbc->f("state_name");
         } else {
             $dest_country_name = $db->f("country_name");
         }
         $dest_state = $db->f("state");
         $dest_zip = substr($db->f("zip"), 0, 5);
         //$weight_measure
         if ($order_weight < 1) {
             $shipping_pounds_intl = 0;
         } else {
             $shipping_pounds_intl = ceil($order_weight);
         }
         if ($order_weight < 0.88) {
             $shipping_pounds = 0;
             $shipping_ounces = round(16 * ($order_weight - floor($order_weight)));
         } else {
             $shipping_pounds = ceil($order_weight);
             $shipping_ounces = 0;
         }
         $os = array("Mac", "NT", "Irix", "Linux");
         $states = array("AL", "AK", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WI", "WV", "WY");
         //If weight is over 70 pounds, round down to 70 for now.
         //Will update in the future to be able to split the package or something?
         if ($order_weight > 70.0) {
             echo "We are unable to ship USPS as the package weight exceeds the 70 pound limit,<br>please select another shipping method.";
         } else {
             if ($dest_country == "US" && in_array($dest_state, $states)) {
                 /******START OF DOMESTIC RATE******/
                 //the xml that will be posted to usps
                 $xmlPost = 'API=RateV2&XML=<RateV2Request USERID="' . $usps_username . '" PASSWORD="******">';
                 $xmlPost .= '<Package ID="' . $usps_packageid . '">';
                 $xmlPost .= "<Service>" . $shpService . "</Service>";
                 $xmlPost .= "<ZipOrigination>" . $source_zip . "</ZipOrigination>";
                 $xmlPost .= "<ZipDestination>" . $dest_zip . "</ZipDestination>";
                 $xmlPost .= "<Pounds>" . $shipping_pounds . "</Pounds>";
                 $xmlPost .= "<Ounces>" . $shipping_ounces . "</Ounces>";
                 $xmlPost .= "<Size>" . $usps_packagesize . "</Size>";
                 $xmlPost .= "<Machinable>" . $usps_machinable . "</Machinable>";
                 $xmlPost .= "</Package></RateV2Request>";
                 // echo htmlentities( $xmlPost );
                 $host = $usps_server;
                 //$host = "production.shippingapis.com";
                 $path = $usps_path;
                 //"/ups.app/xml/Rate";
                 //$path = "/ShippingAPI.dll";
                 $port = 80;
                 $protocol = "http";
                 $html = "";
                 //echo "<textarea>".$protocol."://".$host.$path."?API=Rate&XML=".$xmlPost."</textarea>";
                 // Using cURL is Up-To-Date and easier!!
                 if (function_exists("curl_init")) {
                     $CR = curl_init();
                     curl_setopt($CR, CURLOPT_URL, $protocol . "://" . $host . $path);
                     //"?API=RateV2&XML=".$xmlPost);
                     curl_setopt($CR, CURLOPT_POST, 1);
                     curl_setopt($CR, CURLOPT_FAILONERROR, true);
                     curl_setopt($CR, CURLOPT_POSTFIELDS, $xmlPost);
                     curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
                     $xmlResult = curl_exec($CR);
                     $error = curl_error($CR);
                     if (!empty($error)) {
                         $GLOBALS['vmLogger']->err(curl_error($CR));
                         $html = "<br/><span class=\"message\">" . $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . " USPS.com</span>";
                         $error = true;
                     } else {
                         /* XML Parsing */
                         require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
                         $xmlDoc = new DOMIT_Lite_Document();
                         $xmlDoc->parseXML($xmlResult, false, true);
                         /* Let's check wether the response from USPS is Success or Failure ! */
                         if (strstr($xmlResult, "Error")) {
                             $error = true;
                             $html = "<span class=\"message\">" . $VM_LANG->_('PHPSHOP_USPS_RESPONSE_ERROR') . "</span><br/>";
                             $error_code = $xmlDoc->getElementsByTagName("Number");
                             $error_code = $error_code->item(0);
                             $error_code = $error_code->getText();
                             $html .= $VM_LANG->_('PHPSHOP_ERROR_CODE') . ": " . $error_code . "<br/>";
                             $error_desc = $xmlDoc->getElementsByTagName("Description");
                             $error_desc = $error_desc->item(0);
                             $error_desc = $error_desc->getText();
                             $html .= $VM_LANG->_('PHPSHOP_ERROR_DESC') . ": " . $error_desc . "<br/>";
                         }
                     }
                     curl_close($CR);
                 } else {
                     $protocol = "http";
                     $fp = fsockopen($protocol . "://" . $host, $errno, $errstr, $timeout = 60);
                     if (!$fp) {
                         $error = true;
                         $html = $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . ": {$errstr} ({$errno})";
                     } else {
                         //send the server request
                         fputs($fp, "POST {$path} HTTP/1.1\r\n");
                         fputs($fp, "Host: {$host}\r\n");
                         fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
                         fputs($fp, "Content-length: " . strlen($xmlPost) . "\r\n");
                         fputs($fp, "Connection: close\r\n\r\n");
                         fputs($fp, $xmlPost . "\r\n\r\n");
                         $xmlResult = '';
                         while (!feof($fp)) {
                             $xmlResult .= fgets($fp, 4096);
                         }
                         if (stristr($xmlResult, "Success")) {
                             /* XML Parsing */
                             require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
                             $xmlDoc = new DOMIT_Lite_Document();
                             $xmlDoc->parseXML($xmlResult, false, true);
                             $error = false;
                         } else {
                             $html = "Error processing the Request to USPS.com";
                             $error = true;
                         }
                     }
                 }
                 if (DEBUG) {
                     echo "XML Post: <br>";
                     echo "<textarea cols='80'>" . $protocol . "://" . $host . $path . "?" . $xmlPost . "</textarea>";
                     echo "<br>";
                     echo "XML Result: <br>";
                     echo "<textarea cols='80' rows='10'>" . $xmlResult . "</textarea>";
                     echo "<br>";
                     echo "Cart Contents: " . $order_weight . " " . $weight_measure . "<br><br>\n";
                 }
                 if ($error) {
                     // comment out, if you don't want the Errors to be shown!!
                     //$vmLogger->err( $html );
                     // Switch to StandardShipping on Error !!!
                     //require_once( CLASSPATH . 'shipping/standard_shipping.php' );
                     //$shipping = new standard_shipping();
                     //$shipping->list_rates( $d );
                     echo "We are unable to ship USPS as the there was an error,<br> please select another shipping method.";
                     return;
                 }
                 // Domestic shipping - add how long it might take
                 $ship_commit[0] = "1 - 2 Days";
                 $ship_commit[1] = "1 - 2 Days";
                 $ship_commit[2] = "1 - 2 Days";
                 $ship_commit[3] = "1 - 3 Days";
                 $ship_commit[4] = "1 - 3 Days";
                 $ship_commit[5] = "1 - 3 Days";
                 $ship_commit[6] = "2 - 9 Days";
                 $ship_commit[7] = "2 - 9 Days";
                 $ship_commit[8] = "2 - 9 Days";
                 $ship_commit[9] = "2 - 9 Days";
                 $ship_commit[10] = "2 Days or More";
                 // retrieve the service and postage items
                 $i = 0;
                 if ($order_weight > 15) {
                     $count = 8;
                     $usps_ship[6] = $usps_ship[7];
                     $usps_ship[7] = $usps_ship[9];
                     $usps_ship[8] = $usps_ship[10];
                 } else {
                     if ($order_weight >= 0.86) {
                         $count = 9;
                         $usps_ship[6] = $usps_ship[7];
                         $usps_ship[7] = $usps_ship[8];
                         $usps_ship[8] = $usps_ship[9];
                         $usps_ship[9] = $usps_ship[10];
                     } else {
                         $count = 10;
                     }
                 }
                 while ($i <= $count) {
                     if (isset($xmlDoc)) {
                         $ship_service[$i] = $xmlDoc->getElementsByTagName('MailService');
                         $ship_service[$i] = $ship_service[$i]->item($i);
                         $ship_service[$i] = $ship_service[$i]->getText();
                         $ship_postage[$i] = $xmlDoc->getElementsByTagName('Rate');
                         $ship_postage[$i] = $ship_postage[$i]->item($i);
                         $ship_postage[$i] = $ship_postage[$i]->getText();
                         if (preg_match('/%$/', USPS_HANDLINGFEE)) {
                             $ship_postage[$i] = $ship_postage[$i] * (1 + substr(USPS_HANDLINGFEE, 0, -1) / 100);
                         } else {
                             $ship_postage[$i] = $ship_postage[$i] + USPS_HANDLINGFEE;
                         }
                         $i++;
                     }
                 }
                 /******END OF DOMESTIC RATE******/
             } else {
                 /******START INTERNATIONAL RATE******/
                 //the xml that will be posted to usps
                 $xmlPost = 'API=IntlRate&XML=<IntlRateRequest USERID="' . $usps_username . '" PASSWORD="******">';
                 $xmlPost .= '<Package ID="' . $usps_packageid . '">';
                 $xmlPost .= "<Pounds>" . $shipping_pounds_intl . "</Pounds>";
                 $xmlPost .= "<Ounces>" . $shipping_ounces . "</Ounces>";
                 $xmlPost .= "<MailType>Package</MailType>";
                 $xmlPost .= "<Country>" . $dest_country_name . "</Country>";
                 $xmlPost .= "</Package></IntlRateRequest>";
                 // echo htmlentities( $xmlPost );
                 $host = $usps_server;
                 //$host = "production.shippingapis.com";
                 $path = $usps_path;
                 //"/ups.app/xml/Rate";
                 //$path = "/ShippingAPI.dll";
                 $port = 80;
                 $protocol = "http";
                 //echo "<textarea>".$protocol."://".$host.$path."?API=Rate&XML=".$xmlPost."</textarea>";
                 // Using cURL is Up-To-Date and easier!!
                 if (function_exists("curl_init")) {
                     $CR = curl_init();
                     curl_setopt($CR, CURLOPT_URL, $protocol . "://" . $host . $path);
                     //"?API=RateV2&XML=".$xmlPost);
                     curl_setopt($CR, CURLOPT_POST, 1);
                     curl_setopt($CR, CURLOPT_FAILONERROR, true);
                     curl_setopt($CR, CURLOPT_POSTFIELDS, $xmlPost);
                     curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
                     $xmlResult = curl_exec($CR);
                     //echo "<textarea>".$xmlResult."</textarea>";
                     $error = curl_error($CR);
                     if (!empty($error)) {
                         $GLOBALS['vmLogger']->err(curl_error($CR));
                         $html = "<br/><span class=\"message\">" . $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . " USPS.com</span>";
                         $error = true;
                     } else {
                         /* XML Parsing */
                         require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
                         $xmlDoc = new DOMIT_Lite_Document();
                         $xmlDoc->parseXML($xmlResult, false, true);
                         /* Let's check wether the response from USPS is Success or Failure ! */
                         if (strstr($xmlResult, "Error")) {
                             $error = true;
                             $html = "<span class=\"message\">" . $VM_LANG->_('PHPSHOP_USPS_RESPONSE_ERROR') . "</span><br/>";
                             $error_code = $xmlDoc->getElementsByTagName("Number");
                             $error_code = $error_code->item(0);
                             $error_code = $error_code->getText();
                             $html .= $VM_LANG->_('PHPSHOP_ERROR_CODE') . ": " . $error_code . "<br/>";
                             $error_desc = $xmlDoc->getElementsByTagName("Description");
                             $error_desc = $error_desc->item(0);
                             $error_desc = $error_desc->getText();
                             $html .= $VM_LANG->_('PHPSHOP_ERROR_DESC') . ": " . $error_desc . "<br/>";
                         }
                     }
                     curl_close($CR);
                 } else {
                     $protocol = "http";
                     $fp = fsockopen($protocol . "://" . $host, $errno, $errstr, $timeout = 60);
                     if (!$fp) {
                         $error = true;
                         $html = $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . ": {$errstr} ({$errno})";
                     } else {
                         //send the server request
                         fputs($fp, "POST {$path} HTTP/1.1\r\n");
                         fputs($fp, "Host: {$host}\r\n");
                         fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
                         fputs($fp, "Content-length: " . strlen($xmlPost) . "\r\n");
                         fputs($fp, "Connection: close\r\n\r\n");
                         fputs($fp, $xmlPost . "\r\n\r\n");
                         $xmlResult = '';
                         while (!feof($fp)) {
                             $xmlResult .= fgets($fp, 4096);
                         }
                         if (stristr($xmlResult, "Success")) {
                             /* XML Parsing */
                             require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
                             $xmlDoc = new DOMIT_Lite_Document();
                             $xmlDoc->parseXML($xmlResult, false, true);
                             $error = false;
                         } else {
                             $html = "Error processing the Request to USPS.com";
                             $error = true;
                         }
                     }
                 }
                 if (DEBUG) {
                     echo "XML Post: <br>";
                     echo "<textarea cols='80'>" . $protocol . "://" . $host . $path . "?" . $xmlPost . "</textarea>";
                     echo "<br>";
                     echo "XML Result: <br>";
                     echo "<textarea cols='80' rows='10'>" . $xmlResult . "</textarea>";
                     echo "<br>";
                     echo "Cart Contents: " . $order_weight . " " . $weight_measure . "<br><br>\n";
                 }
                 if ($error) {
                     // comment out, if you don't want the Errors to be shown!!
                     //$vmLogger->err( $html );
                     // Switch to StandardShipping on Error !!!
                     //require_once( CLASSPATH . 'shipping/standard_shipping.php' );
                     //$shipping = new standard_shipping();
                     //$shipping->list_rates( $d );
                     //return;
                     echo "We are unable to ship USPS as there was an error,<br> please select another shipping method.";
                 }
                 // retrieve the service and postage items
                 $i = 0;
                 $numChildren = 0;
                 $numChildren = $xmlDoc->documentElement->firstChild->childCount;
                 $numChildren = $numChildren - 7;
                 // this line removes the preceeding 6 lines of crap not needed plus 1 to make up for the $i starting at 0
                 while ($i <= $numChildren) {
                     if (isset($xmlDoc)) {
                         $ship_service[$i] = $xmlDoc->getElementsByTagName("SvcDescription");
                         $ship_service[$i] = $ship_service[$i]->item($i);
                         $ship_service[$i] = $ship_service[$i]->getText();
                         $ship_weight[$i] = $xmlDoc->getElementsByTagName("MaxWeight");
                         $ship_weight[$i] = $ship_weight[$i]->item($i);
                         $ship_weight[$i] = $ship_weight[$i]->getText($i);
                     }
                     $i++;
                 }
                 // retrieve postage for countries that support all nine shipping methods and weights
                 $ship_weight[8] = $ship_weight[8] / 16;
                 if ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5] && $ship_weight[6] && $ship_weight[7] && $ship_weight[8]) {
                     $count = 8;
                 } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5] && $ship_weight[6] && $ship_weight[7]) {
                     $count = 7;
                     // $usps_intl[6] = $usps_intl[7];
                 } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5] && $ship_weight[6]) {
                     $count = 6;
                 } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5]) {
                     $count = 5;
                 } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4]) {
                     $count = 4;
                 } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3]) {
                     $count = 3;
                 } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2]) {
                     $count = 2;
                 } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1]) {
                     $count = 1;
                 } elseif ($order_weight <= $ship_weight[0]) {
                     $count = 0;
                 } else {
                     echo "We are unable to ship USPS as the package weight exceeds what your<br>country allows, please select another shipping method.";
                 }
                 $i = 0;
                 while ($i <= $numChildren) {
                     if (isset($xmlDoc)) {
                         $ship_service[$i] = $xmlDoc->getElementsByTagName("SvcDescription");
                         $ship_service[$i] = $ship_service[$i]->item($i);
                         $ship_service[$i] = $ship_service[$i]->getText();
                         $ship_commit[$i] = $xmlDoc->getElementsByTagName("SvcCommitments");
                         $ship_commit[$i] = $ship_commit[$i]->item($i);
                         $ship_commit[$i] = $ship_commit[$i]->getText();
                         $ship_postage[$i] = $xmlDoc->getElementsByTagName("Postage");
                         $ship_postage[$i] = $ship_postage[$i]->item($i);
                         $ship_postage[$i] = $ship_postage[$i]->getText($i);
                         $ship_postage[$i] = $ship_postage[$i] + USPS_INTLHANDLINGFEE;
                         $i++;
                     }
                     /******END INTERNATIONAL RATE******/
                 }
             }
             $i = 0;
             while ($i <= $count) {
                 $html = "";
                 // USPS returns Charges in USD.
                 $charge[$i] = $ship_postage[$i];
                 $ship_postage[$i] = $CURRENCY_DISPLAY->getFullValue($charge[$i]);
                 $shipping_rate_id = urlencode(__CLASS__ . "|USPS|" . $ship_service[$i] . "|" . $charge[$i]);
                 //$checked = (@$d["shipping_rate_id"] == $value) ? "checked=\"checked\"" : "";
                 $html .= "\n<input type=\"radio\" name=\"shipping_rate_id\" checked=\"checked\" value=\"{$shipping_rate_id}\" id=\"{$shipping_rate_id}\" />\n";
                 $_SESSION[$shipping_rate_id] = 1;
                 $html .= "<label for=\"{$shipping_rate_id}\">";
                 $html .= "USPS " . $ship_service[$i] . " ";
                 $html .= "<strong>(" . $ship_postage[$i] . ")</strong>";
                 if (USPS_SHOW_DELIVERY_QUOTE == 1) {
                     $html .= "&nbsp;&nbsp;-&nbsp;&nbsp;" . $ship_commit[$i];
                 }
                 $html .= "</label>";
                 $html .= "<br />";
                 if ($dest_country_name == "United States" && $usps_ship[$i] == "TRUE") {
                     echo $html;
                 } else {
                     if ($dest_country_name != "United States" && $usps_intl[$i] == "TRUE") {
                         echo $html;
                     }
                 }
                 $i++;
             }
         }
     }
     return true;
 }
示例#6
0
 function list_rates(&$d)
 {
     global $vendor_country_2_code, $vendor_currency, $vmLogger;
     global $VM_LANG, $CURRENCY_DISPLAY, $mosConfig_absolute_path;
     $db = new ps_DB();
     $dbv = new ps_DB();
     $cart = $_SESSION['cart'];
     /** Read current Configuration ***/
     require_once CLASSPATH . "shipping/" . __CLASS__ . ".cfg.php";
     $q = "SELECT * FROM #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR country=country_3_code)";
     $db->query($q);
     $q = "SELECT * FROM #__{vm}_vendor WHERE vendor_id='" . $_SESSION['ps_vendor_id'] . "'";
     $dbv->query($q);
     $dbv->next_record();
     $order_weight = $d['weight'];
     $html = "";
     if ($order_weight > 0) {
         if ($order_weight < 1) {
             $order_weight = 1;
         }
         if ($order_weight > 150.0) {
             $order_weight = 150.0;
         }
         //Access code for online tools at ups.com
         $ups_access_code = UPS_ACCESS_CODE;
         //Username from registering for online tools at ups.com
         $ups_user_id = UPS_USER_ID;
         //Password from registering for online tools at ups.com
         $ups_user_password = UPS_PASSWORD;
         //Title for your request
         $request_title = "Shipping Estimate";
         //The zip that you are shipping from
         // Add ability to override vendor zip code as source ship from...
         if (Override_Source_Zip != "" or Override_Source_Zip != NULL) {
             $source_zip = Override_Source_Zip;
         } else {
             $source_zip = $dbv->f("vendor_zip");
         }
         //The zip that you are shipping to
         $dest_country = $db->f("country_2_code");
         $dest_zip = substr($db->f("zip"), 0, 5);
         // Make sure the ZIP is 5 chars long
         //LBS  = Pounds
         //KGS  = Kilograms
         $weight_measure = WEIGHT_UOM == 'KG' ? "KGS" : "LBS";
         // The XML that will be posted to UPS
         $xmlPost = "<?xml version=\"1.0\"?>";
         $xmlPost .= "<AccessRequest xml:lang=\"en-US\">";
         $xmlPost .= " <AccessLicenseNumber>" . $ups_access_code . "</AccessLicenseNumber>";
         $xmlPost .= " <UserId>" . $ups_user_id . "</UserId>";
         $xmlPost .= " <Password>" . $ups_user_password . "</Password>";
         $xmlPost .= "</AccessRequest>";
         $xmlPost .= "<?xml version=\"1.0\"?>";
         $xmlPost .= "<RatingServiceSelectionRequest xml:lang=\"en-US\">";
         $xmlPost .= " <Request>";
         $xmlPost .= "  <TransactionReference>";
         $xmlPost .= "  <CustomerContext>" . $request_title . "</CustomerContext>";
         $xmlPost .= "  <XpciVersion>1.0001</XpciVersion>";
         $xmlPost .= "  </TransactionReference>";
         $xmlPost .= "  <RequestAction>rate</RequestAction>";
         $xmlPost .= "  <RequestOption>shop</RequestOption>";
         $xmlPost .= " </Request>";
         $xmlPost .= " <PickupType>";
         $xmlPost .= "  <Code>" . UPS_PICKUP_TYPE . "</Code>";
         $xmlPost .= " </PickupType>";
         $xmlPost .= " <Shipment>";
         $xmlPost .= "  <Shipper>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $source_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$vendor_country_2_code}</CountryCode>";
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </Shipper>";
         $xmlPost .= "  <ShipTo>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $dest_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$dest_country}</CountryCode>";
         if (UPS_RESIDENTIAL == "yes") {
             $xmlPost .= "    <ResidentialAddressIndicator/>";
         }
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </ShipTo>";
         $xmlPost .= "  <ShipFrom>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $source_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$vendor_country_2_code}</CountryCode>";
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </ShipFrom>";
         // Service is only required, if the Tag "RequestOption" contains the value "rate"
         // We don't want a specific servive, but ALL Rates
         //$xmlPost .= "  <Service>";
         //$xmlPost .= "   <Code>".$shipping_type."</Code>";
         //$xmlPost .= "  </Service>";
         $xmlPost .= "  <Package>";
         $xmlPost .= "   <PackagingType>";
         $xmlPost .= "    <Code>" . UPS_PACKAGE_TYPE . "</Code>";
         $xmlPost .= "   </PackagingType>";
         $xmlPost .= "   <PackageWeight>";
         $xmlPost .= "    <UnitOfMeasurement>";
         $xmlPost .= "     <Code>" . $weight_measure . "</Code>";
         $xmlPost .= "    </UnitOfMeasurement>";
         $xmlPost .= "    <Weight>" . $order_weight . "</Weight>";
         $xmlPost .= "   </PackageWeight>";
         $xmlPost .= "  </Package>";
         $xmlPost .= " </Shipment>";
         $xmlPost .= "</RatingServiceSelectionRequest>";
         // echo htmlentities( $xmlPost );
         $upsURL = "https://www.ups.com:443/ups.app/xml/Rate";
         require_once CLASSPATH . 'connectionTools.class.php';
         $error = false;
         $xmlResult = vmConnector::handleCommunication($upsURL, $xmlPost);
         if (!$xmlResult) {
             $vmLogger->err($VM_LANG->_('PHPSHOP_INTERNAL_ERROR', false) . " UPS.com");
             $error = true;
         } else {
             /* XML Parsing */
             require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
             $xmlDoc = new DOMIT_Lite_Document();
             $xmlDoc->parseXML($xmlResult, false, true);
             /* Let's check wether the response from UPS is Success or Failure ! */
             if (strstr($xmlResult, "Failure")) {
                 $error = true;
                 $error_code = $xmlDoc->getElementsByTagName("ErrorCode");
                 $error_code = $error_code->item(0);
                 $error_code = $error_code->getText();
                 $error_desc = $xmlDoc->getElementsByTagName("ErrorDescription");
                 $error_desc = $error_desc->item(0);
                 $error_desc = $error_desc->getText();
                 $vmLogger->err($VM_LANG->_('PHPSHOP_UPS_RESPONSE_ERROR', false) . '. ' . $VM_LANG->_('PHPSHOP_ERROR_CODE') . ": " . $error_code . ', ' . $VM_LANG->_('PHPSHOP_ERROR_DESC') . ": " . $error_desc);
             }
         }
         if ($error) {
             // Switch to StandardShipping on Error !!!
             require_once CLASSPATH . 'shipping/standard_shipping.php';
             $shipping = new standard_shipping();
             $shipping->list_rates($d);
             return;
         }
         // retrieve the list of all "RatedShipment" Elements
         $rate_list =& $xmlDoc->getElementsByTagName("RatedShipment");
         $allservicecodes = array("UPS_Next_Day_Air", "UPS_2nd_Day_Air", "UPS_Ground", "UPS_Worldwide_Express_SM", "UPS_Worldwide_Expedited_SM", "UPS_Standard", "UPS_3_Day_Select", "UPS_Next_Day_Air_Saver", "UPS_Next_Day_Air_Early_AM", "UPS_Worldwide_Express_Plus_SM", "UPS_2nd_Day_Air_AM", "UPS_Saver", "na");
         $myservicecodes = array();
         foreach ($allservicecodes as $servicecode) {
             if (constant($servicecode) != '' || constant($servicecode) != 0) {
                 $myservicecodes[] = constant($servicecode);
             }
         }
         if (DEBUG) {
             echo "Cart Contents: " . $order_weight . " " . $weight_measure . "<br><br>\n";
             echo "XML Post: <br>";
             echo "<textarea cols='80'>" . $xmlPost . "</textarea>";
             echo "<br>";
             echo "XML Result: <br>";
             echo "<textarea cols='80' rows='10'>" . $xmlResult . "</textarea>";
             echo "<br>";
         }
         // Loop through the rate List
         for ($i = 0; $i < $rate_list->getLength(); $i++) {
             $currNode =& $rate_list->item($i);
             if (in_array($currNode->childNodes[0]->getText(), $myservicecodes)) {
                 $e = 0;
                 // First Element: Service Code
                 $shipment[$i]["ServiceCode"] = $currNode->childNodes[$e++]->getText();
                 // Second Element: BillingWeight
                 if ($currNode->childNodes[$e]->nodeName == 'RatedShipmentWarning') {
                     $e++;
                 }
                 $shipment[$i]["BillingWeight"] = $currNode->childNodes[$e++];
                 // Third Element: TransportationCharges
                 $shipment[$i]["TransportationCharges"] = $currNode->childNodes[$e++];
                 $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->getElementsByTagName("MonetaryValue");
                 $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->item(0);
                 if (is_object($shipment[$i]["TransportationCharges"])) {
                     $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->getText();
                 }
                 // Fourth Element: ServiceOptionsCharges
                 $shipment[$i]["ServiceOptionsCharges"] = $currNode->childNodes[$e++];
                 // Fifth Element: TotalCharges
                 $shipment[$i]["TotalCharges"] = $currNode->childNodes[$e++];
                 // Sixth Element: GuarenteedDaysToDelivery
                 $shipment[$i]["GuaranteedDaysToDelivery"] = $currNode->childNodes[$e++]->getText();
                 // Seventh Element: ScheduledDeliveryTime
                 $shipment[$i]["ScheduledDeliveryTime"] = $currNode->childNodes[$e++]->getText();
                 // Eighth Element: RatedPackage
                 $shipment[$i]["RatedPackage"] = $currNode->childNodes[$e++];
                 // map ServiceCode to ServiceName
                 switch ($shipment[$i]["ServiceCode"]) {
                     case "01":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air";
                         break;
                     case "02":
                         $shipment[$i]["ServiceName"] = "UPS 2nd Day Air";
                         break;
                     case "03":
                         $shipment[$i]["ServiceName"] = "UPS Ground";
                         break;
                     case "07":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Express SM";
                         break;
                     case "08":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Expedited SM";
                         break;
                     case "11":
                         $shipment[$i]["ServiceName"] = "UPS Standard";
                         break;
                     case "12":
                         $shipment[$i]["ServiceName"] = "UPS 3 Day Select";
                         break;
                     case "13":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air Saver";
                         break;
                     case "14":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air Early A.M.";
                         break;
                     case "54":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Express Plus SM";
                         break;
                     case "59":
                         $shipment[$i]["ServiceName"] = "UPS 2nd Day Air A.M.";
                         break;
                     case "64":
                         $shipment[$i]["ServiceName"] = "n/a";
                         break;
                     case "65":
                         $shipment[$i]["ServiceName"] = "UPS Saver";
                         break;
                 }
                 unset($currNode);
             }
         }
         if (!$shipment) {
             //$vmLogger->err( "Error processing the Request to UPS.com" );
             /*$vmLogger->err( "We could not find a UPS shipping rate.
             		Please make sure you have entered a valid shipping address.
             		Or choose a rate below." );
             		// Switch to StandardShipping on Error !!!
             		require_once( CLASSPATH . 'shipping/standard_shipping.php' );
             		$shipping = new standard_shipping();
             		$shipping->list_rates( $d );*/
             return;
         }
         // UPS returns Charges in USD ONLY.
         // So we have to convert from USD to Vendor Currency if necessary
         if ($_SESSION['vendor_currency'] != "USD") {
             $convert = true;
         } else {
             $convert = false;
         }
         if ($_SESSION['auth']['show_price_including_tax'] != 1) {
             $taxrate = 1;
         } else {
             $taxrate = $this->get_tax_rate() + 1;
         }
         foreach ($shipment as $key => $value) {
             //Get the Fuel SurCharge rate, defined in config.
             $fsc = $value['ServiceName'] . "_FSC";
             $fsc = str_replace(" ", "_", str_replace(".", "", str_replace("/", "", $fsc)));
             $fsc = constant($fsc);
             if ($fsc == 0) {
                 $fsc_rate = 1;
             } else {
                 $fsc_rate = $fsc / 100;
                 $fsc_rate = $fsc_rate + 1;
             }
             if ($convert) {
                 $tmp = $GLOBALS['CURRENCY']->convert($value['TransportationCharges'], "USD", $vendor_currency);
                 // tmp is empty when the Vendor Currency could not be converted!!!!
                 if (!empty($tmp)) {
                     $charge = $tmp;
                     // add Fuel SurCharge
                     $charge *= $fsc_rate;
                     // add Handling Fee
                     $charge += UPS_HANDLING_FEE;
                     $charge *= $taxrate;
                     $value['TransportationCharges'] = $CURRENCY_DISPLAY->getFullValue($tmp);
                 } else {
                     $charge = $value['TransportationCharges'] + intval(UPS_HANDLING_FEE);
                     // add Fuel SurCharge
                     $charge *= $fsc_rate;
                     // add Handling Fee
                     $charge += UPS_HANDLING_FEE;
                     $charge *= $taxrate;
                     $value['TransportationCharges'] = $value['TransportationCharges'] . " USD";
                 }
             } else {
                 $charge = $charge_unrated = $value['TransportationCharges'];
                 // add Fuel SurCharge
                 $charge *= $fsc_rate;
                 // add Handling Fee
                 $charge += UPS_HANDLING_FEE;
                 $charge *= $taxrate;
                 $value['TransportationCharges'] = $CURRENCY_DISPLAY->getFullValue($charge);
             }
             $shipping_rate_id = urlencode(__CLASS__ . "|UPS|" . $value['ServiceName'] . "|" . $charge);
             $checked = @$d["shipping_rate_id"] == $value ? "checked=\"checked\"" : "";
             if (count($shipment) == 1) {
                 $checked = "checked=\"checked\"";
             }
             $html .= '<label for="' . $shipping_rate_id . '">' . "\n<input type=\"radio\" name=\"shipping_rate_id\" {$checked} value=\"{$shipping_rate_id}\" id=\"{$shipping_rate_id}\" />\n";
             $_SESSION[$shipping_rate_id] = 1;
             $html .= $value['ServiceName'] . ' ';
             $html .= "<strong>(" . $value['TransportationCharges'] . ")</strong>";
             if (DEBUG) {
                 $html .= " - " . $VM_LANG->_('PHPSHOP_PRODUCT_FORM_WEIGHT') . ": " . $order_weight . " " . $weight_measure . ", " . $VM_LANG->_('PHPSHOP_RATE_FORM_VALUE') . ": [[" . $charge_unrated . "(" . $fsc_rate . ")]+" . UPS_HANDLING_FEE . "](" . $taxrate . ")]";
             }
             // DELIVERY QUOTE
             if (Show_Delivery_Days_Quote == 1) {
                 if (!empty($value['GuaranteedDaysToDelivery'])) {
                     $html .= "&nbsp;&nbsp;-&nbsp;&nbsp;" . $value['GuaranteedDaysToDelivery'] . " " . $VM_LANG->_('PHPSHOP_UPS_SHIPPING_GUARANTEED_DAYS');
                 }
             }
             if (Show_Delivery_ETA_Quote == 1) {
                 if (!empty($value['ScheduledDeliveryTime'])) {
                     $html .= "&nbsp;(ETA:&nbsp;" . $value['ScheduledDeliveryTime'] . ")";
                 }
             }
             if (Show_Delivery_Warning == 1 && !empty($value['RatedShipmentWarning'])) {
                 $html .= "</label><br/>\n&nbsp;&nbsp;&nbsp;*&nbsp;<em>" . $value['RatedShipmentWarning'] . "</em>\n";
             }
             $html .= "<br />\n";
         }
     }
     echo $html;
     //DEBUG
     if (DEBUG) {
         /*
         echo "My Services: <br>";
         print_r($myservicecodes);
         echo "<br>";
         echo "All Services: <br>";
         print_r($allservicecodes);
         echo "<br>";
         echo "XML Result: <br>";
         echo "<textarea cols='80' rows='10'>".$xmlResult."</textarea>";
         echo "<br>";
         */
     }
     return true;
 }
 function _echoUpload()
 {
     $jpconfiguration =& JoomlapackConfiguration::getInstance();
     $db = JoomlapackAbstraction::getDatabase();
     echo JoomlapackCommonHTML::getAdminHeadingHTML(JoomlapackLangManager::_('CPANEL_CONFIGMIGRATE'));
     /*
      * Check for problematic uploads
      */
     if (count($_FILES) == 0) {
         // Handle no uploaded file
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_NOUPLOADED') . '</p>';
         return;
     }
     if (!isset($_FILES['userfile'])) {
         // Handle illegal upload key
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_ILLEGALKEY') . '</p>';
         return;
     }
     $fileDescriptor = $_FILES['userfile'];
     if ($fileDescriptor['size'] < 1) {
         // Handle zero length file
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_ZEROLENGTH') . '</p>';
         return;
     }
     if ($fileDescriptor['error'] != 0) {
         // Handle error in upload
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_UPLOAD') . '</p>';
         return;
     }
     // Get the file data
     $fileData = file_get_contents($fileDescriptor['tmp_name']);
     // Try to get a DOM document instance
     require_once JPATH_SITE . DS . 'includes' . DS . 'domit' . DS . 'xml_domit_lite_include.php';
     $domDoc = new DOMIT_Lite_Document();
     $domDoc->resolveErrors(true);
     if (!$domDoc->parseXML($fileData, false, true)) {
         // Handle wrong file type
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_WRONGFORMAT') . '</p>';
         return;
     }
     // Check we have a correct XML root node
     $root =& $domDoc->documentElement;
     if ($root->nodeName != 'jpexport') {
         // Handle wrong XML format
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_WRONGXML') . '</p>';
         return;
     }
     // Check export version
     $version = $root->attributes['version'];
     if (version_compare(JPEXPORTVERSION, $version) < 0) {
         // Handle future version
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_FUTUREVER') . '</p>';
         return;
     }
     // Check for the existence of the config, incusion and exclusion nodes
     $config =& $root->getElementsByPath('config', 1);
     $inclusion =& $root->getElementsByPath('inclusion', 1);
     $exclusion =& $root->getElementsByPath('inclusion', 1);
     if (is_null($config) || is_null($inclusion) || is_null($exclusion)) {
         echo '<h1>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERROR') . '</h1>';
         echo '<p>' . JoomlapackLangManager::_('CONFIGMIGRATE_ERR_NOREQNODES') . '</p>';
         return;
     }
     // Process configuration
     if ($config->hasChildNodes()) {
         foreach ($config->childNodes as $node) {
             $key = $node->nodeName;
             $value = unserialize($node->getText());
             $jpconfiguration->set($key, $value);
         }
     }
     $jpconfiguration->SaveConfiguration();
     // Process inclusion filters
     if ($inclusion->hasChildNodes()) {
         // Nuke old inclusion filters
         $sql = 'TRUNCATE TABLE #__jp_inclusion';
         $db->setQuery($sql);
         if (!$db->query()) {
             echo $db->ErrorMsg();
             return;
         }
         // Import inclusion filters
         foreach ($inclusion->childNodes as $node) {
             $key = $node->nodeName;
             $data = $node->getText();
             $sql = 'INSERT INTO #__jp_inclusion (' . $db->nameQuote('id') . ',' . $db->nameQuote('class') . ',' . $db->nameQuote('value') . ') ' . 'VALUES (' . $db->Quote($data['id']) . ', ' . $db->Quote($data['class']) . ', ' . $db->Quote($data['value']) . ')';
             $db->setQuery($sql);
             if (!$db->query()) {
                 echo $db->ErrorMsg();
                 return;
             }
             //echo $key . ' => '; var_dump($data); echo "<br/>";
         }
     }
     // Process exclusion filters
     if ($exclusion->hasChildNodes()) {
         // Nuke old inclusion filters
         $sql = 'TRUNCATE TABLE #__jp_exclusion';
         $db->setQuery($sql);
         if (!$db->query()) {
             echo $db->ErrorMsg();
             return;
         }
         // Import inclusion filters
         foreach ($exclusion->childNodes as $node) {
             $key = $node->nodeName;
             $data = $node->getText();
             $sql = 'INSERT INTO #__jp_exclusion (' . $db->nameQuote('id') . ',' . $db->nameQuote('class') . ',' . $db->nameQuote('value') . ') ' . 'VALUES (' . $db->Quote($data['id']) . ', ' . $db->Quote($data['class']) . ', ' . $db->Quote($data['value']) . ')';
             $db->setQuery($sql);
             if (!$db->query()) {
                 echo $db->ErrorMsg();
                 return;
             }
             //echo $key . ' => '; var_dump($data); echo "<br/>";
         }
     }
     echo JoomlapackLangManager::_('CONFIGMIGRATE_IMPORT_OK');
 }