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.ilFileDataImport.php");
00034
00035 class ilFileDataImportMail extends ilFileDataImport
00036 {
00042 var $mail_path;
00043
00044 var $files;
00045 var $xml_file;
00046
00047
00055 function ilFileDataImportMail()
00056 {
00057 define('MAIL_IMPORT_PATH','mail');
00058 parent::ilFileDataImport();
00059 $this->mail_path = parent::getPath()."/".MAIL_IMPORT_PATH;
00060
00061
00062
00063 ilFileDataImportMail::_initDirectory();
00064 $this->__readFiles();
00065 }
00066
00067 function getFiles()
00068 {
00069 return $this->files ? $this->files : array();
00070 }
00071
00072 function getXMLFile()
00073 {
00074 return $this->xml_file;
00075 }
00076
00083 function storeUploadedFile($a_http_post_file)
00084 {
00085
00086
00087
00088
00089 if(isset($a_http_post_file) && $a_http_post_file['size'])
00090 {
00091
00092 $this->unlinkLast();
00093
00094
00095 ilUtil::moveUploadedFile($a_http_post_file['tmp_name'], $a_http_post_file['name'],
00096 $this->getPath().'/'.$a_http_post_file['name']);
00097
00098
00099
00100 $this->__readFiles();
00101 return true;
00102 }
00103 else
00104 {
00105 return false;
00106 }
00107 }
00108 function findXMLFile($a_dir = '')
00109 {
00110 $a_dir = $a_dir ? $a_dir : $this->getPath();
00111
00112 $this->__readFiles($a_dir);
00113
00114 foreach($this->getFiles() as $file_data)
00115 {
00116 if(is_dir($file_data["abs_path"]))
00117 {
00118 $this->findXMLFile($file_data["abs_path"]);
00119 }
00120 if(($tmp = explode(".",$file_data["name"])) !== false)
00121 {
00122 if($tmp[count($tmp) - 1] == "xml")
00123 {
00124 return $this->xml_file = $file_data["abs_path"];
00125 }
00126 }
00127 }
00128 return $this->xml_file;
00129 }
00130
00131 function unzip()
00132 {
00133 foreach($this->getFiles() as $file_data)
00134 {
00135 ilUtil::unzip($file_data["abs_path"]);
00136
00137 return true;
00138 }
00139 return false;
00140 }
00141
00147 function getPath()
00148 {
00149 return $this->mail_path;
00150 }
00151
00152 function unlinkLast()
00153 {
00154 foreach($this->getFiles() as $file_data)
00155 {
00156 if(is_dir($file_data["abs_path"]))
00157 {
00158 ilUtil::delDir($file_data["abs_path"]);
00159 }
00160 else
00161 {
00162 unlink($file_data["abs_path"]);
00163 }
00164 }
00165 return true;
00166 }
00167
00168 function __readFiles($a_dir = '')
00169 {
00170 $a_dir = $a_dir ? $a_dir : $this->getPath();
00171
00172 $this->files = array();
00173 $dp = opendir($a_dir);
00174
00175 while($file = readdir($dp))
00176 {
00177 if($file == "." or $file == "..")
00178 {
00179 continue;
00180 }
00181 $this->files[] = array(
00182 'name' => $file,
00183 'abs_path' => $a_dir."/".$file,
00184 'size' => filesize($a_dir."/".$file),
00185 'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($a_dir.'/'.$file))));
00186 }
00187 closedir($dp);
00188
00189 return true;
00190 }
00191
00198 function __checkReadWrite()
00199 {
00200 if(is_writable($this->mail_path) && is_readable($this->mail_path))
00201 {
00202 return true;
00203 }
00204 else
00205 {
00206 $this->ilias->raiseError("Mail import directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
00207 }
00208 }
00216 function _initDirectory()
00217 {
00218 if(!@file_exists($this->mail_path))
00219 {
00220 ilUtil::makeDir($this->mail_path);
00221 }
00222 return true;
00223 }
00224 }