25 if (!defined(
'NOSTYLECHECK')) define(
'NOSTYLECHECK',
'1');
27 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/advtargetemailing.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/html.formadvtargetemailing.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/advthirdparties.modules.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
38 $langs->loadLangs(array(
'mails',
'companies'));
39 if (!empty($conf->categorie->enabled)) {
40 $langs->load(
"categories");
44 if (!$user->rights->mailing->lire || $user->socid > 0)
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
50 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52 if (empty($page) || $page == -1) { $page = 0; }
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
62 $rowid =
GETPOST(
'rowid',
'int');
63 $action =
GETPOST(
'action',
'aZ09');
64 $search_nom =
GETPOST(
"search_nom");
65 $search_prenom =
GETPOST(
"search_prenom");
66 $search_email =
GETPOST(
"search_email");
67 $template_id =
GETPOST(
'template_id',
'int');
70 if (
GETPOST(
'button_removefilter_x',
'alpha')) {
75 $array_query = array();
79 if (empty($template_id)) {
80 $advTarget->fk_element = $id;
81 $advTarget->type_element =
'mailing';
82 $result = $advTarget->fetch_by_mailing();
84 $result = $advTarget->fetch($template_id);
91 if (!empty($advTarget->id)) {
92 $array_query = json_decode($advTarget->filtervalue,
true);
101 if ($action ==
'loadfilter') {
102 if (!empty($template_id)) {
103 $result = $advTarget->fetch($template_id);
107 if (!empty($advTarget->id)) {
108 $array_query = json_decode($advTarget->filtervalue,
true);
114 if ($action ==
'add') {
115 $user_contact_query =
false;
117 $array_query = array();
121 foreach ($_POST as $key => $value) {
123 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
125 if (preg_match(
"/st_dt/", $key)) {
127 $dtarr = explode(
'_', $key);
128 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
129 $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'));
131 } elseif (preg_match(
"/end_dt/", $key)) {
134 $dtarr = explode(
'_', $key);
135 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
136 $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'));
139 $array_query[$key] =
GETPOST($key);
142 if (preg_match(
"/^options_.*_cnct/", $key)) {
143 $user_contact_query =
true;
145 if (preg_match(
"/st_dt/", $key)) {
147 $dtarr = explode(
'_', $key);
148 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
149 $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'));
151 } elseif (preg_match(
"/end_dt/", $key)) {
154 $dtarr = explode(
'_', $key);
155 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
156 $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'));
159 $array_query[$key] =
GETPOST($key);
163 if (preg_match(
"/^cust_/", $key)) {
164 $array_query[$key] =
GETPOST($key);
167 if (preg_match(
"/^contact_/", $key)) {
168 $array_query[$key] =
GETPOST($key);
170 $specials_date_key = array(
171 'contact_update_st_dt',
172 'contact_update_end_dt',
173 'contact_create_st_dt',
174 'contact_create_end_dt'
176 foreach ($specials_date_key as $date_key) {
177 if ($key == $date_key) {
182 $array_query[$key] =
'';
187 if (!empty($array_query[$key])) {
188 $user_contact_query =
true;
192 if ($array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4) {
193 $user_contact_query =
true;
196 if (preg_match(
"/^type_of_target/", $key)) {
197 $array_query[$key] =
GETPOST($key);
202 $result = $advTarget->query_thirdparty($array_query);
210 if ($user_contact_query && ($array_query[
'type_of_target'] == 1 || $array_query[
'type_of_target'] == 2 || $array_query[
'type_of_target'] == 4)) {
211 $result = $advTarget->query_contact($array_query, 1);
216 if (count($advTarget->contact_lines) == 0) {
217 $advTarget->contact_lines = array(
222 $advTarget->contact_lines = array();
225 if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
228 $result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query[
'type_of_target'], $advTarget->contact_lines);
234 $query_temlate_id =
'';
235 if (!empty($template_id)) {
236 $query_temlate_id =
'&template_id='.$template_id;
239 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$id.$query_temlate_id);
250 if ($action ==
'clear') {
252 $classname =
"MailingTargets";
253 $obj =
new $classname($db);
254 $obj->clear_target($id);
256 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$id);
260 if ($action ==
'savefilter' || $action ==
'createfilter') {
261 $template_name =
GETPOST(
'template_name');
264 if ($action ==
'createfilter' && empty($template_name)) {
265 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'AdvTgtOrCreateNewFilter')), null,
'errors');
270 $array_query = array();
273 foreach ($_POST as $key => $value) {
274 if (preg_match(
"/^options_.*(?<!_cnct)$/", $key)) {
276 if (preg_match(
"/st_dt/", $key)) {
278 $dtarr = explode(
'_', $key);
279 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt', $array_query)) {
280 $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'));
282 } elseif (preg_match(
"/end_dt/", $key)) {
285 $dtarr = explode(
'_', $key);
286 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt', $array_query)) {
287 $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'));
292 $array_query[$key] =
GETPOST($key);
295 if (preg_match(
"/^options_.*_cnct/", $key)) {
297 if (preg_match(
"/st_dt/", $key)) {
299 $dtarr = explode(
'_', $key);
300 if (!array_key_exists(
'options_'.$dtarr[1].
'_st_dt_cnct', $array_query)) {
301 $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'));
303 } elseif (preg_match(
"/end_dt/", $key)) {
306 $dtarr = explode(
'_', $key);
307 if (!array_key_exists(
'options_'.$dtarr[1].
'_end_dt_cnct', $array_query)) {
308 $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'));
313 $array_query[$key] =
GETPOST($key);
317 if (preg_match(
"/^cust_/", $key)) {
318 $array_query[$key] =
GETPOST($key);
321 if (preg_match(
"/^contact_/", $key)) {
322 $array_query[$key] =
GETPOST($key);
324 $specials_date_key = array(
325 'contact_update_st_dt',
326 'contact_update_end_dt',
327 'contact_create_st_dt',
328 'contact_create_end_dt'
330 foreach ($specials_date_key as $date_key) {
331 if ($key == $date_key) {
336 $array_query[$key] =
'';
342 if (preg_match(
"/^type_of_target/", $key)) {
343 $array_query[$key] =
GETPOST($key);
346 $advTarget->filtervalue = json_encode($array_query);
348 if ($action ==
'createfilter') {
349 $advTarget->name = $template_name;
350 $result = $advTarget->create($user);
354 } elseif ($action ==
'savefilter') {
355 $result = $advTarget->update($user);
360 $template_id = $advTarget->id;
364 if ($action ==
'deletefilter') {
365 $result = $advTarget->delete($user);
369 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$id);
373 if ($action ==
'delete') {
375 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE rowid=".$rowid;
376 $resql = $db->query($sql);
379 $classname =
"MailingTargets";
380 $obj =
new $classname($db);
381 $obj->update_nb($id);
383 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$id);
386 header(
"Location: liste.php");
394 if ($_POST[
"button_removefilter"]) {
406 llxHeader(
'', $langs->trans(
"MailAdvTargetRecipients"));
410 $form =
new Form($db);
415 if ($object->fetch($id) >= 0) {
420 print '<table class="border centpercent">';
422 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/liste.php">'.$langs->trans(
"BackToList").
'</a>';
424 print
'<tr><td>'.$langs->trans(
"Ref").
'</td>';
425 print
'<td colspan="3">';
426 print $form->showrefnav($object,
'id', $linkback);
429 print
'<tr><td>'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.$object->title.
'</td></tr>';
431 print
'<tr><td>'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email($object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
434 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
438 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td colspan="3">'.$object->getLibStatut(4).
'</td></tr>';
442 print $langs->trans(
"TotalNbOfDistinctRecipients");
443 print
'</td><td colspan="3">';
444 $nbemail = ($object->nbemail ? $object->nbemail :
'0');
445 if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
446 $text = $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
447 print $form->textwithpicto($nbemail, $text, 1,
'warning');
458 if ($object->statut == 0 && $user->rights->mailing->creer) {
459 include DOL_DOCUMENT_ROOT.
'/core/tpl/advtarget.tpl.php';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
Class to manage a list of personalised recipients for mailing feature.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
emailing_prepare_head(Mailing $object)
Prepare array with list of tabs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage emailings module.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Class to manage advanced emailing target selector.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
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.