<?php

header('Access-Control-Allow-Origin: *');
header("Content-type: application/json; charset=utf-8");

include '../../../utils/database.php';
include '../../../utils/helper.php';

showErrors();

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname_process);
// Check connection
mysqli_set_charset($conn, "utf8");
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$fromLan = "_" . "it";
$toLan = "_" . "sp";

$result = $conn->query("SELECT * FROM answersV2 WHERE `type`='fastfit" . $fromLan . "'");
if ($result->num_rows > 0) {
  while ($row = $result->fetch_assoc()) {
    $pastQid = $row["qid"];
    $pastType = $row["type"];
    $pastAid = $row["aid"];
    $pastPrevQ = $row["prev_question"];
    $pastNextQ = $row["next_question"];

    $qid = str_replace($fromLan, $toLan, $pastQid);
    $type = str_replace($fromLan, $toLan, $pastType);
    $aid = str_replace($fromLan, $toLan, $pastAid);
    $pervQ = str_replace($fromLan, $toLan, $pastPrevQ);
    $nextQ = str_replace($fromLan, $toLan, $pastNextQ);
    $text = $row["text"];
    $description = $row["description"];
    $hintIcon = $row["hintIcon"];
    $hintTitle = $row["hintTitle"];
    $hintDescription = $row["hintDescription"];
    $is_result = $row["is_result"];
    $image = $row["image"];
    $created_at = $row["created_at"];
    $updated_at = $row["updated_at"];
    $priority = $row["priority"];

    $resultCheck = $conn->query("SELECT * FROM answersV2 WHERE `aid`='$aid' AND `type`='fastfit" . $fromLan . "'");
    if ($resultCheck->num_rows == 0) {
      // if ($conn->query("INSERT INTO answersV2(`qid` , `type` , `aid` , `prev_question` , `next_question` , `text` , `description` , `hintIcon` , `hintTitle` , `hintDescription` , `is_result` , `image` , `created_at` , `updated_at` , `priority`) 
      //                                              VALUE('$qid' , '$type' , '$aid' , '$pervQ' , '$nextQ' , '$text' , '$description' , '$hintIcon' , '$hintTitle' , '$hintDescription' , '$is_result' , '$image' , '$created_at' , '$updated_at' , '$priority')")) {
      //   echo "Inserted \n\n";
      // }
    }
  }
}
