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 require_once("classes/class.ilSaxParser.php");
00025 require_once("./classes/class.ilMailbox.php");
00026
00036 class ilMailImportParser extends ilSaxParser
00037 {
00038 var $mode;
00039 var $counter;
00040
00041
00049 function ilMailImportParser($a_xml_file,$a_mode)
00050 {
00051 define('EXPORT_VERSION',4);
00052
00053 parent::ilSaxParser($a_xml_file);
00054 $this->mode = $a_mode;
00055 $this->counter = -1;
00056 }
00057
00058 function getMode()
00059 {
00060 return $this->mode;
00061 }
00062
00063 function getCountImported()
00064 {
00065 return count($this->mails);
00066 }
00067
00068 function getNotAssignableUsers()
00069 {
00070 if(count($this->not_imported))
00071 {
00072 return implode("<br/>",$this->not_imported);
00073 }
00074 return "";
00075 }
00076
00082 function setHandlers($a_xml_parser)
00083 {
00084 xml_set_object($a_xml_parser,$this);
00085 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00086 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00087 }
00088
00092 function startParsing()
00093 {
00094 parent::startParsing();
00095
00096 switch($this->getMode())
00097 {
00098 case "check":
00099 if(count($this->not_imported))
00100 {
00101 return false;
00102 }
00103 break;
00104
00105 case "import":
00106 $this->__insert();
00107 break;
00108 }
00109 return true;
00110 }
00111
00112
00116 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
00117 {
00118 global $ilErr;
00119
00120 switch($a_name)
00121 {
00122 case "users":
00123 if($a_attribs["exportVersion"] < EXPORT_VERSION)
00124 {
00125 $ilErr->raiseError("!!! This export Version isn't supported, update your ILIAS 2 installation"
00126 ,$ilErr->WARNING);
00127 }
00128 break;
00129
00130 case "user":
00131 if(!($this->i3_id = ilObjUser::_getImportedUserId($a_attribs["id"])))
00132 {
00133 $this->not_imported[] = $a_attribs["id"];
00134 }
00135 break;
00136
00137 case "mail":
00138 if($this->i3_id)
00139 {
00140 $this->mails[++$this->counter]["usr_id"] = $this->i3_id;
00141 $this->mails[$this->counter]["m_email"] = $a_attribs["asEmail"];
00142
00143
00144 if($a_attribs["systemMessage"])
00145 {
00146 $this->mails[$this->counter]["folder_id"] = 0;
00147 }
00148 }
00149 break;
00150
00151 case "sender":
00152 if($this->i3_id)
00153 {
00154 $sender = ilObjUser::_getImportedUserId($a_attribs["id"]);
00155 $this->mails[$this->counter]["sender_id"] = $sender;
00156 $this->mails[$this->counter]["import_name"] = $a_attribs["import_name"];
00157 }
00158 break;
00159
00160
00161 default:
00162
00163 break;
00164 }
00165 }
00166
00167
00171 function handlerEndTag($a_xml_parser, $a_name)
00172 {
00173
00174 if(!$this->i3_id)
00175 {
00176 $this->cdata = '';
00177 return;
00178 }
00179 switch($a_name)
00180 {
00181 case "targetFolder":
00182 if(!isset($this->mails[$this->counter]["folder_id"]))
00183 {
00184 $tmp_mailbox =& new ilMailbox($this->i3_id);
00185 switch($this->cdata)
00186 {
00187 case "inbox":
00188 $this->mails[$this->counter]["folder_id"] = $tmp_mailbox->getInboxFolder();
00189 $this->mails[$this->counter]["read"] = "unread";
00190 break;
00191 case "sentbox":
00192 $this->mails[$this->counter]["folder_id"] = $tmp_mailbox->getSentFolder();
00193 $this->mails[$this->counter]["read"] = "read";
00194 break;
00195 case "draft":
00196 $this->mails[$this->counter]["folder_id"] = $tmp_mailbox->getDraftsFolder();
00197 $this->mails[$this->counter]["read"] = "read";
00198 break;
00199 case "trash":
00200 $this->mails[$this->counter]["folder_id"] = $tmp_mailbox->getTrashFolder();
00201 $this->mails[$this->counter]["read"] = "read";
00202 break;
00203 }
00204 }
00205 break;
00206
00207 case "sendTime":
00208 $this->mails[$this->counter]["send_time"] = date("Y-m-d H:i:s",$this->cdata);
00209 $this->mails[$this->counter]["timest"] = date("YmdHis",$this->cdata);
00210 break;
00211
00212 case "to":
00213 $this->mails[$this->counter]["rcp_to"] = $this->cdata;
00214 break;
00215
00216 case "cc":
00217 $this->mails[$this->counter]["rcp_cc"] = $this->cdata;
00218 break;
00219
00220 case "bcc":
00221 $this->mails[$this->counter]["rcp_bcc"] = $this->cdata;
00222 break;
00223
00224 case "url":
00225 if($this->cdata)
00226 {
00227 $this->mails[$this->counter]["m_message"] = "Url: ".$this->cdata." <br>";
00228 }
00229 break;
00230
00231 case "urlDescription":
00232 if($this->cdata)
00233 {
00234 $this->mails[$this->counter]["m_message"] .= $this->cdata."<br>";
00235 }
00236 break;
00237
00238 case "subject":
00239 $this->mails[$this->counter]["m_subject"] = $this->cdata;
00240 break;
00241
00242 case "message":
00243 $this->mails[$this->counter]["m_message"] .= $this->cdata;
00244 break;
00245 }
00246 $this->cdata = '';
00247 }
00248
00249
00253 function handlerCharacterData($a_xml_parser, $a_data)
00254 {
00255
00256
00257
00258
00259 $a_data = str_replace("<","<",$a_data);
00260 $a_data = str_replace(">",">",$a_data);
00261
00262 if(!empty($a_data))
00263 {
00264 $this->cdata .= $a_data;
00265 }
00266 }
00267
00268 function __insert()
00269 {
00270 global $ilDB;
00271
00272 $sth = $ilDB->prepare("INSERT INTO mail VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
00273
00274 $ilDB->executeMultiple($sth,$this->__buildSQLArray());
00275
00276 return true;
00277 }
00278 function __buildSQLArray()
00279 {
00280 $sql = array();
00281
00282 if(!count($this->mails))
00283 {
00284 return array();
00285 }
00286
00287 foreach($this->mails as $mail)
00288 {
00289 $sql[] = (array('0',
00290 $mail["usr_id"],
00291 $mail["folder_id"],
00292 $mail["sender_id"],
00293 addslashes(serialize(array())),
00294 $mail["send_time"],
00295 addslashes($mail["rcp_to"]),
00296 addslashes($mail["rcp_cc"]),
00297 addslashes($mail["rcp_bcc"]),
00298 $mail["read"],
00299 addslashes(serialize(array("normal"))),
00300 $mail["m_email"],
00301 addslashes($mail["m_subject"]),
00302 addslashes($mail["m_message"]),
00303 addslashes($mail["import_name"])));
00304
00305 }
00306 return $sql ? $sql :array();
00307 }
00308 }
00309 ?>