<?
include "header.php";
$action = $_POST['action'];
$fehler = "";
if ( logged_in() )
{
SmartyPaginate::connect();
SmartyPaginate::setLimit(10);
SmartyPaginate::setPageLimit(10);
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM `leistungen` order by `id` desc";
$sql .= " LIMIT ".SmartyPaginate::getCurrentIndex().",".SmartyPaginate::getLimit();
$result = mysql_query($sql) or die( mysql_error() );
$leistungen = array();
if (mysql_num_rows($result) > 0)
{
while ( $row = mysql_fetch_array($result) )
{
$leistungen[$row['id']] = $row ;
$leistungen[$row['id']]['preis'] = ereg_replace("\.",",",$leistungen[$row['id']]['preis']);
$leistungen[$row['id']]['preis_max'] = ereg_replace("\.",",",$leistungen[$row['id']]['preis_max']);
$leistungen[$row['id']]['zeitbedarf'] = ereg_replace("\.",",",$leistungen[$row['id']]['zeitbedarf']);
}
}
$aktion = $_POST['aktion'];
if ( $aktion == "edit" )
{
$id= $_POST['id'];
$edleistung = $leistungen[$id] ;
$edleistung['preis'] = ereg_replace("\.",",",$edleistung['preis']);
$edleistung['preis_max'] = ereg_replace("\.",",",$edleistung['preis_max']);
$edleistung['zeitbedarf'] = ereg_replace("\.",",",$edleistung['zeitbedarf']);
$smarty->assign("edleistung", $edleistung);
}
if ( $aktion == "resetedit" )
{
$edleistung = array();
$smarty->assign("edleistung", $edleistung);
}
if ( $aktion == "delete" )
{
$id = $_POST['id'];
$sql = "DELETE FROM `leistungen` WHERE `id`=".$id." LIMIT 1";
$result = mysql_query($sql) or die( mysql_error() );
$edleistung = array();
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM `leistungen` order by `id` desc";
$sql .= " LIMIT ".SmartyPaginate::getCurrentIndex().",".SmartyPaginate::getLimit();
$result = mysql_query($sql) or die( mysql_error() );
$leistungen = array();
if (mysql_num_rows($result) > 0)
{
while ( $row = mysql_fetch_array($result) )
{
$leistungen[$row['id']] = $row ;
$leistungen[$row['id']]['preis'] = ereg_replace("\.",",",$leistungen[$row['id']]['preis']);
$leistungen[$row['id']]['preis_max'] = ereg_replace("\.",",",$leistungen[$row['id']]['preis_max']);
$leistungen[$row['id']]['zeitbedarf'] = ereg_replace("\.",",",$leistungen[$row['id']]['zeitbedarf']);
}
}
$edleistung = $leistungen[$id] ;
$smarty->assign("edleistung", $edleistung);
}
if ( $aktion == "update" )
{
$id= $_POST['id'];
$bezeichnung = $_POST['bezeichnung'];
$rubrik = $_POST['rubrik'];
$preis = round( ereg_replace(",",".",$_POST['preis']), 2);
$preis_max = round( ereg_replace(",",".",$_POST['preis_max']), 2);
$zeitbedarf = round( ereg_replace(",",".",$_POST['zeitbedarf']), 2);
if ( $id > 0 )
{
$sql = "UPDATE `leistungen` ";
$sql .= "SET `bezeichnung`='".$bezeichnung."', ";
$sql .= "`rubrik`='".$rubrik."', ";
$sql .= "`preis`=".$preis.", ";
$sql .= "`preis_max`=".$preis_max.", ";
$sql .= "`zeitbedarf`=".$zeitbedarf." ";
$sql .= " WHERE `id`=".$id." LIMIT 1";
$result = mysql_query($sql) or die( mysql_error() );
}
if ( ( $id < 1 ) || ( mysql_affected_rows() == 0 ) )
{
if ( $id > 0 )
{
$sql = "SELECT * FROM `leistungen` WHERE `id` = ".$id." LIMIT 1";
$result = mysql_query($sql) or die( mysql_error() );
}
if ( ( $id < 1 ) || (mysql_num_rows($result) == 0) )
{
$sql = "INSERT into `leistungen` ( `bezeichnung`, `rubrik`, `preis`, `preis_max`, `zeitbedarf` )";
$sql .= " VALUES ( '".$bezeichnung."', '".$rubrik."', ".$preis.", ".$preis_max.", ".$zeitbedarf." )";
$result = mysql_query($sql) or die( mysql_error() );
}
}
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM `leistungen` order by `id` desc";
$sql .= " LIMIT ".SmartyPaginate::getCurrentIndex().",".SmartyPaginate::getLimit();
$result = mysql_query($sql) or die( mysql_error() );
$leistungen = array();
if (mysql_num_rows($result) > 0)
{
while ( $row = mysql_fetch_array($result) )
{
$leistungen[$row['id']] = $row ;
$leistungen[$row['id']]['preis'] = ereg_replace("\.",",",$leistungen[$row['id']]['preis']);
$leistungen[$row['id']]['preis_max'] = ereg_replace("\.",",",$leistungen[$row['id']]['preis_max']);
$leistungen[$row['id']]['zeitbedarf'] = ereg_replace("\.",",",$leistungen[$row['id']]['zeitbedarf']);
}
}
$edleistung = $leistungen[$id] ;
$smarty->assign("edleistung", $edleistung);
}
$sql = "SELECT FOUND_ROWS() as total";
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
SmartyPaginate::setTotal($row['total']);
mysql_free_result($result);
SmartyPaginate::assign($smarty);
}
else
{
$fehler = "<p>Du bist nicht eingeloggt!</p>";
}
$smarty->assign("Fehlertext", $fehler );
$smarty->assign("leistungen", $leistungen );
$smarty->assign("TEMPLATE", "artikeladmin.tpl");
$smarty->assign("AKTION", $action);
include "footer.php";
$smarty->display('template.tpl');
?>