index.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  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/index.php
  22. * \ingroup mailing
  23. * \brief Home page for emailing area
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  29. $hookmanager = new HookManager($db);
  30. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  31. $hookmanager->initHooks(array('mailingindex'));
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('commercial', 'orders', 'mails'));
  34. $object = new Mailing($db);
  35. // Security check
  36. $result = restrictedArea($user, 'mailing');
  37. /*
  38. * View
  39. */
  40. $help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
  41. $title = $langs->trans('MailingArea');
  42. llxHeader('', $title, $help_url);
  43. print load_fiche_titre($title);
  44. //print '<table class="notopnoleftnoright" width="100%">';
  45. //print '<tr><td valign="top" width="30%" class="notopnoleft">';
  46. print '<div class="fichecenter"><div class="fichethirdleft">';
  47. $titlesearch = $langs->trans("SearchAMailing");
  48. if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
  49. $titlesearch .= ' | '.$langs->trans("smsing");
  50. }
  51. // Search into emailings
  52. print '<form method="post" action="'.DOL_URL_ROOT.'/comm/mailing/list.php">';
  53. print '<input type="hidden" name="token" value="'.newToken().'">';
  54. print '<div class="div-table-responsive-no-min">';
  55. print '<table class="noborder nohover centpercent">';
  56. print '<tr class="liste_titre"><td colspan="3">'.$titlesearch.'</td></tr>';
  57. print '<tr class="oddeven"><td class="nowrap">';
  58. print $langs->trans("Ref").':</td><td><input type="text" class="flat inputsearch" name="sref"></td>';
  59. print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  60. print '<tr class="oddeven"><td class="nowrap">';
  61. print $langs->trans("Other").':</td><td><input type="text" class="flat inputsearch" name="sall"></td>';
  62. print "</table></div></form><br>\n";
  63. // Affiche stats de tous les modules de destinataires mailings
  64. print '<table class="noborder centpercent">';
  65. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("TargetsStatistics").'</td></tr>';
  66. $dir = DOL_DOCUMENT_ROOT."/core/modules/mailings";
  67. $handle = opendir($dir);
  68. if (is_resource($handle)) {
  69. while (($file = readdir($handle)) !== false) {
  70. if (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS') {
  71. if (preg_match("/(.*)\.(.*)\.(.*)/i", $file, $reg)) {
  72. $modulename = $reg[1];
  73. if ($modulename == 'example') {
  74. continue;
  75. }
  76. // Loading Class
  77. $file = $dir."/".$modulename.".modules.php";
  78. $classname = "mailing_".$modulename;
  79. require_once $file;
  80. $mailmodule = new $classname($db);
  81. $qualified = 1;
  82. foreach ($mailmodule->require_module as $key) {
  83. if (!isModEnabled($key) || (!$user->admin && !empty($mailmodule->require_admin))) {
  84. $qualified = 0;
  85. //print "Prerequisites are not not, selector won't be active";
  86. break;
  87. }
  88. }
  89. // If emailing is qualified for statistic section
  90. if ($qualified) {
  91. foreach ($mailmodule->getSqlArrayForStats() as $sql) {
  92. print '<tr class="oddeven">';
  93. $result = $db->query($sql);
  94. if ($result) {
  95. $num = $db->num_rows($result);
  96. $i = 0;
  97. while ($i < $num) {
  98. $obj = $db->fetch_object($result);
  99. print '<td>'.img_object('', $mailmodule->picto).' '.dol_escape_htmltag($obj->label).'</td>';
  100. print '<td class="right">'.$obj->nb.'</td>';
  101. $i++;
  102. }
  103. $db->free($result);
  104. } else {
  105. dol_print_error($db);
  106. }
  107. print '</tr>';
  108. }
  109. }
  110. }
  111. }
  112. }
  113. closedir($handle);
  114. }
  115. print "</table><br>";
  116. print '</div><div class="fichetwothirdright">';
  117. /*
  118. * List of last emailings
  119. */
  120. $limit = 10;
  121. $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut as status, m.date_creat";
  122. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
  123. $sql .= " WHERE m.entity = ".$conf->entity;
  124. $sql .= " ORDER BY m.date_creat DESC";
  125. $sql .= " LIMIT ".$limit;
  126. $result = $db->query($sql);
  127. if ($result) {
  128. print '<div class="div-table-responsive-no-min">';
  129. print '<table class="noborder centpercent">';
  130. print '<tr class="liste_titre">';
  131. print '<td colspan="2">'.$langs->trans("LastMailings", $limit).'</td>';
  132. print '<td class="center">'.$langs->trans("DateCreation").'</td>';
  133. print '<td class="center">'.$langs->trans("NbOfEMails").'</td>';
  134. print '<td class="right"><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("AllEMailings").'</a></td></tr>';
  135. $num = $db->num_rows($result);
  136. if ($num > 0) {
  137. $i = 0;
  138. while ($i < $num) {
  139. $obj = $db->fetch_object($result);
  140. $mailstatic = new Mailing($db);
  141. $mailstatic->id = $obj->rowid;
  142. $mailstatic->ref = $obj->rowid;
  143. print '<tr class="oddeven">';
  144. print '<td class="nowrap">'.$mailstatic->getNomUrl(1).'</td>';
  145. print '<td>'.(!empty($obj->title) ? dol_trunc($obj->title, 38) : '').'</td>';
  146. print '<td class="center">'.dol_print_date($db->jdate($obj->date_creat), 'day').'</td>';
  147. print '<td class="center">'.($obj->nbemail ? $obj->nbemail : "0").'</td>';
  148. print '<td class="right">'.$mailstatic->LibStatut($obj->status, 5).'</td>';
  149. print '</tr>';
  150. $i++;
  151. }
  152. } else {
  153. print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  154. }
  155. print "</table></div><br>";
  156. $db->free($result);
  157. } else {
  158. dol_print_error($db);
  159. }
  160. print '</div></div>';
  161. $parameters = array('user' => $user);
  162. $reshook = $hookmanager->executeHooks('dashboardEmailings', $parameters, $object); // Note that $action and $object may have been modified by hook
  163. // End of page
  164. llxFooter();
  165. $db->close();