Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezupsservice.php
Go to the documentation of this file.
1 <?php
3 //
4 // dependancies
5 // include_once("classes/INIFile.php");
6 // include_once("classes/ezdb.php");
7 //
8 // eZ UPS class
9
10 class ezups {
11 var $resultArray = array();
12 var $xmlarray = array();
13 var $xml = "";
14 var $adminstate = "";
15 var $adminzip = "";
16 var $admincountry = "";
17 var $userups = "";
18 var $accessups = "";
19 var $passups = "";
20 var $flatservice = "";
21 var $service = "";
22 var $state = "";
23 var $zip = "";
24 var $country = "";
25 var $totalarr = "";
26 var $residential = "";
27 var $package_type = "";
28 var $emptyarr = "";
29 var $addamount = "";
30 var $ID = "";
31 var $result = "";
32 var $request = "";
33 var $i = 0;
34 function ezupsser($id = "", $service = 01, $state = false, $zip = false, $country = false, $totarr = false)
35 {
36 if ($id != "") {
37 $ini = &eZINI::instance( 'site.ini' );
38 $this->adminstate = $ini->variable("eZTradeMain", "Adminstate");
39 $this->adminzip = $ini->variable("eZTradeMain", "Adminzip");
40 $this->admincountry = $ini->variable("eZTradeMain", "Admincountry");
41 $this->userups = $ini->variable("site", "UserUPS");
42 $this->accessups = $ini->variable("site", "AccessUPS");
43 $this->passups = $ini->variable("site", "PassUPS");
44 $this->flatservice = $ini->variable("eZTradeMain", "FlatUPSService");
45 $this->totalarr = $totarr;
46 $this->ID = $id;
47 $this->service = $service;
48 $this->state = $state;
49 $this->zip = $zip;
50 $this->country = $country;
51 $this->totalarr = $totarr;
52 $this->residential = 0;
53 $this->package_type = 02;
54 $this->emptyarr = "false";
55 // $this->addamount=0;
56 $getresult = $this->get();
57
58 return $getresult;
59 }
60 }
61 function get()
62 {
63 $id = $this->ID;
64 $service = $this->service;
65 $state = $this->state;
66 $zip = $this->zip;
67 $country = $this->country;
68 $totalarr = $this->totalarr;
69 $getservice = $this->getservices($state, $country);
70 return $getservice;
71 }
72
73 function getservices($sta, $cou)
74 {
75 $ini = &eZINI::instance( 'site.ini' );
76 $emptyarr = array();
77 if (strtolower($cou) == "us") {
78 if (($sta != "AF") && ($sta != "AA") && ($sta != "AC") && ($sta != "AE") && ($sta != "AM") && ($sta != "AP")) {
79 if (($sta != "AK") && ($sta != "HI")) {
80 // $servicearr =array ( '02','03','12');
81 $serviceprearr = $ini->variable("eZTradeMain", "USExcept");
82
83 $splsitearr = explode(";", $serviceprearr);
84 for($sitecount = 0;$sitecount < count($splsitearr);$sitecount++) {
85 $servicearr[] = $splsitearr[$sitecount];
86 }
87 } else {
88 // $servicearr = array ('01','02');
89 $serviceprearr = $ini->variable("eZTradeMain", "USInclude");
90
91 $splsitearr = explode(";", $serviceprearr);
92 for($sitecount = 0;$sitecount < count($splsitearr);$sitecount++) {
93 $servicearr[] = $splsitearr[$sitecount];
94 }
95 }
96 } else {
97 // If armed forces return nothing.
98 return $emptyarr;
99 }
100 } else {
101 $jointcountry = $cou . "ups";
102 $serviceprearr = $ini->variable("eZTradeMain", "$jointcountry");
103 if (!empty($serviceprearr)) {
104 $splsitearr = explode(";", $serviceprearr);
105 for($sitecount = 0;$sitecount < count($splsitearr);$sitecount++) {
106 $servicearr[] = $splsitearr[$sitecount];
107 }
108 // $servicearr = array('11');
109 } else {
110 $serviceprearr = $ini->variable("eZTradeMain", "Defaultups");
111 $splsitearr = explode(';', $serviceprearr);
112 for($sitecount = 0;$sitecount < count($splsitearr);$sitecount++) {
113 $servicearr[] = $splsitearr[$sitecount];
114 }
115 }
116 }
117 $getthis = $this->getxml($servicearr);
118 return $getthis;
119 }
120
121 function getxml($service)
122 {
123 $resultArray = array();
124 $inc = 0;
125 $j = 0;
126 $boxesarr = array();
127 $s_state = $this->adminstate;
128 $s_zip = $this->adminzip;
129 $s_country = $this->admincountry;
130 // echo "count service ".count($service);
131 $i = 0;
132 foreach($service as $ser) {
133 $packxml = '';
134 $packxml2 = '';
135
136 if ($service == '') {
137 $this->request = 'shop';
138 } else {
139 $this->request = 'rate';
140 }
141
142 $xml = "<?xml version=\"1.0\"?>
143 <AccessRequest xml:lang=\"en-US\">
144 <AccessLicenseNumber>$this->accessups</AccessLicenseNumber>
145 <UserId>$this->userups</UserId>
146 <Password>$this->passups</Password>
147 </AccessRequest>
148 <?xml version=\"1.0\"?>
149 <RatingServiceSelectionRequest xml:lang=\"en-US\">
150 <Request>
151 <TransactionReference>
152 <CustomerContext>Rating and Service</CustomerContext>
153 <XpciVersion>1.0001</XpciVersion>
154 </TransactionReference>
155 <RequestAction>Rate</RequestAction>
156 <RequestOption>$this->request</RequestOption>
157 </Request>
158 <PickupType>
159 <Code>01</Code>
160 </PickupType>
161 <Shipment>
162 <Shipper>
163 <Address>
164 <StateProvinceCode>$s_state</StateProvinceCode>
165 <PostalCode>$s_zip</PostalCode>
166 <CountryCode>$s_country</CountryCode>
167 </Address>
168 </Shipper>
169 <ShipTo>
170 <Address>
171 <StateProvinceCode>$this->state</StateProvinceCode>
172 <PostalCode>$this->zip</PostalCode>
173 <CountryCode>$this->country</CountryCode>
174 <ResidentialAddressIndicator>$this->residential</ResidentialAddressIndicator>
175 </Address>
176 </ShipTo>
177 <Service>
178 <Code>$ser</Code>
179 </Service>";
180 // <? just a syntax highlighting restart
181 $inc = 0;
182 $gettotarr = $this->totalarr;
183 $boxesarr = $gettotarr['box'];
184
185 if ( isset($gettotarr['withoutbox'] ) && !empty($gettotarr['withoutbox']) )
186 {
187 foreach($boxesarr as $tot)
188 {
189 $weight = $tot['weight'];
190 $length = $tot['length'];
191 $height = $tot['height'];
192 $width = $tot['width'];
193 $count = $tot['count'];
194 if (!$count < 1) {
195 while ($inc < $count) {
196 if ($ser == $this->flatservice && is_numeric($tot['flatups']) && $tot['flatups'] == 0) { // don't add it in if it is a free shipping item
197 $inc += 1;
198 continue;
199 }
200 if ($ser == $this->flatservice && $tot['flatups'] != 'off' && !$tot['combineflat']) {
201 $this->addamount += $tot['flatups'];
202 $inc += 1;
203 continue;
204 }
205
206 $packxml .= "<Package>
207 <PackagingType>
208 <Code>02</Code>
209 <Description>Package</Description>
210 </PackagingType>
211 <Dimensions>
212 <UnitOfMeasurement>
213 <Code>IN</Code>
214 </UnitOfMeasurement>
215 <Length>$length</Length>
216 <Width>$width</Width>
217 <Height>$height</Height>
218 </Dimensions>
219 <Description>Rate Shopping</Description>
220 <PackageWeight>
221 <Weight>$weight</Weight>
222 </PackageWeight>
223 </Package>";
224
225 $inc += 1;
226 }
227 }
228 $inc = 0;
229 $count = 0;
230 }
231 $this->nocombine = true; // if $this->nocombine
232 if (!empty($boxesarr)) {
233 foreach ($boxesarr as $tot) {
234 if ($tot['flatups'] == 'off') {
235 $this->nocombine = false;
236 }
237 }
238 }
239 foreach ($gettotarr['withoutbox'] as $withoutbox) {
240 if ($withoutbox['flatups'] == 'off') {
241 $this->nocombine = false;
242 }
243 }
244 if (isset($gettotarr['withoutbox'][0]['weight'])) {
245 for ($j = 0; $j < sizeof($gettotarr['withoutbox']); $j++) {
246 if ($ser == $this->flatservice && is_numeric($gettotarr['withoutbox'][$j]['flatups']) && $gettotarr['withoutbox'][$j]['flatups'] == 0) continue; // free shipping
247 if ($ser == $this->flatservice && $gettotarr['withoutbox'][$j]['flatups'] != 'off' && !$gettotarr['withoutbox'][$j]['combineflat']) {
248 $this->addamount += $gettotarr['withoutbox'][$j]['flatups'];
249 continue;
250 }
251 if ($this->nocombine && $ser == $this->flatservice && $gettotarr['withoutbox'][$j]['flatups'] != 'off' && $gettotarr['withoutbox'][$j]['combineflat']) {
252 $this->addamount += $gettotarr['withoutbox'][$j]['flatups'];
253 continue;
254 }
255 $withoutweight = $gettotarr['withoutbox'][$j]['weight'];
256 $packxml2 .= "<Package>
257 <PackagingType>
258 <Code>02</Code>
259 <Description>Package</Description>
260 </PackagingType>
261 <Dimensions>
262 <UnitOfMeasurement>
263 <Code>IN</Code>
264 </UnitOfMeasurement>
265 <Length>0</Length>
266 <Width>0</Width>
267 <Height>0</Height>
268 </Dimensions>
269 <Description>Rate Shopping</Description>
270 <PackageWeight>
271 <Weight>$withoutweight</Weight>
272 </PackageWeight>
273 </Package>";
274 }
275 }
276 $withoutbox = 0;
277 $lastxml = "<ShipmentServiceOptions/></Shipment></RatingServiceSelectionRequest>";
278 // echo ("ser: $ser <br>");
279 // echo ("flatservice: $this->flatservice <br>");
280 if ($this->nocombine && $ser == $this->flatservice) {
281 if (strlen($this->addamount) < 3 && strlen($this->addamount) > 0) $this->addamount = $this->addamount . '.00';
282 elseif (strlen($this->addamount) < 4 && strlen($this->addamount) > 0) $this->addamount = $this->addamount . '0';
283 $resultArray[$i] = $this->addamount . '||' . $this->flatservice;
284 $i++;
285 } else {
286 $xml = $xml . $packxml . $packxml2 . $lastxml;
287 $ch = curl_init();
288
289 curl_setopt($ch, CURLOPT_URL, "https://www.ups.com/ups.app/xml/Rate");
290
291 curl_setopt($ch, CURLOPT_HEADER, 0);
292
293 curl_setopt($ch, CURLOPT_POST, 1);
294
295 curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
296
297 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
298
299 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
300
301 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
302
303 $this->xmlreturndata = curl_exec($ch);
304
305 $this->xmlarray = $this->_get_xml_array($this->xmlreturndata);
306 // curl_close($this->xmlarray);
307 curl_close($ch);
308 if ($this->xmlarray == "") {
309 $this->error = 0;
310
311 $this->errormsg = "Unable to retrieve the Shipping info";
312 // return NULL;
313 }
314
315 if( isset( $this->xmlarray['RatingServiceSelectionResponse']['Response'][0] ) )
316 {
317 $values = $this->xmlarray['RatingServiceSelectionResponse']['Response'][0];
318
319 if (isset ($values['ResponseStatusCode']) && $values['ResponseStatusCode'] == 0)
320 {
321 $this->error = $values['Error'][0]['ErrorCode'];
322 $this->errormsg = $values['Error'][0]['ErrorDescription'];
323 // return NULL;
324 }
325 }
326
327 $resultArray[$i] = $this->get_rates();
328 $i++;
329 }
330 }
331 }
332 // die(print_r($resultArray));
333 return $resultArray;
334 }
335
336 function _get_xml_array($data)
337 {
338 $values = array();
339
340 $index = array();
341
342 $array = array();
343
344 $parser = xml_parser_create();
345
346 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
347
348 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
349
350 xml_parse_into_struct($parser, $data, $values, $index);
351
352 xml_parser_free($parser);
353
354 $i = 0;
355
356 if( isset( $values[$i]['tag'] ) )
357 $name = $values[$i]['tag'];
358 else
359 $name = false;
360
361 if( isset( $values[$i]['attributes'] ) )
362 $array[$name] = $values[$i]['attributes'];
363
364 $array[$name] = $this->__get_xml_array($values, $i);
365
366 return $array;
367 }
368
369 function __get_xml_array($values, &$i)
370 {
371 $child = array();
372
373 if (isset($values[$i]['value']) &&$values[$i]['value'])
374 array_push($child, $values[$i]['value']);
375
376 while (++$i < count($values)) {
377 switch ($values[$i]['type']) {
378 case 'cdata':
379
380 array_push($child, $values[$i]['value']);
381
382 break;
383
384 case 'complete':
385
386 $name = $values[$i]['tag'];
387
388 $child[$name] = $values[$i]['value'];
389
390 if ($values[$i]['attributes']) {
391 $child[$name] = $values[$i]['attributes'];
392 }
393
394 break;
395
396 case 'open':
397
398 $name = $values[$i]['tag'];
399
400 $size = sizeof($child[$name]);
401
402 if ($values[$i]['attributes']) {
403 $child[$name][$size] = $values[$i]['attributes'];
404
405 $child[$name][$size] = $this->__get_xml_array($values, $i);
406 } else {
407 $child[$name][$size] = $this->__get_xml_array($values, $i);
408 }
409
410 break;
411
412 case 'close':
413
414 return $child;
415
416 break;
417 }
418 }
419 return $child;
420 }
421
422 function get_rates()
423 {
424 // $retArray = array('service'=>'','basic'=>0,'option'=>0,'total'=>0,'days'=>'','time'=>'');
425 $retArray = array();
426 $servicevalue = false;
427 $moneyvalue = false;
428 if( isset( $this->xmlarray['RatingServiceSelectionResponse']['RatedShipment'] ) && (int)$this->xmlarray['RatingServiceSelectionResponse']['RatedShipment'] == null )
429 {
430 $values = $this->xmlarray['RatingServiceSelectionResponse']['RatedShipment'];
431 //echo '<pre>';
432 //var_dump($this->xmlarray);
433 //echo '</pre>';
434 if( isset($values) )
435 {
436 $ct = count($values);
437 }
438 else {
439 $ct = 0;
440 }
441
442 // echo "count :".$ct;
443 for($i = 0;$i < $ct;$i++) {
444 $current = &$values[$i];
445
446 $retArray[$i]['service'] = $current['Service'][0]['Code'];
447
448 $retArray[$i]['basic'] = $current['TransportationCharges'][0]['MonetaryValue'];
449
450 $retArray[$i]['option'] = $current['ServiceOptionsCharges'][0]['MonetaryValue'];
451
452 $retArray[$i]['total'] = $current['TotalCharges'][0]['MonetaryValue'];
453
454 $retArray[$i]['days'] = $current['GuaranteedDaysToDelivery'];
455
456 $retArray[$i]['time'] = $current['ScheduledDeliveryTime'];
457 $servicevalue = $retArray[$i]['service'];
458
459 if ($this->flatservice == $retArray[$i]['service'] && $this->addamount != '' && !$this->nocombine) {
460 $moneyvalue = $retArray[$i]['total'] + $this->addamount;
461 } else {
462 $moneyvalue = $retArray[$i]['total'];
463 }
464 // echo "<br>service code :".$servicevalue;
465 // echo "<br>cost :".$moneyvalue;
466 }
467
468 $getvalue = $moneyvalue . "||" . $servicevalue;
469 return $getvalue;
470 }
471 }
472
473 function setservice($uid, $value)
474 {
475 $db = &eZDB::globalDatabase();
476
477 $dbError = false;
478 $db->begin();
479 // lock the table
480 $db->lock("eZUps_Servicecode");
481
482 $query = "SELECT id FROM eZUps_Servicecode WHERE userid=$uid";
483
484 $db->array_query($value_array, $query);
485
486 if (count($value_array) == 1) {
487 $res = $db->query("UPDATE eZUps_Servicecode SET servicecode=$value WHERE userid=$uid");
488 } else {
489 $nextID = $db->nextID("eZUps_Servicecode", "id");
490
491 $res = $db->query("INSERT INTO eZUps_Servicecode(id,userid,servicecode,value)VALUES($nextID,$uid,$value,$value)");
492
493 if ($res == false)
494 $dbError = true;
495 }
496
497 $db->unlock();
498
499 if ($dbError == true)
500 $db->rollback();
501 else
502 $db->commit();
503 }
504
505 function getservice($uid)
506 {
507 $db = &eZDB::globalDatabase();
508 $db->array_query($value_array, "select servicecode from eZUps_Servicecode where userid=$uid");
509
510 $ret = $value_array[$db->fieldName("servicecode")];
511
512 return $ret;
513 }
514 }
515
516 ?>
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
$ini
$ini
Definition: classes/admin/linklist.php:64
ezups
Definition: ezupsservice.php:10
ezups\ezupsser
ezupsser($id="", $service=01, $state=false, $zip=false, $country=false, $totarr=false)
Definition: ezupsservice.php:34
ezups\_get_xml_array
_get_xml_array($data)
Definition: ezupsservice.php:336
ezups\$userups
$userups
Definition: ezupsservice.php:17
ezups\$emptyarr
$emptyarr
Definition: ezupsservice.php:28
ezups\$zip
$zip
Definition: ezupsservice.php:23
ezups\$xml
$xml
Definition: ezupsservice.php:13
ezups\getservice
getservice($uid)
Definition: ezupsservice.php:505
ezups\$addamount
$addamount
Definition: ezupsservice.php:29
ezups\$state
$state
Definition: ezupsservice.php:22
ezups\$i
$i
Definition: ezupsservice.php:33
ezups\$totalarr
$totalarr
Definition: ezupsservice.php:25
ezups\getxml
getxml($service)
Definition: ezupsservice.php:121
ezups\__get_xml_array
__get_xml_array($values, &$i)
Definition: ezupsservice.php:369
ezups\$package_type
$package_type
Definition: ezupsservice.php:27
ezups\get_rates
get_rates()
Definition: ezupsservice.php:422
ezups\$request
$request
Definition: ezupsservice.php:32
ezups\$adminzip
$adminzip
Definition: ezupsservice.php:15
ezups\$resultArray
$resultArray
Definition: ezupsservice.php:11
ezups\$passups
$passups
Definition: ezupsservice.php:19
ezups\getservices
getservices($sta, $cou)
Definition: ezupsservice.php:73
ezups\$residential
$residential
Definition: ezupsservice.php:26
ezups\setservice
setservice($uid, $value)
Definition: ezupsservice.php:473
ezups\$flatservice
$flatservice
Definition: ezupsservice.php:20
ezups\$admincountry
$admincountry
Definition: ezupsservice.php:16
ezups\$accessups
$accessups
Definition: ezupsservice.php:18
ezups\$ID
$ID
Definition: ezupsservice.php:30
ezups\$adminstate
$adminstate
Definition: ezupsservice.php:14
ezups\$xmlarray
$xmlarray
Definition: ezupsservice.php:12
ezups\$country
$country
Definition: ezupsservice.php:24
ezups\$service
$service
Definition: ezupsservice.php:21
ezups\$result
$result
Definition: ezupsservice.php:31
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
error
error( $errmsg)
Definition: eZPBINIFile.php:465
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$index
$index
Definition: ezforum/user/messageedit.php:36
$j
$j
Definition: ezimagecatalogue/admin/imagelist.php:345
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$values
$values
Definition: fixedvalues.php:103
$count
$count
Definition: onlinetypelist.php:108
$current
$current
Definition: slideshow.php:97
$height
$height
Definition: user/imageview.php:171
$width
$width
Definition: user/imageview.php:170
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.