ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
22
23 var $files;
25
26
34 public function __construct()
35 {
36 define('MAIL_IMPORT_PATH','mail');
37 parent::__construct();
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 function getFiles()
47 {
48 return $this->files ? $this->files : array();
49 }
50
51 function getXMLFile()
52 {
53 return $this->xml_file;
54 }
55
62 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 {
70 // DELETE OLD FILES
71 $this->unlinkLast();
72
73 // CHECK IF FILE WITH SAME NAME EXISTS
74 ilUtil::moveUploadedFile($a_http_post_file['tmp_name'], $a_http_post_file['name'],
75 $this->getPath().'/'.$a_http_post_file['name']);
76 //move_uploaded_file($a_http_post_file['tmp_name'],$this->getPath().'/'.$a_http_post_file['name']);
77
78 // UPDATE FILES LIST
79 $this->__readFiles();
80 return true;
81 }
82 else
83 {
84 return false;
85 }
86 }
87 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 {
95 if(is_dir($file_data["abs_path"]))
96 {
97 $this->findXMLFile($file_data["abs_path"]);
98 }
99 if(($tmp = explode(".",$file_data["name"])) !== false)
100 {
101 if($tmp[count($tmp) - 1] == "xml")
102 {
103 return $this->xml_file = $file_data["abs_path"];
104 }
105 }
106 }
107 return $this->xml_file;
108 }
109
110 function unzip()
111 {
112 foreach($this->getFiles() as $file_data)
113 {
114 ilUtil::unzip($file_data["abs_path"]);
115
116 return true;
117 }
118 return false;
119 }
120
126 function getPath()
127 {
128 return $this->mail_path;
129 }
130
131 function unlinkLast()
132 {
133 foreach($this->getFiles() as $file_data)
134 {
135 if(is_dir($file_data["abs_path"]))
136 {
137 ilUtil::delDir($file_data["abs_path"]);
138 }
139 else
140 {
141 unlink($file_data["abs_path"]);
142 }
143 }
144 return true;
145 }
146 // PRIVATE METHODS
147 function __readFiles($a_dir = '')
148 {
149 $a_dir = $a_dir ? $a_dir : $this->getPath();
150
151 $this->files = array();
152 $dp = opendir($a_dir);
153
154 while($file = readdir($dp))
155 {
156 if($file == "." or $file == "..")
157 {
158 continue;
159 }
160 $this->files[] = array(
161 'name' => $file,
162 'abs_path' => $a_dir."/".$file,
163 'size' => filesize($a_dir."/".$file),
164 'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($a_dir.'/'.$file))));
165 }
166 closedir($dp);
167
168 return true;
169 }
170
178 {
179 if(is_writable($this->mail_path) && is_readable($this->mail_path))
180 {
181 return true;
182 }
183 else
184 {
185 $this->ilias->raiseError("Mail import directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
186 }
187 }
195 function _initDirectory()
196 {
197 if(!@file_exists($this->mail_path))
198 {
199 ilUtil::makeDir($this->mail_path);
200 }
201 return true;
202 }
203}
print $file
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.
formatDate($a_date, $a_mode="datetime", $a_omit_seconds=false, $a_relative=TRUE)
format a date according to the user language shortcut for Format::fmtDateTime @access public
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 ...
redirection script todo: (a better solution should control the processing via a xml file)