27if (!defined(
'NOSTYLECHECK')) {
28 define(
'NOSTYLECHECK',
'1');
32require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/advtargetemailing.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/html.formadvtargetemailing.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/advthirdparties.modules.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
43$langs->loadLangs(array(
'mails',
'companies'));
44if (isModEnabled(
'category')) {
45 $langs->load(
"categories");
50$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
51$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
53if (empty($page) || $page == -1) {
56$offset = $limit * $page;
68$action =
GETPOST(
'action',
'aZ09');
69$search_nom =
GETPOST(
"search_nom");
70$search_prenom =
GETPOST(
"search_prenom");
71$search_email =
GETPOST(
"search_email");
75if (
GETPOST(
'button_removefilter_x',
'alpha')) {
80$array_query = array();
81'@phan-var-force array<string,int|string|string[]> $array_query';
85if (empty($template_id)) {
86 $advTarget->fk_element =
$id;
87 $advTarget->type_element =
'mailing';
88 $result = $advTarget->fetch_by_mailing();
90 $result = $advTarget->fetch($template_id);
96 if (!empty($advTarget->id)) {
97 $array_query = json_decode($advTarget->filtervalue,
true);
102if (!$user->hasRight(
'mailing',
'lire') || (!
getDolGlobalString(
'EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
107$permissiontoread = $user->hasRight(
'mailing',
'lire');
108$permissiontoadd = $user->hasRight(
'mailing',
'creer');
115if ($action ==
'loadfilter' && $permissiontoread) {
116 if (!empty($template_id)) {
117 $result = $advTarget->fetch($template_id);
121 if (!empty($advTarget->id)) {
122 $array_query = json_decode($advTarget->filtervalue,
true);
128if ($action ==
'add' && $permissiontoadd) {
129 $user_contact_query =
false;
131 $array_query = array();
135 foreach ($_POST as $key => $value) {
137 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
139 if (preg_match(
"/st_dt/", $key)) {
141 $dtarr = explode(
'_', $key);
142 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
143 $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'));
145 } elseif (preg_match(
"/end_dt/", $key)) {
148 $dtarr = explode(
'_', $key);
149 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
150 $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'));
153 $array_query[$key] =
GETPOST($key);
156 if (preg_match(
"/^options_.*_cnct/", $key)) {
157 $user_contact_query =
true;
159 if (preg_match(
"/st_dt/", $key)) {
161 $dtarr = explode(
'_', $key);
162 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
163 $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'));
165 } elseif (preg_match(
"/end_dt/", $key)) {
168 $dtarr = explode(
'_', $key);
169 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
170 $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'));
173 $array_query[$key] =
GETPOST($key);
177 if (preg_match(
"/^cust_/", $key)) {
178 $array_query[$key] =
GETPOST($key);
181 if (preg_match(
"/^contact_/", $key)) {
182 $array_query[$key] =
GETPOST($key);
184 $specials_date_key = array(
185 'contact_update_st_dt',
186 'contact_update_end_dt',
187 'contact_create_st_dt',
188 'contact_create_end_dt'
190 foreach ($specials_date_key as $date_key) {
191 if ($key == $date_key) {
196 $array_query[$key] =
'';
201 if (!empty($array_query[$key])) {
202 $user_contact_query =
true;
206 if ($array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4) {
207 $user_contact_query =
true;
210 if (preg_match(
"/^type_of_target/", $key)) {
211 $array_query[$key] =
GETPOST($key);
216 $result = $advTarget->query_thirdparty($array_query);
224 if ($user_contact_query && ($array_query[
'type_of_target'] == 1 || $array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4)) {
225 $result = $advTarget->query_contact($array_query, 1);
230 if (count($advTarget->contact_lines) == 0) {
231 $advTarget->contact_lines = array(
236 $advTarget->contact_lines = array();
239 $mailingadvthirdparties =
null;
240 if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
243 $result = $mailingadvthirdparties->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query[
'type_of_target'], $advTarget->contact_lines);
249 $query_temlate_id =
'';
250 if (!empty($template_id)) {
251 $query_temlate_id =
'&template_id='.$template_id;
254 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$id.$query_temlate_id);
260 if ($result < 0 && is_object($mailingadvthirdparties)) {
261 setEventMessages($mailingadvthirdparties->error, $mailingadvthirdparties->errors,
'errors');
265if ($action ==
'clear' && $permissiontoadd) {
267 $mailingtargets->clear_target($id);
269 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
273if (($action ==
'savefilter' || $action ==
'createfilter') && $permissiontoadd) {
274 $template_name =
GETPOST(
'template_name');
277 if ($action ==
'createfilter' && empty($template_name) && $permissiontoadd) {
278 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'AdvTgtOrCreateNewFilter')),
null,
'errors');
283 $array_query = array();
286 foreach ($_POST as $key => $value) {
287 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
289 if (preg_match(
"/st_dt/", $key)) {
291 $dtarr = explode(
'_', $key);
292 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
293 $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'));
295 } elseif (preg_match(
"/end_dt/", $key)) {
298 $dtarr = explode(
'_', $key);
299 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
300 $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'));
305 $array_query[$key] =
GETPOST($key);
308 if (preg_match(
"/^options_.*_cnct/", $key)) {
310 if (preg_match(
"/st_dt/", $key)) {
312 $dtarr = explode(
'_', $key);
313 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
314 $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'));
316 } elseif (preg_match(
"/end_dt/", $key)) {
319 $dtarr = explode(
'_', $key);
320 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
321 $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'));
326 $array_query[$key] =
GETPOST($key);
330 if (preg_match(
"/^cust_/", $key)) {
331 $array_query[$key] =
GETPOST($key);
334 if (preg_match(
"/^contact_/", $key)) {
335 $array_query[$key] =
GETPOST($key);
337 $specials_date_key = array(
338 'contact_update_st_dt',
339 'contact_update_end_dt',
340 'contact_create_st_dt',
341 'contact_create_end_dt'
343 foreach ($specials_date_key as $date_key) {
344 if ($key == $date_key) {
349 $array_query[$key] =
'';
355 if (preg_match(
"/^type_of_target/", $key)) {
356 $array_query[$key] =
GETPOST($key);
359 $advTarget->filtervalue = json_encode($array_query);
361 if ($action ==
'createfilter') {
362 $advTarget->name = $template_name;
363 $result = $advTarget->create($user);
367 } elseif ($action ==
'savefilter') {
368 $result = $advTarget->update($user);
373 $template_id = $advTarget->id;
377if ($action ==
'deletefilter' && $permissiontoadd) {
378 $result = $advTarget->delete($user);
382 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
386if ($action ==
'delete' && $permissiontoadd) {
388 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE rowid = ".((int) $rowid);
389 $resql = $db->query($sql);
393 $mailingtargets->update_nb($id);
395 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
398 header(
"Location: liste.php");
406if (
GETPOST(
"button_removefilter")) {
417llxHeader(
'', $langs->trans(
"MailAdvTargetRecipients"));
419$form =
new Form($db);
429 print
'<table class="border centpercent">';
431 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/liste.php">'.$langs->trans(
"BackToList").
'</a>';
433 print
'<tr><td>'.$langs->trans(
"Ref").
'</td>';
434 print
'<td colspan="3">';
435 print $form->showrefnav($object,
'id', $linkback);
438 print
'<tr><td>'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.
$object->title.
'</td></tr>';
440 print
'<tr><td>'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email(
$object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
443 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email(
$object->email_errorsto, 0, 0, 0, 0, 1);
447 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td colspan="3">'.
$object->getLibStatut(4).
'</td></tr>';
451 print $langs->trans(
"TotalNbOfDistinctRecipients");
452 print
'</td><td colspan="3">';
454 if (
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
455 $text = $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
457 print $form->textwithpicto($nbemail, $text, 1,
'warning');
468 if (
$object->status == 0 && $user->hasRight(
'mailing',
'creer')) {
473 include DOL_DOCUMENT_ROOT.
'/core/tpl/advtarget.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
Class to manage advanced emailing target selector.
Class to manage emailings module.
Parent class of emailing target selectors modules.
Class to manage a list of personalised recipients for mailing feature.
emailing_prepare_head(Mailing $object)
Prepare array with list of tabs.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
Show tabs of a record.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.