ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
12 require_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');
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  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
73  ilUtil::moveUploadedFile(
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 }
This class handles all operations on files for the exercise object.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
__construct()
Constructor call base constructors checks if directory is writable and sets the optional obj_id...
_initDirectory()
init directory overwritten method public
getPath()
get exercise path public
__checkReadWrite()
check if directory is writable overwritten method from base class private
redirection script todo: (a better solution should control the processing via a xml file) ...
Create styles array
The data for the language used.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
storeUploadedFile($a_http_post_file)
store uploaded file in filesystem
This class handles all operations on files for the exercise object.
Done writing files
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively