prefix . "foxypress_inventory_categories SET category_name='" . foxypress_FixPostVar('foxypress_new_category') . "'"; $wpdb->query($sql); header("location: " . foxypress_GetCurrentPageURL(false) . "?post_type=" . FOXYPRESS_CUSTOM_POST_TYPE . "&page=inventory-category"); } else if(isset($_POST['foxy_cat_save'])) //updating { $Category_Name = foxypress_FixPostVar('foxy_cat_name'); $Category_ID = foxypress_FixPostVar('foxy_cat_id'); $sql = "UPDATE " . $wpdb->prefix . "foxypress_inventory_categories SET category_name='" . $Category_Name . "' WHERE category_id=" . $Category_ID; $wpdb->query($sql); header("location: " . foxypress_GetCurrentPageURL(false) . "?post_type=" . FOXYPRESS_CUSTOM_POST_TYPE . "&page=inventory-category"); } else if($mode == "delete" && foxypress_FixGetVar('category_id') != "") //deleting { $category_id = foxypress_FixGetVar('category_id'); //before we delete, we need to default items to the general category unless they are already apart of that category $sql = "INSERT INTO " . $wpdb->prefix . "foxypress_inventory_to_category (inventory_id, category_id) SELECT i.inventory_id, '1' FROM " . $wpdb->prefix . "posts as i INNER JOIN " . $wpdb->prefix . "foxypress_inventory_to_category as itc on i.ID = itc.inventory_id AND itc.category_id = '" . foxypress_FixGetVar('category_id') . "' LEFT JOIN " . $wpdb->prefix . "foxypress_inventory_to_category as ltc on i.ID = ltc.inventory_id and ltc.category_id = '1' WHERE ltc.itc_id is null AND i.post_type='" . FOXYPRESS_CUSTOM_POST_TYPE . "'"; $wpdb->query($sql); //delete image associated $directory = ABSPATH . INVENTORY_IMAGE_LOCAL_DIR; $data = $wpdb->get_row("select category_image from " . $wpdb->prefix . "foxypress_inventory_categories where category_id = '" . mysql_escape_string($category_id) . "'"); if (!empty($data)) { foxypress_DeleteItem($directory . $data->category_image); } //delete from categories $sql = "DELETE FROM " . $wpdb->prefix . "foxypress_inventory_categories WHERE category_id=" . $category_id; $wpdb->query($sql); //delete from inventory to categories $sql = "DELETE FROM " . $wpdb->prefix . "foxypress_inventory_to_category WHERE category_id=" . $category_id; $wpdb->query($sql); header("location: " . foxypress_GetCurrentPageURL(false) . "?post_type=" . FOXYPRESS_CUSTOM_POST_TYPE. "&page=inventory-category"); } else if(isset($_POST['foxy_order_items_save'])) { $categoryID = foxypress_FixGetVar('categoryid'); $OrderArray = explode(",", foxypress_FixPostVar('hdn_foxy_items_order')); $counter = 1; foreach ($OrderArray as $itc_id) { $wpdb->query("UPDATE " . $wpdb->prefix . "foxypress_inventory_to_category SET sort_order = '$counter' WHERE itc_id='" . $itc_id . "'"); $counter++; } header("location: " . foxypress_GetCurrentPageURL(false) . "?post_type=" . FOXYPRESS_CUSTOM_POST_TYPE . "&page=inventory-category&view=sort&categoryid=" . $categoryID); } else if(isset($_POST['foxy_cat_image_submit'])) { //attempt to upload the image $category_id = foxypress_FixPostVar('hdn_category_id'); if(!empty($_FILES["fp_cat_image"])) { $image = isset($_FILES["fp_cat_image"]["name"]) ? $_FILES["fp_cat_image"]["name"] : ""; if ($image) { $imgname = foxypress_UploadImage("fp_cat_image", $category_id); } //if the upload succeeded, insert into database if ($imgname) { $imgquery = "UPDATE " . $wpdb->prefix . "foxypress_inventory_categories SET category_image = '" . mysql_escape_string($imgname) . "' WHERE category_id = '" . $category_id . "'"; $wpdb->query($imgquery); } } header("location: " . foxypress_GetCurrentPageURL(false) . "?post_type=" . FOXYPRESS_CUSTOM_POST_TYPE . "&page=inventory-category"); } else if($mode == "delete_image" && foxypress_FixGetVar('category_id') != "") { $category_id = foxypress_FixGetVar('category_id'); $directory = ABSPATH . INVENTORY_IMAGE_LOCAL_DIR; $data = $wpdb->get_row("select category_image from " . $wpdb->prefix . "foxypress_inventory_categories where category_id = '" . mysql_escape_string($category_id) . "'"); if (!empty($data)) { foxypress_DeleteItem($directory . $data->category_image); $wpdb->query("UPDATE " . $wpdb->prefix . "foxypress_inventory_categories SET category_image = NULL where category_id = '" . mysql_escape_string($category_id) . "'"); } header("location: " . foxypress_GetCurrentPageURL(false) . "?post_type=" . FOXYPRESS_CUSTOM_POST_TYPE . "&page=inventory-category"); } } } //page load function foxypress_inventory_category_page_load() { $page_view = foxypress_FixGetVar('view'); if($page_view == "sort") { foxypress_inventory_category_sort(); } else { foxypress_inventory_category_view_categories(); } } //sort items in specific categories function foxypress_inventory_category_sort() { global $wpdb; $category_id = foxypress_FixGetVar('categoryid'); ?>
| Sort | Item Code | Item Name |
|---|---|---|
| " . get_post_meta($i->ID, "_code", true) . " | " . $i->post_title . " |
| " . $category->category_id . " | "; if ($category->category_id == 1) { echo "" . stripslashes($category->category_name) . " | "; } else { echo ""; } $ImageOutput = ""; if($category->category_image != "") { $ImageOutput = ""; } else { $ImageOutput = ""; } echo(" | " . $ImageOutput . " | category_id . "\">Sort Inventory Items | "); if ($category->category_id == 1) { echo "" . __("N/A","inventory") . " | "; } else { echo "category_id . "\" class=\"delete\" onclick=\"return confirm('" . __('Are you sure you want to delete this category?','inventory') . "');\">" . __("Delete","inventory") . " | "; } echo ""; } ?>
There are currently no categories
'; } echo '