cibles.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2021 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/mailing/cibles.php
  22. * \ingroup mailing
  23. * \brief Page to define emailing targets
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
  27. require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmailing.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  32. // Load translation files required by the page
  33. $langs->load("mails");
  34. // Load variable for pagination
  35. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  36. $sortfield = GETPOST('sortfield', 'aZ09comma');
  37. $sortorder = GETPOST('sortorder', 'aZ09comma');
  38. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  39. if (empty($page) || $page == -1) {
  40. $page = 0;
  41. } // If $page is not defined, or '' or -1
  42. $offset = $limit * $page;
  43. $pageprev = $page - 1;
  44. $pagenext = $page + 1;
  45. if (!$sortfield) {
  46. $sortfield = "mc.statut,email";
  47. }
  48. if (!$sortorder) {
  49. $sortorder = "DESC,ASC";
  50. }
  51. $id = GETPOST('id', 'int');
  52. $rowid = GETPOST('rowid', 'int');
  53. $action = GETPOST('action', 'aZ09');
  54. $search_lastname = GETPOST("search_lastname", 'alphanohtml');
  55. $search_firstname = GETPOST("search_firstname", 'alphanohtml');
  56. $search_email = GETPOST("search_email", 'alphanohtml');
  57. $search_other = GETPOST("search_other", 'alphanohtml');
  58. $search_dest_status = GETPOST('search_dest_status', 'int');
  59. // Search modules dirs
  60. $modulesdir = dolGetModulesDirs('/mailings');
  61. $object = new Mailing($db);
  62. $result = $object->fetch($id);
  63. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  64. $hookmanager->initHooks(array('ciblescard', 'globalcard'));
  65. // Security check
  66. if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
  67. accessforbidden();
  68. }
  69. //$result = restrictedArea($user, 'mailing');
  70. /*
  71. * Actions
  72. */
  73. if ($action == 'add') {
  74. $module = GETPOST("module", 'alpha');
  75. $result = -1;
  76. foreach ($modulesdir as $dir) {
  77. // Load modules attributes in arrays (name, numero, orders) from dir directory
  78. //print $dir."\n<br>";
  79. dol_syslog("Scan directory ".$dir." for modules");
  80. // Loading Class
  81. $file = $dir."/".$module.".modules.php";
  82. $classname = "mailing_".$module;
  83. if (file_exists($file)) {
  84. require_once $file;
  85. // Add targets into database
  86. $obj = new $classname($db);
  87. dol_syslog("Call add_to_target on class ".$classname);
  88. $result = $obj->add_to_target($id);
  89. }
  90. }
  91. if ($result > 0) {
  92. setEventMessages($langs->trans("XTargetsAdded", $result), null, 'mesgs');
  93. $action = '';
  94. }
  95. if ($result == 0) {
  96. setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings');
  97. }
  98. if ($result < 0) {
  99. setEventMessages($langs->trans("Error").($obj->error ? ' '.$obj->error : ''), null, 'errors');
  100. }
  101. }
  102. if (GETPOST('clearlist', 'int')) {
  103. // Loading Class
  104. $obj = new MailingTargets($db);
  105. $obj->clear_target($id);
  106. /* Avoid this to allow reposition
  107. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  108. exit;
  109. */
  110. }
  111. if (GETPOST('exportcsv', 'int')) {
  112. $completefilename = 'targets_emailing'.$object->id.'_'.dol_print_date(dol_now(), 'dayhourlog').'.csv';
  113. header('Content-Type: text/csv');
  114. header('Content-Disposition: attachment;filename='.$completefilename);
  115. // List of selected targets
  116. $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut as status, mc.date_envoi, mc.tms,";
  117. $sql .= " mc.source_id, mc.source_type, mc.error_text";
  118. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
  119. $sql .= " WHERE mc.fk_mailing = ".((int) $object->id);
  120. $sql .= $db->order($sortfield, $sortorder);
  121. $resql = $db->query($sql);
  122. if ($resql) {
  123. $num = $db->num_rows($resql);
  124. $sep = ',';
  125. while ($obj = $db->fetch_object($resql)) {
  126. print $obj->rowid.$sep;
  127. print '"'.$obj->lastname.'"'.$sep;
  128. print '"'.$obj->firstname.'"'.$sep;
  129. print $obj->email.$sep;
  130. print $obj->other.$sep;
  131. print $obj->tms.$sep;
  132. print $obj->source_type.$sep;
  133. print $obj->source_id.$sep;
  134. print $obj->date_envoi.$sep;
  135. print $obj->status.$sep;
  136. print '"'.$obj->error_text.'"'.$sep;
  137. print "\n";
  138. }
  139. exit;
  140. } else {
  141. dol_print_error($db);
  142. }
  143. exit;
  144. }
  145. if ($action == 'delete') {
  146. // Ici, rowid indique le destinataire et id le mailing
  147. $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid = ".((int) $rowid);
  148. $resql = $db->query($sql);
  149. if ($resql) {
  150. if (!empty($id)) {
  151. $obj = new MailingTargets($db);
  152. $obj->update_nb($id);
  153. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  154. } else {
  155. header("Location: list.php");
  156. exit;
  157. }
  158. } else {
  159. dol_print_error($db);
  160. }
  161. }
  162. // Purge search criteria
  163. 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
  164. $search_lastname = '';
  165. $search_firstname = '';
  166. $search_email = '';
  167. $search_other = '';
  168. $search_dest_status = '';
  169. }
  170. /*
  171. * View
  172. */
  173. llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
  174. $form = new Form($db);
  175. $formmailing = new FormMailing($db);
  176. if ($object->fetch($id) >= 0) {
  177. $head = emailing_prepare_head($object);
  178. print dol_get_fiche_head($head, 'targets', $langs->trans("Mailing"), -1, 'email');
  179. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  180. $morehtmlright = '';
  181. $nbtry = $nbok = 0;
  182. if ($object->statut == 2 || $object->statut == 3) {
  183. $nbtry = $object->countNbOfTargets('alreadysent');
  184. $nbko = $object->countNbOfTargets('alreadysentko');
  185. $nbok = ($nbtry - $nbko);
  186. $morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail;
  187. if ($nbko) {
  188. $morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error");
  189. }
  190. $morehtmlright .= ') &nbsp; ';
  191. }
  192. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
  193. print '<div class="fichecenter">';
  194. print '<div class="underbanner clearboth"></div>';
  195. print '<table class="border centpercent tableforfield">';
  196. print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->title.'</td></tr>';
  197. print '<tr><td>'.$langs->trans("MailFrom").'</td><td colspan="3">';
  198. $emailarray = CMailFile::getArrayAddress($object->email_from);
  199. foreach ($emailarray as $email => $name) {
  200. if ($name && $name != $email) {
  201. print dol_escape_htmltag($name).' &lt;'.$email;
  202. print '&gt;';
  203. if (!isValidEmail($email)) {
  204. $langs->load("errors");
  205. print img_warning($langs->trans("ErrorBadEMail", $email));
  206. }
  207. } else {
  208. print dol_print_email($object->email_from, 0, 0, 0, 0, 1);
  209. }
  210. }
  211. //print dol_print_email($object->email_from, 0, 0, 0, 0, 1);
  212. //var_dump($object->email_from);
  213. print '</td></tr>';
  214. // Errors to
  215. print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">';
  216. $emailarray = CMailFile::getArrayAddress($object->email_errorsto);
  217. foreach ($emailarray as $email => $name) {
  218. if ($name != $email) {
  219. print dol_escape_htmltag($name).' &lt;'.$email;
  220. print '&gt;';
  221. if (!isValidEmail($email)) {
  222. $langs->load("errors");
  223. print img_warning($langs->trans("ErrorBadEMail", $email));
  224. }
  225. } else {
  226. print dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
  227. }
  228. }
  229. print '</td></tr>';
  230. // Nb of distinct emails
  231. print '<tr><td>';
  232. print $langs->trans("TotalNbOfDistinctRecipients");
  233. print '</td><td colspan="3">';
  234. $nbemail = ($object->nbemail ? $object->nbemail : 0);
  235. if (is_numeric($nbemail)) {
  236. $text = '';
  237. if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
  238. if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
  239. $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
  240. } else {
  241. $text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
  242. }
  243. }
  244. if (empty($nbemail)) {
  245. $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
  246. }
  247. if ($text) {
  248. print $form->textwithpicto($nbemail, $text, 1, 'warning');
  249. } else {
  250. print $nbemail;
  251. }
  252. }
  253. print '</td></tr>';
  254. print '</table>';
  255. print "</div>";
  256. print dol_get_fiche_end();
  257. print '<br>';
  258. $allowaddtarget = ($object->statut == 0);
  259. // Show email selectors
  260. if ($allowaddtarget && $user->rights->mailing->creer) {
  261. print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin ?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"), 1) : ''), 'generic');
  262. //print '<table class="noborder centpercent">';
  263. print '<div class="div-table-responsive">';
  264. print '<div class="tagtable centpercent liste_titre_bydiv borderbottom" id="tablelines">';
  265. //print '<tr class="liste_titre">';
  266. print '<div class="tagtr liste_titre">';
  267. //print '<td class="liste_titre">'.$langs->trans("RecipientSelectionModules").'</td>';
  268. print '<div class="tagtd">'.$langs->trans("RecipientSelectionModules").'</div>';
  269. //print '<td class="liste_titre" align="center">'.$langs->trans("NbOfUniqueEMails").'</td>';
  270. print '<div class="tagtd" align="center">'.$langs->trans("NbOfUniqueEMails").'</div>';
  271. //print '<td class="liste_titre" align="left">'.$langs->trans("Filter").'</td>';
  272. print '<div class="tagtd left">'.$langs->trans("Filter").'</div>';
  273. //print '<td class="liste_titre" align="center">&nbsp;</td>';
  274. print '<div class="tagtd">&nbsp;</div>';
  275. //print "</tr>\n";
  276. print '</div>'; // End tr
  277. clearstatcache();
  278. foreach ($modulesdir as $dir) {
  279. $modulenames = array();
  280. // Load modules attributes in arrays (name, numero, orders) from dir directory
  281. //print $dir."\n<br>";
  282. dol_syslog("Scan directory ".$dir." for modules");
  283. $handle = @opendir($dir);
  284. if (is_resource($handle)) {
  285. while (($file = readdir($handle)) !== false) {
  286. if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') {
  287. $reg = array();
  288. if (preg_match("/(.*)\.modules\.php$/i", $file, $reg)) {
  289. if ($reg[1] == 'example') {
  290. continue;
  291. }
  292. $modulenames[] = $reg[1];
  293. }
  294. }
  295. }
  296. closedir($handle);
  297. }
  298. // Sort $modulenames
  299. sort($modulenames);
  300. $var = true;
  301. // Loop on each submodule
  302. foreach ($modulenames as $modulename) {
  303. // Loading Class
  304. $file = $dir.$modulename.".modules.php";
  305. $classname = "mailing_".$modulename;
  306. require_once $file;
  307. $obj = new $classname($db);
  308. // Check if qualified
  309. $qualified = (is_null($obj->enabled) ? 1 : dol_eval($obj->enabled, 1));
  310. // Check dependencies
  311. foreach ($obj->require_module as $key) {
  312. if (empty($conf->$key->enabled) || (empty($user->admin) && $obj->require_admin)) {
  313. $qualified = 0;
  314. //print "Les prerequis d'activation du module mailing ne sont pas respectes. Il ne sera pas actif";
  315. break;
  316. }
  317. }
  318. // If module is qualified
  319. if ($qualified) {
  320. $var = !$var;
  321. if ($allowaddtarget) {
  322. 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">';
  323. print '<input type="hidden" name="token" value="'.newToken().'">';
  324. print '<input type="hidden" name="page_y" value="'.newToken().'">';
  325. } else {
  326. print '<div '.$bctag[$var].'>';
  327. }
  328. print '<div class="tagtd">';
  329. if (empty($obj->picto)) {
  330. $obj->picto = 'generic';
  331. }
  332. print img_object($langs->trans("EmailingTargetSelector").': '.get_class($obj), $obj->picto, 'class="valignmiddle pictomodule"');
  333. print ' ';
  334. print $obj->getDesc();
  335. print '</div>';
  336. try {
  337. $nbofrecipient = $obj->getNbOfRecipients('');
  338. } catch (Exception $e) {
  339. dol_syslog($e->getMessage(), LOG_ERR);
  340. }
  341. print '<div class="tagtd center">';
  342. if ($nbofrecipient === '' || $nbofrecipient >= 0) {
  343. print $nbofrecipient;
  344. } else {
  345. print $langs->trans("Error").' '.img_error($obj->error);
  346. }
  347. print '</div>';
  348. print '<div class="tagtd left">';
  349. if ($allowaddtarget) {
  350. try {
  351. $filter = $obj->formFilter();
  352. } catch (Exception $e) {
  353. dol_syslog($e->getMessage(), LOG_ERR);
  354. }
  355. if ($filter) {
  356. print $filter;
  357. } else {
  358. print $langs->trans("None");
  359. }
  360. }
  361. print '</div>';
  362. print '<div class="tagtd right">';
  363. if ($allowaddtarget) {
  364. print '<input type="submit" class="button button-add small reposition" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
  365. } else {
  366. print '<input type="submit" class="button small disabled" disabled="disabled" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
  367. //print $langs->trans("MailNoChangePossible");
  368. print "&nbsp;";
  369. }
  370. print '</div>';
  371. if ($allowaddtarget) {
  372. print '</form>';
  373. } else {
  374. print '</div>';
  375. }
  376. }
  377. }
  378. } // End foreach dir
  379. $parameters = array();
  380. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  381. print $hookmanager->resPrint;
  382. print '</div>'; // End table
  383. print '</div>';
  384. print '<br><br>';
  385. }
  386. // List of selected targets
  387. $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms,";
  388. $sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text";
  389. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
  390. $sql .= " WHERE mc.fk_mailing=".((int) $object->id);
  391. $asearchcriteriahasbeenset = 0;
  392. if ($search_lastname) {
  393. $sql .= natural_search("mc.lastname", $search_lastname);
  394. $asearchcriteriahasbeenset++;
  395. }
  396. if ($search_firstname) {
  397. $sql .= natural_search("mc.firstname", $search_firstname);
  398. $asearchcriteriahasbeenset++;
  399. }
  400. if ($search_email) {
  401. $sql .= natural_search("mc.email", $search_email);
  402. $asearchcriteriahasbeenset++;
  403. }
  404. if ($search_other) {
  405. $sql .= natural_search("mc.other", $search_other);
  406. $asearchcriteriahasbeenset++;
  407. }
  408. if ($search_dest_status != '' && $search_dest_status >= -1) {
  409. $sql .= " AND mc.statut = ".((int) $search_dest_status);
  410. $asearchcriteriahasbeenset++;
  411. }
  412. $sql .= $db->order($sortfield, $sortorder);
  413. // Count total nb of records
  414. $nbtotalofrecords = '';
  415. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  416. $result = $db->query($sql);
  417. $nbtotalofrecords = $db->num_rows($result);
  418. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  419. $page = 0;
  420. $offset = 0;
  421. }
  422. // Fix/update nbemail on emailing record if it differs (may happen if user edit lines from database directly)
  423. if (empty($asearchcriteriahasbeenset)) {
  424. if ($nbtotalofrecords != $object->nbemail) {
  425. dol_syslog("We found a difference in nb of record in target table and the property ->nbemail, we fix ->nbemail");
  426. //print "nbemail=".$object->nbemail." nbtotalofrecords=".$nbtotalofrecords;
  427. $resultrefresh = $object->refreshNbOfTargets();
  428. if ($resultrefresh < 0) {
  429. dol_print_error($db, $object->error, $object->errors);
  430. }
  431. }
  432. }
  433. }
  434. //$nbtotalofrecords=$object->nbemail; // nbemail is a denormalized field storing nb of targets
  435. $sql .= $db->plimit($limit + 1, $offset);
  436. $resql = $db->query($sql);
  437. if ($resql) {
  438. $num = $db->num_rows($resql);
  439. $param = "&id=".$object->id;
  440. //if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  441. if ($limit > 0 && $limit != $conf->liste_limit) {
  442. $param .= '&limit='.urlencode($limit);
  443. }
  444. if ($search_lastname) {
  445. $param .= "&search_lastname=".urlencode($search_lastname);
  446. }
  447. if ($search_firstname) {
  448. $param .= "&search_firstname=".urlencode($search_firstname);
  449. }
  450. if ($search_email) {
  451. $param .= "&search_email=".urlencode($search_email);
  452. }
  453. if ($search_other) {
  454. $param .= "&search_other=".urlencode($search_other);
  455. }
  456. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  457. print '<input type="hidden" name="token" value="'.newToken().'">';
  458. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  459. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  460. print '<input type="hidden" name="page" value="'.$page.'">';
  461. print '<input type="hidden" name="id" value="'.$object->id.'">';
  462. $morehtmlcenter = '';
  463. if ($allowaddtarget) {
  464. $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>';
  465. }
  466. $morehtmlcenter .= ' &nbsp; <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?exportcsv=1&id='.$object->id.'">'.$langs->trans("Download").'</a>';
  467. $massactionbutton = '';
  468. print_barre_liste($langs->trans("MailSelectedRecipients"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $morehtmlcenter, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit);
  469. print '</form>';
  470. print "\n<!-- Liste destinataires selectionnes -->\n";
  471. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  472. print '<input type="hidden" name="token" value="'.newToken().'">';
  473. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  474. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  475. print '<input type="hidden" name="page" value="'.$page.'">';
  476. print '<input type="hidden" name="id" value="'.$object->id.'">';
  477. print '<input type="hidden" name="limit" value="'.$limit.'">';
  478. print '<div class="div-table-responsive">';
  479. print '<table class="noborder centpercent">';
  480. // Ligne des champs de filtres
  481. print '<tr class="liste_titre_filter">';
  482. // EMail
  483. print '<td class="liste_titre">';
  484. print '<input class="flat maxwidth75" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
  485. print '</td>';
  486. // Name
  487. print '<td class="liste_titre">';
  488. print '<input class="flat maxwidth50" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'">';
  489. print '</td>';
  490. // Firstname
  491. print '<td class="liste_titre">';
  492. print '<input class="flat maxwidth50" type="text" name="search_firstname" value="'.dol_escape_htmltag($search_firstname).'">';
  493. print '</td>';
  494. // Other
  495. print '<td class="liste_titre">';
  496. print '<input class="flat maxwidth100" type="text" name="search_other" value="'.dol_escape_htmltag($search_other).'">';
  497. print '</td>';
  498. // Source
  499. print '<td class="liste_titre">';
  500. print '&nbsp;';
  501. print '</td>';
  502. // Date last update
  503. print '<td class="liste_titre">';
  504. print '&nbsp;';
  505. print '</td>';
  506. // Date sending
  507. print '<td class="liste_titre">';
  508. print '&nbsp;';
  509. print '</td>';
  510. //Statut
  511. print '<td class="liste_titre right">';
  512. print $formmailing->selectDestinariesStatus($search_dest_status, 'search_dest_status', 1);
  513. print '</td>';
  514. // Action column
  515. print '<td class="liste_titre maxwidthsearch">';
  516. $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
  517. print $searchpicto;
  518. print '</td>';
  519. print '</tr>';
  520. if ($page) {
  521. $param .= "&page=".urlencode($page);
  522. }
  523. print '<tr class="liste_titre">';
  524. print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "mc.email", $param, "", "", $sortfield, $sortorder);
  525. print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "mc.lastname", $param, "", "", $sortfield, $sortorder);
  526. print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "mc.firstname", $param, "", "", $sortfield, $sortorder);
  527. print_liste_field_titre("OtherInformations", $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
  528. print_liste_field_titre("Source", $_SERVER["PHP_SELF"], "", $param, "", 'align="center"', $sortfield, $sortorder);
  529. // Date last update
  530. print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "mc.tms", $param, "", 'align="center"', $sortfield, $sortorder);
  531. // Date sending
  532. print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, '', 'align="center"', $sortfield, $sortorder);
  533. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "mc.statut", $param, '', 'class="right"', $sortfield, $sortorder);
  534. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
  535. print '</tr>';
  536. $i = 0;
  537. if ($num) {
  538. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  539. include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  540. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  541. include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  542. $objectstaticmember = new Adherent($db);
  543. $objectstaticuser = new User($db);
  544. $objectstaticcompany = new Societe($db);
  545. $objectstaticcontact = new Contact($db);
  546. while ($i < min($num, $limit)) {
  547. $obj = $db->fetch_object($resql);
  548. print '<tr class="oddeven">';
  549. print '<td class="tdoverflowmax150">'.img_picto('$obj->email', 'email', 'class="paddingright"').dol_escape_htmltag($obj->email).'</td>';
  550. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->lastname).'</td>';
  551. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
  552. print '<td>'.dol_escape_htmltag($obj->other).'</td>';
  553. print '<td class="center tdoverflowmax150">';
  554. if (empty($obj->source_id) || empty($obj->source_type)) {
  555. print empty($obj->source_url) ? '' : $obj->source_url; // For backward compatibility
  556. } else {
  557. if ($obj->source_type == 'member') {
  558. $objectstaticmember->fetch($obj->source_id);
  559. print $objectstaticmember->getNomUrl(1);
  560. } elseif ($obj->source_type == 'user') {
  561. $objectstaticuser->fetch($obj->source_id);
  562. print $objectstaticuser->getNomUrl(1);
  563. } elseif ($obj->source_type == 'thirdparty') {
  564. $objectstaticcompany->fetch($obj->source_id);
  565. print $objectstaticcompany->getNomUrl(1);
  566. } elseif ($obj->source_type == 'contact') {
  567. $objectstaticcontact->fetch($obj->source_id);
  568. print $objectstaticcontact->getNomUrl(1);
  569. } else {
  570. print $obj->source_url;
  571. }
  572. }
  573. print '</td>';
  574. // Date last update
  575. print '<td class="center nowraponall">';
  576. print dol_print_date($obj->tms, 'dayhour');
  577. print '</td>';
  578. // Status of recipient sending email (Warning != status of emailing)
  579. if ($obj->statut == 0) {
  580. // Date sent
  581. print '<td align="center"></td>';
  582. print '<td class="nowrap right">';
  583. print $object::libStatutDest($obj->statut, 2, '');
  584. print '</td>';
  585. } else {
  586. // Date sent
  587. print '<td class="center nowraponall">'.$obj->date_envoi.'</td>';
  588. print '<td class="nowrap right">';
  589. print $object::libStatutDest($obj->statut, 2, $obj->error_text);
  590. print '</td>';
  591. }
  592. // Search Icon
  593. print '<td class="right">';
  594. print '<!-- ID mailing_cibles = '.$obj->rowid.' -->';
  595. if ($obj->statut == 0) { // Not sent yet
  596. if (!empty($user->rights->mailing->creer) && $allowaddtarget) {
  597. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&rowid='.$obj->rowid.$param.'">'.img_delete($langs->trans("RemoveRecipient")).'</a>';
  598. }
  599. }
  600. /*if ($obj->statut == -1) // Sent with error
  601. {
  602. print '<a href="'.$_SERVER['PHP_SELF'].'?action=retry&rowid='.$obj->rowid.$param.'">'.$langs->trans("Retry").'</a>';
  603. }*/
  604. print '</td>';
  605. print '</tr>';
  606. $i++;
  607. }
  608. } else {
  609. if ($object->statut < 2) {
  610. print '<tr><td colspan="9" class="opacitymedium">';
  611. print $langs->trans("NoTargetYet");
  612. print '</td></tr>';
  613. }
  614. }
  615. print "</table><br>";
  616. print '</div>';
  617. print '</form>';
  618. $db->free($resql);
  619. } else {
  620. dol_print_error($db);
  621. }
  622. print "\n<!-- Fin liste destinataires selectionnes -->\n";
  623. }
  624. // End of page
  625. llxFooter();
  626. $db->close();