index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. //if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  48. //{
  49. // Search into emailings
  50. print '<form method="post" action="'.DOL_URL_ROOT.'/comm/mailing/list.php">';
  51. print '<input type="hidden" name="token" value="'.newToken().'">';
  52. print '<div class="div-table-responsive-no-min">';
  53. print '<table class="noborder nohover centpercent">';
  54. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAMailing").'</td></tr>';
  55. print '<tr class="oddeven"><td class="nowrap">';
  56. print $langs->trans("Ref").':</td><td><input type="text" class="flat inputsearch" name="sref"></td>';
  57. print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  58. print '<tr class="oddeven"><td class="nowrap">';
  59. print $langs->trans("Other").':</td><td><input type="text" class="flat inputsearch" name="sall"></td>';
  60. print "</table></div></form><br>\n";
  61. //}
  62. // Affiche stats de tous les modules de destinataires mailings
  63. print '<table class="noborder centpercent">';
  64. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("TargetsStatistics").'</td></tr>';
  65. $dir = DOL_DOCUMENT_ROOT."/core/modules/mailings";
  66. $handle = opendir($dir);
  67. if (is_resource($handle)) {
  68. while (($file = readdir($handle)) !== false) {
  69. if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') {
  70. if (preg_match("/(.*)\.(.*)\.(.*)/i", $file, $reg)) {
  71. $modulename = $reg[1];
  72. if ($modulename == 'example') {
  73. continue;
  74. }
  75. // Loading Class
  76. $file = $dir."/".$modulename.".modules.php";
  77. $classname = "mailing_".$modulename;
  78. require_once $file;
  79. $mailmodule = new $classname($db);
  80. $qualified = 1;
  81. foreach ($mailmodule->require_module as $key) {
  82. if (!$conf->$key->enabled || (!$user->admin && $mailmodule->require_admin)) {
  83. $qualified = 0;
  84. //print "Les pr�requis d'activation du module mailing ne sont pas respect�s. Il ne sera pas actif";
  85. break;
  86. }
  87. }
  88. // Si le module mailing est qualifi�
  89. if ($qualified) {
  90. foreach ($mailmodule->getSqlArrayForStats() as $sql) {
  91. print '<tr class="oddeven">';
  92. $result = $db->query($sql);
  93. if ($result) {
  94. $num = $db->num_rows($result);
  95. $i = 0;
  96. while ($i < $num) {
  97. $obj = $db->fetch_object($result);
  98. print '<td>'.img_object('', $mailmodule->picto).' '.$obj->label.'</td><td class="right">'.$obj->nb.'<td>';
  99. $i++;
  100. }
  101. $db->free($result);
  102. } else {
  103. dol_print_error($db);
  104. }
  105. print '</tr>';
  106. }
  107. }
  108. }
  109. }
  110. }
  111. closedir($handle);
  112. }
  113. print "</table><br>";
  114. print '</div><div class="fichetwothirdright">';
  115. /*
  116. * List of last emailings
  117. */
  118. $limit = 10;
  119. $sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat";
  120. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
  121. $sql .= " WHERE m.entity = ".$conf->entity;
  122. $sql .= " ORDER BY m.date_creat DESC";
  123. $sql .= " LIMIT ".$limit;
  124. $result = $db->query($sql);
  125. if ($result) {
  126. print '<div class="div-table-responsive-no-min">';
  127. print '<table class="noborder centpercent">';
  128. print '<tr class="liste_titre">';
  129. print '<td colspan="2">'.$langs->trans("LastMailings", $limit).'</td>';
  130. print '<td class="center">'.$langs->trans("DateCreation").'</td>';
  131. print '<td class="center">'.$langs->trans("NbOfEMails").'</td>';
  132. print '<td class="right"><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("AllEMailings").'</a></td></tr>';
  133. $num = $db->num_rows($result);
  134. if ($num > 0) {
  135. $i = 0;
  136. while ($i < $num) {
  137. $obj = $db->fetch_object($result);
  138. $mailstatic = new Mailing($db);
  139. $mailstatic->id = $obj->rowid;
  140. $mailstatic->ref = $obj->rowid;
  141. print '<tr class="oddeven">';
  142. print '<td class="nowrap">'.$mailstatic->getNomUrl(1).'</td>';
  143. print '<td>'.dol_trunc($obj->title, 38).'</td>';
  144. print '<td class="center">'.dol_print_date($db->jdate($obj->date_creat), 'day').'</td>';
  145. print '<td class="center">'.($obj->nbemail ? $obj->nbemail : "0").'</td>';
  146. print '<td class="right">'.$mailstatic->LibStatut($obj->statut, 5).'</td>';
  147. print '</tr>';
  148. $i++;
  149. }
  150. } else {
  151. print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  152. }
  153. print "</table></div><br>";
  154. $db->free($result);
  155. } else {
  156. dol_print_error($db);
  157. }
  158. print '</div></div>';
  159. $parameters = array('user' => $user);
  160. $reshook = $hookmanager->executeHooks('dashboardEmailings', $parameters, $object); // Note that $action and $object may have been modified by hook
  161. // End of page
  162. llxFooter();
  163. $db->close();