<?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 questionsV2 WHERE `type`='fastfit". $fromLan . "'");
if ($result->num_rows > 0) {
  while ($row = $result->fetch_assoc()) {
    $pastQid = $row["qid"];
    $pastType = $row["type"];
    $pastPid = $row["pid"];
    $pastParaAid = $row["parasiteAid"];

    $qid = str_replace($fromLan , $toLan , $pastQid);
    $type = str_replace($fromLan, $toLan, $pastType);
    $pid = str_replace($fromLan, $toLan, $pastPid);
    $paraAid = str_replace($fromLan, $toLan, $pastParaAid);
    $hint = $row["hint"];
    $text = $row["text"];
    $description = $row["description"];
    $bgColor = $row["bgColor"];
    $textColor = $row["textColor"];
    $video = $row["video"];
    $cover = $row["cover"];
    $image = $row["image"];
    $background = $row["background"];
    $created_at = $row["created_at"];
    $updated_at = $row["updated_at"];
    $questionType = $row["questionType"];
    $inputQuestion = $row["inputQuestion"];
    $questionNumber = $row["questionNumber"];
    $hasHeader = $row["hasHeader"];

    $resultCheck = $conn->query("SELECT * FROM questionsV2 WHERE `qid`='$qid' AND `type`='fastfit" . $fromLan . "'");
    if ($resultCheck->num_rows == 0) {
      // if ($conn->query("INSERT INTO questionsV2(`qid` , `type` , `pid` , `parasiteAid` , `hint` , `text` , `description` , `bgColor` , `textColor` , `video` , `cover` , `image` , `background` , `created_at` , `updated_at` , `questionType` , `inputQuestion` , `questionNumber` , `hasHeader`) VALUE('$qid' , '$type' , '$pid' , '$paraAid' , '$hint' , '$text' , '$description' , '$bgColor' , '$textColor' , '$video' , '$cover' , '$image' , '$background' , '$created_at' , '$updated_at' , '$questionType' , '$inputQuestion' , '$questionNumber' , '$hasHeader')")){
      //   echo "Inserted \n\n"; 
      // }
    }
  }
}
