<?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";

$action = $_GET['action'];
if(isset($_GET['id'])){
  $_SESSION["status_id"] = $_GET['id'];
}

if($action == ''){


  
  $db = dbconnect();
    
    $query = "SELECT a.vid, betreff, date_format(a.erfass_dat, '%d.%m.%Y %H:%i:%s') erfass_dat_form, vorname, nachname, date_format(frist_datum, '%d.%m.%Y') frist_dat_form
                FROM imt_vorschlag a, imt_beteiligte b, imt_user c
               WHERE a.vid = b.vid
                 AND a.imtuid=c.imtuid
                 AND 1 = (SELECT CASE 1 WHEN (SELECT count(*)
			                        FROM imt_verlauf d
			                       WHERE d.vid=a.vid
			                         AND d.status IN ('7', '8')
			                       GROUP BY vid
			                     )>0 
			                THEN '0'
			                ELSE '1'
			                END 
			                # Man darf den Fall solange sehen, bis er abgeschlossen ist, also entweder mit Status 7 oder 8
			 )
                 AND b.imtuid = '$uid'
               GROUP BY a.vid
               ORDER BY frist_datum ASC";

    $result = $db->query ($query)
              or die ("Cannot execute query");
    
    $table_data1 = array();
      
    while ($row = $result->fetch_array()){
     
      array_push($table_data1, array(  
       'vid' => $row['vid'],
       'betreff' => $row['betreff'],
       'erfass_dat_form' => $row['erfass_dat_form'],
       'frist_dat_form' => $row['frist_dat_form']
      )
      );
    }
    
    $smarty->assign('table_data1', $table_data1);
    

}





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

?>
