cibles.php 25 KB

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