dolibarr  17.0.4
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Load Dolibarr environment
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
28 
29 // Load translation files required by the page
30 $langs->load("mails");
31 
32 $sortfield = GETPOST('sortfield', 'aZ09comma');
33 $sortorder = GETPOST('sortorder', 'aZ09comma');
34 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
35 $optioncss = GETPOST('optioncss', 'alpha');
36 $massaction = GETPOST('massaction', 'alpha');
37 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
38 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
39  $page = 0;
40 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
41 $offset = $limit * $page;
42 $pageprev = $page - 1;
43 $pagenext = $page + 1;
44 if (!$sortorder) {
45  $sortorder = "DESC";
46 }
47 if (!$sortfield) {
48  $sortfield = "m.date_creat";
49 }
50 
51 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
52 $search_ref = GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha");
53 $filteremail = GETPOST('filteremail', 'alpha');
54 
55 $object = new Mailing($db);
56 
57 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
58 $hookmanager->initHooks(array('mailinglist'));
59 $extrafields = new ExtraFields($db);
60 
61 // fetch optionals attributes and labels
62 $extrafields->fetch_name_optionals_label($object->table_element);
63 
64 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
65 
66 // List of fields to search into when doing a "search in all"
67 $fieldstosearchall = array(
68  'm.titre'=>'Ref',
69 );
70 
71 // Security check
72 if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
74 }
75 //$result = restrictedArea($user, 'mailing');
76 
77 
78 
79 /*
80  * Actions
81  */
82 
83 if (GETPOST('cancel', 'alpha')) {
84  $action = 'list'; $massaction = '';
85 }
86 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
87  $massaction = '';
88 }
89 
90 $parameters = array();
91 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
92 if ($reshook < 0) {
93  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
94 }
95 
96 if (empty($reshook)) {
97  // Selection of new fields
98  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
99 
100  // Purge search criteria
101  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
102  /*foreach($object->fields as $key => $val)
103  {
104  $search[$key]='';
105  }*/
106  $search_ref = '';
107  $search_all = '';
108  $toselect = array();
109  $search_array_options = array();
110  }
111  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
112  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
113  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
114  }
115 
116  // Mass actions
117  /*$objectclass='MyObject';
118  $objectlabel='MyObject';
119  $permissiontoread = $user->rights->mymodule->read;
120  $permissiontodelete = $user->rights->mymodule->delete;
121  $uploaddir = $conf->mymodule->dir_output;
122  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
123  */
124 }
125 
126 
127 /*
128  * View
129  */
130 
131 llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
132 
133 $form = new Form($db);
134 
135 if ($filteremail) {
136  $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
137  $sql .= " mc.statut as sendstatut";
138  $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
139  $sql .= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
140  $sql .= " AND mc.email = '".$db->escape($filteremail)."'";
141  if ($search_ref) {
142  $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
143  }
144  if ($search_all) {
145  $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
146  }
147  if (!$sortorder) {
148  $sortorder = "ASC";
149  }
150  if (!$sortfield) {
151  $sortfield = "m.rowid";
152  }
153 } else {
154  $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
155  $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
156  $sql .= " WHERE m.entity = ".$conf->entity;
157  if ($search_ref) {
158  $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
159  }
160  if ($search_all) {
161  $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
162  }
163  if (!$sortorder) {
164  $sortorder = "ASC";
165  }
166  if (!$sortfield) {
167  $sortfield = "m.rowid";
168  }
169 }
170 
171 $sql .= $db->order($sortfield, $sortorder);
172 
173 $nbtotalofrecords = '';
174 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
175  $resql = $db->query($sql);
176  $nbtotalofrecords = $db->num_rows($resql);
177  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
178  $page = 0;
179  $offset = 0;
180  }
181 }
182 
183 $sql .= $db->plimit($limit + 1, $offset);
184 //print $sql;
185 
186 dol_syslog("comm/mailing/list.php", LOG_DEBUG);
187 $resql = $db->query($sql);
188 if ($resql) {
189  $num = $db->num_rows($resql);
190 
191  $title = $langs->trans("EMailings");
192  if ($filteremail) {
193  $title .= ' ('.$langs->trans("SentTo", $filteremail).')';
194  }
195 
196  $newcardbutton = '';
197  if ($user->rights->mailing->creer) {
198  $newcardbutton .= dolGetButtonTitle($langs->trans('NewMailing'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/mailing/card.php?action=create');
199  }
200 
201  $i = 0;
202 
203  $param = "&search_all=".urlencode($search_all);
204  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
205  $param .= '&contextpage='.urlencode($contextpage);
206  }
207  if ($limit > 0 && $limit != $conf->liste_limit) {
208  $param .= '&limit='.urlencode($limit);
209  }
210  if ($filteremail) {
211  $param .= '&filteremail='.urlencode($filteremail);
212  }
213 
214  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
215  if ($optioncss != '') {
216  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
217  }
218  print '<input type="hidden" name="token" value="'.newToken().'">';
219  print '<input type="hidden" name="action" value="list">';
220  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
221  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
222 
223  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_email', 0, $newcardbutton, '', $limit, 0, 0, 1);
224 
225  $moreforfilter = '';
226 
227  print '<div class="div-table-responsive">';
228  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
229 
230  print '<tr class="liste_titre_filter">';
231  print '<td class="liste_titre">';
232  print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
233  print '</td>';
234  // Title
235  print '<td class="liste_titre">';
236  print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
237  print '</td>';
238  print '<td class="liste_titre">&nbsp;</td>';
239  if (!$filteremail) {
240  print '<td class="liste_titre">&nbsp;</td>';
241  }
242  print '<td class="liste_titre">&nbsp;</td>';
243  print '<td class="liste_titre">&nbsp;</td>';
244  print '<td class="liste_titre maxwidthsearch">';
245  $searchpicto = $form->showFilterAndCheckAddButtons(0);
246  print $searchpicto;
247  print '</td>';
248  print "</tr>\n";
249 
250  print '<tr class="liste_titre">';
251  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "m.rowid", $param, "", "", $sortfield, $sortorder);
252  print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "m.titre", $param, "", "", $sortfield, $sortorder);
253  print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", 'align="center"', $sortfield, $sortorder);
254  if (!$filteremail) {
255  print_liste_field_titre("NbOfEMails", $_SERVER["PHP_SELF"], "m.nbemail", $param, "", 'align="center"', $sortfield, $sortorder);
256  }
257  if (!$filteremail) {
258  print_liste_field_titre("DateLastSend", $_SERVER["PHP_SELF"], "m.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
259  } else {
260  print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
261  }
262  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], ($filteremail ? "mc.statut" : "m.statut"), $param, "", 'class="right"', $sortfield, $sortorder);
263  print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', 'class="right"', $sortfield, $sortorder, 'maxwidthsearch ');
264  print "</tr>\n";
265 
266 
267  $email = new Mailing($db);
268 
269  while ($i < min($num, $limit)) {
270  $obj = $db->fetch_object($resql);
271 
272  $email->id = $obj->rowid;
273  $email->ref = $obj->rowid;
274 
275  print '<tr class="oddeven">';
276 
277  print '<td>';
278  print $email->getNomUrl(1);
279  print '</td>';
280 
281  // Title
282  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
283 
284  // Date creation
285  print '<td class="center">';
286  print dol_print_date($db->jdate($obj->datec), 'day');
287  print '</td>';
288 
289  // Nb of email
290  if (!$filteremail) {
291  print '<td class="center nowraponall">';
292  $nbemail = $obj->nbemail;
293  /*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
294  {
295  $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
296  print $form->textwithpicto($nbemail,$text,1,'warning');
297  }
298  else
299  {
300  print $nbemail;
301  }*/
302  print $nbemail;
303  print '</td>';
304  }
305 
306  // Last send
307  print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi), 'day').'</td>';
308  print '</td>';
309 
310  // Status
311  print '<td class="nowrap right">';
312  if ($filteremail) {
313  print $email::libStatutDest($obj->sendstatut, 2);
314  } else {
315  print $email->LibStatut($obj->statut, 5);
316  }
317  print '</td>';
318 
319  print '<td></td>';
320 
321  print "</tr>\n";
322  $i++;
323  }
324  if (empty($num)) {
325  $colspan = 6;
326  if (!$filteremail) {
327  $colspan++;
328  }
329  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
330  }
331 
332  print '</table>';
333  print '</div>';
334  print '</form>';
335 
336  $db->free($resql);
337 } else {
338  dol_print_error($db);
339 }
340 
341 // End of page
342 llxFooter();
343 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage emailings module.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.