33 require_once(
"Services/Mail/classes/class.ilMail.php");
106 $this->user_id = $a_user_id;
108 $this->table_mail_obj_data =
'mail_obj_data';
109 $this->table_tree =
'mail_tree';
113 $this->mtree =
new ilTree($this->user_id);
114 $this->mtree->setTableNames($this->table_tree,$this->table_mail_obj_data);
120 if (is_object($this->lng))
122 $this->lng->loadLanguageModule(
"mail");
124 $this->actions = array(
125 "moveMails" => $this->lng->txt(
"mail_move_to"),
126 "markMailsRead" => $this->lng->txt(
"mail_mark_read"),
127 "markMailsUnread" => $this->lng->txt(
"mail_mark_unread"),
128 "deleteMails" => $this->lng->txt(
"delete"));
132 $this->default_folder = array(
133 "b_inbox" =>
"inbox",
134 "c_trash" =>
"trash",
135 "d_drafts" =>
"drafts",
137 "z_local" =>
"local");
148 $query =
"SELECT * FROM ".$this->table_mail_obj_data.
" ".
149 "WHERE user_id = ".$ilDB->quote($this->user_id).
" ".
150 "AND type = 'inbox'";
164 $query =
"SELECT * FROM ".$this->table_mail_obj_data .
" ".
165 "WHERE user_id = ".$ilDB->quote($this->user_id).
" ".
166 "AND type = 'drafts'";
180 $query =
"SELECT * FROM ".$this->table_mail_obj_data .
" ".
181 "WHERE user_id = ".$ilDB->quote($this->user_id).
" ".
182 "AND type = 'trash'";
196 $query =
"SELECT * FROM $this->table_mail_obj_data ".
197 "WHERE user_id = ".$ilDB->quote($this->user_id).
" ".
210 return $this->mtree->getRootID($this->user_id);
226 if ($folder_data[
"type"] ==
"user_folder" or $folder_data[
"type"] ==
"local")
228 #return array_merge($this->actions,array("add" => $this->lng->txt("mail_add_subfolder")));
254 $query =
"SELECT mail_id FROM mail WHERE folder_id = 0 AND user_id = ".$ilDB->quote($a_user_id).
" ".
255 "AND m_status = 'unread'";
261 return $row->mail_id;
264 $query =
"SELECT m.mail_id FROM mail AS m,mail_obj_data AS mo ".
265 "WHERE m.user_id = mo.user_id ".
266 "AND m.folder_id = mo.obj_id ".
267 "AND mo.type = 'inbox' ".
268 "AND m.user_id = ".$ilDB->quote($a_user_id).
" ".
269 "AND m.m_status = 'unread'";
272 return $row ? $row->mail_id : 0;
293 $query =
"SELECT count(*) as cnt FROM mail WHERE folder_id = 0 AND user_id = ".$ilDB->quote($a_user_id).
" ".
294 "AND m_status = 'unread'";
298 $query =
"SELECT count(*) as cnt FROM mail AS m,mail_obj_data AS mo ".
299 "WHERE m.user_id = mo.user_id ".
300 "AND m.folder_id = mo.obj_id ".
301 "AND mo.type = 'inbox' ".
302 "AND m.user_id = ".$ilDB->quote($a_user_id).
" ".
303 "AND m.m_status = 'unread'";
306 return $row->cnt + $row2->cnt;
320 $query =
"INSERT INTO $this->table_mail_obj_data ".
321 "SET user_id = ".$ilDB->quote($this->user_id).
", ".
324 $res = $this->ilias->db->query($query);
325 $this->mtree->addTree($this->user_id,$root_id);
327 foreach ($this->default_folder as $key => $folder)
332 $query =
"INSERT INTO $this->table_mail_obj_data ".
333 "SET user_id = ".$ilDB->quote($this->user_id).
", ".
334 "title = ".$ilDB->quote($key).
", ".
335 "type = ".$ilDB->quote($folder);
336 $res = $this->ilias->db->query($query);
337 $this->mtree->insertNode($last_id,$root_id);
356 $query =
"INSERT INTO $this->table_mail_obj_data ".
357 "SET user_id = ".$ilDB->quote($this->user_id).
", ".
358 "title = ".$ilDB->quote($a_folder_name).
",".
359 "type = 'user_folder'";
360 $res = $this->ilias->db->query($query);
364 $this->mtree->insertNode($new_id,$a_parent_id);
385 $query =
"UPDATE $this->table_mail_obj_data ".
386 "SET title = ".$ilDB->quote($a_new_folder_name).
" ".
387 "WHERE obj_id = ".$ilDB->quote($a_obj_id).
" ";
388 $res = $this->ilias->db->query($query);
403 $query =
"SELECT obj_id FROM $this->table_mail_obj_data ".
404 "WHERE user_id = ".$ilDB->quote($this->user_id).
" ".
405 "AND title = ".$ilDB->quote($a_folder_name).
" ";
408 return $row->obj_id ?
true :
false;
420 include_once(
"Services/Mail/classes/class.ilMail.php");
421 $umail =
new ilMail($this->user_id);
424 $subtree = $this->mtree->getSubtree($this->mtree->getNodeData($a_folder_id));
427 $this->mtree->deleteTree($this->mtree->getNodeData($a_folder_id));
430 foreach($subtree as $node)
433 $mails = $umail->getMailsOfFolder($node[
"obj_id"]);
435 foreach ($mails as $mail)
437 $mail_ids[] = $mail[
"mail_id"];
440 if (is_array($mail_ids))
442 $umail->deleteMails($mail_ids);
446 $query =
"DELETE FROM $this->table_mail_obj_data ".
447 "WHERE obj_id = ".$ilDB->quote($node[
"obj_id"]).
" ";
448 $res = $this->ilias->db->query($query);
459 return $ilDB->getLastInsertId();
471 $query =
"SELECT * FROM $this->table_mail_obj_data ".
472 "WHERE user_id = ".$ilDB->quote($this->user_id).
" ".
473 "AND obj_id = ".$ilDB->quote($a_obj_id).
" ";
478 "title" => stripslashes($row->title),
491 $query =
"SELECT * FROM $this->table_tree ".
492 "WHERE child = ".$ilDB->quote($a_obj_id).
" ";
512 foreach ($this->default_folder as $key => $value)
514 $query =
"SELECT obj_id,type FROM $this->table_mail_obj_data ".
515 "WHERE user_id = ".$ilDB->quote($this->user_id).
" ".
516 "AND title = ".$ilDB->quote($key).
" ";
519 $user_folder[] = array(
521 "type" => $row->type,
522 "obj_id" => $row->obj_id);
525 $query =
"SELECT * FROM $this->table_tree, $this->table_mail_obj_data ".
526 "WHERE $this->table_mail_obj_data.obj_id = $this->table_tree.child ".
527 "AND $this->table_tree.depth > '2' ".
528 "AND $this->table_tree.tree = ".$ilDB->quote($this->user_id).
" ".
529 "ORDER BY $this->table_mail_obj_data.title";
531 $res = $this->ilias->db->query($query);
535 $user_folder[] = array(
536 "title" => stripslashes($row->title),
537 "type" => $row->type,
538 "obj_id" => $row->child);
551 $this->user_id = $a_user_id;
566 $q =
"DELETE FROM mail_obj_data WHERE user_id=".$ilDB->quote($this->user_id).
" ";
567 $this->ilias->db->query($q);
569 $q =
"DELETE FROM mail_options WHERE user_id= ".$ilDB->quote($this->user_id).
" ";
570 $this->ilias->db->query($q);
572 $q =
"DELETE FROM mail_saved WHERE user_id= ".$ilDB->quote($this->user_id).
" ";
573 $this->ilias->db->query($q);
575 $q =
"DELETE FROM mail_tree WHERE tree=".$ilDB->quote($this->user_id).
" ";
576 $this->ilias->db->query($q);
594 $query =
"UPDATE mail SET sender_id = '0',import_name = ".$ilDB->quote($tmp_user->getLogin()).
" ".
595 "WHERE sender_id = ".$ilDB->quote($this->user_id).
" ";
597 $this->ilias->db->query($query);