Subversion-Projekte lars-tiefland.content-management

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
    /**
4
     * eportiert Adressen von Kunden an DHL
5
     *
6
     * @package   Content-management
7
     * @author    Lars Tiefland <tiefland@weban.de>
8
     * @copyright 2009 Webagentur Niewerth
9
     * @license   propietary http://www.weban.de
10
     * @version   $Rev: 3931 $
11
     * @filesource
12
     *
13
     */
14
 
15
    /**
16
     *
17
     *   @package   Content-management
18
     *   @author    Lars Tiefland <tiefland@weban.de>
19
     *   @copyright 2009 Webagentur Niewerth
20
     */
21
 
22
    // SVN: $Id: dhl_export.php 3931 2011-09-16 08:17:57Z tiefland $
23
 
24
    require_once 'Weban_Smarty.class.php';
25
    require_once '../Online-Shop/connect2.php';
26
    require_once 'File/Find.php';
27
    require_once 'module/functions.common.php';
28
 
29
    $GLOBALS["ui"] = new Weban_Smarty();
30
    $GLOBALS["ui"]->compile_dir = $_SERVER["DOCUMENT_ROOT"] . "/templates_c/";
31
    $GLOBALS["ui"]->compile_id = "Warenwirtschaft|export";
32
    $GLOBALS["ui"]->use_sub_dirs = true;
33
    $GLOBALS["ui"]->assign( "title", "Adressdaten nach DHL exportieren" );
34
    if ( isset( $user_rechte['Warenwirtschaft']['dhl_export']['dhl'] ) )
35
    {
36
        if ( $_GET['mode'] == 'new' )
37
        {
38
            dhl_export();
39
        } elseif ( $_GET['file'] )
40
        {
41
            $file = $_GET['file'];
42
            if ( file_exists( $file ) )
43
            {
44
                //header( 'Content-Type: text/plain' );
45
                header( 'Content-Disposition: attachment; filename="' .
46
                    basename( $file ) . '"' );
47
                readfile( $file );
48
            }
49
        }
50
        else
51
        {
52
            if ( !file_exists( "archiv/$site" ) )
53
            {
54
                mkdir( "archiv/$site" );
55
            }
56
            if ( !file_exists( "archiv/$site" ) )
57
            {
58
                mkdir( "archiv/$site" );
59
            }
60
            $ff = new File_Find();
61
            $files = $ff->search( "/export_Bestellungen_dhl_[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}.txt$/i",
62
                "archiv/$site/", "perl" );
63
            rsort( $files );
64
            foreach ( $files as $f_id => $file )
65
            {
66
                $files_arr[$f_id]["name"] = $file;
67
                $date = date( "d.m.Y H:i:s", filemtime( $file ) );
68
                $files_arr[$f_id]["desc"] = $date;
69
            }
70
            $GLOBALS["ui"]->assign( "files", $files_arr );
71
            $GLOBALS["ui"]->display( "export.tpl" );
72
        }
73
    }
74
    else
75
    {
76
        $GLOBALS["ui"]->assign( "meld",
77
            "Sie haben nicht das Recht dieses Tool zu nutzen!" );
78
        $GLOBALS["ui"]->assign( "error", true );
79
        $GLOBALS["ui"]->display( "meld.tpl" );
80
    }
81
 
82
 
83
    /**
84
     * dhl_export()
85
     *
86
     * @return void
87
     */
88
    function dhl_export()
