PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/application/views/pages/admin/uspsshipping.php

https://bitbucket.org/chadsaun/ifrogz-panel
PHP | 507 lines | 490 code | 5 blank | 12 comment | 126 complexity | 7e4c69cbc6545e49970fc7897abe1044 MD5 | raw file
  1. <?php
  2. //This code is copyright (c) Internet Business Solutions SL, all rights reserved.
  3. //The contents of this file are protect under law as the intellectual property of Internet
  4. //Business Solutions SL. Any use, reproduction, disclosure or copying of any kind
  5. //without the express and written permission of Internet Business Solutions SL is forbidden.
  6. //Author: Vince Reid, vince@virtualred.net
  7. $numfirstclass=0;
  8. $firstclasscost=0;
  9. function sortshippingarray(){
  10. global $intShipping,$maxshipoptions;
  11. for($ssaindex2=0; $ssaindex2 < $maxshipoptions; $ssaindex2++){
  12. $intShipping[$ssaindex2][2] = (double)$intShipping[$ssaindex2][2];
  13. for($ssaindex=1; $ssaindex < 20; $ssaindex++){
  14. if($intShipping[$ssaindex][3] && (double)$intShipping[$ssaindex][2] < (double)$intShipping[$ssaindex-1][2]){
  15. $tt = $intShipping[$ssaindex];
  16. $intShipping[$ssaindex] = $intShipping[$ssaindex-1];
  17. $intShipping[$ssaindex-1] = $tt;
  18. }
  19. }
  20. }
  21. // for($ssaindex=0; $ssaindex < $maxshipoptions; $ssaindex++)
  22. // print $intShipping[$ssaindex][0] . ":" . $intShipping[$ssaindex][1] . ":" . $intShipping[$ssaindex][2] . ":" . $intShipping[$ssaindex][3] . "<br>";
  23. }
  24. function ParseXMLOutput($sXML, $international, &$totalCost, &$errormsg, &$intShipping){
  25. global $iTotItems, $numfirstclass, $firstclasscost, $xxDay,$xxDays;
  26. $noError = TRUE;
  27. $totalCost = 0;
  28. $packCost = 0;
  29. $errormsg = "";
  30. $xmlDoc = new vrXMLDoc($sXML);
  31. if($xmlDoc->nodeList->nodeName[0] == "Error"){ // Top-level Error
  32. $noError = FALSE;
  33. $nodeList = $xmlDoc->nodeList->childNodes[0];
  34. for($i = 0; $i < $nodeList->length; $i++){
  35. if($nodeList->nodeName[$i]=="Description"){
  36. $errormsg = $nodeList->nodeValue[$i];
  37. }
  38. }
  39. }else{ // no Top-level Error
  40. $nodeList = $xmlDoc->nodeList->childNodes[0];
  41. for($i = 0; $i < $nodeList->length; $i++){
  42. if($nodeList->nodeName[$i]=="Package"){
  43. $tmpArr = split('x', getattributes($nodeList->attributes[$i], 'ID'));
  44. $quantity = (int)$tmpArr[1];
  45. $e = $nodeList->childNodes[$i];
  46. for($j = 0; $j < $nodeList->childNodes[$i]->length; $j++){
  47. if($e->nodeName[$j] == "Error"){ // Lower-level error
  48. $noError = FALSE;
  49. $t = $e->childNodes[$j];
  50. for($k = 0; $k < $t->length; $k++){
  51. if($t->nodeName[$k] == "Description")
  52. $errormsg = $t->nodeValue[$k];
  53. }
  54. }else{
  55. if($e->nodeName[$j] == "Postage"){
  56. //$packCost += $e->nodeValue[$j];
  57. if($international == ""){
  58. $l = 0;
  59. while($intShipping[$l][0] != $thisService && $intShipping[$l][0] != "")
  60. $l++;
  61. $intShipping[$l][0] = $thisService;
  62. if($thisService=="PARCEL")
  63. $intShipping[$l][1] = "2-7 " . $xxDays;
  64. elseif($thisService=="EXPRESS")
  65. $intShipping[$l][1] = "Overnight to most areas";
  66. elseif($thisService=="PRIORITY")
  67. $intShipping[$l][1] = "1-2 " . $xxDays;
  68. elseif($thisService=="BPM")
  69. $intShipping[$l][1] = "2-7 " . $xxDays;
  70. elseif($thisService=="Media")
  71. $intShipping[$l][1] = "2-7 " . $xxDays;
  72. $intShipping[$l][2] = $intShipping[$l][2] + ($e->nodeValue[$j] * $quantity);
  73. $intShipping[$l][3] = $intShipping[$l][3] + 1;
  74. }
  75. }elseif($e->nodeName[$j] == "Service"){
  76. if($international != ""){
  77. $t = $e->childNodes[$j];
  78. for($k = 0; $k < $t->length; $k++){
  79. if($t->nodeName[$k] == "SvcDescription")
  80. $SvcDescription = $t->nodeValue[$k];
  81. elseif($t->nodeName[$k] == "SvcCommitments")
  82. $SvcCommitments = $t->nodeValue[$k];
  83. elseif($t->nodeName[$k] == "Postage")
  84. $Postage = $t->nodeValue[$k];
  85. }
  86. $l = 0;
  87. while($intShipping[$l][0] != "" && $intShipping[$l][0] != $SvcDescription)
  88. $l++;
  89. $intShipping[$l][0] = $SvcDescription;
  90. $intShipping[$l][1] = $SvcCommitments;
  91. $intShipping[$l][2] += ($Postage * $quantity);
  92. $intShipping[$l][3]++;
  93. }
  94. else
  95. $thisService = $e->nodeValue[$j];
  96. }
  97. }
  98. }
  99. $totalCost += $packCost;
  100. $packCost = 0;
  101. }
  102. }
  103. if($iTotItems==$numfirstclass){
  104. $l = 0;
  105. while($intShipping[$l][0] != "")
  106. $l++;
  107. $intShipping[$l][0] = "FIRSTCLASS";
  108. $intShipping[$l][1] = "1-3 " . $xxDays;
  109. $intShipping[$l][2] = $firstclasscost;
  110. $intShipping[$l][3] = $numfirstclass;
  111. }
  112. }
  113. return $noError;
  114. }
  115. function checkUPSShippingMeth($method, &$discountsApply){
  116. global $numuspsmeths, $uspsmethods;
  117. for($index=0; $index < $numuspsmeths; $index++){
  118. if($method==$uspsmethods[$index][0]){
  119. $discountsApply = $uspsmethods[$index][1];
  120. return(TRUE);
  121. }
  122. }
  123. return(FALSE);
  124. }
  125. function ParseUPSXMLOutput($sXML, $international, &$totalCost, &$errormsg, &$errorcode, &$intShipping){
  126. global $xxDay,$xxDays;
  127. $noError = TRUE;
  128. $totalCost = 0;
  129. $packCost = 0;
  130. $errormsg = "";
  131. $l = 0;
  132. $discntsApp = "";
  133. $xmlDoc = new vrXMLDoc($sXML);
  134. $nodeList = $xmlDoc->nodeList->childNodes[0];
  135. for($i = 0; $i < $nodeList->length; $i++){
  136. if($nodeList->nodeName[$i]=="Response"){
  137. $e = $nodeList->childNodes[$i];
  138. for($j = 0; $j < $e->length; $j++){
  139. if($e->nodeName[$j]=="ResponseStatusCode"){
  140. $noError = ((int)$e->nodeValue[$j])==1;
  141. }
  142. if($e->nodeName[$j]=="Error"){
  143. $errormsg = "";
  144. $t = $e->childNodes[$j];
  145. for($k = 0; $k < $t->length; $k++){
  146. if($t->nodeName[$k]=="ErrorCode"){
  147. $errorcode = $t->nodeValue[$k];
  148. }elseif($t->nodeName[$k]=="ErrorSeverity"){
  149. if($t->nodeValue[$k]=="Transient")
  150. $errormsg = "This is a temporary error. Please wait a few moments then refresh this page.<br />" . $errormsg;
  151. }elseif($t->nodeName[$k]=="ErrorDescription"){
  152. $errormsg .= $t->nodeValue[$k];
  153. }
  154. }
  155. }
  156. // print "The Nodename is : " . e.nodeName . ":" . e.firstChild.nodeValue . "<br />";
  157. }
  158. }elseif($nodeList->nodeName[$i]=="RatedShipment"){ // no Top-level Error
  159. $wantthismethod=TRUE;
  160. $nodeList = $xmlDoc->nodeList->childNodes[0];
  161. $e = $nodeList->childNodes[$i];
  162. for($j = 0; $j < $e->length; $j++){
  163. if($e->nodeName[$j] == "Service"){ // Lower-level error
  164. $t = $e->childNodes[$j];
  165. for($k = 0; $k < $t->length; $k++){
  166. if($t->nodeName[$k]=="Code"){
  167. if($t->nodeValue[$k]=="01")
  168. $intShipping[$l][0] = "UPS Next Day Air&reg;";
  169. elseif($t->nodeValue[$k]=="02")
  170. $intShipping[$l][0] = "UPS 2nd Day Air&reg;";
  171. elseif($t->nodeValue[$k]=="03")
  172. $intShipping[$l][0] = "UPS Ground";
  173. elseif($t->nodeValue[$k]=="07")
  174. $intShipping[$l][0] = "UPS Worldwide Express";
  175. elseif($t->nodeValue[$k]=="08")
  176. $intShipping[$l][0] = "UPS Worldwide Expedited";
  177. elseif($t->nodeValue[$k]=="11")
  178. $intShipping[$l][0] = "UPS Standard";
  179. elseif($t->nodeValue[$k]=="12")
  180. $intShipping[$l][0] = "UPS 3 Day Select&reg;";
  181. elseif($t->nodeValue[$k]=="13")
  182. $intShipping[$l][0] = "UPS Next Day Air Saver&reg;";
  183. elseif($t->nodeValue[$k]=="14")
  184. $intShipping[$l][0] = "UPS Next Day Air&reg; Early A.M.&reg;";
  185. elseif($t->nodeValue[$k]=="54")
  186. $intShipping[$l][0] = "UPS Worldwide Express Plus";
  187. elseif($t->nodeValue[$k]=="59")
  188. $intShipping[$l][0] = "UPS 2nd Day Air A.M.&reg;";
  189. elseif($t->nodeValue[$k]=="65")
  190. $intShipping[$l][0] = "UPS Express Saver";
  191. $wantthismethod = checkUPSShippingMeth($t->nodeValue[$k], $discntsApp);
  192. $intShipping[$l][4] = $discntsApp;
  193. }
  194. }
  195. }elseif($e->nodeName[$j] == "TotalCharges"){
  196. $t = $e->childNodes[$j];
  197. for($k = 0; $k < $t->length; $k++){
  198. if($t->nodeName[$k]=="MonetaryValue"){
  199. $intShipping[$l][2] = (double)$t->nodeValue[$k];
  200. }
  201. }
  202. }elseif($e->nodeName[$j] == "GuaranteedDaysToDelivery"){
  203. if(strlen($e->nodeValue[$j]) > 0){
  204. if($e->nodeValue[$j]=="1")
  205. $intShipping[$l][1] = "1 " . $xxDay . $intShipping[$l][1];
  206. else
  207. $intShipping[$l][1] = $e->nodeValue[$j] . " " . $xxDays . $intShipping[$l][1];
  208. }
  209. }elseif($e->nodeName[$j] == "ScheduledDeliveryTime"){
  210. if(strlen($e->nodeValue[$j]) > 0){
  211. $intShipping[$l][1] .= " by " . $e->nodeValue[$j];
  212. }
  213. }
  214. }
  215. if($wantthismethod){
  216. $intShipping[$l][3] = TRUE;
  217. $l++;
  218. }else
  219. $intShipping[$l][1] = "";
  220. $wantthismethod=TRUE;
  221. }
  222. }
  223. return $noError;
  224. }
  225. function ParseCanadaPostXMLOutput($sXML, $international, &$totalCost, &$errormsg, &$errorcode, &$intShipping){
  226. global $xxDay,$xxDays;
  227. $noError = TRUE;
  228. $totalCost = 0;
  229. $packCost = 0;
  230. $errormsg = "";
  231. $discntsApp = "";
  232. $l = strpos($sXML, ']>');
  233. if($l > 0) $sXML = substr($sXML, $l+2);
  234. $l = 0;
  235. $xmlDoc = new vrXMLDoc($sXML);
  236. $nodeList = $xmlDoc->nodeList->childNodes[0];
  237. for($i = 0; $i < $nodeList->length; $i++){
  238. if($nodeList->nodeName[$i]=="error"){
  239. $noError = FALSE;
  240. $e = $nodeList->childNodes[$i];
  241. for($j = 0; $j < $e->length; $j++){
  242. if($e->nodeName[$j]=="statusCode"){
  243. $errorcode = $e->nodeValue[$j];
  244. }elseif($e->nodeName[$j]=="statusMessage"){
  245. $errormsg = $e->nodeValue[$j];
  246. }
  247. }
  248. }elseif($nodeList->nodeName[$i]=="ratesAndServicesResponse"){ // no Top-level Error
  249. $wantthismethod=TRUE;
  250. $nodeList = $xmlDoc->nodeList->childNodes[0];
  251. $e = $nodeList->childNodes[$i];
  252. for($j = 0; $j < $e->length; $j++){
  253. if($e->nodeName[$j] == "product"){
  254. $wantthismethod = checkUPSShippingMeth(getattributes($e->attributes[$j], 'id'), $discntsApp);
  255. $intShipping[$l][4] = $discntsApp;
  256. $wantthismethod=TRUE;
  257. $t = $e->childNodes[$j];
  258. for($k = 0; $k < $t->length; $k++){
  259. if($t->nodeName[$k]=="name"){
  260. $intShipping[$l][0] = $t->nodeValue[$k];
  261. }elseif($t->nodeName[$k]=="rate"){
  262. $intShipping[$l][2] = (double)$t->nodeValue[$k];
  263. }elseif($t->nodeName[$k]=="deliveryDate"){
  264. $today = getdate();
  265. $daytoday = $today["yday"];
  266. if(($ttimeval = strtotime($t->nodeValue[$k])) < 0){
  267. $intShipping[$l][1] = $t->nodeValue[$k] . $intShipping[$l][1];
  268. }else{
  269. $deldate = getdate($ttimeval);
  270. $daydeliv = $deldate["yday"];
  271. if($daydeliv < $daytoday) $daydeliv+=365;
  272. $intShipping[$l][1] = ($daydeliv - $daytoday) . " " . ($daydeliv - $daytoday < 2?$xxDay:$xxDays) . $intShipping[$l][1];
  273. }
  274. }elseif($t->nodeName[$k]=="nextDayAM"){
  275. if($t->nodeValue[$k]=="true")
  276. $intShipping[$l][1] = $intShipping[$l][1] . " AM";
  277. }
  278. }
  279. if($wantthismethod){
  280. $intShipping[$l][3] = TRUE;
  281. $l++;
  282. }else
  283. $intShipping[$l][1] = "";
  284. $wantthismethod=TRUE;
  285. }
  286. }
  287. }
  288. }
  289. return $noError;
  290. }
  291. function addDomestic($id,$service,$orig,$dest,$iWeight,$quantity,$container,$size,$machinable){
  292. global $numuspsmeths,$uspsmethods,$numfirstclass,$firstclasscost;
  293. $sXML="";
  294. $pounds = (int)$iWeight;
  295. $ounces = round(($iWeight-$pounds)*16.0);
  296. if($pounds==0 && $ounces==0) $ounces=1;
  297. for($index=0;$index<$numuspsmeths;$index++){
  298. if($uspsmethods[$index][0]=="FIRSTCLASS"){
  299. if($pounds==0 && $ounces<=13){
  300. $numfirstclass++;
  301. $firstclasscost += (((double)$ounces*0.23)+0.14);
  302. }
  303. }else{
  304. $sXML .= '<Package ID="' . $uspsmethods[$index][0] . $id . 'x' . $quantity . '">';
  305. $sXML .= "<Service>" . $uspsmethods[$index][0] . "</Service>";
  306. $sXML .= "<ZipOrigination>" . $orig . "</ZipOrigination>";
  307. $sXML .= "<ZipDestination>" . substr($dest, 0, 5) . "</ZipDestination>";
  308. $sXML .= "<Pounds>" . $pounds . "</Pounds>";
  309. $sXML .= "<Ounces>" . $ounces . "</Ounces>";
  310. $sXML .= "<Container>" . $container . "</Container>";
  311. $sXML .= "<Size>" . $size . "</Size>";
  312. $sXML .= "<Machinable>" . $machinable . "</Machinable>";
  313. $sXML .= "</Package>";
  314. }
  315. }
  316. return $sXML;
  317. }
  318. function addInternational($id,$iWeight,$quantity,$mailtype,$country){
  319. $pounds = (int)$iWeight;
  320. $ounces = round(($iWeight-$pounds)*16.0);
  321. if($pounds==0 && $ounces==0) $ounces=1;
  322. $sXML = "<Package ID=\"" . $id . 'x' . $quantity . "\">";
  323. $sXML .= "<Pounds>" . $pounds . "</Pounds>";
  324. $sXML .= "<Ounces>" . $ounces . "</Ounces>";
  325. $sXML .= "<MailType>" . $mailtype . "</MailType>";
  326. $sXML .= "<Country>" . $country . "</Country>";
  327. return $sXML . "</Package>";
  328. }
  329. function addUPSInternational($iWeight,$adminUnits,$packTypeCode,$country,$packcost){
  330. global $addshippinginsurance, $countryCurrency;
  331. if($iWeight<0.1) $iWeight=0.1;
  332. $sXML = "<Package><PackagingType><Code>" . $packTypeCode . "</Code><Description>Package</Description></PackagingType>";
  333. $sXML .= "<Description>Rate Shopping</Description><PackageWeight><UnitOfMeasurement><Code>" . $adminUnits . "</Code></UnitOfMeasurement><Weight>" . $iWeight . "</Weight></PackageWeight>";
  334. if(abs(@$addshippinginsurance)==1 || (abs(@$addshippinginsurance)==2 && trim(@$_POST["wantinsurance"])=="Y")){
  335. if($packcost > 50000) $packcost=50000;
  336. $sXML .= "<PackageServiceOptions><InsuredValue><CurrencyCode>" . $countryCurrency . "</CurrencyCode><MonetaryValue>" . number_format($packcost,2,'.','') . "</MonetaryValue></InsuredValue></PackageServiceOptions>";
  337. }
  338. return $sXML . "</Package>";
  339. }
  340. function addCanadaPostPackage($iWeight,$adminUnits,$packTypeCode,$country,$packcost,$dimens){
  341. global $addshippinginsurance, $countryCurrency, $packtogether, $productdimensions;
  342. if($iWeight<0.1) $iWeight=0.1;
  343. if($packtogether) $thesize = 1; else $thesize = 19;
  344. if(@$productdimensions==TRUE){
  345. $proddims = split("x", $dimens);
  346. if(@$proddims[0] != '') $thelength = $proddims[0]; else $thelength = $thesize;
  347. if(@$proddims[1] != '') $thewidth = $proddims[1]; else $thewidth = $thesize;
  348. if(@$proddims[2] != '') $theheight = $proddims[2]; else $theheight = $thesize;
  349. }else{
  350. $thelength = $thesize;
  351. $thewidth = $thesize;
  352. $theheight = $thesize;
  353. }
  354. $sXML = "<item><quantity> 1 </quantity><weight> " . $iWeight . " </weight><length> ".$thelength." </length><width> ".$thewidth." </width><height> ".$theheight." </height><description> Goods for shipping rates selection </description></item>";
  355. return $sXML;
  356. }
  357. function USPSCalculate($sXML,$international,&$totalCost,&$errormsg,&$intShipping){
  358. global $usecurlforfsock,$pathtocurl,$curlproxy;
  359. $success = TRUE;
  360. $sXML = "API=" . $international . "Rate&XML=" . $sXML;
  361. if(@$usecurlforfsock){
  362. if(@$pathtocurl != ""){
  363. exec($pathtocurl . ' --data-binary \'' . str_replace("'","\'",$sXML) . '\' http://production.shippingapis.com/ShippingAPI.dll', $res, $retvar);
  364. $res = implode("\n",$res);
  365. }else{
  366. if (!$ch = curl_init()) {
  367. $errormsg = "cURL package not installed in PHP";
  368. return FALSE;
  369. }else{
  370. curl_setopt($ch, CURLOPT_URL,'http://production.shippingapis.com/ShippingAPI.dll');
  371. curl_setopt($ch, CURLOPT_POST, 1);
  372. curl_setopt($ch, CURLOPT_HEADER, 0);
  373. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  374. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  375. curl_setopt($ch, CURLOPT_POSTFIELDS, $sXML);
  376. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  377. if(@$curlproxy!=''){
  378. curl_setopt($ch, CURLOPT_PROXY, $curlproxy);
  379. }
  380. $res = curl_exec($ch);
  381. if(curl_error($ch) != "") print "Error with cURL installation: " . curl_error($ch) . "<br />";
  382. curl_close($ch);
  383. }
  384. }
  385. }else{
  386. $header = "POST /ShippingAPI.dll HTTP/1.0\r\n";
  387. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  388. $header .= 'Content-Length: ' . strlen($sXML) . "\r\n\r\n";
  389. $fp = fsockopen ('production.shippingapis.com', 80, $errno, $errstr, 30);
  390. if (!$fp){
  391. echo "$errstr ($errno)"; // HTTP error handling
  392. return FALSE;
  393. }else{
  394. $res = "";
  395. fputs ($fp, $header . $sXML);
  396. while (!feof($fp)) {
  397. $res .= fgets ($fp, 1024);
  398. }
  399. fclose ($fp);
  400. }
  401. }
  402. if($success){
  403. // print str_replace("<","<br />&lt;",$res) . "<br />\n";
  404. $success = ParseXMLOutput($res, $international, $totalCost, $errormsg, $intShipping);
  405. sortshippingarray();
  406. }
  407. return $success;
  408. }
  409. function UPSCalculate($sXML,$international,&$totalCost, &$errormsg, &$intShipping){
  410. global $pathtocurl,$curlproxy;
  411. $success = true;
  412. if(@$pathtocurl != ""){
  413. exec($pathtocurl . ' --data-binary \'' . str_replace("'","\'",$sXML) . '\' https://www.ups.com/ups.app/xml/Rate', $res, $retvar);
  414. $res = implode("\n",$res);
  415. }else{
  416. if (!$ch = curl_init()) {
  417. $success = false;
  418. $errormsg = "cURL package not installed in PHP";
  419. }else{
  420. curl_setopt($ch, CURLOPT_URL,'https://www.ups.com/ups.app/xml/Rate');
  421. curl_setopt($ch, CURLOPT_POST, 1);
  422. curl_setopt($ch, CURLOPT_HEADER, 0);
  423. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  424. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  425. curl_setopt($ch, CURLOPT_POSTFIELDS, $sXML);
  426. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  427. if(@$curlproxy!=''){
  428. curl_setopt($ch, CURLOPT_PROXY, $curlproxy);
  429. }
  430. $res = curl_exec($ch);
  431. if(curl_error($ch) != ""){
  432. $vsRESPMSG= "Error with cURL installation: " . curl_error($ch) . "<br />";
  433. flush();
  434. }
  435. curl_close($ch);
  436. }
  437. }
  438. if($success){
  439. // print str_replace("<","<br />&lt;",$res) . "<br />\n";
  440. $success = ParseUPSXMLOutput($res, $international, $totalCost, $errormsg, $errorcode, $intShipping);
  441. sortshippingarray();
  442. if($errorcode == 111210) $errormsg = "The destination zip / postal code is invalid.";
  443. }
  444. return $success;
  445. }
  446. function CanadaPostCalculate($sXML,$international,&$totalCost, &$errormsg, &$intShipping){
  447. global $pathtocurl,$canadaposttest,$usecurlforfsock,$curlproxy;
  448. $success = true;
  449. // print str_replace("<","<br />&lt;",$sXML) . "<HR>\n";
  450. if(@$canadaposttest==TRUE)
  451. $ipaddr = '206.191.4.228';
  452. else
  453. $ipaddr = '216.191.36.73';
  454. if(@$usecurlforfsock){
  455. if(@$pathtocurl != ""){
  456. exec($pathtocurl . ' --data-binary \'' . str_replace("'","\'",$sXML) . '\' ' . $ipaddr . ":30000", $res, $retvar);
  457. $res = implode("\n",$res);
  458. }else{
  459. if (!$ch = curl_init()) {
  460. $success = false;
  461. $errormsg = "cURL package not installed in PHP";
  462. }else{
  463. curl_setopt($ch, CURLOPT_URL, $ipaddr . ":30000");
  464. curl_setopt($ch, CURLOPT_POST, 1);
  465. curl_setopt($ch, CURLOPT_HEADER, 0);
  466. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  467. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  468. curl_setopt($ch, CURLOPT_POSTFIELDS, $sXML);
  469. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  470. if(@$curlproxy!=''){
  471. curl_setopt($ch, CURLOPT_PROXY, $curlproxy);
  472. }
  473. $res = curl_exec($ch);
  474. if(curl_error($ch) != "") print "Error with cURL installation: " . curl_error($ch) . "<br />";
  475. curl_close($ch);
  476. }
  477. }
  478. }else{
  479. $header = "POST / HTTP/1.0\r\n";
  480. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  481. $header .= 'Content-Length: ' . strlen($sXML) . "\r\n\r\n";
  482. $fp = fsockopen ($ipaddr, 30000, $errno, $errstr, 30);
  483. if (!$fp){
  484. echo "$errstr ($errno)"; // HTTP error handling
  485. return FALSE;
  486. }else{
  487. $res = "";
  488. fputs ($fp, $header . $sXML);
  489. while (!feof($fp)) {
  490. $res .= fgets ($fp, 1024);
  491. }
  492. fclose ($fp);
  493. }
  494. }
  495. if($success){
  496. // print str_replace("<","<br />&lt;",$res) . "<br />\n";
  497. $success = ParseCanadaPostXMLOutput($res, $international, $totalCost, $errormsg, $errorcode, $intShipping);
  498. sortshippingarray();
  499. }
  500. return $success;
  501. }
  502. ?>