function addElemToStorage() { require_once "textstorageconnection.php"; $mas = getArrayFromFile("buyers"); $buyer = new buyer(); $buyer->id = uniqid(); $buyer->name = $_POST["addName"]; $buyer->adress = $_POST["addAdress"]; $buyer->phone = $_POST["addPhone"]; $mas[count($mas)] = $buyer; writeArrayToFile("buyers", $mas); }
function addElemToStorage() { require_once "textstorageconnection.php"; $mas = getArrayFromFile("cars"); $car = new Car(); $car->id = uniqid(); $car->brand = $_POST["addBrand"]; $colors = ""; foreach ($_POST["addColor"] as $currentColor) { $colors .= $currentColor; $colors .= ", "; } $colors = substr($colors, 0, -2); $car->color = $colors; $car->date = $_POST["addDate"]["month"] . "." . $_POST["addDate"]["year"]; $car->price = $_POST["addPrice"]; $car->percent = $_POST["addPercent"]; $mas[count($mas)] = $car; writeArrayToFile("cars", $mas); }
require_once "textstorageconnection.php"; $target; $id = $_POST["id"]; $isDeleted = false; switch ($_POST["deleteObject"]) { case "Car": $target = "cars"; break; case "Owner": $target = "owners"; break; case "Buyer": $target = "buyers"; break; } $mas = getArrayFromFile($target); foreach ($mas as $k => $v) { if ($v->id == $id) { $isDeleted = true; unset($mas[$k]); } } $mas = array_values($mas); writeArrayToFile($target, $mas); if ($isDeleted) { echo "<h4>Запись успешно удалена</h4>"; } else { echo "Запись не найдена"; } ?> <form action=start.php method=POST role=form>
<link href="css/bootstrap.css" rel="stylesheet"> <style> body { margin: 10px; } </style> </head> <body> <?php require_once "objects.php"; require_once "sortRules.php"; require_once "filterHelp.php"; require_once "textstorageconnection.php"; $masCar = getArrayFromFile("cars"); $masOwner = getArrayFromFile("owners"); $masBuyer = getArrayFromFile("buyers"); if (isset($_POST["filter"])) { switch ($_POST["filter"]) { case "Car": filterCar(); break; case "Owner": filterOwner(); break; case "Buyer": filterBuyer(); break; } } function filterCar() {