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