dolibarr  7.0.0-beta
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 
31 $langs->load("members");
32 
33 $filter=$_GET["filter"];
34 $statut=isset($_GET["statut"])?$_GET["statut"]:1;
35 $search_ref=GETPOST('search_ref','alpha');
36 $search_lastname=GETPOST('search_lastname','alpha');
37 $search_login=GETPOST('search_login','alpha');
38 $search_note=GETPOST('search_note','alpha');
39 $search_account=GETPOST('search_account','int');
40 $search_amount=GETPOST('search_amount','alpha');
41 $optioncss = GETPOST('optioncss','alpha');
42 
43 $date_select=isset($_GET["date_select"])?$_GET["date_select"]:$_POST["date_select"];
44 
45 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
46 $sortfield = GETPOST("sortfield",'alpha');
47 $sortorder = GETPOST("sortorder",'alpha');
48 $page = GETPOST("page",'int');
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 $offset = $limit * $page ;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (! $sortorder) { $sortorder="DESC"; }
54 if (! $sortfield) { $sortfield="c.dateadh"; }
55 
56 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
57 $hookmanager->initHooks(array('subscriptionlist'));
58 $extrafields = new ExtraFields($db);
59 
60 // fetch optionals attributes and labels
61 $extralabels = $extrafields->fetch_name_optionals_label('subscription');
62 $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
63 
64 // List of fields to search into when doing a "search in all"
65 $fieldstosearchall = array(
66 );
67 $arrayfields=array(
68 );
69 
70 // Security check
71 $result=restrictedArea($user,'adherent','','','cotisation');
72 
73 
74 /*
75  * Actions
76  */
77 
78 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
79 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
80 
81 $parameters=array('socid'=>$socid);
82 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
83 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
84 
85 if (empty($reshook))
86 {
87  // Selection of new fields
88  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
89 
90  // Purge search criteria
91  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
92  {
93  $search="";
94  $search_ref="";
95  $search_lastname="";
96  $search_firstname="";
97  $search_login="";
98  $search_note="";
99  $search_amount="";
100  $search_account="";
101  $toselect='';
102  $search_array_options=array();
103  }
104 }
105 
106 
107 /*
108  * View
109  */
110 
111 $form=new Form($db);
112 
113 llxHeader('',$langs->trans("ListOfSubscriptions"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
114 
115 
116 // List of subscriptions
117 $sql = "SELECT d.rowid, d.login, d.firstname, d.lastname, d.societe, d.photo,";
118 $sql.= " c.rowid as crowid, c.subscription,";
119 $sql.= " c.dateadh,";
120 $sql.= " c.datef,";
121 $sql.= " c.fk_bank as bank, c.note,";
122 $sql.= " b.fk_account";
123 $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
124 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank=b.rowid";
125 $sql.= " WHERE d.rowid = c.fk_adherent";
126 $sql.= " AND d.entity IN (".getEntity('adherent').")";
127 if (isset($date_select) && $date_select != '')
128 {
129  $sql.= " AND c.dateadh LIKE '".$date_select."%'";
130 }
131 if ($search_ref)
132 {
133  if (is_numeric($search_ref)) $sql.= " AND (c.rowid = ".$db->escape($search_ref).")";
134  else $sql.=" AND 1 = 2"; // Always wrong
135 }
136 if ($search_lastname) $sql.= natural_search(array('d.firstname','d.lastname','d.societe'), $search_lastname);
137 if ($search_login) $sql.= natural_search('c.subscription', $search_login);
138 if ($search_note) $sql.= natural_search('c.note', $search_note);
139 if ($search_account > 0) $sql.= " AND b.fk_account = ".$search_account;
140 if ($search_amount) $sql.= natural_search('c.subscription', $search_amount, 1);
141 $sql.= $db->order($sortfield,$sortorder);
142 
143 $nbtotalofrecords = '';
144 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
145 {
146  $result = $db->query($sql);
147  $nbtotalofrecords = $db->num_rows($result);
148 }
149 
150 $sql.= $db->plimit($limit+1, $offset);
151 
152 $result = $db->query($sql);
153 if ($result)
154 {
155  $num = $db->num_rows($result);
156 
157  $arrayofselected=is_array($toselect)?$toselect:array();
158 
159  $i = 0;
160 
161  $title=$langs->trans("ListOfSubscriptions");
162  if (! empty($date_select)) $title.=' ('.$langs->trans("Year").' '.$date_select.')';
163 
164  $param='';
165  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
166  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
167  if ($statut != '') $param.="&statut=".$statut;
168  if ($date_select) $param.="&date_select=".$date_select;
169  if ($search_lastname) $param.="&search_lastname=".$search_lastname;
170  if ($search_login) $param.="&search_login=".$search_login;
171  if ($search_acount) $param.="&search_account=".$search_account;
172  if ($search_amount) $param.="&search_amount=".$search_amount;
173  if ($optioncss != '') $param.='&optioncss='.$optioncss;
174 
175  // List of mass actions available
176  $arrayofmassactions = array(
177  //'presend'=>$langs->trans("SendByMail"),
178  //'builddoc'=>$langs->trans("PDFMerge"),
179  );
180  if ($user->rights->adherent->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
181  if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
182  $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
183 
184  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
185  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
186  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
187  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
188  print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
189  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
190  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
191  print '<input type="hidden" name="page" value="'.$page.'">';
192  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
193 
194  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_generic.png', 0, '', '', $limit);
195 
196  $topicmail="Information";
197  $modelmail="subscription";
198  $objecttmp=new Subscription($db);
199  $trackid='sub'.$object->id;
200  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
201 
202  if ($sall)
203  {
204  print $langs->trans("Filter")." (".$langs->trans("Ref").", ".$langs->trans("Lastname").", ".$langs->trans("Firstname").", ".$langs->trans("EMail").", ".$langs->trans("Address")." ".$langs->trans("or")." ".$langs->trans("Town")."): ".$sall;
205  }
206 
207  $moreforfilter = '';
208 
209  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
210  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
211  if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
212 
213  print '<div class="div-table-responsive">';
214  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
215 
216  // Line for filters fields
217  print '<tr class="liste_titre_filter">';
218 
219  print '<td class="liste_titre" align="left">';
220  print '<input class="flat" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'" size="4"></td>';
221 
222  print '<td class="liste_titre" align="left">';
223  print '<input class="flat" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'" size="12"></td>';
224 
225  print '<td class="liste_titre" align="left">';
226  print '<input class="flat" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'" size="7"></td>';
227 
228  print '<td class="liste_titre" align="left">';
229  print '<input class="flat" type="text" name="search_note" value="'.dol_escape_htmltag($search_note).'" size="7"></td>';
230 
231  if (! empty($conf->banque->enabled))
232  {
233  print '<td class="liste_titre">';
234  print $form->select_comptes($search_account, 'search_account', 0, '', 1);
235  print '</td>';
236  }
237 
238  print '<td class="liste_titre">&nbsp;</td>';
239 
240  print '<td class="liste_titre">&nbsp;</td>';
241 
242  print '<td align="right" class="liste_titre">';
243  print '<input class="flat" type="text" name="search_amount" value="'.dol_escape_htmltag($search_amount).'" size="4">';
244  print '</td>';
245 
246  // Action column
247  print '<td class="liste_titre" align="right">';
248  $searchpicto=$form->showFilterButtons();
249  print $searchpicto;
250  print '</td>';
251 
252  print "</tr>\n";
253 
254 
255  print '<tr class="liste_titre">';
256  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"c.rowid",$param,"","",$sortfield,$sortorder);
257  print_liste_field_titre("Name",$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder);
258  print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder);
259  print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"c.note",$param,"",'align="left"',$sortfield,$sortorder);
260  if (! empty($conf->banque->enabled))
261  {
262  print_liste_field_titre("Account",$_SERVER["PHP_SELF"],"b.fk_account",$pram,"","",$sortfield,$sortorder);
263  }
264  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"c.dateadh",$param,"",'align="center"',$sortfield,$sortorder);
265  print_liste_field_titre("DateEnd",$_SERVER["PHP_SELF"],"c.datef",$param,"",'align="center"',$sortfield,$sortorder);
266  print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"c.subscription",$param,"",'align="right"',$sortfield,$sortorder);
267  //print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
268  print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
269  print "</tr>\n";
270 
271 
272  // Static objects
273  $subscription=new Subscription($db);
274  $adherent=new Adherent($db);
275  $accountstatic=new Account($db);
276 
277  $total=0;
278  while ($i < min($num, $limit))
279  {
280  $obj = $db->fetch_object($result);
281  $total+=$obj->subscription;
282 
283  $subscription->ref=$obj->crowid;
284  $subscription->id=$obj->crowid;
285 
286  $adherent->lastname=$obj->lastname;
287  $adherent->firstname=$obj->firstname;
288  $adherent->ref=$obj->rowid;
289  $adherent->id=$obj->rowid;
290  $adherent->statut=$obj->statut;
291  $adherent->login=$obj->login;
292  $adherent->photo=$obj->photo;
293 
294 
295 
296  print '<tr class="oddeven">';
297 
298  // Ref
299  print '<td>'.$subscription->getNomUrl(1).'</td>';
300 
301  // Lastname
302  print '<td>'.$adherent->getNomUrl(-1).'</td>';
303 
304  // Login
305  print '<td>'.$adherent->login.'</td>';
306 
307  // Libelle
308  print '<td>';
309  print dol_trunc($obj->note,32);
310  print '</td>';
311 
312  // Banque
313  if (! empty($conf->banque->enabled))
314  {
315  if ($obj->fk_account > 0)
316  {
317  $accountstatic->id=$obj->fk_account;
318  $accountstatic->fetch($obj->fk_account);
319  //$accountstatic->label=$obj->label;
320  print '<td>'.$accountstatic->getNomUrl(1).'</td>';
321  }
322  else
323  {
324  print "<td>";
325  print "</td>\n";
326  }
327  }
328 
329  // Date start
330  print '<td align="center">'.dol_print_date($db->jdate($obj->dateadh),'day')."</td>\n";
331 
332  // Date end
333  print '<td align="center">'.dol_print_date($db->jdate($obj->datef),'day')."</td>\n";
334 
335  // Price
336  print '<td align="right">'.price($obj->subscription).'</td>';
337 
338  print '<td></td>';
339 
340  print "</tr>";
341 
342  $i++;
343  }
344 
345  // Total
346 
347  print '<tr class="liste_total">';
348  print "<td>".$langs->trans("Total")."</td>\n";
349  print "<td align=\"right\">&nbsp;</td>\n";
350  print "<td align=\"right\">&nbsp;</td>\n";
351  print "<td align=\"right\">&nbsp;</td>\n";
352  if (! empty($conf->banque->enabled))
353  {
354  print '<td>&nbsp;</td>';
355  }
356  print '<td>&nbsp;</td>';
357  print '<td>&nbsp;</td>';
358  print '<td align="right">'.price($total)."</td>\n";
359  print '<td></td>';
360  print "</tr>\n";
361 
362  print "</table>";
363  print '</div>';
364  print '</form>';
365 }
366 else
367 {
368  dol_print_error($db);
369 }
370 
371 
372 llxFooter();
373 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
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
Class to manage bank accounts.
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
Class to manage members of a foundation.
llxHeader()
Empty header.
Definition: wrapper.php:46
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
Class to manage subscriptions of foundation members.
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.