ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilFileDataImportMail.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12require_once("./Services/FileSystem/classes/class.ilFileDataImport.php");
13
15{
21 public $mail_path;
22
23 public $files;
24 public $xml_file;
25
26
34 public function __construct()
35 {
36 define('MAIL_IMPORT_PATH', 'mail');
38 $this->mail_path = parent::getPath() . "/" . MAIL_IMPORT_PATH;
39
40 // IF DIRECTORY ISN'T CREATED CREATE IT
41 // CALL STTIC TO AVOID OVERWRITE PROBLEMS
43 $this->__readFiles();
44 }
45
46 public function getFiles()
47 {
48 return $this->files ? $this->files : array();
49 }
50
51 public function getXMLFile()
52 {
53 return $this->xml_file;
54 }
55
62 public function storeUploadedFile($a_http_post_file)
63 {
64 // TODO:
65 // CHECK UPLOAD LIMIT
66 //
67
68 if (isset($a_http_post_file) && $a_http_post_file['size']) {
69 // DELETE OLD FILES
70 $this->unlinkLast();
71
72 // CHECK IF FILE WITH SAME NAME EXISTS
74 $a_http_post_file['tmp_name'],
75 $a_http_post_file['name'],
76 $this->getPath() . '/' . $a_http_post_file['name']
77 );
78 //move_uploaded_file($a_http_post_file['tmp_name'],$this->getPath().'/'.$a_http_post_file['name']);
79
80 // UPDATE FILES LIST
81 $this->__readFiles();
82 return true;
83 } else {
84 return false;
85 }
86 }
87 public function findXMLFile($a_dir = '')
88 {
89 $a_dir = $a_dir ? $a_dir : $this->getPath();
90
91 $this->__readFiles($a_dir);
92
93 foreach ($this->getFiles() as $file_data) {
94 if (is_dir($file_data["abs_path"])) {
95 $this->findXMLFile($file_data["abs_path"]);
96 }
97 if (($tmp = explode(".", $file_data["name"])) !== false) {
98 if ($tmp[count($tmp) - 1] == "xml") {
99 return $this->xml_file = $file_data["abs_path"];
100 }
101 }
102 }
103 return $this->xml_file;
104 }
105
106 public function unzip()
107 {
108 foreach ($this->getFiles() as $file_data) {
109 ilUtil::unzip($file_data["abs_path"]);
110
111 return true;
112 }
113 return false;
114 }
115
121 public function getPath()
122 {
123 return $this->mail_path;
124 }
125
126 public function unlinkLast()
127 {
128 foreach ($this->getFiles() as $file_data) {
129 if (is_dir($file_data["abs_path"])) {
130 ilUtil::delDir($file_data["abs_path"]);
131 } else {
132 unlink($file_data["abs_path"]);
133 }
134 }
135 return true;
136 }
137 // PRIVATE METHODS
138 public function __readFiles($a_dir = '')
139 {
140 $a_dir = $a_dir ? $a_dir : $this->getPath();
141
142 $this->files = array();
143 $dp = opendir($a_dir);
144
145 while ($file = readdir($dp)) {
146 if ($file == "." or $file == "..") {
147 continue;
148 }
149 $this->files[] = array(
150 'name' => $file,
151 'abs_path' => $a_dir . "/" . $file,
152 'size' => filesize($a_dir . "/" . $file),
153 'ctime' => filectime($a_dir . '/' . $file)
154 );
155 }
156 closedir($dp);
157
158 return true;
159 }
160
167 public function __checkReadWrite()
168 {
169 if (is_writable($this->mail_path) && is_readable($this->mail_path)) {
170 return true;
171 } else {
172 $this->ilias->raiseError("Mail import directory is not readable/writable by webserver", $this->ilias->error_obj->FATAL);
173 }
174 }
182 public function _initDirectory()
183 {
184 if (!@file_exists($this->mail_path)) {
185 ilUtil::makeDir($this->mail_path);
186 }
187 return true;
188 }
189}
An exception for terminatinating execution or to throw for unit testing.
This class handles all operations on files for the exercise object.
storeUploadedFile($a_http_post_file)
store uploaded file in filesystem
getPath()
get exercise path @access public
__construct()
Constructor call base constructors checks if directory is writable and sets the optional obj_id.
__checkReadWrite()
check if directory is writable overwritten method from base class @access private
_initDirectory()
init directory overwritten method @access public
This class handles all operations on files for the exercise object.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)