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(
'category')) {
43 $langs->load(
"categories");
48$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
49$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
51if (empty($page) || $page == -1) {
54$offset = $limit * $page;
66$action =
GETPOST(
'action',
'aZ09');
67$search_nom =
GETPOST(
"search_nom");
68$search_prenom =
GETPOST(
"search_prenom");
69$search_email =
GETPOST(
"search_email");
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->hasRight(
'mailing',
'lire') || (!
getDolGlobalString(
'EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
104$permissiontoread = $user->hasRight(
'mailing',
'lire');
105$permissiontoadd = $user->hasRight(
'mailing',
'creer');
112if ($action ==
'loadfilter' && $permissiontoread) {
113 if (!empty($template_id)) {
114 $result = $advTarget->fetch($template_id);
118 if (!empty($advTarget->id)) {
119 $array_query = json_decode($advTarget->filtervalue,
true);
125if ($action ==
'add' && $permissiontoadd) {
126 $user_contact_query =
false;
128 $array_query = array();
132 foreach ($_POST as $key => $value) {
134 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
136 if (preg_match(
"/st_dt/", $key)) {
138 $dtarr = explode(
'_', $key);
139 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
140 $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'));
142 } elseif (preg_match(
"/end_dt/", $key)) {
145 $dtarr = explode(
'_', $key);
146 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
147 $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'));
150 $array_query[$key] =
GETPOST($key);
153 if (preg_match(
"/^options_.*_cnct/", $key)) {
154 $user_contact_query =
true;
156 if (preg_match(
"/st_dt/", $key)) {
158 $dtarr = explode(
'_', $key);
159 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
160 $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'));
162 } elseif (preg_match(
"/end_dt/", $key)) {
165 $dtarr = explode(
'_', $key);
166 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
167 $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'));
170 $array_query[$key] =
GETPOST($key);
174 if (preg_match(
"/^cust_/", $key)) {
175 $array_query[$key] =
GETPOST($key);
178 if (preg_match(
"/^contact_/", $key)) {
179 $array_query[$key] =
GETPOST($key);
181 $specials_date_key = array(
182 'contact_update_st_dt',
183 'contact_update_end_dt',
184 'contact_create_st_dt',
185 'contact_create_end_dt'
187 foreach ($specials_date_key as $date_key) {
188 if ($key == $date_key) {
193 $array_query[$key] =
'';
198 if (!empty($array_query[$key])) {
199 $user_contact_query =
true;
203 if ($array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4) {
204 $user_contact_query =
true;
207 if (preg_match(
"/^type_of_target/", $key)) {
208 $array_query[$key] =
GETPOST($key);
213 $result = $advTarget->query_thirdparty($array_query);
221 if ($user_contact_query && ($array_query[
'type_of_target'] == 1 || $array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4)) {
222 $result = $advTarget->query_contact($array_query, 1);
227 if (count($advTarget->contact_lines) == 0) {
228 $advTarget->contact_lines = array(
233 $advTarget->contact_lines = array();
236 if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
239 $result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query[
'type_of_target'], $advTarget->contact_lines);
245 $query_temlate_id =
'';
246 if (!empty($template_id)) {
247 $query_temlate_id =
'&template_id='.$template_id;
250 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id.$query_temlate_id);
261if ($action ==
'clear' && $permissiontoadd) {
263 $classname =
"MailingTargets";
264 $obj =
new $classname($db);
265 $obj->clear_target($id);
267 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
271if (($action ==
'savefilter' || $action ==
'createfilter') && $permissiontoadd) {
272 $template_name =
GETPOST(
'template_name');
275 if ($action ==
'createfilter' && empty($template_name) && $permissiontoadd) {
276 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'AdvTgtOrCreateNewFilter')),
null,
'errors');
281 $array_query = array();
284 foreach ($_POST as $key => $value) {
285 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
287 if (preg_match(
"/st_dt/", $key)) {
289 $dtarr = explode(
'_', $key);
290 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
291 $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'));
293 } elseif (preg_match(
"/end_dt/", $key)) {
296 $dtarr = explode(
'_', $key);
297 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
298 $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'));
303 $array_query[$key] =
GETPOST($key);
306 if (preg_match(
"/^options_.*_cnct/", $key)) {
308 if (preg_match(
"/st_dt/", $key)) {
310 $dtarr = explode(
'_', $key);
311 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
312 $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'));
314 } elseif (preg_match(
"/end_dt/", $key)) {
317 $dtarr = explode(
'_', $key);
318 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
319 $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'));
324 $array_query[$key] =
GETPOST($key);
328 if (preg_match(
"/^cust_/", $key)) {
329 $array_query[$key] =
GETPOST($key);
332 if (preg_match(
"/^contact_/", $key)) {
333 $array_query[$key] =
GETPOST($key);
335 $specials_date_key = array(
336 'contact_update_st_dt',
337 'contact_update_end_dt',
338 'contact_create_st_dt',
339 'contact_create_end_dt'
341 foreach ($specials_date_key as $date_key) {
342 if ($key == $date_key) {
347 $array_query[$key] =
'';
353 if (preg_match(
"/^type_of_target/", $key)) {
354 $array_query[$key] =
GETPOST($key);
357 $advTarget->filtervalue = json_encode($array_query);
359 if ($action ==
'createfilter') {
360 $advTarget->name = $template_name;
361 $result = $advTarget->create($user);
365 } elseif ($action ==
'savefilter') {
366 $result = $advTarget->update($user);
371 $template_id = $advTarget->id;
375if ($action ==
'deletefilter' && $permissiontoadd) {
376 $result = $advTarget->delete($user);
380 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
384if ($action ==
'delete' && $permissiontoadd) {
386 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE rowid = ".((int) $rowid);
387 $resql = $db->query($sql);
390 $classname =
"MailingTargets";
391 $obj =
new $classname($db);
392 $obj->update_nb($id);
394 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
397 header(
"Location: liste.php");
405if (
GETPOST(
"button_removefilter")) {
416llxHeader(
'', $langs->trans(
"MailAdvTargetRecipients"));
418$form =
new Form($db);
428 print
'<table class="border centpercent">';
430 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/liste.php">'.$langs->trans(
"BackToList").
'</a>';
432 print
'<tr><td>'.$langs->trans(
"Ref").
'</td>';
433 print
'<td colspan="3">';
434 print $form->showrefnav($object,
'id', $linkback);
437 print
'<tr><td>'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.
$object->title.
'</td></tr>';
439 print
'<tr><td>'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email(
$object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
442 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email(
$object->email_errorsto, 0, 0, 0, 0, 1);
446 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td colspan="3">'.
$object->getLibStatut(4).
'</td></tr>';
450 print $langs->trans(
"TotalNbOfDistinctRecipients");
451 print
'</td><td colspan="3">';
453 if (
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
454 $text = $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
456 print $form->textwithpicto($nbemail, $text, 1,
'warning');
467 if (
$object->status == 0 && $user->hasRight(
'mailing',
'creer')) {
468 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()
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 information (by default a local PHP server timestamp) Rep...
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)
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.
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 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.