Subversion-Projekte lars-tiefland.content-management

Revision

Revision 1 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php
    $path = "module/content-management/";
    if ( !defined( "IS_WEBAN" ) )
    {
        if ( $_SERVER["REMOTE_ADDR"] == "89.245.130.99" || $_SERVER["PHP_AUTH_USER"] ==
            "admin" || preg_match( "/192\.168\.0/", $_SERVER["REMOTE_ADDR"] ) )
        {
            define( "IS_WEBAN", true );
        }
        else
        {
            define( "IS_WEBAN", false );
        }
    }
    require_once "Log.php";
    function microtime_float()
    {
        list( $usec, $sec ) = explode( " ", microtime() );
        return ( ( float )$usec + ( float )$sec );
    }

    define( "DEBUG", true );

    session_start();

    $database_name = "content_management";

    $MySQL_Host = "localhost";

    if ( $_SERVER["SERVER_NAME"] != "server3" && !stristr($_SERVER["SERVER_NAME"],".local"))
    {
        $self = basename( $_SERVER["PHP_SELF"] );
        $MySQL_User = "Shop_Daemon";
        $MySQL_Passwd = "S-Jp-g";
        $MySQL_Host_write = "213.203.217.142";
    }
    else
    {
        $MySQL_User = "root";
        $MySQL_Passwd = "";
        $_SERVER["PHP_AUTH_USER"] = "admin";
        $root = -1;
    }

    // Verbindung zum Server herstellen
    if ( !$localhost_dbh = mysql_connect( "$MySQL_Host", "$MySQL_User", "$MySQL_Passwd" ) )
    {
        echo
            "Die Verbindung zum Datenbanksever konnte nicht hergestellt werden<br>";
        die( mysql_errno() . ": " . mysql_error() );
    }

    // Datenbank CMS anwählen
    if ( !$db = mysql_select_db( "$database_name" ) )
    {
        echo "Die Verbindung zur Datenbank <font color=\"#FF0000\">$database_name</font> konnte nicht hergestellt werden<br>";
        die( mysql_errno() . ": " . mysql_error() );
    }

    // Datenbank des Kunden auslesen
    require_once $path . "whoami.php";
    require_once $path . "webs.php";

    // user & web_rechte einlesen
    require_once $path . "get_rechte.php";

    // Falls ein remoteServer eingetragen ist Verbindung zu diesem Server herstellen
    if ( $webs["db_server"] )
    {
        if ( !$remoteServer_dbh = mysql_connect( $webs["db_server"], $webs["db_username"],
            $webs["db_password"] ) )
        {
            echo
                "Die Verbindung zum Datenbanksever konnte nicht hergestellt werden<br>";
            die( mysql_errno() . ": " . mysql_error() );
        }
    }

    // Shop-Datenbank anwählen
    //$webs[datenbank] = "kuehlerundklima_de";
    if ( !$db = mysql_select_db( $webs["datenbank"] ) )
    {
        var_dump( $webs );
        echo "Die Verbindung zur Datenbank <font color=\"#FF0000\">" . $webs["datenbank"] .
            "</font> konnte nicht hergestellt werden<br>";
        die( mysql_errno() . ": " . mysql_error() );
    }

    if ( !$webs["bgcolor_seite"] )
    {
        $webs["bgcolor_seite"] = "FFFFFF";
    }
    if ( !$webs["bgcolor_links"] )
    {
        $webs["bgcolor_links"] = "FFFFFF";
    }
    if ( !$webs["bgcolor_rechts"] )
    {
        $webs["bgcolor_rechts"] = "FFFFFF";
    }

    if ( !$webs["font_color_seite"] )
    {
        $webs["font_color_seite"] = "000000";
    }
    if ( !$webs["font_color_links"] )
    {
        $webs["font_color_links"] = "000000";
    }
    if ( !$webs["font_color_rechts"] )
    {
        $webs["font_color_rechts"] = "000000";
    }

    // Variablen freigeben
    unset( $query );
    unset( $result );

    function timestamp2human( $date )
    {
        $Jahr = substr( $date, 0, 4 );
        $Monat = substr( $date, 4, 2 );
        $Tag = substr( $date, 6, 2 );

        $Stunde = substr( $date, 8, 2 );
        $Minute = substr( $date, 10, 2 );
        $Sekunde = substr( $date, 12, 2 );

        return array( "Datum" => "$Tag.$Monat.$Jahr", "Zeit" => "$Stunde:$Minute:$Sekunde" );
    }

    function datetime2human( $date )
    {
        $date = preg_split( "/ /", $date );
        return array( "Datum" => join( ".", array_reverse( preg_split( "/-/",
            $date[0] ) ) ), "Zeit" => $date[1] );
    }

    function date2human( $date )
    {
        return join( ".", array_reverse( preg_split( "/-/", $date ) ) );
    }

    function human2date( $date )
    {
        return join( "-", array_reverse( preg_split( "/\./", $date ) ) );
    }

    function display( $ar )
    {
        return pre( $ar, true );
    }

    function pre( $elem, $r = false, $dump = false )
    {
        if ( $dump == true )
        {
            $output = "<pre>" . htmlentities( var_export( $elem, true ) ) .
                "</pre>";
        }
        else
        {
            $output = "<pre>" . htmlentities( print_r( $elem, true ) ) .
                "</pre>";
        }

        if ( $r == true )
        {
            return $output;
        }
        else
        {
            echo $output;
        }
    }

    function build_log( $id, $type, $filename = "" )
    {
        $old_content = "";
        switch ( $type )
        {
            case "xml_export":
                $content = date( "d.m.Y H:i:s", time() ) .
                    " -xml- Die Datei " . $filename . " wurde erstellt.\n";

                break;
            case "ftp_upload":
                $content = date( "d.m.Y H:i:s", time() ) .
                    " -ftp- Die Datei " . $filename . " wurde hochgeladen.\n";
                break;
            case "img_upload":
                $content = date( "d.m.Y H:i:s", time() ) .
                    " -img- Die Datei " . $filename . " wurde hochgeladen.\n";
                break;
            default:
                break;
        }

        $sql = "select ID,content from log where data_id = " . $id . "";

        $old_content = "";
        if ( $q = mysql_query( $sql ) )
        {
            $r = mysql_fetch_assoc( $q );
            $old_content = $r['content'];
        }
        $sql = "replace into log (data_id,content) 
                                        values (" . $id . ",concat('" . $old_content . "','" . $content . "'))";
        if ( $q = mysql_query( $sql ) )
        {
        }

    }


    function getUserInfo()
    {
        global $localhost_dbh;
        $sql = "
            SELECT
                *
            FROM
                content_management.Access
            WHERE
                user='" . $_SERVER["PHP_AUTH_USER"] . "'
        ";
        $res = mysql_query( $sql, $localhost_dbh );
        if ( $res )
        {
            $row = mysql_fetch_assoc( $res );
            $ret = $row;
        }
        if ( empty( $ret["name"] ) )
        {
            $ret["name"] = $_SERVER["PHP_AUTH_USER"];
        }
        return $ret;
    }

    function hilfeOverlib( $modul )
    {
        global $localhost_dbh;
        if ( empty( $modul ) )
        {
            die( 'Fehler! Es wurde $modul nicht übergeben!' );
        }

        $sql = '
            SELECT
                hilfetext,
                name
            FROM
               content_management.properties
            WHERE
                interner_name = "' . $modul . '"
       ;';
        $result = mysql_query( $sql, $localhost_dbh ) or die( mysql_errno() .
            ': ' . mysql_error() . '<hr />' . $sql );
        $row = mysql_fetch_assoc( $result );

        $name = $row['name'];
        $hilfetext = $row['hilfetext'];

        $hilfetext = strip_tags( $hilfetext );
        $hilfetext = str_replace( "\"", "", $hilfetext );
        $hilfetext = str_replace( "\r\n", "<br>", $hilfetext );

        $hilfeReturn = "<a href='http://" . $_SERVER['SERVER_NAME'] .
            "/html/batterieverordnung.htm'
                                onmouseover='return overlib(\"" . $hilfetext . "\", CAPTION, \"$name\", HAUTO, VAUTO, WIDTH, 500);' onmouseout='return nd();'
                                >[?]</a>";

        return $hilfeReturn;
    }

    $erg = getUserInfo();
    $_SESSION["USERNAME"] = $erg["name"];
    $_SESSION["U_ID"] = $erg["ID"];
    $_SESSION["U_EMAIL"] = $erg["email"];
    $_SESSION["U_TELEFON"] = $erg["telefon"];
    $_SESSION["U_FAX"] = $erg["fax"];
    require_once $path . "loginTest.php";

    if ( isset( $web_rechte["admin"]["toolbox"]["logbuch"] ) )
    {
        require_once "MDB2.php";
        $conf["dsn"] = "mysqli://" . $webs["db_username"] . ":" . $webs["db_password"] .
            "@" . $webs["db_server"] . "/" . $webs["datenbank"];
        $conf["u_id"] = $_SESSION["U_ID"];
        $GLOBALS["Log"]["best"] = Log::factory( "weban_sql", "logbuch", "1",
            $conf );
        if ( PEAR::isError( $GLOBALS["Log"]["best"] ) )
        {
            die( $GLOBALS["Log"]["best"]->getMessage() );
        }
        $GLOBALS["Log"]["art"] = &Log::singleton( "weban_sql", "logbuch",
            "2", $conf );
        if ( PEAR::isError( $GLOBALS["Log"]["art"] ) )
        {
            die( $GLOBALS["Log"]["art"]->getMessage() );
        }
        $GLOBALS["Log"]["dir"] = &Log::singleton( "weban_sql", "logbuch",
            "3", $conf );
        if ( PEAR::isError( $GLOBALS["Log"]["dir"] ) )
        {
            die( $GLOBALS["Log"]["dir"]->getMessage() );
        }
    }
    if ( isset( $web_rechte["online_shop"]["language"]["standardsprache"] ) )
    {
        require_once "language_pack.php";
        foreach ( $language_pack as $l )
        {
            //if($)
            $val_langs[$l[0]] = 1;
        }
        $lang = $web_rechte["online_shop"]["language"]["standardsprache"];
        if ( !$lang || !array_key_exists( $lang, $val_langs ) )
        {
            $lang = "DE";
        }
    }
    else
    {
        $lang = "DE";
    }
    define( "DEFAULT_LANG", $lang );
    function weban_debug( $msg, $dump = false )
    {
        if ( IS_WEBAN )
        {
            return pre( $msg, true, $dump );
        }
    }
    function getWebSettings( $settings, $shop = 1, $bestell_art = 1 )
    {
        $sql = "SHOW COLUMNS FROM web_settings";
        $res = mysql_query( $sql );
        $where_sql="";
        while ( $row = mysql_fetch_assoc( $res ) )
        {
            if($row["Field"]=="bestellart_id")
            {
                $where_sql = " AND bestellart_id = $bestell_art";
            }
        }
        $sql = "SELECT
                *
            FROM
                web_settings
            WHERE
                shops_id = $shop
            $where_sql
            AND
                ID IN (".implode(",",$settings).")
        ";
        $res = mysql_query($sql);
        while($row = mysql_fetch_assoc($res))
        {
            $ret[$row["ID"]] = $row["Inhalt"];
        }
        return $ret;
    }
?>