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


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


if($action == ''){
    
    
    $query1 = "SELECT klasse, punkte_umsetzbar, punkte_nicht_umsetzbar, replace(praemie_euro,'€','&euro;') praemie_euro, praemie_dienstfrei
                 FROM imt_praemie
                ORDER BY klasse asc
               ";
  
    $result1 = $db->query ($query1)
              or die ("Cannot execute query1");
    
    $table_data1 = array();
      
    while ($row1 = $result1->fetch_array()){

      array_push($table_data1, array(  
       'klasse' => $row1['klasse'],
       'punkte_umsetzbar' => $row1['punkte_umsetzbar'],
       'punkte_nicht_umsetzbar' => $row1['punkte_nicht_umsetzbar'],
       'praemie_euro' => $row1['praemie_euro'],
       'praemie_dienstfrei' => $row1['praemie_dienstfrei']
      )
      );
    }
    $smarty->assign('table_data1', $table_data1);
    
}

if($action == 'step2'){

  for ($i=1;$i<11;$i++) {
    $euro = iconv("UTF-8", "CP1252", $_POST['euro_'.$i]);
    $dienstfrei = iconv("UTF-8", "CP1252", $_POST['dienstfrei_'.$i]);
 
    $db = dbconnect();
    $sql1 = $db->query("UPDATE imt_praemie 
                            SET praemie_euro = '$euro'
                               ,praemie_dienstfrei = '$dienstfrei'
                          WHERE klasse=$i");
  }
  echo "<meta http-equiv=\"refresh\" content=\"0; URL=".$_SERVER['PHP_SELF']."\">";

}

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

?>