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