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

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

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

    $index++;
    echo 1;

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