dolibarr 19.0.3
index.php
Go to the documentation of this file.
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
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31
32$hookmanager = new HookManager($db);
33
34// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
35$hookmanager->initHooks(array('mailingindex'));
36
37// Load translation files required by the page
38$langs->loadLangs(array('commercial', 'orders', 'mails'));
39
40$object = new Mailing($db);
41
42// Security check
43$result = restrictedArea($user, 'mailing');
44
45
46/*
47 * View
48 */
49
50$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
51$title = $langs->trans('MailingArea');
52
53llxHeader('', $title, $help_url);
54
55print load_fiche_titre($title);
56
57//print '<table class="notopnoleftnoright" width="100%">';
58//print '<tr><td valign="top" width="30%" class="notopnoleft">';
59print '<div class="fichecenter"><div class="fichethirdleft">';
60
61$titlesearch = $langs->trans("SearchAMailing");
62if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
63 $titlesearch .= ' | '.$langs->trans("smsing");
64}
65
66// Search into emailings
67print '<form method="post" action="'.DOL_URL_ROOT.'/comm/mailing/list.php">';
68print '<input type="hidden" name="token" value="'.newToken().'">';
69print '<div class="div-table-responsive-no-min">';
70print '<table class="noborder nohover centpercent">';
71print '<tr class="liste_titre"><td colspan="3">'.$titlesearch.'</td></tr>';
72print '<tr class="oddeven"><td class="nowrap">';
73print $langs->trans("Ref").':</td><td><input type="text" class="flat inputsearch" name="sref"></td>';
74print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
75print '<tr class="oddeven"><td class="nowrap">';
76print $langs->trans("Other").':</td><td><input type="text" class="flat inputsearch" name="sall"></td>';
77
78print "</table></div></form><br>\n";
79
80
81
82
83// Affiche stats de tous les modules de destinataires mailings
84print '<table class="noborder centpercent">';
85print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("TargetsStatistics").'</td></tr>';
86
87$dir = DOL_DOCUMENT_ROOT."/core/modules/mailings";
88$handle = opendir($dir);
89
90if (is_resource($handle)) {
91 while (($file = readdir($handle)) !== false) {
92 if (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS') {
93 if (preg_match("/(.*)\.(.*)\.(.*)/i", $file, $reg)) {
94 $modulename = $reg[1];
95 if ($modulename == 'example') {
96 continue;
97 }
98
99 // Loading Class
100 $file = $dir."/".$modulename.".modules.php";
101 $classname = "mailing_".$modulename;
102 require_once $file;
103 $mailmodule = new $classname($db);
104
105 $qualified = 1;
106 foreach ($mailmodule->require_module as $key) {
107 if (!isModEnabled($key) || (!$user->admin && !empty($mailmodule->require_admin))) {
108 $qualified = 0;
109 //print "Prerequisites are not not, selector won't be active";
110 break;
111 }
112 }
113
114 // If emailing is qualified for statistic section
115 if ($qualified) {
116 foreach ($mailmodule->getSqlArrayForStats() as $sql) {
117 print '<tr class="oddeven">';
118
119 $result = $db->query($sql);
120 if ($result) {
121 $num = $db->num_rows($result);
122
123 $i = 0;
124 while ($i < $num) {
125 $obj = $db->fetch_object($result);
126 print '<td>'.img_object('', $mailmodule->picto).' '.dol_escape_htmltag($obj->label).'</td>';
127 print '<td class="right">'.$obj->nb.'</td>';
128 $i++;
129 }
130
131 $db->free($result);
132 } else {
133 dol_print_error($db);
134 }
135 print '</tr>';
136 }
137 }
138 }
139 }
140 }
141 closedir($handle);
142}
143
144
145print "</table><br>";
146
147
148print '</div><div class="fichetwothirdright">';
149
150
151/*
152 * List of last emailings
153 */
154$limit = 10;
155$sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut as status, m.date_creat";
156$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
157$sql .= " WHERE m.entity = ".$conf->entity;
158$sql .= " ORDER BY m.date_creat DESC";
159$sql .= " LIMIT ".$limit;
160$result = $db->query($sql);
161if ($result) {
162 print '<div class="div-table-responsive-no-min">';
163 print '<table class="noborder centpercent">';
164 print '<tr class="liste_titre">';
165 print '<td colspan="2">'.$langs->trans("LastMailings", $limit).'</td>';
166 print '<td class="center">'.$langs->trans("DateCreation").'</td>';
167 print '<td class="center">'.$langs->trans("NbOfEMails").'</td>';
168 print '<td class="right"><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("AllEMailings").'</a></td></tr>';
169
170 $num = $db->num_rows($result);
171 if ($num > 0) {
172 $i = 0;
173
174 while ($i < $num) {
175 $obj = $db->fetch_object($result);
176 $mailstatic = new Mailing($db);
177 $mailstatic->id = $obj->rowid;
178 $mailstatic->ref = $obj->rowid;
179
180 print '<tr class="oddeven">';
181 print '<td class="nowrap">'.$mailstatic->getNomUrl(1).'</td>';
182 print '<td>'.(!empty($obj->title) ? dol_trunc($obj->title, 38) : '').'</td>';
183 print '<td class="center">'.dol_print_date($db->jdate($obj->date_creat), 'day').'</td>';
184 print '<td class="center">'.($obj->nbemail ? $obj->nbemail : "0").'</td>';
185 print '<td class="right">'.$mailstatic->LibStatut($obj->status, 5).'</td>';
186 print '</tr>';
187 $i++;
188 }
189 } else {
190 print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
191 }
192 print "</table></div><br>";
193 $db->free($result);
194} else {
195 dol_print_error($db);
196}
197
198
199print '</div></div>';
200
201
202$parameters = array('user' => $user);
203$reshook = $hookmanager->executeHooks('dashboardEmailings', $parameters, $object); // Note that $action and $object may have been modified by hook
204
205// End of page
206llxFooter();
207$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage hooks.
Class to manage emailings module.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.