<?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($action == ''){
  $sid = session_id();
  
  
    $db = dbconnect();
    $query = "SELECT name, mail FROM imt_gruppenmitglieder_temp WHERE session='$sid' AND imtuid='$_SESSION[global_uid]' ORDER BY name ASC";
    $result = $db->query ($query)
              or die ("Cannot execute query");

    $table_data = array();
    
    while ($row = $result->fetch_array()){
      
      array_push($table_data, array(
       'name' => $row['name'],
       'mail' => $row['mail']
      )
      );
    }

    $smarty->assign('table_data', $table_data);
    
}

if($action == 'save'){
  $name = $_POST["mitgl_name"];
  $mail = $_POST["mitgl_mail"];
  $sid = session_id();
  
  $datum = date("Y-m-d H:i:s");
  
  if($name != ''){
    $db = dbconnect();
    $sql = $db->query("INSERT INTO imt_gruppenmitglieder_temp (session, imtuid, name, mail, datum) VALUES ('$sid', '$_SESSION[global_uid]', '$name', '$mail', '$datum')");
  }
  
  echo "<meta http-equiv=\"refresh\" content=\"0; URL=".$_SERVER['PHP_SELF']."?\">";

}

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

?>