1
|
|
|
<?php |
2
|
|
|
/************************************************************************ |
3
|
|
|
* OVIDENTIA http://www.ovidentia.org * |
4
|
|
|
************************************************************************ |
5
|
|
|
* Copyright (c) 2003 by CANTICO ( http://www.cantico.fr ) * |
6
|
|
|
* * |
7
|
|
|
* This file is part of Ovidentia. * |
8
|
|
|
* * |
9
|
|
|
* Ovidentia is free software; you can redistribute it and/or modify * |
10
|
|
|
* it under the terms of the GNU General Public License as published by * |
11
|
|
|
* the Free Software Foundation; either version 2, or (at your option) * |
12
|
|
|
* any later version. * |
13
|
|
|
* * |
14
|
|
|
* This program is distributed in the hope that it will be useful, but * |
15
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
17
|
|
|
* See the GNU General Public License for more details. * |
18
|
|
|
* * |
19
|
|
|
* You should have received a copy of the GNU General Public License * |
20
|
|
|
* along with this program; if not, write to the Free Software * |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,* |
22
|
|
|
* USA. * |
23
|
|
|
************************************************************************/ |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
|
34
|
|
|
class absences_notifyRequestApproversCls |
35
|
|
|
{ |
36
|
|
|
public $message; |
37
|
|
|
public $commenttxt; |
38
|
|
|
public $comment; |
39
|
|
|
public $title_message; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
private $requests; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
private $fields; |
52
|
|
|
|
53
|
|
|
public function __construct(Array $requests) |
54
|
|
|
{ |
55
|
|
|
$this->requests = $requests; |
56
|
|
|
|
57
|
|
|
$this->fromuser = absences_translate("User"); |
|
|
|
|
58
|
|
|
$this->commenttxt = absences_translate("Comment"); |
59
|
|
|
$this->t_approbation_page = absences_translate("Approbations page"); |
|
|
|
|
60
|
|
|
$this->approburl = $GLOBALS['babUrlScript'].'?tg=approb'; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function getRequest() |
65
|
|
|
{ |
66
|
|
|
return $this->requests; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function getnextrequest() |
71
|
|
|
{ |
72
|
|
|
if (list(,$request) = each($this->requests)) |
73
|
|
|
{ |
74
|
|
|
/* @var $request absences_Request */ |
75
|
|
|
|
76
|
|
|
if ($request->modifiedOn() !== $request->createdOn()) |
77
|
|
|
{ |
78
|
|
|
$this->title_message = bab_toHtml(sprintf(absences_translate("The %s has been modified"), $request->getTitle())); |
79
|
|
|
} |
80
|
|
|
else |
81
|
|
|
{ |
82
|
|
|
$this->title_message = bab_toHtml(sprintf(absences_translate("A %s is waiting to be validated"), $request->getTitle())); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->username = bab_toHtml(bab_getUserName($request->id_user)); |
|
|
|
|
86
|
|
|
$this->comment = bab_toHtml($request->comment, BAB_HTML_ENTITIES | BAB_HTML_BR); |
|
|
|
|
87
|
|
|
$this->fields = $request->getNotifyFields(); |
88
|
|
|
$this->alert = $request->approbAlert(); |
|
|
|
|
89
|
|
|
|
90
|
|
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
View Code Duplication |
public function getnextfield() |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
if ($arr = each($this->fields)) |
100
|
|
|
{ |
101
|
|
|
$this->label = bab_toHtml($arr[0]); |
|
|
|
|
102
|
|
|
$this->value = bab_toHtml($arr[1]); |
|
|
|
|
103
|
|
|
return true; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Notifier les approbateurs |
114
|
|
|
* |
115
|
|
|
*/ |
116
|
|
|
function absences_notifyRequestApprovers() |
117
|
|
|
{ |
118
|
|
|
$mail = bab_mail(); |
119
|
|
|
if( $mail == false ) |
120
|
|
|
{ |
121
|
|
|
return; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
$list = absences_getRequestsApprovers(); |
126
|
|
|
|
127
|
|
|
foreach($list as $email) |
128
|
|
|
{ |
129
|
|
|
$mail->clearTo(); |
130
|
|
|
|
131
|
|
|
foreach($email['approvers'] as $id_user) |
132
|
|
|
{ |
133
|
|
|
$mail->mailTo(bab_getUserEmail($id_user), bab_getUserName($id_user)); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$mail->mailFrom($GLOBALS['babAdminEmail'], $GLOBALS['babAdminName']); |
137
|
|
|
$mail->mailSubject(absences_translate("Vacation request is waiting to be validated", "Vacations requests are waiting to be validated", count($email['requests']))); |
138
|
|
|
|
139
|
|
|
$content = new absences_notifyRequestApproversCls($email['requests']); |
140
|
|
|
|
141
|
|
|
$message = $mail->mailTemplate(bab_printTemplate($content, absences_addon()->getRelativePath()."mailinfo.html", "newrequests")); |
|
|
|
|
142
|
|
|
$mail->mailBody($message, "html"); |
143
|
|
|
|
144
|
|
|
$message = bab_printTemplate($content, absences_addon()->getRelativePath()."mailinfo.html", "newrequeststxt"); |
|
|
|
|
145
|
|
|
$mail->mailAltBody($message); |
146
|
|
|
|
147
|
|
|
if ($mail->send()) |
148
|
|
|
{ |
149
|
|
|
$requests = $content->getRequest(); |
150
|
|
|
foreach($requests as $request) |
151
|
|
|
{ |
152
|
|
|
$request->setNotified(); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
|
161
|
|
|
|
162
|
|
|
|
163
|
|
|
|
164
|
|
|
|
165
|
|
|
|
166
|
|
|
|
167
|
|
|
|
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
|
172
|
|
|
|
173
|
|
|
|
174
|
|
|
|
175
|
|
|
|
176
|
|
|
|
177
|
|
|
|
178
|
|
|
class absences_notifyRequestAuthorCls |
179
|
|
|
{ |
180
|
|
|
public $message; |
181
|
|
|
public $from; |
182
|
|
|
public $site; |
183
|
|
|
public $bview; |
184
|
|
|
public $by; |
185
|
|
|
public $reason; |
186
|
|
|
public $reasontxt; |
187
|
|
|
|
188
|
|
|
private $res; |
189
|
|
|
|
190
|
|
|
function __construct(absences_Request $request, $message) |
|
|
|
|
191
|
|
|
{ |
192
|
|
|
$this->message = $message; |
193
|
|
|
|
194
|
|
|
$this->reasontxt = absences_translate("Additional information"); |
195
|
|
|
$this->reason = bab_toHtml($request->comment2, BAB_HTML_BR | BAB_HTML_ENTITIES); |
196
|
|
|
if( $request->status == 'N') |
197
|
|
|
{ |
198
|
|
|
$this->by = absences_translate("By"); |
199
|
|
|
$this->username = bab_getUserName($request->id_approver); |
|
|
|
|
200
|
|
|
$this->bview = true; |
201
|
|
|
} |
202
|
|
|
else |
203
|
|
|
{ |
204
|
|
|
$this->bview = false; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$this->res = $request->getNotifyFields(); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
View Code Duplication |
public function getnext() |
|
|
|
|
212
|
|
|
{ |
213
|
|
|
if ($arr = each($this->res)) |
214
|
|
|
{ |
215
|
|
|
$this->label = bab_toHtml($arr[0]); |
|
|
|
|
216
|
|
|
$this->value = bab_toHtml($arr[1]); |
|
|
|
|
217
|
|
|
return true; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return false; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Notify author of a request about approval |
228
|
|
|
* @param array | Iterator $requests <absences_Request> |
229
|
|
|
* @param string $subject Email subject |
230
|
|
|
* @param string $message message content introduction for each request |
231
|
|
|
* @param int $id_user Recipient (author) |
232
|
|
|
*/ |
233
|
|
|
function absences_notifyRequestAuthor($requests, $subject, $message, $id_user) |
|
|
|
|
234
|
|
|
{ |
235
|
|
|
global $BAB_SESS_USER, $BAB_SESS_EMAIL, $babAdminEmail; |
236
|
|
|
|
237
|
|
|
$mail = bab_mail(); |
238
|
|
|
if( $mail == false ) |
239
|
|
|
return; |
240
|
|
|
|
241
|
|
|
$mail->mailTo(bab_getUserEmail($id_user), bab_getUserName($id_user)); |
242
|
|
|
|
243
|
|
|
$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER); |
244
|
|
|
$mail->mailSubject($subject); |
245
|
|
|
|
246
|
|
|
$message = ''; |
247
|
|
|
$messagetxt = ''; |
248
|
|
|
|
249
|
|
View Code Duplication |
foreach($requests as $request) |
|
|
|
|
250
|
|
|
{ |
251
|
|
|
$tempa = new absences_notifyRequestAuthorCls($request, $message); |
252
|
|
|
$message .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "infovacation"); |
|
|
|
|
253
|
|
|
$messagetxt .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "infovacationtxt"); |
|
|
|
|
254
|
|
|
} |
255
|
|
|
$mail->mailBody($mail->mailTemplate($message), "html"); |
256
|
|
|
$mail->mailAltBody($messagetxt); |
257
|
|
|
|
258
|
|
|
$mail->send(); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
|
263
|
|
|
|
264
|
|
|
|
265
|
|
|
|
266
|
|
|
|
267
|
|
|
|
268
|
|
|
class absences_notifyEntryOwnerEmailsCls |
269
|
|
|
{ |
270
|
|
|
public $message; |
271
|
|
|
public $from; |
272
|
|
|
public $site; |
273
|
|
|
public $bview; |
274
|
|
|
public $by; |
275
|
|
|
public $reason; |
276
|
|
|
public $reasontxt; |
277
|
|
|
|
278
|
|
|
private $res; |
279
|
|
|
|
280
|
|
|
function __construct(absences_Entry $entry, $subject) |
|
|
|
|
281
|
|
|
{ |
282
|
|
|
$this->message = $subject; |
283
|
|
|
|
284
|
|
|
$this->res = $entry->getNotifyFields(); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
|
288
|
|
View Code Duplication |
public function getnext() |
|
|
|
|
289
|
|
|
{ |
290
|
|
|
if ($arr = each($this->res)) |
291
|
|
|
{ |
292
|
|
|
$this->label = bab_toHtml($arr[0]); |
|
|
|
|
293
|
|
|
$this->value = bab_toHtml($arr[1]); |
|
|
|
|
294
|
|
|
return true; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
return false; |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
|
303
|
|
|
|
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* |
307
|
|
|
* @param Array | absences_EntryIterator $entries <absences_Entry> |
308
|
|
|
* @param Array $emails <string> |
309
|
|
|
*/ |
310
|
|
|
function absences_notifyEntryOwnerEmails($entries, Array $emails) |
311
|
|
|
{ |
312
|
|
|
global $babBody, $babDB, $BAB_SESS_USER, $BAB_SESS_EMAIL, $babAdminEmail; |
313
|
|
|
|
314
|
|
|
$mail = bab_mail(); |
315
|
|
|
if( $mail == false ) |
316
|
|
|
return; |
317
|
|
|
|
318
|
|
|
$i = 0; |
319
|
|
|
foreach($emails as $email) |
320
|
|
|
{ |
321
|
|
|
$email = trim($email); |
322
|
|
|
if (!empty($email)) |
323
|
|
|
{ |
324
|
|
|
$mail->mailTo($email); |
325
|
|
|
$i++; |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
if ($i === 0) |
330
|
|
|
{ |
331
|
|
|
return; // no recipient |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
|
335
|
|
|
$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER); |
336
|
|
|
if (1 === count($entries)) |
337
|
|
|
{ |
338
|
|
|
$entry = reset($entries); |
339
|
|
|
$subject = sprintf(absences_translate("An absence has been confirmed for %s"), $entry->getUserName()); |
340
|
|
|
} else { |
341
|
|
|
$subject = absences_translate("absences request set has been confirmed"); |
342
|
|
|
} |
343
|
|
|
$mail->mailSubject($subject); |
344
|
|
|
|
345
|
|
|
$message = ''; |
346
|
|
|
$messagetxt = ''; |
347
|
|
|
foreach($entries as $entry) |
348
|
|
|
{ |
349
|
|
|
$subject = sprintf(absences_translate("An absence has been confirmed for %s"), $entry->getUserName()); |
350
|
|
|
$tempa = new absences_notifyEntryOwnerEmailsCls($entry, $subject); |
351
|
|
|
$message .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "vacationemails"); |
|
|
|
|
352
|
|
|
$messagetxt .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "vacationemailstxt"); |
|
|
|
|
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
$mail->mailBody($mail->mailTemplate($message), "html"); |
356
|
|
|
$mail->mailAltBody($messagetxt); |
357
|
|
|
|
358
|
|
|
$mail->send(); |
359
|
|
|
} |
360
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: