<?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->getFirstVvtQuest($_GET['id']);
  } else {
    $_GET['vvt_id']                 = $_GET['vvt_id'];
  }
  $belongToUser                     = 1;
  include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . '/Auth/chk.auth.php');
  
  $amountSelectedQuests             = $vvt->getAmountSelectedVvtQuest($_GET['id']);
  $row                              = $vvt->showQuestsByKundenIdAndQuest($_GET['id'], $_GET['vvt_id']);
  $rowsDropdownThemenblock          = $vvt->getDropdownVvtThemenblock($_GET['id']);
  $rowsDropdownStatus               = $vvt->getVvtStatus();
  $rowsDropdownRiskProbability      = $vvt->getVvtRiskProbability();
  $rowsDropdownRiskPotential        = $vvt->getVvtRiskPotential();
  $nextQuest                        = $vvt->getNextVvtQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  if ($nextQuest                    == "") {
    $nextThemenblockId              = $vvt->getNextVvtThemenblock($_GET['id'], $row['themenblock_id']);
    $nextQuest                      = $vvt->getNextVvtQuest($_GET['id'], $nextThemenblockId, 0);
  } else {
    $nextQuest                      = $vvt->getNextVvtQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  }
  $previousQuest                    = $vvt->getPreviousVvtQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  if ($previousQuest                == "") {
    $previousThemenblockId          = $vvt->getPreviousVvtThemenblock($_GET['id'], $row['themenblock_id']);
    $previousQuest                  = $vvt->getLastVvtQuest($_GET['id'], $previousThemenblockId);
  } else {
    $previousQuest                  = $vvt->getPreviousVvtQuest($_GET['id'], $row['themenblock_id'], $row['vvt_id']);
  }
  include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . TEMPLATE_DIR . '/report/vvt/edit.php');
}