PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/modules/shipping/dp.php

https://bitbucket.org/flth/xtcm
PHP | 169 lines | 115 code | 28 blank | 26 comment | 25 complexity | ab6d262c8f0bd54dba86a2f30c4b171b MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id: dp.php 899 2005-04-29 02:40:57Z hhgag $
  4. XT-Commerce - community made shopping
  5. http://www.xt-commerce.com
  6. Copyright (c) 2003 XT-Commerce
  7. -----------------------------------------------------------------------------------------
  8. based on:
  9. (c) 2000-2001 The Exchange Project (earlier name of osCommerce)
  10. (c) 2002-2003 osCommerce(dp.php,v 1.36 2003/03/09 02:14:35); www.oscommerce.com
  11. (c) 2003 nextcommerce (dp.php,v 1.12 2003/08/24); www.nextcommerce.org
  12. Released under the GNU General Public License
  13. -----------------------------------------------------------------------------------------
  14. Third Party contributions:
  15. German Post (Deutsche Post WorldNet) Autor: Copyright (C) 2002 - 2003 TheMedia, Dipl.-Ing Thomas Plänkers | http://www.themedia.at & http://www.oscommerce.at
  16. Released under the GNU General Public License
  17. ---------------------------------------------------------------------------------------*/
  18. class dp {
  19. var $code, $title, $description, $icon, $enabled, $num_dp;
  20. function dp() {
  21. global $order;
  22. $this->code = 'dp';
  23. $this->title = MODULE_SHIPPING_DP_TEXT_TITLE;
  24. $this->description = MODULE_SHIPPING_DP_TEXT_DESCRIPTION;
  25. $this->sort_order = MODULE_SHIPPING_DP_SORT_ORDER;
  26. $this->icon = DIR_WS_ICONS . 'shipping_dp.gif';
  27. $this->tax_class = MODULE_SHIPPING_DP_TAX_CLASS;
  28. $this->enabled = ((MODULE_SHIPPING_DP_STATUS == 'True') ? true : false);
  29. if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_DP_ZONE > 0) ) {
  30. $check_flag = false;
  31. $check_query = xtc_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_DP_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  32. while ($check = xtc_db_fetch_array($check_query)) {
  33. if ($check['zone_id'] < 1) {
  34. $check_flag = true;
  35. break;
  36. } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  37. $check_flag = true;
  38. break;
  39. }
  40. }
  41. if ($check_flag == false) {
  42. $this->enabled = false;
  43. }
  44. }
  45. /**
  46. * CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
  47. */
  48. $this->num_dp = 6;
  49. }
  50. /**
  51. * class methods
  52. */
  53. function quote($method = '') {
  54. global $order, $shipping_weight, $shipping_num_boxes;
  55. $dest_country = $order->delivery['country']['iso_code_2'];
  56. $dest_zone = 0;
  57. $error = false;
  58. for ($i=1; $i<=$this->num_dp; $i++) {
  59. $countries_table = constant('MODULE_SHIPPING_DP_COUNTRIES_' . $i);
  60. $country_zones = explode(",", $countries_table); // Hetfield - 2009-08-18 - replaced deprecated function split with explode to be ready for PHP >= 5.3
  61. if (in_array($dest_country, $country_zones)) {
  62. $dest_zone = $i;
  63. break;
  64. }
  65. }
  66. if ($dest_zone == 0) {
  67. $error = true;
  68. } else {
  69. $shipping = -1;
  70. $dp_cost = constant('MODULE_SHIPPING_DP_COST_' . $i);
  71. $dp_table = preg_split("/[:,]/" , $dp_cost); // Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  72. for ($i=0; $i<sizeof($dp_table); $i+=2) {
  73. if ($shipping_weight <= $dp_table[$i]) {
  74. $shipping = $dp_table[$i+1];
  75. $shipping_method = MODULE_SHIPPING_DP_TEXT_WAY . ' ' . $dest_country . ': ';
  76. break;
  77. }
  78. }
  79. if ($shipping == -1) {
  80. $shipping_cost = 0;
  81. $shipping_method = MODULE_SHIPPING_DP_UNDEFINED_RATE;
  82. } else {
  83. $shipping_cost = ($shipping + MODULE_SHIPPING_DP_HANDLING);
  84. }
  85. }
  86. $this->quotes = array('id' => $this->code,
  87. 'module' => MODULE_SHIPPING_DP_TEXT_TITLE,
  88. 'methods' => array(array('id' => $this->code,
  89. 'title' => $shipping_method . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . ' ' . MODULE_SHIPPING_DP_TEXT_UNITS .')',
  90. 'cost' => $shipping_cost * $shipping_num_boxes)));
  91. if ($this->tax_class > 0) {
  92. $this->quotes['tax'] = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  93. }
  94. if (xtc_not_null($this->icon)) $this->quotes['icon'] = xtc_image($this->icon, $this->title);
  95. if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_DP_INVALID_ZONE;
  96. return $this->quotes;
  97. }
  98. function check() {
  99. if (!isset($this->_check)) {
  100. $check_query = xtc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_DP_STATUS'");
  101. $this->_check = xtc_db_num_rows($check_query);
  102. }
  103. return $this->_check;
  104. }
  105. function install() {
  106. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SHIPPING_DP_STATUS', 'True', '6', '0', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  107. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_HANDLING', '0', '6', '0', now())");
  108. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_SHIPPING_DP_TAX_CLASS', '0', '6', '0', 'xtc_get_tax_class_title', 'xtc_cfg_pull_down_tax_classes(', now())");
  109. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_SHIPPING_DP_ZONE', '0', '6', '0', 'xtc_get_zone_class_title', 'xtc_cfg_pull_down_zone_classes(', now())");
  110. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_SORT_ORDER', '0', '6', '0', now())");
  111. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_ALLOWED', '', '6', '0', now())");
  112. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COUNTRIES_1', 'AD,AT,BE,CZ,DK,FO,FI,FR,GR,GL,IE,IT,LI,LU,MC,NL,PL,PT,SM,SK,SE,CH,VA,GB,SP', '6', '0', now())");
  113. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COST_1', '5:16.50,10:20.50,20:28.50', '6', '0', now())");
  114. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COUNTRIES_2', 'AL,AM,AZ,BY,BA,BG,HR,CY,GE,GI,HU,IS,KZ,LT,MK,MT,MD,NO,SI,UA,TR,YU,RU,RO,LV,EE', '6', '0', now())");
  115. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COST_2', '5:25.00,10:35.00,20:45.00', '6', '0', now())");
  116. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COUNTRIES_3', 'DZ,BH,CA,EG,IR,IQ,IL,JO,KW,LB,LY,OM,SA,SY,US,AE,YE,MA,QA,TN,PM', '6', '0', now())");
  117. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COST_3', '5:29.00,10:39.00,20:59.00', '6', '0', now())");
  118. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COUNTRIES_4', 'AF,AS,AO,AI,AG,AR,AW,AU,BS,BD,BB,BZ,BJ,BM,BT,BO,BW,BR,IO,BN,BF,BI,KH,CM,CV,KY,CF,TD,CL,CN,CC,CO,KM,CG,CR,CI,CU,DM,DO,EC,SV,ER,ET,FK,FJ,GF,PF,GA,GM,GH,GD,GP,GT,GN,GW,GY,HT,HN,HK,IN,ID,JM,JP,KE,KI,KG,KP,KR,LA,LS', '6', '0', now())");
  119. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COST_4', '5:35.00,10:50.00,20:80.00', '6', '0', now())");
  120. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COUNTRIES_5', 'MO,MG,MW,MY,MV,ML,MQ,MR,MU,MX,MN,MS,MZ,MM,NA,NR,NP,AN,NC,NZ,NI,NE,NG,PK,PA,PG,PY,PE,PH,PN,RE,KN,LC,VC,SN,SC,SL,SO,LK,SR,SZ,ZA,SG,TG,TH,TZ,TT,TO,TM,TV,VN,WF,VE,UG,UZ,UY,ST,SH,SD,TW,GQ,LR,DJ,CG,RW,ZM,ZW', '6', '0', now())");
  121. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COST_5', '5:35.00,10:50.00,20:80.00', '6', '0', now())");
  122. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COUNTRIES_6', 'DE', '6', '0', now())");
  123. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_DP_COST_6', '5:6.70,10:9.70,20:13.00', '6', '0', now())");
  124. }
  125. function remove() {
  126. xtc_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  127. }
  128. function keys() {
  129. $keys = array('MODULE_SHIPPING_DP_STATUS', 'MODULE_SHIPPING_DP_HANDLING','MODULE_SHIPPING_DP_ALLOWED', 'MODULE_SHIPPING_DP_TAX_CLASS', 'MODULE_SHIPPING_DP_ZONE', 'MODULE_SHIPPING_DP_SORT_ORDER');
  130. for ($i = 1; $i <= $this->num_dp; $i ++) {
  131. $keys[count($keys)] = 'MODULE_SHIPPING_DP_COUNTRIES_' . $i;
  132. $keys[count($keys)] = 'MODULE_SHIPPING_DP_COST_' . $i;
  133. }
  134. return $keys;
  135. }
  136. }
  137. ?>