PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/includes/modules/export/guenstiger.php

https://bitbucket.org/flth/xtcm
PHP | 824 lines | 573 code | 152 blank | 99 comment | 115 complexity | 04a5eb4dcc80cc072e627f8c64982ccb MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id: guenstiger.php 2124 2011-08-29 10:14:43Z dokuman $
  4. xtcModified - community made shopping
  5. http://www.xtc-modified.org
  6. Copyright (c) 2010 xtcModified
  7. --------------------------------------------------------------
  8. based on:
  9. (c) 2000-2001 The Exchange Project (earlier name of osCommerce)
  10. (c) 2002-2003 osCommerce(cod.php,v 1.28 2003/02/14); www.oscommerce.com
  11. (c) 2003 nextcommerce (invoice.php,v 1.6 2003/08/24); www.nextcommerce.org
  12. (c) 2006 xt-commerce; www.xt-commerce.com
  13. Released under the GNU General Public License
  14. ---------------------------------------------------------------------------------------*/
  15. defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.' );
  16. define('MODULE_GUENSTIGER_TEXT_DESCRIPTION', '<hr noshade="noshade"><br><center><a href="http://www.guenstiger.de/"><img src="http://www.guenstiger.de/bilder/guenstiger_L_blau.GIF" width="149" height="113" border="0" alt="guenstiger.de - Der grosse Preisvergleich im Internet"></a></center><br><br>
  17. <b>Export</b><br>guenstiger.de<br><br>
  18. <b>Trennzeichen</b><br>getrennt durch | (PIPE)<br><br>
  19. <b>Format</b><br>- ProduktID<br>- Gewicht<br>- EAN<br>- Lagerbestand<br>- Hersteller<br>- ProduktBezeichnung<br>- ArtikelNr. (ggf. auch Hersteller-ArtikelNr.)<br>- Preis<br>- Produktbeschreibung (kurz)<br>- Produktbeschreibung (lang)<br>- Lieferzeit<br><span style="color:#006">- Produktlink <i>(nur in Kooperation mit Preissuchmaschine.de relevant)</i></span><br>- FotoLink<br>- Kategoriename<br>- Vorkasse<br>- Nachnahme<br>- Rechnung<br>- Kreditkarte<br>- Lastschrift<br>- PayPal<br>- Moneybookers<br>- Giropay<br><br>
  20. <span style="color:#006"><b>Besonderheiten</b><br><i>(nur in Kooperation mit Preissuchmaschine.de relevant)</i><br>- Automatisches Kampagnentracking innherhalb von XT-Commerce<br>- Unterst&uuml;tzt Google-Analytics Kampagnentracking<br><br></span>
  21. <b>Modulversion</b><br>guenstiger.de - <i>November 2009 - 2.0</i><br><br>
  22. <b>Fragen</b><br>guenstiger.de Verlag GmbH<br>Vorsetzen 53<br>20459 Hamburg<br><br>Tel: 040 319 796-0<br>Fax: 040 319 796-99<br>E-Mail:<a href="mailto:kontakt@guenstiger.de?SUBJECT=Fragen zum XT:Commerce-Modul November 2009 - 2.0"><u>kontakt@guenstiger.de</u></a>');
  23. define('MODULE_GUENSTIGER_EMAIL','Sehr%20geehrtes%20guenstiger.de-Team,%0A%0Ahierbei%20handelt%20es%20sich%20um%20eine%20%FCber%20das%20%22guenstiger.de%20-%20CSV%22%20Modul%20automatisch%20generierte%20E-Mail%20aus%20dem%20XT-Commerce%20Backoffice.%0A%0ABitte%20pr%FCfen%20Sie%20meinen%20Shop%20<-SHOP->%20,%20ob%20dieser%20bei%20Ihnen%20aufgenommen%20werden%20kann.%0A%0ADer%20Link%20zu%20der%20Produktdatenliste%20ist:%0A<-LINK->%0A%0ABitte%20geben%20Sie%20diese%20Informationen%20an%20den%20entsprechenden%20kaufm%E4nnischen%20Berater%20weiter.%0A%0AVielen%20Dank.');
  24. define('MODULE_GUENSTIGER_TEXT_TITLE', 'guenstiger.de - CSV');
  25. define('MODULE_GUENSTIGER_FILE_TITLE' , '<hr noshade>Dateiname:');
  26. define('MODULE_GUENSTIGER_FILE_DESC' , 'Das Modul legt diese generierte Preisliste/Produktdatenliste/Exportdatei bei der Speicherart \'Auf dem Server speichern\' automatisch im Unterverzeichnis Ihres Shops mit dem Namen \'export/\' (Das Verzeichnis ben&ouml;tigt folgende Rechte 0777) ab. Die Datei hat dort folgende Bezeichnung:');
  27. define('MODULE_GUENSTIGER_STATUS_DESC','Modulstatus');
  28. define('MODULE_GUENSTIGER_STATUS_TITLE','Status');
  29. define('MODULE_GUENSTIGER_EXPORT_YES','Auf dem Server speichern und herunterladen');
  30. define('MODULE_GUENSTIGER_EXPORT_NO','Auf dem Server speichern');
  31. define('MODULE_GUENSTIGER_EXPORT_LINK','export/');
  32. define('MODULE_GUENSTIGER_EXPORT','Bitte diesen Export-Prozess AUF <b>KEINEN</b> FALL unterbrechen. Dieser kann vor allem bei Shops mit gr&ouml;&szlig;eren Datenbest&auml;nden einige Minuten in Anspruch nehmen.');
  33. define('MODULE_GUENSTIGER_GTGOOGLEHeader','<span style="color:#006"><hr noshade><b>Google-Analytics:</b></span>');
  34. define('MODULE_GUENSTIGER_GTGOOGLE_DESC','<span style="color:#006"><i>(nur in Kooperation mit Preissuchmaschine.de relevant)</i><br>Wenn Sie diese Option einschalten, werden an die Produktlinks automatisch Parameter angeh&auml;ngt, mit denen Sie den Erfolg der Kooperation mit Preissuchmaschine.de zus&auml;tzlich in Google-Analytics verfolgen k&ouml;nnen. Sie finden die Auswertung unter dem Men&uuml;punkt "Zugriffsquellen" -&gt; "Kampagnen" -&gt; "preissuchmaschine".</span>');
  35. define('MODULE_GUENSTIGER_GTGOOGLE_NO','<span style="color:#006">Nicht aktivieren</span>');
  36. define('MODULE_GUENSTIGER_GTGOOGLE_YES','<span style="color:#006">Aktivieren</span>');
  37. define('MODULE_GUENSTIGER_EXPORT_TYPE','<hr noshade><b>Speicherart:</b>');
  38. define('MODULE_GUENSTIGER_CAMPAIGNS','<span style="color:#006"><hr noshade><b>Kampagnen:</b> (automatisch)</span>');
  39. //BOF - web28 - 2010-09-06 - Fix admin to DIR_WS_ADMIN
  40. //define('MODULE_GUENSTIGER_CAMPAIGNS_LINK',HTTP_CATALOG_SERVER.DIR_WS_CATALOG."admin/stats_campaigns.php?report=2&startD=1&startM=".date("m")."&startY=".date("Y")."&status=0&campaign=psm&endD=".date("d")."&endM=".date("m")."&endY=".date("Y"));
  41. define('MODULE_GUENSTIGER_CAMPAIGNS_LINK',HTTP_CATALOG_SERVER.DIR_WS_ADMIN."stats_campaigns.php?report=2&startD=1&startM=".date("m")."&startY=".date("Y")."&status=0&campaign=psm&endD=".date("d")."&endM=".date("m")."&endY=".date("Y"));
  42. //EOF - web28 - 2010-09-06 - Fix admin to DIR_WS_ADMIN
  43. define('MODULE_GUENSTIGER_CAMPAIGNS_DESC','<span style="color:#006"><i>(nur in Kooperation mit Preissuchmaschine.de relevant)</i><br>Durch unsere automatische Kampagneneinrichtung k&ouml;nnen Sie jederzeit die von der <a href="campaigns.php"><i>Kampagne</i></a> Preissuchmaschine.de in Ihren Onlineshop weitergeleiteten Nutzer auswerten. Sie sollten &uuml;ber folgenden Link den durch uns generierten Warenkorbumsatz jederzeit nachvollziehen k&ouml;nnen:<br><br><a style="text-decoration:underline:color:#006" href=\''.MODULE_GUENSTIGER_CAMPAIGNS_LINK.'\'><i><b>Kampagnen-Report</b></i></a><br><br></span>');
  44. define('MODULE_GUENSTIGER_EXPORT_LINK_SEND','<a style="text-decoration:underline" href=\'mailto:haendlerinfo@guenstiger.de?SUBJECT=Anfrage - Interesse an einer eventuellen Onlinekooperation&BODY=' . str_replace("<-SHOP->",HTTP_CATALOG_SERVER . DIR_WS_CATALOG,str_replace("<-LINK->",HTTP_CATALOG_SERVER . DIR_WS_CATALOG . MODULE_GUENSTIGER_EXPORT_LINK . MODULE_GUENSTIGER_FILE,MODULE_GUENSTIGER_EMAIL)) . '\'><br><br><i><b>zur Anfrage</b> </i></a>(sofern noch nicht erfolgt)');
  45. $gtgoogle_input_query = xtc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_GUENSTIGER_PSMGOOGLEV' LIMIT 1");
  46. $res = xtc_db_fetch_array($gtgoogle_input_query);
  47. if (isset($_POST['gtgoogle'])) {
  48. $_POST['gtgoogle'] == "yes"?$val="Y":$val="N";
  49. if( $res !== false ) {
  50. // update value if $_POST['freeshippinglimit_input'] != $freeshipping_comment_db
  51. if( $val != $res['configuration_value'] ) {
  52. xtc_db_query("update " . TABLE_CONFIGURATION . "
  53. set configuration_value = '" . $val . "'
  54. where configuration_key = 'MODULE_GUENSTIGER_PSMGOOGLEV'");
  55. }
  56. } else {
  57. // insert data
  58. xtc_db_query("insert into " . TABLE_CONFIGURATION . "
  59. (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added)
  60. values ('MODULE_GUENSTIGER_PSMGOOGLEV', '" . $val . "', 6, 1, '', now()) ");
  61. }
  62. $UseGoogle = $val=="Y";
  63. } else {
  64. if( $res !== false ) {
  65. $resArray = xtc_db_fetch_array($res) ;
  66. $UseGoogle = $resArray['configuration_value'] == "Y";
  67. } else {
  68. $UseGoogle = false;
  69. }
  70. }
  71. class guenstiger {
  72. var $code, $title, $description, $enabled;
  73. var $shippingtax = -1;
  74. var $shippingtaxcod = -1;
  75. var $shipping_free_shipping = -1;
  76. var $payment = array('MONEYORDER' => array('active' => false,
  77. 'title' => 'Vorkasse'),
  78. 'COD' => array('active' => false,
  79. 'title' => 'Nachnahme'),
  80. 'INVOICE' => array('active' => false,
  81. 'title' => 'Rechnung'),
  82. 'CC' => array('active' => false,
  83. 'title' => 'Kreditkarte'),
  84. 'BANKTRANSFER' => array('active' => false,
  85. 'title' => 'Lastschrift'),
  86. 'PAYPAL' => array('active' => false,
  87. 'title' => 'PayPal'),
  88. 'MONEYBOOKERS' => array('active' => false,
  89. 'title' => 'Moneybookers'),
  90. );
  91. function guenstiger() {
  92. global $order;
  93. $this->code = 'guenstiger';
  94. $this->title = MODULE_GUENSTIGER_TEXT_TITLE;
  95. $this->description = MODULE_GUENSTIGER_TEXT_DESCRIPTION;
  96. $this->sort_order = MODULE_GUENSTIGER_SORT_ORDER;
  97. $this->CAT=array();
  98. $this->PARENT=array();
  99. $this->enabled = ((MODULE_GUENSTIGER_STATUS == 'True') ? true : false);
  100. // check which payment method (cod, cash etc. ...) is active
  101. $this->checkActivePayment();
  102. // check which payment option (default, per item, table) is active
  103. $this->checkStandardShippingCostsOption();
  104. $this->TAX = array ();
  105. $zones_query = xtDBquery("SELECT tax_class_id as class FROM ".TABLE_TAX_CLASS);
  106. while ($zones_data = xtc_db_fetch_array($zones_query,true)) {
  107. // calculate tax based on shipping or deliverey country (for downloads)
  108. if (isset($_SESSION['billto']) && isset($_SESSION['sendto'])) {
  109. $tax_address_query = xtc_db_query("select ab.entry_country_id, ab.entry_zone_id from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = '" . $_SESSION['customer_id'] . "' and ab.address_book_id = '" . ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'");
  110. $tax_address = xtc_db_fetch_array($tax_address_query);
  111. $this->TAX[$zones_data['class']]=xtc_get_tax_rate($zones_data['class'],$tax_address['entry_country_id'], $tax_address['entry_zone_id']);
  112. } else {
  113. $this->TAX[$zones_data['class']]=xtc_get_tax_rate($zones_data['class']);
  114. }
  115. }
  116. // take the tax data from the db
  117. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  118. FROM " . TABLE_CONFIGURATION . "
  119. WHERE `configuration_key` LIKE 'MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS';");
  120. $result = xtc_db_fetch_array($getValues);
  121. if( isset($result['table_values']) && $result['table_values'] != '') {
  122. $this->shippingtaxcod = $result['table_values'];
  123. }
  124. // take the tax data from the db
  125. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  126. FROM " . TABLE_CONFIGURATION . "
  127. WHERE `configuration_key` LIKE 'MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING';");
  128. $result = xtc_db_fetch_array($getValues);
  129. if( isset($result['table_values']) && $result['table_values'] != '') {
  130. if($result['table_values']) {
  131. // take the tax data from the db
  132. $getValues2 = xtc_db_query("SELECT `configuration_value` AS `table_values`
  133. FROM " . TABLE_CONFIGURATION . "
  134. WHERE `configuration_key` LIKE 'MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER';");
  135. $result2 = xtc_db_fetch_array($getValues2);
  136. if( isset($result2['table_values']) && $result2['table_values'] != '') {
  137. $this->shipping_free_shipping = $result2['table_values'];
  138. }
  139. }
  140. }
  141. }
  142. /**
  143. * Method sets the "table shipping costs" values
  144. */
  145. function setPaymentTableValues() {
  146. $explodedValues = array();
  147. // take the tax data from the db
  148. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  149. FROM " . TABLE_CONFIGURATION . "
  150. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_TABLE_TAX_CLASS';");
  151. $result = xtc_db_fetch_array($getValues);
  152. if( isset($result['table_values']) && $result['table_values'] != '') {
  153. $this->shippingtax = $result['table_values'];
  154. }
  155. // take the data from the db
  156. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  157. FROM " . TABLE_CONFIGURATION . "
  158. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_TABLE_COST';");
  159. $result = xtc_db_fetch_array($getValues);
  160. // the result shouldnt be empty
  161. // otherwise $this->paymentTableValues stays empty
  162. // example string: 25:8.50,50:5.50,10000:0.00
  163. if( isset($result['table_values']) && $result['table_values'] != '') {
  164. // split die Value at the comma
  165. $explodedValues = explode(',', $result['table_values']);
  166. // run through the values and split again at the colon
  167. // the key is the weight / price and the value is the sc
  168. foreach($explodedValues as $values) {
  169. $tmpAr = array();
  170. $tmpAr = explode(":", $values);
  171. // are there only numbers?
  172. if( is_numeric($tmpAr[0]) && is_numeric($tmpAr[1]) ) {
  173. $this->paymentTableValues[$tmpAr[0]] = $tmpAr[1];
  174. }
  175. unset($tmpAr);
  176. }
  177. }
  178. // check what param is used for "table sc": weight or price
  179. $getPaymentTableMode = xtc_db_query("SELECT `configuration_value` AS `table_mode`
  180. FROM " . TABLE_CONFIGURATION . "
  181. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_TABLE_MODE';");
  182. $result = xtc_db_fetch_array($getPaymentTableMode);
  183. if(isset($result['table_mode']) && $result['table_mode'] != '') {
  184. $this->paymentTableMode = $result['table_mode'];
  185. }
  186. }
  187. function checkStandardShippingCostsOption() {
  188. // free shipping?
  189. if($this->checkShippingCostOption('FREEAMOUNT') > 0 ) {
  190. $this->freeShipping = true;
  191. // catch the limit for free shipping
  192. $getFreeamountValue = xtc_db_query("SELECT `configuration_value` AS `freeShippingValue`
  193. FROM `configuration`
  194. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_FREEAMOUNT_AMOUNT';");
  195. $result = xtc_db_fetch_array($getFreeamountValue);
  196. // if the value of the free shipping value is not set, its 0.00 ( = always free)
  197. if(isset($result['freeShippingValue']) && is_numeric($result['freeShippingValue'])) {
  198. $this->freeShippingValue = $result['freeShippingValue'];
  199. } else {
  200. $this->freeShippingValue = 0.00;
  201. }
  202. }
  203. if($this->checkShippingCostOption('TABLE') > 0) {
  204. // table shipping cost
  205. $this->paymentTable = true;
  206. // set the values for table sc to get the correct sc for every offer
  207. $this->setPaymentTableValues();
  208. } elseif($this->checkShippingCostOption('ITEM') > 0) {
  209. // sc per item
  210. $this->paymentItem = true;
  211. // set the standard shipping costs
  212. $this->setStandardShippingCosts();
  213. } elseif($this->checkShippingCostOption('FLAT') > 0) {
  214. // flat sc
  215. $this->paymentFlat = true;
  216. // set the standard shipping costs
  217. $this->setStandardShippingCosts();
  218. } elseif($this->checkShippingCostOption('DP') > 0) {
  219. $this->paymentTable = true;
  220. $this->setPaymentParcelServicesValues('DP');
  221. } elseif($this->checkShippingCostOption('UPS') > 0) {
  222. $this->paymentTable = true;
  223. $this->setPaymentParcelServicesValues('UPS');
  224. } elseif($this->checkShippingCostOption('UPSE') > 0) {
  225. $this->paymentTable = true;
  226. $this->setPaymentParcelServicesValues('UPSE');
  227. }
  228. }
  229. function setPaymentParcelServicesValues($name) {
  230. $explodedValues = array();
  231. // take the tax data from the db
  232. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  233. FROM " . TABLE_CONFIGURATION . "
  234. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_".$name."_TAX_CLASS';");
  235. $result = xtc_db_fetch_array($getValues);
  236. if( isset($result['table_values']) && $result['table_values'] != '') {
  237. $this->shippingtax = $result['table_values'];
  238. }
  239. // take the data from the db
  240. $getValues = xtc_db_query("SELECT RIGHT(`configuration_key`,1) AS `table_values` ".
  241. "FROM ". TABLE_CONFIGURATION ." ".
  242. "WHERE `configuration_key` LIKE '%SHIPPING_".$name."%' ".
  243. "AND `configuration_value` LIKE '%DE%'");
  244. $result = xtc_db_fetch_array($getValues);
  245. if( isset($result['table_values']) && $result['table_values'] != '') {}
  246. else {return;}
  247. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  248. FROM " . TABLE_CONFIGURATION . "
  249. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_".$name."_COST_".$result['table_values']."';");
  250. $result = xtc_db_fetch_array($getValues);
  251. // the result shouldnt be empty
  252. // otherwise $this->paymentTableValues stays empty
  253. // example string: 25:8.50,50:5.50,10000:0.00
  254. if( isset($result['table_values']) && $result['table_values'] != '') {
  255. // split die Value at the comma
  256. $explodedValues = explode(',', $result['table_values']);
  257. // run through the values and split again at the colon
  258. // the key is the weight / price and the value is the sc
  259. foreach($explodedValues as $values) {
  260. $tmpAr = array();
  261. $tmpAr = explode(":", $values);
  262. // are there only numbers?
  263. if( is_numeric($tmpAr[0]) && is_numeric($tmpAr[1]) ) {
  264. $this->paymentTableValues[$tmpAr[0]] = $tmpAr[1];
  265. }
  266. unset($tmpAr);
  267. }
  268. }
  269. $this->paymentTableMode = 'weight';
  270. }
  271. function setStandardShippingCosts() {
  272. $shippingModul = '';
  273. if($this->paymentItem === true) {
  274. $shippingModul = 'MODULE_SHIPPING_ITEM_COST';
  275. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  276. FROM " . TABLE_CONFIGURATION . "
  277. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_ITEM_TAX_CLASS';");
  278. } else {
  279. $shippingModul = 'MODULE_SHIPPING_FLAT_COST';
  280. $getValues = xtc_db_query("SELECT `configuration_value` AS `table_values`
  281. FROM " . TABLE_CONFIGURATION . "
  282. WHERE `configuration_key` LIKE 'MODULE_SHIPPING_FLAT_TAX_CLASS';");
  283. }
  284. // take the tax data from the db
  285. $result = xtc_db_fetch_array($getValues);
  286. if( isset($result['table_values']) && $result['table_values'] != '') {
  287. $this->shippingtax = $result['table_values'];
  288. }
  289. $getStandardShippingCosts = xtc_db_query("SELECT `configuration_value` AS `standard_sc`
  290. FROM `configuration`
  291. WHERE `configuration_key` LIKE '{$shippingModul}';");
  292. $result = xtc_db_fetch_array($getStandardShippingCosts);
  293. // if $result['standard_sc'] is not set, $this->standardShippingCost stays empty (to be on the safe side)
  294. if(isset($result['standard_sc'])) {
  295. $this->standardShippingCost = $result['standard_sc'];
  296. } else {
  297. $this->standardShippingCost = '';
  298. }
  299. }
  300. function checkActivePayment() {
  301. // run through every payment method
  302. foreach($this->payment as $singlePayment => $status) {
  303. // is the pm active?
  304. $checkPayment = xtc_db_query("SELECT COUNT(*) AS `found`
  305. FROM `configuration`
  306. WHERE `configuration_key` LIKE 'MODULE_PAYMENT_{$singlePayment}_STATUS'
  307. AND `configuration_value` LIKE 'True';");
  308. $result = xtc_db_fetch_array($checkPayment);
  309. // if the result is > 0, the pm is active
  310. if($result['found'] > 0) {
  311. $this->payment[$singlePayment]['active'] = true;
  312. }
  313. }
  314. }
  315. function checkShippingCostOption($option) {
  316. // transform to uppercase
  317. $option = strtoupper($option);
  318. $checkOption = xtc_db_query("
  319. SELECT COUNT(*) AS found
  320. FROM configuration
  321. WHERE configuration_key LIKE 'MODULE_SHIPPING_{$option}_STATUS'
  322. AND configuration_value LIKE 'True';
  323. ");
  324. $result = xtc_db_fetch_array($checkOption);
  325. if (isset($result['found']) && $result['found'] > 0) { // module is active, check allowed countries
  326. $countryOption = xtc_db_query("
  327. SELECT COUNT(*) AS found
  328. FROM configuration
  329. WHERE configuration_key LIKE 'MODULE_SHIPPING_{$option}_ALLOWED' AND
  330. (configuration_value LIKE '%DE%' OR configuration_value='');
  331. ");
  332. $countryOk = xtc_db_fetch_array($countryOption);
  333. // if $countryOk['found'] is not set, 0 (country is not activated) will be returned
  334. return (isset($countryOk['found'])) ? $countryOk['found'] : 0;
  335. } else {
  336. return 0;
  337. }
  338. }
  339. function process($file) {
  340. global $UseGoogle;
  341. @xtc_set_time_limit(0);
  342. require(DIR_FS_CATALOG.DIR_WS_CLASSES . 'xtcPrice.php');
  343. $xtPrice = new xtcPrice("EUR",1);
  344. $UseGoogle ? $gtgoogle_link="utm_source=preissuchmaschine&utm_medium=cpc&utm_campaign=preissuchmaschine&" : $gtgoogle_link="";
  345. $schema = 'ProduktID|Gewicht|EAN|Lagerbestand|Hersteller|ProduktBezeichnung|ArtikelNroderHerstellerArtikelNr|Preis|ProduktLangBeschreibung|ProduktKurzBeschreibung|Lieferzeit|Produktlink|FotoLink|Kategoriename|' ;
  346. // run through the payment method titles to display them in the header
  347. foreach($this->payment as $payment => $options) {
  348. // display only the payment methods that are active (if this is desired)
  349. $schema .= $options['title'] . "|";
  350. }
  351. $schema .= "\n";
  352. $export_query =xtc_db_query("SELECT
  353. p.products_id,
  354. pd.products_name,
  355. pd.products_description,
  356. pd.products_short_description,
  357. p.products_weight,
  358. p.products_ean,
  359. p.products_quantity,
  360. p.products_model,
  361. p.products_shippingtime,
  362. p.products_image,
  363. p.products_price,
  364. p.products_status,
  365. p.products_discount_allowed,
  366. p.products_tax_class_id,
  367. IF(s.status, s.specials_new_products_price, NULL) AS specials_new_products_price,
  368. p.products_date_added,
  369. m.manufacturers_name
  370. FROM
  371. " . TABLE_PRODUCTS . " p LEFT JOIN
  372. " . TABLE_MANUFACTURERS . " m
  373. ON p.manufacturers_id = m.manufacturers_id LEFT JOIN
  374. " . TABLE_PRODUCTS_DESCRIPTION . " pd
  375. ON p.products_id = pd.products_id AND
  376. pd.language_id = '".$_SESSION['languages_id']."' LEFT JOIN
  377. " . TABLE_SPECIALS . " s
  378. ON p.products_id = s.products_id
  379. WHERE
  380. p.products_status = 1
  381. ORDER BY
  382. p.products_date_added DESC,
  383. pd.products_name");
  384. while ($products = xtc_db_fetch_array($export_query)) {
  385. $products_price = $xtPrice->xtcGetPrice($products['products_id'],
  386. $format=false,
  387. 1,
  388. $products['products_tax_class_id'],
  389. '');
  390. // get product categorie
  391. $categorie_query=xtc_db_query("SELECT
  392. categories_id
  393. FROM ".TABLE_PRODUCTS_TO_CATEGORIES."
  394. WHERE products_id='".$products['products_id']."'");
  395. while ($categorie_data=xtc_db_fetch_array($categorie_query)) {
  396. $categories=$categorie_data['categories_id'];
  397. }
  398. // remove trash in $products_description
  399. $products_description = strip_tags($products['products_description']);
  400. $products_description = str_replace(";",", ",$products_description);
  401. $products_description = str_replace("'",", ",$products_description);
  402. $products_description = str_replace("\n"," ",$products_description);
  403. $products_description = str_replace("\r"," ",$products_description);
  404. $products_description = str_replace("\t"," ",$products_description);
  405. $products_description = str_replace("\v"," ",$products_description);
  406. $products_description = str_replace("&quot,"," \"",$products_description);
  407. $products_description = str_replace("&qout,"," \"",$products_description);
  408. $products_description = str_replace("|",",",$products_description);
  409. $products_description = substr($products_description, 0, 253);
  410. // remove trash in $products_short_description
  411. $products_short_description = strip_tags($products['products_short_description']);
  412. $products_short_description = str_replace(";",", ",$products_short_description);
  413. $products_short_description = str_replace("'",", ",$products_short_description);
  414. $products_short_description = str_replace("\n"," ",$products_short_description);
  415. $products_short_description = str_replace("\r"," ",$products_short_description);
  416. $products_short_description = str_replace("\t"," ",$products_short_description);
  417. $products_short_description = str_replace("\v"," ",$products_short_description);
  418. $products_short_description = str_replace("&quot,"," \"",$products_short_description);
  419. $products_short_description = str_replace("&qout,"," \"",$products_short_description);
  420. $products_short_description = str_replace("|",",",$products_short_description);
  421. $products_short_description = substr($products_short_description, 0, 253);
  422. $cat = $this->buildCAT($categories);
  423. // creates pathes of images, if images are integrated
  424. if ($products['products_image'] != '')
  425. {
  426. $image_if_available = HTTP_CATALOG_SERVER . DIR_WS_CATALOG_ORIGINAL_IMAGES .$products['products_image'];
  427. }
  428. else
  429. {
  430. $image_if_available = '';
  431. }
  432. //create content
  433. $schema .= $products['products_id'] .'|'.
  434. number_format($products['products_weight'],2,',','.') .'|' .
  435. $products['products_ean'] .'|' .
  436. $products['products_quantity'] .'|' .
  437. $products['manufacturers_name'] .'|'.
  438. $products['products_name'] .'|' .
  439. $products['products_model'] . '|' .
  440. number_format($products_price,2,',','.'). '|' .
  441. $products_description .'|'.
  442. $products_short_description .'|'.
  443. xtc_get_shipping_status_name($products['products_shippingtime']). '|' .
  444. HTTP_CATALOG_SERVER . DIR_WS_CATALOG . 'product_info.php?'.$_POST['campaign']. $gtgoogle_link .xtc_product_link($products['products_id'], $products['products_name']). '|' .
  445. $image_if_available . '|' .
  446. substr($cat,0,strlen($cat)-2) ."|";
  447. foreach($this->payment as $singlePayment => $options) {
  448. // display only the payment fee that is active (if this is desired)
  449. $sc = $this->getShippingCosts($singlePayment, $products_price, $products['products_weight'],$products['products_tax_class_id']);
  450. $schema .= $sc . "|";
  451. // if there's one payment with sc > 0.00, display the sc free comment
  452. // exception: cash on delivery
  453. if( $singlePayment != 'COD' && $sc > 0.00 ) {
  454. $showScFreeComment = true;
  455. }
  456. }
  457. $schema .= "\n";
  458. }
  459. // create File
  460. $fp = fopen(DIR_FS_DOCUMENT_ROOT.'export/' . $file, "w+");
  461. fputs($fp, $schema);
  462. fclose($fp);
  463. switch ($_POST['export']) {
  464. case 'yes':
  465. // send File to Browser
  466. $extension = substr($file, -3);
  467. $fp = fopen(DIR_FS_DOCUMENT_ROOT.'export/' . $file,"rb");
  468. $buffer = fread($fp, filesize(DIR_FS_DOCUMENT_ROOT.'export/' . $file));
  469. fclose($fp);
  470. header('Content-type: application/x-octet-stream');
  471. header('Content-disposition: attachment; filename=' . $file);
  472. echo $buffer;
  473. exit;
  474. break;
  475. }
  476. }
  477. function getShippingCosts($payment, $price = null, $offerWeight = null, $taxClass = -1) {
  478. $shippingCost = '';
  479. // is the is payment active?
  480. if( $this->payment[$payment]['active'] === true ) {
  481. // is free delivery active and price equal or higher than the limit?
  482. if(($this->freeShipping) === true && ($price >= $this->freeShippingValue)) {
  483. $shippingCost = 0.00;
  484. }
  485. elseif (($this->shipping_free_shipping > 0) && ($price > $this->shipping_free_shipping)) {
  486. $shippingCost = 0.00;
  487. }
  488. // is at least one shipping option active?
  489. elseif(($this->paymentTable === true) || ($this->paymentItem === true) || ($this->paymentFlat === true) ) {
  490. // first of all we get the standard shipping costs (default sc, per item or table)
  491. // are the table shipping costs active? Check which table payment option is active
  492. if($this->paymentTable === true) {
  493. // run through the table values and check which weight / price matches the offer
  494. switch($this->paymentTableMode) {
  495. case 'weight':
  496. $offerCompareValue = $offerWeight;
  497. break;
  498. case 'price':
  499. $offerCompareValue = $price;
  500. break;
  501. }
  502. if(is_array($this->paymentTableValues) && $offerCompareValue != null) {
  503. foreach($this->paymentTableValues as $tableModeValue => $tablePrice) {
  504. // stop the loop if sth. matched
  505. if($offerCompareValue <= $tableModeValue) {
  506. $shippingCost = $tablePrice;
  507. break;
  508. }
  509. }
  510. // If no weight / price was matched accordingly, the last entry in the array is taken
  511. if($shippingCost == '') {
  512. end($this->paymentTableValues); // Zeiger an letzte Stelle bewegen
  513. $shippingCost = current($this->paymentTableValues); // Wert ausgeben auf den der Zeiger aktuell zeigt
  514. reset($this->paymentTableValues); // Setze Zeiger wieder in Ausgangsposition
  515. }
  516. } else {
  517. // if the table sc values are not correct or the weight / price is null => nothing shall appear in the csv
  518. $shippingCost = '';
  519. }
  520. } else {
  521. $shippingCost = $this->standardShippingCost;
  522. }
  523. }
  524. // calculate taxes
  525. if ($this->shippingtax > 0) {
  526. $tax = $this->TAX[$this->shippingtax];
  527. $shippingCost = xtc_add_tax($shippingCost, $tax);
  528. }
  529. // cod needs additional calculation
  530. // the additional cod_fee (if active) depends on the shipping option that is active as the fee can differ
  531. if($payment == 'COD') {
  532. // check if extra fee for "Cash on Delivery" is active
  533. // 1. get the db data
  534. $getCodExtraFeeStatus = xtc_db_query("SELECT `configuration_value` AS `cod_fee_status`
  535. FROM `configuration`
  536. WHERE `configuration_key` LIKE 'MODULE_ORDER_TOTAL_COD_FEE_STATUS';");
  537. $result = array();
  538. $result = xtc_db_fetch_array($getCodExtraFeeStatus);
  539. // 2. is the fee status active?
  540. if(isset($result['cod_fee_status']) && $result['cod_fee_status'] == 'true') {
  541. $modul = '';
  542. // which shipping option is active?
  543. if(($this->freeShipping) === true && ($price >= $this->freeShippingValue)) {
  544. $modul = 'MODULE_ORDER_TOTAL_FREEAMOUNT_FREE';
  545. } elseif($this->paymentTable === true) {
  546. $modul = 'MODULE_ORDER_TOTAL_COD_FEE_TABLE';
  547. } elseif($this->paymentItem === true) {
  548. $modul = 'MODULE_ORDER_TOTAL_COD_FEE_ITEM';
  549. } elseif($this->paymentFlat === true) {
  550. $modul = 'MODULE_ORDER_TOTAL_COD_FEE_FLAT';
  551. }
  552. $getCodCost = xtc_db_query("SELECT `configuration_value` AS `cod_cost`
  553. FROM `configuration`
  554. WHERE `configuration_key` LIKE '{$modul}';");
  555. unset($result);
  556. $result = array();
  557. $result = xtc_db_fetch_array($getCodCost);
  558. // Are there any costs?
  559. if(isset($result['cod_cost']) && $result['cod_cost'] != '') {
  560. // get the value for the country
  561. preg_match_all('/DE:([^,]+)?/', $result['cod_cost'], $match);
  562. // $match[1][0] contains the result in the form of (e.g.) 7.00 or 7
  563. // to make sure that mistakes like 7.00:9.99 (correct would be 7,00:9.99) are also handled, we check for the colon
  564. if(preg_match('/:/', $match[1][0])) {
  565. $tmpArr = explode(':', $match[1][0]);
  566. $codCost = $tmpArr[0];
  567. } else {
  568. $codCost = $match[1][0];
  569. }
  570. // de we ge a useful value?
  571. if(isset($codCost) && $codCost != NULL && is_numeric($codCost)) {
  572. // calculate taxes
  573. if ($this->shippingtaxcod > 0) {
  574. $tax = $this->TAX[$this->shippingtaxcod];
  575. $codCost = xtc_add_tax($codCost, $tax);
  576. }
  577. $shippingCost += $codCost;
  578. }
  579. }
  580. }
  581. }
  582. // format and round numbers
  583. $shippingCost = number_format($shippingCost, 2, ',', '.');
  584. }
  585. return $shippingCost;
  586. }
  587. function buildCAT($catID)
  588. {
  589. if (isset($this->CAT[$catID]))
  590. {
  591. return $this->CAT[$catID];
  592. } else {
  593. $cat=array();
  594. $tmpID=$catID;
  595. while ($this->getParent($catID)!=0 || $catID!=0)
  596. {
  597. $cat_select=xtc_db_query("SELECT categories_name FROM ".TABLE_CATEGORIES_DESCRIPTION." WHERE categories_id='".$catID."' and language_id='".$_SESSION['languages_id']."'");
  598. $cat_data=xtc_db_fetch_array($cat_select);
  599. $catID=$this->getParent($catID);
  600. $cat[]=$cat_data['categories_name'];
  601. }
  602. $catStr='';
  603. for ($i=count($cat);$i>0;$i--)
  604. {
  605. $catStr.=$cat[$i-1].' > ';
  606. }
  607. $this->CAT[$tmpID]=$catStr;
  608. return $this->CAT[$tmpID];
  609. }
  610. }
  611. function getParent($catID)
  612. {
  613. if (isset($this->PARENT[$catID]))
  614. {
  615. return $this->PARENT[$catID];
  616. } else {
  617. $parent_query=xtc_db_query("SELECT parent_id FROM ".TABLE_CATEGORIES." WHERE categories_id='".$catID."'");
  618. $parent_data=xtc_db_fetch_array($parent_query);
  619. $this->PARENT[$catID]=$parent_data['parent_id'];
  620. return $parent_data['parent_id'];
  621. }
  622. }
  623. function display() {
  624. global $UseGoogle;
  625. $campaign_array = array(array('id' => '', 'text' => TEXT_NONE));
  626. $campaign_query = xtc_db_query("select campaigns_name, campaigns_refID from ".TABLE_CAMPAIGNS." order by campaigns_id");
  627. $PSMFound = false;
  628. while ($campaign = xtc_db_fetch_array($campaign_query)) {
  629. $campaign_array[] = array ('id' => 'refID='.$campaign['campaigns_refID'].'&', 'text' => $campaign['campaigns_name'],);
  630. $PSMFound |= $campaign['campaigns_refID']=="psm";
  631. }
  632. if (!$PSMFound) {
  633. xtc_db_query("INSERT INTO ".TABLE_CAMPAIGNS." VALUES (NULL, 'Preissuchmaschine (automatisch)', 'psm', '0', NOW(), NOW())");
  634. $campaign_array[] = array ('id' => 'refID=psm&', 'text' => "Preissuchmaschine (automatisch)",);
  635. }
  636. return array('text' => '<br>' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG . MODULE_GUENSTIGER_EXPORT_LINK . MODULE_GUENSTIGER_FILE . '<br><br>' . MODULE_GUENSTIGER_EXPORT_LINK_SEND .
  637. MODULE_GUENSTIGER_CAMPAIGNS.'<br>'.
  638. MODULE_GUENSTIGER_CAMPAIGNS_DESC.
  639. xtc_draw_pull_down_menu('campaign',$campaign_array, 'refID=psm&').'<br>'.
  640. MODULE_GUENSTIGER_GTGOOGLEHeader.'<br>'.
  641. MODULE_GUENSTIGER_GTGOOGLE_DESC.'<br>'.
  642. xtc_draw_radio_field('gtgoogle', 'no',!$UseGoogle).MODULE_GUENSTIGER_GTGOOGLE_NO.'<br>'.
  643. xtc_draw_radio_field('gtgoogle', 'yes',$UseGoogle).MODULE_GUENSTIGER_GTGOOGLE_YES.'<br><br>'.
  644. MODULE_GUENSTIGER_EXPORT_TYPE.'<br>'.
  645. MODULE_GUENSTIGER_EXPORT.'<br>'.
  646. xtc_draw_radio_field('export', 'no',true).MODULE_GUENSTIGER_EXPORT_NO.'<br>'.
  647. xtc_draw_radio_field('export', 'yes',false).MODULE_GUENSTIGER_EXPORT_YES.'<br><br>' . xtc_button(BUTTON_EXPORT) .
  648. xtc_button_link(BUTTON_CANCEL, xtc_href_link(FILENAME_MODULE_EXPORT, 'set=' . $_GET['set'] . '&module=preissuchmaschine')));
  649. }
  650. function check() {
  651. if (!isset($this->_check)) {
  652. $check_query = xtc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_GUENSTIGER_STATUS'");
  653. $this->_check = xtc_db_num_rows($check_query);
  654. }
  655. return $this->_check;
  656. }
  657. function install() {
  658. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_GUENSTIGER_FILE', 'preissuchmaschine.csv', '6', '1', '', now())");
  659. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_GUENSTIGER_STATUS', 'True', '6', '1', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  660. }
  661. function remove() {
  662. xtc_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  663. }
  664. function keys() {
  665. return array('MODULE_GUENSTIGER_STATUS', 'MODULE_GUENSTIGER_FILE');
  666. }
  667. }
  668. ?>