<?php
include_once 'classes/TestProjektSmarty.class.php';
require_once("config.inc.php");
$templatename = substr(basename($_SERVER['PHP_SELF']),0,-3)."html";
$smarty = new Smarty();
require_once "language/german.inc.php";

require_once "validation/func_validEmail.php";
require_once "func_genUser.php";
require_once("func_verlauf.php");
require_once("func_gutachter_entscheid.php");
require_once("func_gutachter_status.php");
require_once("func_mail_einstell.php");
require_once("func_rechte_vergabe.php");

$action = $_GET['action'];

  if(isset($_GET['id'])){
    $_SESSION["edit_id"] = $_GET['id'];
    $search_prefix = 'ausschuss_gutachter_uberblick_';
    $search_len = strlen($search_prefix);
    foreach( $_SESSION as $key => $value){
      if ( substr( $key, 0, $search_len) == $search_prefix) {
        unset( $_SESSION[$key]);
      }
    }
  }



if($action == ''){
 
    $id = $_SESSION["edit_id"];
  
    $query1 = "SELECT a.gid, vorname, nachname, date_format(frist_datum, '%d.%m.%Y') frist_tag, date_format(frist_datum_abgabe, '%d.%m.%Y') frist_datum_abgabe
                 FROM imt_gutachter a, imt_user b
                WHERE a.imtuid=b.imtuid
                  AND a.vid='$id'
                ORDER BY nachname ASC";
  
    $result1 = $db->query ($query1)
              or die ("Cannot execute query");
    
    $table_data1 = array();
    
    $gutachter = new gutachter();
    
    while ($row1 = $result1->fetch_array()){
      
      gutachter_entscheid($uid, $row1[gid], $id);
      $status = $gutachter -> gutachter_status($row1[gid]);
      $status_klartext = $gutachter -> gutachter_status_klartext($row1[gid], $status);
      
      if($row1[frist_datum_abgabe] == '00.00.0000'){
        $abgabefrist = "Gutachter noch nicht angeschrieben";
      }else{
        $abgabefrist = $row1[frist_datum_abgabe];
      }

      array_push($table_data1, array(  
       'gid' => $row1[gid],
       'vorname' => $row1[vorname],
       'nachname' => $row1[nachname],
       'status' => $status,
       'status_klartext' => $status_klartext,
       'frist_tag' => $row1[frist_tag],
       'frist_datum_abgabe' => $abgabefrist
      )
      );
    }
    $smarty->assign('table_data1', $table_data1);

}

$smarty->assign('action', "$action");
$smarty->display("$template/$templatename");

?>