creator != SESSION["userId"]) pageBuilder::errorCode(404); if($item->type == 19) catalog::$gear_attributes = json_decode($item->gear_attributes, true); $alert = false; if($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST['name'] ?? false; $description = $_POST['description'] ?? false; $comments = isset($_POST['comments']) && $_POST['comments'] == "on"; $sale = isset($_POST['sell']) && $_POST['sell'] == "on"; $sell_for_price = isset($_POST['sell-for-currency']) && $_POST['sell-for-currency'] == "on"; $price = $sell_for_price && isset($_POST['sell-price']) ? $_POST['sell-price'] : false; $file = $_FILES["file"] ?? false; catalog::parse_gear_attributes(); if($sale && $sell_for_price && $price === "") $sell_for_price = $price = false; if(!strlen($name)) $alert = ["text" => "Item name cannot be empty", "color" => "danger"]; elseif(mb_strlen($name, "utf-8") > 50) $alert = ["text" => "Item name cannot be any longer than 50 characters", "color" => "danger"]; elseif(strlen($description) > 1000) $alert = ["text" => "Item description cannot be any longer than 1000 characters", "color" => "danger"]; elseif($sale && $sell_for_price && !is_numeric($price)) $alert = ["text" => "Item price is invalid", "color" => "danger"]; elseif($sale && $sell_for_price && $price < 0) $alert = ["text" => "Item price cannot be less than zero", "color" => "danger"]; elseif($sale && $sell_for_price && $price > (2**31)) $alert = ["text" => "Item price is too large", "color" => "danger"]; else { $item->name = $name; $item->description = $description; $item->comments = $comments; if($item->type != 1) $item->sale = $sale; if(in_array($item->type, [2, 8, 11, 12, 17, 18, 19])) $item->price = $price; if($item->type == 19) $item->gear_attributes = json_encode(catalog::$gear_attributes); if(SESSION["adminLevel"] && $file && $file["size"]) { copy($file["tmp_name"], $_SERVER['DOCUMENT_ROOT']."/asset/files/".$item->id); if($item->type == 10) gzip::compress($_SERVER['DOCUMENT_ROOT']."/asset/files/".$item->id); } $query = $pdo->prepare("UPDATE assets SET name = :name, description = :description, comments = :comments, sale = :sale, price = :price, gear_attributes = :gear, updated = UNIX_TIMESTAMP() WHERE id = :id"); $query->bindParam(":name", $item->name, PDO::PARAM_STR); $query->bindParam(":description", $item->description, PDO::PARAM_STR); $query->bindParam(":comments", $item->comments, PDO::PARAM_INT); $query->bindParam(":sale", $item->sale, PDO::PARAM_INT); $query->bindParam(":price", $item->price, PDO::PARAM_INT); $query->bindParam(":gear", $item->gear_attributes, PDO::PARAM_STR); $query->bindParam(":id", $item->id, PDO::PARAM_STR); $query->execute(); $alert = ["text" => "Your changes to this item have been saved (".date('h:i:s A').")", "color" => "primary"]; } } pageBuilder::$pageConfig['title'] = "Configure ".catalog::getTypeByNum($item->type); pageBuilder::buildHeader(); ?>