dolibarr 22.0.5
advtargetemailing.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
3 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmailing.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/advthirdparties.modules.php';
35require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/advtargetemailing.class.php';
36require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/html.formadvtargetemailing.class.php';
37require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
38require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41
50// Load translation files required by the page
51$langs->loadLangs(array('mails', 'admin', 'companies', 'categories'));
52
53$action = GETPOST('action', 'aZ09');
54$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
55
56// Load variable for pagination
57$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
58$sortfield = GETPOST('sortfield', 'aZ09comma');
59$sortorder = GETPOST('sortorder', 'aZ09comma');
60$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
61if (empty($page) || $page == -1) {
62 $page = 0;
63} // If $page is not defined, or '' or -1
64$offset = $limit * $page;
65$pageprev = $page - 1;
66$pagenext = $page + 1;
67if (!$sortorder) {
68 $sortorder = "ASC";
69}
70if (!$sortfield) {
71 $sortfield = "email";
72}
73
74$id = GETPOSTINT('id');
75$rowid = GETPOSTINT('rowid');
76$search_nom = GETPOST("search_nom");
77$search_prenom = GETPOST("search_prenom");
78$search_email = GETPOST("search_email");
79$template_id = GETPOSTINT('template_id');
80
81// Do we click on purge search criteria ?
82if (GETPOST('button_removefilter_x', 'alpha')) {
83 $search_nom = '';
84 $search_prenom = '';
85 $search_email = '';
86}
87$array_query = array();
88'@phan-var-force array<string,int|string|string[]> $array_query';
89
90$object = new Mailing($db);
91$result = $object->fetch($id);
92
93$advTarget = new AdvanceTargetingMailing($db);
94
95if ($template_id <= 0) {
96 $advTarget->fk_element = $id;
97 $advTarget->type_element = 'mailing';
98 $result = $advTarget->fetch_by_mailing();
99} else {
100 $result = $advTarget->fetch($template_id);
101}
102
103if ($result < 0) {
104 setEventMessages($advTarget->error, $advTarget->errors, 'errors');
105} else {
106 if (!empty($advTarget->id)) {
107 $array_query = json_decode($advTarget->filtervalue, true);
108 }
109}
110
111// List of sending methods
112$listofmethods = array();
113//$listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
114$listofmethods['mail'] = 'PHP mail function';
115//$listofmethods['simplemail']='Simplemail class';
116$listofmethods['smtps'] = 'SMTP/SMTPS socket library';
117if (version_compare(phpversion(), '7.0', '>=')) {
118 $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
119}
120
121// Security check
122if (!$user->hasRight('mailing', 'lire') || (!getDolGlobalString('EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
124}
125if (empty($action) && empty($object->id)) {
126 accessforbidden('Object not found');
127}
128
129$permissiontoread = $user->hasRight('mailing', 'lire');
130$permissiontoadd = $user->hasRight('mailing', 'creer');
131$permissiontovalidatesend = $user->hasRight('mailing', 'valider');
132$permissiontodelete = $user->hasRight('mailing', 'supprimer');
133
134
135/*
136 * Actions
137 */
138
139if ($action == 'loadfilter' && $permissiontoread) {
140 if (!empty($template_id)) {
141 $result = $advTarget->fetch($template_id);
142 if ($result < 0) {
143 setEventMessages($advTarget->error, $advTarget->errors, 'errors');
144 } else {
145 if (!empty($advTarget->id)) {
146 $array_query = json_decode($advTarget->filtervalue, true);
147 }
148 }
149 }
150}
151
152if ($action == 'add' && $permissiontoadd) { // Add recipients
153 $user_contact_query = false;
154
155 $array_query = array();
156
157 // Get extra fields
158
159 foreach ($_POST as $key => $value) {
160 // print '$key='.$key.' $value='.$value.'<BR>';
161 if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
162 // Special case for start date come with 3 inputs day, month, year
163 if (preg_match("/st_dt/", $key)) {
164 $dtarr = array();
165 $dtarr = explode('_', $key);
166 if (!array_key_exists('options_'.$dtarr[1].'_st_dt', $array_query)) {
167 $array_query['options_'.$dtarr[1].'_st_dt'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_st_dtmonth'), GETPOSTINT('options_'.$dtarr[1].'_st_dtday'), GETPOSTINT('options_'.$dtarr[1].'_st_dtyear'));
168 }
169 } elseif (preg_match("/end_dt/", $key)) {
170 // Special case for end date come with 3 inputs day, month, year
171 $dtarr = array();
172 $dtarr = explode('_', $key);
173 if (!array_key_exists('options_'.$dtarr[1].'_end_dt', $array_query)) {
174 $array_query['options_'.$dtarr[1].'_end_dt'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_end_dtmonth'), GETPOSTINT('options_'.$dtarr[1].'_end_dtday'), GETPOSTINT('options_'.$dtarr[1].'_end_dtyear'));
175 }
176 } else {
177 $array_query[$key] = GETPOST($key);
178 }
179 }
180 if (preg_match("/^options_.*_cnct/", $key)) {
181 $user_contact_query = true;
182 // Special case for start date come with 3 inputs day, month, year
183 if (preg_match("/st_dt/", $key)) {
184 $dtarr = array();
185 $dtarr = explode('_', $key);
186 if (!array_key_exists('options_'.$dtarr[1].'_st_dt_cnct', $array_query)) {
187 $array_query['options_'.$dtarr[1].'_st_dt_cnct'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_st_dtmonth_cnct'), GETPOSTINT('options_'.$dtarr[1].'_st_dtday_cnct'), GETPOSTINT('options_'.$dtarr[1].'_st_dtyear_cnct'));
188 }
189 } elseif (preg_match("/end_dt/", $key)) {
190 // Special case for end date come with 3 inputs day, month, year
191 $dtarr = array();
192 $dtarr = explode('_', $key);
193 if (!array_key_exists('options_'.$dtarr[1].'_end_dt_cnct', $array_query)) {
194 $array_query['options_'.$dtarr[1].'_end_dt_cnct'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_end_dtmonth_cnct'), GETPOSTINT('options_'.$dtarr[1].'_end_dtday_cnct'), GETPOSTINT('options_'.$dtarr[1].'_end_dtyear_cnct'));
195 }
196 } else {
197 $array_query[$key] = GETPOST($key);
198 }
199 }
200
201 if (preg_match("/^cust_/", $key)) {
202 $array_query[$key] = GETPOST($key);
203 }
204
205 if (preg_match("/^contact_/", $key)) {
206 $array_query[$key] = GETPOST($key);
207
208 $specials_date_key = array(
209 'contact_update_st_dt',
210 'contact_update_end_dt',
211 'contact_create_st_dt',
212 'contact_create_end_dt'
213 );
214 foreach ($specials_date_key as $date_key) {
215 if ($key == $date_key) {
216 $dt = GETPOST($date_key);
217 if (!empty($dt)) {
218 $array_query[$key] = dol_mktime(0, 0, 0, GETPOSTINT($date_key.'month'), GETPOSTINT($date_key.'day'), GETPOSTINT($date_key.'year'));
219 } else {
220 $array_query[$key] = '';
221 }
222 }
223 }
224
225 if (!empty($array_query[$key])) {
226 $user_contact_query = true;
227 }
228 }
229
230 if ($array_query['type_of_target'] == 2 || $array_query['type_of_target'] == 4) {
231 $user_contact_query = true;
232 }
233
234 if (preg_match("/^type_of_target/", $key)) {
235 $array_query[$key] = GETPOST($key);
236 }
237 }
238
239 // if ($array_query ['type_of_target'] == 1 || $array_query ['type_of_target'] == 3) {
240 $result = $advTarget->query_thirdparty($array_query);
241 if ($result < 0) {
242 setEventMessages($advTarget->error, $advTarget->errors, 'errors');
243 }
244 /*} else {
245 $advTarget->thirdparty_lines = array ();
246 }*/
247
248 if ($user_contact_query && ($array_query['type_of_target'] == 1 || $array_query['type_of_target'] == 2 || $array_query['type_of_target'] == 4)) {
249 $result = $advTarget->query_contact($array_query, 1);
250 if ($result < 0) {
251 setEventMessages($advTarget->error, $advTarget->errors, 'errors');
252 }
253 // If use contact but no result use artefact to so not use socid into add_to_target
254 if (count($advTarget->contact_lines) == 0) {
255 $advTarget->contact_lines = array(
256 0
257 );
258 }
259 } else {
260 $advTarget->contact_lines = array();
261 }
262
263 $mailingadvthirdparties = null;
264 if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
265 // Add targets into database
266 $mailingadvthirdparties = new mailing_advthirdparties($db);
267 $result = $mailingadvthirdparties->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query['type_of_target'], $advTarget->contact_lines);
268 } else {
269 $result = 0;
270 }
271
272 if ($result > 0) {
273 $query_temlate_id = '';
274 if (!empty($template_id)) {
275 $query_temlate_id = '&template_id='.$template_id;
276 }
277 setEventMessages($langs->trans("XTargetsAdded", $result), null, 'mesgs');
278 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id.$query_temlate_id);
279 exit();
280 }
281 if ($result == 0) {
282 setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings');
283 }
284 if ($result < 0 && is_object($mailingadvthirdparties)) {
285 setEventMessages($mailingadvthirdparties->error, $mailingadvthirdparties->errors, 'errors');
286 }
287}
288
289if ($action == 'clear' && $permissiontoadd) {
290 $mailingtargets = new MailingTargets($db);
291 $mailingtargets->clear_target($id);
292
293 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
294 exit();
295}
296
297if (($action == 'savefilter' || $action == 'createfilter') && $permissiontoadd) {
298 $template_name = GETPOST('template_name');
299 $error = 0;
300
301 if ($action == 'createfilter' && empty($template_name) && $permissiontoadd) {
302 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('AdvTgtOrCreateNewFilter')), null, 'errors');
303 $error++;
304 }
305
306 if (empty($error)) {
307 $array_query = array();
308
309 // Get extra fields
310 foreach ($_POST as $key => $value) {
311 if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
312 // Special case for start date come with 3 inputs day, month, year
313 if (preg_match("/st_dt/", $key)) {
314 $dtarr = array();
315 $dtarr = explode('_', $key);
316 if (!array_key_exists('options_'.$dtarr[1].'_st_dt', $array_query)) {
317 $array_query['options_'.$dtarr[1].'_st_dt'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_st_dtmonth'), GETPOSTINT('options_'.$dtarr[1].'_st_dtday'), GETPOSTINT('options_'.$dtarr[1].'_st_dtyear'));
318 }
319 } elseif (preg_match("/end_dt/", $key)) {
320 // Special case for end date come with 3 inputs day, month, year
321 $dtarr = array();
322 $dtarr = explode('_', $key);
323 if (!array_key_exists('options_'.$dtarr[1].'_end_dt', $array_query)) {
324 $array_query['options_'.$dtarr[1].'_end_dt'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_end_dtmonth'), GETPOSTINT('options_'.$dtarr[1].'_end_dtday'), GETPOSTINT('options_'.$dtarr[1].'_end_dtyear'));
325 // print $array_query['options_'.$dtarr[1].'_end_dt'];
326 // 01/02/1013=1361228400
327 }
328 } else {
329 $array_query[$key] = GETPOST($key);
330 }
331 }
332 if (preg_match("/^options_.*_cnct/", $key)) {
333 // Special case for start date come with 3 inputs day, month, year
334 if (preg_match("/st_dt/", $key)) {
335 $dtarr = array();
336 $dtarr = explode('_', $key);
337 if (!array_key_exists('options_'.$dtarr[1].'_st_dt_cnct', $array_query)) {
338 $array_query['options_'.$dtarr[1].'_st_dt_cnct'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_st_dtmonth_cnct'), GETPOSTINT('options_'.$dtarr[1].'_st_dtday_cnct'), GETPOSTINT('options_'.$dtarr[1].'_st_dtyear_cnct'));
339 }
340 } elseif (preg_match("/end_dt/", $key)) {
341 // Special case for end date come with 3 inputs day, month, year
342 $dtarr = array();
343 $dtarr = explode('_', $key);
344 if (!array_key_exists('options_'.$dtarr[1].'_end_dt_cnct', $array_query)) {
345 $array_query['options_'.$dtarr[1].'_end_dt_cnct'] = dol_mktime(0, 0, 0, GETPOSTINT('options_'.$dtarr[1].'_end_dtmonth_cnct'), GETPOSTINT('options_'.$dtarr[1].'_end_dtday_cnct'), GETPOSTINT('options_'.$dtarr[1].'_end_dtyear_cnct'));
346 // print $array_query['cnct_options_'.$dtarr[1].'_end_dt'];
347 // 01/02/1013=1361228400
348 }
349 } else {
350 $array_query[$key] = GETPOST($key);
351 }
352 }
353
354 if (preg_match("/^cust_/", $key)) {
355 $array_query[$key] = GETPOST($key);
356 }
357
358 if (preg_match("/^contact_/", $key)) {
359 $array_query[$key] = GETPOST($key);
360
361 $specials_date_key = array(
362 'contact_update_st_dt',
363 'contact_update_end_dt',
364 'contact_create_st_dt',
365 'contact_create_end_dt'
366 );
367 foreach ($specials_date_key as $date_key) {
368 if ($key == $date_key) {
369 $dt = GETPOST($date_key);
370 if (!empty($dt)) {
371 $array_query[$key] = dol_mktime(0, 0, 0, GETPOSTINT($date_key.'month'), GETPOSTINT($date_key.'day'), GETPOSTINT($date_key.'year'));
372 } else {
373 $array_query[$key] = '';
374 }
375 }
376 }
377 }
378
379 if (preg_match("/^type_of_target/", $key)) {
380 $array_query[$key] = GETPOST($key);
381 }
382 }
383 $advTarget->filtervalue = json_encode($array_query);
384
385 if ($action == 'createfilter') { // Test on permission already done
386 $advTarget->name = $template_name;
387 $result = $advTarget->create($user);
388 if ($result < 0) {
389 setEventMessages($advTarget->error, $advTarget->errors, 'errors');
390 }
391 } elseif ($action == 'savefilter') { // Test on permission already done
392 $result = $advTarget->update($user);
393 if ($result < 0) {
394 setEventMessages($advTarget->error, $advTarget->errors, 'errors');
395 }
396 }
397 $template_id = $advTarget->id;
398 }
399}
400
401if ($action == 'deletefilter' && $permissiontoadd) {
402 $result = $advTarget->delete($user);
403 if ($result < 0) {
404 setEventMessages($advTarget->error, $advTarget->errors, 'errors');
405 }
406 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
407 exit();
408}
409
410if ($action == 'delete' && $permissiontoadd) {
411 // Ici, rowid indique le destinataire et id le mailing
412 $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid = ".((int) $rowid);
413 $sql .= " AND fk_mailing = ".((int) $object->id);
414 $resql = $db->query($sql);
415 if ($resql) {
416 if (!empty($id)) {
417 $mailingtargets = new MailingTargets($db);
418 $mailingtargets->update_nb($id);
419
420 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
421 exit();
422 } else {
423 header("Location: liste.php");
424 exit();
425 }
426 } else {
427 dol_print_error($db);
428 }
429}
430
431if (GETPOST("button_removefilter")) {
432 $search_nom = '';
433 $search_prenom = '';
434 $search_email = '';
435}
436
437
438/*
439 * View
440 */
441
442$form = new Form($db);
443$formmailing = new FormMailing($db);
444$formadvtargetemaling = new FormAdvTargetEmailing($db);
445$formcompany = new FormCompany($db);
446$formother = new FormOther($db);
447
448$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
449llxHeader('', $langs->trans("MailAdvTargetRecipients"), $help_url);
450
451$arrayofselected = is_array($toselect) ? $toselect : array();
452$totalarray = [
453 'nbfield' => 0,
454];
455
456if ($object->fetch($id) >= 0) {
457 $head = emailing_prepare_head($object);
458
459 print dol_get_fiche_head($head, 'advtargets', $langs->trans("Mailing"), -1, 'email');
460
461 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
462
463 $morehtmlref = '<div class="refidno">';
464 // Ref customer
465 $morehtmlref .= $form->editfieldkey("", 'title', $object->title, $object, 0, 'string', '', 0, 1);
466 $morehtmlref .= $form->editfieldval("", 'title', $object->title, $object, 0, 'string', '', null, null, '', 1);
467 $morehtmlref .= '</div>';
468
469 $morehtmlstatus = '';
470 $nbtry = $nbok = 0;
471 if ($object->status == $object::STATUS_SENTPARTIALY || $object->status == $object::STATUS_SENTCOMPLETELY) {
472 $nbtry = $object->countNbOfTargets('alreadysent');
473 $nbko = $object->countNbOfTargets('alreadysentko');
474 $nbok = ($nbtry - $nbko);
475
476 $morehtmlstatus .= ' ('.$nbtry.'/'.$object->nbemail;
477 if ($nbko) {
478 $morehtmlstatus .= ' - '.$nbko.' '.$langs->trans("Error");
479 }
480 $morehtmlstatus .= ') &nbsp; ';
481 }
482
483 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
484
485 print '<div class="fichecenter">';
486 print '<div class="fichehalfleft">';
487 print '<div class="underbanner clearboth"></div>';
488
489 print '<table class="border centpercent tableforfield">'."\n";
490
491 // From
492 print '<tr><td class="titlefield">';
493 print $langs->trans("MailFrom").'</td><td>';
494 $emailarray = CMailFile::getArrayAddress($object->email_from);
495 foreach ($emailarray as $email => $name) {
496 if ($name && $name != $email) {
497 print dol_escape_htmltag($name).' &lt;'.$email;
498 print '&gt;';
499 if (!isValidEmail($email)) {
500 $langs->load("errors");
501 print img_warning($langs->trans("ErrorBadEMail", $email));
502 }
503 } else {
504 print dol_print_email($object->email_from, 0, 0, 0, 0, 1);
505 }
506 }
507
508 print '</td></tr>';
509
510 // Errors to
511 if ($object->messtype != 'sms') {
512 print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
513 $emailarray = CMailFile::getArrayAddress($object->email_errorsto);
514 foreach ($emailarray as $email => $name) {
515 if ($name != $email) {
516 print dol_escape_htmltag((string) $name).' &lt;'.$email;
517 print '&gt;';
518 if ($email && !isValidEmail($email)) {
519 $langs->load("errors");
520 print img_warning($langs->trans("ErrorBadEMail", $email));
521 } elseif ($email && !isValidMailDomain($email)) {
522 $langs->load("errors");
523 print img_warning($langs->trans("ErrorBadMXDomain", $email));
524 }
525 } else {
526 print dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
527 }
528 }
529 print '</td></tr>';
530 }
531
532 // Reply to
533 if ($object->messtype != 'sms') {
534 print '<tr><td>';
535 print $form->editfieldkey("MailReply", 'email_replyto', $object->email_replyto, $object, (int) ($user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY), 'string');
536 print '</td><td>';
537 print $form->editfieldval("MailReply", 'email_replyto', $object->email_replyto, $object, $user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY, 'string');
538 $email = CMailFile::getValidAddress($object->email_replyto, 2);
539 if ($action != 'editemail_replyto') {
540 if ($email && !isValidEmail($email)) {
541 $langs->load("errors");
542 print img_warning($langs->trans("ErrorBadEMail", $email));
543 } elseif ($email && !isValidMailDomain($email)) {
544 $langs->load("errors");
545 print img_warning($langs->trans("ErrorBadMXDomain", $email));
546 }
547 }
548 print '</td></tr>';
549 }
550
551 print '</table>';
552 print '</div>';
553
554
555 print '<div class="fichehalfright">';
556 print '<div class="underbanner clearboth"></div>';
557
558 print '<table class="border centpercent tableforfield">';
559
560 // Number of distinct emails
561 print '<tr><td>';
562 print $langs->trans("TotalNbOfDistinctRecipients");
563 print '</td><td>';
564 $nbemail = ($object->nbemail ? $object->nbemail : 0);
565 if (is_numeric($nbemail)) {
566 $htmltooltip = '';
567 if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') < $nbemail) && ($object->status == 1 || ($object->status == 2 && $nbtry < $nbemail))) {
568 if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') > 0) {
569 $htmltooltip .= $langs->trans('LimitSendingEmailing', getDolGlobalString('MAILING_LIMIT_SENDBYWEB'));
570 } else {
571 $htmltooltip .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
572 }
573 }
574 if (empty($nbemail)) {
575 $nbemail .= ' '.img_warning($langs->trans('ToAddRecipientsChooseHere'));//.' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
576 }
577 if ($htmltooltip) {
578 print $form->textwithpicto($nbemail, $htmltooltip, 1, 'info');
579 } else {
580 print $nbemail;
581 }
582 }
583 print '</td></tr>';
584
585 print '<tr><td>';
586 print $langs->trans("MAIN_MAIL_SENDMODE");
587 print '</td><td>';
588 if ($object->messtype != 'sms') {
589 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') && getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
590 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING')];
591 } elseif (getDolGlobalString('MAIN_MAIL_SENDMODE')) {
592 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE')];
593 } else {
594 $text = $listofmethods['mail'];
595 }
596 print $text;
597 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
598 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'mail') {
599 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER_EMAILING', getDolGlobalString('MAIN_MAIL_SMTP_SERVER')).')</span>';
600 }
601 } elseif (getDolGlobalString('MAIN_MAIL_SENDMODE') != 'mail' && getDolGlobalString('MAIN_MAIL_SMTP_SERVER')) {
602 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').')</span>';
603 }
604 } else {
605 print 'SMS ';
606 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').')</span>';
607 }
608 print '</td></tr>';
609
610 // Other attributes. Fields from hook formObjectOptions and Extrafields.
611 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
612
613 print '</table>';
614 print '</div>';
615 print '</div>';
616
617 print '<div class="clearboth"></div>';
618
619 print dol_get_fiche_end();
620
621 print '<br>';
622
623
624 // Show email selectors
625 if ($object->status == 0 && $user->hasRight('mailing', 'creer')) {
626 // @phan-assert FormAdvTargetEmailing $formadvtargetemaling
627 // @phan-assert AdvanceTargetingMailing $advTarget
628
629 // @phan-assert array<string,int|string|string[] $array_query'
630
631 // From controller using view
632 '
633 @phan-var-force FormAdvTargetEmailing $formadvtargetemaling
634 @phan-var-force AdvanceTargetingMailing $advTarget
635 @phan-var-force array<string,string|int|string[]> $array_query
636 ';
637
638 print '<script>
639 $(document).ready(function() {
640
641 // Click Function
642 $(":button[name=addcontact]").click(function() {
643 $(":hidden[name=action]").val("add");
644 $("#find_customer").submit();
645 });
646
647 $(":button[name=loadfilter]").click(function() {
648 $(":hidden[name=action]").val("loadfilter");
649 $("#find_customer").submit();
650 });
651
652 $(":button[name=deletefilter]").click(function() {
653 $(":hidden[name=action]").val("deletefilter");
654 $("#find_customer").submit();
655 });
656
657 $(":button[name=savefilter]").click(function() {
658 $(":hidden[name=action]").val("savefilter");
659 $("#find_customer").submit();
660 });
661
662 $(":button[name=createfilter]").click(function() {
663 $(":hidden[name=action]").val("createfilter");
664 $("#find_customer").submit();
665 });
666 });
667 </script>';
668
669
670 print load_fiche_titre($langs->trans("AdvTgtTitle").'...', '', '');
671
672 print '<form name="find_customer" id="find_customer" action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'."\n";
673 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
674 print '<input type="hidden" name="action" value="">'."\n";
675 print '<table class="border centpercent">'."\n";
676
677 print '<tr><td class="titlefieldcreate">'.$langs->trans('AdvTgtNameTemplate').'</td><td class="valignmiddle">';
678 if (!empty($template_id)) {
679 $default_template = $template_id;
680 } else {
681 $default_template = $advTarget->id;
682 }
683 print $formadvtargetemaling->selectAdvtargetemailingTemplate('template_id', $default_template, $langs->trans("SelectAPredefinedFilter"), $advTarget->type_element, 'minwidth100 valignmiddle');
684 print '<input type="button" name="loadfilter" id="loadfilter" value="'.$langs->trans('AdvTgtLoadFilter').'" class="button smallpaddingimp"/>';
685 print '<input type="button" name="deletefilter" id="deletefilter" value="'.$langs->trans('AdvTgtDeleteFilter').'" class="button smallpaddingimp"/>';
686 print '<input type="button" name="savefilter" id="savefilter" value="'.$langs->trans('AdvTgtSaveFilter').'" class="button smallpaddingimp"/>'; // Update filter
687 print '</td><td>'."\n";
688 print '</td></tr>'."\n";
689
690 print '<tr><td>'.$langs->trans('AdvTgtOrCreateNewFilter').'</td><td>';
691 print '<input type="text" name="template_name" id="template_name" value=""/>';
692 print '<input type="button" name="createfilter" id="createfilter" value="'.$langs->trans('AdvTgtCreateFilter').'" class="button smallpaddingimp"/>';
693 print '</td><td>'."\n";
694 print '</td></tr>'."\n";
695
696 print '<tr><td colspan="3"><hr></td></tr>';
697
698 print '<tr>'."\n";
699 print '<td colspan="3" class="center">'."\n";
700 print '<input type="button" name="addcontact" id="addcontact" value="'.$langs->trans('AdvTgtAddContact').'" class="button"/>'."\n";
701 print '</td>'."\n";
702 print '</tr>'."\n";
703
704 print '<tr><td>'.$langs->trans('AdvTgtTypeOfIncude').'</td><td>';
705 print $form->selectarray('type_of_target', $advTarget->select_target_type, $array_query['type_of_target']);
706 print '</td><td>'."\n";
707 print $form->textwithpicto('', $langs->trans("AdvTgtTypeOfIncudeHelp"), 1, 'help');
708 print '</td></tr>'."\n";
709
710 // Customer name
711 print '<tr><td>'.$langs->trans('ThirdPartyName');
712 if (!empty($array_query['cust_name'])) {
713 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
714 }
715 print '</td><td><input type="text" name="cust_name" value="'.$array_query['cust_name'].'"/></td><td>'."\n";
716 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
717 print '</td></tr>'."\n";
718
719 // Code Client
720 print '<tr><td>'.$langs->trans('CustomerCode');
721 if (!empty($array_query['cust_code'])) {
722 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
723 $cust_code_str = (string) $array_query['cust_code'];
724 } else {
725 $cust_code_str = null;
726 }
727 print '</td><td><input type="text" name="cust_code"'.($cust_code_str != null ? ' value="'.$cust_code_str : '').'"/></td><td>'."\n";
728 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
729 print '</td></tr>'."\n";
730
731 // Address Client
732 print '<tr><td>'.$langs->trans('Address');
733 if (!empty($array_query['cust_adress'])) {
734 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
735 }
736 print '</td><td><input type="text" name="cust_adress" value="'.$array_query['cust_adress'].'"/></td><td>'."\n";
737 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
738 print '</td></tr>'."\n";
739
740 // Zip Client
741 print '<tr><td>'.$langs->trans('Zip');
742 if (!empty($array_query['cust_zip'])) {
743 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
744 }
745 print '</td><td><input type="text" name="cust_zip" value="'.$array_query['cust_zip'].'"/></td><td>'."\n";
746 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
747 print '</td></tr>'."\n";
748
749 // City Client
750 print '<tr><td>'.$langs->trans('Town');
751 if (!empty($array_query['cust_city'])) {
752 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
753 }
754 print '</td><td><input type="text" name="cust_city" value="'.$array_query['cust_city'].'"/></td><td>'."\n";
755 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
756 print '</td></tr>'."\n";
757
758 // State Client
759 print '<tr><td>'.$langs->trans('State');
760 if (!empty($array_query['cust_state'])) {
761 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
762 }
763 print '</td><td>'."\n";
764 print $formadvtargetemaling->multiselectState('cust_state', $array_query['cust_state']);
765 print '</td><td>'."\n";
766 print '</td></tr>'."\n";
767
768 // Customer Country
769 print '<tr><td>'.$langs->trans("Country");
770 if (!empty($array_query['cust_country'])) {
771 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
772 }
773 print '</td><td>'."\n";
774 print $formadvtargetemaling->multiselectCountry('cust_country', $array_query['cust_country']);
775 print '</td><td>'."\n";
776 print '</td></tr>'."\n";
777
778 // State Customer
779 print '<tr><td>'.$langs->trans('Status').' '.$langs->trans('ThirdParty');
780 if (!empty($array_query['cust_status'])) {
781 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
782 }
783 print '</td><td>';
784 print $formadvtargetemaling->advMultiselectarray(
785 'cust_status',
786 array(
787 '0' => $langs->trans('ActivityCeased'),
788 '1' => $langs->trans('InActivity')
789 ),
790 $array_query['cust_status']
791 );
792 print '</td><td>'."\n";
793 print '</td></tr>'."\n";
794
795 // Mother Company
796 print '<tr><td>'.$langs->trans("ParentCompany");
797 if (!empty($array_query['cust_mothercompany'])) {
798 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
799 }
800 print '</td><td>'."\n";
801 print '<input type="text" name="cust_mothercompany" value="'.$array_query['cust_mothercompany'].'"/>';
802 print '</td><td>'."\n";
803 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
804 print '</td></tr>'."\n";
805
806 // Prospect/Customer
807 $selected = $array_query['cust_typecust'];
808 print '<tr><td>'.$langs->trans('ProspectCustomer').' '.$langs->trans('ThirdParty');
809 if (!empty($array_query['cust_typecust'])) {
810 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
811 }
812 print '</td><td>';
813 $options_array = array(
814 2 => $langs->trans('Prospect'),
815 3 => $langs->trans('ProspectCustomer'),
816 1 => $langs->trans('Customer'),
817 0 => $langs->trans('NorProspectNorCustomer')
818 );
819 print $formadvtargetemaling->advMultiselectarray('cust_typecust', $options_array, $selected);
820 print '</td><td>'."\n";
821 print '</td></tr>'."\n";
822
823 // Prospection status
824 print '<tr><td>'.$langs->trans('ProspectLevel');
825 if (!empty($array_query['cust_prospect_status'])) {
826 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
827 }
828 print '</td><td>';
829 print $formadvtargetemaling->multiselectProspectionStatus($array_query['cust_prospect_status'], 'cust_prospect_status');
830 print '</td><td>'."\n";
831 print '</td></tr>'."\n";
832
833 // Prospection comm status
834 print '<tr><td>'.$langs->trans('StatusProsp');
835 if (!empty($array_query['cust_comm_status'])) {
836 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
837 }
838 print '</td><td>';
839 print $formadvtargetemaling->advMultiselectarray('cust_comm_status', $advTarget->type_statuscommprospect, $array_query['cust_comm_status']);
840 print '</td><td>'."\n";
841 print '</td></tr>'."\n";
842
843 // Customer Type
844 print '<tr><td>'.$langs->trans("ThirdPartyType");
845 if (!empty($array_query['cust_typeent'])) {
846 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
847 }
848 print '</td><td>'."\n";
849 print $formadvtargetemaling->advMultiselectarray('cust_typeent', $formcompany->typent_array(0, " AND id <> 0"), $array_query['cust_typeent']);
850 print '</td><td>'."\n";
851 print '</td></tr>'."\n";
852
853 // Staff number
854 print '<td>'.$langs->trans("Staff");
855 if (!empty($array_query['cust_effectif_id'])) {
856 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
857 }
858 print '</td><td>';
859 print $formadvtargetemaling->advMultiselectarray("cust_effectif_id", $formcompany->effectif_array(0, " AND id <> 0"), $array_query['cust_effectif_id']);
860 print '</td><td>'."\n";
861 print '</td></tr>'."\n";
862
863 // Sales manager
864 print '<tr><td>'.$langs->trans("SalesRepresentatives");
865 if (!empty($array_query['cust_saleman'])) {
866 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
867 }
868 print '</td><td>'."\n";
869 print $formadvtargetemaling->multiselectselectSalesRepresentatives('cust_saleman', $array_query['cust_saleman'], $user);
870 print '</td><td>'."\n";
871 print '</td></tr>'."\n";
872
873 // Customer Default Language
874 if (getDolGlobalInt('MAIN_MULTILANGS')) {
875 print '<tr><td>'.$langs->trans("DefaultLang");
876 if (!empty($array_query['cust_language'])) {
877 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
878 }
879 print '</td><td>'."\n";
880 print $formadvtargetemaling->multiselectselectLanguage('cust_language', $array_query['cust_language']);
881 print '</td><td>'."\n";
882 print '</td></tr>'."\n";
883 }
884
885 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
886 // Customer Categories
887 print '<tr><td>'.$langs->trans("CustomersCategoryShort");
888 print '</td><td>'."\n";
889 print $form->selectCategories(Categorie::TYPE_CUSTOMER, 'cust_categ', $object);
890 print '</td><td>'."\n";
891 print '</td></tr>'."\n";
892 }
893
894 // Standard Extrafield feature
895 if (!getDolGlobalString('MAIN_EXTRAFIELDS_DISABLED')) {
896 $socstatic = new Societe($db);
897 $elementtype = $socstatic->table_element;
898 // fetch optionals attributes and labels
899 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
900 $extrafields = new ExtraFields($db);
901 $extrafields->fetch_name_optionals_label($elementtype);
902 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $val) {
903 if ($key != 'ts_nameextra' && $key != 'ts_payeur') {
904 if (isset($extrafields->attributes[$elementtype]['langfile'][$key])) {
905 $langs->load($extrafields->attributes[$elementtype]['langfile'][$key]);
906 }
907 print '<tr><td>'.$langs->trans($extrafields->attributes[$elementtype]['label'][$key]);
908 if (!empty($array_query['options_'.$key]) || (is_array($array_query['options_'.$key]) && count($array_query['options_'.$key]) > 0)) {
909 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
910 }
911 print '</td><td>';
912 if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') || ($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
913 print '<input type="text" name="options_'.$key.'"/></td><td>'."\n";
914 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
915 } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'int') || ($extrafields->attributes[$elementtype]['type'][$key] == 'double')) {
916 print $langs->trans("AdvTgtMinVal").'<input type="text" name="options'.$key.'_min"/>';
917 print $langs->trans("AdvTgtMaxVal").'<input type="text" name="options'.$key.'_max"/>';
918 print '</td><td>'."\n";
919 print $form->textwithpicto('', $langs->trans("AdvTgtSearchIntHelp"), 1, 'help');
920 } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'date') || ($extrafields->attributes[$elementtype]['type'][$key] == 'datetime')) {
921 print '<table class="nobordernopadding"><tr>';
922 print '<td>'.$langs->trans("AdvTgtStartDt").'</td><td>';
923 print $form->selectDate('', 'options_'.$key.'_st_dt', 0, 0, 1);
924 print '</td><td>'.$langs->trans("AdvTgtEndDt").'</td><td>';
925 print $form->selectDate('', 'options_'.$key.'_end_dt', 0, 0, 1);
926 print '</td></tr></table>';
927
928 print '</td><td>'."\n";
929 print $form->textwithpicto('', $langs->trans("AdvTgtSearchDtHelp"), 1, 'help');
930 } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'boolean')) {
931 print $form->selectarray(
932 'options_'.$key,
933 array(
934 '' => '',
935 '1' => $langs->trans('Yes'),
936 '0' => $langs->trans('No')
937 ),
938 $array_query['options_'.$key]
939 );
940 print '</td><td>'."\n";
941 } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'select') {
942 print $formadvtargetemaling->advMultiselectarray('options_'.$key, $extrafields->attributes[$elementtype]['param'][$key]['options'], $array_query['options_'.$key]);
943 print '</td><td>'."\n";
944 } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'sellist') {
945 print $formadvtargetemaling->advMultiselectarraySelllist('options_'.$key, $extrafields->attributes[$elementtype]['param'][$key]['options'], $array_query['options_'.$key]);
946 print '</td><td>'."\n";
947 } else {
948 print '<table class="nobordernopadding"><tr>';
949 print '<td></td><td>';
950 if (is_array($array_query['options_'.$key])) {
951 print $extrafields->showInputField($key, implode(',', $array_query['options_'.$key]), '', '', '', '', 0, 'societe', 1);
952 } else {
953 print $extrafields->showInputField($key, $array_query['options_'.$key], '', '', '', '', 0, 'societe', 1);
954 }
955 print '</td></tr></table>';
956
957 print '</td><td>'."\n";
958 }
959 print '</td></tr>'."\n";
960 }
961 }
962 } else {
963 $std_soc = new Societe($db);
964 $action_search = 'query';
965
966 $parameters = array('advtarget' => 1);
967 if (!empty($advTarget->id)) {
968 $parameters = array('array_query' => $advTarget->filtervalue);
969 }
970 // Other attributes
971 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $std_soc, $action_search);
972 print $hookmanager->resPrint;
973 }
974
975 // State Contact
976 print '<tr><td>'.$langs->trans('Status').' '.$langs->trans('Contact');
977 if (!empty($array_query['contact_status'])) {
978 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
979 }
980 print '</td><td>';
981 print $formadvtargetemaling->advMultiselectarray(
982 'contact_status',
983 array(
984 '0' => $langs->trans('ActivityCeased'),
985 '1' => $langs->trans('InActivity')
986 ),
987 $array_query['contact_status']
988 );
989 print '</td><td>'."\n";
990 print $form->textwithpicto('', $langs->trans("AdvTgtContactHelp"), 1, 'help');
991 print '</td></tr>'."\n";
992
993 // Civility
994 print '<tr><td>'.$langs->trans("UserTitle");
995 if (!empty($array_query['contact_civility'])) {
996 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
997 }
998 print '</td><td>';
999 print $formadvtargetemaling->multiselectCivility('contact_civility', $array_query['contact_civility']);
1000 print '</td></tr>';
1001
1002 // contact name
1003 print '<tr><td>'.$langs->trans('Contact').' '.$langs->trans('Lastname');
1004 if (!empty($array_query['contact_lastname'])) {
1005 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
1006 }
1007 print '</td><td><input type="text" name="contact_lastname" value="'.$array_query['contact_lastname'].'"/></td><td>'."\n";
1008 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
1009 print '</td></tr>'."\n";
1010 print '<tr><td>'.$langs->trans('Contact').' '.$langs->trans('Firstname');
1011 if (!empty($array_query['contact_firstname'])) {
1012 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
1013 }
1014 print '</td><td><input type="text" name="contact_firstname" value="'.$array_query['contact_firstname'].'"/></td><td>'."\n";
1015 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
1016 print '</td></tr>'."\n";
1017
1018 // Contact Country
1019 print '<tr><td>'.$langs->trans('Contact').' '.$langs->trans("Country");
1020 if (!empty($array_query['contact_country'])) {
1021 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
1022 }
1023 print '</td><td>'."\n";
1024 print $formadvtargetemaling->multiselectCountry('contact_country', $array_query['contact_country']);
1025 print '</td><td>'."\n";
1026 print '</td></tr>'."\n";
1027
1028 // Never send mass mailing
1029 print '<tr><td>'.$langs->trans('Contact').' '.$langs->trans("No_Email");
1030 if (!empty($array_query['contact_no_email'])) {
1031 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
1032 }
1033 print '</td><td>'."\n";
1034 print $form->selectarray(
1035 'contact_no_email',
1036 array(
1037 '' => '',
1038 '1' => $langs->trans('Yes'),
1039 '0' => $langs->trans('No')
1040 ),
1041 $array_query['contact_no_email']
1042 );
1043 print '</td><td>'."\n";
1044 print '</td></tr>'."\n";
1045
1046 // Contact Date Create
1047 print '<tr><td>'.$langs->trans('Contact').' '.$langs->trans("DateCreation");
1048 if (!empty($array_query['contact_create_st_dt'])) {
1049 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
1050 }
1051 print '</td><td>'."\n";
1052 print '<table class="nobordernopadding"><tr>';
1053 print '<td>'.$langs->trans("AdvTgtStartDt").'</td><td>';
1054 print $form->selectDate($array_query['contact_create_st_dt'], 'contact_create_st_dt', 0, 0, 1, 'find_customer', 1, 1);
1055 print '</td><td>'.$langs->trans("AdvTgtEndDt").'</td><td>';
1056 print $form->selectDate($array_query['contact_create_end_dt'], 'contact_create_end_dt', 0, 0, 1, 'find_customer', 1, 1);
1057 print '</td></tr></table>';
1058 print '</td><td>'."\n";
1059 print '</td></tr>'."\n";
1060
1061 // Contact update Create
1062 print '<tr><td>'.$langs->trans('Contact').' '.$langs->trans("DateLastModification");
1063 if (!empty($array_query['contact_update_st_dt'])) {
1064 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
1065 }
1066 print '</td><td>'."\n";
1067 print '<table class="nobordernopadding"><tr>';
1068 print '<td>'.$langs->trans("AdvTgtStartDt").'</td><td>';
1069 print $form->selectDate($array_query['contact_update_st_dt'], 'contact_update_st_dt', 0, 0, 1, 'find_customer', 1, 1);
1070 print '</td><td>'.$langs->trans("AdvTgtEndDt").'</td><td>';
1071 print $form->selectDate($array_query['contact_update_end_dt'], 'contact_update_end_dt', 0, 0, 1, 'find_customer', 1, 1);
1072 print '</td></tr></table>';
1073 print '</td><td>'."\n";
1074 print '</td></tr>'."\n";
1075
1076 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1077 // Customer Categories
1078 print '<tr><td>'.$langs->trans("ContactCategoriesShort");
1079 print '</td><td>'."\n";
1080 print $form->selectCategories(Categorie::TYPE_CONTACT, 'contact_categ', $object);
1081 print '</td><td>'."\n";
1082 print '</td></tr>'."\n";
1083 }
1084
1085 // Standard Extrafield feature
1086 if (!getDolGlobalString('MAIN_EXTRAFIELDS_DISABLED')) {
1087 $contactstatic = new Contact($db);
1088 $elementtype = $contactstatic->table_element;
1089 // fetch optionals attributes and labels
1090 dol_include_once('/core/class/extrafields.class.php');
1091 $extrafields = new ExtraFields($db);
1092 $extrafields->fetch_name_optionals_label($elementtype);
1093 if (!empty($extrafields->attributes[$elementtype]['type'])) {
1094 foreach ($extrafields->attributes[$elementtype]['type'] as $key => &$value) {
1095 if ($value == 'radio') {
1096 $value = 'select';
1097 }
1098 }
1099 }
1100 if (!empty($extrafields->attributes[$elementtype]['label'])) {
1101 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $val) {
1102 print '<tr><td>'.$extrafields->attributes[$elementtype]['label'][$key];
1103 if ($array_query['options_'.$key.'_cnct'] != '' || (is_array($array_query['options_'.$key.'_cnct']) && count($array_query['options_'.$key.'_cnct']) > 0)) {
1104 print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
1105 }
1106 print '</td><td>';
1107 if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') || ($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
1108 print '<input type="text" name="options_'.$key.'_cnct"/></td><td>'."\n";
1109 print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
1110 } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'int') || ($extrafields->attributes[$elementtype]['type'][$key] == 'double')) {
1111 print $langs->trans("AdvTgtMinVal").'<input type="text" name="options_'.$key.'_min_cnct"/>';
1112 print $langs->trans("AdvTgtMaxVal").'<input type="text" name="options_'.$key.'_max_cnct"/>';
1113 print '</td><td>'."\n";
1114 print $form->textwithpicto('', $langs->trans("AdvTgtSearchIntHelp"), 1, 'help');
1115 } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'date') || ($extrafields->attributes[$elementtype]['type'][$key] == 'datetime')) {
1116 print '<table class="nobordernopadding"><tr>';
1117 print '<td>'.$langs->trans("AdvTgtStartDt").'</td><td>';
1118 print $form->selectDate('', 'options_'.$key.'_st_dt_cnct', 0, 0, 1);
1119 print '</td><td>'.$langs->trans("AdvTgtEndDt").'</td><td>';
1120 print $form->selectDate('', 'options_'.$key.'_end_dt_cnct', 0, 0, 1);
1121 print '</td></tr></table>';
1122 print '</td><td>'."\n";
1123 print $form->textwithpicto('', $langs->trans("AdvTgtSearchDtHelp"), 1, 'help');
1124 } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'boolean')) {
1125 print $form->selectarray(
1126 'options_'.$key.'_cnct',
1127 array(
1128 '' => '',
1129 '1' => $langs->trans('Yes'),
1130 '0' => $langs->trans('No')
1131 ),
1132 $array_query['options_'.$key.'_cnct']
1133 );
1134 print '</td><td>'."\n";
1135 } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'select') {
1136 print $formadvtargetemaling->advMultiselectarray('options_'.$key.'_cnct', $extrafields->attributes[$elementtype]['param'][$key]['options'], $array_query['options_'.$key.'_cnct']);
1137 print '</td><td>'."\n";
1138 } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'sellist') {
1139 print $formadvtargetemaling->advMultiselectarraySelllist('options_'.$key.'_cnct', $extrafields->attributes[$elementtype]['param'][$key]['options'], $array_query['options_'.$key.'_cnct']);
1140 print '</td><td>'."\n";
1141 } else {
1142 if (is_array($array_query['options_'.$key.'_cnct'])) {
1143 print $extrafields->showInputField($key, implode(',', $array_query['options_'.$key.'_cnct']), '', '_cnct', '', '', 0, 'socpeople', 1);
1144 } else {
1145 print $extrafields->showInputField($key, $array_query['options_'.$key.'_cnct'], '', '_cnct', '', '', 0, 'socpeople', 1);
1146 }
1147 print '</td><td>'."\n";
1148 }
1149 print '</td></tr>'."\n";
1150 }
1151 }
1152 }
1153
1154 print '</table>'."\n";
1155 print '<br>';
1156 print '<center><input type="button" name="addcontact" id="addcontact" value="'.$langs->trans('AdvTgtAddContact').'" class="butAction"/></center>'."\n";
1157 print '<br>';
1158 print '</form>'."\n";
1159
1160 print '<br>';
1161
1162 // TODO Replace this with an include of a.tpl that contains samecode than into targetemailing.php
1163 print '<form action="'.$_SERVER['PHP_SELF'].'?action=clear&id='.$object->id.'" method="POST">';
1164 print '<input type="hidden" name="token" value="'.newToken().'">';
1165 print load_fiche_titre($langs->trans("ToClearAllRecipientsClickHere"));
1166 print '<table class="noborder centpercent">';
1167 print '<tr class="liste_titre">';
1168 print '<td class="liste_titre right"><input type="submit" class="button" value="'.$langs->trans("TargetsReset").'"></td>';
1169 print '</tr>';
1170 print '</table>';
1171 print '</form>';
1172
1173
1174 print '<br>';
1175 }
1176}
1177
1178// End of page
1179llxFooter();
1180$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$totalarray
Definition export.php:1206
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage advanced emailing target selector.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
static getArrayAddress($address)
Return a formatted array of address string for SMTP protocol.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to offer components to list and upload files.
Class permettant la generation de composants html autre Only common components are here.
Class to manage emailings module.
Parent class of emailing target selectors modules.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage a list of personalised recipients for mailing feature.
emailing_prepare_head(Mailing $object)
Prepare array with list of tabs.
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.