dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32
33$hookmanager = new HookManager($db);
34
35// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
36$hookmanager->initHooks(array('mailingindex'));
37
38// Load translation files required by the page
39$langs->loadLangs(array('commercial', 'orders', 'mails'));
40
41$object = new Mailing($db);
42
43// Security check
44$result = restrictedArea($user, 'mailing');
45
46
47/*
48 * View
49 */
50
51$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
52$title = $langs->trans('MailingArea');
53
54llxHeader('', $title, $help_url);
55
56print load_fiche_titre($title);
57
58
59print '<div class="fichecenter">';
60
61print '<div class="twocolumns">';
62
63print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
64
65
66$titlesearch = $langs->trans("SearchAMailing");
67if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
68 $titlesearch .= ' | '.$langs->trans("smsing");
69}
70
71// Search into emailings
72print '<form method="post" action="'.DOL_URL_ROOT.'/comm/mailing/list.php">';
73print '<input type="hidden" name="token" value="'.newToken().'">';
74print '<div class="div-table-responsive-no-min">';
75print '<table class="noborder nohover centpercent">';
76print '<tr class="liste_titre"><td colspan="3">'.$titlesearch.'</td></tr>';
77print '<tr class="oddeven"><td class="nowrap">';
78print $langs->trans("Ref").':</td><td><input type="text" class="flat inputsearch" name="sref"></td>';
79print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
80print '<tr class="oddeven"><td class="nowrap">';
81print $langs->trans("Other").':</td><td><input type="text" class="flat inputsearch" name="sall"></td>';
82
83print "</table></div></form><br>\n";
84
85
86
87
88// Affiche stats de tous les modules de destinataires mailings
89print '<table class="noborder centpercent">';
90print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("TargetsStatistics").'</td></tr>';
91
92$dir = DOL_DOCUMENT_ROOT."/core/modules/mailings";
93$handle = opendir($dir);
94
95if (is_resource($handle)) {
96 while (($file = readdir($handle)) !== false) {
97 if (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS') {
98 if (preg_match("/(.*)\.(.*)\.(.*)/i", $file, $reg)) {
99 $modulename = $reg[1];
100 if ($modulename == 'example') {
101 continue;
102 }
103
104 // Loading Class
105 $file = $dir."/".$modulename.".modules.php";
106 $classname = "mailing_".$modulename;
107 require_once $file;
108 $mailmodule = new $classname($db);
109 '@phan-var-force MailingTargets $mailmodule';
110
111 $qualified = 1;
112 foreach ($mailmodule->require_module as $key) {
113 if (!isModEnabled($key) || (!$user->admin && !empty($mailmodule->require_admin))) {
114 $qualified = 0;
115 //print "Prerequisites are not not, selector won't be active";
116 break;
117 }
118 }
119
120 // If emailing is qualified for statistic section
121 if ($qualified) {
122 foreach ($mailmodule->getSqlArrayForStats() as $sql) {
123 print '<tr class="oddeven">';
124
125 $result = $db->query($sql);
126 if ($result) {
127 $num = $db->num_rows($result);
128
129 $i = 0;
130 while ($i < $num) {
131 $obj = $db->fetch_object($result);
132 print '<td>'.img_object('', $mailmodule->picto).' '.dol_escape_htmltag($obj->label).'</td>';
133 print '<td class="right">'.$obj->nb.'</td>';
134 $i++;
135 }
136
137 $db->free($result);
138 } else {
139 dol_print_error($db);
140 }
141 print '</tr>';
142 }
143 }
144 }
145 }
146 }
147 closedir($handle);
148}
149
150
151print "</table><br>";
152
153
154print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
155
156
157/*
158 * List of last emailings
159 */
160
161$limit = 10;
162$sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut as status, m.date_creat, m.messtype";
163$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
164$sql .= " WHERE m.entity = ".$conf->entity;
165$sql .= " ORDER BY m.date_creat DESC";
166$sql .= " LIMIT ".$limit;
167$result = $db->query($sql);
168if ($result) {
169 print '<div class="div-table-responsive-no-min">';
170 print '<table class="noborder centpercent">';
171 print '<tr class="liste_titre">';
172 print '<td colspan="2">'.$langs->trans("LastMailings", $limit).'</td>';
173 if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
174 print '<td class="center">'.$langs->trans("Type").'</td>';
175 }
176 print '<td class="center">'.$langs->trans("DateCreation").'</td>';
177 print '<td class="center">';
178 print $langs->trans("NbOfEMails");
179 if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
180 print ' | '.$langs->trans("Phone");
181 }
182 print '</td>';
183 print '<td class="right"><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("AllEMailings").'</a></td>';
184 print '</tr>';
185
186 $num = $db->num_rows($result);
187 if ($num > 0) {
188 $i = 0;
189
190 while ($i < $num) {
191 $obj = $db->fetch_object($result);
192 $mailstatic = new Mailing($db);
193 $mailstatic->id = $obj->rowid;
194 $mailstatic->ref = $obj->rowid;
195 $mailstatic->messtype = $obj->messtype;
196
197 print '<tr class="oddeven">';
198 print '<td class="nowrap">'.$mailstatic->getNomUrl(1).'</td>';
199 print '<td class="tdoverflowmax100">'.dol_escape_htmltag($obj->title).'</td>';
200 if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
201 print '<td class="center">'.dol_escape_htmltag($obj->messtype).'</td>';
202 }
203 print '<td class="center">'.dol_print_date($db->jdate($obj->date_creat), 'day').'</td>';
204 print '<td class="center">'.($obj->nbemail ? (int) $obj->nbemail : "0").'</td>';
205 print '<td class="right">'.$mailstatic->LibStatut($obj->status, 5).'</td>';
206 print '</tr>';
207 $i++;
208 }
209 } else {
210 print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
211 }
212 print "</table></div><br>";
213 $db->free($result);
214} else {
215 dol_print_error($db);
216}
217
218
219print '</div></div></div>';
220
221
222$parameters = array('user' => $user);
223$reshook = $hookmanager->executeHooks('dashboardEmailings', $parameters, $object); // Note that $action and $object may have been modified by hook
224
225// End of page
226llxFooter();
227$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage hooks.
Class to manage emailings module.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.