25 if (!defined(
'NOSTYLECHECK')) {
26 define(
'NOSTYLECHECK',
'1');
29 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/advtargetemailing.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/html.formadvtargetemailing.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/advthirdparties.modules.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
40 $langs->loadLangs(array(
'mails',
'companies'));
41 if (!empty($conf->categorie->enabled)) {
42 $langs->load(
"categories");
46 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
47 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
48 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
50 if (empty($page) || $page == -1) {
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
64 $rowid =
GETPOST(
'rowid',
'int');
65 $action =
GETPOST(
'action',
'aZ09');
66 $search_nom =
GETPOST(
"search_nom");
67 $search_prenom =
GETPOST(
"search_prenom");
68 $search_email =
GETPOST(
"search_email");
69 $template_id =
GETPOST(
'template_id',
'int');
72 if (
GETPOST(
'button_removefilter_x',
'alpha')) {
77 $array_query = array();
81 if (empty($template_id)) {
82 $advTarget->fk_element = $id;
83 $advTarget->type_element =
'mailing';
84 $result = $advTarget->fetch_by_mailing();
86 $result = $advTarget->fetch($template_id);
92 if (!empty($advTarget->id)) {
93 $array_query = json_decode($advTarget->filtervalue,
true);
98 if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
108 if ($action ==
'loadfilter') {
109 if (!empty($template_id)) {
110 $result = $advTarget->fetch($template_id);
114 if (!empty($advTarget->id)) {
115 $array_query = json_decode($advTarget->filtervalue,
true);
121 if ($action ==
'add') {
122 $user_contact_query =
false;
124 $array_query = array();
128 foreach ($_POST as $key => $value) {
130 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
132 if (preg_match(
"/st_dt/", $key)) {
134 $dtarr = explode(
'_', $key);
135 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
136 $array_query[
'options_'.$dtarr[1].
'_st_dt'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_st_dtmonth',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtday',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtyear',
'int'));
138 } elseif (preg_match(
"/end_dt/", $key)) {
141 $dtarr = explode(
'_', $key);
142 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
143 $array_query[
'options_'.$dtarr[1].
'_end_dt'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_end_dtmonth',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtday',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtyear',
'int'));
146 $array_query[$key] =
GETPOST($key);
149 if (preg_match(
"/^options_.*_cnct/", $key)) {
150 $user_contact_query =
true;
152 if (preg_match(
"/st_dt/", $key)) {
154 $dtarr = explode(
'_', $key);
155 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
156 $array_query[
'options_'.$dtarr[1].
'_st_dt_cnct'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_st_dtmonth_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtday_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtyear_cnct',
'int'));
158 } elseif (preg_match(
"/end_dt/", $key)) {
161 $dtarr = explode(
'_', $key);
162 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
163 $array_query[
'options_'.$dtarr[1].
'_end_dt_cnct'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_end_dtmonth_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtday_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtyear_cnct',
'int'));
166 $array_query[$key] =
GETPOST($key);
170 if (preg_match(
"/^cust_/", $key)) {
171 $array_query[$key] =
GETPOST($key);
174 if (preg_match(
"/^contact_/", $key)) {
175 $array_query[$key] =
GETPOST($key);
177 $specials_date_key = array(
178 'contact_update_st_dt',
179 'contact_update_end_dt',
180 'contact_create_st_dt',
181 'contact_create_end_dt'
183 foreach ($specials_date_key as $date_key) {
184 if ($key == $date_key) {
189 $array_query[$key] =
'';
194 if (!empty($array_query[$key])) {
195 $user_contact_query =
true;
199 if ($array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4) {
200 $user_contact_query =
true;
203 if (preg_match(
"/^type_of_target/", $key)) {
204 $array_query[$key] =
GETPOST($key);
209 $result = $advTarget->query_thirdparty($array_query);
217 if ($user_contact_query && ($array_query[
'type_of_target'] == 1 || $array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4)) {
218 $result = $advTarget->query_contact($array_query, 1);
223 if (count($advTarget->contact_lines) == 0) {
224 $advTarget->contact_lines = array(
229 $advTarget->contact_lines = array();
232 if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
235 $result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query[
'type_of_target'], $advTarget->contact_lines);
241 $query_temlate_id =
'';
242 if (!empty($template_id)) {
243 $query_temlate_id =
'&template_id='.$template_id;
246 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id.$query_temlate_id);
257 if ($action ==
'clear') {
259 $classname =
"MailingTargets";
260 $obj =
new $classname($db);
261 $obj->clear_target($id);
263 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
267 if ($action ==
'savefilter' || $action ==
'createfilter') {
268 $template_name =
GETPOST(
'template_name');
271 if ($action ==
'createfilter' && empty($template_name)) {
272 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'AdvTgtOrCreateNewFilter')),
null,
'errors');
277 $array_query = array();
280 foreach ($_POST as $key => $value) {
281 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
283 if (preg_match(
"/st_dt/", $key)) {
285 $dtarr = explode(
'_', $key);
286 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
287 $array_query[
'options_'.$dtarr[1].
'_st_dt'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_st_dtmonth',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtday',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtyear',
'int'));
289 } elseif (preg_match(
"/end_dt/", $key)) {
292 $dtarr = explode(
'_', $key);
293 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
294 $array_query[
'options_'.$dtarr[1].
'_end_dt'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_end_dtmonth',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtday',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtyear',
'int'));
299 $array_query[$key] =
GETPOST($key);
302 if (preg_match(
"/^options_.*_cnct/", $key)) {
304 if (preg_match(
"/st_dt/", $key)) {
306 $dtarr = explode(
'_', $key);
307 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
308 $array_query[
'options_'.$dtarr[1].
'_st_dt_cnct'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_st_dtmonth_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtday_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_st_dtyear_cnct',
'int'));
310 } elseif (preg_match(
"/end_dt/", $key)) {
313 $dtarr = explode(
'_', $key);
314 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
315 $array_query[
'options_'.$dtarr[1].
'_end_dt_cnct'] =
dol_mktime(0, 0, 0,
GETPOST(
'options_'.$dtarr[1].
'_end_dtmonth_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtday_cnct',
'int'),
GETPOST(
'options_'.$dtarr[1].
'_end_dtyear_cnct',
'int'));
320 $array_query[$key] =
GETPOST($key);
324 if (preg_match(
"/^cust_/", $key)) {
325 $array_query[$key] =
GETPOST($key);
328 if (preg_match(
"/^contact_/", $key)) {
329 $array_query[$key] =
GETPOST($key);
331 $specials_date_key = array(
332 'contact_update_st_dt',
333 'contact_update_end_dt',
334 'contact_create_st_dt',
335 'contact_create_end_dt'
337 foreach ($specials_date_key as $date_key) {
338 if ($key == $date_key) {
343 $array_query[$key] =
'';
349 if (preg_match(
"/^type_of_target/", $key)) {
350 $array_query[$key] =
GETPOST($key);
353 $advTarget->filtervalue = json_encode($array_query);
355 if ($action ==
'createfilter') {
356 $advTarget->name = $template_name;
357 $result = $advTarget->create($user);
361 } elseif ($action ==
'savefilter') {
362 $result = $advTarget->update($user);
367 $template_id = $advTarget->id;
371 if ($action ==
'deletefilter') {
372 $result = $advTarget->delete($user);
376 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
380 if ($action ==
'delete') {
382 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE rowid = ".((int) $rowid);
383 $resql = $db->query($sql);
386 $classname =
"MailingTargets";
387 $obj =
new $classname($db);
388 $obj->update_nb($id);
390 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
393 header(
"Location: liste.php");
401 if (
GETPOST(
"button_removefilter")) {
411 llxHeader(
'', $langs->trans(
"MailAdvTargetRecipients"));
418 if ($object->fetch($id) >= 0) {
423 print
'<table class="border centpercent">';
425 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/liste.php">'.$langs->trans(
"BackToList").
'</a>';
427 print
'<tr><td>'.$langs->trans(
"Ref").
'</td>';
428 print
'<td colspan="3">';
429 print
$form->showrefnav($object,
'id', $linkback);
432 print
'<tr><td>'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.$object->title.
'</td></tr>';
434 print
'<tr><td>'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email($object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
437 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
441 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td colspan="3">'.$object->getLibStatut(4).
'</td></tr>';
445 print $langs->trans(
"TotalNbOfDistinctRecipients");
446 print
'</td><td colspan="3">';
447 $nbemail = ($object->nbemail ? $object->nbemail :
'0');
448 if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
449 $text = $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
450 print
$form->textwithpicto($nbemail, $text, 1,
'warning');
461 if ($object->statut == 0 && $user->rights->mailing->creer) {
462 include DOL_DOCUMENT_ROOT.
'/core/tpl/advtarget.tpl.php';