1 <?php declare(strict_types=1);
46 $this->lng = $DIC->language();
47 $this->db = $DIC->database();
49 $this->usrId = (int) $a_user_id;
50 $this->table_mail_obj_data =
'mail_obj_data';
51 $this->table_tree =
'mail_tree';
54 $this->mtree =
new ilTree($this->usrId);
55 $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
61 if (is_object($this->lng)) {
62 $this->lng->loadLanguageModule(
"mail");
65 'moveMails' => $this->lng->txt(
'mail_move_to'),
66 'markMailsRead' => $this->lng->txt(
'mail_mark_read'),
67 'markMailsUnread' => $this->lng->txt(
'mail_mark_unread'),
68 'deleteMails' => $this->lng->txt(
'delete')
73 $this->defaultFolders = [
76 'd_drafts' =>
'drafts',
87 $res = $this->db->queryF(
88 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
90 [$this->usrId,
'inbox']
93 $row = $this->db->fetchAssoc(
$res);
95 return (
int) $row[
'obj_id'];
103 $res = $this->db->queryF(
104 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
106 [$this->usrId,
'drafts']
109 $row = $this->db->fetchAssoc(
$res);
111 return (
int) $row[
'obj_id'];
119 $res = $this->db->queryF(
120 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
122 [$this->usrId,
'trash']
125 $row = $this->db->fetchAssoc(
$res);
127 return (
int) $row[
'obj_id'];
135 $res = $this->db->queryF(
136 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
138 [$this->usrId,
'sent']
141 $row = $this->db->fetchAssoc(
$res);
143 return (
int) $row[
'obj_id'];
151 return (
int) $this->mtree->getRootId();
162 if ($folder_data[
'type'] ===
'user_folder' || $folder_data[
'type'] ===
'local') {
175 $rootFolderId = (int) $this->db->nextId($this->table_mail_obj_data);
176 $this->db->manipulateF(
177 'INSERT INTO ' . $this->table_mail_obj_data .
' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
178 [
'integer',
'integer',
'text',
'text'],
179 [$rootFolderId, $this->usrId,
'a_root',
'root']
181 $this->mtree->addTree($this->usrId, $rootFolderId);
183 foreach ($this->defaultFolders as $key => $folder) {
184 $last_id = $this->db->nextId($this->table_mail_obj_data);
185 $this->db->manipulateF(
186 'INSERT INTO ' . $this->table_mail_obj_data .
' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
187 [
'integer',
'integer',
'text',
'text'],
188 [$last_id, $this->usrId, $key, $folder]
190 $this->mtree->insertNode($last_id, $rootFolderId);
205 $nextId = (int) $this->db->nextId($this->table_mail_obj_data);
206 $this->db->manipulateF(
207 'INSERT INTO ' . $this->table_mail_obj_data .
' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
208 [
'integer',
'integer',
'text',
'text'],
209 [$nextId, $this->usrId, $name,
'user_folder']
211 $this->mtree->insertNode($nextId, $parentFolderId);
227 $this->db->manipulateF(
228 'UPDATE ' . $this->table_mail_obj_data .
' SET title = %s WHERE obj_id = %s AND user_id = %s',
229 [
'text',
'integer',
'integer'],
230 [$name, $folderId, $this->usrId]
242 $res = $this->db->queryF(
243 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND title = %s',
245 [$this->usrId, $name]
247 $row = $this->db->fetchAssoc(
$res);
249 return is_array($row) && $row[
'obj_id'] > 0 ? true :
false;
259 $query = $this->db->queryF(
260 'SELECT obj_id, title FROM ' . $this->table_mail_obj_data .
' WHERE obj_id = %s AND user_id = %s',
261 [
'integer',
'integer'],
262 [$folderId, $this->usrId]
264 $row = $this->db->fetchAssoc(
$query);
266 if (!is_array($row) || array_key_exists($row[
'title'], $this->defaultFolders)) {
270 $mailer =
new ilMail($this->usrId);
272 $subtree = $this->mtree->getSubtree($this->mtree->getNodeData($folderId));
273 $this->mtree->deleteTree($this->mtree->getNodeData($folderId));
275 foreach ($subtree as $node) {
276 $nodeId = (int) $node[
'obj_id'];
278 $mails = $mailer->getMailsOfFolder($nodeId);
281 foreach ($mails as $mail) {
282 $mailIds[] = $mail[
'mail_id'];
285 $mailer->deleteMails($mailIds);
287 $this->db->manipulateF(
288 'DELETE FROM ' . $this->table_mail_obj_data .
' WHERE obj_id = %s AND user_id = %s',
289 [
'integer',
'integer'],
290 [$nodeId, $this->usrId]
303 $res = $this->db->queryF(
304 'SELECT * FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND obj_id = %s',
305 [
'integer',
'integer'],
306 [$this->usrId, $folderId]
308 $row = $this->db->fetchAssoc(
$res);
311 'obj_id' => (int) $row[
'obj_id'],
312 'title' => (
string) $row[
'title'],
313 'type' => (string) $row[
'm_type'],
323 $res = $this->db->queryF(
324 'SELECT * FROM ' . $this->table_tree .
' WHERE child = %s AND tree = %s',
325 [
'integer',
'integer'],
326 [$folderId, $this->usrId]
328 $row = $this->db->fetchAssoc(
$res);
330 return is_array($row) ? (int) $row[
'parent'] : 0;
340 foreach ($this->defaultFolders as $key => $value) {
341 $res = $this->db->queryF(
342 'SELECT obj_id, m_type FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND title = %s',
346 $row = $this->db->fetchAssoc(
$res);
349 'title' => (string) $key,
350 'type' => (
string) $row[
'm_type'],
351 'obj_id' => (int) $row[
'obj_id'],
356 'SELECT * FROM ' . $this->table_tree .
', ' . $this->table_mail_obj_data,
357 'WHERE ' . $this->table_mail_obj_data .
'.obj_id = ' . $this->table_tree .
'.child',
358 'AND ' . $this->table_tree .
'.depth > %s',
359 'AND ' . $this->table_tree .
'.tree = %s',
360 'ORDER BY ' . $this->table_tree .
'.lft, ' . $this->table_mail_obj_data .
'.title' 362 $res = $this->db->queryF(
364 [
'integer',
'integer'],
367 while ($row = $this->db->fetchAssoc(
$res)) {
369 'title' => (string) $row[
'title'],
370 'type' => (
string) $row[
'm_type'],
371 'obj_id' => (int) $row[
'child'],
397 public function delete() :
void 399 $this->db->manipulateF(
400 'DELETE FROM mail_obj_data WHERE user_id = %s',
405 $this->db->manipulateF(
406 'DELETE FROM mail_options WHERE user_id = %s',
411 $this->db->manipulateF(
412 'DELETE FROM mail_saved WHERE user_id = %s',
417 $this->db->manipulateF(
418 'DELETE FROM mail_tree WHERE tree = %s',
425 $fdm->onUserDelete();
428 $this->db->manipulateF(
429 'DELETE FROM mail WHERE user_id = %s',
442 $this->db->manipulateF(
443 'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
444 [
'integer',
'text',
'integer'],
445 [0, $nameToShow, $this->usrId]
457 return (
int) $folderData[
'obj_id'] === $folderId;
addFolder(int $parentFolderId, string $name)
updateMailsOfDeletedUser(string $nameToShow)
Update existing mails.
foreach($_POST as $key=> $value) $res
Mail Box class Base class for creating and handling mail boxes.
createDefaultFolder()
Creates all default folders for a user.
getParentFolderId(int $folderId)
renameFolder(int $folderId, string $name)
__construct($a_user_id=0)
ilMailbox constructor.
folderNameExists(string $name)
isOwnedFolder(int $folderId)