dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("mails");
29 
30 // Security check
31 $result=restrictedArea($user,'mailing');
32 
33 $sortfield = GETPOST("sortfield",'alpha');
34 $sortorder = GETPOST("sortorder",'alpha');
35 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
36 $page = GETPOST("page",'int');
37 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
38 $offset = $limit * $page;
39 $pageprev = $page - 1;
40 $pagenext = $page + 1;
41 if (! $sortorder) $sortorder="DESC";
42 if (! $sortfield) $sortfield="m.date_creat";
43 
44 $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
45 $sref=GETPOST("sref", "alpha");
46 $filteremail=GETPOST('filteremail','alpha');
47 
48 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
49 $hookmanager->initHooks(array('mailinglist'));
50 $extrafields = new ExtraFields($db);
51 
52 // fetch optionals attributes and labels
53 $extralabels = $extrafields->fetch_name_optionals_label('mailing');
54 $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
55 
56 // List of fields to search into when doing a "search in all"
57 $fieldstosearchall = array(
58  'm.titre'=>'Ref',
59 );
60 
61 
62 
63 /*
64  * View
65  */
66 
67 llxHeader('',$langs->trans("Mailing"),'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
68 
69 $form = new Form($db);
70 
71 if ($filteremail)
72 {
73  $sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
74  $sql.= " mc.statut as sendstatut";
75  $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
76  $sql.= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
77  $sql.= " AND mc.email = '".$db->escape($filteremail)."'";
78  if ($sref) $sql.= " AND m.rowid = '".$db->escape($sref)."'";
79  if ($sall) $sql.= " AND (m.titre like '%".$db->escape($sall)."%' OR m.sujet like '%".$db->escape($sall)."%' OR m.body like '%".$db->escape($sall)."%')";
80  if (! $sortorder) $sortorder="ASC";
81  if (! $sortfield) $sortfield="m.rowid";
82  $sql.= $db->order($sortfield,$sortorder);
83  $sql.= $db->plimit($conf->liste_limit +1, $offset);
84 }
85 else
86 {
87  $sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
88  $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
89  $sql.= " WHERE m.entity = ".$conf->entity;
90  if ($sref) $sql.= " AND m.rowid = '".$db->escape($sref)."'";
91  if ($sall) $sql.= " AND (m.titre like '%".$db->escape($sall)."%' OR m.sujet like '%".$db->escape($sall)."%' OR m.body like '%".$db->escape($sall)."%')";
92  if (! $sortorder) $sortorder="ASC";
93  if (! $sortfield) $sortfield="m.rowid";
94  $sql.= $db->order($sortfield,$sortorder);
95  $sql.= $db->plimit($conf->liste_limit +1, $offset);
96 }
97 
98 //print $sql;
99 $result = $db->query($sql);
100 if ($result)
101 {
102  $num = $db->num_rows($result);
103 
104  $title=$langs->trans("ListOfEMailings");
105  if ($filteremail) $title.=' ('.$langs->trans("SentTo",$filteremail).')';
106  print_barre_liste($title, $page, $_SERVER["PHP_SELF"],"",$sortfield,$sortorder,"",$num);
107 
108  $i = 0;
109 
110  $param = "&amp;sall=".urlencode($sall);
111  if ($filteremail) $param.='&amp;filteremail='.urlencode($filteremail);
112 
113  print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
114  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
115  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
116  print '<input type="hidden" name="action" value="list">';
117  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
118  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
119  print '<input type="hidden" name="page" value="'.$page.'">';
120 
121  $moreforfilter = '';
122 
123  print '<div class="div-table-responsive">';
124  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
125 
126  print '<tr class="liste_titre_filter">';
127  print '<td class="liste_titre">';
128  print '<input type="text" class="flat maxwidth50" name="sref" value="'.dol_escape_htmltag($sref).'">';
129  print '</td>';
130  // Title
131  print '<td class="liste_titre">';
132  print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="sall" value="'.dol_escape_htmltag($sall).'">';
133  print '</td>';
134  print '<td class="liste_titre">&nbsp;</td>';
135  if (! $filteremail) print '<td class="liste_titre">&nbsp;</td>';
136  print '<td class="liste_titre">&nbsp;</td>';
137  print '<td class="liste_titre">&nbsp;</td>';
138  print '<td class="liste_titre" align="right">';
139  $searchpicto=$form->showFilterAndCheckAddButtons(0);
140  print $searchpicto;
141  print '</td>';
142  print "</tr>\n";
143 
144  print '<tr class="liste_titre">';
145  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"m.rowid",$param,"","",$sortfield,$sortorder);
146  print_liste_field_titre("Title",$_SERVER["PHP_SELF"],"m.titre",$param,"","",$sortfield,$sortorder);
147  print_liste_field_titre("DateCreation",$_SERVER["PHP_SELF"],"m.date_creat",$param,"",'align="center"',$sortfield,$sortorder);
148  if (! $filteremail) print_liste_field_titre("NbOfEMails",$_SERVER["PHP_SELF"],"m.nbemail",$param,"",'align="center"',$sortfield,$sortorder);
149  if (! $filteremail) print_liste_field_titre("DateLastSend",$_SERVER["PHP_SELF"],"m.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
150  else print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
151  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],($filteremail?"mc.statut":"m.statut"),$param,"",'align="right"',$sortfield,$sortorder);
152  print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
153  print "</tr>\n";
154 
155 
156  $email=new Mailing($db);
157 
158  while ($i < min($num,$limit))
159  {
160  $obj = $db->fetch_object($result);
161 
162 
163 
164  print "<tr>";
165  print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$obj->rowid.'">';
166  print img_object($langs->trans("ShowEMail"),"email").' '.stripslashes($obj->rowid).'</a></td>';
167  print '<td>'.$obj->titre.'</td>';
168  // Date creation
169  print '<td align="center">';
170  print dol_print_date($db->jdate($obj->datec),'day');
171  print '</td>';
172  // Nb of email
173  if (! $filteremail)
174  {
175  print '<td align="center">';
176  $nbemail = $obj->nbemail;
177  /*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
178  {
179  $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
180  print $form->textwithpicto($nbemail,$text,1,'warning');
181  }
182  else
183  {
184  print $nbemail;
185  }*/
186  print $nbemail;
187  print '</td>';
188  }
189  // Last send
190  print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi),'day').'</td>';
191  print '</td>';
192  // Status
193  print '<td align="right" class="nowrap">';
194  if ($filteremail)
195  {
196  print $email::libStatutDest($obj->sendstatut,2);
197  }
198  else
199  {
200  print $email->LibStatut($obj->statut,5);
201  }
202  print '</td>';
203  print '<td></td>';
204  print "</tr>\n";
205  $i++;
206  }
207  print '</table>';
208  print '</div>';
209  print '</form>';
210  $db->free($result);
211 }
212 else
213 {
214  dol_print_error($db);
215 }
216 
217 llxFooter();
218 
219 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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).
print
Draft customers invoices.
Definition: index.php:91
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.