<?php
session_start();
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";

  if(isset($_GET['id'])){
    $_SESSION["edit_id"] = $_GET['id'];
  }
  $id = $_SESSION["edit_id"];
  
  
  $query = "SELECT date_format(datum,'%d.%m.%Y (%H:%i)') date_form, verlauf, vorname, nachname
              FROM imt_user a, imt_verlauf b
             WHERE a.imtuid=b.bearbeiter
               AND b.vid = '$id'
             ORDER BY datum DESC, vlid ASC";
    $result = $db->query ($query)
            or die ("Cannot execute query");
  
  $table_data = array();
  
  while ($row = $result->fetch_array()){


        $upas = Array("&auml;" => "ä", "&uuml;" => "ü", "&ouml;" => "ö", "&Auml;" => "Ä", "&Uuml;" => "Ü", "&Ouml;" => "Ö", "&szlig;" => "ß"); 
        $upas2 = Array("ä" => "&auml;", "ü" => "&uuml;", "ö" => "&ouml;", "Ä" => "&Auml;", "Ü" => "&Uuml;", "Ö" => "&Ouml;", "ß" => "&szlig;"); 

        $spalte2_width = 25;
        $spalte2 = "$row[vorname] $row[nachname]";
        $spalte2_len = strtr($spalte2, $upas);
        $len_spalte2 = strlen($spalte2_len);
        if($len_spalte2 >= $spalte2_width){        
          $spalte2 = substr("$spalte2",0 ,$spalte2_width-4)."...";
          $spalte2_len = strtr($spalte2, $upas);
          $len_spalte2 = strlen($spalte2_len);
        }else{
          $spalte2_len = strtr($spalte2, $upas);
          $len_spalte2 = strlen($spalte2_len);
        }
        
        $rest_spalte2 = $spalte2_width-$len_spalte2;
        $space_spalte2 = "";
        $spalte2 = strtr($spalte2, $upas2);
        for($j=0;$j<$rest_spalte2;$j++){
          $space_spalte2 .= "&nbsp;";
        }
        
        
        
        $spalte3_width = 100;
        $spalte3 = "$row[verlauf]";
        $spalte3_len = strtr($spalte3, $upas);
        $len_spalte3 = strlen($spalte3_len);
        if($len_spalte3 >= $spalte3_width){        
          $spalte3 = substr("$spalte3",0 ,$spalte3_width-4)."...";
          $spalte3_len = strtr($spalte3, $upas);
          $len_spalte3 = strlen($spalte3_len);
        }else{
          $spalte3_len = strtr($spalte3, $upas);
          $len_spalte3 = strlen($spalte3_len);
        }
        $spalte3 = strtr($spalte3, $upas2);
        $rest_spalte3 = $spalte3_width-$len_spalte3;
        $space_spalte3 = "";
        
        for($j=0;$j<$rest_spalte3;$j++){
          $space_spalte3 .= "&nbsp;";
        }
  
    array_push($table_data, array(
     'date_form' => $row['date_form'],
     'name' => $spalte2,
     'space_name' => $space_spalte2,
     'verlauf' => $spalte3,
     'space_verlauf' => $space_spalte3
    )
    );
  }
$smarty->assign('table_data', $table_data);

$smarty->display("$template/$templatename");
?>