Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
3 lars 1
<?php
2
 
3
    /**
4
     * @package   php_share
5
     * @author    Lars Tiefland <tiefland@weban.de>
6
     * @copyright 2010 Webagentur Niewerth
7
     * @license   propietary http://www.weban.de
8
     * @version   $Rev: 753 $
9
     * @filesource
10
     *
11
     */
12
 
13
    /**
14
     *
15
     * @package   php_share
16
     * @author    Lars Tiefland <tiefland@weban.de>
17
     * @copyright 2010 Webagentur Niewerth
18
     */
19
 
20
    // SVN: $Id: frankana.class.php 753 2011-10-12 07:36:40Z tiefland $
21
 
22
    require_once "lieferantenbase.class.php";
23
    require_once "File.php";
24
    require_once "module/shop/html_mails/mail_func.php";
25
    require_once "Net/FTP.php";
26
 
27
    require_once "File/CSV.php";
28
 
29
    class Frankana extends LieferantenBase
30
    {
31
        public function import( $file )
32
        {
33
            $sql_lager = "SELECT
34
                    id
35
                FROM
36
                    lieferanten_lager
37
                WHERE
38
                    lieferanten_id=$this->lieferant_id
39
            ";
40
            $res_lager = $GLOBALS["db"]->query( $sql_lager );
41
            while ( $row = $res_lager->fetchRow() )
42
            {
43
                $lager_ids[] = $row["id"];
44
            }
45
            $lager_id_str = implode( ", ", $lager_ids );
46
            if ( !isset( $file["port"] ) )
47
            {
48
                $file["port"] = 21;
49
            }
50
            $ftp = new Net_FTP( $file["server"], $file["port"] );
51
            $ftp->connect();
52
            $res = $ftp->login( $file["user"], $file["password"] );
53
            $ftp->get( $file["name"], $file["name"], true, FTP_ASCII );
54
 
55
            $csv = new File_CSV();
56
 
57
            $fmt = $csv->discoverFormat( $file["name"], array( "@" ) );
58
 
59
            while ( $row = $csv->read( $file["name"], $fmt ) )
60
            {
61
                $content[] = $row;
62
            }
63
            foreach ( $this->databases as $database )
64
            {
65
                $sql = "DELETE FROM
66
                        " . $database . ".artikel_lagerbestand
67
                    WHERE
68
                        lager_id IN ($lager_id_str)
69
                ";
70
                $res = $GLOBALS["db"]->exec( $sql );
71
                $sql_a_s = "SELECT
72
                        id
73
                    FROM
74
                        " . $database . ".artikel
75
                    WHERE
76
                        kennung=:kennung
77
                    AND
78
                        language='DE'
79
                ";
80
 
81
                $sql_alb_i = "
82
                    INSERT INTO
83
                        " . $database . ".artikel_lagerbestand
84
                    (
85
                        lager_id,
86
                        artikel_id,
87
                        `status`,
88
                        ek_preis,
89
                        vk_preis
90
                    )
91
                    VALUES
92
                    (
93
                        :lager,
94
                        :id,
95
                        :lb_status,
96
                        :ek_preis,
97
                        :vk_preis
98
                    )
99
                ";
100
                $GLOBALS["sql_sth_a_s"] = $GLOBALS["db"]->prepare( $sql_a_s );
101
                $GLOBALS["sql_sth_alb_i"] = $GLOBALS["db"]->prepare( $sql_alb_i );
102
 
103
                foreach ( $content as $row )
104
                {
105
                    $res = $GLOBALS["sql_sth_a_s"]->execute( array( "kennung" =>
106
                        $row[0] ) );
107
                    $artikel = $res->fetchRow();
108
                    if ( $artikel["id"] )
109
                    {
110
                        $daten_bestand["id"] = $artikel["id"];
111
                        foreach ( $lager_ids as $lager )
112
                        {
113
                            switch ( $row[$lager + 6] )
114
                            {
115
                                case 0:
116
                                    $lb_status = 4;
117
                                    break;
118
                                case 1:
119
                                    $lb_status = 3;
120
                                    break;
121
                                case 2:
122
                                    $lb_status = 2;
123
                                    break;
124
                                case 3:
125
                                    $lb_status = 1;
126
                                    break;
127
                                case 4:
128
                                    $lb_status = 0;
129
                                    break;
130
                            }
131
                            $daten_bestand["ek_preis"] = str_replace( ",", ".",
132
                                $row[5] );
133
                            $daten_bestand["vk_preis"] = str_replace( ",", ".",
134
                                $row[6] );
135
                            $daten_bestand["lb_status"] = $lb_status;
136
                            $daten_bestand["lager"] = $lager;
137
                            $res_alb_i = $GLOBALS["sql_sth_alb_i"]->execute( $daten_bestand );
138
                        }
139
                    }
140
                }
141
            }
142
        }
143
    }
144
?>