Subversion-Projekte lars-tiefland.content-management

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
    /**
3
     * @author Webagentur Niewerth niewerth@weban.de
4
     * @copyright 2008
5
     * @package Content-management
6
     * @version 1.0.0
7
     * @license propietary
8
     */
9
 
10
 
11
    require_once  "../Online-Shop/connect2.php";
12
 
13
    session_start();
14
 
15
    $webId = isset( $_REQUEST['webId'] ) ? $_REQUEST['webId'] : null;
16
    $expName = isset( $_REQUEST['expName'] ) ? $_REQUEST['expName'] : null;
17
 
18
    $path = "../Online-Shop/includes/artikel_zusatzinfo/";
19
    if ( !$ini = parse_ini_file($path . $webId . ".ini", true) )
20
    {
21
        var_dump($_REQUEST);
22
        die();
23
    }
24
 
25
    $src_folder = "../xml/" . $expName . "/" . $ini['web']['xmlFolder'];
26
 
27
    $files = get_files( $src_folder );
28
    $html = "";
29
 
30
    if ( $_REQUEST['xml_upload'] == 1 )
31
    {
32
        $html .= xml_upload( $files, $src_folder );
33
    }
34
 
35
    //echo $html;
36
 
37
    // ziel, quelle,
38
    function xml_upload( $files, $src_folder )
39
    {
40
        global $ini;
41
        global $expName;
42
        $html = "";
43
 
44
        $ftpName = $ini[$expName]['ftpName'];
45
        $ftpPass = $ini[$expName]['ftpPass'];
46
 
47
        if ( $files )
48
        {
49
            // soll die datei exportiert werden?
50
            $sql = "select *
51
				from artikel where immo_export_" . $ini[$expName]['immoExportId'] . "=1
52
				order by ID";
53
 
54
 
55
            if ( $q = mysql_query($sql) )
56
            {
57
				if ( $ftp = ftp_connect($ini[$expName]['ftpHost']) )
58
                {
59
					if ( ftp_login($ftp, $ini[$expName]['ftpName'], $ini[$expName]['ftpPass']) )
60
					{
61
                		while ( $r = mysql_fetch_assoc($q) )
62
                		{
63
 
64
                    		if ( $r['immo_export_0'] == 1 )
65
                    		{
66
	                            foreach ( $files as $k => $v )
67
	                            {
68
	                                $tmp = explode( "_", $v );
69
	                                $fileID = $tmp[0];
70
	                                if ( $fileID == $r['ID'] )
71
	                                {
72
	                                    $local = $src_folder . "/" . $v;
73
 
74
	                                    if ( is_file($local) )
75
	                                    {
76
	                                        if ( ftp_put($ftp, $v, $local, FTP_ASCII) )
77
	                                        {
78
 
79
	                                            // die dateien in lokalen archivordner kopieren
80
	                                            $archive = $src_folder . "/archive/" . $v;
81
 
82
	                                            if ( rename($local, $archive) )
83
	                                            {
84
	                                                if ( $_REQUEST['img_upload'] == 1 )
85
	                                                {
86
	                                                    $html .= img_upload( $r['ID'] );
87
	                                                }
88
 
89
	                                                build_log( $r['ID'], "ftp_upload", "/xml/" . $expName . "/" . $ini['web']['xmlFolder'] .
90
	                                                    "/" . $val );
91
	                                            }
92
	                                        }
93
	                                    }
94
	                                }
95
	                        	}
96
                        	}
97
                    	} // end while
98
                	}
99
            	}
100
				if ( ftp_close($ftp) )
101
                {
102
	                //echo "<br>ftp conn closed.";
103
                }
104
        	}
105
		}
106
        return $html;
107
    }
108
 
109
 
110
 
111
    function img_upload( $id ) {
112
        global $ini;
113
        global $webs;
114
        global $expName;
115
        $html = "";
116
 
117
        if ( $ftp = ftp_connect($ini[$expName]['ftpHost']) ) {
118
 
119
            if ( ftp_login($ftp, $ini[$expName]['ftpName'], $ini[$expName]['ftpPass']) )
120
            {
121
 
122
 
123
                $imgData = array();
124
                // Sonderfall is24:
125
                if ( $expName == "is24" )
126
                {
127
                    if ( $imgData = getImgData($ini, $expName, $id) )
128
                    {
129
 
130
                        foreach ( $imgData as $key_ => $val_ )
131
                        {
132
                            $local = $ini['web']['weburl'] . "/images/" . $key_ . "/" . $val_;
133
 
134
                            if ( ftp_put($ftp, $val_, $local, FTP_ASCII) )
135
                            {
136
                                //echo "<br>" . $local . " übertragen.";
137
                                build_log( $id, "img_upload", $local );
138
                            }
139
                        }
140
                    }
141
                }
142
 
143
            }
144
            if ( ftp_close($ftp) )
145
            {
146
                //echo "<br>ftp conn closed.";
147
            }
148
        }
149
        return $html;
150
    }
151
 
152
    function get_files( $src_folder )
153
    {
154
        // src folder einlesen
155
        if ( $dp = opendir($src_folder) )
156
        {
157
            while ( false !== ($file = readdir($dp)) )
158
            {
159
                if ( $file != "." && $file != ".." )
160
                {
161
                    $files[] = $file;
162
                }
163
            }
164
        }
165
        closedir( $dp );
166
        return $files;
167
    }
168
 
169
 
170
    function getImgData( $ini, $expName, $artikelId )
171
    {
172
        //quasi-hardcoded die 7 db felder für das select erzeugen
173
        for ( $i = 1; $i <= 7; $i++ )
174
        {
175
            $fldArr[$i] = "bild_" . $i . "_url";
176
        }
177
        $flds = implode( ",", $fldArr );
178
 
179
 
180
        $sql = "select " . $flds . " from artikel where ID=" . $artikelId . "";
181
 
182
        if ( $q = mysql_query($sql) )
183
        {
184
            while ( $r = mysql_fetch_assoc($q) )
185
            {
186
 
187
                foreach ( $fldArr as $key => $val )
188
                {
189
 
190
                    if ( $r[$val] )
191
                    {
192
 
193
                        //	echo "<br>bild: ".$r[$val];
194
                        $imgData[ereg_replace( "b", "B", substr($val, 0, 6) )] = $r[$val];
195
 
196
                    }
197
                }
198
            }
199
        }
200
        return $imgData;
201
    }
202
 
203
?>