dolibarr/htdocs/comm/mailing/cibles.php

732 lines
25 KiB
PHP
Raw Normal View History

2012-08-22 23:27:53 +02:00
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2021-07-31 17:20:48 +02:00
* Copyright (C) 2005-2021 Laurent Destailleur <eldy@uers.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
2005-01-05 16:26:05 +01:00
*
* 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
2005-01-05 16:26:05 +01:00
* (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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2005-01-05 16:26:05 +01:00
*/
/**
* \file htdocs/comm/mailing/cibles.php
* \ingroup mailing
2010-12-01 22:16:28 +01:00
* \brief Page to define emailing targets
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmailing.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2005-01-05 16:26:05 +01:00
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
$langs->load("mails");
// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST('sortfield', 'aZ09comma');
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-02-23 18:59:19 +01:00
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
2010-11-20 14:08:44 +01:00
$pageprev = $page - 1;
$pagenext = $page + 1;
2021-02-23 18:59:19 +01:00
if (!$sortfield) {
$sortfield = "mc.statut,email";
}
if (!$sortorder) {
$sortorder = "DESC,ASC";
}
$id = GETPOST('id', 'int');
$rowid = GETPOST('rowid', 'int');
$action = GETPOST('action', 'aZ09');
$search_lastname = GETPOST("search_lastname", 'alphanohtml');
$search_firstname = GETPOST("search_firstname", 'alphanohtml');
$search_email = GETPOST("search_email", 'alphanohtml');
$search_other = GETPOST("search_other", 'alphanohtml');
$search_dest_status = GETPOST('search_dest_status', 'int');
// Search modules dirs
2012-05-09 16:40:54 +02:00
$modulesdir = dolGetModulesDirs('/mailings');
$object = new Mailing($db);
$result = $object->fetch($id);
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('ciblescard', 'globalcard'));
2021-03-29 22:43:39 +02:00
// Security check
if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
accessforbidden();
}
//$result = restrictedArea($user, 'mailing');
/*
* Actions
*/
2009-08-12 14:59:14 +02:00
2021-02-23 18:59:19 +01:00
if ($action == 'add') {
$module = GETPOST("module", 'alpha');
$result = -1;
2009-01-26 22:57:14 +01:00
2021-02-23 18:59:19 +01:00
foreach ($modulesdir as $dir) {
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog("Scan directory ".$dir." for modules");
2009-01-26 22:57:14 +01:00
// Loading Class
$file = $dir."/".$module.".modules.php";
$classname = "mailing_".$module;
2009-01-26 22:57:14 +01:00
2021-02-23 18:59:19 +01:00
if (file_exists($file)) {
require_once $file;
2009-01-26 22:57:14 +01:00
// Add targets into database
$obj = new $classname($db);
dol_syslog("Call add_to_target on class ".$classname);
$result = $obj->add_to_target($id);
2009-01-26 22:57:14 +01:00
}
}
2021-02-23 18:59:19 +01:00
if ($result > 0) {
setEventMessages($langs->trans("XTargetsAdded", $result), null, 'mesgs');
$action = '';
2009-01-26 22:57:14 +01:00
}
2021-02-23 18:59:19 +01:00
if ($result == 0) {
2015-11-06 09:36:16 +01:00
setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings');
2009-01-26 22:57:14 +01:00
}
2021-02-23 18:59:19 +01:00
if ($result < 0) {
setEventMessages($langs->trans("Error").($obj->error ? ' '.$obj->error : ''), null, 'errors');
2009-01-26 22:57:14 +01:00
}
2005-01-05 16:26:05 +01:00
}
2021-02-23 18:59:19 +01:00
if (GETPOST('clearlist', 'int')) {
2015-11-06 09:36:16 +01:00
// Loading Class
$obj = new MailingTargets($db);
$obj->clear_target($id);
/* Avoid this to allow reposition
2012-08-31 05:58:38 +02:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
2009-01-26 22:57:14 +01:00
exit;
*/
}
2021-02-23 18:59:19 +01:00
if (GETPOST('exportcsv', 'int')) {
2019-10-13 15:00:07 +02:00
$completefilename = 'targets_emailing'.$object->id.'_'.dol_print_date(dol_now(), 'dayhourlog').'.csv';
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename='.$completefilename);
// List of selected targets
$sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut as status, mc.date_envoi, mc.tms,";
$sql .= " mc.source_id, mc.source_type, mc.error_text";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
$sql .= " WHERE mc.fk_mailing = ".((int) $object->id);
$sql .= $db->order($sortfield, $sortorder);
$resql = $db->query($sql);
2021-02-23 18:59:19 +01:00
if ($resql) {
$num = $db->num_rows($resql);
$sep = ',';
2021-02-23 18:59:19 +01:00
while ($obj = $db->fetch_object($resql)) {
print $obj->rowid.$sep;
print '"'.$obj->lastname.'"'.$sep;
print '"'.$obj->firstname.'"'.$sep;
print $obj->email.$sep;
print $obj->other.$sep;
print $obj->tms.$sep;
print $obj->source_type.$sep;
print $obj->source_id.$sep;
print $obj->date_envoi.$sep;
print $obj->status.$sep;
print '"'.$obj->error_text.'"'.$sep;
print "\n";
}
exit;
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
}
exit;
}
2021-02-23 18:59:19 +01:00
if ($action == 'delete') {
2009-01-26 22:57:14 +01:00
// Ici, rowid indique le destinataire et id le mailing
2021-04-24 20:18:11 +02:00
$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid = ".((int) $rowid);
$resql = $db->query($sql);
2021-02-23 18:59:19 +01:00
if ($resql) {
if (!empty($id)) {
$obj = new MailingTargets($db);
2012-06-15 11:20:09 +02:00
$obj->update_nb($id);
2012-11-17 00:58:43 +01:00
2019-05-21 21:47:25 +02:00
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
2020-05-21 15:05:19 +02:00
} else {
header("Location: list.php");
exit;
}
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
2009-01-26 22:57:14 +01:00
}
}
2017-08-25 21:12:22 +02:00
// Purge search criteria
2021-02-23 18:59:19 +01:00
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$search_lastname = '';
$search_firstname = '';
$search_email = '';
$search_other = '';
$search_dest_status = '';
}
2005-01-05 16:26:05 +01:00
/*
2009-08-12 14:59:14 +02:00
* View
2005-01-05 16:26:05 +01:00
*/
2018-01-29 12:58:33 +01:00
llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
2005-01-05 16:26:05 +01:00
$form = new Form($db);
$formmailing = new FormMailing($db);
2009-07-29 20:41:39 +02:00
2021-02-23 18:59:19 +01:00
if ($object->fetch($id) >= 0) {
$head = emailing_prepare_head($object);
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, 'targets', $langs->trans("Mailing"), -1, 'email');
$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2012-07-28 21:49:47 +02:00
$morehtmlright = '';
2018-01-29 12:46:07 +01:00
$nbtry = $nbok = 0;
2021-02-23 18:59:19 +01:00
if ($object->statut == 2 || $object->statut == 3) {
2018-01-29 12:46:07 +01:00
$nbtry = $object->countNbOfTargets('alreadysent');
$nbko = $object->countNbOfTargets('alreadysentko');
$nbok = ($nbtry - $nbko);
2018-01-29 12:46:07 +01:00
$morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail;
2021-02-23 18:59:19 +01:00
if ($nbko) {
$morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error");
}
$morehtmlright .= ') &nbsp; ';
2018-01-29 12:46:07 +01:00
}
2016-11-11 01:55:53 +01:00
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
print '<div class="fichecenter">';
2016-11-11 01:55:53 +01:00
print '<div class="underbanner clearboth"></div>';
2019-05-21 21:36:48 +02:00
print '<table class="border centpercent tableforfield">';
print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->title.'</td></tr>';
2009-07-29 20:41:39 +02:00
print '<tr><td>'.$langs->trans("MailFrom").'</td><td colspan="3">';
$emailarray = CMailFile::getArrayAddress($object->email_from);
foreach ($emailarray as $email => $name) {
if ($name && $name != $email) {
print dol_escape_htmltag($name).' &lt;'.$email;
print '&gt;';
if (!isValidEmail($email)) {
$langs->load("errors");
print img_warning($langs->trans("ErrorBadEMail", $email));
}
} else {
print dol_print_email($object->email_from, 0, 0, 0, 0, 1);
}
}
//print dol_print_email($object->email_from, 0, 0, 0, 0, 1);
//var_dump($object->email_from);
print '</td></tr>';
2009-07-29 20:41:39 +02:00
// Errors to
print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">';
$emailarray = CMailFile::getArrayAddress($object->email_errorsto);
foreach ($emailarray as $email => $name) {
if ($name != $email) {
print dol_escape_htmltag($name).' &lt;'.$email;
print '&gt;';
if (!isValidEmail($email)) {
$langs->load("errors");
print img_warning($langs->trans("ErrorBadEMail", $email));
}
} else {
print dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
}
}
2009-07-29 20:41:39 +02:00
print '</td></tr>';
// Nb of distinct emails
2016-07-06 22:28:13 +02:00
print '<tr><td>';
print $langs->trans("TotalNbOfDistinctRecipients");
print '</td><td colspan="3">';
$nbemail = ($object->nbemail ? $object->nbemail : 0);
2021-02-23 18:59:19 +01:00
if (is_numeric($nbemail)) {
$text = '';
2021-02-23 18:59:19 +01:00
if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
$text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
2020-05-21 15:05:19 +02:00
} else {
$text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
2018-01-26 15:12:40 +01:00
}
}
2021-02-23 18:59:19 +01:00
if (empty($nbemail)) {
$nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
2021-02-23 18:59:19 +01:00
}
if ($text) {
print $form->textwithpicto($nbemail, $text, 1, 'warning');
2020-05-21 15:05:19 +02:00
} else {
2018-01-26 15:12:40 +01:00
print $nbemail;
}
}
print '</td></tr>';
2009-07-29 20:41:39 +02:00
2009-01-26 22:57:14 +01:00
print '</table>';
print "</div>";
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2017-11-03 16:29:23 +01:00
print '<br>';
2009-01-26 22:57:14 +01:00
$allowaddtarget = ($object->statut == 0);
2013-06-12 22:12:06 +02:00
2010-12-13 19:40:04 +01:00
// Show email selectors
2021-02-23 18:59:19 +01:00
if ($allowaddtarget && $user->rights->mailing->creer) {
print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin ?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"), 1) : ''), 'generic');
2009-07-29 20:41:39 +02:00
2019-11-05 21:24:41 +01:00
//print '<table class="noborder centpercent">';
2022-01-31 12:02:48 +01:00
print '<div class="div-table-responsive">';
2018-03-02 11:18:29 +01:00
print '<div class="tagtable centpercent liste_titre_bydiv borderbottom" id="tablelines">';
//print '<tr class="liste_titre">';
print '<div class="tagtr liste_titre">';
//print '<td class="liste_titre">'.$langs->trans("RecipientSelectionModules").'</td>';
print '<div class="tagtd">'.$langs->trans("RecipientSelectionModules").'</div>';
//print '<td class="liste_titre" align="center">'.$langs->trans("NbOfUniqueEMails").'</td>';
print '<div class="tagtd" align="center">'.$langs->trans("NbOfUniqueEMails").'</div>';
//print '<td class="liste_titre" align="left">'.$langs->trans("Filter").'</td>';
2019-01-31 13:34:32 +01:00
print '<div class="tagtd left">'.$langs->trans("Filter").'</div>';
//print '<td class="liste_titre" align="center">&nbsp;</td>';
print '<div class="tagtd">&nbsp;</div>';
//print "</tr>\n";
2022-01-31 12:02:48 +01:00
print '</div>'; // End tr
2009-01-26 22:57:14 +01:00
clearstatcache();
2008-12-07 20:19:32 +01:00
2021-02-23 18:59:19 +01:00
foreach ($modulesdir as $dir) {
$modulenames = array();
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog("Scan directory ".$dir." for modules");
$handle = @opendir($dir);
2021-02-23 18:59:19 +01:00
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') {
2021-07-31 17:20:48 +02:00
$reg = array();
2021-02-23 18:59:19 +01:00
if (preg_match("/(.*)\.modules\.php$/i", $file, $reg)) {
if ($reg[1] == 'example') {
continue;
}
$modulenames[] = $reg[1];
2009-01-26 22:57:14 +01:00
}
}
}
closedir($handle);
}
// Sort $modulenames
2012-01-26 23:08:20 +01:00
sort($modulenames);
2018-08-29 11:57:43 +02:00
$var = true;
// Loop on each submodule
2021-02-23 18:59:19 +01:00
foreach ($modulenames as $modulename) {
2015-11-06 09:46:18 +01:00
// Loading Class
$file = $dir.$modulename.".modules.php";
$classname = "mailing_".$modulename;
require_once $file;
$obj = new $classname($db);
// Check if qualified
$qualified = (is_null($obj->enabled) ? 1 : dol_eval($obj->enabled, 1));
// Check dependencies
2021-02-23 18:59:19 +01:00
foreach ($obj->require_module as $key) {
if (empty($conf->$key->enabled) || (empty($user->admin) && $obj->require_admin)) {
$qualified = 0;
//print "Les prerequis d'activation du module mailing ne sont pas respectes. Il ne sera pas actif";
break;
}
}
// If module is qualified
2021-02-23 18:59:19 +01:00
if ($qualified) {
$var = !$var;
2021-02-23 18:59:19 +01:00
if ($allowaddtarget) {
2021-10-02 12:58:15 +02:00
print '<form '.$bctag[$var].' name="'.$modulename.'" action="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&module='.$modulename.'" method="POST" enctype="multipart/form-data">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2022-06-22 22:14:08 +02:00
print '<input type="hidden" name="page_y" value="'.newToken().'">';
2020-05-21 15:05:19 +02:00
} else {
print '<div '.$bctag[$var].'>';
}
print '<div class="tagtd">';
2021-02-23 18:59:19 +01:00
if (empty($obj->picto)) {
$obj->picto = 'generic';
}
print img_object($langs->trans("EmailingTargetSelector").': '.get_class($obj), $obj->picto, 'class="valignmiddle pictomodule"');
print ' ';
print $obj->getDesc();
print '</div>';
2014-08-25 19:32:36 +02:00
try {
$nbofrecipient = $obj->getNbOfRecipients('');
2021-02-23 18:59:19 +01:00
} catch (Exception $e) {
2014-08-25 19:32:36 +02:00
dol_syslog($e->getMessage(), LOG_ERR);
}
print '<div class="tagtd center">';
2022-05-29 09:58:36 +02:00
if ($nbofrecipient === '' || $nbofrecipient >= 0) {
print $nbofrecipient;
2020-05-21 15:05:19 +02:00
} else {
print $langs->trans("Error").' '.img_error($obj->error);
}
print '</div>';
2019-01-31 13:34:32 +01:00
print '<div class="tagtd left">';
2021-02-23 18:59:19 +01:00
if ($allowaddtarget) {
try {
$filter = $obj->formFilter();
2021-02-23 18:59:19 +01:00
} catch (Exception $e) {
dol_syslog($e->getMessage(), LOG_ERR);
}
2021-02-23 18:59:19 +01:00
if ($filter) {
print $filter;
} else {
print $langs->trans("None");
}
2014-08-25 19:32:36 +02:00
}
print '</div>';
2019-01-31 13:34:32 +01:00
print '<div class="tagtd right">';
2021-02-23 18:59:19 +01:00
if ($allowaddtarget) {
2022-06-22 22:14:08 +02:00
print '<input type="submit" class="button button-add small reposition" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
2020-05-21 15:05:19 +02:00
} else {
2022-01-31 12:02:48 +01:00
print '<input type="submit" class="button small disabled" disabled="disabled" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
//print $langs->trans("MailNoChangePossible");
print "&nbsp;";
}
print '</div>';
2021-02-23 18:59:19 +01:00
if ($allowaddtarget) {
print '</form>';
} else {
print '</div>';
}
2008-12-04 18:52:32 +01:00
}
2009-01-26 22:57:14 +01:00
}
} // End foreach dir
$parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
2022-01-31 12:02:48 +01:00
print '</div>'; // End table
print '</div>';
print '<br><br>';
2009-01-26 22:57:14 +01:00
}
2009-01-26 22:57:14 +01:00
// List of selected targets
$sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms,";
$sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text";
2009-01-26 22:57:14 +01:00
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2021-08-27 16:33:03 +02:00
$sql .= " WHERE mc.fk_mailing=".((int) $object->id);
$asearchcriteriahasbeenset = 0;
2021-02-23 18:59:19 +01:00
if ($search_lastname) {
$sql .= natural_search("mc.lastname", $search_lastname);
$asearchcriteriahasbeenset++;
}
if ($search_firstname) {
$sql .= natural_search("mc.firstname", $search_firstname);
$asearchcriteriahasbeenset++;
}
2021-02-23 18:59:19 +01:00
if ($search_email) {
$sql .= natural_search("mc.email", $search_email);
$asearchcriteriahasbeenset++;
}
2021-02-23 18:59:19 +01:00
if ($search_other) {
$sql .= natural_search("mc.other", $search_other);
$asearchcriteriahasbeenset++;
}
if ($search_dest_status != '' && $search_dest_status >= -1) {
$sql .= " AND mc.statut = ".((int) $search_dest_status);
$asearchcriteriahasbeenset++;
}
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
2021-02-23 18:59:19 +01:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
// Fix/update nbemail on emailing record if it differs (may happen if user edit lines from database directly)
if (empty($asearchcriteriahasbeenset)) {
if ($nbtotalofrecords != $object->nbemail) {
dol_syslog("We found a difference in nb of record in target table and the property ->nbemail, we fix ->nbemail");
//print "nbemail=".$object->nbemail." nbtotalofrecords=".$nbtotalofrecords;
$resultrefresh = $object->refreshNbOfTargets();
if ($resultrefresh < 0) {
dol_print_error($db, $object->error, $object->errors);
}
}
}
}
//$nbtotalofrecords=$object->nbemail; // nbemail is a denormalized field storing nb of targets
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
2021-02-23 18:59:19 +01:00
if ($resql) {
2009-01-26 22:57:14 +01:00
$num = $db->num_rows($resql);
2019-11-01 23:58:14 +01:00
$param = "&id=".$object->id;
2018-01-26 15:37:23 +01:00
//if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
2021-02-23 18:59:19 +01:00
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($search_lastname) {
$param .= "&search_lastname=".urlencode($search_lastname);
}
if ($search_firstname) {
$param .= "&search_firstname=".urlencode($search_firstname);
}
if ($search_email) {
$param .= "&search_email=".urlencode($search_email);
}
if ($search_other) {
$param .= "&search_other=".urlencode($search_other);
}
2013-04-10 18:34:19 +02:00
2013-06-12 22:12:06 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2013-06-12 22:12:06 +02:00
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
2013-06-12 22:12:06 +02:00
print '<input type="hidden" name="id" value="'.$object->id.'">';
$morehtmlcenter = '';
if ($allowaddtarget) {
2022-01-31 12:02:48 +01:00
$morehtmlcenter = '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ToClearAllRecipientsClickHere").'</span> <a href="'.$_SERVER["PHP_SELF"].'?clearlist=1&id='.$object->id.'" class="button reposition smallpaddingimp">'.$langs->trans("TargetsReset").'</a>';
}
2021-07-31 17:20:48 +02:00
$morehtmlcenter .= ' &nbsp; <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?exportcsv=1&id='.$object->id.'">'.$langs->trans("Download").'</a>';
2019-11-01 23:58:14 +01:00
$massactionbutton = '';
print_barre_liste($langs->trans("MailSelectedRecipients"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $morehtmlcenter, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit);
2013-06-12 22:12:06 +02:00
print '</form>';
print "\n<!-- Liste destinataires selectionnes -->\n";
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="limit" value="'.$limit.'">';
2018-01-12 14:41:57 +01:00
print '<div class="div-table-responsive">';
2019-05-21 21:36:48 +02:00
print '<table class="noborder centpercent">';
2009-01-26 22:57:14 +01:00
// Ligne des champs de filtres
2017-05-04 13:41:37 +02:00
print '<tr class="liste_titre_filter">';
2009-01-26 22:57:14 +01:00
// EMail
print '<td class="liste_titre">';
2019-08-28 19:48:20 +02:00
print '<input class="flat maxwidth75" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
2009-01-26 22:57:14 +01:00
print '</td>';
// Name
print '<td class="liste_titre">';
2019-08-28 19:48:20 +02:00
print '<input class="flat maxwidth50" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'">';
2009-01-26 22:57:14 +01:00
print '</td>';
// Firstname
print '<td class="liste_titre">';
2019-08-28 19:48:20 +02:00
print '<input class="flat maxwidth50" type="text" name="search_firstname" value="'.dol_escape_htmltag($search_firstname).'">';
2009-01-26 22:57:14 +01:00
print '</td>';
// Other
print '<td class="liste_titre">';
print '<input class="flat maxwidth100" type="text" name="search_other" value="'.dol_escape_htmltag($search_other).'">';
2009-01-26 22:57:14 +01:00
print '</td>';
2010-12-28 03:04:41 +01:00
// Source
print '<td class="liste_titre">';
2021-02-07 19:05:10 +01:00
print '&nbsp;';
print '</td>';
// Date last update
print '<td class="liste_titre">';
2021-02-07 19:05:10 +01:00
print '&nbsp;';
print '</td>';
// Date sending
print '<td class="liste_titre">';
2021-02-07 19:05:10 +01:00
print '&nbsp;';
print '</td>';
//Statut
2019-01-31 13:34:32 +01:00
print '<td class="liste_titre right">';
print $formmailing->selectDestinariesStatus($search_dest_status, 'search_dest_status', 1);
print '</td>';
// Action column
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2017-05-14 21:06:33 +02:00
print $searchpicto;
2009-01-26 22:57:14 +01:00
print '</td>';
print '</tr>';
2021-02-23 18:59:19 +01:00
if ($page) {
$param .= "&page=".urlencode($page);
}
2019-11-01 23:58:14 +01:00
2017-05-04 13:41:37 +02:00
print '<tr class="liste_titre">';
print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "mc.email", $param, "", "", $sortfield, $sortorder);
print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "mc.lastname", $param, "", "", $sortfield, $sortorder);
print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "mc.firstname", $param, "", "", $sortfield, $sortorder);
print_liste_field_titre("OtherInformations", $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
print_liste_field_titre("Source", $_SERVER["PHP_SELF"], "", $param, "", 'align="center"', $sortfield, $sortorder);
// Date last update
2019-08-28 18:20:19 +02:00
print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "mc.tms", $param, "", 'align="center"', $sortfield, $sortorder);
2017-05-04 13:41:37 +02:00
// Date sending
print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, '', 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "mc.statut", $param, '', 'class="right"', $sortfield, $sortorder);
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
2017-05-04 13:41:37 +02:00
print '</tr>';
2009-01-26 22:57:14 +01:00
$i = 0;
2021-02-23 18:59:19 +01:00
if ($num) {
2019-05-21 21:47:25 +02:00
include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$objectstaticmember = new Adherent($db);
$objectstaticuser = new User($db);
$objectstaticcompany = new Societe($db);
$objectstaticcontact = new Contact($db);
2019-05-21 21:47:25 +02:00
2021-02-23 18:59:19 +01:00
while ($i < min($num, $limit)) {
2009-01-26 22:57:14 +01:00
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
2022-06-15 03:26:27 +02:00
print '<td class="tdoverflowmax150">'.img_picto('$obj->email', 'email', 'class="paddingright"').dol_escape_htmltag($obj->email).'</td>';
print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->lastname).'</td>';
print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
print '<td>'.dol_escape_htmltag($obj->other).'</td>';
2021-09-01 21:34:59 +02:00
print '<td class="center tdoverflowmax150">';
2021-02-23 18:59:19 +01:00
if (empty($obj->source_id) || empty($obj->source_type)) {
print empty($obj->source_url) ? '' : $obj->source_url; // For backward compatibility
} else {
2021-02-23 18:59:19 +01:00
if ($obj->source_type == 'member') {
2019-05-21 21:47:25 +02:00
$objectstaticmember->fetch($obj->source_id);
print $objectstaticmember->getNomUrl(1);
2021-02-23 18:59:19 +01:00
} elseif ($obj->source_type == 'user') {
2019-05-21 21:47:25 +02:00
$objectstaticuser->fetch($obj->source_id);
print $objectstaticuser->getNomUrl(1);
2021-02-23 18:59:19 +01:00
} elseif ($obj->source_type == 'thirdparty') {
2019-05-21 21:47:25 +02:00
$objectstaticcompany->fetch($obj->source_id);
print $objectstaticcompany->getNomUrl(1);
2021-02-23 18:59:19 +01:00
} elseif ($obj->source_type == 'contact') {
$objectstaticcontact->fetch($obj->source_id);
print $objectstaticcontact->getNomUrl(1);
} else {
print $obj->source_url;
}
}
2010-12-28 03:04:41 +01:00
print '</td>';
2009-01-26 22:57:14 +01:00
// Date last update
2021-04-12 13:02:34 +02:00
print '<td class="center nowraponall">';
print dol_print_date($obj->tms, 'dayhour');
print '</td>';
2018-01-29 12:58:33 +01:00
// Status of recipient sending email (Warning != status of emailing)
2021-02-23 18:59:19 +01:00
if ($obj->statut == 0) {
// Date sent
2021-04-12 13:02:34 +02:00
print '<td align="center"></td>';
2020-02-13 10:41:31 +01:00
print '<td class="nowrap right">';
print $object::libStatutDest($obj->statut, 2, '');
print '</td>';
2020-05-21 15:05:19 +02:00
} else {
// Date sent
2021-04-12 13:02:34 +02:00
print '<td class="center nowraponall">'.$obj->date_envoi.'</td>';
2019-01-31 13:34:32 +01:00
print '<td class="nowrap right">';
2018-01-29 12:58:33 +01:00
print $object::libStatutDest($obj->statut, 2, $obj->error_text);
2009-01-26 22:57:14 +01:00
print '</td>';
}
2014-08-25 19:32:36 +02:00
2016-05-05 23:44:44 +02:00
// Search Icon
2019-01-22 14:04:33 +01:00
print '<td class="right">';
2021-04-16 19:14:01 +02:00
print '<!-- ID mailing_cibles = '.$obj->rowid.' -->';
2021-02-23 18:59:19 +01:00
if ($obj->statut == 0) { // Not sent yet
if (!empty($user->rights->mailing->creer) && $allowaddtarget) {
print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&rowid='.$obj->rowid.$param.'">'.img_delete($langs->trans("RemoveRecipient")).'</a>';
}
}
2018-01-29 12:58:33 +01:00
/*if ($obj->statut == -1) // Sent with error
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=retry&rowid='.$obj->rowid.$param.'">'.$langs->trans("Retry").'</a>';
}*/
print '</td>';
2009-01-26 22:57:14 +01:00
print '</tr>';
$i++;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 18:59:19 +01:00
if ($object->statut < 2) {
print '<tr><td colspan="9" class="opacitymedium">';
print $langs->trans("NoTargetYet");
print '</td></tr>';
}
2009-01-26 22:57:14 +01:00
}
print "</table><br>";
2018-01-12 14:41:57 +01:00
print '</div>';
2009-01-26 22:57:14 +01:00
print '</form>';
2013-06-12 22:12:06 +02:00
2009-01-26 22:57:14 +01:00
$db->free($resql);
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
2009-01-26 22:57:14 +01:00
}
print "\n<!-- Fin liste destinataires selectionnes -->\n";
2005-01-05 16:26:05 +01:00
}
2018-07-29 17:17:29 +02:00
// End of page
llxFooter();
$db->close();