89
    {
90
        global $site, $web_rechte;
91
        $date = date( 'Y-m-d_H-i-s' );
92
        $f_name = "export_Bestellungen_dhl_$date.txt";
93
        switch ( $web_rechte['Warenwirtschaft']['dhl_export']['dhl'] )
94
        {
95
            case "intraship":
96
                break;
97
            case "easylog":
98
                break;
99
            default:
100
                $header_arr[] = "SEND_NAME1";
101
                $header_arr[] = "SEND_NAME2";
102
                $header_arr[] = "SEND_STREET";
103
                $header_arr[] = "SEND_HOUSENUMBER";
104
                $header_arr[] = "SEND_PLZ";
105
                $header_arr[] = "SEND_CITY";
106
                $header_arr[] = "SEND_COUNTRY";
107
                $header_arr[] = "RECV_NAME1";
108
                $header_arr[] = "RECV_NAME2";
109
                $header_arr[] = "RECV_STREET";
110
                $header_arr[] = "RECV_HOUSENUMBER";
111
                $header_arr[] = "RECV_PLZ";
112
                $header_arr[] = "RECV_CITY";
113
                $header_arr[] = "RECV_COUNTRY";
114
                $header_arr[] = "PRODUCT";
115
                $header_arr[] = "COUPON";
116
                $header = implode( "\t", $header_arr ) . "\r\n";
117
                break;
118
        }
119
        require_once  "includes/versand/body_$site.inc.php";
120
 
121
        $sql = "
122
            SELECT DISTINCT
123
                Bestellung,
124
                artikel
125
            FROM
126
                artikel_to_Bestellung ab
127
            JOIN
128
                artikel AS a
129
            ON
130
                a.ID=ab.artikel
131
            WHERE
132
                ab.status='freigegeben'
133
            AND
134
                a.Father = -3
135
        ";
136
        $res_b = mysql_query( $sql );
137
        while ( $row_b = mysql_fetch_assoc( $res_b ) )
138
        {
139
            $b_id = $row_b["Bestellung"];
140
            $a_id = $row_b["artikel"];
141
            $sql = "
142
                SELECT
143
                    b.*,
144
                    l.E_Mail,
145
                    l.Vorname,
146
                    l.Name1,
147
                    l.Name2 as Firma,
148
                    l.Strasse,
149
                    l.Hausnummer,
150
                    l.PLZ,
151
                    l.Ort,
152
                    l.Land,
153
                    l.Telefon
154
                FROM
155
                    Bestellung b,
156
                    Logins l
157
                WHERE
158
                    l.ID=b.Login
159
                AND
160
                    b.id= $b_id
161
            ";
162
            $res = mysql_query( $sql );
163
            while ( $row = mysql_fetch_assoc( $res ) )
164
            {
165
                $b_id = $row["ID"];
166
                $login = $row["Login"];
167
                $f_row = array();
168
                switch ( $web_rechte['Warenwirtschaft']['dhl_export']['dhl'] )
169
                {
170
                    case "intraship":
171
                        $anrede = ( $row['liefer_Andrede'] ) ? $row['liefer_Andrede']:
172
                        $row['Anrede'];
173
                        $name = ( $row['liefer_Firma'] ) ? $row['liefer_Firma']:
174
                        $row['Firma'];
175
                        if ( !$name )
176
                        {
177
                            $name = ( $row['liefer_Name'] ) ? $row['liefer_Name'] :
178
                                $row['Name1'];
179
                        }
180
                        $kontakt = ( $row['liefer_Vorname'] ) ? $row['liefer_Vorname']:
181
                        $row['Vorname'];
182
                        $kontakt .= ( $row['liefer_Name'] || $row['Name1'] ) ?
183
                            " ":
184
                        "";
185
                        $kontakt .= ( $row['liefer_Name'] ) ? $row['liefer_Name']:
186
                        $row['Name1'];
187
                        $strasse = ( $row['liefer_Strasse'] ) ? $row['liefer_Strasse']:
188
                        $row['Strasse'];
189
                        $hausnummer = ( $row['liefer_Str_Nr'] ) ? $row['liefer_Str_Nr']:
190
                        $row['Hausnummer'];
191
                        $plz = ( $row['liefer_PLZ'] ) ? $row['liefer_PLZ']:
192
                        $row['PLZ'];
193
                        $ort = ( $row['liefer_Ort'] ) ? $row['liefer_Ort']:
194
                        $row['Ort'];
195
                        $iso = getISOCode( ( $row['liefer_Land'] ) ? $row['liefer_Land'] :
196
                            $row['Land'], 2 );
197
                        $telefon = $row["Telefon"];
198
                        $email = $row["E_Mail"];
199
                        $f_row[] = "";
200
                        $f_row[] = $login;
201
                        $f_row[] = "I";
202
                        $f_row[] = $anrede;
203
                        $f_row[] = $name;
204
                        $f_row[] = "";
205
                        $f_row[] = "";
206
                        $f_row[] = $kontakt;
207
                        $f_row[] = $strasse;
208
                        $f_row[] = $hausnummer;
209
                        $f_row[] = "";
210
                        $f_row[] = "";
211
                        $f_row[] = $plz;
212
                        $f_row[] = $ort;
213
                        $f_row[] = $iso;
214
                        $f_row[] = "";
215
                        $f_row[] = $telefon;
216
                        $f_row[] = "";
217
                        $f_row[] = $email;
218
                        $f_row[] = "";
219
                        $f_row[] = "";
220
                        $f_row[] = "";
221
                        $f_row[] = "";
222
                        $f_row[] = "";
223
                        $f_row[] = "";
224
                        $f_row[] = "";
225
                        $f_row[] = "";
226
                        $f_row[] = "";
227
                        $f_row[] = "";
228
                        $f_row[] = "";
229
                        $f_row[] = "";
230
                        $f_row[] = "";
231
                        $f_row[] = "";
232
                        $f_row[] = "";
233
                        $f_row[] = "";
234
                        $f_row[] = "";
235
                        $f_cont[] = implode( "|", $f_row );
236
                        break;
237
                    case "easylog":
238
                        break;
239
                    default:
240
                        $f_row[] = $umschlag_arr["name"];
241
                        $f_row[] = "";
242
                        $f_row[] = $umschlag_arr["str"];
243
                        $f_row[] = $umschlag_arr["nummer"];
244
                        $f_row[] = $umschlag_arr["plz"];
245
                        $f_row[] = $umschlag_arr["ort"];
246
                        $f_row[] = "DEU";
247
                        $name = ( $row['liefer_Vorname'] ) ? $row['liefer_Vorname']:
248
                        $row['Vorname'];
249
                        $name .= ( $row['liefer_Name'] || $row['Name1'] ) ?
250
                            " ":
251
                        "";
252
                        $name .= ( $row['liefer_Name'] ) ? $row['liefer_Name']:
253
                        $row['Name1'];
254
                        $f_row[] = $name;
255
                        $f_row[] = ( $row['liefer_Firma'] ) ? $row['liefer_Firma']:
256
                        $row['Firma'];
257
                        $f_row[] = ( $row['liefer_Strasse'] ) ? $row['liefer_Strasse']:
258
                        $row['Strasse'];
259
                        $f_row[] = ( $row['liefer_Str_Nr'] ) ? $row['liefer_Str_Nr']:
260
                        $row['Hausnummer'];
261
                        $f_row[] = ( $row['liefer_PLZ'] ) ? $row['liefer_PLZ']:
262
                        $row['PLZ'];
263
                        $f_row[] = ( $row['liefer_Ort'] ) ? $row['liefer_Ort']:
264
                        $row['Ort'];
265
                        $f_row[] = getISOCode( ( $row['liefer_Land'] ) ? $row['liefer_Land'] :
266
                            $row['Land'], 3 );
267
                        $f_row[] = "";
268
                        $f_row[] = "";
269
                        $f_cont[] = implode( "\t", $f_row );
270
                        break;
271
                }
272
                $sql_u = "
273
                    UPDATE
274
                        artikel_to_Bestellung
275
                    SET
276
                        status = 'versand'
277
                    WHERE
278
                        Bestellung = $b_id
279
                    AND
280
                        artikel = $a_id
281
                ";
282
                $res_u = mysql_query( $sql_u );
283
            }
284
        } //end while
285
        $cont = implode( "\r\n", $f_cont );
286
        if ( $cont )
287
        {
288
            //$f = fopen( "archiv/$site/$f_name", 'w' );
289
            if ( $header )
290
            {
291
                $cont = $header . "\r\n" . $cont;
292
            }
293
            /*fwrite( $f, $cont );
294
            fclose( $f );*/
295
            file_put_contents( "archiv/$site/$f_name", $cont );
296
        }
297
        if ( isset( $user_rechte['Warenwirtschaft']['export'] ) )
298
        {
299
            $file = "export.php";
300
        }
301
        else
302
        {
303
            $file = "dhl_export.php";
304
        }
305
        header( 'Location: ' . $file );
306
    }
307
 
308
?>