Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00032 require_once("classes/class.ilFileData.php");
00033
00034 class ilFileDataCourse extends ilFileData
00035 {
00041 var $course_path;
00042
00043 private $course_id;
00044
00052 function ilFileDataCourse($a_course_id)
00053 {
00054 define('COURSE_PATH','course');
00055 parent::ilFileData();
00056 $this->course_path = parent::getPath()."/".COURSE_PATH;
00057 $this->course_id = $a_course_id;
00058
00059
00060 if(!$this->__checkPath())
00061 {
00062 $this->__initDirectory();
00063 }
00064
00065 $this->__checkImportPath();
00066 }
00067
00068 function getArchiveFile($a_rel_name)
00069 {
00070 if(@file_exists($this->course_path.'/'.$a_rel_name.'.zip'))
00071 {
00072 return $this->course_path.'/'.$a_rel_name.'.zip';
00073 }
00074 if(@file_exists($this->course_path.'/'.$a_rel_name.'.pdf'))
00075 {
00076 return $this->course_path.'/'.$a_rel_name.'.pdf';
00077 }
00078 return false;
00079 }
00080
00087 public function getMemberExportFiles()
00088 {
00089 $files = array();
00090 $dp = opendir($this->course_path);
00091
00092 while($file = readdir($dp))
00093 {
00094 if(is_dir($file))
00095 {
00096 continue;
00097 }
00098
00099 if(preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/",$file,$matches) and $matches[3] == $this->course_id)
00100 {
00101 $timest = $matches[1];
00102 $file_info['name'] = $matches[0];
00103 $file_info['timest'] = $matches[1];
00104 $file_info['type'] = $matches[2];
00105 $file_info['id'] = $matches[3];
00106 $file_info['size'] = filesize($this->course_path.'/'.$file);
00107
00108 $files[$timest] = $file_info;
00109 }
00110 }
00111 closedir($dp);
00112 return $files ? $files : array();
00113 }
00114
00115 public function deleteMemberExportFile($a_name)
00116 {
00117 $file_name = $this->course_path.'/'.$a_name;
00118 if(@file_exists($file_name))
00119 {
00120 @unlink($file_name);
00121 }
00122 }
00123
00124 public function getMemberExportFile($a_name)
00125 {
00126 $file_name = $this->course_path.'/'.$a_name;
00127 if(@file_exists($file_name))
00128 {
00129 return file_get_contents($file_name);
00130 }
00131 }
00132
00133
00134 function deleteArchive($a_rel_name)
00135 {
00136 $this->deleteZipFile($this->course_path.'/'.$a_rel_name.'.zip');
00137 $this->deleteDirectory($this->course_path.'/'.$a_rel_name);
00138 $this->deleteDirectory(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00139 $this->deletePdf($this->course_path.'/'.$a_rel_name.'.pdf');
00140
00141 return true;
00142 }
00143 function deleteZipFile($a_abs_name)
00144 {
00145 if(@file_exists($a_abs_name))
00146 {
00147 @unlink($a_abs_name);
00148
00149 return true;
00150 }
00151 return false;
00152 }
00153 function deleteDirectory($a_abs_name)
00154 {
00155 if(file_exists($a_abs_name))
00156 {
00157 ilUtil::delDir($a_abs_name);
00158
00159 return true;
00160 }
00161 return false;
00162 }
00163 function deletePdf($a_abs_name)
00164 {
00165 if(@file_exists($a_abs_name))
00166 {
00167 @unlink($a_abs_name);
00168
00169 return true;
00170 }
00171 return false;
00172 }
00173
00174 function copy($a_from,$a_to)
00175 {
00176 if(@file_exists($a_from))
00177 {
00178 @copy($a_from,$this->getCoursePath().'/'.$a_to);
00179
00180 return true;
00181 }
00182 return false;
00183 }
00184
00185 function rCopy($a_from,$a_to)
00186 {
00187 ilUtil::rCopy($a_from,$this->getCoursePath().'/'.$a_to);
00188
00189 return true;
00190 }
00191
00192
00193 function addDirectory($a_rel_name)
00194 {
00195 ilUtil::makeDir($this->getCoursePath().'/'.$a_rel_name);
00196
00197 return true;
00198 }
00199
00200 function writeToFile($a_data,$a_rel_name)
00201 {
00202 if(!$fp = @fopen($this->getCoursePath().'/'.$a_rel_name,'w+'))
00203 {
00204 die("Cannot open file: ".$this->getCoursePath().'/'.$a_rel_name);
00205 }
00206 @fwrite($fp,$a_data);
00207
00208 return true;
00209 }
00210
00211 function zipFile($a_rel_name,$a_zip_name)
00212 {
00213 ilUtil::zip($this->getCoursePath().'/'.$a_rel_name,$this->getCoursePath().'/'.$a_zip_name);
00214
00215
00216 return filesize($this->getCoursePath().'/'.$a_zip_name);
00217 }
00218
00219
00225 function getCoursePath()
00226 {
00227 return $this->course_path;
00228 }
00229
00230 function createOnlineVersion($a_rel_name)
00231 {
00232 ilUtil::makeDir(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00233 ilUtil::rCopy($this->getCoursePath().'/'.$a_rel_name,CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00234
00235 return true;
00236 }
00237
00238 function getOnlineLink($a_rel_name)
00239 {
00240 return ilUtil::getWebspaceDir('filesystem').'/courses/'.$a_rel_name.'/index.html';
00241 }
00242
00243
00244
00245 function createImportFile($a_tmp_name,$a_name)
00246 {
00247 ilUtil::makeDir($this->getCoursePath().'/import/crs_'.$this->course_id);
00248
00249 ilUtil::moveUploadedFile($a_tmp_name,
00250 $a_name,
00251 $this->getCoursePath().'/import/crs_'.$this->course_id.'/'.$a_name);
00252 $this->import_file_info = pathinfo($this->getCoursePath().'/import/crs_'.$this->course_id.'/'.$a_name);
00253
00254 }
00255
00256 function unpackImportFile()
00257 {
00258 return ilUtil::unzip($this->getCoursePath().'/import/crs_'.$this->course_id.'/'.$this->import_file_info['basename']);
00259 }
00260
00261 function validateImportFile()
00262 {
00263 if(!is_dir($this->getCoursePath().'/import/crs_'.$this->course_id).'/'.
00264 basename($this->import_file_info['basename'],'.zip'))
00265 {
00266 return false;
00267 }
00268 if(!file_exists($this->getCoursePath().'/import/crs_'.$this->course_id
00269 .'/'.basename($this->import_file_info['basename'],'.zip')
00270 .'/'.basename($this->import_file_info['basename'],'.zip').'.xml'))
00271 {
00272 return false;
00273 }
00274 }
00275
00276 function getImportFile()
00277 {
00278 return $this->getCoursePath().'/import/crs_'.$this->course_id
00279 .'/'.basename($this->import_file_info['basename'],'.zip')
00280 .'/'.basename($this->import_file_info['basename'],'.zip').'.xml';
00281 }
00282
00283
00284
00285
00286
00287 function __checkPath()
00288 {
00289 if(!@file_exists($this->getCoursePath()))
00290 {
00291 return false;
00292 }
00293 if(!@file_exists(CLIENT_WEB_DIR.'/courses'))
00294 {
00295 ilUtil::makeDir(CLIENT_WEB_DIR.'/courses');
00296 }
00297
00298
00299 $this->__checkReadWrite();
00300
00301 return true;
00302 }
00303
00304 function __checkImportPath()
00305 {
00306 if(!@file_exists($this->getCoursePath().'/import'))
00307 {
00308 ilUtil::makeDir($this->getCoursePath().'/import');
00309 }
00310
00311 if(!is_writable($this->getCoursePath().'/import') or !is_readable($this->getCoursePath().'/import'))
00312 {
00313 $this->ilias->raiseError("Course import path is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
00314 }
00315 }
00316
00323 function __checkReadWrite()
00324 {
00325 if(is_writable($this->course_path) && is_readable($this->course_path))
00326 {
00327 return true;
00328 }
00329 else
00330 {
00331 $this->ilias->raiseError("Course directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
00332 }
00333 }
00340 function __initDirectory()
00341 {
00342 if(is_writable($this->getPath()))
00343 {
00344 ilUtil::makeDir($this->getPath().'/'.COURSE_PATH);
00345 $this->course_path = $this->getPath().'/'.COURSE_PATH;
00346
00347 return true;
00348 }
00349 return false;
00350 }
00351 }