Location: PHPKode > projects > PHP OpenTailorShop > phpopentailorshop/webkasse/kundenadmin.php
<?
include "header.php";

$action = $_POST['action'];
$fehler = "";

if ( logged_in() )
{
        $sql = "SELECT * FROM `kunden` order by `KundenNr` asc";
        $result = mysql_query($sql) or die( mysql_error() );
        $kunden = array();
        if (mysql_num_rows($result) > 0)
        {
        	while ( $row = mysql_fetch_array($result) )
        	{
                        $kunden[$row['KundenNr']] = $row ;
        	}
        }
        if ( isset ( $_GET['aktion'] ) )  
        {
                $aktion = $_GET['aktion'];
                $methode = "GET";
        }
        else 
        {
                $aktion = $_POST['aktion'];
                $methode = "POST";
        }

        
        if ( $aktion == "edit" )
        {
                if ( $methode == "GET" ) $id = $_GET['KundenNr'];
                else $id= $_POST['KundenNr'];
                $edkunde = $kunden[$id] ;
                $smarty->assign("edkunde", $edkunde);
        }
        if ( $aktion == "resetedit" )
        {
                $edkunde = array();
                $smarty->assign("edkunde", $edkunde);
        }
        if ( $aktion == "delete" )
        {
                if ( $methode == "GET" ) $id = $_GET['KundenNr'];
                else $id= $_POST['KundenNr'];
                $sql = "DELETE FROM `kunden` WHERE `KundenNr`=".$id." LIMIT 1";
                $result = mysql_query($sql) or die( mysql_error() );
                $edkunden = array();
                $sql = "SELECT * FROM `kunden` order by `KundenNr` asc";
                $result = mysql_query($sql) or die( mysql_error() );
                $kunden = array();
                if (mysql_num_rows($result) > 0)
                {
        	        while ( $row = mysql_fetch_array($result) )
        	        {
                                $kunden[$row['KundenNr']] = $row ;
        	        }
                }
                $edkunde = $kunden[$id] ;

                $smarty->assign("edkunde", $edkunde);
        }
        if ( $aktion == "update" )
        {
                if ( $methode == "GET" )
                         $id = $_GET['KundenNr'];
                else $id= $_POST['KundenNr'];
                
                
                $firma = $_POST['Firma'];
                $telefon = $_POST['Telefonnummer'];
                $ort = $_POST['Ort'];
                if ( $id > 0 )
                {
                        $sql = "UPDATE `kunden` ";
                        $sql .= "SET `Firma`='".$firma."', ";
                        $sql .= "`Telefonnummer`='".$telefon."', ";
                        $sql .= "`Ort`='".$ort."' ";
                        $sql .= " WHERE `KundenNr`=".$id." LIMIT 1";
                        $result = mysql_query($sql) or die( mysql_error() );
                }
                if ( ( $id < 1 ) || ( mysql_affected_rows() == 0 ) )
                {
                        if ( $id > 0 )
                        {
                                $sql = "SELECT * FROM `kunden` WHERE `KundenNr` = ".$id." LIMIT 1";
                                $result = mysql_query($sql) or die( mysql_error() );
                        }
                        if ( ( $id < 1 )  || (mysql_num_rows($result) == 0) )
                        {
                                $sql = "INSERT into `kunden` ( `Firma`, `Telefonnummer`, `Ort` )";
                                $sql .= " VALUES ( '".$firma."', '".$telefon."', '".$ort."' )";
                                $result = mysql_query($sql) or die( mysql_error() );
                        }
                }

                $sql = "SELECT * FROM `kunden` order by `KundenNr` asc";
                $result = mysql_query($sql) or die( mysql_error() );
                $kunden = array();
                if (mysql_num_rows($result) > 0)
                {
        	        while ( $row = mysql_fetch_array($result) )
        	        {
                                $kunden[$row['KundenNr']] = $row ;
        	        }
                }
                $edkunde = $kunden[$id] ;

                $smarty->assign("edkunde", $edkunde);

        }
}
else
{
        $fehler = "<p>Du bist nicht eingeloggt!</p>";
}
$smarty->assign("Fehlertext", $fehler );
$smarty->assign("leistungen", $kunden );
$smarty->assign("TEMPLATE", "kundenadmin.tpl");
$smarty->assign("AKTION", $action);
include "footer.php";
$smarty->display('template.tpl');
?>
Return current item: PHP OpenTailorShop