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