1 | <?php |
---|
2 | include("../inc/inc.Settings.php"); |
---|
3 | include("../inc/inc.AccessUtils.php"); |
---|
4 | include("../inc/inc.ClassAccess.php"); |
---|
5 | include("../inc/inc.ClassDocument.php"); |
---|
6 | include("../inc/inc.ClassFolder.php"); |
---|
7 | include("../inc/inc.ClassGroup.php"); |
---|
8 | include("../inc/inc.ClassUser.php"); |
---|
9 | include("../inc/inc.DBAccess.php"); |
---|
10 | include("../inc/inc.FileUtils.php"); |
---|
11 | include("../inc/inc.Language.php"); |
---|
12 | include("../inc/inc.OutUtils.php"); |
---|
13 | include("../inc/inc.Utils.php"); |
---|
14 | |
---|
15 | function addExpiredMsg($document, $users) |
---|
16 | { |
---|
17 | GLOBAL $msgs; |
---|
18 | |
---|
19 | $folder = $document->getFolder(); |
---|
20 | $path = $folder->getPath(); |
---|
21 | $pathStr = ""; |
---|
22 | for ($i = 0; $i < count($path); $i++) |
---|
23 | { |
---|
24 | $pathStr .= $path[$i]->getName(); |
---|
25 | if ($i+1 < count($path)) |
---|
26 | $pathStr .= "/"; |
---|
27 | } |
---|
28 | foreach ($users as $user) |
---|
29 | { |
---|
30 | if (!isset($msgs[$user->getEmail()])) |
---|
31 | $msgs[$user->getEmail()] = array(); |
---|
32 | array_push( |
---|
33 | $msgs[$user->getEmail()], |
---|
34 | getMLText("msg_document_expired", |
---|
35 | array( |
---|
36 | "documentname" => $document->getName(), |
---|
37 | "path" => $pathStr, |
---|
38 | "documentid" => $document->getID(), |
---|
39 | "expires" => getReadableDate($document->getExpires()) |
---|
40 | ) |
---|
41 | ) |
---|
42 | ); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | function addChangedMsg($document, $users) |
---|
47 | { |
---|
48 | GLOBAL $msgs; |
---|
49 | |
---|
50 | $latestContent = $document->getLatestContent(); |
---|
51 | |
---|
52 | $folder = $document->getFolder(); |
---|
53 | $path = $folder->getPath(); |
---|
54 | $pathStr = ""; |
---|
55 | for ($i = 0; $i < count($path); $i++) |
---|
56 | { |
---|
57 | $pathStr .= $path[$i]->getName(); |
---|
58 | if ($i+1 < count($path)) |
---|
59 | $pathStr .= "/"; |
---|
60 | } |
---|
61 | |
---|
62 | foreach ($users as $user) |
---|
63 | { |
---|
64 | if (!isset($msgs[$user->getEmail()])) |
---|
65 | $msgs[$user->getEmail()] = array(); |
---|
66 | |
---|
67 | array_push( |
---|
68 | $msgs[$user->getEmail()], |
---|
69 | getMLText("msg_document_updated", |
---|
70 | array( |
---|
71 | "documentname" => $document->getName(), |
---|
72 | "path" => $pathStr, |
---|
73 | "documentid" => $document->getID(), |
---|
74 | "updated" => getLongReadableDate($latestContent->getDate()) |
---|
75 | ) |
---|
76 | ) |
---|
77 | ); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | function getUserOnlyNotifyList($obj, $oldList, $mode) |
---|
82 | { |
---|
83 | $newList = $oldList; |
---|
84 | $listToAdd = $obj->getNotifyList(); |
---|
85 | |
---|
86 | $tmpList = $listToAdd["users"]; |
---|
87 | foreach ($listToAdd["groups"] as $group) |
---|
88 | { |
---|
89 | $members = $group->getUsers(); |
---|
90 | foreach ($members as $member) |
---|
91 | array_push($tmpList, $member); |
---|
92 | } |
---|
93 | unset($listToAdd); |
---|
94 | foreach ($tmpList as $user) |
---|
95 | { |
---|
96 | $alreadyInList = false; |
---|
97 | foreach ($newList as $_user) |
---|
98 | { |
---|
99 | if ($_user->getID() == $user->getID()) |
---|
100 | { |
---|
101 | $alreadyInList = true; |
---|
102 | break; |
---|
103 | } |
---|
104 | } |
---|
105 | if (!$alreadyInList) |
---|
106 | array_push($newList, $user); |
---|
107 | } |
---|
108 | return filterUsersByAccess($obj, $newList, $mode); |
---|
109 | } |
---|
110 | |
---|
111 | function notifyForDocument($document, $users) |
---|
112 | { |
---|
113 | GLOBAl $settings; |
---|
114 | |
---|
115 | $newUsers = getUserOnlyNotifyList($document, $users, M_READ); |
---|
116 | |
---|
117 | //wenn das letzte update keine 24h (eher updateNotifyTime sek.) zurückliegt, werden |
---|
118 | //alle Benutzer, die in der alten Liste sowie in der Liste für diese Datei enthalten sind, |
---|
119 | //und mindestens Lese-Zugriff haben, benachrichtigt |
---|
120 | $latestContent = $document->getLatestContent(); |
---|
121 | if (mktime() - $latestContent->getDate() < $settings->_updateNotifyTime) |
---|
122 | addChangedMsg($document, $newUsers); |
---|
123 | |
---|
124 | //über veraltete Inhalte werden nur solche Benutzer informiert, die auch noch über Schreib-Rechte verfügen |
---|
125 | if ($document->expires() && (mktime() > $document->getExpires())) |
---|
126 | addExpiredMsg($document, filterUsersByAccess($document, $newUsers, M_READWRITE)); |
---|
127 | } |
---|
128 | |
---|
129 | function notifyForFolder($folder, $users) |
---|
130 | { |
---|
131 | $newUsers = getUserOnlyNotifyList($folder, $users, M_READ); |
---|
132 | |
---|
133 | $documents = $folder->getDocuments(); |
---|
134 | foreach ($documents as $document) |
---|
135 | notifyForDocument($document, $newUsers); |
---|
136 | |
---|
137 | $subFolders = $folder->getSubFolders(); |
---|
138 | foreach ($subFolders as $subFolder) |
---|
139 | notifyForFolder($subFolder, $newUsers); |
---|
140 | } |
---|
141 | |
---|
142 | $rootFolder = getFolder($settings->_rootFolderID); |
---|
143 | $msgs = array(); |
---|
144 | notifyForFolder($rootFolder, array()); |
---|
145 | |
---|
146 | print "<pre>"; |
---|
147 | print_r($msgs); |
---|
148 | print "</pre>"; |
---|
149 | |
---|
150 | $receivers = array_keys($msgs); |
---|
151 | foreach ($receivers as $receiver) |
---|
152 | { |
---|
153 | $msg = implode("\n\n", $msgs[$receiver]); |
---|
154 | mail($receiver, getMLText("notify_subject"), $msg); |
---|
155 | } |
---|
156 | ?> |
---|