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

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

if ( logged_in() )
{

        $sql = "SELECT * FROM `firma` order by `idfirma` desc";
        $result = mysql_query($sql) or die( mysql_error() );
        $firmen = array();
        if (mysql_num_rows($result) > 0)
        {
        	while ( $row = mysql_fetch_array($result) )
        	{
                        $firmen[$row['idfirma']] = $row ;
                        $edfirma = $row;
        	}
        }
        $smarty->assign("firma", $edfirma);
        if ( isset ( $_GET['aktion'] ) )  
        {
                $aktion = $_GET['aktion'];
                $methode = "GET";
        }
        else 
        {
                $aktion = $_POST['aktion'];
                $methode = "POST";
        }

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

                $smarty->assign("firma", $edlieferant);
        }
        if ( $aktion == "update" )
        {
                if ( $methode == "GET" )
                         $id = $_GET['idfirma'];
                else $id= $_POST['idfirma'];
                $daten = array(   'firma' => $_POST['firma'],
                                        'inhaber' => $_POST['inhaber'],
                                        'strasse' => $_POST['strasse'],
                                        'plz' => $_POST['plz'],
                                        'ort' => $_POST['ort'],
                                        'email' => $_POST['email'],
                                        'homepage' => $_POST['homepage'],
                                        'telefon' => $_POST['telefon'],
                                        'fax' => $_POST['fax'],
                                        'kontoinhaber' => $_POST['kontoinhaber'],
                                        'geldinstitut' => $_POST['geldinstitut'],
                                        'blz' => $_POST['blz'],
                                        'kontonr' => $_POST['kontonr'],
                                        'mwstsatz' => $_POST['mwstsatz'],
                                        'steuernr' => $_POST['steuernr'] );                                
                if ( $id > 0 )
                {
                        $sql = "UPDATE `firma` ";
                        $sql .= "SET `firma`='".$daten['firma']."', ";
                        $sql .= "`inhaber`='".$daten['inhaber']."', ";
                        $sql .= "`strasse`='".$daten['strasse']."', ";
                        $sql .= "`plz`='".$daten['plz']."', ";
                        $sql .= "`ort`='".$daten['ort']."', ";
                        $sql .= "`email`='".$daten['email']."', ";
                        $sql .= "`homepage`='".$daten['homepage']."', ";
                        $sql .= "`telefon`='".$daten['telefon']."', ";
                        $sql .= "`fax`='".$daten['fax']."', ";
                        $sql .= "`kontoinhaber`='".$daten['kontoinhaber']."', ";
                        $sql .= "`geldinstitut`='".$daten['geldinstitut']."', ";
                        $sql .= "`blz`='".$daten['blz']."', ";
                        $sql .= "`kontonr`='".$daten['kontonr']."', ";
                        $sql .= "`mwstsatz`=".$daten['mwstsatz'].", ";
                        $sql .= "`steuernr`='".$daten['steuernr']."' ";
                        $sql .= " WHERE `idfirma`=".$id." LIMIT 1";
                        $result = mysql_query($sql) or die( mysql_error() );
                }
                if ( ( $id < 1 ) || ( mysql_affected_rows() == 0 ) )
                {
                        if ( $id > 0 )
                        {
                                $sql = "SELECT * FROM `firma` WHERE `idfirma` = ".$id." LIMIT 1";
                                $result = mysql_query($sql) or die( mysql_error() );
                        }
                        if ( ( $id < 1 )  || (mysql_num_rows($result) == 0) )
                        {
                                $sql = "INSERT into `firma` ( `firma`, ";
                                $sql .= " `inhaber`, ";
                                $sql .= " `strasse`, ";
                                $sql .= " `plz`, ";
                                $sql .= " `ort`, ";
                                $sql .= " `email`, ";
                                $sql .= " `homepage`, ";
                                $sql .= " `telefon`, ";
                                $sql .= " `fax`, ";
                                $sql .= " `kontoinhaber`, ";
                                $sql .= " `geldinstitut`, ";
                                $sql .= " `blz`, ";
                                $sql .= " `kontonr`, ";
                                $sql .= " `mwstsatz`, ";
                                $sql .= " `steuernr` )";
                                $sql .= " VALUES ( ";
                                $sql .= " '".$daten['firma']."', ";
                                $sql .= " '".$daten['inhaber']."', ";
                                $sql .= " '".$daten['strasse']."', ";
                                $sql .= " '".$daten['plz']."', ";
                                $sql .= " '".$daten['ort']."', ";
                                $sql .= " '".$daten['email']."', ";
                                $sql .= " '".$daten['homepage']."', ";
                                $sql .= " '".$daten['telefon']."', ";
                                $sql .= " '".$daten['fax']."', ";
                                $sql .= " '".$daten['kontoinhaber']."', ";
                                $sql .= " '".$daten['geldinstitut']."', ";
                                $sql .= " '".$daten['blz']."', ";
                                $sql .= " '".$daten['kontonr']."', ";
                                $sql .= " ".$daten['mwstsatz'].", ";
                                $sql .= " '".$daten['steuernr']."' )";
                                $result = mysql_query($sql) or die( mysql_error() );
                        }
                }

                $sql = "SELECT * FROM `firma` order by `idfirma` desc";
                $result = mysql_query($sql) or die( mysql_error() );
                $firmen = array();
                if (mysql_num_rows($result) > 0)
                {
        	        while ( $row = mysql_fetch_array($result) )
        	        {
                                $firmen[$row['idfirma']] = $row ;
        	        }
                }
                $edfirma = $firmen[$id] ;

                $smarty->assign("firma", $edfirma);

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