source: contrib/Dms/op/op.NotifyMailer.php @ 3526

Revision 3526, 3.8 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado modulos Timesheet e DMS para a comunidade.

  • Property svn:executable set to *
Line 
1<?php
2include("../inc/inc.Settings.php");
3include("../inc/inc.AccessUtils.php");
4include("../inc/inc.ClassAccess.php");
5include("../inc/inc.ClassDocument.php");
6include("../inc/inc.ClassFolder.php");
7include("../inc/inc.ClassGroup.php");
8include("../inc/inc.ClassUser.php");
9include("../inc/inc.DBAccess.php");
10include("../inc/inc.FileUtils.php");
11include("../inc/inc.Language.php");
12include("../inc/inc.OutUtils.php");
13include("../inc/inc.Utils.php");
14
15function 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
46function 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
81function 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
111function 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
129function 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();
144notifyForFolder($rootFolder, array());
145
146print "<pre>";
147print_r($msgs);
148print "</pre>";
149
150$receivers = array_keys($msgs);
151foreach ($receivers as $receiver)
152{
153        $msg = implode("\n\n", $msgs[$receiver]);
154        mail($receiver, getMLText("notify_subject"), $msg);
155}
156?>
Note: See TracBrowser for help on using the repository browser.