25if (!defined(
'NOSTYLECHECK')) {
26 define(
'NOSTYLECHECK',
'1');
30require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/advtargetemailing.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/html.formadvtargetemailing.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/advthirdparties.modules.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
41$langs->loadLangs(array(
'mails',
'companies'));
42if (isModEnabled(
'categorie')) {
43 $langs->load(
"categories");
47$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
48$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
49$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
50$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
51if (empty($page) || $page == -1) {
54$offset = $limit * $page;
65$rowid =
GETPOST(
'rowid',
'int');
66$action =
GETPOST(
'action',
'aZ09');
67$search_nom =
GETPOST(
"search_nom");
68$search_prenom =
GETPOST(
"search_prenom");
69$search_email =
GETPOST(
"search_email");
70$template_id =
GETPOST(
'template_id',
'int');
73if (
GETPOST(
'button_removefilter_x',
'alpha')) {
78$array_query = array();
82if (empty($template_id)) {
83 $advTarget->fk_element = $id;
84 $advTarget->type_element =
'mailing';
85 $result = $advTarget->fetch_by_mailing();
87 $result = $advTarget->fetch($template_id);
93 if (!empty($advTarget->id)) {
94 $array_query = json_decode($advTarget->filtervalue,
true);
99if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
109if ($action ==
'loadfilter') {
110 if (!empty($template_id)) {
111 $result = $advTarget->fetch($template_id);
115 if (!empty($advTarget->id)) {
116 $array_query = json_decode($advTarget->filtervalue,
true);
122if ($action ==
'add') {
123 $user_contact_query =
false;
125 $array_query = array();
129 foreach ($_POST as $key => $value) {
131 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
133 if (preg_match(
"/st_dt/", $key)) {
135 $dtarr = explode(
'_', $key);
136 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
137 $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'));
139 } elseif (preg_match(
"/end_dt/", $key)) {
142 $dtarr = explode(
'_', $key);
143 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
144 $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'));
147 $array_query[$key] =
GETPOST($key);
150 if (preg_match(
"/^options_.*_cnct/", $key)) {
151 $user_contact_query =
true;
153 if (preg_match(
"/st_dt/", $key)) {
155 $dtarr = explode(
'_', $key);
156 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
157 $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'));
159 } elseif (preg_match(
"/end_dt/", $key)) {
162 $dtarr = explode(
'_', $key);
163 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
164 $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'));
167 $array_query[$key] =
GETPOST($key);
171 if (preg_match(
"/^cust_/", $key)) {
172 $array_query[$key] =
GETPOST($key);
175 if (preg_match(
"/^contact_/", $key)) {
176 $array_query[$key] =
GETPOST($key);
178 $specials_date_key = array(
179 'contact_update_st_dt',
180 'contact_update_end_dt',
181 'contact_create_st_dt',
182 'contact_create_end_dt'
184 foreach ($specials_date_key as $date_key) {
185 if ($key == $date_key) {
190 $array_query[$key] =
'';
195 if (!empty($array_query[$key])) {
196 $user_contact_query =
true;
200 if ($array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4) {
201 $user_contact_query =
true;
204 if (preg_match(
"/^type_of_target/", $key)) {
205 $array_query[$key] =
GETPOST($key);
210 $result = $advTarget->query_thirdparty($array_query);
218 if ($user_contact_query && ($array_query[
'type_of_target'] == 1 || $array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4)) {
219 $result = $advTarget->query_contact($array_query, 1);
224 if (count($advTarget->contact_lines) == 0) {
225 $advTarget->contact_lines = array(
230 $advTarget->contact_lines = array();
233 if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
236 $result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query[
'type_of_target'], $advTarget->contact_lines);
242 $query_temlate_id =
'';
243 if (!empty($template_id)) {
244 $query_temlate_id =
'&template_id='.$template_id;
247 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id.$query_temlate_id);
258if ($action ==
'clear') {
260 $classname =
"MailingTargets";
261 $obj =
new $classname($db);
262 $obj->clear_target($id);
264 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
268if ($action ==
'savefilter' || $action ==
'createfilter') {
269 $template_name =
GETPOST(
'template_name');
272 if ($action ==
'createfilter' && empty($template_name)) {
273 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'AdvTgtOrCreateNewFilter')),
null,
'errors');
278 $array_query = array();
281 foreach ($_POST as $key => $value) {
282 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
284 if (preg_match(
"/st_dt/", $key)) {
286 $dtarr = explode(
'_', $key);
287 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
288 $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'));
290 } elseif (preg_match(
"/end_dt/", $key)) {
293 $dtarr = explode(
'_', $key);
294 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
295 $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'));
300 $array_query[$key] =
GETPOST($key);
303 if (preg_match(
"/^options_.*_cnct/", $key)) {
305 if (preg_match(
"/st_dt/", $key)) {
307 $dtarr = explode(
'_', $key);
308 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
309 $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'));
311 } elseif (preg_match(
"/end_dt/", $key)) {
314 $dtarr = explode(
'_', $key);
315 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
316 $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'));
321 $array_query[$key] =
GETPOST($key);
325 if (preg_match(
"/^cust_/", $key)) {
326 $array_query[$key] =
GETPOST($key);
329 if (preg_match(
"/^contact_/", $key)) {
330 $array_query[$key] =
GETPOST($key);
332 $specials_date_key = array(
333 'contact_update_st_dt',
334 'contact_update_end_dt',
335 'contact_create_st_dt',
336 'contact_create_end_dt'
338 foreach ($specials_date_key as $date_key) {
339 if ($key == $date_key) {
344 $array_query[$key] =
'';
350 if (preg_match(
"/^type_of_target/", $key)) {
351 $array_query[$key] =
GETPOST($key);
354 $advTarget->filtervalue = json_encode($array_query);
356 if ($action ==
'createfilter') {
357 $advTarget->name = $template_name;
358 $result = $advTarget->create($user);
362 } elseif ($action ==
'savefilter') {
363 $result = $advTarget->update($user);
368 $template_id = $advTarget->id;
372if ($action ==
'deletefilter') {
373 $result = $advTarget->delete($user);
377 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
381if ($action ==
'delete') {
383 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE rowid = ".((int) $rowid);
384 $resql = $db->query($sql);
387 $classname =
"MailingTargets";
388 $obj =
new $classname($db);
389 $obj->update_nb($id);
391 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
394 header(
"Location: liste.php");
402if (
GETPOST(
"button_removefilter")) {
412llxHeader(
'', $langs->trans(
"MailAdvTargetRecipients"));
414$form =
new Form($db);
419if ($object->fetch($id) >= 0) {
424 print
'<table class="border centpercent">';
426 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/liste.php">'.$langs->trans(
"BackToList").
'</a>';
428 print
'<tr><td>'.$langs->trans(
"Ref").
'</td>';
429 print
'<td colspan="3">';
430 print $form->showrefnav($object,
'id', $linkback);
433 print
'<tr><td>'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.$object->title.
'</td></tr>';
435 print
'<tr><td>'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email($object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
438 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
442 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td colspan="3">'.$object->getLibStatut(4).
'</td></tr>';
446 print $langs->trans(
"TotalNbOfDistinctRecipients");
447 print
'</td><td colspan="3">';
448 $nbemail = ($object->nbemail ? $object->nbemail :
'0');
449 if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
450 $text = $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
451 print $form->textwithpicto($nbemail, $text, 1,
'warning');
462 if ($object->statut == 0 && $user->rights->mailing->creer) {
463 include DOL_DOCUMENT_ROOT.
'/core/tpl/advtarget.tpl.php';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage advanced emailing target selector.
Class to manage emailings module.
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 informations (by default a local PHP server timestamp) Re...
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_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.