ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFileDataCourse.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
32 require_once("./Services/FileSystem/classes/class.ilFileData.php");
33 
35 {
42 
43  private $course_id;
44 
52  function ilFileDataCourse($a_course_id)
53  {
54  define('COURSE_PATH','course');
56  $this->course_path = parent::getPath()."/".COURSE_PATH;
57  $this->course_id = $a_course_id;
58 
59  // IF DIRECTORY ISN'T CREATED CREATE IT
60  if(!$this->__checkPath())
61  {
62  $this->__initDirectory();
63  }
64  // Check import dir
65  $this->__checkImportPath();
66  }
67 
68  function getArchiveFile($a_rel_name)
69  {
70  if(@file_exists($this->course_path.'/'.$a_rel_name.'.zip'))
71  {
72  return $this->course_path.'/'.$a_rel_name.'.zip';
73  }
74  if(@file_exists($this->course_path.'/'.$a_rel_name.'.pdf'))
75  {
76  return $this->course_path.'/'.$a_rel_name.'.pdf';
77  }
78  return false;
79  }
80 
87  public function getMemberExportFiles()
88  {
89  $files = array();
90  $dp = opendir($this->course_path);
91 
92  while($file = readdir($dp))
93  {
94  if(is_dir($file))
95  {
96  continue;
97  }
98 
99  if(preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/",$file,$matches) and $matches[3] == $this->course_id)
100  {
101  $timest = $matches[1];
102  $file_info['name'] = $matches[0];
103  $file_info['timest'] = $matches[1];
104  $file_info['type'] = $matches[2];
105  $file_info['id'] = $matches[3];
106  $file_info['size'] = filesize($this->course_path.'/'.$file);
107 
108  $files[$timest] = $file_info;
109  }
110  }
111  closedir($dp);
112  return $files ? $files : array();
113  }
114 
115  public function deleteMemberExportFile($a_name)
116  {
117  $file_name = $this->course_path.'/'.$a_name;
118  if(@file_exists($file_name))
119  {
120  @unlink($file_name);
121  }
122  }
123 
124  public function getMemberExportFile($a_name)
125  {
126  $file_name = $this->course_path.'/'.$a_name;
127  if(@file_exists($file_name))
128  {
129  return file_get_contents($file_name);
130  }
131  }
132 
133 
134  function deleteArchive($a_rel_name)
135  {
136  $this->deleteZipFile($this->course_path.'/'.$a_rel_name.'.zip');
137  $this->deleteDirectory($this->course_path.'/'.$a_rel_name);
138  $this->deleteDirectory(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
139  $this->deletePdf($this->course_path.'/'.$a_rel_name.'.pdf');
140 
141  return true;
142  }
143  function deleteZipFile($a_abs_name)
144  {
145  if(@file_exists($a_abs_name))
146  {
147  @unlink($a_abs_name);
148 
149  return true;
150  }
151  return false;
152  }
153  function deleteDirectory($a_abs_name)
154  {
155  if(file_exists($a_abs_name))
156  {
157  ilUtil::delDir($a_abs_name);
158 
159  return true;
160  }
161  return false;
162  }
163  function deletePdf($a_abs_name)
164  {
165  if(@file_exists($a_abs_name))
166  {
167  @unlink($a_abs_name);
168 
169  return true;
170  }
171  return false;
172  }
173 
174  function copy($a_from,$a_to)
175  {
176  if(@file_exists($a_from))
177  {
178  @copy($a_from,$this->getCoursePath().'/'.$a_to);
179 
180  return true;
181  }
182  return false;
183  }
184 
185  function rCopy($a_from,$a_to)
186  {
187  ilUtil::rCopy($a_from,$this->getCoursePath().'/'.$a_to);
188 
189  return true;
190  }
191 
192 
193  function addDirectory($a_rel_name)
194  {
195  ilUtil::makeDir($this->getCoursePath().'/'.$a_rel_name);
196 
197  return true;
198  }
199 
200  function writeToFile($a_data,$a_rel_name)
201  {
202  if(!$fp = @fopen($this->getCoursePath().'/'.$a_rel_name,'w+'))
203  {
204  die("Cannot open file: ".$this->getCoursePath().'/'.$a_rel_name);
205  }
206  @fwrite($fp,$a_data);
207 
208  return true;
209  }
210 
211  function zipFile($a_rel_name,$a_zip_name)
212  {
213  ilUtil::zip($this->getCoursePath().'/'.$a_rel_name,$this->getCoursePath().'/'.$a_zip_name);
214 
215  // RETURN filesize
216  return filesize($this->getCoursePath().'/'.$a_zip_name);
217  }
218 
219 
225  function getCoursePath()
226  {
227  return $this->course_path;
228  }
229 
230  function createOnlineVersion($a_rel_name)
231  {
232  ilUtil::makeDir(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
233  ilUtil::rCopy($this->getCoursePath().'/'.$a_rel_name,CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
234 
235  return true;
236  }
237 
238  function getOnlineLink($a_rel_name)
239  {
240  return ilUtil::getWebspaceDir('filesystem').'/courses/'.$a_rel_name.'/index.html';
241  }
242 
243 
244  // METHODS FOR XML IMPORT OF COURSE
245  function createImportFile($a_tmp_name,$a_name)
246  {
247  ilUtil::makeDir($this->getCoursePath().'/import/crs_'.$this->course_id);
248 
249  ilUtil::moveUploadedFile($a_tmp_name,
250  $a_name,
251  $this->getCoursePath().'/import/crs_'.$this->course_id.'/'.$a_name);
252  $this->import_file_info = pathinfo($this->getCoursePath().'/import/crs_'.$this->course_id.'/'.$a_name);
253 
254  }
255 
256  function unpackImportFile()
257  {
258  return ilUtil::unzip($this->getCoursePath().'/import/crs_'.$this->course_id.'/'.$this->import_file_info['basename']);
259  }
260 
262  {
263  if(!is_dir($this->getCoursePath().'/import/crs_'.$this->course_id).'/'.
264  basename($this->import_file_info['basename'],'.zip'))
265  {
266  return false;
267  }
268  if(!file_exists($this->getCoursePath().'/import/crs_'.$this->course_id
269  .'/'.basename($this->import_file_info['basename'],'.zip')
270  .'/'.basename($this->import_file_info['basename'],'.zip').'.xml'))
271  {
272  return false;
273  }
274  }
275 
276  function getImportFile()
277  {
278  return $this->getCoursePath().'/import/crs_'.$this->course_id
279  .'/'.basename($this->import_file_info['basename'],'.zip')
280  .'/'.basename($this->import_file_info['basename'],'.zip').'.xml';
281  }
282 
283 
284 
285 
286  // PRIVATE METHODS
287  function __checkPath()
288  {
289  if(!@file_exists($this->getCoursePath()))
290  {
291  return false;
292  }
293  if(!@file_exists(CLIENT_WEB_DIR.'/courses'))
294  {
295  ilUtil::makeDir(CLIENT_WEB_DIR.'/courses');
296  }
297 
298 
299  $this->__checkReadWrite();
300 
301  return true;
302  }
303 
304  function __checkImportPath()
305  {
306  if(!@file_exists($this->getCoursePath().'/import'))
307  {
308  ilUtil::makeDir($this->getCoursePath().'/import');
309  }
310 
311  if(!is_writable($this->getCoursePath().'/import') or !is_readable($this->getCoursePath().'/import'))
312  {
313  $this->ilias->raiseError("Course import path is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
314  }
315  }
316 
323  function __checkReadWrite()
324  {
325  if(is_writable($this->course_path) && is_readable($this->course_path))
326  {
327  return true;
328  }
329  else
330  {
331  $this->ilias->raiseError("Course directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
332  }
333  }
340  function __initDirectory()
341  {
342  if(is_writable($this->getPath()))
343  {
344  ilUtil::makeDir($this->getPath().'/'.COURSE_PATH);
345  $this->course_path = $this->getPath().'/'.COURSE_PATH;
346 
347  return true;
348  }
349  return false;
350  }
351 }