1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : BackendProxy.php |
---|
4 | * Project : Z-Push |
---|
5 | * Descr : It route calls to three Backends thru one interface. |
---|
6 | * |
---|
7 | * Created : 04.10.2010 - emerson-faria.nobre@serpro.gov.br |
---|
8 | * |
---|
9 | * ᅵ Zarafa Deutschland GmbH, www.zarafaserver.de |
---|
10 | * This file is distributed under GPL v2. |
---|
11 | * Consult LICENSE file for details |
---|
12 | ************************************************/ |
---|
13 | require_once("diffbackend.php"); |
---|
14 | |
---|
15 | class BackendProxy extends BackendDiff { |
---|
16 | var $BackendEmail; |
---|
17 | var $BackendContacts; |
---|
18 | var $BackendCalendar; |
---|
19 | var $folderid; |
---|
20 | |
---|
21 | function __construct() |
---|
22 | { |
---|
23 | global $BACKEND_EMAIL, $BACKEND_CONTACTS, $BACKEND_CALENDAR; |
---|
24 | if (isset($BACKEND_EMAIL)) $this->BackendEmail = new $BACKEND_EMAIL(); |
---|
25 | if (isset($BACKEND_CONTACTS)) $this->BackendContacts = new $BACKEND_CONTACTS(); |
---|
26 | if (isset($BACKEND_CALENDAR)) $this->BackendCalendar = new $BACKEND_CALENDAR(); |
---|
27 | } |
---|
28 | |
---|
29 | function Logon($username, $domain, $password) { |
---|
30 | global $BACKEND_EMAIL, $BACKEND_CONTACTS, $BACKEND_CALENDAR; |
---|
31 | if (isset($BACKEND_EMAIL) and (! $this->BackendEmail->Logon($username, $domain, $password))) return false; |
---|
32 | if (isset($BACKEND_CONTACTS) and (! $this->BackendContacts->Logon($username, $domain, $password))) return false; |
---|
33 | if (isset($BACKEND_CALENDAR) and (! $this->BackendCalendar->Logon($username, $domain, $password))) return false; |
---|
34 | return true; |
---|
35 | } |
---|
36 | |
---|
37 | function Logoff() { |
---|
38 | global $BACKEND_EMAIL; |
---|
39 | if (isset($BACKEND_EMAIL)) return $this->BackendEmail->Logoff(); |
---|
40 | else return true; |
---|
41 | } |
---|
42 | |
---|
43 | function Setup($user, $devid, $protocolversion) { |
---|
44 | debugLog('BackendProxy::Setup('.$user.','.$devid.','.$protocolversion.')'); |
---|
45 | global $BACKEND_EMAIL, $BACKEND_CONTACTS, $BACKEND_CALENDAR; |
---|
46 | if (isset($BACKEND_EMAIL)) $this->BackendEmail->Setup($user, $devid, $protocolversion); |
---|
47 | if (isset($BACKEND_CONTACTS)) $this->BackendContacts->Setup($user, $devid, $protocolversion); |
---|
48 | if (isset($BACKEND_CALENDAR)) $this->BackendCalendar->Setup($user, $devid, $protocolversion); |
---|
49 | return true; |
---|
50 | } |
---|
51 | |
---|
52 | function GetExporter($folderid = false) { |
---|
53 | $this->folderid = $folderid; |
---|
54 | return parent::GetExporter($folderid); |
---|
55 | } |
---|
56 | |
---|
57 | function SendMail($rfc822, $forward = false, $reply = false, $parent = false) { |
---|
58 | global $BACKEND_EMAIL; |
---|
59 | if (isset($BACKEND_EMAIL)) return $this->BackendEmail->SendMail($rfc822, $forward, $reply, $parent); |
---|
60 | else return false; |
---|
61 | } |
---|
62 | |
---|
63 | function GetWasteBasket() { |
---|
64 | if (isset($BACKEND_EMAIL)) return $this->BackendEmail->GetWasteBasket(); |
---|
65 | else return false; |
---|
66 | } |
---|
67 | |
---|
68 | function GetMessageList($folderid, $cutoffdate) { |
---|
69 | if ($folderid == 'root') { |
---|
70 | return $this->BackendContacts->GetMessageList($folderid, $cutoffdate); |
---|
71 | } else if ($folderid == 'calendar') { |
---|
72 | return $this->BackendCalendar->GetMessageList($folderid, $cutoffdate); |
---|
73 | } else return $this->BackendEmail->GetMessageList($folderid, $cutoffdate); |
---|
74 | } |
---|
75 | |
---|
76 | function GetFolderList() { |
---|
77 | global $BACKEND_EMAIL, $BACKEND_CONTACTS, $BACKEND_CALENDAR; |
---|
78 | $folders = Array(); |
---|
79 | if (isset($BACKEND_EMAIL)) $folders += $this->BackendEmail->GetFolderList(); |
---|
80 | if (isset($BACKEND_CALENDAR)) array_push($folders, $this->BackendCalendar->GetFolderList()); |
---|
81 | if (isset($BACKEND_CONTACTS)) array_push($folders, $this->BackendContacts->GetFolderList()); |
---|
82 | return $folders; |
---|
83 | } |
---|
84 | |
---|
85 | function GetFolder($id) { |
---|
86 | if ($id == 'root') { |
---|
87 | return $this->BackendContacts->GetFolder($id); |
---|
88 | } else if ($id == 'calendar') { |
---|
89 | return $this->BackendCalendar->GetFolder($id); |
---|
90 | } else return $this->BackendEmail->GetFolder($id); |
---|
91 | } |
---|
92 | |
---|
93 | function StatFolder($id) { |
---|
94 | if ($id == 'root') { |
---|
95 | return $this->BackendContacts->StatFolder($id); |
---|
96 | } else if ($id == 'calendar') { |
---|
97 | return $this->BackendCalendar->StatFolder($id); |
---|
98 | } else return $this->BackendEmail->StatFolder($id); |
---|
99 | } |
---|
100 | |
---|
101 | function GetAttachmentData($attname) { |
---|
102 | list($folderid, $id, $part) = explode(":", $attname); |
---|
103 | if ($folderid == 'root') { |
---|
104 | return $this->BackendContacts->GetAttachmentData($attname); |
---|
105 | } else if ($folderid == 'calendar') { |
---|
106 | return $this->BackendCalendar->GetAttachmentData($attname); |
---|
107 | } else return $this->BackendEmail->GetAttachmentData($attname); |
---|
108 | } |
---|
109 | |
---|
110 | function StatMessage($folderid, $id) { |
---|
111 | if ($folderid == 'root') { |
---|
112 | return $this->BackendContacts->StatMessage($folderid, $id); |
---|
113 | } else if ($folderid == 'calendar') { |
---|
114 | return $this->BackendCalendar->StatMessage($folderid, $id); |
---|
115 | } else return $this->BackendEmail->StatMessage($folderid, $id); |
---|
116 | } |
---|
117 | |
---|
118 | function GetMessage($folderid, $id, $truncsize, $mimesupport = 0) { |
---|
119 | if ($folderid == 'root') { |
---|
120 | return $this->BackendContacts->GetMessage($folderid, $id, $truncsize, $mimesupport = 0); |
---|
121 | } else if ($folderid == 'calendar') { |
---|
122 | return $this->BackendCalendar->GetMessage($folderid, $id, $truncsize, $mimesupport = 0); |
---|
123 | } else return $this->BackendEmail->GetMessage($folderid, $id, $truncsize, $mimesupport = 0); |
---|
124 | } |
---|
125 | |
---|
126 | function DeleteMessage($folderid, $id) { |
---|
127 | if ($folderid == 'root') { |
---|
128 | return $this->BackendContacts->DeleteMessage($folderid, $id); |
---|
129 | } else if ($folderid == 'calendar') { |
---|
130 | return $this->BackendCalendar->DeleteMessage($folderid, $id); |
---|
131 | } else return $this->BackendEmail->DeleteMessage($folderid, $id); |
---|
132 | } |
---|
133 | |
---|
134 | function SetReadFlag($folderid, $id, $flags) { |
---|
135 | if ($folderid == 'root') { |
---|
136 | return $this->BackendContacts->SetReadFlag($folderid, $id, $flags); |
---|
137 | } else if ($folderid == 'calendar') { |
---|
138 | return $this->BackendCalendar->SetReadFlag($folderid, $id, $flags); |
---|
139 | } else return $this->BackendEmail->SetReadFlag($folderid, $id, $flags); |
---|
140 | } |
---|
141 | |
---|
142 | function ChangeMessage($folderid, $id, $message) { |
---|
143 | if ($folderid == 'root') { |
---|
144 | return $this->BackendContacts->ChangeMessage($folderid, $id, $message); |
---|
145 | } else if ($folderid == 'calendar') { |
---|
146 | return $this->BackendCalendar->ChangeMessage($folderid, $id, $message); |
---|
147 | } else return $this->BackendEmail->ChangeMessage($folderid, $id, $message); |
---|
148 | } |
---|
149 | |
---|
150 | function MoveMessage($folderid, $id, $newfolderid) { |
---|
151 | if ($folderid == 'root') { |
---|
152 | return $this->BackendContacts->MoveMessage($folderid, $id, $newfolderid); |
---|
153 | } else if ($folderid == 'calendar') { |
---|
154 | return $this->BackendCalendar->MoveMessage($folderid, $id, $newfolderid); |
---|
155 | } else return $this->BackendEmail->MoveMessage($folderid, $id, $newfolderid); |
---|
156 | } |
---|
157 | |
---|
158 | function AlterPing() { |
---|
159 | if ($this->folderid == 'root') { |
---|
160 | return false; |
---|
161 | } else if ($this->folderid == 'calendar') { |
---|
162 | return false; |
---|
163 | } else return true; |
---|
164 | } |
---|
165 | |
---|
166 | function AlterPingChanges($folderid, &$syncstate) { |
---|
167 | if ($folderid == 'root') { |
---|
168 | return $this->BackendContacts->AlterPingChanges($folderid, &$syncstate); |
---|
169 | } else if ($folderid == 'calendar') { |
---|
170 | return $this->BackendCalendar->AlterPingChanges($folderid, &$syncstate); |
---|
171 | } else return $this->BackendEmail->AlterPingChanges($folderid, &$syncstate); |
---|
172 | } |
---|
173 | }; |
---|
174 | ?> |
---|