Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php
    /**
     * @author Webagentur Niewerth niewerth@weban.de
     * @copyright 2008 
     * @package Content-management
     * @version 1.0.0
     * @license propietary
     */


    require_once  "../Online-Shop/connect2.php";

    session_start();

    $webId = isset( $_REQUEST['webId'] ) ? $_REQUEST['webId'] : null;
    $expName = isset( $_REQUEST['expName'] ) ? $_REQUEST['expName'] : null;

    $path = "../Online-Shop/includes/artikel_zusatzinfo/";
    if ( !$ini = parse_ini_file($path . $webId . ".ini", true) )
    {
        var_dump($_REQUEST);
        die();
    }

    $src_folder = "../xml/" . $expName . "/" . $ini['web']['xmlFolder'];

    $files = get_files( $src_folder );
    $html = "";

    if ( $_REQUEST['xml_upload'] == 1 )
    {
        $html .= xml_upload( $files, $src_folder );
    }

    //echo $html;

    // ziel, quelle,
    function xml_upload( $files, $src_folder )
    {
        global $ini;
        global $expName;
        $html = "";

        $ftpName = $ini[$expName]['ftpName'];
        $ftpPass = $ini[$expName]['ftpPass'];

        if ( $files )
        {
            // soll die datei exportiert werden?
            $sql = "select * 
                                from artikel where immo_export_" . $ini[$expName]['immoExportId'] . "=1 
                                order by ID";

            
            if ( $q = mysql_query($sql) )
            {
                                if ( $ftp = ftp_connect($ini[$expName]['ftpHost']) )
                {
                                        if ( ftp_login($ftp, $ini[$expName]['ftpName'], $ini[$expName]['ftpPass']) )
                                        {
                                while ( $r = mysql_fetch_assoc($q) )
                                {

                                if ( $r['immo_export_0'] == 1 )
                                {
                                    foreach ( $files as $k => $v )
                                    {
                                        $tmp = explode( "_", $v );
                                        $fileID = $tmp[0];
                                        if ( $fileID == $r['ID'] )
                                        {
                                            $local = $src_folder . "/" . $v;
                                            
                                            if ( is_file($local) )
                                            {
                                                if ( ftp_put($ftp, $v, $local, FTP_ASCII) )
                                                {
                                            
                                                    // die dateien in lokalen archivordner kopieren
                                                    $archive = $src_folder . "/archive/" . $v;
        
                                                    if ( rename($local, $archive) )
                                                    {
                                                        if ( $_REQUEST['img_upload'] == 1 )
                                                        {
                                                            $html .= img_upload( $r['ID'] );
                                                        }
        
                                                        build_log( $r['ID'], "ftp_upload", "/xml/" . $expName . "/" . $ini['web']['xmlFolder'] .
                                                            "/" . $val );
                                                    }
                                                }
                                            }
                                        }
                                        }
                                }
                        } // end while
                        }
                }
                                if ( ftp_close($ftp) )
                {
                        //echo "<br>ftp conn closed.";
                }
                }
                }
        return $html;
    }



    function img_upload( $id ) {
        global $ini;
        global $webs;
        global $expName;
        $html = "";

        if ( $ftp = ftp_connect($ini[$expName]['ftpHost']) ) {

            if ( ftp_login($ftp, $ini[$expName]['ftpName'], $ini[$expName]['ftpPass']) )
            {


                $imgData = array();
                // Sonderfall is24:
                if ( $expName == "is24" )
                {
                    if ( $imgData = getImgData($ini, $expName, $id) )
                    {

                        foreach ( $imgData as $key_ => $val_ )
                        {
                            $local = $ini['web']['weburl'] . "/images/" . $key_ . "/" . $val_;

                            if ( ftp_put($ftp, $val_, $local, FTP_ASCII) )
                            {
                                //echo "<br>" . $local . " übertragen.";
                                build_log( $id, "img_upload", $local );
                            }
                        }
                    }
                }

            }
            if ( ftp_close($ftp) )
            {
                //echo "<br>ftp conn closed.";
            }
        }
        return $html;
    }

    function get_files( $src_folder )
    {
        // src folder einlesen
        if ( $dp = opendir($src_folder) )
        {
            while ( false !== ($file = readdir($dp)) )
            {
                if ( $file != "." && $file != ".." )
                {
                    $files[] = $file;
                }
            }
        }
        closedir( $dp );
        return $files;
    }


    function getImgData( $ini, $expName, $artikelId )
    {
        //quasi-hardcoded die 7 db felder für das select erzeugen
        for ( $i = 1; $i <= 7; $i++ )
        {
            $fldArr[$i] = "bild_" . $i . "_url";
        }
        $flds = implode( ",", $fldArr );


        $sql = "select " . $flds . " from artikel where ID=" . $artikelId . "";

        if ( $q = mysql_query($sql) )
        {
            while ( $r = mysql_fetch_assoc($q) )
            {

                foreach ( $fldArr as $key => $val )
                {

                    if ( $r[$val] )
                    {

                        //      echo "<br>bild: ".$r[$val];
                        $imgData[ereg_replace( "b", "B", substr($val, 0, 6) )] = $r[$val];

                    }
                }
            }
        }
        return $imgData;
    }

?>