PageRenderTime 72ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/alx/barceloneta
PHP | 1462 lines | 1184 code | 191 blank | 87 comment | 277 complexity | 428f700294d64641378d3c9cf1dee31f MD5 | raw file

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

  1. <?php
  2. include_once('tagging_functions.php');
  3. include_once('google_base_functions.php');
  4. $category_data = null;
  5. function topcategorylist() {
  6. global $wpdb,$category_data;
  7. $siteurl = get_option('siteurl');
  8. $url = $siteurl."/wp-admin/admin.php?page=".WPSC_DIR_NAME."/display-items.php";
  9. $options = "";
  10. $options .= "<option value='$url'>".TXT_WPSC_ALLCATEGORIES."</option>\r\n";
  11. $options .= top_category_options(null, 0, $_GET['catid']);
  12. $concat .= "<select name='category' onChange='categorylist(this.options[this.selectedIndex].value)'>".$options."</select>\r\n";
  13. return $concat;
  14. }
  15. function top_category_options($category_id = null, $iteration = 0, $selected_id = null) {
  16. /*
  17. * Displays the category forms for adding and editing products
  18. * Recurses to generate the branched view for subcategories
  19. */
  20. global $wpdb;
  21. $siteurl = get_option('siteurl');
  22. $url = $siteurl."/wp-admin/admin.php?page=".WPSC_DIR_NAME."/display-items.php";
  23. if(is_numeric($category_id)) {
  24. $values = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_categories` WHERE `active`='1' AND `category_parent` = '$category_id' ORDER BY `id` ASC",ARRAY_A);
  25. } else {
  26. $values = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_categories` WHERE `active`='1' AND `category_parent` = '0' ORDER BY `id` ASC",ARRAY_A);
  27. }
  28. foreach((array)$values as $option) {
  29. if($selected_id == $option['id']) {
  30. $selected = "selected='selected'";
  31. }
  32. $output .= "<option $selected value='$url&amp;catid=".$option['id']."'>".str_repeat("-", $iteration).stripslashes($option['name'])."</option>\r\n";
  33. $output .= top_category_options($option['id'], $iteration+1, $selected_id);
  34. $selected = "";
  35. }
  36. return $output;
  37. }
  38. function brandslist($current_brand = '') {
  39. global $wpdb;
  40. $options = "";
  41. $options .= "<option $selected value='0'>".TXT_WPSC_SELECTABRAND."</option>\r\n";
  42. $values = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_brands` WHERE `active`='1' ORDER BY `id` ASC",ARRAY_A);
  43. foreach((array)$values as $option) {
  44. if($curent_category == $option['id']) {
  45. $selected = "selected='selected'";
  46. }
  47. $options .= "<option $selected value='".$option['id']."'>".$option['name']."</option>\r\n";
  48. $selected = "";
  49. }
  50. $concat .= "<select name='brand'>".$options."</select>\r\n";
  51. return $concat;
  52. }
  53. function variationslist($current_variation = '') {
  54. global $wpdb;
  55. $options = "";
  56. $values = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_variations` ORDER BY `id` ASC",ARRAY_A);
  57. $options .= "<option $selected value='0'>".TXT_WPSC_PLEASECHOOSE."</option>\r\n";
  58. foreach((array)$values as $option) {
  59. if($current_brand == $option['id']) {
  60. $selected = "selected='selected'";
  61. }
  62. $options .= "<option $selected value='".$option['id']."'>".$option['name']."</option>\r\n";
  63. $selected = "";
  64. }
  65. $concat .= "<select name='variations' onChange='add_variation_value_list(this.options[this.selectedIndex].value)'>".$options."</select>\r\n";
  66. return $concat;
  67. }
  68. /*
  69. * Makes the order changes
  70. */
  71. if(is_numeric($_GET['catid']) && is_numeric($_GET['product_id']) && ($_GET['position_action'] != ''))
  72. {
  73. $position_cat_id = $_GET['catid'];
  74. $position_prod_id = $_GET['product_id'];
  75. $current_order_row = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_order` WHERE `category_id` IN('$position_cat_id') AND `product_id` IN('$position_prod_id') LIMIT 1;",ARRAY_A);
  76. $current_order_row = $current_order_row[0];
  77. switch($_GET['position_action'])
  78. {
  79. case 'top':
  80. if($current_order_row['order'] > 0)
  81. {
  82. $check_existing = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_order` WHERE `category_id` IN('$position_cat_id') AND `order` IN('0') LIMIT 1;",ARRAY_A);
  83. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = '0' WHERE `category_id` IN('$position_cat_id') AND `product_id` IN('$position_prod_id') LIMIT 1;");
  84. if($check_existing != null)
  85. {
  86. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = (`order` + 1) WHERE `category_id` IN('$position_cat_id') AND `product_id` NOT IN('$position_prod_id') AND `order` < '".$current_order_row['order']."'");
  87. }
  88. }
  89. break;
  90. case 'up':
  91. if($current_order_row['order'] > 0)
  92. {
  93. $target_rows = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_order` WHERE `category_id` IN ('".$position_cat_id."') AND `order` <= '".$current_order_row['order']."' ORDER BY `order` DESC LIMIT 2",ARRAY_A);
  94. //exit("<pre>".print_r($target_rows,true)."</pre>");
  95. if(count($target_rows) == 2)
  96. {
  97. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = '".$target_rows[1]['order']."' WHERE `category_id` IN('$position_cat_id') AND `product_id` IN('".$target_rows[0]['product_id']."') LIMIT 1");
  98. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = '".$target_rows[0]['order']."' WHERE `category_id` IN('$position_cat_id') AND `product_id` IN('".$target_rows[1]['product_id']."') LIMIT 1");
  99. }
  100. }
  101. break;
  102. case 'down':
  103. $target_rows = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_order` WHERE `category_id` IN ('".$position_cat_id."') AND `order` >= '".$current_order_row['order']."' ORDER BY `order` ASC LIMIT 2",ARRAY_A);
  104. //exit("<pre>".print_r($target_rows,true)."</pre>");
  105. if(count($target_rows) == 2)
  106. {
  107. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = '".$target_rows[1]['order']."' WHERE `category_id` IN('$position_cat_id') AND `product_id` IN('".$target_rows[0]['product_id']."') LIMIT 1");
  108. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = '".$target_rows[0]['order']."' WHERE `category_id` IN('$position_cat_id') AND `product_id` IN('".$target_rows[1]['product_id']."') LIMIT 1");
  109. }
  110. break;
  111. case 'bottom':
  112. $end_row = $wpdb->get_results("SELECT MAX( `order` ) AS `order` FROM `".$wpdb->prefix."product_order` WHERE `category_id` IN ('".$position_cat_id."') LIMIT 1",ARRAY_A);
  113. $end_order_number = $end_row[0]['order'];
  114. //exit($current_order_row['order'] . " | " . $end_order_number);
  115. if($current_order_row['order'] < $end_order_number)
  116. {
  117. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = '$end_order_number' WHERE `category_id` IN('$position_cat_id') AND `product_id` IN('$position_prod_id') LIMIT 1;");
  118. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order` = (`order` - 1) WHERE `category_id` IN('$position_cat_id') AND `product_id` NOT IN('$position_prod_id') AND `order` > '".$current_order_row['order']."'");
  119. }
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. /*
  126. * Adds new products
  127. */
  128. if($_POST['submit_action'] == 'add') {
  129. // well, there is simply no way to do this other than the blatantly obvious, so here it is
  130. if(!is_callable('getshopped_item_limit') || (@getshopped_item_limit() !== false)) {
  131. //Allen's Change for Google base
  132. if (isset($_GET['token']) || isset($_SESSION['google_base_sessionToken'])) {
  133. $sessionToken=exchangeToken($_GET['token']);
  134. $_SESSION['google_base_sessionToken'] = $sessionToken;
  135. if (isset($_SESSION['google_base_sessionToken']))
  136. $sessionToken=$_SESSION['google_base_sessionToken'];
  137. postItem($_POST['name'], $_POST['price'], $_POST['description'], $sessionToken);
  138. }
  139. //Google base change ends here
  140. $file_name = null;
  141. if($_POST['file_url'] != null) {
  142. $url_array = array_reverse(explode("/",$_POST['file_url']));
  143. if(is_file(WPSC_FILE_DIR.$url_array[0])) {
  144. $file_name = $url_array[0];
  145. }
  146. }
  147. $thumbnail_image = '';
  148. $file = 0;
  149. /* handle adding file uploads here */
  150. if(!empty($_FILES['file']['name'])) {
  151. $fileid = wpsc_item_process_file('add');
  152. $file = $fileid;
  153. } else if (($_POST['select_product_file'] != '')) {
  154. $fileid = wpsc_item_reassign_file($_POST['select_product_file'], 'add');
  155. $file = $fileid;
  156. }
  157. if(is_numeric($_POST['quantity']) && ($_POST['quantity_limited'] == "yes")) {
  158. $quantity_limited = 1;
  159. $quantity = (int)$_POST['quantity'];
  160. } else {
  161. $quantity_limited = 0;
  162. $quantity = 0;
  163. }
  164. if($_POST['special'] == 'yes') {
  165. $special = 1;
  166. if(is_numeric($_POST['special_price'])) {
  167. $special_price = $_POST['price'] - $_POST['special_price'];
  168. }
  169. } else {
  170. $special = 0;
  171. $special_price = '';
  172. }
  173. if($_POST['notax'] == 'yes') {
  174. $notax = 1;
  175. } else {
  176. $notax = 0;
  177. }
  178. if($_POST['display_frontpage'] == "yes") {
  179. $display_frontpage = 1;
  180. } else {
  181. $display_frontpage = 0;
  182. }
  183. if($_POST['donation'] == "yes") {
  184. $is_donation = 1;
  185. } else {
  186. $is_donation = 0;
  187. }
  188. if($_POST['no_shipping'] == "yes") {
  189. $no_shipping = 1;
  190. } else {
  191. $no_shipping = 0;
  192. }
  193. //modified for USPS
  194. $insertsql = "INSERT INTO `".$wpdb->prefix."product_list` ( `name` , `description` , `additional_description` , `price`, `weight`, `weight_unit`, `pnp`, `international_pnp`, `file` , `image` , `brand`, `quantity_limited`, `quantity`, `special`, `special_price`, `display_frontpage`,`notax`, `donation`, `no_shipping`, `thumbnail_image`, `thumbnail_state`) VALUES ('".$wpdb->escape($_POST['name'])."', '".$wpdb->escape($_POST['description'])."', '".$wpdb->escape($_POST['additional_description'])."','".(float)$wpdb->escape(str_replace(",","",$_POST['price']))."','".$wpdb->escape((float)$_POST['weight'])."','".$wpdb->escape($_POST['weight_unit'])."', '".$wpdb->escape((float)$_POST['pnp'])."', '".$wpdb->escape($_POST['international_pnp'])."', '".(int)$file."', '".$image."', '0', '$quantity_limited','$quantity','$special','$special_price', '$display_frontpage', '$notax', '$is_donation', '$no_shipping', '".$wpdb->escape($thumbnail_image)."', '" . $wpdb->escape($_POST['image_resize']) . "');";
  195. if($wpdb->query($insertsql)) {
  196. $product_id_data = $wpdb->get_results("SELECT LAST_INSERT_ID() AS `id` FROM `".$wpdb->prefix."product_list` LIMIT 1",ARRAY_A);
  197. $product_id = $product_id_data[0]['id'];
  198. if(function_exists('wp_insert_term')) {
  199. product_tag_init();
  200. $tags = $_POST['product_tag'];
  201. if ($tags!="") {
  202. $tags = explode(',',$tags);
  203. foreach($tags as $tag) {
  204. $tt = wp_insert_term((string)$tag, 'product_tag');
  205. }
  206. $return = wp_set_object_terms($product_id, $tags, 'product_tag');
  207. }
  208. }
  209. /* Handle new image uploads here */
  210. $image = wpsc_item_process_image($product_id);
  211. /* Process extra meta values */
  212. if($_POST['productmeta_values'] != null) {
  213. foreach((array)$_POST['productmeta_values'] as $key => $value) {
  214. if(get_product_meta($product_id, $key) != false) {
  215. update_product_meta($product_id, $key, $value);
  216. } else {
  217. add_product_meta($product_id, $key, $value);
  218. }
  219. }
  220. }
  221. if($_POST['new_custom_meta'] != null) {
  222. foreach((array)$_POST['new_custom_meta']['name'] as $key => $name) {
  223. $value = $_POST['new_custom_meta']['value'][(int)$key];
  224. if(($name != '') && ($value != '')) {
  225. add_product_meta($product_id, $name, $value, false, true);
  226. }
  227. }
  228. }
  229. do_action('wpsc_product_form_submit', $product_id);
  230. /* Add tidy url name */
  231. $tidied_name = trim($_POST['name']);
  232. $tidied_name = strtolower($tidied_name);
  233. $url_name = preg_replace(array("/(\s)+/","/[^\w-]+/i"), array("-", ''), $tidied_name);
  234. $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '$url_name', '')) AS `max_number` FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `meta_key` IN ('url_name') AND `meta_value` REGEXP '^($url_name){1}(\d)*$' ",ARRAY_A);
  235. $extension_number = '';
  236. if($similar_names['count'] > 0) {
  237. $extension_number = (int)$similar_names['max_number']+1;
  238. }
  239. $url_name .= $extension_number;
  240. add_product_meta($product_id, 'url_name', $url_name,true);
  241. if(($_FILES['extra_image'] != null) && function_exists('edit_submit_extra_images')) {
  242. $var = edit_submit_extra_images($product_id);
  243. }
  244. $variations_procesor = new nzshpcrt_variations;
  245. if($_POST['variation_values'] != null) {
  246. $variations_procesor->add_to_existing_product($product_id,$_POST['variation_values']);
  247. }
  248. if($_POST['variation_priceandstock'] != null) {
  249. $variations_procesor->update_variation_values($product_id, $_POST['variation_priceandstock']);
  250. // exit("<pre>".print_r($_POST,true)."</pre>");
  251. }
  252. //$variations_procesor->edit_add_product_values($_POST['prodid'],$_POST['edit_add_variation_values']);
  253. $counter = 0;
  254. $item_list = '';
  255. if(count($_POST['category']) > 0) {
  256. foreach($_POST['category'] as $category_id) {
  257. $check_existing = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."item_category_associations` WHERE `product_id` = ".$product_id." AND `category_id` = '$category_id' LIMIT 1");
  258. if($check_existing == null) {
  259. $wpdb->query("INSERT INTO `".$wpdb->prefix."item_category_associations` ( `product_id` , `category_id` ) VALUES ( '".$product_id."', '".$category_id."');");
  260. }
  261. }
  262. }
  263. // send the pings out.
  264. wpsc_ping();
  265. $display_added_product = "filleditform(".$product_id.");";
  266. echo "<div class='updated'><p align='center'>".TXT_WPSC_ITEMHASBEENADDED."</p></div>";
  267. } else {
  268. echo "<div class='updated'><p align='center'>".TXT_WPSC_ITEMHASNOTBEENADDED."</p></div>";
  269. }
  270. } else {
  271. echo "<div class='updated'><p align='center'>".TXT_WPSC_MAX_PRODUCTS."</p></div>";
  272. }
  273. }
  274. if($_GET['submit_action'] == "remove_set")
  275. {
  276. if(is_numeric($_GET['product_id']) && is_numeric($_GET['variation_assoc_id']))
  277. {
  278. $product_id = $_GET['product_id'];
  279. $variation_assoc_id = $_GET['variation_assoc_id'];
  280. $check_association_id = $wpdb->get_var("SELECT `id` FROM `".$table_prefix."variation_associations` WHERE `id` = '$variation_assoc_id' LIMIT 1");
  281. if(($variation_assoc_id > 0) && ($variation_assoc_id == $check_association_id))
  282. {
  283. $variation_association = $wpdb->get_row("SELECT * FROM `".$table_prefix."variation_associations` WHERE `id` = '$variation_assoc_id' LIMIT 1",ARRAY_A);
  284. $delete_variation_sql = "DELETE FROM `".$table_prefix."variation_associations` WHERE `id` = '$variation_assoc_id' LIMIT 1";
  285. $wpdb->query($delete_variation_sql);
  286. //echo("<pre>".print_r($variation_association,true)."</pre>");
  287. if($variation_association != null)
  288. {
  289. $variation_id = $variation_association['variation_id'];
  290. $delete_value_sql = "DELETE FROM `".$table_prefix."variation_values_associations` WHERE `product_id` = '$product_id' AND `variation_id` = '$variation_id'";
  291. //exit($delete_value_sql);
  292. $wpdb->query($delete_value_sql);
  293. }
  294. echo "<div class='updated'><p align='center'>".TXT_WPSC_PRODUCTHASBEENEDITED."</p></div>";
  295. }
  296. }
  297. }
  298. if($_POST['submit_action'] == "edit") {
  299. // exit("<pre>".print_r($_POST,true)."</pre>");
  300. $id = $_POST['prodid'];
  301. if(function_exists('edit_submit_extra_images'))
  302. {
  303. if(($_FILES['extra_image'] != null))
  304. {
  305. $var = edit_submit_extra_images($id);
  306. }
  307. }
  308. if(function_exists('edit_extra_images'))
  309. {
  310. $var = edit_extra_images($id);
  311. }
  312. $file_name = null;
  313. if($_POST['file_url'] != null) {
  314. $url_array = array_reverse(explode("/",$_POST['file_url']));
  315. //exit("<pre>".print_r($url_array,true)."</pre>");
  316. if(is_file(WPSC_FILE_DIR.$url_array[0])) {
  317. $file_name = $url_array[0];
  318. }
  319. }
  320. //written by allen
  321. if(isset($_POST['product_tags'])) {
  322. $imtags = $_POST['product_tags'];
  323. $tags = explode(',',$imtags);
  324. product_tag_init();
  325. if(is_array($tags)) {
  326. foreach((array)$tags as $tag){
  327. $tt = wp_insert_term((string)$tag, 'product_tag');
  328. }
  329. }
  330. wp_set_object_terms($id, $tags, 'product_tag');
  331. }
  332. //end of written by allen
  333. if (isset($_POST['external_link'])) {
  334. add_product_meta($_POST['prodid'], 'external_link', $_POST['external_link'],true);
  335. }
  336. if (isset($_POST['merchant_notes'])) {
  337. $id = (int)$_POST['prodid'];
  338. $notes = $_POST['merchant_notes'];
  339. $updatelink_sql = "SELECT * FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `product_id` = '$id' AND `meta_key`='merchant_notes'";
  340. $updatelink_data = $wpdb->get_results($updatelink_sql, ARRAY_A);
  341. if (count($updatelink_data)>0){
  342. $updatelink_sql = "UPDATE `".$wpdb->prefix."wpsc_productmeta` SET `meta_value` = '$notes' WHERE `product_id` = '$id' AND `meta_key`='merchant_notes'";
  343. $updatelink_data = $wpdb->query($updatelink_sql);
  344. } else {
  345. $updatelink_sql = "INSERT INTO `".$wpdb->prefix."wpsc_productmeta` (`product_id`,`meta_key`,`meta_value`) VALUES('$id','merchant_notes' ,'$notes')";
  346. $updatelink_data = $wpdb->query($updatelink_sql);
  347. }
  348. }
  349. // if (isset($_POST['engrave'])) {
  350. // $id = $_POST['prodid'];
  351. // $engrave = $_POST['engrave'];
  352. // $updatelink_sql = "SELECT * FROM ".$wpdb->prefix."wpsc_productmeta WHERE product_id = $id AND meta_key='merchant_notes'";
  353. // $updatelink_data = $wpdb->get_results($updatelink_sql, ARRAY_A);
  354. // if (count($updatelink_data)>0){
  355. // $updatelink_sql = "UPDATE ".$wpdb->prefix."wpsc_productmeta SET meta_value = '$notes' WHERE product_id = $id AND meta_key='merchant_notes'";
  356. // $updatelink_data = $wpdb->query($updatelink_sql);
  357. // } else {
  358. // $updatelink_sql = "INSERT INTO ".$wpdb->prefix."wpsc_productmeta VALUES('',$id,'merchant_notes' ,'$notes')";
  359. // $updatelink_data = $wpdb->query($updatelink_sql);
  360. // }
  361. // }
  362. /* handle editing file uploads here */
  363. if(!empty($_FILES['file']['name'])) {
  364. $fileid = wpsc_item_process_file('edit');
  365. $file = $fileid;
  366. } else if (($_POST['select_product_file'] != '')) {
  367. $fileid = wpsc_item_reassign_file($_POST['select_product_file'], 'edit');
  368. $file = $fileid;
  369. }
  370. if(file_exists($_FILES['preview_file']['tmp_name'])) {
  371. $fileid = $wpdb->get_var("SELECT `file` FROM `".$wpdb->prefix."product_list` WHERE `id` = '$id' LIMIT 1");
  372. copy($_FILES['preview_file']['tmp_name'], (WPSC_PREVIEW_DIR.basename($_FILES['preview_file']['name'])));
  373. $mimetype = wpsc_get_mimetype(WPSC_PREVIEW_DIR.basename($_FILES['preview_file']['name']));
  374. $wpdb->query("UPDATE `".$wpdb->prefix."product_files` SET `preview` = '".$wpdb->escape(basename($_FILES['preview_file']['name']))."', `preview_mimetype` = '".$mimetype."' WHERE `id` = '$fileid' LIMIT 1");
  375. }
  376. /* Handle new image uploads here */
  377. $image = wpsc_item_process_image();
  378. if(is_numeric($_POST['prodid'])) {
  379. if(($_POST['image_resize'] == 1 || $_POST['image_resize'] == 2) && ($image == '')) {
  380. /* resize the image if directed to do so and no new image is supplied */
  381. $image_data = $wpdb->get_row("SELECT `id`,`image` FROM `".$wpdb->prefix."product_list` WHERE `id`=".$_POST['prodid']." LIMIT 1",ARRAY_A);
  382. // prevent images from being replaced by those from other products
  383. $check_multiple_use = $wpdb->get_var("SELECT COUNT(`image`) AS `count` FROM `".$wpdb->prefix."product_list` WHERE `image`='".$image_data['image']."'");
  384. if($check_multiple_use > 1) {
  385. $new_filename = $image_data['id']."_".$image_data['image'];
  386. if(file_exists(WPSC_THUMBNAIL_DIR.$image_data['image']) && ($image_data['image'] != null)) {
  387. copy(WPSC_THUMBNAIL_DIR.$image_data['image'], WPSC_THUMBNAIL_DIR.$new_filename);
  388. }
  389. if(file_exists(WPSC_IMAGE_DIR.$image_data['image']) && ($image_data['image'] != null)) {
  390. copy(WPSC_IMAGE_DIR.$image_data['image'], WPSC_IMAGE_DIR.$new_filename);
  391. }
  392. $wpdb->query("UPDATE `".$wpdb->prefix."product_list` SET `image` = '".$new_filename."' WHERE `id`='".$image_data['id']."' LIMIT 1");
  393. $image_data = $wpdb->get_row("SELECT `id`,`image` FROM `".$wpdb->prefix."product_list` WHERE `id`=".$_POST['prodid']." LIMIT 1",ARRAY_A);
  394. }
  395. if(file_exists(WPSC_THUMBNAIL_DIR.$image_data['image']) && ($image_data['image'] != '')) {
  396. $imagepath = WPSC_IMAGE_DIR . $image_data['image'];
  397. $image_output = WPSC_THUMBNAIL_DIR . $image_data['image'];
  398. switch($_POST['image_resize']) {
  399. case 1:
  400. $height = get_option('product_image_height');
  401. $width = get_option('product_image_width');
  402. break;
  403. case 2:
  404. $height = $_POST['height'];
  405. $width = $_POST['width'];
  406. break;
  407. }
  408. image_processing($imagepath, $image_output, $width, $height);
  409. }
  410. }
  411. if(is_numeric($_POST['prodid'])) {
  412. $counter = 0;
  413. $item_list = '';
  414. if(count($_POST['category']) > 0) {
  415. foreach($_POST['category'] as $category_id) {
  416. $category_id = (int)$category_id; // force it to be an integer rather than check if it is one
  417. $check_existing = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."item_category_associations` WHERE `product_id` = ".$id." AND `category_id` = '$category_id' LIMIT 1");
  418. if($check_existing == null) {
  419. $wpdb->query("INSERT INTO `".$wpdb->prefix."item_category_associations` ( `product_id` , `category_id` ) VALUES ('".$id."', '".$category_id."');");
  420. }
  421. if($counter > 0) {
  422. $item_list .= ", ";
  423. }
  424. $item_list .= "'".$category_id."'";
  425. $counter++;
  426. }
  427. } else {
  428. $item_list = "'0'";
  429. }
  430. $wpdb->query("DELETE FROM `".$wpdb->prefix."item_category_associations` WHERE `product_id`= '$id' AND `category_id` NOT IN (".$item_list.")");
  431. }
  432. $key = Array();
  433. if(is_numeric($_POST['quantity']) && ($_POST['quantity_limited'] == "yes")){
  434. $quantity_limited = 1;
  435. $quantity = $_POST['quantity'];
  436. } else {
  437. $quantity_limited = 0;
  438. $quantity = 0;
  439. }
  440. if($_POST['special'] == 'yes') {
  441. $special = 1;
  442. if(is_numeric($_POST['special_price'])) {
  443. $special_price = $_POST['price'] - $_POST['special_price'];
  444. }
  445. } else {
  446. $special = 0;
  447. $special_price = '';
  448. }
  449. if($_POST['notax'] == 'yes') {
  450. $notax = 1;
  451. } else {
  452. $notax = 0;
  453. }
  454. if($_POST['display_frontpage'] == "yes") {
  455. $display_frontpage = 1;
  456. } else {
  457. $display_frontpage = 0;
  458. }
  459. if($_POST['donation'] == "yes") {
  460. $is_donation = 1;
  461. } else {
  462. $is_donation = 0;
  463. }
  464. if($_POST['no_shipping'] == "yes") {
  465. $no_shipping = 1;
  466. } else {
  467. $no_shipping = 0;
  468. }
  469. $updatesql = "UPDATE `".$wpdb->prefix."product_list` SET `name` = '".$wpdb->escape($_POST['title'])."', `description` = '".$wpdb->escape($_POST['description'])."', `additional_description` = '".$wpdb->escape($_POST['additional_description'])."', `price` = '".$wpdb->escape(str_replace(",","",$_POST['price']))."', `pnp` = '".(float)$wpdb->escape($_POST['pnp'])."', `international_pnp` = '".(float)$wpdb->escape($_POST['international_pnp'])."', `brand` = '0', quantity_limited = '".$quantity_limited."', `quantity` = '".(int)$quantity."', `special`='$special', `special_price`='$special_price', `display_frontpage`='$display_frontpage', `notax`='$notax', `donation`='$is_donation', `no_shipping` = '$no_shipping', `weight` = '".$wpdb->escape($_POST['weight'])."', `weight_unit` = '".$wpdb->escape($_POST['weight_unit'])."' WHERE `id`='".$_POST['prodid']."' LIMIT 1";
  470. $wpdb->query($updatesql);
  471. if(($_FILES['image']['name'] != null) && ($image != null)) {
  472. $wpdb->query("UPDATE `".$wpdb->prefix."product_list` SET `image` = '".$image."' WHERE `id`='".$_POST['prodid']."' LIMIT 1");
  473. }
  474. if($_POST['productmeta_values'] != null) {
  475. foreach((array)$_POST['productmeta_values'] as $key => $value) {
  476. if(get_product_meta($_POST['prodid'], $key) != false) {
  477. update_product_meta($_POST['prodid'], $key, $value);
  478. } else {
  479. add_product_meta($_POST['prodid'], $key, $value);
  480. }
  481. }
  482. }
  483. if($_POST['new_custom_meta'] != null) {
  484. foreach((array)$_POST['new_custom_meta']['name'] as $key => $name) {
  485. $value = $_POST['new_custom_meta']['value'][(int)$key];
  486. if(($name != '') && ($value != '')) {
  487. add_product_meta($_POST['prodid'], $name, $value, false, true);
  488. }
  489. }
  490. }
  491. if($_POST['custom_meta'] != null) {
  492. foreach((array)$_POST['custom_meta'] as $key => $values) {
  493. if(($values['name'] != '') && ($values['value'] != '')) {
  494. $wpdb->query("UPDATE `".$wpdb->prefix."wpsc_productmeta` SET `meta_key` = '".$wpdb->escape($values['name'])."', `meta_value` = '".$wpdb->escape($values['value'])."' WHERE `id` IN ('".(int)$key."')LIMIT 1 ;");
  495. // echo "UPDATE `".$wpdb->prefix."wpsc_productmeta` SET `meta_key` = '".$wpdb->escape($values['name'])."', `meta_value` = '".$wpdb->escape($values['value'])."' WHERE `id` IN ('".(int)$key."') LIMIT 1 ;";
  496. //add_product_meta($_POST['prodid'], $values['name'], $values['value'], false, true);
  497. }
  498. }
  499. }
  500. do_action('wpsc_product_form_submit', $product_id);
  501. /* Add or edit tidy url name */
  502. $tidied_name = trim($_POST['title']);
  503. $tidied_name = strtolower($tidied_name);
  504. $url_name = preg_replace(array("/(\s)+/","/[^\w-]+/i"), array("-", ''), $tidied_name);
  505. $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '$url_name', '')) AS `max_number` FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `meta_key` IN ('url_name') AND `meta_value` REGEXP '^($url_name){1}(\d)*$' ",ARRAY_A);
  506. $extension_number = '';
  507. if($similar_names['count'] > 0) {
  508. $extension_number = (int)$similar_names['max_number']+1;
  509. }
  510. $stored_name = get_product_meta($_POST['prodid'], 'url_name', true);
  511. if(get_product_meta($_POST['prodid'], 'url_name', true) != false) {
  512. $current_url_name = get_product_meta($_POST['prodid'], 'url_name');
  513. if($current_url_name[0] != $url_name) {
  514. $url_name .= $extension_number;
  515. update_product_meta($_POST['prodid'], 'url_name', $url_name);
  516. }
  517. } else {
  518. $url_name .= $extension_number;
  519. add_product_meta($_POST['prodid'], 'url_name', $url_name, true);
  520. }
  521. /* update thumbnail images */
  522. if(!($thumbnail_image == null && $_POST['image_resize'] == 3 && $_POST['current_thumbnail_image'] != null)) {
  523. if($thumbnail_image != null) {
  524. $wpdb->query("UPDATE `".$wpdb->prefix."product_list` SET `thumbnail_image` = '".$thumbnail_image."' WHERE `id`='".$_POST['prodid']."' LIMIT 1");
  525. }
  526. }
  527. $image_resize = $_POST['image_resize'];
  528. if(!is_numeric($image_resize) || ($image_resize < 1)) {
  529. $image_resize = 0;
  530. }
  531. $wpdb->query("UPDATE `".$wpdb->prefix."product_list` SET `thumbnail_state` = '".$image_resize."' WHERE `id`='".$_POST['prodid']."' LIMIT 1");
  532. if($_POST['deleteimage'] == 1) {
  533. $wpdb->query("UPDATE `".$wpdb->prefix."product_list` SET `image` = '' WHERE `id`='".$_POST['prodid']."' LIMIT 1");
  534. }
  535. $variations_procesor = new nzshpcrt_variations;
  536. if($_POST['variation_values'] != null) {
  537. //$variations_procesor->add_to_existing_product($_POST['prodid'],$_POST['variation_values']);
  538. }
  539. if($_POST['edit_variation_values'] != null) {
  540. $variations_procesor->edit_product_values($_POST['prodid'],$_POST['edit_variation_values']);
  541. }
  542. if($_POST['edit_add_variation_values'] != null) {
  543. $variations_procesor->edit_add_product_values($_POST['prodid'],$_POST['edit_add_variation_values']);
  544. }
  545. if($_POST['variation_priceandstock'] != null) {
  546. $variations_procesor->update_variation_values($_POST['prodid'], $_POST['variation_priceandstock']);
  547. }
  548. // send the pings out.
  549. wpsc_ping();
  550. echo "<div class='updated'><p align='center'>".TXT_WPSC_PRODUCTHASBEENEDITED."</p></div>";
  551. }
  552. }
  553. if(is_numeric($_GET['deleteid'])) {
  554. $wpdb->query("DELETE FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `product_id` = '".$_GET['deleteid']."' AND `meta_key` IN ('url_name')");
  555. $wpdb->query("UPDATE `".$wpdb->prefix."product_list` SET `active` = '0' WHERE `id`='".$_GET['deleteid']."' LIMIT 1");
  556. }
  557. /*
  558. * Sort out the searching of the products
  559. */
  560. if($_GET['search_products']) {
  561. $search_string_title = "%".$wpdb->escape(stripslashes($_GET['search_products']))."%";
  562. $search_string_description = "% ".$wpdb->escape(stripslashes($_GET['search_products']))."%";
  563. $search_sql = "AND (`".$wpdb->prefix."product_list`.`name` LIKE '".$search_string_title."' OR `".$wpdb->prefix."product_list`.`description` LIKE '".$search_string_description."')";
  564. $search_string = $_GET['search_products'];
  565. } else {
  566. $search_sql = '';
  567. $search_string = '';
  568. }
  569. /*
  570. * Gets the product list, commented to make it stick out more, as it is hard to notice
  571. */
  572. if(is_numeric($_GET['catid'])) { // if we are getting items from only one category, this is a monster SQL query to do this with the product order
  573. $sql = "SELECT `".$wpdb->prefix."product_list`.`id` , `".$wpdb->prefix."product_list`.`name` , `".$wpdb->prefix."product_list`.`price` , `".$wpdb->prefix."product_list`.`image`, `".$wpdb->prefix."item_category_associations`.`category_id`,`".$wpdb->prefix."product_order`.`order`, IF(ISNULL(`".$wpdb->prefix."product_order`.`order`), 0, 1) AS `order_state`
  574. FROM `".$wpdb->prefix."product_list`
  575. LEFT JOIN `".$wpdb->prefix."item_category_associations` ON `".$wpdb->prefix."product_list`.`id` = `".$wpdb->prefix."item_category_associations`.`product_id`
  576. LEFT JOIN `".$wpdb->prefix."product_order` ON ( (
  577. `".$wpdb->prefix."product_list`.`id` = `".$wpdb->prefix."product_order`.`product_id`
  578. )
  579. AND (
  580. `".$wpdb->prefix."item_category_associations`.`category_id` = `".$wpdb->prefix."product_order`.`category_id`
  581. ) )
  582. WHERE `".$wpdb->prefix."product_list`.`active` = '1' $search_sql
  583. AND `".$wpdb->prefix."item_category_associations`.`category_id`
  584. IN (
  585. '".$_GET['catid']."'
  586. )
  587. ORDER BY `order_state` DESC,`".$wpdb->prefix."product_order`.`order` ASC, `".$wpdb->prefix."product_list`.`id` DESC";
  588. } else {
  589. $itempp = 20;
  590. if ($_GET['pnum']!='all') {
  591. $page = (int)$_GET['pnum'];
  592. $start = $page * $itempp;
  593. $sql = "SELECT DISTINCT * FROM `{$wpdb->prefix}product_list` WHERE `active`='1' $search_sql LIMIT $start,$itempp";
  594. } else {
  595. $sql = "SELECT DISTINCT * FROM `{$wpdb->prefix}product_list` WHERE `active`='1' $search_sql";
  596. }
  597. }
  598. $product_list = $wpdb->get_results($sql,ARRAY_A);
  599. $num_products = $wpdb->get_var("SELECT COUNT(DISTINCT `id`) FROM `".$wpdb->prefix."product_list` WHERE `active`='1' $search_sql");
  600. /*
  601. * The product list is stored in $product_list now
  602. */
  603. /*
  604. * Detects if the directories for images, thumbnails and files are writeable, if they are not, tells the user to make them writeable.
  605. */
  606. $unwriteable_directories = Array();
  607. if(!is_writable(WPSC_FILE_DIR)) {
  608. $unwriteable_directories[] = WPSC_FILE_DIR;
  609. }
  610. if(!is_writable(WPSC_PREVIEW_DIR)) {
  611. $unwriteable_directories[] = WPSC_PREVIEW_DIR;
  612. }
  613. if(!is_writable(WPSC_IMAGE_DIR)) {
  614. $unwriteable_directories[] = WPSC_IMAGE_DIR;
  615. }
  616. if(!is_writable(WPSC_THUMBNAIL_DIR)) {
  617. $unwriteable_directories[] = WPSC_THUMBNAIL_DIR;
  618. }
  619. if(!is_writable(WPSC_CATEGORY_DIR)) {
  620. $unwriteable_directories[] = WPSC_CATEGORY_DIR;
  621. }
  622. if(count($unwriteable_directories) > 0)
  623. {
  624. echo "<div class='error'>".str_replace(":directory:","<ul><li>".implode($unwriteable_directories, "</li><li>")."</li></ul>",TXT_WPSC_WRONG_FILE_PERMS)."</div>";
  625. }
  626. ?>
  627. <div class="wrap">
  628. <h2><?php echo TXT_WPSC_DISPLAYPRODUCTS;?></h2>
  629. <?php
  630. ?>
  631. <script language='javascript' type='text/javascript'>
  632. function conf() {
  633. var check = confirm("<?php echo TXT_WPSC_SURETODELETEPRODUCT;?>");
  634. if(check) {
  635. return true;
  636. } else {
  637. return false;
  638. }
  639. }
  640. <?php
  641. if(is_numeric($_POST['prodid'])) {
  642. echo "filleditform(".$_POST['prodid'].");";
  643. }
  644. else if(is_numeric($_GET['product_id'])) {
  645. echo "filleditform(".$_GET['product_id'].");";
  646. }
  647. echo $display_added_product ;
  648. ?>
  649. </script>
  650. <div class="tablenav wpsc_products_nav">
  651. <div style="width: 500px;" class="alignleft">
  652. <a href='' onclick='return showaddform()' class='add_item_link'><img src='<?php echo WPSC_URL; ?>/images/package_add.png' alt='<?php echo TXT_WPSC_ADD; ?>' title='<?php echo TXT_WPSC_ADD; ?>' />&nbsp;<span><?php echo TXT_WPSC_ADDPRODUCT;?></span></a>
  653. </div>
  654. <div class="alignright">
  655. <?php echo setting_button(); ?>
  656. <a target="_blank" href='http://www.instinct.co.nz/e-commerce/products/' class='about_this_page'><span><?php echo TXT_WPSC_ABOUT_THIS_PAGE;?></span>&nbsp;</a>
  657. </div>
  658. <br class="clear"/>
  659. </div>
  660. <?php
  661. $num = 0;
  662. echo " <table id='productpage'>\n\r";
  663. echo " <tr><td style='padding: 0px;'>\n\r";
  664. echo " <table id='itemlist'>\n\r";
  665. echo " <tr class='firstrowth'>\n\r";
  666. echo " <td colspan='4' style='text-align: left;'>\n\r";
  667. echo "<span id='loadingindicator_span' class='product_loadingindicator'><img id='loadingimage' src='".WPSC_URL."/images/grey-loader.gif' alt='Loading' title='Loading' /></span>";
  668. echo "<strong class='form_group'>".TXT_WPSC_SELECT_PRODUCT."</strong>";
  669. echo " </td>\n\r";
  670. echo " </tr>\n\r";
  671. if(($num_products > 20) || ($search_string != '')) {
  672. echo " <tr class='selectcategory'>\n\r";
  673. echo " <td colspan='3'>\n\r";
  674. echo TXT_WPSC_ADMIN_SEARCH_PRODUCTS.": ";
  675. echo " </td>\n\r";
  676. echo " <td colspan='1'>\n\r";
  677. echo "<div>\n\r";
  678. echo " <form method='GET' action=''>\n\r";
  679. echo "<input type='hidden' value='{$_GET['page']}' name='page'>";
  680. echo "<input type='text' value='{$search_string}' name='search_products' style='width: 115px; padding: 1px;'>";
  681. echo " </form>\n\r";
  682. echo "</div>\n\r";
  683. echo " </td>\n\r";
  684. echo " </tr>\n\r";
  685. }
  686. echo " <tr class='selectcategory'>\n\r";
  687. echo " <td colspan='3'>\n\r";
  688. echo TXT_WPSC_PLEASESELECTACATEGORY.": ";
  689. echo " </td>\n\r";
  690. echo " <td colspan='1'>\n\r";
  691. echo "<div>\n\r";
  692. echo topcategorylist();
  693. //echo "<div style='float: right; width: 160px;'>". topcategorylist() ."</div>";
  694. echo "</div>\n\r";
  695. echo " </td>\n\r";
  696. echo " </tr>\n\r";
  697. if(is_numeric($_GET['catid'])) {
  698. $name_style = 'class="pli_name"';
  699. $price_style = 'class="pli_price"';
  700. $edit_style = 'class="pli_edit"';
  701. } else {
  702. $name_style = '';
  703. $price_style = '';
  704. $edit_style = '';
  705. }
  706. echo " <tr class='firstrow'>\n\r";
  707. echo " <td width='45px'>";
  708. echo "</td>\n\r";
  709. echo " <td ".$name_style.">";
  710. echo TXT_WPSC_NAME;
  711. echo "</td>\n\r";
  712. echo " <td ".$price_style.">";
  713. echo TXT_WPSC_PRICE;
  714. echo "</td>\n\r";
  715. if(!is_numeric($_GET['catid'])) {
  716. echo " <td>";
  717. echo TXT_WPSC_CATEGORIES;
  718. echo "</td>\n\r";
  719. }
  720. echo " </tr>\n\r";
  721. if(is_numeric($_GET['catid'])) {
  722. echo "<tr><td colspan='4' class='category_item_container'>\n\r";
  723. }
  724. if($product_list != null)
  725. {
  726. $order_number = 0;
  727. if(is_numeric($_GET['catid'])){
  728. echo " <form><input type='hidden' name='category_id' id='item_list_category_id' value='".(int)$_GET['catid']."'/></form>";
  729. echo " <div id='sort1' class='groupWrapper'>\n\r";
  730. }
  731. $tablei=1;
  732. foreach($product_list as $product)
  733. {
  734. /*
  735. * Creates order table entries if they are not already present
  736. * No need for extra database queries to determine the highest order number
  737. * anything without one is automatically at the bottom
  738. * so anything with an order number is already processed by the time it starts adding rows
  739. */
  740. if(is_numeric($_GET['catid'])){
  741. echo " <div id='".$product['id']."' class='groupItem'>\n\r";
  742. //echo " <div class='itemHeader'></div>\n\r";
  743. echo " <div class='itemContent'>\n\r";
  744. } else {
  745. if ($tablei==1) {
  746. echo "<tr class='products'>";
  747. } else {
  748. echo "<tr class='productsalt'>";
  749. }
  750. $tablei*=-1;
  751. }
  752. if(is_numeric($_GET['catid'])) {
  753. if($product['order_state'] > 0) {
  754. if($product['order'] > $order_number) {
  755. $order_number = $product['order'];
  756. $order_number++;
  757. }
  758. } else {
  759. $wpdb->query("INSERT INTO `".$wpdb->prefix."product_order` ( `category_id` , `product_id` , `order` ) VALUES ( '".$product['category_id']."', '".$product['id']."', '$order_number');");
  760. $order_number++;
  761. }
  762. }
  763. if(is_numeric($_GET['catid'])) {
  764. echo " <div class='itemHeader pli_img'>\n\r";
  765. echo "<a class='noline' title='Drag to a new position'>";
  766. } else {
  767. echo " <td style='width: 40px;' class='imagecol'>\r\n";
  768. }
  769. if(($product['thumbnail_image'] != null) && file_exists(WPSC_THUMBNAIL_DIR.$product['thumbnail_image'])) { // check for custom thumbnail images
  770. echo "<img title='Drag to a new position' src='".WPSC_THUMBNAIL_URL.$product['thumbnail_image']."' title='".$product['name']."' alt='".$product['name']."' width='35' height='35' />";
  771. } else if(($product['image'] != null) && file_exists(WPSC_THUMBNAIL_DIR.$product['image'])) { // check for automatic thumbnail images
  772. echo "<img title='Drag to a new position' src='".WPSC_THUMBNAIL_URL.$product['image']."' title='".$product['name']."' alt='".$product['name']."' width='35' height='35' />";
  773. } else { // no image, display this fact
  774. echo "<img title='Drag to a new position' src='".WPSC_URL."/no-image-uploaded.gif' title='".$product['name']."' alt='".$product['name']."' width='35' height='35' />";
  775. }
  776. echo "</a>";
  777. if(is_numeric($_GET['catid'])){
  778. echo " </div>\n\r";
  779. } else {
  780. echo "</td><td width='25%'>";
  781. }
  782. if(is_numeric($_GET['catid'])) {
  783. echo " <div class='pli_name'>\n\r";
  784. }
  785. echo "<a href='#' onclick='filleditform(".$product['id'].");return false;'>";
  786. if ($product['name']=='') {
  787. echo "(".TXT_WPSC_NONAME.")";
  788. } else {
  789. echo htmlentities(stripslashes($product['name']), ENT_QUOTES, 'UTF-8');
  790. }
  791. echo "</a>";
  792. if(is_numeric($_GET['catid'])){
  793. echo " </div>\n\r";
  794. } else {
  795. echo "</td><td>";
  796. }
  797. if(is_numeric($_GET['catid'])){
  798. echo " <div class='pli_price'>\n\r";
  799. }
  800. echo nzshpcrt_currency_display($product['price'], 1);
  801. if(is_numeric($_GET['catid'])){
  802. echo " </div>\n\r";
  803. }
  804. if(!is_numeric($_GET['catid'])) {
  805. echo " <td>\n\r";
  806. $category_list = $wpdb->get_results("SELECT `".$wpdb->prefix."product_categories`.`id`,`".$wpdb->prefix."product_categories`.`name` FROM `".$wpdb->prefix."item_category_associations` , `".$wpdb->prefix."product_categories` WHERE `".$wpdb->prefix."item_category_associations`.`product_id` IN ('".$product['id']."') AND `".$wpdb->prefix."item_category_associations`.`category_id` = `".$wpdb->prefix."product_categories`.`id` AND `".$wpdb->prefix."product_categories`.`active` IN('1')",ARRAY_A);
  807. $i = 0;
  808. foreach((array)$category_list as $category_row) {
  809. if($i > 0) {
  810. echo "<br />";
  811. }
  812. echo "<a href='?page=".$_GET['page']."&amp;catid=".$category_row['id']."'>".stripslashes($category_row['name'])."</a>";
  813. $i++;
  814. }
  815. }
  816. if(!is_numeric($_GET['catid'])){
  817. echo "</td>";
  818. }
  819. // echo "<a href='#' title='sth' onclick='filleditform(".$product['id'].");return false;'>".TXT_WPSC_EDIT."</a>";
  820. echo " </div>\n\r";
  821. echo " </div>\n\r";
  822. if(!is_numeric($_GET['catid'])){
  823. echo "</tr>";
  824. }
  825. }
  826. echo " </div>\n\r";
  827. echo "</td></tr>";
  828. if(is_numeric($_GET['catid'])){
  829. //echo "<tr><td>&nbsp;&nbsp;&nbsp;<a href='#' onClick='serialize();return false;'>".TXT_WPSC_SAVE_PRODUCT_ORDER."</a></td><td></td></tr>";
  830. } else {
  831. if (isset($itempp)) {
  832. $num_pages = floor($num_products/$itempp);
  833. }
  834. if (!isset($_GET['pnum'])) {
  835. $_GET['pnum']=0;
  836. }
  837. echo "<tr class='selectcategory' style='border: none;'><td style='text-align:right;' colspan='4' width='70%'>";
  838. $page_links = paginate_links( array(
  839. 'base' => add_query_arg( 'pnum', '%#%' ),
  840. 'format' => '',
  841. 'total' => $num_pages,
  842. 'current' => $_GET['pnum'],
  843. 'end_size' => 2, // How many numbers on either end including the end
  844. 'mid_size' => 2, // How many numbers to either side of current not including current
  845. ));
  846. echo "<div class='tablenav-pages'>";
  847. echo $page_links;
  848. // for ($i=0;$i<$num_pages;$i++) {
  849. // $newpage=$_GET['pnum']+1;
  850. // $pagenumber=$i+1;
  851. // if (($i==$_GET['pnum']) && is_numeric($_GET['pnum'] )) {
  852. // echo '<span class="page-numbers current">'.$pagenumber.'</span>';
  853. // } else {
  854. // echo "<a style='text-decoration:none;' class='page-numbers' href='?page=".$_GET['page']."&pnum=".$i."'>".$pagenumber."</a>";
  855. // }
  856. // }
  857. //
  858. if (!isset($_GET['catid'])) {
  859. if ($_GET['pnum']==='all') {
  860. echo '<span class="page-numbers current">'.TXT_WPSC_SHOWALL.'</span>';
  861. } else {
  862. echo "<a style='text-decoration:none;' class='page-numbers' href='?page=".$_GET['page']."&pnum=all'>".TXT_WPSC_SHOWALL."</a>";
  863. }
  864. echo "</div>";
  865. }
  866. echo "</td></tr>";
  867. }
  868. }
  869. echo " </table>\n\r";
  870. echo " </td><td class='secondcol'>\n\r";
  871. echo " <div id='productform'>";
  872. echo "<div class='categorisation_title'><strong class='form_group'>". TXT_WPSC_PRODUCTDETAILS." <span>".TXT_WPSC_ENTERPRODUCTDETAILSHERE."</span></strong></div>";
  873. echo "<form method='POST' enctype='multipart/form-data' name='editproduct$num'>";
  874. echo " <table class='producttext'>\n\r";;
  875. echo " </table>\n\r";
  876. echo " <div id='formcontent' style='width:100%;'>\n\r";
  877. echo " </div>\n\r";
  878. echo "</form>";
  879. echo " </div>";
  880. ?>
  881. <div id='additem'>
  882. <div class="categorisation_title"><strong class="form_group"><?php echo TXT_WPSC_PRODUCTDETAILS;?> <span><?php echo TXT_WPSC_ENTERPRODUCTDETAILSHERE;?></span></strong></div>
  883. <form method='POST' enctype='multipart/form-data'>
  884. <table class='additem'>
  885. <tr>
  886. <td class='itemfirstcol'>
  887. <?php echo TXT_WPSC_PRODUCTNAME;?>:
  888. </td>
  889. <td class='itemformcol'>
  890. <div class='admin_product_name'>
  891. <input size='30' type='text' name='name' value='' class='text' />
  892. <a href='#' class='shorttag_toggle'></a>
  893. <div class='admin_product_shorttags'>
  894. <?php echo TXT_WPSC_NO_SHORTCODE;?>
  895. </div>
  896. </div>
  897. </td>
  898. </tr>
  899. <tr>
  900. <td class='itemfirstcol'>
  901. <?php echo TXT_WPSC_SKU;?>:
  902. </td>
  903. <td class='itemformcol'>
  904. <input size='30' type='text' name='productmeta_values[sku]' value='' class='text' />
  905. </td>
  906. </tr>
  907. <tr>
  908. <td class='itemfirstcol'>
  909. <?php echo TXT_WPSC_PRODUCTDESCRIPTION;?>:
  910. </td>
  911. <td class='itemformcol'>
  912. <textarea name='description' cols='40' rows='8'></textarea><br />
  913. </td>
  914. </tr>
  915. <tr>
  916. <td class='itemfirstcol'>
  917. <?php echo TXT_WPSC_ADDITIONALDESCRIPTION;?>:
  918. </td>
  919. <td class='itemformcol'>
  920. <textarea name='additional_description' cols='40' rows='8'></textarea><br />
  921. </td>
  922. </tr>
  923. <tr>
  924. <td class='itemfirstcol'>
  925. <?php echo TXT_WPSC_PRODUCT_TAGS;?>:
  926. </td>
  927. <td class='itemformcol'>
  928. <input type='text' class='text' name='product_tag' id='product_tag'><br /><span class='small_italic'>Seperate with commas</span>
  929. </td>
  930. </tr>
  931. <tr>
  932. <td class='itemfirstcol'>
  933. <?php echo TXT_WPSC_CATEGORISATION; ?>
  934. </td>
  935. <td>
  936. <?php
  937. $categorisation_groups = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}wpsc_categorisation_groups` WHERE `active` IN ('1')", ARRAY_A);
  938. foreach($categorisation_groups as $categorisation_group){
  939. $category_count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}product_categories` WHERE `group_id` IN ('{$categorisation_group['id']}')");
  940. if($category_count > 0) {
  941. echo "<p>";
  942. $category_group_name = str_replace("[categorisation]", $categorisation_group['name'], TXT_WPSC_PRODUCT_CATEGORIES);
  943. echo "<strong>".$category_group_name.":</strong><br>";
  944. echo categorylist($categorisation_group['id'], false, 'add_');
  945. echo "</p>";
  946. }
  947. }
  948. ?>
  949. </td>
  950. </tr>
  951. <tr><td colspan='2'><div id='price_and_stock' class='postbox'>
  952. <h3>
  953. <a class="togbox">+</a>
  954. <?php echo TXT_WPSC_PRICE_AND_STOCK_CONTROL;?>
  955. </h3>
  956. <div class='inside'>
  957. <table>
  958. <tr>
  959. <td>
  960. <?php echo TXT_WPSC_PRICE;?>:&nbsp;<input type='text' size='10' name='price' value='0.00' />
  961. </td>
  962. </tr>
  963. <tr>
  964. <td>
  965. <input id='add_form_tax' type='checkbox' name='notax' value='yes' />&nbsp;<label for='add_form_tax'><?php echo TXT_WPSC_TAXALREADYINCLUDED;?></label>
  966. </td>
  967. </tr>
  968. <tr>
  969. <td>
  970. <input id='add_form_donation' type='checkbox' name='donation' value='yes' />&nbsp;<label for='add_form_donation'><?php echo TXT_WPSC_IS_DONATION;?></label>
  971. </td>
  972. </tr>
  973. <tr>
  974. <td>
  975. <input id='add_form_no_shipping' type='checkbox' name='no_shipping' value='yes' />&nbsp;<label for='add_form_no_shipping'><?php echo TXT_WPSC_NO_SHIPPING;?></label>
  976. </td>
  977. </tr>
  978. <tr>
  979. <td>
  980. <input type="checkbox" onclick="hideelement('add_special')" value="yes" name="special" id="add_form_special"/>
  981. <label for="add_form_special"><?php echo TXT_WPSC_SPECIAL;?></label>
  982. <div style="display: none;" id="add_special">
  983. <input type="text" size="10" value="0.00" name="special_price"/>
  984. </div>
  985. </td>
  986. </tr>
  987. <tr>
  988. <td style='width:430px;'>
  989. <input id='add_form_quantity_limited' type="checkbox" onclick="hideelement('add_stock')" value="yes" name="quantity_limited"/>
  990. <label for='add_form_quantity_limited' class='small'><?php echo TXT_WPSC_UNTICKBOX;?></label>
  991. <div style="display: none;" id="add_stock">
  992. <input type='text' name='quantity' value='0' size='10' />
  993. </div>
  994. </td>
  995. </tr>
  996. </table></div></div></TD></tr>
  997. <?php
  998. do_action('wpsc_product_form', array('product_id' => 0, 'state' => 'add'));
  999. ?>
  1000. <tr>
  1001. <td colspan="2">
  1002. <div id='variation' class='postbox closed'>
  1003. <h3>
  1004. <a class="togbox">+</a>
  1005. <?php echo TXT_WPSC_VARIATION_CONTROL; ?>
  1006. </h3>
  1007. <div class='inside'>
  1008. <table>
  1009. <tr>
  1010. <td>
  1011. <?php echo TXT_WPSC_ADD_VAR; ?>
  1012. </td>
  1013. <td>
  1014. <?php echo variationslist(); ?>
  1015. <div id='add_product_variations'>
  1016. </div>
  1017. <div id='add_product_variation_details'>
  1018. </div>
  1019. </td>
  1020. </tr>
  1021. </table></div></div></td></tr>
  1022. <tr>
  1023. <td colspan='2'>
  1024. <div class='postbox closed' id='shipping'>
  1025. <h3>
  1026. <a class="togbox">+</a>
  1027. <?php echo TXT_WPSC_SHIPPING_DETAILS; ?>
  1028. </h3>
  1029. <div class='inside'>
  1030. <table>
  1031. <!--USPS shipping changes-->
  1032. <tr>
  1033. <td>
  1034. <?php echo TXT_WPSC_WEIGHT; ?>
  1035. </td>
  1036. <td>
  1037. <input type="text" size='5' name='weight' value=''>
  1038. <select name='weight_unit'>
  1039. <option value="pound">Pounds</option>
  1040. <option value="once">Ounce</option>
  1041. </select>
  1042. </td>
  1043. </tr>
  1044. <!--USPS shipping changes ends-->
  1045. <tr>
  1046. <td>
  1047. <?php echo TXT_WPSC_LOCAL_PNP; ?>
  1048. </td>
  1049. <td>
  1050. <input type='text' size='10' name='pnp' value='0.00' />
  1051. </td>
  1052. </tr>
  1053. <tr>
  1054. <td>
  1055. <?php echo TXT_WPSC_INTERNATIONAL_PNP; ?>
  1056. </td>
  1057. <td>
  1058. <input type='text' size='10' name='international_pnp' value='0.00' />
  1059. </td>
  1060. </tr>
  1061. </table></div></div></td></tr>
  1062. <tr><td colspan='2'><div id='advanced' class='postbox closed'>
  1063. <h3>
  1064. <a class="togbox">+</a>
  1065. <?php echo TXT_WPSC_ADVANCED_OPTIONS;?>
  1066. </h3>
  1067. <div class='inside'>
  1068. <table>
  1069. <tr>
  1070. <td class='itemfirstcol'>
  1071. <?php echo TXT_WPSC_ADMINNOTES;?>:
  1072. </td>
  1073. <td>
  1074. <textarea cols="40" rows="3" type='text' name='merchant_notes' id='merchant_notes'></textarea>
  1075. </td>
  1076. </tr>
  1077. <tr>
  1078. <td class='itemfirstcol'>
  1079. </td>
  1080. <td>
  1081. <input type="checkbox" value="yes" id="add_form_display_frontpage" name="display_frontpage"/>
  1082. <label for='add_form_display_frontpage'><?php echo TXT_WPSC_DISPLAY_FRONT_PAGE;?></label>
  1083. </td>
  1084. </tr>
  1085. <tr>
  1086. <td class='itemfirstcol'>
  1087. </td>
  1088. <td>
  1089. <input type='checkbox' name="productmeta_values[engraved]" id='add_engrave_text'>
  1090. <label for='add_engrave_text'><?php echo TXT_WPSC_ENGRAVE;?></label>
  1091. <br />
  1092. </td>
  1093. </tr>
  1094. <tr>
  1095. <td class='itemfirstcol'>
  1096. </td>
  1097. <td>
  1098. <input type='checkbox' name="productmeta_values[can_have_uploaded_image]" id='can_have_uploaded_image'>
  1099. <label for='can_have_uploaded_image'><?php echo TXT_WPSC_ALLOW_UPLOADING_IMAGE;?></label>
  1100. <br />
  1101. </td>
  1102. </tr>
  1103. <?php if(get_option('payment_gateway') == 'google') { ?>
  1104. <tr>
  1105. <td class='itemfirstcol'>
  1106. </td>
  1107. <td>
  1108. <input type='checkbox' name="productmeta_values['google_prohibited']" id='add_google_prohibited' /> <label for='add_google_prohibited'>
  1109. <?php echo TXT_WPSC_PROHIBITED;?></label><br />
  1110. Prohibited <a href='http://checkout.google.com/support/sell/bin/answer.py?answer=75724'>by Google?</a>
  1111. </td>
  1112. </tr>
  1113. <?php } ?>
  1114. <tr>
  1115. <td class='itemfirstcol'>
  1116. <?php echo TXT_WPSC_EXTERNALLINK;?>:
  1117. </td>
  1118. <td>
  1119. <input type='text' class='text' name='external_link' id='external_link' size='40'>
  1120. </td>
  1121. </tr>
  1122. <tr>
  1123. <td></td>
  1124. <td>
  1125. <?php echo TXT_WPSC_USEONLYEXTERNALLINK;?></strong>
  1126. </td>
  1127. </tr>
  1128. <tr>
  1129. <td>
  1130. <?php echo TXT_WPSC_ADD_CUSTOM_FIELD;?>:
  1131. </td>
  1132. <td>
  1133. <div class="product_custom_meta">
  1134. <label >
  1135. <?php echo TXT_WPSC_NAME;?>:
  1136. <input type="text" name="new_custom_meta[name][]" value="" class="text"/>
  1137. </label>
  1138. <label>
  1139. <?php echo TXT_WPSC_VALUE;?>:
  1140. <input type="text" name="new_custom_meta[value][]" value="" class="text"/>
  1141. </label>
  1142. <a href='#' class='add_more_meta' onclick='return add_more_meta(this)'>+</a>
  1143. <b

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