ryxeo-glpi-git / inc / mailing.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (36,6 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: mailing.class.php 7763 2009-01-06 18:44:50Z moyo $
|
4 |
-------------------------------------------------------------------------
|
5 |
GLPI - Gestionnaire Libre de Parc Informatique
|
6 |
Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
7 |
|
8 |
http://indepnet.net/ http://glpi-project.org
|
9 |
-------------------------------------------------------------------------
|
10 |
|
11 |
LICENSE
|
12 |
|
13 |
This file is part of GLPI.
|
14 |
|
15 |
GLPI is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
17 |
the Free Software Foundation; either version 2 of the License, or
|
18 |
(at your option) any later version.
|
19 |
|
20 |
GLPI is distributed in the hope that it will be useful,
|
21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
GNU General Public License for more details.
|
24 |
|
25 |
You should have received a copy of the GNU General Public License
|
26 |
along with GLPI; if not, write to the Free Software
|
27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
28 |
--------------------------------------------------------------------------
|
29 |
*/
|
30 |
|
31 |
// ----------------------------------------------------------------------
|
32 |
// Original Author of file:
|
33 |
// Purpose of file:
|
34 |
// ----------------------------------------------------------------------
|
35 |
|
36 |
if (!defined('GLPI_ROOT')){ |
37 |
die("Sorry. You can't access directly to this file"); |
38 |
} |
39 |
|
40 |
require_once(GLPI_ROOT . "/lib/phpmailer/class.phpmailer.php"); |
41 |
|
42 |
/**
|
43 |
* glpi_phpmailer class extends
|
44 |
*/
|
45 |
class glpi_phpmailer extends phpmailer { |
46 |
|
47 |
/// Set default variables for all new objects
|
48 |
var $WordWrap = 80; |
49 |
/// Defaut charset
|
50 |
var $CharSet ="utf-8"; |
51 |
|
52 |
|
53 |
/**
|
54 |
* Constructor
|
55 |
**/
|
56 |
function glpi_phpmailer(){ |
57 |
global $CFG_GLPI; |
58 |
|
59 |
// Comes from config
|
60 |
$this->SetLanguage("en", GLPI_ROOT . "/lib/phpmailer/language/"); |
61 |
if($CFG_GLPI['smtp_mode'] == '1') { |
62 |
$this->Host = $CFG_GLPI['smtp_host']; |
63 |
$this->Port = $CFG_GLPI['smtp_port']; |
64 |
|
65 |
if($CFG_GLPI['smtp_username'] != '') { |
66 |
$this->SMTPAuth = true; |
67 |
$this->Username = $CFG_GLPI['smtp_username']; |
68 |
$this->Password = $CFG_GLPI['smtp_password']; |
69 |
} |
70 |
|
71 |
/*if($CFG_GLPI['debug']=="2"){
|
72 |
$this->SMTPDebug = TRUE;
|
73 |
}*/
|
74 |
|
75 |
$this->Mailer = "smtp"; |
76 |
} |
77 |
|
78 |
} |
79 |
|
80 |
|
81 |
|
82 |
|
83 |
} |
84 |
|
85 |
|
86 |
/**
|
87 |
* Mailing class for trackings
|
88 |
*/
|
89 |
class Mailing |
90 |
{ |
91 |
//! mailing type (new,attrib,followup,finish)
|
92 |
var $type=NULL; |
93 |
/** Job class variable - job to be mailed
|
94 |
* @see Job
|
95 |
*/
|
96 |
var $job=NULL; |
97 |
/** User class variable - user who make changes
|
98 |
* @see User
|
99 |
*/
|
100 |
var $user=NULL; |
101 |
/// Is the followupadded private ?
|
102 |
var $followupisprivate=NULL; |
103 |
|
104 |
|
105 |
/**
|
106 |
* Constructor
|
107 |
* @param $type mailing type (new,attrib,followup,finish)
|
108 |
* @param $job Job to mail
|
109 |
* @param $user User who made change
|
110 |
* @param $followupisprivate true if the currently added/modified followup is private
|
111 |
* @return nothing
|
112 |
*/
|
113 |
function Mailing ($type="",$job=NULL,$user=NULL,$followupisprivate=false) |
114 |
{ |
115 |
$this->type=$type; |
116 |
if (!isset($job->hardwaredatas)||!count($job->hardwaredatas)){ |
117 |
$job->getHardwareData();
|
118 |
} |
119 |
$this->job=$job; |
120 |
$this->user=$user; |
121 |
$this->followupisprivate=$followupisprivate; |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Give mails to send the mail
|
126 |
*
|
127 |
* Determine email to send mail using global config and Mailing type
|
128 |
* @param $sendprivate false : all users; true : only users who have the right to see private followups
|
129 |
*
|
130 |
* @return array containing email
|
131 |
*/
|
132 |
function get_users_to_send_mail($sendprivate=false) |
133 |
{ |
134 |
global $DB,$CFG_GLPI; |
135 |
|
136 |
$emails=array(); |
137 |
|
138 |
$query="SELECT * FROM glpi_mailing WHERE type='".$this->type."'"; |
139 |
$result=$DB->query($query); |
140 |
if ($DB->numrows($result)){ |
141 |
|
142 |
$select =""; |
143 |
$join=""; |
144 |
$joinprofile=""; |
145 |
// If send private is the user can see private followups ?
|
146 |
if ($sendprivate){ |
147 |
$join=" INNER JOIN glpi_users_profiles |
148 |
ON (glpi_users_profiles.FK_users = glpi_users.ID
|
149 |
".getEntitiesRestrictRequest("AND","glpi_users_profiles","FK_entities",$this->job->fields['FK_entities'],true).") |
150 |
INNER JOIN glpi_profiles
|
151 |
ON (glpi_profiles.ID = glpi_users_profiles.FK_profiles AND glpi_profiles.interface='central' AND glpi_profiles.show_full_ticket = '1') ";
|
152 |
$joinprofile= "INNER JOIN glpi_profiles |
153 |
ON (glpi_profiles.ID = glpi_users_profiles.FK_profiles AND glpi_profiles.interface='central' AND glpi_profiles.show_full_ticket = '1') ";
|
154 |
|
155 |
} |
156 |
|
157 |
while ($data=$DB->fetch_assoc($result)){ |
158 |
switch ($data["item_type"]){ |
159 |
case USER_MAILING_TYPE : |
160 |
switch($data["FK_item"]){ |
161 |
// ADMIN SEND
|
162 |
case ADMIN_MAILING : |
163 |
if (isValidEmail($CFG_GLPI["admin_email"])&&!isset($emails[$CFG_GLPI["admin_email"]])){ |
164 |
$emails[$CFG_GLPI["admin_email"]]=$CFG_GLPI["default_language"]; |
165 |
} |
166 |
break;
|
167 |
// ADMIN ENTITY SEND
|
168 |
case ADMIN_ENTITY_MAILING : |
169 |
$query2 = "SELECT admin_email AS EMAIL |
170 |
FROM glpi_entities_data
|
171 |
WHERE (FK_entities = '".$this->job->fields["FK_entities"]."')"; |
172 |
if ($result2 = $DB->query($query2)) { |
173 |
if ($DB->numrows($result2)==1){ |
174 |
$row = $DB->fetch_array($result2); |
175 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
176 |
$emails[$row['EMAIL']]=$CFG_GLPI["default_language"]; |
177 |
} |
178 |
} |
179 |
} |
180 |
break;
|
181 |
// ASSIGN SEND
|
182 |
case ASSIGN_MAILING : |
183 |
if (isset($this->job->fields["assign"])&&$this->job->fields["assign"]>0){ |
184 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
185 |
FROM glpi_users $join
|
186 |
WHERE (glpi_users.ID = '".$this->job->fields["assign"]."')"; |
187 |
if ($result2 = $DB->query($query2)) { |
188 |
if ($DB->numrows($result2)==1){ |
189 |
$row = $DB->fetch_array($result2); |
190 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
191 |
$emails[$row['EMAIL']]=$row['LANG']; |
192 |
} |
193 |
} |
194 |
} |
195 |
} |
196 |
break;
|
197 |
// ASSIGN SEND
|
198 |
case ASSIGN_ENT_MAILING : |
199 |
|
200 |
if (!$sendprivate&&isset($this->job->fields["assign_ent"])&&$this->job->fields["assign_ent"]>0){ |
201 |
$query2 = "SELECT DISTINCT glpi_enterprises.email AS EMAIL |
202 |
FROM glpi_enterprises
|
203 |
WHERE (glpi_enterprises.ID = '".$this->job->fields["assign_ent"]."')"; |
204 |
if ($result2 = $DB->query($query2)) { |
205 |
if ($DB->numrows($result2)==1){ |
206 |
$row = $DB->fetch_array($result2); |
207 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
208 |
$emails[$row['EMAIL']]=$CFG_GLPI["default_language"]; |
209 |
} |
210 |
} |
211 |
} |
212 |
} |
213 |
break;
|
214 |
// ASSIGN GROUP SEND
|
215 |
case ASSIGN_GROUP_MAILING : |
216 |
if (isset($this->job->fields["assign_group"])&&$this->job->fields["assign_group"]>0){ |
217 |
$query="SELECT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
218 |
FROM glpi_users_groups
|
219 |
INNER JOIN glpi_users ON (glpi_users_groups.FK_users = glpi_users.ID) $join
|
220 |
WHERE glpi_users.deleted=0 AND glpi_users_groups.FK_groups='".$this->job->fields["assign_group"]."'"; |
221 |
|
222 |
if ($result2= $DB->query($query)){ |
223 |
if ($DB->numrows($result2)){ |
224 |
while ($row=$DB->fetch_assoc($result2)){ |
225 |
if (isValidEmail($row["EMAIL"])&&!isset($emails[$row['EMAIL']])){ |
226 |
$emails[$row['EMAIL']]=$row['LANG']; |
227 |
} |
228 |
} |
229 |
} |
230 |
} |
231 |
} |
232 |
break;
|
233 |
// SUPERVISOR ASSIGN GROUP SEND
|
234 |
case SUPERVISOR_ASSIGN_GROUP_MAILING : |
235 |
if (isset($this->job->fields["assign_group"])&&$this->job->fields["assign_group"]>0){ |
236 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
237 |
FROM glpi_groups
|
238 |
LEFT JOIN glpi_users ON (glpi_users.ID = glpi_groups.FK_users) $join
|
239 |
WHERE (glpi_groups.ID = '".$this->job->fields["assign_group"]."')"; |
240 |
if ($result2 = $DB->query($query2)) { |
241 |
if ($DB->numrows($result2)==1){ |
242 |
$row = $DB->fetch_array($result2); |
243 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
244 |
$emails[$row['EMAIL']]=$row['LANG']; |
245 |
} |
246 |
} |
247 |
} |
248 |
} |
249 |
break;
|
250 |
|
251 |
|
252 |
// RECIPIENT SEND
|
253 |
case RECIPIENT_MAILING : |
254 |
if (isset($this->job->fields["recipient"])&&$this->job->fields["recipient"]>0){ |
255 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
256 |
FROM glpi_users $join
|
257 |
WHERE (glpi_users.ID = '".$this->job->fields["recipient"]."')"; |
258 |
if ($result2 = $DB->query($query2)) { |
259 |
if ($DB->numrows($result2)==1){ |
260 |
$row = $DB->fetch_array($result2); |
261 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
262 |
$emails[$row['EMAIL']]=$row['LANG']; |
263 |
} |
264 |
} |
265 |
} |
266 |
} |
267 |
break;
|
268 |
|
269 |
// AUTHOR SEND
|
270 |
case AUTHOR_MAILING : |
271 |
if ($this->job->fields["emailupdates"]&&isValidEmail($this->job->fields["uemail"])&&!isset($emails[$this->job->fields["uemail"]])){ |
272 |
// Uemail = mail of the author ? -> use right of the author to see private followups
|
273 |
// Else not see private
|
274 |
$authorsend=false; |
275 |
$authorlang=$CFG_GLPI["default_language"]; |
276 |
if (!$sendprivate){ |
277 |
$authorsend=true; |
278 |
} |
279 |
|
280 |
// Is the user have the same mail that uemail ?
|
281 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
282 |
FROM glpi_users $join
|
283 |
WHERE (glpi_users.ID = '".$this->job->fields["author"]."')"; |
284 |
if ($result2 = $DB->query($query2)) { |
285 |
if ($DB->numrows($result2)==1){ |
286 |
$row = $DB->fetch_array($result2); |
287 |
if ($row['EMAIL']==$this->job->fields["uemail"]){ |
288 |
$authorsend=true; |
289 |
$authorlang=$row['LANG']; |
290 |
} |
291 |
} |
292 |
} |
293 |
|
294 |
if ($authorsend){ |
295 |
$emails[$this->job->fields["uemail"]]=$authorlang; |
296 |
} |
297 |
} |
298 |
break;
|
299 |
// SUPERVISOR ASSIGN GROUP SEND
|
300 |
case SUPERVISOR_AUTHOR_GROUP_MAILING : |
301 |
if (isset($this->job->fields["FK_group"])&&$this->job->fields["FK_group"]>0){ |
302 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
303 |
FROM glpi_groups
|
304 |
LEFT JOIN glpi_users ON (glpi_users.ID = glpi_groups.FK_users) $join
|
305 |
WHERE (glpi_groups.ID = '".$this->job->fields["FK_group"]."')"; |
306 |
if ($result2 = $DB->query($query2)) { |
307 |
if ($DB->numrows($result2)==1){ |
308 |
$row = $DB->fetch_array($result2); |
309 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
310 |
$emails[$row['EMAIL']]=$row['LANG']; |
311 |
} |
312 |
} |
313 |
} |
314 |
} |
315 |
break;
|
316 |
|
317 |
// OLD ASSIGN SEND
|
318 |
case OLD_ASSIGN_MAILING : |
319 |
if (isset($this->job->fields["_old_assign"])&&$this->job->fields["_old_assign"]>0){ |
320 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
321 |
FROM glpi_users $join
|
322 |
WHERE (glpi_users.ID = '".$this->job->fields["_old_assign"]."')"; |
323 |
if ($result2 = $DB->query($query2)) { |
324 |
if ($DB->numrows($result2)==1){ |
325 |
$row = $DB->fetch_array($result2); |
326 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
327 |
$emails[$row['EMAIL']]=$row['LANG']; |
328 |
} |
329 |
} |
330 |
} |
331 |
} |
332 |
break;
|
333 |
// TECH SEND
|
334 |
case TECH_MAILING : |
335 |
if (isset($this->job->fields["computer"])&&$this->job->fields["computer"]>0&&isset($this->job->fields["device_type"])&&$this->job->fields["device_type"]>0){ |
336 |
$ci= new CommonItem(); |
337 |
$ci->getFromDB($this->job->fields["device_type"],$this->job->fields["computer"]); |
338 |
if ($tmp=$ci->getField('tech_num')){ |
339 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
340 |
FROM glpi_users $join
|
341 |
WHERE (glpi_users.ID = '".$tmp."')"; |
342 |
if ($result2 = $DB->query($query2)) { |
343 |
if ($DB->numrows($result2)==1){ |
344 |
$row = $DB->fetch_array($result2); |
345 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
346 |
$emails[$row['EMAIL']]=$row['LANG']; |
347 |
} |
348 |
} |
349 |
} |
350 |
} |
351 |
} |
352 |
break;
|
353 |
// USER SEND
|
354 |
case USER_MAILING : |
355 |
if (isset($this->job->fields["computer"])&&$this->job->fields["computer"]>0&&isset($this->job->fields["device_type"])&&$this->job->fields["device_type"]>0){ |
356 |
$ci= new CommonItem(); |
357 |
$ci->getFromDB($this->job->fields["device_type"],$this->job->fields["computer"]); |
358 |
if ($tmp=$ci->getField('FK_users')){ |
359 |
$query2 = "SELECT DISTINCT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
360 |
FROM glpi_users $join
|
361 |
WHERE (glpi_users.ID = '".$tmp."')"; |
362 |
if ($result2 = $DB->query($query2)) { |
363 |
if ($DB->numrows($result2)==1){ |
364 |
$row = $DB->fetch_array($result2); |
365 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
366 |
$emails[$row['EMAIL']]=$row['LANG']; |
367 |
} |
368 |
} |
369 |
} |
370 |
} |
371 |
} |
372 |
break;
|
373 |
|
374 |
} |
375 |
break;
|
376 |
case PROFILE_MAILING_TYPE : |
377 |
$query="SELECT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
378 |
FROM glpi_users_profiles
|
379 |
INNER JOIN glpi_users ON (glpi_users_profiles.FK_users = glpi_users.ID) $joinprofile
|
380 |
WHERE glpi_users.deleted=0 AND glpi_users_profiles.FK_profiles='".$data["FK_item"]."' ". |
381 |
getEntitiesRestrictRequest("AND","glpi_users_profiles","FK_entities",$this->job->fields['FK_entities'],true); |
382 |
|
383 |
if ($result2= $DB->query($query)){ |
384 |
if ($DB->numrows($result2)) |
385 |
while ($row=$DB->fetch_assoc($result2)){ |
386 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
387 |
$emails[$row['EMAIL']]=$row['LANG']; |
388 |
} |
389 |
} |
390 |
} |
391 |
break;
|
392 |
case GROUP_MAILING_TYPE : |
393 |
$query="SELECT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
394 |
FROM glpi_users_groups
|
395 |
INNER JOIN glpi_users ON (glpi_users_groups.FK_users = glpi_users.ID) $join
|
396 |
WHERE glpi_users.deleted=0 AND glpi_users_groups.FK_groups='".$data["FK_item"]."'"; |
397 |
|
398 |
if ($result2= $DB->query($query)){ |
399 |
if ($DB->numrows($result2)) |
400 |
while ($row=$DB->fetch_assoc($result2)){ |
401 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
402 |
$emails[$row['EMAIL']]=$row['LANG']; |
403 |
} |
404 |
} |
405 |
} |
406 |
break;
|
407 |
} |
408 |
} |
409 |
} |
410 |
|
411 |
return $emails; |
412 |
} |
413 |
|
414 |
/**
|
415 |
* Format the mail body to send
|
416 |
* @param $format text or html
|
417 |
* @param $sendprivate true if the email contains private followups
|
418 |
* @return mail body string
|
419 |
*/
|
420 |
function get_mail_body($format="text", $sendprivate=false) |
421 |
{ |
422 |
global $CFG_GLPI, $LANG; |
423 |
|
424 |
// Create message body from Job and type
|
425 |
$body=""; |
426 |
|
427 |
if($format=="html"){ |
428 |
if ($CFG_GLPI["url_in_mail"]&&!empty($CFG_GLPI["url_base"])){ |
429 |
//ryxeo
|
430 |
$body.="Pour répondre à cet échange, veuillez vous connecter sur la plate forme suivante :<a href=\"".$CFG_GLPI["url_base"]."/index.php?redirect=tracking_".$this->job->fields["ID"]."\">".$CFG_GLPI["url_base"]."/index.php?redirect=tracking_".$this->job->fields["ID"]." </a><br><br>"; |
431 |
|
432 |
} |
433 |
|
434 |
$body.=$this->job->textDescription($format); |
435 |
$body.=$this->job->textFollowups($format, $sendprivate); |
436 |
|
437 |
$body.="<br>-- <br>".$CFG_GLPI["mailing_signature"]; |
438 |
$body.="</body></html>"; |
439 |
$body=ereg_replace("\n","<br>\n",$body); |
440 |
|
441 |
}else{ // text format |
442 |
|
443 |
if ($CFG_GLPI["url_in_mail"]&&!empty($CFG_GLPI["url_base"])){ |
444 |
//ryxeo
|
445 |
$body.=$LANG["mailing"][1]."\n"; $body.="Pour répondre à cet échange, veuillez vous connecter sur la plate forme suivante : : ".$CFG_GLPI["url_base"]."/index.php?redirect=tracking_".$this->job->fields["ID"]."\n"; |
446 |
|
447 |
} |
448 |
|
449 |
$body.=$this->job->textDescription($format); |
450 |
$body.=$this->job->textFollowups($format, $sendprivate); |
451 |
|
452 |
$body.="\n-- \n".$CFG_GLPI["mailing_signature"]; |
453 |
$body=ereg_replace("<br />","\n",$body); |
454 |
$body=ereg_replace("<br>","\n",$body); |
455 |
} |
456 |
|
457 |
return $body; |
458 |
} |
459 |
|
460 |
/**
|
461 |
* Format the mail sender to send
|
462 |
* @return mail sender email string
|
463 |
*/
|
464 |
function get_mail_sender(){ |
465 |
global $CFG_GLPI,$DB; |
466 |
|
467 |
$query = "SELECT admin_email AS EMAIL FROM glpi_entities_data WHERE (FK_entities = '".$this->job->fields["FK_entities"]."')"; |
468 |
if ($result=$DB->query($query)){ |
469 |
if ($DB->numrows($result)){ |
470 |
$data=$DB->fetch_assoc($result); |
471 |
if (isValidEmail($data["EMAIL"])){ |
472 |
return $data["EMAIL"]; |
473 |
} |
474 |
} |
475 |
} |
476 |
|
477 |
return $CFG_GLPI["admin_email"]; |
478 |
} |
479 |
|
480 |
/**
|
481 |
* Format the mail subject to send
|
482 |
* @return mail subject string
|
483 |
*/
|
484 |
function get_mail_subject() |
485 |
{ |
486 |
global $LANG; |
487 |
|
488 |
// Create the message subject
|
489 |
$subject=sprintf("%s%07d%s","[SUPPORT RYXEO #",$this->job->fields["ID"],"] "); |
490 |
|
491 |
if (isMultiEntitiesMode()){
|
492 |
$subject.=getDropdownName("glpi_entities",$this->job->fields['FK_entities'])." | "; |
493 |
} |
494 |
|
495 |
switch ($this->type){ |
496 |
case "new": |
497 |
$subject.=$LANG["mailing"][9]; |
498 |
break;
|
499 |
case "attrib": |
500 |
$subject.=$LANG["mailing"][12]; |
501 |
break;
|
502 |
case "followup": |
503 |
$subject.=$LANG["mailing"][10]; |
504 |
break;
|
505 |
case "update": |
506 |
$subject.=$LANG["mailing"][30]; |
507 |
break;
|
508 |
case "finish": |
509 |
$subject.=$LANG["mailing"][11]." ".convDateTime($this->job->fields["closedate"]); |
510 |
break;
|
511 |
default :
|
512 |
$subject.=$LANG["mailing"][13]; |
513 |
break;
|
514 |
} |
515 |
|
516 |
if (strlen($this->job->fields['name'])>150){ |
517 |
$subject.=" - ".utf8_substr($this->job->fields['name'],0,150)." (...)"; |
518 |
}else{
|
519 |
$subject.=" - ".$this->job->fields['name']; |
520 |
} |
521 |
|
522 |
return $subject; |
523 |
} |
524 |
|
525 |
/**
|
526 |
* Get reply to address
|
527 |
* @param $sender sender address
|
528 |
* @return return mail
|
529 |
*/
|
530 |
function get_reply_to_address ($sender){ |
531 |
global $CFG_GLPI,$DB; |
532 |
|
533 |
$replyto=$CFG_GLPI["admin_email"]; |
534 |
|
535 |
// Entity conf
|
536 |
$query = "SELECT admin_email AS EMAIL, admin_reply AS REPLY FROM glpi_entities_data WHERE (FK_entities = '".$this->job->fields["FK_entities"]."')"; |
537 |
if ($result=$DB->query($query)){ |
538 |
if ($DB->numrows($result)){ |
539 |
$data=$DB->fetch_assoc($result); |
540 |
if (isValidEmail($data["REPLY"])){ |
541 |
return $data["REPLY"]; |
542 |
} else if (isValidEmail($data["EMAIL"])){ |
543 |
$replyto=$data["EMAIL"]; |
544 |
} |
545 |
} |
546 |
} |
547 |
// Global conf
|
548 |
if (isValidEmail($CFG_GLPI["admin_reply"])){ |
549 |
return $CFG_GLPI["admin_reply"]; |
550 |
} |
551 |
|
552 |
// No specific config
|
553 |
switch ($this->type){ |
554 |
case "new": |
555 |
if (isset($this->job->fields["uemail"]) && isValidEmail($this->job->fields["uemail"])) { |
556 |
$replyto=$this->job->fields["uemail"]; |
557 |
} else {
|
558 |
$replyto=$sender; |
559 |
} |
560 |
break;
|
561 |
case "followup": |
562 |
case "update": |
563 |
if (isset($this->user->fields["email"]) && isValidEmail($this->user->fields["email"])) { |
564 |
$replyto=$this->user->fields["email"]; |
565 |
} else {
|
566 |
$replyto=$sender; |
567 |
} |
568 |
break;
|
569 |
} |
570 |
return $replyto; |
571 |
} |
572 |
/**
|
573 |
* Send mail function
|
574 |
*
|
575 |
* Construct email and send it
|
576 |
*
|
577 |
* @return mail subject string
|
578 |
*/
|
579 |
function send() |
580 |
{ |
581 |
global $CFG_GLPI,$LANG; |
582 |
if ($CFG_GLPI["mailing"]) |
583 |
{ |
584 |
if (!is_null($this->job)&&in_array($this->type,array("new","update","followup","finish"))) |
585 |
{ |
586 |
$senderror=false; |
587 |
// get users to send mail
|
588 |
$users=array(); |
589 |
// All users
|
590 |
$users[0]=$this->get_users_to_send_mail(0); |
591 |
// Users who could see private followups
|
592 |
$users[1]=$this->get_users_to_send_mail(1); |
593 |
// Delete users who can see private followups to all users list
|
594 |
foreach ($users[1] as $email => $lang){ |
595 |
if (isset($users[0][$email])){ |
596 |
unset($users[0][$email]); |
597 |
} |
598 |
} |
599 |
|
600 |
// New Followup is private : do not send to common users
|
601 |
if ($this->followupisprivate){ |
602 |
unset($users[0]); |
603 |
} |
604 |
|
605 |
$subjects=array(); |
606 |
// get sender
|
607 |
$sender= $this->get_mail_sender(); |
608 |
// get reply-to address : user->email ou job_email if not set OK
|
609 |
$replyto=$this->get_reply_to_address ($sender); |
610 |
|
611 |
$messageerror=$LANG["mailing"][47]; |
612 |
// Send all mails
|
613 |
foreach ($users as $private=>$someusers) { |
614 |
if (count($someusers)){ |
615 |
|
616 |
$mmail=new glpi_phpmailer(); |
617 |
$mmail->From=$sender; |
618 |
$mmail->AddReplyTo("$replyto", ''); |
619 |
$mmail->FromName=$sender; |
620 |
$mmail->isHTML(true); |
621 |
|
622 |
$bodys=array(); |
623 |
$altbodys=array(); |
624 |
foreach ($someusers as $email => $lang){ |
625 |
if (!isset($subjects[$lang])||!isset($bodys[$lang])||!isset($altbodys[$lang])){ |
626 |
loadLanguage($lang);
|
627 |
if (!isset($subjects[$lang])){ |
628 |
$subjects[$lang]=$this->get_mail_subject(); |
629 |
} |
630 |
$bodys[$lang]=$this->get_mail_body("html",$private); |
631 |
$altbodys[$lang]=$this->get_mail_body("text",$private); |
632 |
} |
633 |
$mmail->Subject=$subjects[$lang]; |
634 |
$mmail->Body=$bodys[$lang]; |
635 |
$mmail->AltBody=$altbodys[$lang]; |
636 |
|
637 |
$mmail->AddAddress($email, ""); |
638 |
|
639 |
if(!$mmail->Send()){ |
640 |
$senderror=true; |
641 |
addMessageAfterRedirect($messageerror."<br>".$mmail->ErrorInfo); |
642 |
}else{
|
643 |
logInFile("mail",$LANG["tracking"][38]." ".$email.": ".$subjects[$lang]."\n"); |
644 |
} |
645 |
|
646 |
$mmail->ClearAddresses(); |
647 |
} |
648 |
} |
649 |
} |
650 |
// Reinit language
|
651 |
loadLanguage(); |
652 |
if ($senderror){ |
653 |
return false; |
654 |
} |
655 |
} else {
|
656 |
addMessageAfterRedirect($LANG["mailing"][112]); |
657 |
} |
658 |
} |
659 |
return true; |
660 |
} |
661 |
} |
662 |
|
663 |
/**
|
664 |
* Mailing class for reservations
|
665 |
*/
|
666 |
class MailingResa{ |
667 |
/** ReservationResa class variable
|
668 |
* @see ReservationResa
|
669 |
*/
|
670 |
var $resa; |
671 |
//! type of mailing (new, update, delete)
|
672 |
var $type; |
673 |
|
674 |
/**
|
675 |
* Constructor
|
676 |
* @param $type mailing type (new,attrib,followup,finish)
|
677 |
* @param $resa ReservationResa to mail
|
678 |
* @return nothing
|
679 |
*/
|
680 |
function MailingResa ($resa,$type="new") |
681 |
{ |
682 |
$this->resa=$resa; |
683 |
$this->type=$type; |
684 |
|
685 |
} |
686 |
|
687 |
/**
|
688 |
* Give mails to send the mail
|
689 |
*
|
690 |
* Determine email to send mail using global config and Mailing type
|
691 |
*
|
692 |
* @return array containing email
|
693 |
*/
|
694 |
function get_users_to_send_mail() |
695 |
{ |
696 |
global $DB,$CFG_GLPI; |
697 |
|
698 |
$emails=array(); |
699 |
|
700 |
$query="SELECT * FROM glpi_mailing WHERE type='resa'"; |
701 |
$result=$DB->query($query); |
702 |
if ($DB->numrows($result)){ |
703 |
while ($data=$DB->fetch_assoc($result)){ |
704 |
switch ($data["item_type"]){ |
705 |
case USER_MAILING_TYPE : |
706 |
switch ($data["FK_item"]){ |
707 |
// ADMIN SEND
|
708 |
case ADMIN_MAILING : |
709 |
if (isValidEmail($CFG_GLPI["admin_email"])&&!isset($emails[$CFG_GLPI["admin_email"]])) |
710 |
$emails[$CFG_GLPI["admin_email"]]=$CFG_GLPI["default_language"]; |
711 |
break;
|
712 |
// ADMIN ENTITY SEND
|
713 |
case ADMIN_ENTITY_MAILING : |
714 |
|
715 |
$ri=new ReservationItem(); |
716 |
$ci=new CommonItem(); |
717 |
$entity=-1; |
718 |
if ($ri->getFromDB($this->resa->fields["id_item"])){ |
719 |
if ($ci->getFromDB($ri->fields['device_type'],$ri->fields['id_device']) ){ |
720 |
$entity=$ci->getField('FK_entities'); |
721 |
} |
722 |
} |
723 |
|
724 |
if ($entity>=0){ |
725 |
$query2 = "SELECT admin_email AS EMAIL FROM glpi_entities_data WHERE (FK_entities = '".$entity."')"; |
726 |
if ($result2 = $DB->query($query2)) { |
727 |
if ($DB->numrows($result2)==1){ |
728 |
$row = $DB->fetch_array($result2); |
729 |
if (isValidEmail($CFG_GLPI["admin_email"])&&!isset($emails[$CFG_GLPI["admin_email"]])){ |
730 |
$emails[$row['EMAIL']]=$CFG_GLPI["default_language"]; |
731 |
} |
732 |
} |
733 |
} |
734 |
} |
735 |
break;
|
736 |
// AUTHOR SEND
|
737 |
case AUTHOR_MAILING : |
738 |
$user = new User; |
739 |
if ($user->getFromDB($this->resa->fields["id_user"])) |
740 |
if (isValidEmail($user->fields["email"])&&!isset($emails[$user->fields["email"]])){ |
741 |
$emails[$user->fields["email"]]=$user->fields['language']; |
742 |
} |
743 |
break;
|
744 |
// TECH SEND
|
745 |
case TECH_MAILING : |
746 |
$ri=new ReservationItem(); |
747 |
if ($ri->getFromDB($this->resa->fields["id_item"])){ |
748 |
$ci=new CommonItem(); |
749 |
$ci->getFromDB($ri->fields["device_type"],$ri->fields["id_device"]); |
750 |
|
751 |
if ($tmp=$ci->getField('tech_num')){ |
752 |
$query2 = "SELECT glpi_users.email as EMAIL, glpi_users.language as LANG |
753 |
FROM glpi_users WHERE (glpi_users.ID = '".$tmp."')"; |
754 |
if ($result2 = $DB->query($query2)) { |
755 |
if ($DB->numrows($result2)==1){ |
756 |
$row = $DB->fetch_row($result2); |
757 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
758 |
$emails[$row['EMAIL']]=$row['LANG']; |
759 |
} |
760 |
} |
761 |
} |
762 |
} |
763 |
} |
764 |
break;
|
765 |
// USER SEND
|
766 |
case USER_MAILING : |
767 |
$ri=new ReservationItem(); |
768 |
if ($ri->getFromDB($this->resa->fields["id_item"])){ |
769 |
$ci=new CommonItem(); |
770 |
$ci->getFromDB($ri->fields["device_type"],$ri->fields["id_device"]); |
771 |
|
772 |
if ($tmp=$ci->getField('FK_users')){ |
773 |
$query2 = "SELECT glpi_users.email AS EMAIL, glpi_users.language as LANG |
774 |
FROM glpi_users WHERE (glpi_users.ID = '".$tmp."')"; |
775 |
if ($result2 = $DB->query($query2)) { |
776 |
if ($DB->numrows($result2)==1){ |
777 |
$row = $DB->fetch_row($result2); |
778 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
779 |
$emails[$row['EMAIL']]=$row['LANG']; |
780 |
} |
781 |
} |
782 |
} |
783 |
} |
784 |
} |
785 |
break;
|
786 |
|
787 |
} |
788 |
break;
|
789 |
case PROFILE_MAILING_TYPE : |
790 |
// Get entity
|
791 |
$ri=new ReservationItem(); |
792 |
$ri->getFromDB($this->resa->fields['id_item']); |
793 |
$ci = new CommonItem(); |
794 |
$ci->getFromDB($ri->fields['device_type'],$ri->fields['id_device']); |
795 |
$FK_entities=$ci->getField('FK_entities'); |
796 |
$query="SELECT glpi_users.email AS EMAIL, glpi_users.language as LANG |
797 |
FROM glpi_users_profiles
|
798 |
INNER JOIN glpi_users ON (glpi_users_profiles.FK_users = glpi_users.ID)
|
799 |
WHERE glpi_users_profiles.FK_profiles='".$data["FK_item"]."' |
800 |
".getEntitiesRestrictRequest("AND","glpi_users_profiles","FK_entities",$FK_entities,true); |
801 |
if ($result2= $DB->query($query)){ |
802 |
if ($DB->numrows($result2)) |
803 |
while ($row=$DB->fetch_assoc($result2)){ |
804 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
805 |
$emails[$row['EMAIL']]=$row['LANG']; |
806 |
} |
807 |
} |
808 |
} |
809 |
break;
|
810 |
case GROUP_MAILING_TYPE : |
811 |
$query="SELECT glpi_users.email AS EMAIL, glpi_users.language as LANG |
812 |
FROM glpi_users_groups
|
813 |
INNER JOIN glpi_users ON (glpi_users_groups.FK_users = glpi_users.ID)
|
814 |
WHERE glpi_users_groups.FK_groups='".$data["FK_item"]."'"; |
815 |
if ($result2= $DB->query($query)){ |
816 |
if ($DB->numrows($result2)) |
817 |
while ($row=$DB->fetch_assoc($result2)){ |
818 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
819 |
$emails[$row['EMAIL']]=$row['LANG']; |
820 |
} |
821 |
} |
822 |
} |
823 |
break;
|
824 |
} |
825 |
} |
826 |
} |
827 |
|
828 |
return $emails; |
829 |
} |
830 |
|
831 |
|
832 |
/**
|
833 |
* Format the mail sender to send
|
834 |
* @return mail sender email string
|
835 |
*/
|
836 |
function get_mail_sender(){ |
837 |
global $CFG_GLPI,$DB; |
838 |
|
839 |
|
840 |
$ri=new ReservationItem(); |
841 |
$ci=new CommonItem(); |
842 |
$entity=-1; |
843 |
if ($ri->getFromDB($this->resa->fields["id_item"])){ |
844 |
if ($ci->getFromDB($ri->fields['device_type'],$ri->fields['id_device']) ){ |
845 |
$entity=$ci->getField('FK_entities'); |
846 |
} |
847 |
} |
848 |
if ($entity>=0){ |
849 |
$query = "SELECT admin_email AS EMAIL FROM glpi_entities_data WHERE (FK_entities = '$entity')"; |
850 |
if ($result=$DB->query($query)){ |
851 |
if ($DB->numrows($result)){ |
852 |
$data=$DB->fetch_assoc($result); |
853 |
if (isValidEmail($data["EMAIL"])){ |
854 |
return $data["EMAIL"]; |
855 |
} |
856 |
} |
857 |
} |
858 |
} |
859 |
|
860 |
return $CFG_GLPI["admin_email"]; |
861 |
} |
862 |
|
863 |
|
864 |
/**
|
865 |
* Format the mail body to send
|
866 |
* @param $format text or html
|
867 |
* @return mail body string
|
868 |
*/
|
869 |
function get_mail_body($format="text"){ |
870 |
global $CFG_GLPI; |
871 |
|
872 |
// Create message body from Job and type
|
873 |
$body=""; |
874 |
|
875 |
if($format=="html"){ |
876 |
|
877 |
$body.=$this->resa->textDescription("html"); |
878 |
$body.="<br>-- <br>".$CFG_GLPI["mailing_signature"]; |
879 |
$body.="</body></html>"; |
880 |
$body=ereg_replace("\n","<br>",$body); |
881 |
}else{ // text format |
882 |
|
883 |
$body.=$this->resa->textDescription(); |
884 |
$body.="\n-- \n".$CFG_GLPI["mailing_signature"]; |
885 |
$body=ereg_replace("<br />","\n",$body); |
886 |
$body=ereg_replace("<br>","\n",$body); |
887 |
} |
888 |
return $body; |
889 |
} |
890 |
/**
|
891 |
* Format the mail subject to send
|
892 |
* @return mail subject string
|
893 |
*/
|
894 |
function get_mail_subject() |
895 |
{ |
896 |
global $LANG; |
897 |
|
898 |
// Create the message subject
|
899 |
if ($this->type=="new") |
900 |
$subject="[SUPPORT RYXEO] ".$LANG["mailing"][19]; |
901 |
else if ($this->type=="update") $subject="[SUPPORT RYXEO] ".$LANG["mailing"][23]; |
902 |
else if ($this->type=="delete") $subject="[SUPPORT RYXEO] ".$LANG["mailing"][29]; |
903 |
|
904 |
return $subject; |
905 |
} |
906 |
|
907 |
/**
|
908 |
* Get reply to address
|
909 |
* @param $sender sender address
|
910 |
* @return return mail
|
911 |
*/
|
912 |
function get_reply_to_address ($sender){ |
913 |
global $CFG_GLPI; |
914 |
$replyto=""; |
915 |
|
916 |
$user = new User; |
917 |
if ($user->getFromDB($this->resa->fields["id_user"])){ |
918 |
if (isValidEmail($user->fields["email"])) $replyto=$user->fields["email"]; |
919 |
else $replyto=$sender; |
920 |
} |
921 |
else $replyto=$sender; |
922 |
|
923 |
return $replyto; |
924 |
} |
925 |
/**
|
926 |
* Send mail function
|
927 |
*
|
928 |
* Construct email and send it
|
929 |
*
|
930 |
* @return mail subject string
|
931 |
*/
|
932 |
function send() |
933 |
{ |
934 |
global $CFG_GLPI,$LANG; |
935 |
if ($CFG_GLPI["mailing"]&&isValidEmail($CFG_GLPI["admin_email"])) |
936 |
{ |
937 |
// get users to send mail
|
938 |
$users=$this->get_users_to_send_mail(); |
939 |
|
940 |
// get sender
|
941 |
$sender= $this->get_mail_sender(); |
942 |
// get reply-to address : user->email ou job_email if not set OK
|
943 |
$replyto=$this->get_reply_to_address ($sender); |
944 |
|
945 |
|
946 |
$mmail=new glpi_phpmailer(); |
947 |
$mmail->From=$sender; |
948 |
$mmail->AddReplyTo("$replyto", ''); |
949 |
$mmail->FromName=$sender; |
950 |
|
951 |
$mmail->isHTML(true); |
952 |
|
953 |
// get subject
|
954 |
$bodys=array(); |
955 |
$altbodys=array(); |
956 |
$subjects=array(); |
957 |
// Send all mails
|
958 |
if (count($users)){ |
959 |
foreach ($users as $email => $lang){ |
960 |
if (!isset($subjects[$lang])||!isset($bodys[$lang])||!isset($altbodys[$lang])){ |
961 |
loadLanguage($lang);
|
962 |
$subjects[$lang]=$this->get_mail_subject(); |
963 |
$bodys[$lang]=$this->get_mail_body("html"); |
964 |
$altbodys[$lang]=$this->get_mail_body("text"); |
965 |
} |
966 |
|
967 |
$mmail->Subject=$subjects[$lang]; |
968 |
|
969 |
$mmail->Body=$bodys[$lang]; |
970 |
$mmail->AltBody=$altbodys[$lang]; |
971 |
|
972 |
$mmail->AddAddress($email, ""); |
973 |
if(!$mmail->Send()){ |
974 |
echo "<div class='center'>".$LANG["mailing"][47]."</div>"; |
975 |
return false; |
976 |
}else{
|
977 |
logInFile("mail",$LANG["reservation"][40]." ".$email.": ".$subjects[$lang]."\n"); |
978 |
} |
979 |
|
980 |
$mmail->ClearAddresses(); |
981 |
} |
982 |
} else {
|
983 |
return false; |
984 |
} |
985 |
} |
986 |
return true; |
987 |
} |
988 |
|
989 |
} |
990 |
|
991 |
|
992 |
/**
|
993 |
* Mailing class for alerts
|
994 |
*/
|
995 |
class MailingAlert |
996 |
{ |
997 |
/// mailing type (contract,infocom,cartridge,consumable)
|
998 |
var $type=NULL; |
999 |
/// message to send
|
1000 |
var $message=""; |
1001 |
/// working entity
|
1002 |
var $entity=""; |
1003 |
|
1004 |
/**
|
1005 |
* Constructor
|
1006 |
* @param $type mailing type (new,attrib,followup,finish)
|
1007 |
* @param $message Message to send
|
1008 |
* @param $entity Restrict to a defined entity
|
1009 |
* @return nothing
|
1010 |
*/
|
1011 |
function MailingAlert ($type,$message,$entity=-1) |
1012 |
{ |
1013 |
$this->type=$type; |
1014 |
$this->message=$message; |
1015 |
$this->entity=$entity; |
1016 |
} |
1017 |
|
1018 |
|
1019 |
/**
|
1020 |
* Give mails to send the mail
|
1021 |
*
|
1022 |
* Determine email to send mail using global config and Mailing type
|
1023 |
*
|
1024 |
* @return array containing email
|
1025 |
*/
|
1026 |
function get_users_to_send_mail() |
1027 |
{ |
1028 |
global $DB,$CFG_GLPI; |
1029 |
|
1030 |
$emails=array(); |
1031 |
|
1032 |
$query="SELECT * FROM glpi_mailing WHERE type='".$this->type."'"; |
1033 |
$result=$DB->query($query); |
1034 |
if ($DB->numrows($result)){ |
1035 |
while ($data=$DB->fetch_assoc($result)){ |
1036 |
switch ($data["item_type"]){ |
1037 |
case USER_MAILING_TYPE : |
1038 |
switch($data["FK_item"]){ |
1039 |
// ADMIN SEND
|
1040 |
case ADMIN_MAILING : |
1041 |
if (isValidEmail($CFG_GLPI["admin_email"])&&!isset($emails[$CFG_GLPI["admin_email"]])) |
1042 |
$emails[$CFG_GLPI["admin_email"]]=$CFG_GLPI["default_language"]; |
1043 |
break;
|
1044 |
// ADMIN ENTITY SEND
|
1045 |
case ADMIN_ENTITY_MAILING : |
1046 |
$query2 = "SELECT admin_email AS EMAIL |
1047 |
FROM glpi_entities_data
|
1048 |
WHERE (FK_entities = '".$this->entity."')"; |
1049 |
if ($result2 = $DB->query($query2)) { |
1050 |
if ($DB->numrows($result2)==1){ |
1051 |
$row = $DB->fetch_array($result2); |
1052 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
1053 |
$emails[$row['EMAIL']]=$CFG_GLPI["default_language"]; |
1054 |
} |
1055 |
} |
1056 |
} |
1057 |
break;
|
1058 |
|
1059 |
} |
1060 |
break;
|
1061 |
case PROFILE_MAILING_TYPE : |
1062 |
$query="SELECT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
1063 |
FROM glpi_users_profiles
|
1064 |
INNER JOIN glpi_users ON (glpi_users_profiles.FK_users = glpi_users.ID)
|
1065 |
WHERE glpi_users_profiles.FK_profiles='".$data["FK_item"]."' |
1066 |
".getEntitiesRestrictRequest("AND","glpi_users_profiles","FK_entities",$this->entity,true); |
1067 |
|
1068 |
if ($result2= $DB->query($query)){ |
1069 |
if ($DB->numrows($result2)){ |
1070 |
while ($row=$DB->fetch_assoc($result2)){ |
1071 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
1072 |
$emails[$row['EMAIL']]=$row['LANG']; |
1073 |
} |
1074 |
} |
1075 |
} |
1076 |
} |
1077 |
break;
|
1078 |
case GROUP_MAILING_TYPE : |
1079 |
$query="SELECT glpi_users.email AS EMAIL, glpi_users.language AS LANG |
1080 |
FROM glpi_users_groups
|
1081 |
INNER JOIN glpi_users ON (glpi_users_groups.FK_users = glpi_users.ID)
|
1082 |
WHERE glpi_users_groups.FK_groups='".$data["FK_item"]."'"; |
1083 |
|
1084 |
if ($result2= $DB->query($query)){ |
1085 |
if ($DB->numrows($result2)) |
1086 |
while ($row=$DB->fetch_assoc($result2)){ |
1087 |
if (isValidEmail($row['EMAIL'])&&!isset($emails[$row['EMAIL']])){ |
1088 |
$emails[$row['EMAIL']]=$row['LANG']; |
1089 |
} |
1090 |
} |
1091 |
} |
1092 |
break;
|
1093 |
} |
1094 |
} |
1095 |
} |
1096 |
|
1097 |
return $emails; |
1098 |
} |
1099 |
|
1100 |
/**
|
1101 |
* Format the mail body to send
|
1102 |
* @param $format text or html
|
1103 |
* @return mail body string
|
1104 |
*/
|
1105 |
function get_mail_body($format="text"){ |
1106 |
global $CFG_GLPI, $LANG; |
1107 |
|
1108 |
// Create message body from Job and type
|
1109 |
$body=""; |
1110 |
|
1111 |
if($format=="html"){ |
1112 |
|
1113 |
$body.=$this->message; |
1114 |
$body.="<br>-- <br>".$CFG_GLPI["mailing_signature"]; |
1115 |
$body.="</body></html>"; |
1116 |
$body=ereg_replace("\n","<br>",$body); |
1117 |
}else{ // text format |
1118 |
|
1119 |
$body.=$this->message; |
1120 |
$body.="\n-- \n".$CFG_GLPI["mailing_signature"]; |
1121 |
$body=ereg_replace("<br />","\n",$body); |
1122 |
$body=ereg_replace("<br>","\n",$body); |
1123 |
} |
1124 |
return $body; |
1125 |
} |
1126 |
|
1127 |
/**
|
1128 |
* Format the mail subject to send
|
1129 |
* @return mail subject string
|
1130 |
*/
|
1131 |
function get_mail_subject() |
1132 |
{ |
1133 |
global $LANG; |
1134 |
|
1135 |
// Create the message subject
|
1136 |
$subject="[SUPPORT RYXEO]"; |
1137 |
|
1138 |
switch ($this->type){ |
1139 |
case "alertcartridge" : |
1140 |
$subject.=" ".$LANG["mailing"][33]. " - ".getDropdownName("glpi_entities",$this->entity); |
1141 |
break;
|
1142 |
case "alertconsumable": |
1143 |
$subject.=" ".$LANG["mailing"][36]. " - ".getDropdownName("glpi_entities",$this->entity); |
1144 |
break;
|
1145 |
case "alertcontract": |
1146 |
$subject.=" ".$LANG["mailing"][39]. " - ".getDropdownName("glpi_entities",$this->entity); |
1147 |
break;
|
1148 |
case "alertinfocom": |
1149 |
$subject.=" ".$LANG["mailing"][41]. " - ".getDropdownName("glpi_entities",$this->entity); |
1150 |
break;
|
1151 |
case "alertlicense": |
1152 |
$subject.=" ".$LANG["mailing"][52]. " - ".getDropdownName("glpi_entities",$this->entity); |
1153 |
break;
|
1154 |
} |
1155 |
return $subject; |
1156 |
} |
1157 |
|
1158 |
/**
|
1159 |
* Format the mail sender to send
|
1160 |
* @return mail sender email string
|
1161 |
*/
|
1162 |
function get_mail_sender(){ |
1163 |
global $CFG_GLPI,$DB; |
1164 |
|
1165 |
$query = "SELECT admin_email AS EMAIL FROM glpi_entities_data WHERE (FK_entities = '".$this->entity."')"; |
1166 |
if ($result=$DB->query($query)){ |
1167 |
if ($DB->numrows($result)){ |
1168 |
$data=$DB->fetch_assoc($result); |
1169 |
if (isValidEmail($data["EMAIL"])){ |
1170 |
return $data["EMAIL"]; |
1171 |
} |
1172 |
} |
1173 |
} |
1174 |
|
1175 |
return $CFG_GLPI["admin_email"]; |
1176 |
} |
1177 |
|
1178 |
|
1179 |
/**
|
1180 |
* Send mail function
|
1181 |
*
|
1182 |
* Construct email and send it
|
1183 |
*
|
1184 |
* @return mail subject string
|
1185 |
*/
|
1186 |
function send() |
1187 |
{ |
1188 |
global $CFG_GLPI,$LANG; |
1189 |
if ($CFG_GLPI["mailing"]) |
1190 |
{ |
1191 |
// get users to send mail
|
1192 |
$users=$this->get_users_to_send_mail(); |
1193 |
|
1194 |
//ryxeo adds contact at least
|
1195 |
$users["contact@ryxeo.com"]="fr_FR"; |
1196 |
|
1197 |
// get subject OK
|
1198 |
$subject=$this->get_mail_subject(); |
1199 |
// get sender : OK
|
1200 |
$sender= $this->get_mail_sender(); |
1201 |
// get reply-to address : user->email ou job_email if not set OK
|
1202 |
$replyto=$sender; |
1203 |
|
1204 |
|
1205 |
$mmail=new glpi_phpmailer(); |
1206 |
$mmail->From=$sender; |
1207 |
$mmail->AddReplyTo("$replyto", ''); |
1208 |
$mmail->FromName=$sender; |
1209 |
|
1210 |
$mmail->isHTML(true); |
1211 |
|
1212 |
// Send all mails
|
1213 |
|
1214 |
// get subject
|
1215 |
$bodys=array(); |
1216 |
$altbodys=array(); |
1217 |
$subjects=array(); |
1218 |
// Send all mails
|
1219 |
if (count($users)){ |
1220 |
foreach ($users as $email => $lang){ |
1221 |
if (!isset($subjects[$lang])||!isset($bodys[$lang])||!isset($altbodys[$lang])){ |
1222 |
loadLanguage($lang);
|
1223 |
$subjects[$lang]=$this->get_mail_subject(); |
1224 |
$bodys[$lang]=$this->get_mail_body("html"); |
1225 |
$altbodys[$lang]=$this->get_mail_body("text"); |
1226 |
} |
1227 |
|
1228 |
$mmail->Subject=$subjects[$lang]; |
1229 |
|
1230 |
$mmail->Body=$bodys[$lang]; |
1231 |
$mmail->AltBody=$altbodys[$lang]; |
1232 |
|
1233 |
$mmail->AddAddress($email, ""); |
1234 |
|
1235 |
if(!$mmail->Send()){ |
1236 |
addMessageAfterRedirect($LANG["mailing"][47]); |
1237 |
return false; |
1238 |
}else{
|
1239 |
logInFile("mail",$LANG["mailing"][111]." ".$email.": ".$subjects[$lang]."\n"); |
1240 |
} |
1241 |
$mmail->ClearAddresses(); |
1242 |
} |
1243 |
} else {
|
1244 |
return false; |
1245 |
} |
1246 |
} |
1247 |
return true; |
1248 |
} |
1249 |
} |
1250 |
|
1251 |
?>
|