dolibarr  16.0.1
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  * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
30 if (!empty($conf->project->enabled)) {
31  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32 }
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("companies", "donations"));
36 
37 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'sclist';
38 
39 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
40 $sortfield = GETPOST('sortfield', 'aZ09comma');
41 $sortorder = GETPOST('sortorder', 'aZ09comma');
42 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
43 if (empty($page) || $page == -1) {
44  $page = 0;
45 } // If $page is not defined, or '' or -1
46 $offset = $limit * $page;
47 $pageprev = $page - 1;
48 $pagenext = $page + 1;
49 if (!$sortorder) {
50  $sortorder = "DESC";
51 }
52 if (!$sortfield) {
53  $sortfield = "d.datedon";
54 }
55 
56 $search_status = (GETPOST("search_status", 'intcomma') != '') ? GETPOST("search_status", 'intcomma') : "-4";
57 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
58 $search_ref = GETPOST('search_ref', 'alpha');
59 $search_company = GETPOST('search_company', 'alpha');
60 $search_name = GETPOST('search_name', 'alpha');
61 $search_amount = GETPOST('search_amount', 'alpha');
62 $optioncss = GETPOST('optioncss', 'alpha');
63 
64 if (!$user->rights->don->lire) {
66 }
67 
68 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
69  $search_all = "";
70  $search_ref = "";
71  $search_company = "";
72  $search_name = "";
73  $search_amount = "";
74  $search_status = '';
75 }
76 
77 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
78 $hookmanager->initHooks(array('orderlist'));
79 
80 
81 // List of fields to search into when doing a "search in all"
82 $fieldstosearchall = array(
83  'd.rowid'=>'Id',
84  'd.ref'=>'Ref',
85  'd.lastname'=>'Lastname',
86  'd.firstname'=>'Firstname',
87 );
88 
89 
90 /*
91  * View
92  */
93 
94 $donationstatic = new Don($db);
95 $form = new Form($db);
96 if (!empty($conf->project->enabled)) {
97  $projectstatic = new Project($db);
98 }
99 
100 $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
101 
102 llxHeader('', $langs->trans("Donations"), $help_url);
103 
104 // Genere requete de liste des dons
105 $sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
106 $sql .= " d.amount, d.fk_statut as status,";
107 $sql .= " p.rowid as pid, p.ref, p.title, p.public";
108 $sql .= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
109 $sql .= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
110 if ($search_status != '' && $search_status != '-4') {
111  $sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
112 }
113 if (trim($search_ref) != '') {
114  $sql .= natural_search('d.ref', $search_ref);
115 }
116 if (trim($search_all) != '') {
117  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
118 }
119 if (trim($search_company) != '') {
120  $sql .= natural_search('d.societe', $search_company);
121 }
122 if (trim($search_name) != '') {
123  $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
124 }
125 if ($search_amount) {
126  $sql .= natural_search('d.amount', $search_amount, 1);
127 }
128 
129 $sql .= $db->order($sortfield, $sortorder);
130 
131 $nbtotalofrecords = '';
132 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
133  $result = $db->query($sql);
134  $nbtotalofrecords = $db->num_rows($result);
135  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
136  $page = 0;
137  $offset = 0;
138  }
139 }
140 
141 $sql .= $db->plimit($limit + 1, $offset);
142 
143 $resql = $db->query($sql);
144 if ($resql) {
145  $num = $db->num_rows($resql);
146  $i = 0;
147 
148  $param = '';
149  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
150  $param .= '&contextpage='.urlencode($contextpage);
151  }
152  if ($limit > 0 && $limit != $conf->liste_limit) {
153  $param .= '&limit='.urlencode($limit);
154  }
155  if ($optioncss != '') {
156  $param .= '&optioncss='.urlencode($optioncss);
157  }
158  if ($search_status && $search_status != -1) {
159  $param .= '&search_status='.urlencode($search_status);
160  }
161  if ($search_ref) {
162  $param .= '&search_ref='.urlencode($search_ref);
163  }
164  if ($search_company) {
165  $param .= '&search_company='.urlencode($search_company);
166  }
167  if ($search_name) {
168  $param .= '&search_name='.urlencode($search_name);
169  }
170  if ($search_amount) {
171  $param .= '&search_amount='.urlencode($search_amount);
172  }
173 
174  $newcardbutton = '';
175  if ($user->rights->don->creer) {
176  $newcardbutton .= dolGetButtonTitle($langs->trans('NewDonation'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/don/card.php?action=create');
177  }
178 
179  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
180  if ($optioncss != '') {
181  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
182  }
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  print '<input type="hidden" name="page" value="'.$page.'">';
188  print '<input type="hidden" name="type" value="'.$type.'">';
189 
190  print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_donation', 0, $newcardbutton, '', $limit, 0, 0, 1);
191 
192  if ($search_all) {
193  foreach ($fieldstosearchall as $key => $val) {
194  $fieldstosearchall[$key] = $langs->trans($val);
195  }
196  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
197  }
198 
199  print '<div class="div-table-responsive">';
200  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
201 
202  // Filters lines
203  print '<tr class="liste_titre_filter">';
204  print '<td class="liste_titre">';
205  print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
206  print '</td>';
207  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
208  print '<td class="liste_titre">';
209  print '<input class="flat" size="10" type="text" name="search_thirdparty" value="'.$search_thirdparty.'">';
210  print '</td>';
211  } else {
212  print '<td class="liste_titre">';
213  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
214  print '</td>';
215  }
216  print '<td class="liste_titre">';
217  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
218  print '</td>';
219  print '<td class="liste_titre left">';
220  print '&nbsp;';
221  print '</td>';
222  if (!empty($conf->project->enabled)) {
223  print '<td class="liste_titre right">';
224  print '&nbsp;';
225  print '</td>';
226  }
227  print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
228  print '<td class="liste_titre right">';
229  $liststatus = array(
230  Don::STATUS_DRAFT=>$langs->trans("DonationStatusPromiseNotValidated"),
231  Don::STATUS_VALIDATED=>$langs->trans("DonationStatusPromiseValidated"),
232  Don::STATUS_PAID=>$langs->trans("DonationStatusPaid"),
233  Don::STATUS_CANCELED=>$langs->trans("Canceled")
234  );
235  print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
236  print '</td>';
237  print '<td class="liste_titre maxwidthsearch">';
238  $searchpicto = $form->showFilterAndCheckAddButtons(0);
239  print $searchpicto;
240  print '</td>';
241  print "</tr>\n";
242 
243  print '<tr class="liste_titre">';
244  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
245  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
246  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "d.fk_soc", "", $param, "", $sortfield, $sortorder);
247  } else {
248  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "d.societe", "", $param, "", $sortfield, $sortorder);
249  }
250  print_liste_field_titre("Name", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
251  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.datedon", "", $param, '', $sortfield, $sortorder, 'center ');
252  if (!empty($conf->project->enabled)) {
253  $langs->load("projects");
254  print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "d.fk_projet", "", $param, "", $sortfield, $sortorder);
255  }
256  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "d.amount", "", $param, '', $sortfield, $sortorder, 'right ');
257  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
259  print "</tr>\n";
260 
261  while ($i < min($num, $limit)) {
262  $objp = $db->fetch_object($resql);
263 
264  print '<tr class="oddeven">';
265  $donationstatic->id = $objp->rowid;
266  $donationstatic->ref = $objp->rowid;
267  $donationstatic->lastname = $objp->lastname;
268  $donationstatic->firstname = $objp->firstname;
269  print "<td>".$donationstatic->getNomUrl(1)."</td>";
270  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
271  $company = new Societe($db);
272  $result = $company->fetch($objp->socid);
273  if (!empty($objp->socid) && $company->id > 0) {
274  print "<td>".$company->getNomUrl(1)."</td>";
275  } else {
276  print "<td>".$objp->societe."</td>";
277  }
278  } else {
279  print "<td>".$objp->societe."</td>";
280  }
281  print "<td>".$donationstatic->getFullName($langs)."</td>";
282  print '<td class="center">'.dol_print_date($db->jdate($objp->datedon), 'day').'</td>';
283  if (!empty($conf->project->enabled)) {
284  print "<td>";
285  if ($objp->pid) {
286  $projectstatic->id = $objp->pid;
287  $projectstatic->ref = $objp->ref;
288  $projectstatic->id = $objp->pid;
289  $projectstatic->public = $objp->public;
290  $projectstatic->title = $objp->title;
291  print $projectstatic->getNomUrl(1);
292  } else {
293  print '&nbsp;';
294  }
295  print "</td>\n";
296  }
297  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
298  print '<td class="right">'.$donationstatic->LibStatut($objp->status, 5).'</td>';
299  print '<td></td>';
300  print "</tr>";
301  $i++;
302  }
303  print "</table>";
304  print '</div>';
305  print "</form>\n";
306  $db->free($resql);
307 } else {
308  dol_print_error($db);
309 }
310 
311 llxFooter();
312 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
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.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
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 from a POST of a form...
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage projects.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Class to manage donations.
Definition: don.class.php:38
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:73