dolibarr  9.0.0
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 C├ędric Salvador <csalvador@gpcsolutions.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
29 if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("companies","donations"));
33 
34 $sortfield = GETPOST("sortfield",'alpha');
35 $sortorder = GETPOST("sortorder",'alpha');
36 $page = GETPOST("page",'int');
37 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
38 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
39 $offset = $limit * $page;
40 $pageprev = $page - 1;
41 $pagenext = $page + 1;
42 if (! $sortorder) $sortorder="DESC";
43 if (! $sortfield) $sortfield="d.datedon";
44 
45 $statut=(GETPOST("statut",'intcomma')!='')?GETPOST("statut",'intcomma'):"-1";
46 $search_all=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
47 $search_ref=GETPOST('search_ref','alpha');
48 $search_company=GETPOST('search_company','alpha');
49 $search_name=GETPOST('search_name','alpha');
50 $search_amount = GETPOST('search_amount','alpha');
51 $optioncss = GETPOST('optioncss','alpha');
52 
53 if (!$user->rights->don->lire) accessforbidden();
54 
55 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
56 {
57  $search_all="";
58  $search_ref="";
59  $search_company="";
60  $search_name="";
61  $search_amount="";
62 }
63 
64 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
65 $hookmanager->initHooks(array('orderlist'));
66 
67 
68 // List of fields to search into when doing a "search in all"
69 $fieldstosearchall = array(
70  'd.rowid'=>'Id',
71  'd.ref'=>'Ref',
72  'd.lastname'=>'Lastname',
73  'd.firstname'=>'Firstname',
74 );
75 
76 /*
77  * View
78  */
79 
80 $form=new Form($db);
81 if (! empty($conf->projet->enabled)) $projectstatic=new Project($db);
82 
83 llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
84 
85 $donationstatic=new Don($db);
86 
87 // Genere requete de liste des dons
88 $sql = "SELECT d.rowid, d.datedon, d.firstname, d.lastname, d.societe,";
89 $sql.= " d.amount, d.fk_statut as statut, ";
90 $sql.= " p.rowid as pid, p.ref, p.title, p.public";
91 $sql.= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
92 $sql.= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
93 if ($statut != '' && $statut != '-1')
94 {
95  $sql .= " AND d.fk_statut IN (".$db->escape($statut).")";
96 }
97 if (trim($search_ref) != '')
98 {
99  $sql.= natural_search('d.ref', $search_ref);
100 }
101 if (trim($search_all) != '')
102 {
103  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
104 }
105 if (trim($search_company) != '')
106 {
107  $sql .= natural_search('d.societe', $search_company);
108 }
109 if (trim($search_name) != '')
110 {
111  $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
112 }
113 if ($search_amount) $sql.= natural_search('d.amount', $search_amount, 1);
114 
115 $sql.= $db->order($sortfield,$sortorder);
116 
117 $nbtotalofrecords = '';
118 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
119 {
120  $result = $db->query($sql);
121  $nbtotalofrecords = $db->num_rows($result);
122  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
123  {
124  $page = 0;
125  $offset = 0;
126  }
127 }
128 
129 $sql.= $db->plimit($limit+1, $offset);
130 
131 $resql = $db->query($sql);
132 if ($resql)
133 {
134  $num = $db->num_rows($resql);
135  $i = 0;
136 
137  $param = '&statut='.$statut;
138  //if ($page > 0) $param.= '&page='.$page;
139  if ($optioncss != '') $param.='&optioncss='.$optioncss;
140 
141  $newcardbutton='';
142  if ($user->rights->don->creer)
143  {
144  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/don/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewDonation').'</span>';
145  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
146  $newcardbutton.= '</a>';
147  }
148 
149  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
150  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
151  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
152  print '<input type="hidden" name="action" value="list">';
153  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
154  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
155  print '<input type="hidden" name="page" value="'.$page.'">';
156  print '<input type="hidden" name="type" value="'.$type.'">';
157 
158  print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num,$nbtotalofrecords, 'title_generic.png', 0, $newcardbutton);
159 
160  if ($search_all)
161  {
162  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
163  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall).'</div>';
164  }
165 
166  print '<div class="div-table-responsive">';
167  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
168 
169  // Filters lines
170  print '<tr class="liste_titre_filter">';
171  print '<td class="liste_titre">';
172  print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
173  print '</td>';
174  print '<td class="liste_titre">';
175  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
176  print '</td>';
177  print '<td class="liste_titre">';
178  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
179  print '</td>';
180  print '<td class="liste_titre" align="left">';
181  print '&nbsp;';
182  print '</td>';
183  if (! empty($conf->projet->enabled))
184  {
185  print '<td class="liste_titre" align="right">';
186  print '&nbsp;';
187  print '</td>';
188  }
189  print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
190  print '<td class="liste_titre" align="right"></td>';
191  print '<td class="liste_titre" align="right">';
192  $searchpicto=$form->showFilterAndCheckAddButtons(0);
193  print $searchpicto;
194  print '</td>';
195  print "</tr>\n";
196 
197  print '<tr class="liste_titre">';
198  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid","", $param,"",$sortfield,$sortorder);
199  print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"d.societe","", $param,"",$sortfield,$sortorder);
200  print_liste_field_titre("Name",$_SERVER["PHP_SELF"],"d.lastname","", $param,"",$sortfield,$sortorder);
201  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"d.datedon","", $param,'align="center"',$sortfield,$sortorder);
202  if (! empty($conf->projet->enabled))
203  {
204  $langs->load("projects");
205  print_liste_field_titre("Project",$_SERVER["PHP_SELF"],"fk_projet","", $param,"",$sortfield,$sortorder);
206  }
207  print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"d.amount","", $param,'align="right"',$sortfield,$sortorder);
208  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.fk_statut","", $param,'align="right"',$sortfield,$sortorder);
210  print "</tr>\n";
211 
212  while ($i < min($num,$limit))
213  {
214  $objp = $db->fetch_object($resql);
215 
216  print '<tr class="oddeven">';
217  $donationstatic->id=$objp->rowid;
218  $donationstatic->ref=$objp->rowid;
219  $donationstatic->lastname=$objp->lastname;
220  $donationstatic->firstname=$objp->firstname;
221  print "<td>".$donationstatic->getNomUrl(1)."</td>\n";
222  print "<td>".$objp->societe."</td>\n";
223  print "<td>".$donationstatic->getFullName($langs)."</td>\n";
224  print '<td align="center">'.dol_print_date($db->jdate($objp->datedon),'day').'</td>';
225  if (! empty($conf->projet->enabled))
226  {
227  print "<td>";
228  if ($objp->pid)
229  {
230  $projectstatic->id=$objp->pid;
231  $projectstatic->ref=$objp->ref;
232  $projectstatic->id=$objp->pid;
233  $projectstatic->public=$objp->public;
234  $projectstatic->title=$objp->title;
235  print $projectstatic->getNomUrl(1);
236  }
237  else print '&nbsp;';
238  print "</td>\n";
239  }
240  print '<td align="right">'.price($objp->amount).'</td>';
241  print '<td align="right">'.$donationstatic->LibStatut($objp->statut,5).'</td>';
242  print '<td></td>';
243  print "</tr>";
244  $i++;
245  }
246  print "</table>";
247  print '</div>';
248  print "</form>\n";
249  $db->free($resql);
250 }
251 else
252 {
253  dol_print_error($db);
254 }
255 
256 llxFooter();
257 $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
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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.
Class to manage projects.
llxHeader()
Empty header.
Definition: wrapper.php:44
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 donations.
Definition: don.class.php:35
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.