aboutsummaryrefslogtreecommitdiff
path: root/lib/calendar/CalendarImportFile.class.php
blob: 3e2ba15c15a835e219fa27017ed9754d3c4cc8b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?
# Lifter002: TODO
# Lifter007: TODO

/**
 * CalendarImportFile.class.php
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Peter Thienel <thienel@data-quest.de>, Suchi & Berg GmbH <info@data-quest.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @package     calendar
 */

class CalendarImportFile extends CalendarImport
{

    private $file;
    private $path;

    /**
     *
     */
    public function __construct(&$parser, $file, $path = '')
    {
        parent::__construct($parser);
        $this->file = $file;
        $this->path = $path;
    }

    /**
     *
     */
    public function getContent()
    {
        $data = '';
        if (!$file = @fopen($this->file['tmp_name'], 'rb')) {
            throw new CalendarExportException(_("Die Import-Datei konnte nicht geöffnet werden!"));
            return false;
        }
        if ($file) {
            while (!feof($file)) {
                $data .= fread($file, 1024);
            }
            fclose($file);
        }
        return $data;
    }

    /**
     *
     */
    public function getFileName()
    {
        return $this->file['name'];
    }

    /**
     *
     */
    public function getFileType()
    {
        return $this->_parser->getType();
    }

    /**
     *
     */
    public function getFileSize()
    {
        if (file_exists($this->file['tmp_name'])) {
            return filesize($this->file['tmp_name']);
        }
        return false;
    }

    /**
     *
     */
    public function checkFile()
    {
        return true;
    }

    /**
     *
     */
    public function importIntoDatabase($range_id, $ignore = CalendarImport::IGNORE_ERRORS)
    {
        if ($this->checkFile()) {
            parent::importIntoDatabase($range_id, $ignore);
            return true;
        }
        throw new CalendarExportException(_('Die Datei konnte nicht gelesen werden!'));
        return false;
    }

    /**
     *
     */
    public function importIntoObjects($ignore = CalendarImport::IGNORE_ERRORS)
    {
        global $_calendar_error;

        if ($this->checkFile()) {
            parent::importIntoObjects($ignore);
            return true;
        }
        throw new CalendarExportException(_('Die Datei konnte nicht gelesen werden!'));
    }

    /**
     *
     */
    public function deleteFile()
    {
        if (!unlink($this->file['tmp_name'])) {
            throw new CalendarExportException(_("Die Datei konnte nicht gelöscht werden!"));
            return false;
        }
        return true;
    }

    /**
     *
     */
    public function _getFileExtension()
    {
        $i = mb_strrpos($this->file['name'], '.');
        if (!$i) {
            return '';
        }
        $l = mb_strlen($this->file['name']) - $i;
        $ext = mb_substr($this->file['name'], $i + 1, $l);
        return $ext;
    }
}