PageRenderTime 61ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-shopping-cart/submit_checkout_function.php

https://github.com/alx/barceloneta
PHP | 501 lines | 346 code | 57 blank | 98 comment | 107 complexity | 3a9bdd85fb685cda32a52fc7359da785 MD5 | raw file
  1. <?php
  2. function nzshpcrt_submit_checkout() {
  3. /*
  4. * This is the function used for handling the submitted checkout page
  5. */
  6. global $wpdb, $nzshpcrt_gateways, $user_ID;
  7. session_start();
  8. if(get_option('permalink_structure') != '') {
  9. $seperator ="?";
  10. } else {
  11. $seperator ="&";
  12. }
  13. if(($_POST['submitwpcheckout'] == 'true')) {
  14. $check_checkout_page = $wpdb->get_var("SELECT `id` FROM `".$wpdb->posts."` WHERE `post_content` LIKE '%[checkout]%' LIMIT 1");
  15. if(is_numeric($check_checkout_page)) {
  16. $returnurl = "Location: ".get_option('shopping_cart_url').$seperator."total=".$_GET['total'];
  17. } else {
  18. $returnurl = "Location: ".get_option('shopping_cart_url');
  19. }
  20. $_SESSION['collected_data'] = $_POST['collected_data'];
  21. $find_us = $_POST['how_find_us'];
  22. if(!(($_POST['engrave1'] == '') && ($_POST['engrave2'] == ''))) {
  23. $engrave = $wpdb->escape($_POST['engrave1'].",".$_POST['engrave2']);
  24. }
  25. $any_bad_inputs = false;
  26. foreach($_POST['collected_data'] as $value_id => $value) {
  27. $form_sql = "SELECT * FROM `".$wpdb->prefix."collect_data_forms` WHERE `id` = '$value_id' LIMIT 1";
  28. $form_data = $wpdb->get_results($form_sql,ARRAY_A);
  29. $form_data = $form_data[0];
  30. /*
  31. if($_POST['collected_data'][get_option('paypal_form_address')] != '')
  32. {
  33. $map_data['address'] = addslashes($_POST['collected_data'][get_option('paypal_form_address')]);
  34. }
  35. if($_POST['collected_data'][get_option('paypal_form_city')] != '')
  36. {
  37. $map_data['city'] = addslashes($_POST['collected_data'][get_option('paypal_form_city')]);
  38. }
  39. if(preg_match("/^[a-zA-Z]{2}$/",$_SESSION['selected_country']))
  40. {
  41. $map_data['country'] = $_SESSION['selected_country'];
  42. }
  43. $map_data['zipcode']='';
  44. $map_data['radius'] = '50000';
  45. $map_data['state'] = '';
  46. $map_data['submit'] = 'Find Store';
  47. $i=0;
  48. if (function_exists('getdistance')) {
  49. $maps = getdistance($map_data);
  50. while($rows = mysql_fetch_array($maps)) {
  51. if ($i==0) {
  52. $closest_store = $rows[5];
  53. }
  54. $i++;
  55. }
  56. }
  57. //$wpdb->query("UPDATE `".$wpdb->prefix."purchase_logs` SET `closest_store` = '".$closest_store."' WHERE `id` = '".$log_id."' LIMIT 1 ;");
  58. */
  59. $bad_input = false;
  60. if(($form_data['mandatory'] == 1) || ($form_data['type'] == "coupon")) {
  61. switch($form_data['type']) {
  62. case "email":
  63. if(!preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\.[a-zA-Z]{2,5}$/",$value)) {
  64. $any_bad_inputs = true;
  65. $bad_input = true;
  66. }
  67. break;
  68. case "delivery_country":
  69. break;
  70. case "country":
  71. break;
  72. default:
  73. if($value == null) {
  74. $any_bad_inputs = true;
  75. $bad_input = true;
  76. }
  77. break;
  78. }
  79. /*
  80. if($form_data['type'] == "coupon") {
  81. if($value != '') { // only act if data has been entered
  82. $coupon_sql = "SELECT * FROM `".$wpdb->prefix."wpsc_coupon_codes` WHERE `coupon_code` = '".$value."' AND `active` = '1' LIMIT 1";
  83. $coupon_data = $wpdb->get_results($coupon_sql,ARRAY_A);
  84. if($coupon_data == null) {
  85. $any_bad_inputs = true;
  86. $bad_input = true;
  87. }
  88. }
  89. }
  90. */
  91. if($bad_input === true) {
  92. switch($form_data['name']) {
  93. case TXT_WPSC_FIRSTNAME:
  94. $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDNAME . "";
  95. break;
  96. case TXT_WPSC_LASTNAME:
  97. $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDSURNAME . "";
  98. break;
  99. case TXT_WPSC_EMAIL:
  100. $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDEMAILADDRESS . "";
  101. break;
  102. case TXT_WPSC_ADDRESS1:
  103. case TXT_WPSC_ADDRESS2:
  104. $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDADDRESS . "";
  105. break;
  106. case TXT_WPSC_CITY:
  107. $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDCITY . "";
  108. break;
  109. case TXT_WPSC_PHONE:
  110. $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDPHONENUMBER . "";
  111. break;
  112. case TXT_WPSC_COUNTRY:
  113. $bad_input_message .= TXT_WPSC_PLEASESELECTCOUNTRY . "";
  114. break;
  115. // case TXT_WPSC_COUPON:
  116. // $bad_input_message .= TXT_WPSC_COUPON_DOESNT_EXIST . "";
  117. // break;
  118. default:
  119. $bad_input_message .= TXT_WPSC_PLEASEENTERAVALID . " " . strtolower($form_data['name']) . ".";
  120. break;
  121. }
  122. $bad_input_message .= "\n\r";
  123. }
  124. }
  125. }
  126. // this here section handles uploading files specified by the user for products
  127. $accepted_file_types['mime'][] = 'image/jpeg';
  128. $accepted_file_types['mime'][] = 'image/gif';
  129. $accepted_file_types['mime'][] = 'image/png';
  130. $accepted_file_types['ext'][] = 'jpeg';
  131. $accepted_file_types['ext'][] = 'jpg';
  132. $accepted_file_types['ext'][] = 'gif';
  133. $accepted_file_types['ext'][] = 'png';
  134. foreach($_SESSION['nzshpcrt_cart'] as $key => $item) {
  135. $can_have_uploaded_image = get_product_meta($item->product_id,'can_have_uploaded_image',true);
  136. if ($can_have_uploaded_image[0]=='on') {
  137. $file_data['name'] = basename($_FILES['uploaded_image']['name'][$key]);
  138. $file_data['type'] = $_FILES['uploaded_image']['type'][$key];
  139. $file_data['tmp_name'] = $_FILES['uploaded_image']['tmp_name'][$key];
  140. $file_data['error'] = $_FILES['uploaded_image']['error'][$key];
  141. $file_data['size'] = $_FILES['uploaded_image']['size'][$key];
  142. $mime_type_data = wpsc_get_mimetype($file_data['tmp_name'], true);
  143. $name_parts = explode('.',basename($file_data['name']));
  144. $extension = array_pop($name_parts);
  145. echo $extension ."<br />";
  146. if($mime_type_data['is_reliable'] == true) {
  147. $mime_type = $mime_type_data['mime_type'];
  148. } else {
  149. // if we can't use what PHP provides us with, we have to trust the user as there aren't really any other choices.
  150. $mime_type = $file_data['type'];
  151. }
  152. if((array_search($mime_type, $accepted_file_types['mime']) !== false) && (array_search($extension, $accepted_file_types['ext']) !== false) ) {
  153. if(is_file(WPSC_USER_UPLOADS_DIR.$file_data['name'])) {
  154. $name_parts = explode('.',basename($file_data['name']));
  155. $extension = array_pop($name_parts);
  156. $name_base = implode('.',$name_parts);
  157. $file_data['name'] = null;
  158. $num = 2;
  159. // loop till we find a free file name, first time I get to do a do loop in yonks
  160. do {
  161. $test_name = "{$name_base}-{$num}.{$extension}";
  162. if(!file_exists(WPSC_USER_UPLOADS_DIR.$test_name)) {
  163. $file_data['name'] = $test_name;
  164. }
  165. $num++;
  166. } while ($file_data['name'] == null);
  167. }
  168. //exit($file_data['name']);
  169. if(move_uploaded_file($file_data['tmp_name'], WPSC_USER_UPLOADS_DIR.$file_data['name']) ) {
  170. $_SESSION['nzshpcrt_cart'][$key]->file_data = array('file_name' => $file_data['name'], 'mime_type' => $mime_type );
  171. }
  172. }
  173. }
  174. }
  175. //echo("<pre>".print_r($_FILES,true)."</pre>");
  176. //exit("<pre>".print_r($_SESSION['nzshpcrt_cart'],true)."</pre>");
  177. foreach((array)$_SESSION['nzshpcrt_cart'] as $item) {
  178. //exit("------><pre>".print_r((array)$_SESSION['nzshpcrt_cart'],1)."</pre>");
  179. $in_stock = check_in_stock($item->product_id, $item->product_variations, $item->quantity);
  180. if (get_option('checkbox_variation')=='1') {
  181. $in_stock = true;
  182. }
  183. if($in_stock == false) {
  184. $bad_input_message .= TXT_WPSC_ITEM_GONE_OUT_OF_STOCK . "";
  185. $bad_input_message .= "\n\r";
  186. $any_bad_inputs = true;
  187. break;
  188. }
  189. }
  190. if(get_option('custom_gateway_options') == null) {
  191. $bad_input_message .= TXT_WPSC_PROCESSING_PROBLEM . "";
  192. $bad_input_message .= "\n\r";
  193. $any_bad_inputs = true;
  194. }
  195. list($bad_input_message, $any_bad_inputs) = apply_filters('wpsc_additional_checkout_checks', array($bad_input_message, $any_bad_inputs));
  196. //exit("<pre>".print_r($bad_input_message, true)."</pre>");
  197. if($any_bad_inputs === true) {
  198. $_SESSION['nzshpcrt_checkouterr'] = nl2br($bad_input_message);
  199. header($returnurl);
  200. exit();
  201. }
  202. $cart = $_SESSION['nzshpcrt_cart'];
  203. $_SESSION['checkoutdata'] = $_POST;
  204. if($_POST['agree'] != 'yes') {
  205. $_SESSION['nzshpcrt_checkouterr'] = TXT_WPSC_PLEASEAGREETERMSANDCONDITIONS;
  206. header($returnurl);
  207. exit();
  208. }
  209. if($cart == null) {
  210. $_SESSION['nzshpcrt_checkouterr'] = TXT_WPSC_NOTHINGINYOURSHOPPINGCART;
  211. header($returnurl);
  212. exit();
  213. }
  214. $sessionid = (mt_rand(100,999).time());
  215. if( !(is_numeric($user_ID) && ($user_ID > 0))) {
  216. $user_ID = 'null';
  217. }
  218. if(isset($_SESSION['usps_shipping']) && is_numeric($_SESSION['usps_shipping'])) {
  219. $base_shipping = $_SESSION['usps_shipping'];
  220. } else {
  221. $base_shipping = nzshpcrt_determine_base_shipping(0, $_SESSION['delivery_country']);
  222. }
  223. //clear the coupon
  224. //$_SESSION['coupon_num'] = '';
  225. //insert the record into the purchase log table
  226. //exit("----->". $_SESSION['delivery_country']);
  227. $price = nzshpcrt_overall_total_price($_SESSION['selected_country'],false);
  228. $sql = "INSERT INTO `".$wpdb->prefix."purchase_logs` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`base_shipping`,`shipping_region`, `user_ID`, `discount_value`, `discount_data`, `find_us`, `engravetext`, `google_status`) VALUES ( '".$wpdb->escape($price)."', '".$sessionid."', '".time()."', '".$_SESSION['selected_country']."', '".$_SESSION['delivery_country']."', '".$base_shipping."','".$_SESSION['selected_region']."' , '".(int)$user_ID."' , '".(float)$_SESSION['wpsc_discount']."', '".$wpdb->escape($_SESSION['coupon_num'])."', '', '{$engrave}', ' ')";
  229. //exit($sql);
  230. $wpdb->query($sql) ;
  231. $email_user_detail = '';
  232. $log_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."purchase_logs` WHERE `sessionid` IN('".$sessionid."') LIMIT 1") ;
  233. foreach($_POST['collected_data'] as $value_id => $value) {
  234. $wpdb->query("INSERT INTO `".$wpdb->prefix."submited_form_data` ( `log_id` , `form_id` , `value` ) VALUES ( '".$log_id."', '".$value_id."', '".$value."');") ;
  235. }
  236. if(function_exists("nzshpcrt_user_log")) {
  237. if($wpdb->get_var("SHOW TABLES LIKE '".$wpdb->prefix."usermeta'")) {
  238. $saved_data_sql = "SELECT * FROM `".$wpdb->prefix."usermeta` WHERE `user_id` = '".$user_ID."' AND `meta_key` = 'wpshpcrt_usr_profile';";
  239. $saved_data = $wpdb->get_row($saved_data_sql,ARRAY_A);
  240. $new_meta_data = serialize($_POST['collected_data']);
  241. if(($saved_data != null)) {
  242. $wpdb->query("UPDATE `".$wpdb->prefix."usermeta` SET `meta_value` = '$new_meta_data' WHERE `user_id` IN ('$user_ID') AND `meta_key` IN ('wpshpcrt_usr_profile');");
  243. } else if(is_numeric($user_ID)) {
  244. $wpdb->query("INSERT INTO `".$wpdb->prefix."usermeta` ( `user_id` , `meta_key` , `meta_value` ) VALUES ( ".$user_ID.", 'wpshpcrt_usr_profile', '$new_meta_data');");
  245. }
  246. }
  247. }
  248. $downloads = get_option('max_downloads');
  249. $also_bought = array();
  250. $all_donations = true;
  251. $all_no_shipping = true;
  252. foreach($cart as $cart_item) {
  253. $row = $cart_item->product_id;
  254. $quantity = $cart_item->quantity;
  255. $variations = $cart_item->product_variations;
  256. $extras = $cart_item->extras;
  257. // serialize file data
  258. if(is_array($cart_item->file_data)) {
  259. $file_data = $wpdb->escape(serialize($cart_item->file_data));
  260. } else {
  261. $file_data = '';
  262. }
  263. /* creates an array of purchased items for logging further on */
  264. if(isset($also_bought[$cart_item->product_id])) {
  265. $also_bought[$cart_item->product_id]++;
  266. } else {
  267. $also_bought[$cart_item->product_id] = 1;
  268. }
  269. $product_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id` = '$row' LIMIT 1",ARRAY_A) ;
  270. if($product_data['file'] > 0) {
  271. $unique_id = sha1(uniqid(mt_rand(), true));
  272. $wpdb->query("INSERT INTO `".$wpdb->prefix."download_status` ( `fileid` , `purchid` , `uniqueid`, `downloads` , `active` , `datetime` ) VALUES ( '".$product_data['file']."', '".$log_id."', '".$unique_id."', '$downloads', '0', NOW( ));");
  273. }
  274. if($product_data['donation'] == 1) {
  275. $price = $cart_item->donation_price;
  276. $gst = 0;
  277. $donation = 1;
  278. } else {
  279. $price = calculate_product_price($row, $variations);
  280. if($product_data['notax'] != 1) {
  281. $price = nzshpcrt_calculate_tax($price, $_SESSION['selected_country'], $_SESSION['selected_region']);
  282. if(get_option('base_country') == $_SESSION['selected_country']) {
  283. $country_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."currency_list` WHERE `isocode` IN('".get_option('base_country')."') LIMIT 1",ARRAY_A);
  284. if(($country_data['has_regions'] == 1)) {
  285. if(get_option('base_region') == $_SESSION['selected_region']) {
  286. $region_data = $wpdb->get_row("SELECT `".$wpdb->prefix."region_tax`.* FROM `".$wpdb->prefix."region_tax` WHERE `".$wpdb->prefix."region_tax`.`country_id` IN('".$country_data['id']."') AND `".$wpdb->prefix."region_tax`.`id` IN('".get_option('base_region')."') ",ARRAY_A) ;
  287. }
  288. $gst = $region_data['tax'];
  289. } else {
  290. $gst = $country_data['tax'];
  291. }
  292. }
  293. } else { $gst = 0; }
  294. $donation = 0;
  295. $all_donations = false;
  296. }
  297. if($product_data['no_shipping'] != 1) {
  298. $all_no_shipping = false;
  299. }
  300. $country = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."submited_form_data` WHERE `log_id`='".$log_id."' AND `form_id` = '".get_option('country_form_field')."' LIMIT 1",ARRAY_A);
  301. $country = $country[0]['value'];
  302. $country_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."currency_list` WHERE `isocode` IN('".get_option('base_country')."') LIMIT 1",ARRAY_A);
  303. $shipping = nzshpcrt_determine_item_shipping($row, 1, $_SESSION['delivery_country']);
  304. $cartsql = "INSERT INTO `".$wpdb->prefix."cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping`, `files` ) VALUES ('".$row."', '".$log_id."','".$price."','".$shipping."', '".$gst."','".$quantity."', '".$donation."', '".$product_data['no_shipping']."', '$file_data')";
  305. //exit($cartsql);
  306. $wpdb->query($cartsql);
  307. $cart_id = $wpdb->get_results("SELECT LAST_INSERT_ID() AS `id` FROM `".$wpdb->prefix."product_variations` LIMIT 1",ARRAY_A);
  308. $cart_id = $cart_id[0]['id'];
  309. $extra_var='';
  310. if($variations != null) {
  311. $extra_var.='[';
  312. $i=0;
  313. foreach($variations as $variation => $value) {
  314. $wpdb->query("INSERT INTO `".$wpdb->prefix."cart_item_variations` ( `cart_id` , `variation_id` , `value_id` ) VALUES ( '".$cart_id."', '".$variation."', '".$value."' );");
  315. $i++;
  316. if ($i==1) {
  317. $extra_var.=$value;
  318. } else {
  319. $extra_var.=",".$value;
  320. }
  321. }
  322. }
  323. $j=0;
  324. $extra_var.='],[';
  325. if($extras != null) {
  326. foreach($extras as $extra) {
  327. $wpdb->query("INSERT INTO `".$wpdb->prefix."cart_item_extras` ( `cart_id` , `extra_id`) VALUES ( '".$cart_id."', '".$extra."');");
  328. $name = $wpdb->get_var("SELECT name FROM ".$wpdb->prefix."extras_values WHERE id=$extra");
  329. $j++;
  330. if ($j==1) {
  331. $extra_var.=$name;
  332. } else {
  333. $extra_var.=",".$name;
  334. }
  335. }
  336. $extra_var.=']';
  337. }
  338. /*
  339. if (function_exists('sendemailstostores')) {
  340. if ($_POST['pickupordelivery']==1){
  341. $delivery = "Pick Up";
  342. } else {
  343. $delivery = "Delivery";
  344. }
  345. $chosen_store = $_POST['chosen_store'];
  346. $email_sql = "SELECT * FROM locations WHERE storename='".$chosen_store."'";
  347. $email_data = $wpdb->get_results($email_sql,ARRAY_A);
  348. $email_message = "Order: ".$product_data['name']." with additional variations : ".$extra_var."<br>";
  349. $email_message .= "<br>";
  350. $email_message .= "Delivery/Pick Up:".$delivery;
  351. $email_message .= "<br>";
  352. $email_message .= "Customer detail: <br>";
  353. $email_message .= "Name:". $_POST['collected_data'][get_option('paypal_form_first_name')]." ".$_POST['collected_data'][get_option('paypal_form_last_name')]."<br>";
  354. $email_message .= "Address: ".$map_data['address']."<br>";
  355. $email_message .= "City:".$map_data['city'];
  356. sendemailstostores($email_data[0]['url'],'New Order',$email_message);
  357. }*/
  358. /*
  359. * This code decrements the stock quantitycart_item_variations`
  360. */
  361. if(is_array($variations)) {
  362. $variation_values = array_values($variations);
  363. }
  364. //$debug .= "<pre>".print_r($variations,true)."</pre>";
  365. if($product_data['quantity_limited'] == 1) {
  366. switch(count($variation_values)) {
  367. case 2:
  368. $variation_stock_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."variation_priceandstock` WHERE `product_id` = '".$product_data['id']."' AND (`variation_id_1` = '".$variation_values[0]."' AND `variation_id_2` = '".$variation_data[1]."') OR (`variation_id_1` = '".$variation_values[1]."' AND `variation_id_2` = '".$variation_values[0]."') LIMIT 1",ARRAY_A);
  369. //$debug .= "<pre>".print_r($variation_stock_data,true)."</pre>";
  370. $wpdb->query("UPDATE `".$wpdb->prefix."variation_priceandstock` SET `stock` = '".($variation_stock_data['stock']-$quantity)."' WHERE `id` = '".$variation_stock_data['id']."' LIMIT 1",ARRAY_A);
  371. break;
  372. case 1:
  373. $variation_stock_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."variation_priceandstock` WHERE `product_id` = '".$product_data['id']."' AND (`variation_id_1` = '".$variation_values[0]."' AND `variation_id_2` = '0') LIMIT 1",ARRAY_A);
  374. //$debug .= "<pre>".print_r($variation_stock_data,true)."</pre>";
  375. $wpdb->query("UPDATE `".$wpdb->prefix."variation_priceandstock` SET `stock` = '".($variation_stock_data['stock']-$quantity)."' WHERE `id` = '".$variation_stock_data['id']."' LIMIT 1",ARRAY_A);
  376. break;
  377. default:
  378. /* normal form of decrementing stock */
  379. $wpdb->query("UPDATE `".$wpdb->prefix."product_list` SET `quantity`='".($product_data['quantity']-$quantity)."' WHERE `id`='".$product_data['id']."' LIMIT 1");
  380. break;
  381. }
  382. }
  383. }
  384. $unneeded_value = null; //this is only used to store the quantity for the item we are working on, so that we can get the array key
  385. $assoc_quantity = null;
  386. foreach($also_bought as $selected_product => $unneeded_value) {
  387. foreach($also_bought as $associated_product => $assoc_quantity) {
  388. if(($selected_product == $associated_product)) {
  389. continue; //don't want to associate products with themselves
  390. }
  391. $check_assoc = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."also_bought_product` WHERE `selected_product` IN('$selected_product') AND `associated_product` IN('$associated_product') LIMIT 1");
  392. if(isset($check_assoc) && ($check_assoc > 0)) {
  393. $wpdb->query("UPDATE `".$wpdb->prefix."also_bought_product` SET `quantity` = (`quantity` + $assoc_quantity) WHERE `id` = '$check_assoc' LIMIT 1;");
  394. } else {
  395. $wpdb->query("INSERT INTO `".$wpdb->prefix."also_bought_product` ( `selected_product` , `associated_product` , `quantity` ) VALUES ( '$selected_product', '".$associated_product."', '".$assoc_quantity."' );");
  396. }
  397. }
  398. }
  399. do_action('wpsc_submit_checkout', $log_id);
  400. //mail( get_option('purch_log_email'),('debug from '.date("d/m/Y H:i:s")), $debug);
  401. $curgateway = get_option('payment_gateway');
  402. // if (get_option('custom_gateway')) {
  403. $selected_gateways = get_option('custom_gateway_options');
  404. if(count($selected_gateways) > 1) {
  405. if (in_array($_POST['custom_gateway'], (array)$selected_gateways)) {
  406. $curgateway = $_POST['custom_gateway'];
  407. } else {
  408. $curgateway = get_option('payment_gateway');
  409. }
  410. } else if(count($selected_gateways) == 1) {
  411. $curgateway = array_pop($selected_gateways);
  412. }
  413. //} else {
  414. // $curgateway = get_option('payment_gateway');
  415. //}
  416. if(get_option('permalink_structure') != '') {
  417. $seperator ="?";
  418. } else {
  419. $seperator ="&";
  420. }
  421. if((($_POST['payment_method'] == 2) && (get_option('payment_method') == 2)) || (get_option('payment_method') == 3)) {
  422. foreach($nzshpcrt_gateways as $gateway) {
  423. if($gateway['internalname'] == 'testmode') {
  424. $gateway_used = $gateway['internalname'];
  425. $wpdb->query("UPDATE `".$wpdb->prefix."purchase_logs` SET `gateway` = '".$gateway_used."' WHERE `id` = '".$log_id."' LIMIT 1 ;");
  426. $gateway['function']($seperator, $sessionid);
  427. }
  428. }
  429. } else {
  430. foreach($nzshpcrt_gateways as $gateway) {
  431. if($gateway['internalname'] == $curgateway ) {
  432. $gateway_used = $gateway['internalname'];
  433. $wpdb->query("UPDATE `".$wpdb->prefix."purchase_logs` SET `gateway` = '".$gateway_used."' WHERE `id` = '".$log_id."' LIMIT 1 ;");
  434. $gateway['function']($seperator, $sessionid);
  435. }
  436. }
  437. }
  438. $_SESSION['coupon_num'] = '';
  439. //exit("<pre>".print_r($nzshpcrt_gateways,true)."</pre>");
  440. }
  441. }
  442. ?>