index.php 6.5 KB

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