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