1 | <?php |
||
2 | /* |
||
3 | * Copyright (C) 2014-2016 Jean-François Ferry <[email protected]> |
||
4 | * 2016 Christophe Battarel <[email protected]> |
||
5 | * |
||
6 | * This program is free software; you can redistribute it and/or modify |
||
7 | * it under the terms of the GNU General Public License as published by |
||
8 | * the Free Software Foundation; either version 3 of the License, or |
||
9 | * (at your option) any later version. |
||
10 | * |
||
11 | * This program is distributed in the hope that it will be useful, |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | * GNU General Public License for more details. |
||
15 | * |
||
16 | * You should have received a copy of the GNU General Public License |
||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * \file htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php |
||
22 | * \ingroup core |
||
23 | * \brief File of trigger for ticket module |
||
24 | */ |
||
25 | require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Class of triggers for ticket module |
||
30 | */ |
||
31 | class InterfaceTicketEmail extends DolibarrTriggers |
||
32 | { |
||
33 | /** |
||
34 | * @var DoliDB Database handler. |
||
35 | */ |
||
36 | public $db; |
||
37 | |||
38 | /** |
||
39 | * Constructor |
||
40 | * |
||
41 | * @param DoliDB $db Database handler |
||
42 | */ |
||
43 | public function __construct($db) |
||
44 | { |
||
45 | $this->db = $db; |
||
46 | |||
47 | $this->name = preg_replace('/^Interface/i', '', get_class($this)); |
||
48 | $this->family = "ticket"; |
||
49 | $this->description = "Triggers of the module ticket"; |
||
50 | $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version |
||
51 | $this->picto = 'ticket'; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Return name of trigger file |
||
56 | * |
||
57 | * @return string Name of trigger file |
||
58 | */ |
||
59 | public function getName() |
||
60 | { |
||
61 | return $this->name; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Return description of trigger file |
||
66 | * |
||
67 | * @return string Description of trigger file |
||
68 | */ |
||
69 | public function getDesc() |
||
70 | { |
||
71 | return $this->description; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Return version of trigger file |
||
76 | * |
||
77 | * @return string Version of trigger file |
||
78 | */ |
||
79 | public function getVersion() |
||
80 | { |
||
81 | global $langs; |
||
82 | $langs->load("admin"); |
||
83 | |||
84 | if ($this->version == 'development') { |
||
85 | return $langs->trans("Development"); |
||
86 | } elseif ($this->version == 'experimental') { |
||
87 | return $langs->trans("Experimental"); |
||
88 | } elseif ($this->version == 'dolibarr') { |
||
89 | return DOL_VERSION; |
||
90 | } elseif ($this->version) { |
||
91 | return $this->version; |
||
92 | } else { |
||
93 | return $langs->trans("Unknown"); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Function called when a Dolibarrr business event is done. |
||
99 | * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers |
||
100 | * |
||
101 | * @param string $action Event action code |
||
102 | * @param Object $object Object |
||
103 | * @param User $user Object user |
||
104 | * @param Translate $langs Object langs |
||
105 | * @param conf $conf Object conf |
||
106 | * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
||
107 | */ |
||
108 | public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
||
109 | { |
||
110 | $ok = 0; |
||
111 | |||
112 | switch ($action) { |
||
113 | case 'TICKET_ASSIGNED': |
||
114 | dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
||
115 | |||
116 | if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) |
||
117 | { |
||
118 | $userstat = new User($this->db); |
||
119 | $res = $userstat->fetch($object->fk_user_assign); |
||
120 | if ($res > 0) |
||
121 | { |
||
122 | if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) |
||
123 | { |
||
124 | // Init to avoid errors |
||
125 | $filepath = array(); |
||
126 | $filename = array(); |
||
127 | $mimetype = array(); |
||
128 | |||
129 | // Send email to assigned user |
||
130 | $subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketAssignedToYou'); |
||
131 | $message = '<p>' . $langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname)) . "</p>"; |
||
132 | $message .= '<ul><li>' . $langs->trans('Title') . ' : ' . $object->subject . '</li>'; |
||
133 | $message .= '<li>' . $langs->trans('Type') . ' : ' . $object->type_label . '</li>'; |
||
134 | $message .= '<li>' . $langs->trans('Category') . ' : ' . $object->category_label . '</li>'; |
||
135 | $message .= '<li>' . $langs->trans('Severity') . ' : ' . $object->severity_label . '</li>'; |
||
136 | // Extrafields |
||
137 | if (is_array($object->array_options) && count($object->array_options) > 0) { |
||
138 | foreach ($object->array_options as $key => $value) { |
||
139 | $message .= '<li>' . $langs->trans($key) . ' : ' . $value . '</li>'; |
||
140 | } |
||
141 | } |
||
142 | |||
143 | $message .= '</ul>'; |
||
144 | $message .= '<p>' . $langs->trans('Message') . ' : <br>' . $object->message . '</p>'; |
||
145 | $message .= '<p><a href="' . dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id . '">' . $langs->trans('SeeThisTicketIntomanagementInterface') . '</a></p>'; |
||
146 | |||
147 | $sendto = $userstat->email; |
||
148 | $from = dolGetFirstLastname($user->firstname, $user->lastname) . '<' . $user->email . '>'; |
||
149 | |||
150 | $message = dol_nl2br($message); |
||
151 | |||
152 | if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
||
153 | $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
||
154 | $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
||
155 | } |
||
156 | include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; |
||
157 | $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); |
||
158 | if ($mailfile->error) { |
||
159 | setEventMessages($mailfile->error, $mailfile->errors, 'errors'); |
||
160 | } else { |
||
161 | $result = $mailfile->sendfile(); |
||
162 | } |
||
163 | if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
||
164 | $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
||
165 | } |
||
166 | } |
||
167 | |||
168 | $ok = 1; |
||
169 | } |
||
170 | else |
||
171 | { |
||
172 | $this->error = $userstat->error; |
||
0 ignored issues
–
show
|
|||
173 | $this->errors = $userstat->errors; |
||
174 | } |
||
175 | } |
||
176 | break; |
||
177 | |||
178 | case 'TICKET_CREATE': |
||
179 | dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
||
180 | |||
181 | $langs->load('ticket'); |
||
182 | |||
183 | $object->fetch('', $object->track_id); // Should be useless |
||
184 | |||
185 | |||
186 | // Send email to notification email |
||
187 | |||
188 | if (empty($conf->global->TICKET_DISABLE_ALL_MAILS) && empty($object->context['disableticketemail'])) |
||
189 | { |
||
190 | $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; |
||
191 | |||
192 | if ($sendto) |
||
193 | { |
||
194 | // Init to avoid errors |
||
195 | $filepath = array(); |
||
196 | $filename = array(); |
||
197 | $mimetype = array(); |
||
198 | |||
199 | /* Send email to admin */ |
||
200 | $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); |
||
201 | $message_admin= $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n"; |
||
202 | $message_admin.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; |
||
203 | $message_admin.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>'; |
||
204 | $message_admin.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>'; |
||
205 | $message_admin.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>'; |
||
206 | $message_admin.='<li>'.$langs->trans('From').' : '.( $object->email_from ? $object->email_from : ( $object->fk_user_create > 0 ? $langs->trans('Internal') : '') ).'</li>'; |
||
207 | // Extrafields |
||
208 | if (is_array($object->array_options) && count($object->array_options) > 0) { |
||
209 | foreach ($object->array_options as $key => $value) { |
||
210 | $message_admin.='<li>'.$langs->trans($key).' : '.$value.'</li>'; |
||
211 | } |
||
212 | } |
||
213 | $message_admin.='</ul>'; |
||
214 | |||
215 | if ($object->fk_soc > 0) { |
||
216 | $object->fetch_thirdparty(); |
||
217 | $message_admin.='<p>'.$langs->trans('Company'). ' : '.$object->thirdparty->name.'</p>'; |
||
218 | } |
||
219 | |||
220 | $message_admin.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>'; |
||
221 | $message_admin.='<p><a href="'.dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id.'">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>'; |
||
222 | |||
223 | $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; |
||
224 | $replyto = $from; |
||
225 | |||
226 | $message_admin = dol_nl2br($message_admin); |
||
227 | |||
228 | if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
||
229 | $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
||
230 | $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
||
231 | } |
||
232 | include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
||
233 | $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||
234 | if ($mailfile->error) { |
||
235 | dol_syslog($mailfile->error, LOG_DEBUG); |
||
236 | } else { |
||
237 | $result=$mailfile->sendfile(); |
||
238 | } |
||
239 | if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
||
240 | $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
||
241 | } |
||
242 | } |
||
243 | } |
||
244 | |||
245 | // Send email to customer |
||
246 | |||
247 | if (empty($conf->global->TICKET_DISABLE_ALL_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) |
||
248 | { |
||
249 | $sendto = ''; |
||
250 | if (empty($user->socid) && empty($user->email)) { |
||
251 | $object->fetch_thirdparty(); |
||
252 | $sendto = $object->thirdparty->email; |
||
253 | } else { |
||
254 | $sendto = $user->email; |
||
255 | } |
||
256 | |||
257 | if ($sendto) { |
||
258 | // Init to avoid errors |
||
259 | $filepath = array(); |
||
260 | $filename = array(); |
||
261 | $mimetype = array(); |
||
262 | |||
263 | $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer'); |
||
264 | $message_customer= $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id)."\n\n"; |
||
265 | $message_customer.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; |
||
266 | $message_customer.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>'; |
||
267 | $message_customer.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>'; |
||
268 | $message_customer.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>'; |
||
269 | |||
270 | // Extrafields |
||
271 | foreach ($this->attributes[$object->table_element]['label'] as $key => $value) |
||
272 | { |
||
273 | $enabled = 1; |
||
274 | if ($enabled && isset($this->attributes[$object->table_element]['list'][$key])) |
||
0 ignored issues
–
show
|
|||
275 | { |
||
276 | $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1); |
||
277 | } |
||
278 | $perms = 1; |
||
279 | if ($perms && isset($this->attributes[$object->table_element]['perms'][$key])) |
||
280 | { |
||
281 | $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); |
||
282 | } |
||
283 | |||
284 | $qualified = true; |
||
285 | if (empty($enabled)) $qualified = false; |
||
286 | if (empty($perms)) $qualified = false; |
||
287 | |||
288 | if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>'; |
||
289 | } |
||
290 | |||
291 | $message_customer.='</ul>'; |
||
292 | $message_customer.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>'; |
||
293 | $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE?$conf->global->TICKET_URL_PUBLIC_INTERFACE.'/':dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$object->track_id; |
||
294 | $message_customer.='<p>' . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>'; |
||
295 | $message_customer.='<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</p>'; |
||
296 | |||
297 | $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; |
||
298 | $replyto = $from; |
||
299 | |||
300 | $message_customer = dol_nl2br($message_customer); |
||
301 | |||
302 | if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
||
303 | $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
||
304 | $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
||
305 | } |
||
306 | include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
||
307 | $mailfile = new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); |
||
308 | if ($mailfile->error) { |
||
309 | dol_syslog($mailfile->error, LOG_DEBUG); |
||
310 | } else { |
||
311 | $result=$mailfile->sendfile(); |
||
312 | } |
||
313 | if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
||
314 | $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
||
315 | } |
||
316 | } |
||
317 | } |
||
318 | $ok = 1; |
||
319 | break; |
||
320 | |||
321 | case 'TICKET_DELETE': |
||
322 | dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
||
323 | break; |
||
324 | |||
325 | case 'TICKET_MODIFY': |
||
326 | dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
||
327 | break; |
||
328 | |||
329 | case 'TICKET_MARK_READ': |
||
330 | dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
||
331 | break; |
||
332 | |||
333 | case 'TICKET_CLOSE': |
||
334 | dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
||
335 | break; |
||
336 | } |
||
337 | |||
338 | |||
339 | return $ok; |
||
340 | } |
||
341 | } |
||
342 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.