PageRenderTime 60ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/alx/barceloneta
PHP | 2608 lines | 2076 code | 343 blank | 189 comment | 544 complexity | 8aea27015246860d47a4e369a46af1d9 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Plugin Name:WP Shopping Cart
  4. Plugin URI: http://www.instinct.co.nz
  5. Description: A plugin that provides a WordPress Shopping Cart. Contact <a href='http://www.instinct.co.nz/?p=16#support'>Instinct Entertainment</a> for support. <br />Click here to to <a href='?wpsc_uninstall=ask'>Uninstall</a>.
  6. Version: 3.6.8 RC1
  7. Author: Thomas Howard of Instinct Entertainment
  8. Author URI: http://www.instinct.co.nz/e-commerce/
  9. /* Major version for "major" releases */
  10. define('WPSC_VERSION', '3.6');
  11. define('WPSC_MINOR_VERSION', '80');
  12. define('WPSC_PRESENTABLE_VERSION', '3.6.8 RC1');
  13. define('WPSC_DEBUG', false);
  14. /*
  15. * {Notes} Language Files
  16. * {Required} Yes
  17. * {WP-Set} Yes (Admin Panel)
  18. */
  19. define('IS_WP25', version_compare($wp_version, '2.4', '>=') );
  20. // // we need to know where we are, rather than assuming where we are
  21. define('WPSC_FILE_PATH', dirname(__FILE__));
  22. define('WPSC_DIR_NAME', basename(WPSC_FILE_PATH));
  23. $siteurl = get_option('siteurl');
  24. // thanks to ikool for this fix
  25. define('WPSC_FOLDER', dirname(plugin_basename(__FILE__)));
  26. define('WPSC_URL', get_option('siteurl').'/wp-content/plugins/' . WPSC_FOLDER);
  27. //exit("");
  28. if(WPSC_DEBUG === true) {
  29. function microtime_float() {
  30. list($usec, $sec) = explode(" ", microtime());
  31. return ((float)$usec + (float)$sec);
  32. }
  33. function wpsc_debug_start_subtimer($name, $action, $loop = false) {
  34. global $wpsc_debug_sections,$loop_debug_increment;
  35. if($loop === true) {
  36. if ($action == 'start') {
  37. $loop_debug_increment[$name]++;
  38. $wpsc_debug_sections[$name.$loop_debug_increment[$name]][$action] = microtime_float();
  39. } else if($action == 'stop') {
  40. $wpsc_debug_sections[$name.$loop_debug_increment[$name]][$action] = microtime_float();
  41. }
  42. } else {
  43. $wpsc_debug_sections[$name][$action] = microtime_float();
  44. }
  45. }
  46. $wpsc_start_time = microtime_float();
  47. } else {
  48. function wpsc_debug_start_subtimer($name) {
  49. return null;
  50. }
  51. }
  52. if(get_option('language_setting') != '') {
  53. require(WPSC_FILE_PATH.'/languages/'.get_option('language_setting'));
  54. } else {
  55. require(WPSC_FILE_PATH.'/languages/EN_en.php');
  56. }
  57. require(WPSC_FILE_PATH.'/classes/variations.class.php');
  58. require(WPSC_FILE_PATH.'/classes/extra.class.php');
  59. // require(WPSC_FILE_PATH.'/classes/http_client.php');
  60. require(WPSC_FILE_PATH.'/classes/mimetype.php');
  61. require(WPSC_FILE_PATH.'/classes/cart.class.php');
  62. require(WPSC_FILE_PATH.'/classes/xmlparser.php');
  63. if (!IS_WP25) {
  64. require(WPSC_FILE_PATH.'/editor.php');
  65. } else {
  66. require(WPSC_FILE_PATH.'/js/tinymce3/tinymce.php');
  67. }
  68. if(IS_WPMU == 1) {
  69. $upload_url = get_option('siteurl').'/files';
  70. $upload_path = ABSPATH.get_option('upload_path');
  71. } else {
  72. if ( !defined('WP_CONTENT_URL') ) {
  73. define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  74. }
  75. if ( !defined('WP_CONTENT_DIR') ) {
  76. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  77. }
  78. $upload_path = WP_CONTENT_DIR."/uploads";
  79. $upload_url = WP_CONTENT_URL."/uploads";
  80. }
  81. $wpsc_file_dir = "{$upload_path}/wpsc/downloadables/";
  82. $wpsc_preview_dir = "{$upload_path}/wpsc/previews/";
  83. $wpsc_image_dir = "{$upload_path}/wpsc/product_images/";
  84. $wpsc_thumbnail_dir = "{$upload_path}/wpsc/product_images/thumbnails/";
  85. $wpsc_category_dir = "{$upload_path}/wpsc/category_images/";
  86. $wpsc_user_uploads_dir = "{$upload_path}/wpsc/user_uploads/";
  87. // $wpsc_file_dir = ABSPATH."{$upload_path}/files/";
  88. // $wpsc_preview_dir = ABSPATH."{$upload_path}/preview_clips/";
  89. // $wpsc_image_dir = ABSPATH."{$upload_path}/product_images/";
  90. // $wpsc_thumbnail_dir = ABSPATH."{$upload_path}/product_images/thumbnails/";
  91. // $wpsc_category_dir = ABSPATH."{$upload_path}/category_images/";
  92. define('WPSC_FILE_DIR', $wpsc_file_dir);
  93. define('WPSC_PREVIEW_DIR', $wpsc_preview_dir);
  94. define('WPSC_IMAGE_DIR', $wpsc_image_dir);
  95. define('WPSC_THUMBNAIL_DIR', $wpsc_thumbnail_dir);
  96. define('WPSC_CATEGORY_DIR', $wpsc_category_dir);
  97. define('WPSC_USER_UPLOADS_DIR', $wpsc_user_uploads_dir);
  98. /**
  99. * files that are uploaded as part of digital products are not directly downloaded, therefore there is no need for a URL constant for them
  100. */
  101. $wpsc_preview_url = "{$upload_url}/wpsc/previews/";
  102. $wpsc_image_url = "{$upload_url}/wpsc/product_images/";
  103. $wpsc_thumbnail_url = "{$upload_url}/wpsc/product_images/thumbnails/";
  104. $wpsc_category_url = "{$upload_url}/wpsc/category_images/";
  105. $wpsc_user_uploads_url = "{$upload_url}/wpsc/user_uploads/";
  106. // $wpsc_preview_url = "{$siteurl}/{$upload_path}/preview_clips/";
  107. // $wpsc_image_url = "{$siteurl}/{$upload_path}/product_images/";
  108. // $wpsc_thumbnail_url = "{$siteurl}/{$upload_path}/product_images/thumbnails/";
  109. // $wpsc_category_url = "{$siteurl}/{$upload_path}/category_images/";
  110. define('WPSC_PREVIEW_URL', $wpsc_preview_url);
  111. define('WPSC_IMAGE_URL', $wpsc_image_url);
  112. define('WPSC_THUMBNAIL_URL', $wpsc_thumbnail_url);
  113. define('WPSC_CATEGORY_URL', $wpsc_category_url);
  114. define('WPSC_USER_UPLOADS_URL', $wpsc_user_uploads_url);
  115. /*
  116. * {Notes} Session will sometimes always exist dependent on server
  117. * {Notes} Controls user Session
  118. */
  119. if((!is_array($_SESSION)) xor (!isset($_SESSION['nzshpcrt_cart'])) xor (!$_SESSION)) {
  120. session_start();
  121. }
  122. if(isset($_SESSION['nzshpcrt_cart'])) {
  123. foreach((array)$_SESSION['nzshpcrt_cart'] as $key => $item) {
  124. if(get_class($item) == "__PHP_Incomplete_Class") {
  125. $_SESSION['nzshpcrt_cart'] = unserialize($_SESSION['nzshpcrt_serialized_cart']);
  126. }
  127. }
  128. } else {
  129. if(isset($_SESSION['nzshpcrt_cart'])) {
  130. $_SESSION['nzshpcrt_cart'] = unserialize($_SESSION['nzshpcrt_serialized_cart']);
  131. }
  132. }
  133. if(is_numeric($_GET['sessionid'])) {
  134. $sessionid = $_GET['sessionid'];
  135. $cart_log_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."purchase_logs` WHERE `sessionid`= ".$sessionid." LIMIT 1");
  136. if(is_numeric($cart_log_id)) {
  137. $_SESSION['nzshpcrt_cart'] = null;
  138. $_SESSION['nzshpcrt_serialized_cart'] = null;
  139. }
  140. }
  141. $GLOBALS['nzshpcrt_imagesize_info'] = TXT_WPSC_IMAGESIZEINFO;
  142. $nzshpcrt_log_states[0]['name'] = TXT_WPSC_RECEIVED;
  143. $nzshpcrt_log_states[1]['name'] = TXT_WPSC_PROCESSING;
  144. $nzshpcrt_log_states[2]['name'] = TXT_WPSC_PROCESSED;
  145. class wp_shopping_cart {
  146. function wp_shopping_cart() {
  147. return;
  148. }
  149. function displaypages()
  150. {
  151. /*
  152. * Fairly standard wordpress plugin API stuff for adding the admin pages, rearrange the order to rearrange the pages
  153. * The bits to display the options page first on first use may be buggy, but tend not to stick around long enough to be identified and fixed
  154. * if you find bugs, feel free to fix them.
  155. *
  156. * If the permissions are changed here, they will likewise need to be changed for the other secions of the admin that either use ajax
  157. * or bypass the normal download system.
  158. * its in an object because nobody has moved it out of the object yet.
  159. */
  160. if(function_exists('add_options_page')) {
  161. // if(get_option('nzshpcrt_first_load') == 0) {
  162. // $base_page = WPSC_DIR_NAME.'/options.php';
  163. // add_menu_page(TXT_WPSC_ECOMMERCE, TXT_WPSC_ECOMMERCE, 7, $base_page);
  164. // add_submenu_page($base_page,TXT_WPSC_OPTIONS, TXT_WPSC_OPTIONS, 7, WPSC_DIR_NAME.'/options.php');
  165. // } else {
  166. $base_page = WPSC_DIR_NAME.'/display-log.php';
  167. add_menu_page(TXT_WPSC_ECOMMERCE, TXT_WPSC_ECOMMERCE, 7, $base_page);
  168. add_submenu_page(WPSC_DIR_NAME.'/display-log.php',TXT_WPSC_PURCHASELOG, TXT_WPSC_PURCHASELOG, 7, WPSC_DIR_NAME.'/display-log.php');
  169. // }
  170. //written by allen
  171. add_submenu_page('users.php',TXT_WPSC_ECOMMERCE_SUBSCRIBERS, TXT_WPSC_ECOMMERCE_SUBSCRIBERS, 7, WPSC_DIR_NAME.'/display-ecommerce-subs.php');
  172. //exit(ABSPATH.'wp-admin/users.php');
  173. //end of written by allen
  174. add_submenu_page($base_page,TXT_WPSC_PRODUCTS, TXT_WPSC_PRODUCTS, 7, WPSC_DIR_NAME.'/display-items.php');
  175. add_submenu_page($base_page,TXT_WPSC_CATEGORISATION, TXT_WPSC_CATEGORISATION, 7, WPSC_DIR_NAME.'/display-category.php');
  176. add_submenu_page($base_page,TXT_WPSC_VARIATIONS, TXT_WPSC_VARIATIONS, 7, WPSC_DIR_NAME.'/display_variations.php');
  177. add_submenu_page($base_page,TXT_WPSC_MARKETING, TXT_WPSC_MARKETING, 7, WPSC_DIR_NAME.'/display-coupons.php');
  178. add_submenu_page($base_page,TXT_WPSC_PAYMENTGATEWAYOPTIONS, TXT_WPSC_PAYMENTGATEWAYOPTIONS, 7, WPSC_DIR_NAME.'/gatewayoptions.php');
  179. add_submenu_page($base_page,TXT_WPSC_FORM_FIELDS, TXT_WPSC_FORM_FIELDS, 7, WPSC_DIR_NAME.'/form_fields.php');
  180. add_submenu_page($base_page,TXT_WPSC_OPTIONS, TXT_WPSC_OPTIONS, 7, WPSC_DIR_NAME.'/options.php');
  181. if(function_exists('gold_shpcrt_options')) {
  182. gold_shpcrt_options($base_page);
  183. }
  184. // add_submenu_page($base_page,TXT_WPSC_HELPINSTALLATION, TXT_WPSC_HELPINSTALLATION, 7, WPSC_DIR_NAME.'/instructions.php');
  185. }
  186. return;
  187. }
  188. }
  189. function nzshpcrt_style() {
  190. ?>
  191. <style type="text/css" media="screen">
  192. <?php
  193. if((get_option('product_view') == 'default') || (get_option('product_view') == '')) {
  194. $thumbnail_width = get_option('product_image_width');
  195. if($thumbnail_width <= 0) {
  196. $thumbnail_width = 96;
  197. }
  198. ?>
  199. div.default_product_display div.textcol{
  200. margin-left: <?php echo $thumbnail_width + 10; ?>px !important;
  201. _margin-left: <?php echo ($thumbnail_width/2) + 5; ?>px !important;
  202. }
  203. div.default_product_display div.textcol div.imagecol{
  204. position:absolute;
  205. top:0px;
  206. left: 0px;
  207. margin-left: -<?php echo $thumbnail_width + 10; ?>px !important;
  208. }
  209. <?php
  210. }
  211. $single_thumbnail_width = get_option('single_view_image_width');
  212. $single_thumbnail_height = get_option('single_view_image_height');
  213. if($single_thumbnail_width <= 0) {
  214. $single_thumbnail_width = 128;
  215. }
  216. ?>
  217. div.single_product_display div.textcol{
  218. margin-left: <?php echo $single_thumbnail_width + 10; ?>px !important;
  219. _margin-left: <?php echo ($single_thumbnail_width/2) + 5; ?>px !important;
  220. min-height: <?php echo $single_thumbnail_height + 10;?>px;
  221. _height: <?php echo $single_thumbnail_height + 10;?>px;
  222. }
  223. div.single_product_display div.textcol div.imagecol{
  224. position:absolute;
  225. top:0px;
  226. left: 0px;
  227. margin-left: -<?php echo $single_thumbnail_width + 10; ?>px !important;
  228. }
  229. <?php
  230. if(is_numeric($_GET['brand']) || (get_option('show_categorybrands') == 3)) {
  231. $brandstate = 'block';
  232. $categorystate = 'none';
  233. } else {
  234. $brandstate = 'none';
  235. $categorystate = 'block';
  236. }
  237. ?>
  238. div#categorydisplay{
  239. display: <?php echo $categorystate; ?>;
  240. }
  241. div#branddisplay{
  242. display: <?php echo $brandstate; ?>;
  243. }
  244. </style>
  245. <?php
  246. }
  247. function nzshpcrt_javascript()
  248. {
  249. $siteurl = get_option('siteurl');
  250. echo "";
  251. if(($_SESSION['nzshpcrt_cart'] == null) && (get_option('show_sliding_cart') == 1)) {
  252. ?>
  253. <style type="text/css" media="screen">
  254. div#sliding_cart{
  255. display: none;
  256. }
  257. </style>
  258. <?php
  259. } else {
  260. ?>
  261. <style type="text/css" media="screen">
  262. div#sliding_cart{
  263. display: block;
  264. }
  265. </style>
  266. <?php
  267. }
  268. ?>
  269. <?php if (get_option('product_ratings') == 1){ ?>
  270. <link href='<?php echo WPSC_URL; ?>/product_rater.css' rel="stylesheet" type="text/css" />
  271. <?php } ?>
  272. <link href='<?php echo WPSC_URL; ?>/thickbox.css' rel="stylesheet" type="text/css" />
  273. <?php if (get_option('catsprods_display_type') == 1){ ?>
  274. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/slideMenu.js"></script>
  275. <?php } ?>
  276. <script language='JavaScript' type='text/javascript'>
  277. jQuery.noConflict();
  278. /* base url */
  279. var base_url = "<?php echo $siteurl; ?>";
  280. var WPSC_URL = "<?php echo WPSC_URL; ?>";
  281. /* LightBox Configuration start*/
  282. var fileLoadingImage = "<?php echo WPSC_URL; ?>/images/loading.gif";
  283. var fileBottomNavCloseImage = "<?php echo WPSC_URL; ?>/images/closelabel.gif";
  284. var fileThickboxLoadingImage = "<?php echo WPSC_URL; ?>/images/loadingAnimation.gif";
  285. var resizeSpeed = 9; // controls the speed of the image resizing (1=slowest and 10=fastest)
  286. var borderSize = 10; //if you adjust the padding in the CSS, you will need to update this variable
  287. jQuery(document).ready( function() {
  288. <?php
  289. if(get_option('show_sliding_cart') == 1) {
  290. if(is_numeric($_SESSION['slider_state'])) {
  291. if($_SESSION['slider_state'] == 0) {
  292. ?>
  293. jQuery("#sliding_cart").css({ display: "none"});
  294. <?php
  295. } else {
  296. ?>
  297. jQuery("#sliding_cart").css({ display: "block"});
  298. <?php
  299. }
  300. } else {
  301. if($_SESSION['nzshpcrt_cart'] == null) {
  302. ?>
  303. jQuery("#sliding_cart").css({ display: "none"});
  304. <?php
  305. } else {
  306. ?>
  307. jQuery("#sliding_cart").css({ display: "block"});
  308. <?php
  309. }
  310. }
  311. }
  312. ?>
  313. });
  314. </script>
  315. <script src="<?php echo WPSC_URL; ?>/ajax.js" language='JavaScript' type="text/javascript"></script>
  316. <script src="<?php echo WPSC_URL; ?>/user.js" language='JavaScript' type="text/javascript">
  317. </script>
  318. <?php
  319. $theme_path = WPSC_FILE_PATH. '/themes/';
  320. if((get_option('wpsc_selected_theme') != '') && (file_exists($theme_path.get_option('wpsc_selected_theme')."/".get_option('wpsc_selected_theme').".css") )) {
  321. ?>
  322. <link href='<?php echo WPSC_URL; ?>/themes/<?php echo get_option('wpsc_selected_theme')."/".get_option('wpsc_selected_theme').".css"; ?>' rel="stylesheet" type="text/css" />
  323. <?php
  324. } else {
  325. ?>
  326. <link href='<?php echo WPSC_URL; ?>/themes/default/default.css' rel="stylesheet" type="text/css" />
  327. <?php
  328. }
  329. ?>
  330. <link href='<?php echo WPSC_URL; ?>/themes/compatibility.css' rel="stylesheet" type="text/css" />
  331. <?php
  332. }
  333. function wpsc_admin_css() {
  334. $siteurl = get_option('siteurl');
  335. if(strpos($_SERVER['REQUEST_URI'], WPSC_DIR_NAME.'') !== false) {
  336. ?>
  337. <link href='<?php echo WPSC_URL; ?>/admin.css' rel="stylesheet" type="text/css" />
  338. <link href='<?php echo WPSC_URL; ?>/js/jquery.ui.tabs.css' rel="stylesheet" type="text/css" />
  339. <?php
  340. if($_GET['page'] == 'wp-shopping-cart/display-log.php') {
  341. ?>
  342. <link href='<?php echo $siteurl; ?>/wp-admin/css/dashboard.css?ver=2.6' rel="stylesheet" type="text/css" />
  343. <?php
  344. }
  345. ?>
  346. <link href='<?php echo WPSC_URL; ?>/thickbox.css' rel="stylesheet" type="text/css" />
  347. <script src="<?php echo WPSC_URL; ?>/ajax.js" language='JavaScript' type="text/javascript"></script>
  348. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/jquery.tooltip.js"></script>
  349. <script language='JavaScript' type='text/javascript'>
  350. /* base url */
  351. var base_url = "<?php echo $siteurl; ?>";
  352. var WPSC_URL = "<?php echo WPSC_URL; ?>";
  353. /* LightBox Configuration start*/
  354. var fileLoadingImage = "<?php echo WPSC_URL; ?>/images/loading.gif";
  355. var fileBottomNavCloseImage = "<?php echo WPSC_URL; ?>/images/closelabel.gif";
  356. var fileThickboxLoadingImage = "<?php echo WPSC_URL; ?>/images/loadingAnimation.gif";
  357. var resizeSpeed = 9;
  358. var borderSize = 10;
  359. /* LightBox Configuration end*/
  360. /* custom admin functions start*/
  361. <?php
  362. echo "var TXT_WPSC_DELETE = '".TXT_WPSC_DELETE."';\n\r";
  363. echo "var TXT_WPSC_TEXT = '".TXT_WPSC_TEXT."';\n\r";
  364. echo "var TXT_WPSC_EMAIL = '".TXT_WPSC_EMAIL."';\n\r";
  365. echo "var TXT_WPSC_COUNTRY = '".TXT_WPSC_COUNTRY."';\n\r";
  366. echo "var TXT_WPSC_TEXTAREA = '".TXT_WPSC_TEXTAREA."';\n\r";
  367. echo "var TXT_WPSC_HEADING = '".TXT_WPSC_HEADING."';\n\r";
  368. echo "var TXT_WPSC_COUPON = '".TXT_WPSC_COUPON."';\n\r";
  369. echo "var HTML_FORM_FIELD_TYPES =\"<option value='text' >".TXT_WPSC_TEXT."</option>";
  370. echo "<option value='email' >".TXT_WPSC_EMAIL."</option>";
  371. echo "<option value='address' >".TXT_WPSC_ADDRESS."</option>";
  372. echo "<option value='city' >".TXT_WPSC_CITY."</option>";
  373. echo "<option value='country'>".TXT_WPSC_COUNTRY."</option>";
  374. echo "<option value='delivery_address' >".TXT_WPSC_DELIVERY_ADDRESS."</option>";
  375. echo "<option value='delivery_city' >".TXT_WPSC_DELIVERY_CITY."</option>";
  376. echo "<option value='delivery_country'>".TXT_WPSC_DELIVERY_COUNTRY."</option>";
  377. echo "<option value='textarea' >".TXT_WPSC_TEXTAREA."</option>";
  378. echo "<option value='heading' >".TXT_WPSC_HEADING."</option>";
  379. echo "<option value='coupon' >".TXT_WPSC_COUPON."</option>\";\n\r";
  380. ?>
  381. /* custom admin functions end*/
  382. </script>
  383. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/thickbox.js"></script>
  384. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/jquery.tooltip.js"></script>
  385. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/dimensions.js"></script>
  386. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/admin.js"></script>
  387. <?php
  388. }
  389. }
  390. function nzshpcrt_displaypages()
  391. {
  392. $nzshpcrt = new wp_shopping_cart;
  393. $nzshpcrt->displaypages();
  394. }
  395. function nzshpcrt_adminpage()
  396. {
  397. $nzshpcrt = new wp_shopping_cart;
  398. $nzshpcrt->adminpage();
  399. }
  400. function nzshpcrt_additem()
  401. {
  402. $nzshpcrt = new wp_shopping_cart;
  403. $nzshpcrt->additem();
  404. }
  405. function nzshpcrt_displayitems()
  406. {
  407. $nzshpcrt = new wp_shopping_cart;
  408. $nzshpcrt->displayitems();
  409. }
  410. function nzshpcrt_instructions()
  411. {
  412. $nzshpcrt = new wp_shopping_cart;
  413. $nzshpcrt->instructions();
  414. }
  415. function nzshpcrt_options()
  416. {
  417. $nzshpcrt = new wp_shopping_cart;
  418. $nzshpcrt->options();
  419. }
  420. function nzshpcrt_gatewayoptions()
  421. {
  422. $nzshpcrt = new wp_shopping_cart;
  423. $nzshpcrt->gatewayoptions();
  424. }
  425. function nzshpcrt_addcategory()
  426. {
  427. $nzshpcrt = new wp_shopping_cart;
  428. $nzshpcrt->addcategory();
  429. //$GLOBALS['nzshpcrt_activateshpcrt'] = true;
  430. }
  431. function nzshpcrt_editcategory()
  432. {
  433. $nzshpcrt = new wp_shopping_cart;
  434. $nzshpcrt->editcategory();
  435. //$GLOBALS['nzshpcrt_activateshpcrt'] = true;
  436. }
  437. function nzshpcrt_editvariations()
  438. {
  439. $nzshpcrt = new wp_shopping_cart;
  440. $nzshpcrt->editvariations();
  441. //$GLOBALS['nzshpcrt_activateshpcrt'] = true;
  442. }
  443. function nzshpcrt_submit_ajax()
  444. {
  445. global $wpdb,$user_level,$wp_rewrite;
  446. get_currentuserinfo();
  447. if(get_option('permalink_structure') != '') {
  448. $seperator ="?";
  449. } else {
  450. $seperator ="&amp;";
  451. }
  452. $cartt = $_SESSION['nzshpcrt_cart'];
  453. $cartt1=$cartt[0]->product_id;
  454. // if is an AJAX request, cruddy code, could be done better but getting approval would be impossible
  455. if(($_POST['ajax'] == "true") || ($_GET['ajax'] == "true"))
  456. {
  457. if ($_POST['changetax'] == "true") {
  458. if (isset($_POST['billing_region'])){
  459. $billing_region=$_POST['billing_region'];
  460. } else {
  461. $billing_region=$_SESSION['selected_region'];
  462. }
  463. $billing_country=$_POST['billing_country'];
  464. foreach($cartt as $cart_item) {
  465. $product_id = $cart_item->product_id;
  466. $quantity = $cart_item->quantity;
  467. //echo("<pre>".print_r($cart_item->product_variations,true)."</pre>");
  468. $product = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id` = '$product_id' LIMIT 1",ARRAY_A);
  469. if($product['donation'] == 1) {
  470. $price = $quantity * $cart_item->donation_price;
  471. } else {
  472. $price = $quantity * calculate_product_price($product_id, $cart_item->product_variations);
  473. if($product['notax'] != 1) {
  474. $tax += nzshpcrt_calculate_tax($price, $billing_country, $billing_region) - $price;
  475. }
  476. $all_donations = false;
  477. }
  478. if($_SESSION['delivery_country'] != null) {
  479. $total_shipping += nzshpcrt_determine_item_shipping($product['id'], $quantity, $_SESSION['delivery_country']);
  480. }
  481. }
  482. echo $tax.":".$price.":".$total_shipping;
  483. exit();
  484. }
  485. if ($_POST['submittogoogle']) {
  486. $newvalue=$_POST['value'];
  487. $amount=$_POST['amount'];
  488. $reason=$_POST['reason'];
  489. $comment=$_POST['comment'];
  490. $message=$_POST['message'];
  491. $amount=number_format($amount, 2, '.', '');
  492. $log_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `id` = '".$_POST['id']."' LIMIT 1",ARRAY_A);
  493. if (($newvalue==2) && function_exists('wpsc_member_activate_subscriptions')){
  494. wpsc_member_activate_subscriptions($_POST['id']);
  495. }
  496. $google_status = unserialize($log_data['google_status']);
  497. switch($newvalue) {
  498. case "Charge":
  499. if ($google_status[0]!='CANCELLED_BY_GOOGLE') {
  500. if ($amount=='') {
  501. $google_status['0']='Partially Charged';
  502. } else {
  503. $google_status['0']='CHARGED';
  504. $google_status['partial_charge_amount']=$amount;
  505. }
  506. }
  507. break;
  508. case "Cancel":
  509. if ($google_status[0]!='CANCELLED_BY_GOOGLE')
  510. $google_status[0]='CANCELLED';
  511. if ($google_status[1]!='DELIVERED')
  512. $google_status[1]='WILL_NOT_DELIVER';
  513. break;
  514. case "Refund":
  515. if ($amount=='') {
  516. $google_status['0']='Partially Refund';
  517. } else {
  518. $google_status['0']='REFUND';
  519. $google_status['partial_refund_amount']=$amount;
  520. }
  521. break;
  522. case "Ship":
  523. if ($google_status[1]!='WILL_NOT_DELIVER')
  524. $google_status[1]='DELIVERED';
  525. break;
  526. case "Archive":
  527. $google_status[1]='ARCHIVED';
  528. break;
  529. }
  530. $google_status_sql="UPDATE `".$wpdb->prefix."purchase_logs` SET google_status='".serialize($google_status)."' WHERE `id` = '".$_POST['id']."' LIMIT 1";
  531. $wpdb->query($google_status_sql);
  532. $merchant_id = get_option('google_id');
  533. $merchant_key = get_option('google_key');
  534. $server_type = get_option('google_server_type');
  535. $currency = get_option('google_cur');
  536. $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type,$currency);
  537. $google_order_number=$wpdb->get_var("SELECT google_order_number FROM `".$wpdb->prefix."purchase_logs` WHERE `id` = '".$_POST['id']."' LIMIT 1");
  538. switch ($newvalue) {
  539. case 'Charge':
  540. $Grequest->SendChargeOrder($google_order_number,$amount);
  541. break;
  542. case 'Ship':
  543. $Grequest->SendDeliverOrder($google_order_number);
  544. break;
  545. case 'Archive':
  546. $Grequest->SendArchiveOrder($google_order_number);
  547. break;
  548. case 'Refund':
  549. $Grequest->SendRefundOrder($google_order_number,$amount,$reason);
  550. break;
  551. case 'Cancel':
  552. $Grequest->SendCancelOrder($google_order_number,$reason,$comment);
  553. break;
  554. case 'Send Message':
  555. $Grequest->SendBuyerMessage($google_order_number,$message);
  556. break;
  557. }
  558. $newvalue++;
  559. $update_sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET `processed` = '".$newvalue."' WHERE `id` = '".$_POST['id']."' LIMIT 1";
  560. //$wpdb->query($update_sql);
  561. exit();
  562. }
  563. ////changes for usps
  564. if ($_POST['uspsswitch']) {
  565. foreach ($_SESSION['uspsQuote'] as $quotes) {
  566. $total=$_POST['total'];
  567. if ($quotes[$_POST['key']]!='') {
  568. echo nzshpcrt_currency_display($total+$quotes[$_POST['key']],1);
  569. echo "<input type='hidden' value='".$total."' id='shopping_cart_total_price'>";
  570. $_SESSION['usps_shipping']= $quotes[$_POST['key']];
  571. }
  572. }
  573. exit();
  574. }
  575. //changes for usps ends
  576. if(($_GET['user'] == "true") && is_numeric($_POST['prodid']))
  577. {
  578. $memberstatus = get_product_meta($_POST['prodid'],'is_membership',true);
  579. if(($memberstatus[0]=='1') && ($_SESSION['nzshopcrt_cart']!=NULL)){
  580. } else{
  581. $sql = "SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id`='".$_POST['prodid']."' LIMIT 1";
  582. $item_data = $wpdb->get_results($sql,ARRAY_A);
  583. $item_quantity = 0;
  584. if($_SESSION['nzshpcrt_cart'] != null)
  585. {
  586. foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item)
  587. {
  588. if (($memberstatus[0]!='1')&&($_SESSION['nzshpcrt_cart']!=NULL)){
  589. if($cart_item->product_id == $_POST['prodid']) {
  590. if(($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $_POST['variation'])&&($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $_POST['extras'])) {
  591. $item_quantity += $_SESSION['nzshpcrt_cart'][$cart_key]->quantity;
  592. $item_variations = $_SESSION['nzshpcrt_cart'][$cart_key]->product_variations;
  593. }
  594. }
  595. }
  596. }
  597. }
  598. $item_stock = null;
  599. $variation_count = count($_POST['variation']);
  600. if(($variation_count >= 1) && ($variation_count <= 2)) {
  601. foreach($_POST['variation'] as $variation_id) {
  602. if(is_numeric($variation_id)) {
  603. $variation_ids[] = (int)$variation_id;
  604. }
  605. }
  606. if(count($variation_ids) == 2) {
  607. $variation_stock_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."variation_priceandstock` WHERE `product_id` = '".$_POST['prodid']."' AND (`variation_id_1` = '".$variation_ids[0]."' AND `variation_id_2` = '".$variation_ids[1]."') OR (`variation_id_1` = '".$variation_ids[1]."' AND `variation_id_2` = '".$variation_ids[0]."') LIMIT 1",ARRAY_A);
  608. $item_stock = $variation_stock_data['stock'];
  609. } else if(count($variation_ids) == 1) {
  610. $variation_stock_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."variation_priceandstock` WHERE `product_id` = '".$_POST['prodid']."' AND (`variation_id_1` = '".$variation_ids[0]."' AND `variation_id_2` = '0') LIMIT 1",ARRAY_A);
  611. $item_stock = $variation_stock_data['stock'];
  612. }
  613. }
  614. if($item_stock === null) {
  615. $item_stock = $item_data[0]['quantity'];
  616. }
  617. if((($item_data[0]['quantity_limited'] == 1) && ($item_stock > 0) && ($item_stock > $item_quantity)) || ($item_data[0]['quantity_limited'] == 0)) {
  618. $cartcount = count($_SESSION['nzshpcrt_cart']);
  619. if(is_array($_POST['variation'])) { $variations = $_POST['variation']; } else { $variations = null; }
  620. if(is_array($_POST['extras'])) { $extras = $_POST['extras']; } else { $extras = null; }
  621. $updated_quantity = false;
  622. if($_SESSION['nzshpcrt_cart'] != null) {
  623. foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) {
  624. if ((!($memberstatus[0]=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))) {
  625. if((int)$cart_item->product_id === (int)$_POST['prodid']) { // force both to integer before testing for identicality
  626. if(($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $extras)&&($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $variations) && ((int)$_SESSION['nzshpcrt_cart'][$cart_key]->donation_price == (int)$_POST['donation_price'])) {
  627. if(is_numeric($_POST['quantity'])) {
  628. $_SESSION['nzshpcrt_cart'][$cart_key]->quantity += (int)$_POST['quantity'];
  629. } else {
  630. $_SESSION['nzshpcrt_cart'][$cart_key]->quantity++;
  631. }
  632. $updated_quantity = true;
  633. }
  634. }
  635. }
  636. }
  637. }
  638. if($item_data[0]['donation'] == 1) {
  639. $donation = $_POST['donation_price'];
  640. } else {
  641. $donation = false;
  642. }
  643. if(!(($memberstatus[0]=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))){
  644. $status = get_product_meta($cartt1, 'is_membership', true);
  645. if ($status[0]=='1'){
  646. exit();
  647. }
  648. if($updated_quantity === false) {
  649. if(is_numeric($_POST['quantity'])) {
  650. if($_POST['quantity'] > 0) {
  651. $new_cart_item = new cart_item($_POST['prodid'],$variations,$_POST['quantity'], $donation,$extras);
  652. }
  653. } else {
  654. //echo "correct";
  655. $new_cart_item = new cart_item($_POST['prodid'],$variations, 1, $donation,$extras);
  656. }
  657. $_SESSION['nzshpcrt_cart'][] = $new_cart_item;
  658. }
  659. }
  660. } else {
  661. $quantity_limit = true;
  662. }
  663. $cart = $_SESSION['nzshpcrt_cart'];
  664. if (($memberstatus[0]=='1')&&(count($cart)>1)) {
  665. } else {
  666. $status = get_product_meta($cartt1, 'is_membership', true);
  667. if ($status[0]=='1'){
  668. exit('st');
  669. }
  670. echo "if(document.getElementById('shoppingcartcontents') != null)
  671. {
  672. document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(nzshpcrt_shopping_basket_internals($cart,$quantity_limit))). "\";
  673. }
  674. ";
  675. if(($_POST['prodid'] != null) &&(get_option('fancy_notifications') == 1)) {
  676. echo "if(document.getElementById('fancy_notification_content') != null)
  677. {
  678. document.getElementById('fancy_notification_content').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(fancy_notification_content($_POST['prodid'], $quantity_limit))). "\";
  679. jQuery('#loading_animation').css('display', 'none');
  680. jQuery('#fancy_notification_content').css('display', 'block');
  681. }
  682. ";
  683. }
  684. if($_SESSION['slider_state'] == 0) {
  685. echo 'jQuery("#sliding_cart").css({ display: "none"});'."\n\r";
  686. } else {
  687. echo 'jQuery("#sliding_cart").css({ display: "block"});'."\n\r";
  688. }
  689. }
  690. }
  691. exit();
  692. } else if(($_POST['user'] == "true") && ($_POST['emptycart'] == "true")) {
  693. //exit("/* \n\r ".get_option('shopping_cart_url')." \n\r ".print_r($_POST,true)." \n\r */");
  694. $_SESSION['nzshpcrt_cart'] = '';
  695. $_SESSION['nzshpcrt_cart'] = Array();
  696. echo "if(document.getElementById('shoppingcartcontents') != null) {
  697. document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "", addslashes(nzshpcrt_shopping_basket_internals($cart))). "\";
  698. }\n\r";
  699. if($_POST['current_page'] == get_option('shopping_cart_url')) {
  700. echo "window.location = '".get_option('shopping_cart_url')."';\n\r"; // if we are on the checkout page, redirect back to it to clear the non-ajax cart too
  701. }
  702. exit();
  703. }
  704. if ($_POST['store_list']=="true") {
  705. $map_data['address'] = $_POST['addr'];
  706. $map_data['city'] = $_POST['city'];
  707. $map_data['country'] = 'US';
  708. $map_data['zipcode']='';
  709. $map_data['radius'] = '50000';
  710. $map_data['state'] = '';
  711. $map_data['submit'] = 'Find Store';
  712. $stores = getdistance($map_data);
  713. $i=0;
  714. while($rows = mysql_fetch_array($stores)) {
  715. //echo "<pre>".print_r($rows,1)."</pre>";
  716. if ($i==0) {
  717. $closest_store = $rows[5];
  718. }
  719. $i++;
  720. $store_list[$i] = $rows[5];
  721. }
  722. foreach ($store_list as $store){
  723. $output.="<option value='$store'>$store</option>";
  724. }
  725. echo $output;
  726. exit();
  727. }
  728. if($_POST['admin'] == "true") {
  729. if(is_numeric($_POST['prodid'])) {
  730. /* fill product form */
  731. echo nzshpcrt_getproductform($_POST['prodid']);
  732. exit();
  733. } else if(is_numeric($_POST['catid'])) {
  734. /* fill category form */
  735. echo nzshpcrt_getcategoryform($_POST['catid']);
  736. exit();
  737. } else if(is_numeric($_POST['brandid'])) {
  738. /* fill brand form */
  739. echo nzshpcrt_getbrandsform($_POST['brandid']);
  740. exit();
  741. } else if(is_numeric($_POST['variation_id'])) {
  742. echo nzshpcrt_getvariationform($_POST['variation_id']);
  743. exit();
  744. }
  745. if($_POST['hide_ecom_dashboard'] == 'true') {
  746. require_once (ABSPATH . WPINC . '/rss.php');
  747. $rss = fetch_rss('http://www.instinct.co.nz/feed/');
  748. $rss->items = array_slice($rss->items, 0, 5);
  749. $rss_hash = sha1(serialize($rss->items));
  750. update_option('wpsc_ecom_news_hash', $rss_hash);
  751. exit(1);
  752. }
  753. if(($_POST['remove_meta'] == 'true') && is_numeric($_POST['meta_id'])) {
  754. $meta_id = (int)$_POST['meta_id'];
  755. $selected_meta = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}wpsc_productmeta` WHERE `id` IN('{$meta_id}') ",ARRAY_A);
  756. if($selected_meta != null) {
  757. if($wpdb->query("DELETE FROM `{$wpdb->prefix}wpsc_productmeta` WHERE `id` IN('{$meta_id}') LIMIT 1")) {
  758. echo $meta_id;
  759. exit();
  760. }
  761. }
  762. echo 0;
  763. exit();
  764. }
  765. exit();
  766. }
  767. if(is_numeric($_POST['currencyid'])){
  768. $currency_data = $wpdb->get_results("SELECT `symbol`,`symbol_html`,`code` FROM `".$wpdb->prefix."currency_list` WHERE `id`='".$_POST['currencyid']."' LIMIT 1",ARRAY_A) ;
  769. $price_out = null;
  770. if($currency_data[0]['symbol'] != '') {
  771. $currency_sign = $currency_data[0]['symbol_html'];
  772. } else {
  773. $currency_sign = $currency_data[0]['code'];
  774. }
  775. echo $currency_sign;
  776. exit();
  777. }
  778. //echo "--==->";
  779. if($_POST['buynow'] == "true") {
  780. $id = $_REQUEST['product_id'];
  781. $price = $_REQUEST['price'];
  782. $downloads = get_option('max_downloads');
  783. $product_sql = "SELECT * FROM ".$wpdb->prefix."product_list WHERE id = ".$id." LIMIT 1";
  784. $product_info = $wpdb->get_results($product_sql, ARRAY_A);
  785. $product_info = $product_info[0];
  786. $sessionid = (mt_rand(100,999).time());
  787. $sql = "INSERT INTO `".$wpdb->prefix."purchase_logs` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`shipping_region`, `user_ID`, `discount_value` ) VALUES ( '".$price."', '".$sessionid."', '".time()."', 'BuyNow', 'BuyNow', 'BuyNow' , NULL , 0)";
  788. $wpdb->query($sql) ;
  789. $log_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."purchase_logs` WHERE `sessionid` IN('".$sessionid."') LIMIT 1") ;
  790. $cartsql = "INSERT INTO `".$wpdb->prefix."cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping` ) VALUES ('".$id."', '".$log_id."','".$price."','0', '0','1', '".$donation."', '1')";
  791. $wpdb->query($cartsql);
  792. $wpdb->query("INSERT INTO `".$wpdb->prefix."download_status` ( `fileid` , `purchid` , `downloads` , `active` , `datetime` ) VALUES ( '".$product_info['file']."', '".$log_id."', '$downloads', '0', NOW( ));");
  793. exit();
  794. }
  795. if(($_POST['changeorder'] == "true") && is_numeric($_POST['category_id'])) {
  796. $category_id = (int)$_POST['category_id'];
  797. $hash=$_POST['sort1'];
  798. $order=1;
  799. foreach($hash as $id) {
  800. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order`=$order WHERE `product_id`=".(int)$id." AND `category_id`=".(int)$category_id." LIMIT 1");
  801. $order++;
  802. }
  803. exit(" ");
  804. }
  805. /* rate item */
  806. if(($_POST['rate_item'] == "true") && is_numeric($_POST['product_id']) && is_numeric($_POST['rating']))
  807. {
  808. $nowtime = time();
  809. $prodid = $_POST['product_id'];
  810. $ip_number = $_SERVER['REMOTE_ADDR'];
  811. $rating = $_POST['rating'];
  812. $cookie_data = explode(",",$_COOKIE['voting_cookie'][$prodid]);
  813. if(is_numeric($cookie_data[0]) && ($cookie_data[0] > 0))
  814. {
  815. $vote_id = $cookie_data[0];
  816. $wpdb->query("UPDATE `".$wpdb->prefix."product_rating` SET `rated` = '".$rating."' WHERE `id` ='".$vote_id."' LIMIT 1 ;");
  817. }
  818. else
  819. {
  820. $insert_sql = "INSERT INTO `".$wpdb->prefix."product_rating` ( `ipnum` , `productid` , `rated`, `time`) VALUES ( '".$ip_number."', '".$prodid."', '".$rating."', '".$nowtime."');";
  821. $wpdb->query($insert_sql);
  822. $data = $wpdb->get_results("SELECT `id`,`rated` FROM `".$wpdb->prefix."product_rating` WHERE `ipnum`='".$ip_number."' AND `productid` = '".$prodid."' AND `rated` = '".$rating."' AND `time` = '".$nowtime."' ORDER BY `id` DESC LIMIT 1",ARRAY_A) ;
  823. $vote_id = $data[0]['id'];
  824. setcookie("voting_cookie[$prodid]", ($vote_id.",".$rating),time()+(60*60*24*360));
  825. }
  826. $output[1]= $prodid;
  827. $output[2]= $rating;
  828. echo $output[1].",".$output[2];
  829. exit();
  830. }
  831. //written by allen
  832. if ($_REQUEST['save_tracking_id'] == "true"){
  833. $id = $_POST['id'];
  834. $value = $_POST['value'];
  835. $update_sql = "UPDATE ".$wpdb->prefix."purchase_logs SET track_id = '".$value."' WHERE id=$id";
  836. $wpdb->query($update_sql);
  837. exit();
  838. }
  839. if(($_POST['get_rating_count'] == "true") && is_numeric($_POST['product_id']))
  840. {
  841. $prodid = $_POST['product_id'];
  842. $data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `".$wpdb->prefix."product_rating` WHERE `productid` = '".$prodid."'",ARRAY_A) ;
  843. echo $data[0]['count'].",".$prodid;
  844. exit();
  845. }
  846. /// Pointless AJAX call is pointless
  847. // if(isset($_POST['changeperpage'])) {
  848. // $item_per_page = $_POST['changeperpage'];
  849. // echo $item_per_page;
  850. // exit();
  851. // }
  852. if(($_POST['remove_variation_value'] == "true") && is_numeric($_POST['variation_value_id']))
  853. {
  854. $wpdb->query("DELETE FROM `".$wpdb->prefix."variation_values_associations` WHERE `value_id` = '".$_POST['variation_value_id']."'");
  855. $wpdb->query("DELETE FROM `".$wpdb->prefix."variation_values` WHERE `id` = '".$_POST['variation_value_id']."' LIMIT 1");
  856. exit();
  857. }
  858. if(($_POST['get_updated_price'] == "true") && is_numeric($_POST['product_id']))
  859. {
  860. $notax = $wpdb->get_var("SELECT `notax` FROM `".$wpdb->prefix."product_list` WHERE `id` IN('".$_POST['product_id']."') LIMIT 1");
  861. foreach((array)$_POST['variation'] as $variation)
  862. {
  863. if(is_numeric($variation))
  864. {
  865. $variations[] = $variation;
  866. }
  867. }
  868. foreach((array)$_POST['extra'] as $extra)
  869. {
  870. if(is_numeric($extra))
  871. {
  872. $extras[] = $extra;
  873. }
  874. }
  875. $pm=$_POST['pm'];
  876. echo "product_id=".$_POST['product_id'].";\n";
  877. echo "price=\"".nzshpcrt_currency_display(calculate_product_price($_POST['product_id'], $variations,'stay',$extras), $notax)."\";\n";
  878. //exit(print_r($extras,1));
  879. exit();
  880. }
  881. if(($_REQUEST['log_state'] == "true") && is_numeric($_POST['id']) && is_numeric($_POST['value'])) {
  882. $newvalue = $_POST['value'];
  883. if ($_REQUEST['suspend']=='true'){
  884. if ($_REQUEST['value']==1){
  885. wpsc_member_dedeactivate_subscriptions($_POST['id']);
  886. } else {
  887. wpsc_member_deactivate_subscriptions($_POST['id']);
  888. }
  889. exit();
  890. } else {
  891. $log_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `id` = '".$_POST['id']."' LIMIT 1",ARRAY_A);
  892. if (($newvalue==2) && function_exists('wpsc_member_activate_subscriptions')){
  893. wpsc_member_activate_subscriptions($_POST['id']);
  894. }
  895. $update_sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET `processed` = '".$newvalue."' WHERE `id` = '".$_POST['id']."' LIMIT 1";
  896. $wpdb->query($update_sql);
  897. //echo("/*");
  898. if(($newvalue > $log_data['processed']) && ($log_data['processed'] < 2)) {
  899. transaction_results($log_data['sessionid'],false);
  900. }
  901. //echo("*/");
  902. $stage_sql = "SELECT * FROM `".$wpdb->prefix."purchase_statuses` WHERE `id`='".$newvalue."' AND `active`='1' LIMIT 1";
  903. $stage_data = $wpdb->get_row($stage_sql,ARRAY_A);
  904. echo "document.getElementById(\"form_group_".$_POST['id']."_text\").innerHTML = '".$stage_data['name']."';\n";
  905. echo "document.getElementById(\"form_group_".$_POST['id']."_text\").style.color = '#".$stage_data['colour']."';\n";
  906. $year = date("Y");
  907. $month = date("m");
  908. $start_timestamp = mktime(0, 0, 0, $month, 1, $year);
  909. $end_timestamp = mktime(0, 0, 0, ($month+1), 0, $year);
  910. echo "document.getElementById(\"log_total_month\").innerHTML = '".addslashes(nzshpcrt_currency_display(admin_display_total_price($start_timestamp, $end_timestamp),1))."';\n";
  911. echo "document.getElementById(\"log_total_absolute\").innerHTML = '".addslashes(nzshpcrt_currency_display(admin_display_total_price(),1))."';\n";
  912. exit();
  913. }
  914. }
  915. if(($_POST['list_variation_values'] == "true") && is_numeric($_POST['new_variation_id'])) {
  916. $variation_processor = new nzshpcrt_variations();
  917. echo "variation_value_id = \"".$_POST['new_variation_id']."\";\n";
  918. echo "variation_value_html = \"".$variation_processor->display_variation_values($_POST['prefix'],$_POST['new_variation_id'])."\";\n";
  919. $variations_selected = array_values(array_unique(array_merge((array)$_POST['new_variation_id'], (array)$_POST['variation_id'])));
  920. echo "variation_subvalue_html = \"".str_replace("\n\r", '\n\r', $variation_processor->variations_add_grid_view((array)$variations_selected))."\";\n";
  921. //echo "/*\n\r".print_r(array_values(array_unique(array_merge((array)$_POST['new_variation_id'], $_POST['variation_id']))),true)."\n\r*/";
  922. exit();
  923. }
  924. if(($_POST['redisplay_variation_values'] == "true")) {
  925. $variation_processor = new nzshpcrt_variations();
  926. $variations_selected = array_values(array_unique(array_merge((array)$_POST['new_variation_id'], (array)$_POST['variation_id'])));
  927. foreach($variations_selected as $variation_id) {
  928. // cast everything to integer to make sure nothing nasty gets in.
  929. $variation_list[] = (int)$variation_id;
  930. }
  931. echo $variation_processor->variations_add_grid_view((array)$variation_list);
  932. //echo "/*\n\r".print_r(array_values(array_unique($_POST['variation_id'])),true)."\n\r*/";
  933. exit();
  934. }
  935. if(($_POST['edit_variation_value_list'] == 'true') && is_numeric($_POST['variation_id']) && is_numeric($_POST['product_id'])) {
  936. $variation_id = (int)$_POST['variation_id'];
  937. $product_id = (int)$_POST['product_id'];
  938. $variations_processor = new nzshpcrt_variations();
  939. $variation_values = $variations_processor->falsepost_variation_values($variation_id);
  940. if(is_array($variation_values)) {
  941. //echo(print_r($variation_values,true));
  942. $check_variation_added = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."variation_associations` WHERE `type` IN ('product') AND `associated_id` IN ('{$product_id}') AND `variation_id` IN ('{$variation_id}') LIMIT 1");
  943. if($check_variation_added == null) {
  944. $variations_processor->add_to_existing_product($product_id,$variation_values);
  945. }
  946. echo $variations_processor->display_attached_variations($product_id);
  947. echo $variations_processor->variations_grid_view($product_id);
  948. } else {
  949. echo "false";
  950. }
  951. exit();
  952. }
  953. if(($_POST['remove_form_field'] == "true") && is_numeric($_POST['form_id'])) {
  954. //exit(print_r($user,true));
  955. if(current_user_can('level_7')) {
  956. $wpdb->query("UPDATE `".$wpdb->prefix."collect_data_forms` SET `active` = '0' WHERE `id` ='".$_POST['form_id']."' LIMIT 1 ;");
  957. exit(' ');
  958. }
  959. }
  960. /*
  961. * function for handling the checkout billing address
  962. */
  963. if(preg_match("/[a-zA-Z]{2,4}/", $_POST['billing_country']))
  964. {
  965. if($_SESSION['selected_country'] == $_POST['billing_country'])
  966. {
  967. $do_not_refresh_regions = true;
  968. }
  969. else
  970. {
  971. $do_not_refresh_regions = false;
  972. $_SESSION['selected_country'] = $_POST['billing_country'];
  973. }
  974. if(is_numeric($_POST['form_id']))
  975. {
  976. $form_id = $_POST['form_id'];
  977. $html_form_id = "region_country_form_$form_id";
  978. }
  979. else
  980. {
  981. $html_form_id = 'region_country_form';
  982. }
  983. if(is_numeric($_POST['billing_region']))
  984. {
  985. $_SESSION['selected_region'] = $_POST['billing_region'];
  986. }
  987. $cart =& $_SESSION['nzshpcrt_cart'];
  988. if (($memberstatus[0]=='1')&&(count($cart)>0)){
  989. echo "
  990. ";
  991. }else{
  992. if ($status[0]=='1'){
  993. exit();
  994. }
  995. echo "if(document.getElementById('shoppingcartcontents') != null)
  996. {
  997. document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(nzshpcrt_shopping_basket_internals($cart,$quantity_limit))). "\";
  998. }
  999. ";
  1000. if($do_not_refresh_regions == false)
  1001. {
  1002. $region_list = $wpdb->get_results("SELECT `".$wpdb->prefix."region_tax`.* FROM `".$wpdb->prefix."region_tax`, `".$wpdb->prefix."currency_list` WHERE `".$wpdb->prefix."currency_list`.`isocode` IN('".$_POST['billing_country']."') AND `".$wpdb->prefix."currency_list`.`id` = `".$wpdb->prefix."region_tax`.`country_id`",ARRAY_A) ;
  1003. if($region_list != null)
  1004. {
  1005. $output .= "<select name='collected_data[".$form_id."][1]' class='current_region' onchange='set_billing_country(\\\"$html_form_id\\\", \\\"$form_id\\\");'>";
  1006. //$output .= "<option value=''>None</option>";
  1007. foreach($region_list as $region)
  1008. {
  1009. if($_SESSION['selected_region'] == $region['id'])
  1010. {
  1011. $selected = "selected='true'";
  1012. }
  1013. else
  1014. {
  1015. $selected = "";
  1016. }
  1017. $output .= "<option value='".$region['id']."' $selected>".$region['name']."</option>";
  1018. }
  1019. $output .= "</select>";
  1020. echo "if(document.getElementById('region_select_$form_id') != null)
  1021. {
  1022. document.getElementById('region_select_$form_id').innerHTML = \"".$output."\";
  1023. }
  1024. ";
  1025. }
  1026. else
  1027. {
  1028. echo "if(document.getElementById('region_select_$form_id') != null)
  1029. {
  1030. document.getElementById('region_select_$form_id').innerHTML = \"\";
  1031. }
  1032. ";
  1033. }
  1034. }
  1035. }
  1036. exit();
  1037. }
  1038. if(($_POST['get_country_tax'] == "true") && preg_match("/[a-zA-Z]{2,4}/",$_POST['country_id']))
  1039. {
  1040. $country_id = $_POST['country_id'];
  1041. $region_list = $wpdb->get_results("SELECT `".$wpdb->prefix."region_tax`.* FROM `".$wpdb->prefix."region_tax`, `".$wpdb->prefix."currency_list` WHERE `".$wpdb->prefix."currency_list`.`isocode` IN('".$country_id."') AND `".$wpdb->prefix."currency_list`.`id` = `".$wpdb->prefix."region_tax`.`country_id`",ARRAY_A) ;
  1042. if($region_list != null)
  1043. {
  1044. echo "<select name='base_region'>\n\r";
  1045. foreach($region_list as $region)
  1046. {
  1047. if(get_option('base_region') == $region['id'])
  1048. {
  1049. $selected = "selected='true'";
  1050. }
  1051. else
  1052. {
  1053. $selected = "";
  1054. }
  1055. echo "<option value='".$region['id']."' $selected>".$region['name']."</option>\n\r";
  1056. }
  1057. echo "</select>\n\r";
  1058. }
  1059. else { echo "&nbsp;"; }
  1060. exit();
  1061. }
  1062. /* fill product form */
  1063. if(($_POST['set_slider'] == "true") && is_numeric($_POST['state']))
  1064. {
  1065. $_SESSION['slider_state'] = $_POST['state'];
  1066. exit();
  1067. } /* fill category form */
  1068. if($_GET['action'] == "register")
  1069. {
  1070. $siteurl = get_option('siteurl');
  1071. require_once( ABSPATH . WPINC . '/registration-functions.php');
  1072. if(($_POST['action']=='register') && get_settings('users_can_register'))
  1073. {
  1074. //exit("fail for testing purposes");
  1075. $user_login = sanitize_user( $_POST['user_login'] );
  1076. $user_email = $_POST['user_email'];
  1077. $errors = array();
  1078. if ( $user_login == '' )
  1079. exit($errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.'));
  1080. /* checking e-mail address */
  1081. if ($user_email == '') {
  1082. exit(__('<strong>ERROR</strong>: Please type your e-mail address.'));
  1083. } else if (!is_email($user_email)) {
  1084. exit( __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
  1085. $user_email = '';
  1086. }
  1087. if ( ! validate_username($user_login) ) {
  1088. $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.');
  1089. $user_login = '';
  1090. }
  1091. if ( username_exists( $user_login ) )
  1092. exit( __('<strong>ERROR</strong>: This username is already registered, please choose another one.'));
  1093. /* checking the email isn't already used by another user */
  1094. $email_exists = $wpdb->get_row("SELECT user_email FROM $wpdb->users WHERE user_email = '$user_email'");
  1095. if ( $email_exists)
  1096. die (__('<strong>ERROR</strong>: This email address is already registered, please supply another.'));
  1097. if ( 0 == count($errors) ) {
  1098. $password = substr( md5( uniqid( microtime() ) ), 0, 7);
  1099. //xit('there?');
  1100. $user_id = wp_create_user( $user_login, $password, $user_email );
  1101. if ( !$user_id )
  1102. {
  1103. exit(sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email')));
  1104. }
  1105. else
  1106. {
  1107. wp_new_user_notification($user_id, $password);
  1108. ?>
  1109. <div id="login">
  1110. <h2><?php _e('Registration Complete') ?></h2>
  1111. <p><?php printf(__('Username: %s'), "<strong>" . wp_specialchars($user_login) . "</strong>") ?><br />
  1112. <?php printf(__('Password: %s'), '<strong>' . __('emailed to you') . '</strong>') ?> <br />
  1113. <?php printf(__('E-mail: %s'), "<strong>" . wp_specialchars($user_email) . "</strong>") ?></p>
  1114. </div>
  1115. <?php
  1116. }
  1117. }
  1118. }
  1119. else
  1120. {
  1121. // onsubmit='submit_register_form(this);return false;'
  1122. echo "<div id='login'>
  1123. <h2>Register for this blog</h2>
  1124. <form id='registerform' action='index.php?ajax=true&amp;action=register' onsubmit='submit_register_form(this);return false;' method='post'>
  1125. <p><input type='hidden' value='register' name='action'/>
  1126. <label for='user_login'>Username:</label><br/> <input type='text' value='' maxlength='20' size='20' id='user_login' name='user_login'/><br/></p>
  1127. <p><label for='user_email'>E-mail:</label><br/> <input type='text' value='' maxlength='100' size='25' id='user_email' name='user_email'/></p>
  1128. <p>A password will be emailed to you.</p>
  1129. <p class='submit'><input type='submit' name='submit_form' id='submit' value='Register »'/><img id='register_loading_img' src='".WPSC_URL."/images/loading.gif' alt='' title=''></p>
  1130. </form>
  1131. </div>";
  1132. }
  1133. exit();
  1134. }
  1135. }
  1136. /*
  1137. * AJAX stuff stops here, I would put an exit here, but it may screw up other plugins
  1138. //exit();
  1139. */
  1140. }
  1141. if(isset($_POST['language_setting']) && ($_GET['page'] = WPSC_DIR_NAME.'/options.php'))
  1142. {
  1143. if($user_level >= 7)
  1144. {
  1145. update_option('language_setting', $_POST['language_setting']);
  1146. }
  1147. }
  1148. if(isset($_POST['language_setting']) && ($_GET['page'] = WPSC_DIR_NAME.'/options.php'))
  1149. {
  1150. if($user_level >= 7)
  1151. {
  1152. update_option('language_setting', $_POST['language_setting']);
  1153. }
  1154. }
  1155. if(($_GET['rss'] == "true") && ($_GET['rss_key'] == 'key') && ($_GET['action'] == "purchase_log"))
  1156. {
  1157. $sql = "SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `date`!='' ORDER BY `date` DESC";
  1158. $purchase_log = $wpdb->get_results($sql,ARRAY_A);
  1159. header("Content-Type: application/xml; charset=UTF-8");
  1160. header('Content-Disposition: inline; filename="WP_E-Commerce_Purchase_Log.rss"');
  1161. $output = '';
  1162. $output .= "<?xml version='1.0'?>\n\r";
  1163. $output .= "<rss version='2.0'>\n\r";
  1164. $output .= " <chann…

Large files files are truncated, but you can click here to view the full file