/** * Toggle publish status and update product record * @return bool Publish status * @param string $product_id */ function wpsc_toggle_publish_status($product_id) { global $wpdb; $status = (int) wpsc_publish_status($product_id) ? 0 : 1; // Flip the Publish flag True <=> False $sql = "UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `publish` = '{$status}' WHERE `id` = '{$product_id}'"; $result = $wpdb->query($sql); return $status; }
function wpsc_admin_products_list($category_id = 0) { global $wpdb, $_wp_column_headers; // set is_sortable to false to start with $is_sortable = false; $page = null; $search_input = ''; if ($_GET['search']) { $search_input = stripslashes($_GET['search']); $search_string = "%" . $wpdb->escape($search_input) . "%"; $search_sql = "AND (`products`.`name` LIKE '" . $search_string . "' OR `products`.`description` LIKE '" . $search_string . "')"; } else { $search_sql = ''; } $search_sql = apply_filters('wpsc_admin_products_list_search_sql', $search_sql); 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 $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`\r\n\t\t\tFROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products`\r\n\t\t\tLEFT JOIN `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` AS `categories` ON `products`.`id` = `categories`.`product_id` \r\n\t\t\tLEFT JOIN `" . WPSC_TABLE_PRODUCT_ORDER . "` AS `order` ON ( \r\n\t\t\t\t(\t`products`.`id` = `order`.`product_id` )\r\n\t\t\tAND \r\n\t\t\t\t( `categories`.`category_id` = `order`.`category_id` )\r\n\t\t\t)\r\n\t\t\tWHERE `products`.`active` = '1' {$search_sql}\r\n\t\t\tAND `categories`.`category_id` \r\n\t\t\tIN (\r\n\t\t\t'" . $category_id . "'\r\n\t\t\t)\r\n\t\t\tORDER BY `order_state` DESC,`order`.`order` ASC, `products`.`date_added` DESC, `products`.`id` DESC"; // if we are selecting a category, set is_sortable to true $is_sortable = true; } else { $itempp = 10; if ($_GET['pageno'] != 'all') { if ($_GET['pageno'] > 0) { $page = absint($_GET['pageno']); } else { $page = 1; } $start = (int) ($page * $itempp) - $itempp; $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}"; if (get_option('wpsc_sort_by') == 'dragndrop') { $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`"; } } else { $sql = "SELECT DISTINCT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products` WHERE `products`.`active`='1' {$search_sql} ORDER BY `products`.`date_added`"; } } // exit($sql); $product_list = $wpdb->get_results($sql, ARRAY_A); //exit('<pre>'.print_r($product_list, true).'</pre>'); $num_products = $wpdb->get_var("SELECT COUNT(DISTINCT `products`.`id`) FROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products` WHERE `products`.`active`='1' {$search_sql}"); if (isset($itempp)) { $num_pages = ceil($num_products / $itempp); } if ($page !== null) { $page_links = paginate_links(array('base' => add_query_arg('pageno', '%#%'), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => $num_pages, 'current' => $page)); } $this_page_url = stripslashes($_SERVER['REQUEST_URI']); ?> <div class="wpsc-separator"><br/></div> <div class="tablenav"> <?php if (get_option('wpsc_sort_by') != 'dragndrop') { ?> <div class="tablenav-pages"> <?php echo $page_links; ?> </div> <?php } ?> <div class="alignleft actions"> <form action="admin.php" method="get"> <?php echo wpsc_admin_category_dropdown(); ?> </form> </div> </div> <form id="posts-filter" action="" method="get"> <div class="tablenav"> <div class="alignright search-box"> <input type='hidden' name='page' value='wpsc-edit-products' /> <input type="text" class="search-input" id="page-search-input" name="search" value="<?php echo $search_input; ?> " /> <input type="submit" name='wpsc_search' value="<?php _e('Search'); ?> " class="button" /> </div> <div class="alignleft actions"> <select name="bulkAction"> <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?> </option> <option value="delete"><?php _e('Delete'); ?> </option> <option value="show"><?php _e('Publish'); ?> </option> <option value="hide"><?php _e('Draft'); ?> </option> </select> <input type='hidden' name='wpsc_admin_action' value='bulk_modify' /> <input type="submit" value="<?php _e('Apply'); ?> " name="doaction" id="doaction" class="button-secondary action" /> <?php wp_nonce_field('bulk-products', 'wpsc-bulk-products'); ?> </div> </div> <input type='hidden' id='products_page_category_id' name='category_id' value='<?php echo $category_id; ?> ' /> <table class="widefat page fixed" id='wpsc_product_list' cellspacing="0"> <thead> <tr> <?php print_column_headers('display-product-list'); ?> </tr> </thead> <tfoot> <tr> <?php print_column_headers('display-product-list', false); ?> </tr> </tfoot> <tbody> <?php if (count($product_list) > 0) { foreach ((array) $product_list as $product) { //first set the patch to the default $image_path = WPSC_URL . "/images/no-image-uploaded.gif"; if (is_numeric($product['image'])) { // check for automatic thumbnail images // file_exists(WPSC_THUMBNAIL_DIR.$product['image']) $product_image = $wpdb->get_var("SELECT `image` FROM `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `id` = '{$product['image']}' LIMIT 1"); // if the image exists, set the image path to it. if ($product_image != null && file_exists(WPSC_THUMBNAIL_DIR . $product_image)) { $image_path = WPSC_THUMBNAIL_URL . $product_image; } } // get the product name, unless there is no name, in which case, display text indicating so if ($product['name'] == '') { $product_name = "(" . __('No Name', 'wpsc') . ")"; } else { $product_name = htmlentities(stripslashes($product['name']), ENT_QUOTES, 'UTF-8'); } $category_html = ''; if (get_option('wpsc_sort_by') != 'dragndrop') { $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); } else { $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); } $i = 0; foreach ((array) $category_list as $category_row) { if ($i > 0) { $category_html .= "<br />"; } $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>"; $i++; } if (get_option('wpsc_sort_by') == 'dragndrop') { $product['id'] = $product['product_id']; } ?> <tr class="product-edit <?php echo wpsc_publish_status($product['id']) ? ' wpsc_published' : ' wpsc_not_published'; ?> " id="product-<?php echo $product['id']; ?> " > <th class="check-column" scope="row"> <input type='checkbox' name='product[]' class='deletecheckbox' value='<?php echo $product['id']; ?> ' title="ID #<?php echo $product['id']; ?> " /> <?php echo do_action('wpsc_admin_product_checkbox', $product['id']); ?> </th> <td class="product-image "> <img title='Drag to a new position' src='<?php echo $image_path; ?> ' alt='<?php echo $product['name']; ?> ' width='38' height='38' /> </td> <td class="product-title column-title"> <?php $edit_product_url = wp_nonce_url(htmlentities(add_query_arg('product_id', $product['id'])), 'edit_product_' . $product['id']); ?> <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> <?php if ($product['publish'] != 1) { ?> - <strong> <?php _e('Draft', 'wpsc'); ?> </strong> <?php } ?> <?php $product_alert = apply_filters('wpsc_product_alert', array(false, ''), $product); if (count($product_alert['messages']) > 0) { $product_alert['messages'] = implode("\n", (array) $product_alert['messages']); } if ($product_alert['state'] === true) { ?> <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='' /> <?php } // If a product alert has stuff to display, show it. // Can be used to add extra icons etc if (!empty($product_alert['display'])) { echo $product_alert['display']; } ?> <img class='loadingImg' style='display:none;' src='<?php echo get_option('siteurl'); ?> /wp-admin/images/wpspin_light.gif' alt='loading' /> <div class="wpsc-row-actions"> <span class="edit"> <a class='edit-product' title="Edit this post" href='<?php echo $edit_product_url; ?> ' style="cursor:pointer;">Edit</a> </span> | <span class="delete"> <a class='submitdelete delete_button' title='<?php echo attribute_escape(__('Delete this product', 'wpsc')); ?> ' href='<?php echo wp_nonce_url("admin.php?wpsc_admin_action=delete_product&product={$product['id']}", 'delete_product_' . $product['id']); ?> ' 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;" > <?php _e('Delete'); ?> </a> </span> | <span class="view"> <a target="_blank" rel="permalink" title='View <?php echo $product_name; ?> ' href="<?php echo wpsc_product_url($product['id']); ?> ">View</a> </span> | <span class="view"> <a rel="permalink" title='Duplicate <?php echo $product_name; ?> ' href="<?php echo wp_nonce_url("admin.php?wpsc_admin_action=duplicate_product&product={$product['id']}", 'duplicate_product_' . $product['id']); ?> "> Duplicate </a> </span> | <span class="publish_toggle"> <a title="Change publish status" href="<?php echo wp_nonce_url("admin.php?wpsc_admin_action=toggle_publish&product=" . $product['id'], 'toggle_publish_' . $product['id']); ?> " > <?php if ($product['publish'] == 1) { _e('Unpublish', 'wpsc'); } else { _e('Publish', 'wpsc'); } ?> </a> </span> </div> </td> <td class="product-price column-price"> <?php echo nzshpcrt_currency_display($product['price'], 1); ?> <div class='price-editing-fields' id='price-editing-fields-<?php echo $product['id']; ?> '> <input type='text' class='the-product-price' name='product_price[<?php echo $product['id']; ?> ][price]' value='<?php echo number_format($product['price'], 2, '.', ''); ?> ' /> <input type='hidden' name='product_price[<?php echo $product['id']; ?> ][id]' value='<?php echo $product['id']; ?> ' /> <input type='hidden' name='product_price[<?php echo $product['id']; ?> ][nonce]' value='<?php echo wp_create_nonce('edit-product_price-' . $product['id']); ?> ' /> </div> </td> <td class="column-categories"><?php echo $category_html; ?> </td> </tr> <?php } } else { ?> <tr> <td colspan='5'> <?php _e("You have no products added."); ?> </td> </tr> <?php } ?> </tbody> </table> </form> <?php }