PageRenderTime 34ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/wpsc-admin/display-items.page.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 510 lines | 403 code | 80 blank | 27 comment | 62 complexity | ab73e293d4f2b32ea57057958532587e MD5 | raw file
  1. <?php
  2. /**
  3. * WP eCommerce edit and add product page functions
  4. *
  5. * These are the main WPSC Admin functions
  6. *
  7. * @package wp-e-commerce
  8. * @since 3.7
  9. */
  10. function wpsc_display_edit_products_page() {
  11. global $wpdb;
  12. $category_id = absint($_GET['category_id']);
  13. $columns = array(
  14. 'cb' => '<input type="checkbox" />',
  15. 'image' => 'Name',
  16. 'title' => '',
  17. 'price' => 'Price',
  18. 'categories' => 'Categories',
  19. );
  20. register_column_headers('display-product-list', $columns);
  21. $baseurl = includes_url('js/tinymce');
  22. ?>
  23. <div class="wrap">
  24. <?php // screen_icon(); ?>
  25. <h2><?php echo wp_specialchars( __('Display Products', 'wpsc') ); ?> </h2>
  26. <?php if(isset($_GET['ErrMessage']) && is_array($_SESSION['product_error_messages'])){ ?>
  27. <div id="message" class="error fade">
  28. <p>
  29. <?php
  30. foreach($_SESSION['product_error_messages'] as $error) {
  31. echo $error;
  32. }
  33. ?>
  34. </p>
  35. </div>
  36. <?php unset($_GET['ErrMessage']); ?>
  37. <?php $_SESSION['product_error_messages'] = ''; ?>
  38. <?php } ?>
  39. <?php if (isset($_GET['flipped']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) || isset($_GET['message']) || isset($_GET['duplicated']) ) { ?>
  40. <div id="message" class="updated fade">
  41. <p>
  42. <?php if ( isset($_GET['updated'])) {
  43. printf( __ngettext( '%s product updated.', '%s products updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
  44. unset($_GET['updated']);
  45. }
  46. if ( isset($_GET['flipped'])) {
  47. printf( __ngettext( '%s product updated.', '%s products updated.', $_GET['flipped'] ), number_format_i18n( $_GET['flipped'] ) );
  48. unset($_GET['flipped']);
  49. }
  50. if ( isset($_GET['skipped'])) {
  51. unset($_GET['skipped']);
  52. }
  53. if ( isset($_GET['deleted'])) {
  54. printf( __ngettext( 'Product deleted.', '%s products deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
  55. unset($_GET['deleted']);
  56. }
  57. if ( isset($_GET['duplicated']) ) {
  58. printf( __ngettext( 'Product duplicated.', '%s products duplicated.', $_GET['duplicated'] ), number_format_i18n( $_GET['duplicated'] ) );
  59. unset($_GET['duplicated']);
  60. }
  61. if ( isset($_GET['message']) ) {
  62. $message = absint( $_GET['message'] );
  63. $messages[1] = __( 'Product updated.' );
  64. echo $messages[$message];
  65. unset($_GET['message']);
  66. }
  67. $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted', 'message', 'duplicated'), $_SERVER['REQUEST_URI'] );
  68. ?>
  69. </p>
  70. </div>
  71. <?php } ?>
  72. <?php
  73. $unwriteable_directories = Array();
  74. if(!is_writable(WPSC_FILE_DIR)) {
  75. $unwriteable_directories[] = WPSC_FILE_DIR;
  76. }
  77. if(!is_writable(WPSC_PREVIEW_DIR)) {
  78. $unwriteable_directories[] = WPSC_PREVIEW_DIR;
  79. }
  80. if(!is_writable(WPSC_IMAGE_DIR)) {
  81. $unwriteable_directories[] = WPSC_IMAGE_DIR;
  82. }
  83. if(!is_writable(WPSC_THUMBNAIL_DIR)) {
  84. $unwriteable_directories[] = WPSC_THUMBNAIL_DIR;
  85. }
  86. if(!is_writable(WPSC_CATEGORY_DIR)) {
  87. $unwriteable_directories[] = WPSC_CATEGORY_DIR;
  88. }
  89. if(!is_writable(WPSC_UPGRADES_DIR)) {
  90. $unwriteable_directories[] = WPSC_UPGRADES_DIR;
  91. }
  92. if(count($unwriteable_directories) > 0) {
  93. echo "<div class='error fade'>".str_replace(":directory:","<ul><li>".implode($unwriteable_directories, "</li><li>")."</li></ul>",__('The following directories are not writable: :directory: You won&#39;t be able to upload any images or files here. You will need to change the permissions on these directories to make them writable.', 'wpsc'))."</div>";
  94. }
  95. // class='stuffbox'
  96. ?>
  97. <div id="col-container">
  98. <div id="wpsc-col-right">
  99. <div id='poststuff' class="col-wrap">
  100. <form id="modify-products" method="post" action="" enctype="multipart/form-data" >
  101. <?php
  102. $product_id = absint($_GET['product_id']);
  103. wpsc_display_product_form($product_id);
  104. ?>
  105. </form>
  106. </div>
  107. </div>
  108. <div id="wpsc-col-left">
  109. <div class="col-wrap">
  110. <?php
  111. wpsc_admin_products_list($category_id);
  112. ?>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. <script type="text/javascript">
  118. /* <![CDATA[ */
  119. (function($){
  120. $(document).ready(function(){
  121. $('#doaction, #doaction2').click(function(){
  122. if ( $('select[name^="action"]').val() == 'delete' ) {
  123. var m = '<?php echo js_escape(__("You are about to delete the selected products.\n 'Cancel' to stop, 'OK' to delete.")); ?>';
  124. return showNotice.warn(m);
  125. }
  126. });
  127. });
  128. })(jQuery);
  129. /* ]]> */
  130. </script>
  131. <?php
  132. }
  133. function wpsc_admin_products_list($category_id = 0) {
  134. global $wpdb,$_wp_column_headers;
  135. // set is_sortable to false to start with
  136. $is_sortable = false;
  137. $page = null;
  138. if($_GET['search']) {
  139. $search_string_title = "%".$wpdb->escape(stripslashes($_GET['search']))."%";
  140. $search_string_description = "% ".$wpdb->escape(stripslashes($_GET['search']))."%";
  141. $search_sql = "AND (`products`.`name` LIKE '".$search_string_title."' OR `products`.`description` LIKE '".$search_string_description."')";
  142. $search_string = $_GET['search'];
  143. } else {
  144. $search_sql = '';
  145. $search_string = '';
  146. }
  147. $search_sql = apply_filters('wpsc_admin_products_list_search_sql', $search_sql);
  148. if($category_id > 0) { // if we are getting items from only one category, this is a monster SQL query to do this with the product order
  149. $sql = "SELECT `products`.`id` , `products`.`name` , `products`.`price` , `products`.`image`,`products`.`weight` , `products`.`publish`, `categories`.`category_id`,`order`.`order`, IF(ISNULL(`order`.`order`), 0, 1) AS `order_state`
  150. FROM `".WPSC_TABLE_PRODUCT_LIST."` AS `products`
  151. LEFT JOIN `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` AS `categories` ON `products`.`id` = `categories`.`product_id`
  152. LEFT JOIN `".WPSC_TABLE_PRODUCT_ORDER."` AS `order` ON (
  153. ( `products`.`id` = `order`.`product_id` )
  154. AND
  155. ( `categories`.`category_id` = `order`.`category_id` )
  156. )
  157. WHERE `products`.`active` = '1' $search_sql
  158. AND `categories`.`category_id`
  159. IN (
  160. '".$category_id."'
  161. )
  162. ORDER BY `order_state` DESC,`order`.`order` ASC, `products`.`date_added` DESC, `products`.`id` DESC";
  163. // if we are selecting a category, set is_sortable to true
  164. $is_sortable = true;
  165. } else {
  166. $itempp = 10;
  167. if ($_GET['pageno']!='all') {
  168. if($_GET['pageno'] > 0) {
  169. $page = absint($_GET['pageno']);
  170. } else {
  171. $page = 1;
  172. }
  173. $start = (int)($page * $itempp) - $itempp;
  174. $sql = "SELECT DISTINCT * FROM `".WPSC_TABLE_PRODUCT_LIST."` AS `products` WHERE `products`.`active`='1' $search_sql ORDER BY `products`.`date_added` DESC LIMIT $start,$itempp";
  175. if(get_option('wpsc_sort_by') == 'dragndrop'){
  176. $sql = "SELECT DISTINCT * FROM `".WPSC_TABLE_PRODUCT_LIST."` AS `products` LEFT JOIN `".WPSC_TABLE_PRODUCT_ORDER."` AS `order` ON `products`.`id`= `order`.`product_id` WHERE `products`.`active`='1' AND `order`.`category_id`='0' $search_sql ORDER BY `order`.`order`";
  177. }
  178. } else {
  179. $sql = "SELECT DISTINCT * FROM `".WPSC_TABLE_PRODUCT_LIST."` AS `products` WHERE `products`.`active`='1' $search_sql ORDER BY `products`.`date_added`";
  180. }
  181. }
  182. // exit($sql);
  183. $product_list = $wpdb->get_results($sql,ARRAY_A);
  184. //exit('<pre>'.print_r($product_list, true).'</pre>');
  185. $num_products = $wpdb->get_var("SELECT COUNT(DISTINCT `products`.`id`) FROM `".WPSC_TABLE_PRODUCT_LIST."` AS `products` WHERE `products`.`active`='1' $search_sql");
  186. if (isset($itempp)) {
  187. $num_pages = ceil($num_products/$itempp);
  188. }
  189. if($page !== null) {
  190. $page_links = paginate_links( array(
  191. 'base' => add_query_arg( 'pageno', '%#%' ),
  192. 'format' => '',
  193. 'prev_text' => __('&laquo;'),
  194. 'next_text' => __('&raquo;'),
  195. 'total' => $num_pages,
  196. 'current' => $page
  197. ));
  198. }
  199. $this_page_url = stripslashes($_SERVER['REQUEST_URI']);
  200. ?>
  201. <div class="wpsc-separator"><br/></div>
  202. <div class="tablenav">
  203. <?php if(get_option('wpsc_sort_by') != 'dragndrop'){ ?>
  204. <div class="tablenav-pages">
  205. <?php
  206. echo $page_links;
  207. ?>
  208. </div>
  209. <?php } ?>
  210. <div class="alignleft actions">
  211. <form action="admin.php" method="get">
  212. <?php
  213. echo wpsc_admin_category_dropdown();
  214. ?>
  215. </form>
  216. </div>
  217. </div>
  218. <form id="posts-filter" action="" method="get">
  219. <div class="tablenav">
  220. <div class="alignright search-box">
  221. <input type='hidden' name='page' value='wpsc-edit-products' />
  222. <input type="text" class="search-input" id="page-search-input" name="search" value="<?php echo $_GET['search']; ?>" />
  223. <input type="submit" name='wpsc_search' value="<?php _e( 'Search' ); ?>" class="button" />
  224. </div>
  225. <div class="alignleft actions">
  226. <select name="bulkAction">
  227. <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
  228. <option value="delete"><?php _e('Delete'); ?></option>
  229. <option value="show"><?php _e('Publish'); ?></option>
  230. <option value="hide"><?php _e('Draft'); ?></option>
  231. </select>
  232. <input type='hidden' name='wpsc_admin_action' value='bulk_modify' />
  233. <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  234. <?php wp_nonce_field('bulk-products', 'wpsc-bulk-products'); ?>
  235. </div>
  236. </div>
  237. <input type='hidden' id='products_page_category_id' name='category_id' value='<?php echo $category_id; ?>' />
  238. <table class="widefat page fixed" id='wpsc_product_list' cellspacing="0">
  239. <thead>
  240. <tr>
  241. <?php print_column_headers('display-product-list'); ?>
  242. </tr>
  243. </thead>
  244. <tfoot>
  245. <tr>
  246. <?php print_column_headers('display-product-list', false); ?>
  247. </tr>
  248. </tfoot>
  249. <tbody>
  250. <?php
  251. if(count($product_list) > 0) {
  252. foreach((array)$product_list as $product) {
  253. //first set the patch to the default
  254. $image_path = WPSC_URL."/images/no-image-uploaded.gif";
  255. if(is_numeric($product['image'])) { // check for automatic thumbnail images
  256. // file_exists(WPSC_THUMBNAIL_DIR.$product['image'])
  257. $product_image = $wpdb->get_var("SELECT `image` FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `id` = '{$product['image']}' LIMIT 1");
  258. // if the image exists, set the image path to it.
  259. if(($product_image != null) && file_exists(WPSC_THUMBNAIL_DIR.$product_image)) {
  260. $image_path = WPSC_THUMBNAIL_URL.$product_image;
  261. }
  262. }
  263. // get the product name, unless there is no name, in which case, display text indicating so
  264. if ($product['name']=='') {
  265. $product_name = "(".__('No Name', 'wpsc').")";
  266. } else {
  267. $product_name = htmlentities(stripslashes($product['name']), ENT_QUOTES, 'UTF-8');
  268. }
  269. $category_html = '';
  270. if(get_option('wpsc_sort_by') != 'dragndrop'){
  271. $category_list = $wpdb->get_results("SELECT `".WPSC_TABLE_PRODUCT_CATEGORIES."`.`id`,`".WPSC_TABLE_PRODUCT_CATEGORIES."`.`name` FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` , `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."`.`product_id` IN ('".$product['id']."') AND `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."`.`category_id` = `".WPSC_TABLE_PRODUCT_CATEGORIES."`.`id` AND `".WPSC_TABLE_PRODUCT_CATEGORIES."`.`active` IN('1')",ARRAY_A);
  272. }else{
  273. $category_list = $wpdb->get_results("SELECT `".WPSC_TABLE_PRODUCT_CATEGORIES."`.`id`,`".WPSC_TABLE_PRODUCT_CATEGORIES."`.`name` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` LEFT JOIN `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` ON `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."`.`category_id`= `".WPSC_TABLE_PRODUCT_CATEGORIES."`.`id` WHERE `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."`.`product_id` IN ('".$product['product_id']."') AND `".WPSC_TABLE_PRODUCT_CATEGORIES."`.`active` IN('1')",ARRAY_A);
  274. }
  275. $i = 0;
  276. foreach((array)$category_list as $category_row) {
  277. if($i > 0) {
  278. $category_html .= "<br />";
  279. }
  280. $category_html .= "<a class='category_link' href='". htmlentities(remove_query_arg('product_id',add_query_arg('category_id', $category_row['id'])))."'>".stripslashes($category_row['name'])."</a>";
  281. $i++;
  282. }
  283. if(get_option('wpsc_sort_by') == 'dragndrop'){
  284. $product['id'] = $product['product_id'];
  285. }
  286. ?>
  287. <tr class="product-edit <?php echo ( wpsc_publish_status($product['id']) ) ? ' wpsc_published' : ' wpsc_not_published'; ?>" id="product-<?php echo $product['id']?>" >
  288. <th class="check-column" scope="row">
  289. <input type='checkbox' name='product[]' class='deletecheckbox' value='<?php echo $product['id'];?>' title="ID #<?php echo $product['id']; ?>" />
  290. <?php echo do_action('wpsc_admin_product_checkbox', $product['id']); ?>
  291. </th>
  292. <td class="product-image ">
  293. <img title='Drag to a new position' src='<?php echo $image_path; ?>' alt='<?php echo $product['name']; ?>' width='38' height='38' />
  294. </td>
  295. <td class="product-title column-title">
  296. <?php
  297. $edit_product_url = wp_nonce_url(htmlentities(add_query_arg('product_id', $product['id'])), 'edit_product_' . $product['id']);
  298. ?>
  299. <a class='edit-product' href='<?php echo $edit_product_url; ?>' title="ID #<?php echo $product['id']; ?>: <?php echo $product_name; ?>"><?php echo $product_name; ?></a>
  300. <?php
  301. if($product['publish'] != 1 ) {
  302. ?> - <strong> <?php _e('Draft', 'wpsc'); ?> </strong> <?php
  303. }
  304. ?>
  305. <?php
  306. $product_alert = apply_filters('wpsc_product_alert', array(false, ''), $product);
  307. if(count($product_alert['messages']) > 0) {
  308. $product_alert['messages'] = implode("\n",(array)$product_alert['messages']);
  309. }
  310. if($product_alert['state'] === true) {
  311. ?>
  312. <img alt='<?php echo $product_alert['messages'];?>' title='<?php echo $product_alert['messages'];?>' class='product-alert-image' src='<?php echo WPSC_URL;?>/images/product-alert.jpg' alt='' />
  313. <?php
  314. }
  315. // If a product alert has stuff to display, show it.
  316. // Can be used to add extra icons etc
  317. if ( !empty( $product_alert['display'] ) ) {
  318. echo $product_alert['display'];
  319. }
  320. ?>
  321. <img class='loadingImg' style='display:none;' src='<?php echo get_option('siteurl'); ?>/wp-admin/images/wpspin_light.gif' alt='loading' />
  322. <div class="wpsc-row-actions">
  323. <span class="edit">
  324. <a class='edit-product' title="Edit this post" href='<?php echo $edit_product_url; ?>' style="cursor:pointer;">Edit</a>
  325. </span>
  326. |
  327. <span class="delete">
  328. <a class='submitdelete delete_button'
  329. title='<?php echo attribute_escape(__('Delete this product', 'wpsc')); ?>'
  330. href='<?php echo wp_nonce_url("admin.php?wpsc_admin_action=delete_product&amp;product={$product['id']}", 'delete_product_' . $product['id']); ?>'
  331. onclick="if ( confirm(' <?php echo js_escape(sprintf( __("You are about to delete this product '%s'\n 'Cancel' to stop, 'OK' to delete."), $product['name'] )) ?>') ) { return true;}return false;"
  332. >
  333. <?php _e('Delete') ?>
  334. </a>
  335. </span>
  336. |
  337. <span class="view">
  338. <a target="_blank" rel="permalink" title='View <?php echo $product_name; ?>' href="<?php echo wpsc_product_url($product['id']); ?>">View</a>
  339. </span>
  340. |
  341. <span class="view">
  342. <a rel="permalink"
  343. title='Duplicate <?php echo $product_name; ?>'
  344. href="<?php echo wp_nonce_url("admin.php?wpsc_admin_action=duplicate_product&amp;product={$product['id']}", 'duplicate_product_' . $product['id']); ?>
  345. ">
  346. Duplicate
  347. </a>
  348. </span>
  349. |
  350. <span class="publish_toggle">
  351. <a title="Change publish status"
  352. href="<?php echo wp_nonce_url("admin.php?wpsc_admin_action=toggle_publish&product=".$product['id'], 'toggle_publish_'.$product['id']); ?>"
  353. >
  354. <?php
  355. if($product['publish'] == 1 ) {
  356. _e('Unpublish', 'wpsc');
  357. } else {
  358. _e('Publish', 'wpsc');
  359. }
  360. ?>
  361. </a>
  362. </span>
  363. </div>
  364. </td>
  365. <td class="product-price column-price">
  366. <?php echo nzshpcrt_currency_display($product['price'], 1); ?>
  367. <div class='price-editing-fields' id='price-editing-fields-<?php echo $product['id']; ?>'>
  368. <input type='text' class='the-product-price' name='product_price[<?php echo $product['id']; ?>][price]' value='<?php echo number_format($product['price'],2,'.',''); ?>' />
  369. <input type='hidden' name='product_price[<?php echo $product['id']; ?>][id]' value='<?php echo $product['id']; ?>' />
  370. <input type='hidden' name='product_price[<?php echo $product['id']; ?>][nonce]' value='<?php echo wp_create_nonce('edit-product_price-'.$product['id']); ?>' />
  371. </div>
  372. </td>
  373. <td class="column-categories"><?php echo $category_html; ?></td>
  374. </tr>
  375. <?php
  376. }
  377. } else {
  378. ?>
  379. <tr>
  380. <td colspan='5'>
  381. <?php _e("You have no products added."); ?>
  382. </td>
  383. </tr>
  384. <?php
  385. }
  386. ?>
  387. </tbody>
  388. </table>
  389. </form>
  390. <?php
  391. }
  392. function wpsc_admin_category_dropdown() {
  393. global $wpdb,$category_data;
  394. $siteurl = get_option('siteurl');
  395. $url = urlencode(remove_query_arg(array('product_id','category_id')));
  396. $options = "<option value=''>".__('View All Categories', 'wpsc')."</option>\r\n";
  397. $options .= wpsc_admin_category_dropdown_tree(null, 0, absint($_GET['category_id']));
  398. $concat = "<input type='hidden' name='page' value='{$_GET['page']}' />\r\n";
  399. $concat .= "<select name='category_id' id='category_select'>".$options."</select>\r\n";
  400. $concat .= "<button class='button' id='submit_category_select'>Filter</button>\r\n";
  401. return $concat;
  402. }
  403. function wpsc_admin_category_dropdown_tree($category_id = null, $iteration = 0, $selected_id = null) {
  404. /*
  405. * Displays the category forms for adding and editing products
  406. * Recurses to generate the branched view for subcategories
  407. */
  408. global $wpdb;
  409. $siteurl = get_option('siteurl');
  410. $url = $siteurl."/wp-admin/admin.php?page=wpsc-edit-products";
  411. $search_sql = apply_filters('wpsc_admin_category_dropdown_tree_search_sql', '');
  412. if(is_numeric($category_id)) {
  413. $sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '$category_id' ".$search_sql." ORDER BY `id` ASC";
  414. } else {
  415. $sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '0' ".$search_sql." ORDER BY `id` ASC";
  416. }
  417. // echo $sql;
  418. $values = $wpdb->get_results($sql, ARRAY_A);
  419. foreach((array)$values as $option) {
  420. if($selected_id == $option['id']) {
  421. $selected = "selected='selected'";
  422. }
  423. //$url = htmlentities(remove_query_arg('product_id',add_query_arg('category_id', $option['id'])));
  424. $output .= "<option $selected value='{$option['id']}'>".str_repeat("-", $iteration).stripslashes($option['name'])."</option>\r\n";
  425. $output .= wpsc_admin_category_dropdown_tree($option['id'], $iteration+1, $selected_id);
  426. $selected = "";
  427. }
  428. return $output;
  429. }
  430. ?>