<?php
include "../../root.class.php";
$db = new db_safeguard();
// var_dump($_POST);
// if(isset($_POST['sorting_id'])){
$sorting_id = $_POST['sorting_id'];
$user_id = $_SESSION['user_id'];
$index = 0;

try {
    foreach ($_POST['equipment_id'] as $equipment_id) {

        $db->query("sorting_equipment_check_list", "DELETE FROM `sorting_equipment_check_list` WHERE `equipment_id` = '$equipment_id' AND `sorting_id` = '$sorting_id'");
        $answer = $_POST['clean_' . $equipment_id][0];
        $text = $_POST['text_clean_' . $equipment_id][0];
        $db->query("sorting_equipment_check_list", "INSERT INTO `sorting_equipment_check_list`(`equipment_id`, `text`, `user_id`, `sorting_id`,`question`) VALUES ('$equipment_id','$answer','$user_id','$sorting_id','$text')");
        $answer = $_POST['excessive_' . $equipment_id][0];
        $text = $_POST['text_excessive_' . $equipment_id][0];
        $db->query("sorting_equipment_check_list", "INSERT INTO `sorting_equipment_check_list`(`equipment_id`, `text`, `user_id`, `sorting_id`,`question`) VALUES ('$equipment_id','$answer','$user_id','$sorting_id','$text')");
        $text = $_POST['text_guardsk_' . $equipment_id][0];
        $answer = $_POST['guardsk_' . $equipment_id][0];
        $db->query("sorting_equipment_check_list", "INSERT INTO `sorting_equipment_check_list`(`equipment_id`, `text`, `user_id`, `sorting_id`,`question`) VALUES ('$equipment_id','$answer','$user_id','$sorting_id','$text')");
        $text = $_POST['text_Moving_' . $equipment_id][0];
        $answer = $_POST['Moving_' . $equipment_id][0];
        $db->query("sorting_equipment_check_list", "INSERT INTO `sorting_equipment_check_list`(`equipment_id`, `text`, `user_id`, `sorting_id`,`question`) VALUES ('$equipment_id','$answer','$user_id','$sorting_id','$text')");
        $text = $_POST['text_Power_' . $equipment_id][0];
        $answer = $_POST['Power_' . $equipment_id][0];
        $db->query("sorting_equipment_check_list", "INSERT INTO `sorting_equipment_check_list`(`equipment_id`, `text`, `user_id`, `sorting_id`,`question`) VALUES ('$equipment_id','$answer','$user_id','$sorting_id','$text')");
    }

    $index++;
    echo 1;

} catch (Exception $e) {
    echo $e->getMessage();
}
// }