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
00033 require_once("classes/class.ilFileData.php");
00034
00035 define('GROUP_PATH','group');
00036
00037 class ilFileDataGroup extends ilFileData
00038 {
00044 var $group_path;
00045
00046 var $group_obj = null;
00047
00055 function ilFileDataGroup($group_obj)
00056 {
00057 global $ilias;
00058
00059 parent::ilFileData();
00060
00061 $this->ilias =& $ilias;
00062 $this->group_path = parent::getPath()."/".GROUP_PATH;
00063 $this->group_obj =& $group_obj;
00064
00065
00066 if(!$this->__checkPath())
00067 {
00068 $this->__initDirectory();
00069 }
00070
00071 #$this->__checkImportPath();
00072 }
00073
00074
00075 function createImportFile($a_tmp_name,$a_name)
00076 {
00077 ilUtil::moveUploadedFile($a_tmp_name,
00078 $a_name,
00079 $this->getGroupPath().'/import/'.$a_name);
00080 $this->import_file_info = pathinfo($this->getGroupPath().'/import/'.$a_name);
00081
00082 }
00083
00084 function unpackImportFile()
00085 {
00086 return ilUtil::unzip($this->getGroupPath().'/import/'.$this->import_file_info['basename']);
00087 }
00088
00089 function validateImportFile()
00090 {
00091 if(!is_dir($this->getGroupPath().'/import/'.basename($this->import_file_info['basename'],'.zip')))
00092 {
00093 return false;
00094 }
00095 if(!file_exists($this->getGroupPath().'/import'.
00096 '/'.basename($this->import_file_info['basename'],'.zip').
00097 '/'.basename($this->import_file_info['basename'],'.zip').'.xml'))
00098 {
00099 return false;
00100 }
00101 return true;
00102 }
00103
00104 function getImportFile()
00105 {
00106 return $this->getGroupPath().'/import'
00107 .'/'.basename($this->import_file_info['basename'],'.zip')
00108 .'/'.basename($this->import_file_info['basename'],'.zip').'.xml';
00109 }
00110
00111
00112
00113
00114 function getExportFile($a_rel_name)
00115 {
00116 if(@file_exists($abs = $this->group_path.'/grp_'.$this->group_obj->getId().'/'.$a_rel_name))
00117 {
00118 return $abs;
00119 }
00120 return false;
00121 }
00122
00123 function getExportFiles()
00124 {
00125 $path = $this->getGroupPath().'/grp_'.$this->group_obj->getId();
00126
00127
00128 if(!@file_exists($path) or !is_readable($path))
00129 {
00130 return array();
00131 }
00132 $dp = dir($path);
00133
00134
00135 while($entry = $dp->read())
00136 {
00137 if ($entry != "." and
00138 $entry != ".." and
00139 substr($entry, -4) == ".zip" and
00140 ereg("^[0-9]{10}_{2}[0-9]+_{2}(grp_)*[0-9]+\.zip\$", $entry))
00141 {
00142 $files[$entry] = array("file" => $entry,
00143 "size" => filesize($path."/".$entry),
00144 'type' => "XML");
00145 }
00146 }
00147 return $files ? $files : array();
00148 }
00149
00150 function deleteFile($a_rel_name)
00151 {
00152 if(@file_exists($abs = $this->group_path.'/grp_'.$this->group_obj->getId().'/'.$a_rel_name))
00153 {
00154 @unlink($abs);
00155
00156 return true;
00157 }
00158 return false;
00159 }
00160
00161 function deleteDirectory($a_rel_dir)
00162 {
00163 if(!@file_exists($abs = $this->getGroupPath().'/grp_'.$this->group_obj->getId().'/'.$a_rel_dir))
00164 {
00165 return false;
00166 }
00167 ilUtil::delDir($abs);
00168
00169 return true;
00170 }
00171
00172
00173 function _deleteAll($a_obj_id)
00174 {
00175 ilUtil::delDir(CLIENT_DATA_DIR.'/'.GROUP_PATH.'/grp_'.$a_obj_id);
00176
00177 return true;
00178 }
00179
00180 function addGroupDirectory()
00181 {
00182 if(@file_exists($this->getGroupPath().'/grp_'.$this->group_obj->getId()))
00183 {
00184 return false;
00185 }
00186 ilUtil::makeDir($this->getGroupPath().'/grp_'.$this->group_obj->getId());
00187
00188 return true;
00189 }
00190
00191 function addImportDirectory()
00192 {
00193 if(@file_exists($this->getGroupPath().'/import'))
00194 {
00195 return false;
00196 }
00197 ilUtil::makeDir($this->getGroupPath().'/import');
00198
00199 return true;
00200 }
00201
00202
00203 function addDirectory($a_rel_name)
00204 {
00205 if(@file_exists($this->getGroupPath().'/grp_'.$this->group_obj->getId().'/'.$a_rel_name))
00206 {
00207 return false;
00208 }
00209 ilUtil::makeDir($this->getGroupPath().'/grp_'.$this->group_obj->getId().'/'.$a_rel_name);
00210
00211 return true;
00212 }
00213
00214 function writeToFile($a_data,$a_rel_name)
00215 {
00216 if(!$fp = @fopen($this->getGroupPath().'/grp_'.$this->group_obj->getId().'/'.$a_rel_name,'w+'))
00217 {
00218 die("Cannot open file: ".$this->getGroupPath().'/'.$a_rel_name);
00219 }
00220 @fwrite($fp,$a_data);
00221
00222 return true;
00223 }
00224
00225 function zipFile($a_rel_name,$a_zip_name)
00226 {
00227 ilUtil::zip($this->getGroupPath().'/grp_'.$this->group_obj->getId().'/'.$a_rel_name,
00228 $this->getGroupPath().'/grp_'.$this->group_obj->getId().'/'.$a_zip_name);
00229
00230 return true;
00231 }
00232
00233
00239 function getGroupPath()
00240 {
00241 return $this->group_path;
00242 }
00243
00244
00245
00246 function __checkPath()
00247 {
00248 if(!@file_exists($this->getGroupPath()))
00249 {
00250 return false;
00251 }
00252
00253 $this->__checkReadWrite();
00254
00255 return true;
00256 }
00257
00264 function __checkReadWrite()
00265 {
00266 if(is_writable($this->group_path) && is_readable($this->group_path))
00267 {
00268 return true;
00269 }
00270 else
00271 {
00272 $this->ilias->raiseError("Group directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
00273 }
00274 }
00281 function __initDirectory()
00282 {
00283 if(is_writable($this->getPath()))
00284 {
00285 ilUtil::makeDir($this->getPath().'/'.GROUP_PATH);
00286 $this->group_path = $this->getPath().'/'.GROUP_PATH;
00287
00288 return true;
00289 }
00290 return false;
00291 }
00292 }