28if (!defined(
'NOSTYLECHECK')) {
29 define(
'NOSTYLECHECK',
'1');
33require
'../../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/advtargetemailing.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/html.formadvtargetemailing.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/advthirdparties.modules.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
52$langs->loadLangs(array(
'mails',
'companies'));
53if (isModEnabled(
'category')) {
54 $langs->load(
"categories");
59$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
60$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
62if (empty($page) || $page == -1) {
65$offset = $limit * $page;
77$action =
GETPOST(
'action',
'aZ09');
78$search_nom =
GETPOST(
"search_nom");
79$search_prenom =
GETPOST(
"search_prenom");
80$search_email =
GETPOST(
"search_email");
84if (
GETPOST(
'button_removefilter_x',
'alpha')) {
89$array_query = array();
90'@phan-var-force array<string,int|string|string[]> $array_query';
94if (empty($template_id)) {
95 $advTarget->fk_element =
$id;
96 $advTarget->type_element =
'mailing';
97 $result = $advTarget->fetch_by_mailing();
99 $result = $advTarget->fetch($template_id);
105 if (!empty($advTarget->id)) {
106 $array_query = json_decode($advTarget->filtervalue,
true);
111if (!$user->hasRight(
'mailing',
'lire') || (!
getDolGlobalString(
'EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
116$permissiontoread = $user->hasRight(
'mailing',
'lire');
117$permissiontoadd = $user->hasRight(
'mailing',
'creer');
124if ($action ==
'loadfilter' && $permissiontoread) {
125 if (!empty($template_id)) {
126 $result = $advTarget->fetch($template_id);
130 if (!empty($advTarget->id)) {
131 $array_query = json_decode($advTarget->filtervalue,
true);
137if ($action ==
'add' && $permissiontoadd) {
138 $user_contact_query =
false;
140 $array_query = array();
144 foreach ($_POST as $key => $value) {
146 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
148 if (preg_match(
"/st_dt/", $key)) {
150 $dtarr = explode(
'_', $key);
151 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
152 $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'));
154 } elseif (preg_match(
"/end_dt/", $key)) {
157 $dtarr = explode(
'_', $key);
158 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
159 $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'));
162 $array_query[$key] =
GETPOST($key);
165 if (preg_match(
"/^options_.*_cnct/", $key)) {
166 $user_contact_query =
true;
168 if (preg_match(
"/st_dt/", $key)) {
170 $dtarr = explode(
'_', $key);
171 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
172 $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'));
174 } elseif (preg_match(
"/end_dt/", $key)) {
177 $dtarr = explode(
'_', $key);
178 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
179 $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'));
182 $array_query[$key] =
GETPOST($key);
186 if (preg_match(
"/^cust_/", $key)) {
187 $array_query[$key] =
GETPOST($key);
190 if (preg_match(
"/^contact_/", $key)) {
191 $array_query[$key] =
GETPOST($key);
193 $specials_date_key = array(
194 'contact_update_st_dt',
195 'contact_update_end_dt',
196 'contact_create_st_dt',
197 'contact_create_end_dt'
199 foreach ($specials_date_key as $date_key) {
200 if ($key == $date_key) {
205 $array_query[$key] =
'';
210 if (!empty($array_query[$key])) {
211 $user_contact_query =
true;
215 if ($array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4) {
216 $user_contact_query =
true;
219 if (preg_match(
"/^type_of_target/", $key)) {
220 $array_query[$key] =
GETPOST($key);
225 $result = $advTarget->query_thirdparty($array_query);
233 if ($user_contact_query && ($array_query[
'type_of_target'] == 1 || $array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4)) {
234 $result = $advTarget->query_contact($array_query, 1);
239 if (count($advTarget->contact_lines) == 0) {
240 $advTarget->contact_lines = array(
245 $advTarget->contact_lines = array();
248 $mailingadvthirdparties =
null;
249 if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
252 $result = $mailingadvthirdparties->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query[
'type_of_target'], $advTarget->contact_lines);
258 $query_temlate_id =
'';
259 if (!empty($template_id)) {
260 $query_temlate_id =
'&template_id='.$template_id;
263 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$id.$query_temlate_id);
269 if ($result < 0 && is_object($mailingadvthirdparties)) {
270 setEventMessages($mailingadvthirdparties->error, $mailingadvthirdparties->errors,
'errors');
274if ($action ==
'clear' && $permissiontoadd) {
276 $mailingtargets->clear_target($id);
278 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
282if (($action ==
'savefilter' || $action ==
'createfilter') && $permissiontoadd) {
283 $template_name =
GETPOST(
'template_name');
286 if ($action ==
'createfilter' && empty($template_name) && $permissiontoadd) {
287 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'AdvTgtOrCreateNewFilter')),
null,
'errors');
292 $array_query = array();
295 foreach ($_POST as $key => $value) {
296 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
298 if (preg_match(
"/st_dt/", $key)) {
300 $dtarr = explode(
'_', $key);
301 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
302 $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'));
304 } elseif (preg_match(
"/end_dt/", $key)) {
307 $dtarr = explode(
'_', $key);
308 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
309 $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'));
314 $array_query[$key] =
GETPOST($key);
317 if (preg_match(
"/^options_.*_cnct/", $key)) {
319 if (preg_match(
"/st_dt/", $key)) {
321 $dtarr = explode(
'_', $key);
322 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
323 $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'));
325 } elseif (preg_match(
"/end_dt/", $key)) {
328 $dtarr = explode(
'_', $key);
329 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
330 $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'));
335 $array_query[$key] =
GETPOST($key);
339 if (preg_match(
"/^cust_/", $key)) {
340 $array_query[$key] =
GETPOST($key);
343 if (preg_match(
"/^contact_/", $key)) {
344 $array_query[$key] =
GETPOST($key);
346 $specials_date_key = array(
347 'contact_update_st_dt',
348 'contact_update_end_dt',
349 'contact_create_st_dt',
350 'contact_create_end_dt'
352 foreach ($specials_date_key as $date_key) {
353 if ($key == $date_key) {
358 $array_query[$key] =
'';
364 if (preg_match(
"/^type_of_target/", $key)) {
365 $array_query[$key] =
GETPOST($key);
368 $advTarget->filtervalue = json_encode($array_query);
370 if ($action ==
'createfilter') {
371 $advTarget->name = $template_name;
372 $result = $advTarget->create($user);
376 } elseif ($action ==
'savefilter') {
377 $result = $advTarget->update($user);
382 $template_id = $advTarget->id;
386if ($action ==
'deletefilter' && $permissiontoadd) {
387 $result = $advTarget->delete($user);
391 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
395if ($action ==
'delete' && $permissiontoadd) {
397 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE rowid = ".((int) $rowid);
398 $resql = $db->query($sql);
402 $mailingtargets->update_nb($id);
404 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
407 header(
"Location: liste.php");
415if (
GETPOST(
"button_removefilter")) {
426llxHeader(
'', $langs->trans(
"MailAdvTargetRecipients"));
428$form =
new Form($db);
438 print
'<table class="border centpercent">';
440 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/liste.php">'.$langs->trans(
"BackToList").
'</a>';
442 print
'<tr><td>'.$langs->trans(
"Ref").
'</td>';
443 print
'<td colspan="3">';
444 print $form->showrefnav($object,
'id', $linkback);
447 print
'<tr><td>'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.
$object->title.
'</td></tr>';
449 print
'<tr><td>'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email(
$object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
452 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email(
$object->email_errorsto, 0, 0, 0, 0, 1);
456 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td colspan="3">'.
$object->getLibStatut(4).
'</td></tr>';
460 print $langs->trans(
"TotalNbOfDistinctRecipients");
461 print
'</td><td colspan="3">';
464 $text = $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
466 print $form->textwithpicto($nbemail, $text, 1,
'warning');
477 if (
$object->status == 0 && $user->hasRight(
'mailing',
'creer')) {
482 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.