* Copyright (C) 2016 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/comm/mailing/advtargetemailing.php * \ingroup mailing * \brief Page to define emailing targets */ if (!defined('NOSTYLECHECK')) { define('NOSTYLECHECK', '1'); } // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php'; require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/advtargetemailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/html.formadvtargetemailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/advthirdparties.modules.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; // Load translation files required by the page $langs->loadLangs(array('mails', 'companies')); if (isModEnabled('categorie')) { $langs->load("categories"); } // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { $sortorder = "ASC"; } if (!$sortfield) { $sortfield = "email"; } $id = GETPOST('id', 'int'); $rowid = GETPOST('rowid', 'int'); $action = GETPOST('action', 'aZ09'); $search_nom = GETPOST("search_nom"); $search_prenom = GETPOST("search_prenom"); $search_email = GETPOST("search_email"); $template_id = GETPOST('template_id', 'int'); // Do we click on purge search criteria ? if (GETPOST('button_removefilter_x', 'alpha')) { $search_nom = ''; $search_prenom = ''; $search_email = ''; } $array_query = array(); $object = new Mailing($db); $advTarget = new AdvanceTargetingMailing($db); if (empty($template_id)) { $advTarget->fk_element = $id; $advTarget->type_element = 'mailing'; $result = $advTarget->fetch_by_mailing(); } else { $result = $advTarget->fetch($template_id); } if ($result < 0) { setEventMessages($advTarget->error, $advTarget->errors, 'errors'); } else { if (!empty($advTarget->id)) { $array_query = json_decode($advTarget->filtervalue, true); } } // Security check if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) { accessforbidden(); } //$result = restrictedArea($user, 'mailing'); /* * Actions */ if ($action == 'loadfilter') { if (!empty($template_id)) { $result = $advTarget->fetch($template_id); if ($result < 0) { setEventMessages($advTarget->error, $advTarget->errors, 'errors'); } else { if (!empty($advTarget->id)) { $array_query = json_decode($advTarget->filtervalue, true); } } } } if ($action == 'add') { $user_contact_query = false; $array_query = array(); // Get extra fields foreach ($_POST as $key => $value) { // print '$key='.$key.' $value='.$value.'
'; if (preg_match("/^options_.*(?query_thirdparty($array_query); if ($result < 0) { setEventMessages($advTarget->error, $advTarget->errors, 'errors'); } /*} else { $advTarget->thirdparty_lines = array (); }*/ if ($user_contact_query && ($array_query['type_of_target'] == 1 || $array_query['type_of_target'] == 2 || $array_query['type_of_target'] == 4)) { $result = $advTarget->query_contact($array_query, 1); if ($result < 0) { setEventMessages($advTarget->error, $advTarget->errors, 'errors'); } // If use contact but no result use artefact to so not use socid into add_to_target if (count($advTarget->contact_lines) == 0) { $advTarget->contact_lines = array( 0 ); } } else { $advTarget->contact_lines = array(); } if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) { // Add targets into database $obj = new mailing_advthirdparties($db); $result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query['type_of_target'], $advTarget->contact_lines); } else { $result = 0; } if ($result > 0) { $query_temlate_id = ''; if (!empty($template_id)) { $query_temlate_id = '&template_id='.$template_id; } setEventMessages($langs->trans("XTargetsAdded", $result), null, 'mesgs'); header("Location: ".$_SERVER['PHP_SELF']."?id=".$id.$query_temlate_id); exit(); } if ($result == 0) { setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings'); } if ($result < 0) { setEventMessages($obj->error, $obj->errors, 'errors'); } } if ($action == 'clear') { // Chargement de la classe $classname = "MailingTargets"; $obj = new $classname($db); $obj->clear_target($id); header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit(); } if ($action == 'savefilter' || $action == 'createfilter') { $template_name = GETPOST('template_name'); $error = 0; if ($action == 'createfilter' && empty($template_name)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('AdvTgtOrCreateNewFilter')), null, 'errors'); $error++; } if (empty($error)) { $array_query = array(); // Get extra fields foreach ($_POST as $key => $value) { if (preg_match("/^options_.*(?filtervalue = json_encode($array_query); if ($action == 'createfilter') { $advTarget->name = $template_name; $result = $advTarget->create($user); if ($result < 0) { setEventMessages($advTarget->error, $advTarget->errors, 'errors'); } } elseif ($action == 'savefilter') { $result = $advTarget->update($user); if ($result < 0) { setEventMessages($advTarget->error, $advTarget->errors, 'errors'); } } $template_id = $advTarget->id; } } if ($action == 'deletefilter') { $result = $advTarget->delete($user); if ($result < 0) { setEventMessages($advTarget->error, $advTarget->errors, 'errors'); } header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit(); } if ($action == 'delete') { // Ici, rowid indique le destinataire et id le mailing $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid = ".((int) $rowid); $resql = $db->query($sql); if ($resql) { if (!empty($id)) { $classname = "MailingTargets"; $obj = new $classname($db); $obj->update_nb($id); header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit(); } else { header("Location: liste.php"); exit(); } } else { dol_print_error($db); } } if (GETPOST("button_removefilter")) { $search_nom = ''; $search_prenom = ''; $search_email = ''; } /* * View */ llxHeader('', $langs->trans("MailAdvTargetRecipients")); $form = new Form($db); $formadvtargetemaling = new FormAdvTargetEmailing($db); $formcompany = new FormCompany($db); $formother = new FormOther($db); if ($object->fetch($id) >= 0) { $head = emailing_prepare_head($object); print dol_get_fiche_head($head, 'advtargets', $langs->trans("Mailing"), 0, 'email'); print ''; $linkback = ''.$langs->trans("BackToList").''; print ''; print ''; print ''; print ''; // Errors to print ''; // Status print ''; // Nb of distinct emails print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($object, 'id', $linkback); print '
'.$langs->trans("MailTitle").''.$object->title.'
'.$langs->trans("MailFrom").''.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'
'.$langs->trans("MailErrorsTo").''.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1); print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'; print $langs->trans("TotalNbOfDistinctRecipients"); print ''; $nbemail = ($object->nbemail ? $object->nbemail : '0'); if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) { $text = $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB); print $form->textwithpicto($nbemail, $text, 1, 'warning'); } else { print $nbemail; } print '
'; print ""; // Show email selectors if ($object->statut == 0 && $user->rights->mailing->creer) { include DOL_DOCUMENT_ROOT.'/core/tpl/advtarget.tpl.php'; } } // End of page llxFooter(); $db->close();