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 $res = $ilDB->queryf(
'
149 SELECT * FROM '.$this->table_mail_obj_data.
'
152 array(
'integer',
'text'),
153 array($this->user_id,
'inbox'));
168 $res = $ilDB->queryf(
'
169 SELECT * FROM '.$this->table_mail_obj_data.
'
172 array(
'integer',
'text'),
173 array($this->user_id,
'drafts'));
189 $res = $ilDB->queryf(
'
190 SELECT * FROM '.$this->table_mail_obj_data.
'
193 array(
'integer',
'text'),
194 array($this->user_id,
'trash'));
209 $res = $ilDB->queryf(
'
210 SELECT * FROM '.$this->table_mail_obj_data.
'
213 array(
'integer',
'text'),
214 array($this->user_id,
'sent'));
228 return $this->mtree->getRootID($this->user_id);
244 if ($folder_data[
"type"] ==
"user_folder" or $folder_data[
"type"] ==
"local")
246 #return array_merge($this->actions,array("add" => $this->lng->txt("mail_add_subfolder")));
272 $res = $ilDB->queryf(
'
273 SELECT count(mail_id) cnt FROM mail
277 array(
'integer',
'integer',
'text'),
278 array(
'0', $a_user_id,
'unread'));
282 $res2 = $ilDB->queryf(
'
283 SELECT count(mail_id) cnt FROM mail m,mail_obj_data mo
284 WHERE m.user_id = mo.user_id
285 AND m.folder_id = mo.obj_id
288 AND m.m_status = %s',
289 array(
'text',
'integer',
'text'),
290 array(
'inbox', $a_user_id,
'unread'));
295 return $row->cnt + $row2->cnt;
309 $root_id = $ilDB->nextId($this->table_mail_obj_data);
311 $res = $ilDB->manipulateF(
'
312 INSERT INTO '. $this->table_mail_obj_data .
'
318 VALUES( %s, %s, %s, %s)',
319 array(
'integer',
'integer',
'text',
'text'),
320 array($root_id, $this->user_id,
'a_root',
'root'));
322 $this->mtree->addTree($this->user_id,$root_id);
324 foreach ($this->default_folder as $key => $folder)
329 $last_id = $ilDB->nextId($this->table_mail_obj_data);
330 $statement = $ilDB->manipulateF(
'
331 INSERT INTO '. $this->table_mail_obj_data .
'
337 VALUES( %s, %s, %s, %s)',
338 array(
'integer',
'integer',
'text',
'text'),
339 array($last_id,$this->user_id, $key, $folder));
341 $this->mtree->insertNode($last_id,$root_id);
360 $next_id = $ilDB->nextId($this->table_mail_obj_data);
361 $statement = $ilDB->manipulateF(
'
362 INSERT INTO '. $this->table_mail_obj_data .
'
368 VALUES(%s,%s,%s,%s)',
369 array(
'integer',
'integer',
'text',
'text'),
370 array($next_id, $this->user_id, $a_folder_name,
'user_folder'));
373 $this->mtree->insertNode($next_id,$a_parent_id);
393 $statement = $ilDB->manipulateF(
'
394 UPDATE '. $this->table_mail_obj_data .
'
397 array(
'text',
'integer'),
398 array($a_new_folder_name, $a_obj_id));
413 $res = $ilDB->queryf(
'
414 SELECT obj_id FROM '. $this->table_mail_obj_data .
'
417 array(
'integer',
'text'),
418 array($this->user_id, $a_folder_name));
422 return $row->obj_id ?
true :
false;
435 SELECT title FROM mail_obj_data
443 if( array_key_exists(
$row[
'title'], $this->default_folder) )
448 include_once(
"Services/Mail/classes/class.ilMail.php");
449 $umail =
new ilMail($this->user_id);
452 $subtree = $this->mtree->getSubtree($this->mtree->getNodeData($a_folder_id));
455 $this->mtree->deleteTree($this->mtree->getNodeData($a_folder_id));
458 foreach($subtree as $node)
461 $mails = $umail->getMailsOfFolder($node[
"obj_id"]);
463 foreach ($mails as $mail)
465 $mail_ids[] = $mail[
"mail_id"];
468 if (is_array($mail_ids))
470 $umail->deleteMails($mail_ids);
474 $statement = $ilDB->manipulateF(
'
475 DELETE FROM '. $this->table_mail_obj_data .
'
478 array($node[
'obj_id']));
489 return $ilDB->getLastInsertId();
501 $res = $ilDB->queryf(
'
502 SELECT * FROM '. $this->table_mail_obj_data .
'
505 array(
'integer',
'integer'),
506 array($this->user_id, $a_obj_id));
511 "title" => stripslashes(
$row->title),
512 "type" =>
$row->m_type
524 $res = $ilDB->queryf(
'
525 SELECT * FROM '. $this->table_tree .
'
551 foreach ($this->default_folder as $key => $value)
553 $res = $ilDB->queryf(
'
554 SELECT obj_id,m_type FROM '. $this->table_mail_obj_data .
'
557 array(
'integer',
'text'),
558 array($this->user_id, $key));
562 $user_folder[] = array(
564 "type" =>
$row->m_type,
565 "obj_id" =>
$row->obj_id);
568 $res = $ilDB->queryf(
'
569 SELECT * FROM '. $this->table_tree.
', '. $this->table_mail_obj_data .
'
570 WHERE '. $this->table_mail_obj_data.
'.obj_id = '. $this->table_tree.
'.child
571 AND '. $this->table_tree.
'.depth > %s
572 AND '. $this->table_tree.
'.tree = %s
573 ORDER BY '. $this->table_mail_obj_data.
'.title ',
574 array(
'integer',
'integer'),
575 array(
'2', $this->user_id));
579 $user_folder[] = array(
580 "title" => stripslashes(
$row->title),
581 "type" =>
$row->m_type,
582 "obj_id" =>
$row->child);
595 $this->user_id = $a_user_id;
610 $data = array($this->user_id);
612 $statement = $ilDB->manipulateF(
'
613 DELETE FROM mail_obj_data WHERE user_id = %s',
614 array(
'integer'), array($this->user_id)
617 $statement = $ilDB->manipulateF(
'
618 DELETE FROM mail_options WHERE user_id = %s',
619 array(
'integer'), array($this->user_id)
622 $statement = $ilDB->manipulateF(
'
623 DELETE FROM mail_saved WHERE user_id = %s',
624 array(
'integer'), array($this->user_id)
627 $statement = $ilDB->manipulateF(
'
628 DELETE FROM mail_tree WHERE tree = %s',
629 array(
'integer'), array($this->user_id)
648 $statement = $ilDB->manipulateF(
'
652 WHERE sender_id = %s',
653 array(
'integer',
'text',
'integer'),