if ($action === NULL) { $action = 'list_product'; } } //main action slection if ($action == 'list_product') { $products = get_products(); include 'product_list.php'; } else { if ($action == 'delete_product') { $productCode = filter_input(INPUT_POST, 'productCode'); if ($productCode == NULL || $productCode == FALSE) { $error = "Missing or incorrect technician ID."; include '../errors/error.php'; } else { delete_products($productCode); header("Location: .?action=list_product"); } } else { if ($action == 'show_add_form') { include 'product_add.php'; } else { if ($action == 'add_product') { $productCode = filter_input(INPUT_POST, 'productCode'); $name = filter_input(INPUT_POST, 'name'); $version = filter_input(INPUT_POST, 'version'); $releaseDate = filter_input(INPUT_POST, 'releaseDate'); if ($productCode == null || $productCode == FALSE || $name == NULL || $name == FALSE || $version == NULL || $version == FALSE || $releaseDate == NULL || $releaseDate == FALSE) { $error = "Missing or incorrect technician informatino."; include '../errors/error.php'; } else {
function delete_categories($categories_ids) { global $db, $table_prefix; // additional connection $dbs = new VA_SQL(); $dbs->DBType = $db->DBType; $dbs->DBDatabase = $db->DBDatabase; $dbs->DBHost = $db->DBHost; $dbs->DBPort = $db->DBPort; $dbs->DBUser = $db->DBUser; $dbs->DBPassword = $db->DBPassword; $dbs->DBPersistent = $db->DBPersistent; $categories = array(); $sql = " SELECT category_id,category_path FROM " . $table_prefix . "categories "; $sql .= " WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ") "; $dbs->query($sql); while ($dbs->next_record()) { $category_id = $dbs->f("category_id"); $category_path = $dbs->f("category_path"); if (!in_array($category_id, $categories)) { $categories[] = $category_id; $sql = " SELECT category_id FROM " . $table_prefix . "categories "; $sql .= " WHERE category_path LIKE '" . $db->tosql($category_path . $category_id . ",", TEXT, false) . "%'"; $db->query($sql); while ($db->next_record()) { $categories[] = $db->f("category_id"); } } } if (is_array($categories) && sizeof($categories) > 0) { $categories_ids = join(",", $categories); $db->query("DELETE FROM " . $table_prefix . "categories WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")"); $db->query("DELETE FROM " . $table_prefix . "items_categories WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")"); $db->query("DELETE FROM " . $table_prefix . "categories_user_types WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")"); $db->query("DELETE FROM " . $table_prefix . "categories_subscriptions WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")"); $db->query("DELETE FROM " . $table_prefix . "categories_sites WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")"); $db->query("DELETE FROM " . $table_prefix . "categories_columns WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")"); } // delete products that are not assigned to any category $sql = " SELECT i.item_id FROM (" . $table_prefix . "items i "; $sql .= " LEFT JOIN " . $table_prefix . "items_categories ic ON i.item_id=ic.item_id) "; $sql .= " WHERE ic.category_id IS NULL "; $dbs->query($sql); while ($dbs->next_record()) { $item_id = $dbs->f("item_id"); delete_products($item_id); } }
function vm_edit_products_check() { $IDs = array(); $Delete_IDs = array(); $dirty_IDs = array(); // Get all IDs from Form foreach ($_POST as $index => $value) { if (startsWith($index, "ID_")) { $IDs[] = str_replace("ID_", "", $index); } elseif (startsWith($index, "Delete_")) { $Delete_IDs[] = str_replace("Delete_", "", $index); } } // Now check for dirty elements foreach ($IDs as $id) { if ($_POST['price_' . $id] != $_POST['price_new_' . $id] || $_POST['product_' . $id] != $_POST['product_new_' . $id] || $_POST['comment_' . $id] != $_POST['comment_new_' . $id]) { // This is a dirty ID $dirty_IDs[] = $id; } } $edited_users = array(); // create User Objects for edited users foreach ($dirty_IDs as $id) { $user = new Product(); $user->comment = $_POST['comment_new_' . $id]; $user->product = $_POST['product_new_' . $id]; $user->price = floatval(str_replace(",", ".", $_POST['price_new_' . $id])); $user->iD = $id; $edited_users[] = $user; } if (count($edited_users) > 0) { $response = update_products($edited_users); } if (count($Delete_IDs) > 0) { $response2 = delete_products($Delete_IDs); } $resp; if (isset($response) && !isset($response2)) { $resp = $response; } elseif (isset($response2) && !isset($response)) { $resp = $response2; } elseif (isset($response2) && isset($response)) { $resp = $response; $resp->status &= $response2->status; $resp->errorDescription = $resp->errorDescription . " " . $response2->errorDescription; } else { return ""; } return $resp; }