<?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');


$vvt                                = new vvt();
  
if($_SERVER["REQUEST_METHOD"]       == "POST") {
  $vvt->saveUpdateVvtData($_POST);
  echo '<meta http-equiv="refresh" content="0; URL=' . $_POST['site'] . '">';
} else {
  if (!isset($_GET['vvt_id'])) {
    $_GET['vvt_id']                 = $vvt->getFirstVvtSelectedQuest($_GET['id']);
  } else {
    $_GET['vvt_id']                 = $_GET['vvt_id'];
  }
  $belongToUser                   = 1;
  include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . '/Auth/chk.auth.php');
  
  $row                            = $vvt->showQuestsByKundenIdAndQuest($_GET['id'], $_GET['vvt_id']);
  $rowsDropdownStatus             = $vvt->getVvtStatus();
  $rowsDropdownRiskProbability    = $vvt->getVvtRiskProbability();
  $rowsDropdownRiskPotential      = $vvt->getVvtRiskPotential();
  $nextQuest                      = $vvt->getNextVvtSelectedQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  if ($nextQuest                  == "") {
    $nextThemenblockId            = $vvt->getNextVvtSelectedThemenblock($_GET['id'], $row['themenblock_id']);
    $nextQuest                    = $vvt->getNextVvtSelectedQuest($_GET['id'], $nextThemenblockId, 0);
  } else {
    $nextQuest                    = $vvt->getNextVvtSelectedQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  }
  $previousQuest                  = $vvt->getPreviousVvtSelectedQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  if ($previousQuest              == "") {
    $previousThemenblockId        = $vvt->getPreviousVvtSelectedThemenblock($_GET['id'], $row['themenblock_id']);
    if ($previousThemenblockId    >= 0) {
      $previousQuest              = $vvt->getLastVvtSelectedQuest($_GET['id'], $previousThemenblockId);
    } else {
      $previousQuest              = "";
    }
  } else {
    $previousQuest                = $vvt->getPreviousVvtSelectedQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  }
  include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . TEMPLATE_DIR . '/report/vvt/edit-selected.php');
}