<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include_once ($_SERVER['DOCUMENT_ROOT'] . '/_config/functions.php');
spl_autoload_register('my_autoload');


$tom                                = new tom();
  
if($_SERVER["REQUEST_METHOD"]       == "POST") {
  
  $tom->saveUpdateTomData($_POST);
  echo '<meta http-equiv="refresh" content="0; URL=' . $_POST['site'] . '">';
} else {
  if (!isset($_GET['frage_id'])) {
    $_GET['frage_id']             = $tom->getFirstQuest($_GET['id']);
  } else {
    $_GET['frage_id']             = $_GET['frage_id'];
  }
  $belongToUser                   = 1;
  include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . '/Auth/chk.auth.php');
  
  $row                            = $tom->showQuestsByKundenIdAndQuest($_GET['id'], $_GET['frage_id']);
  $completedPercent               = $tom->showCompletedPercent($_GET['id']);
  $amountQuests                   = $tom->getAmountQuestions($_GET['id']);
  $amountUncompletedQuestions     = $tom->getAmountUncompletedQuestions($_GET['id']);
  $rowsDropdownThemenblock        = $tom->getDropdownThemenblock($_GET['id']);
  $rowsDropdownStatus             = $tom->getStatus();
  $nextQuest                      = $tom->getNextQuest($_GET['id'], $row['themenblock_id'], $row['themenfrage_id']);
  if ($nextQuest                  == '0') {
    $nextThemenblockId            = $tom->getNextThemenblock($_GET['id'], $row['themenblock_id']);
    $nextQuestShow                = $tom->getNextQuest($_GET['id'], $nextThemenblockId, 0);
  } else {
    $nextQuestShow                = $tom->getNextQuest($_GET['id'], $row['themenblock_id'], $row['themenfrage_id']);
  }
  $previousQuest                  = $tom->getPreviousQuest($_GET['id'], $row['themenblock_id'], $row['themenfrage_id']);
  if ($previousQuest              == '0') {
    $previousThemenblockId        = $tom->getPreviousThemenblock($_GET['id'], $row['themenblock_id']);
    $previousQuestShow            = $tom->getLastQuest($_GET['id'], $previousThemenblockId);
  } else {
    $previousQuestShow            = $tom->getPreviousQuest($_GET['id'], $row['themenblock_id'], $row['themenfrage_id']);
  }
  
  include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . TEMPLATE_DIR . '/report/tom/edit.php');
}