dolibarr  16.0.5
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_thirdparty = GETPOST('search_thirdparty', 'alpha');
61 $search_name = GETPOST('search_name', 'alpha');
62 $search_amount = GETPOST('search_amount', 'alpha');
63 $optioncss = GETPOST('optioncss', 'alpha');
64 
65 if (!$user->rights->don->lire) {
67 }
68 
69 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
70  $search_all = "";
71  $search_ref = "";
72  $search_company = "";
73  $search_thirdparty = "";
74  $search_name = "";
75  $search_amount = "";
76  $search_status = '';
77 }
78 
79 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
80 $hookmanager->initHooks(array('orderlist'));
81 
82 
83 // List of fields to search into when doing a "search in all"
84 $fieldstosearchall = array(
85  'd.rowid'=>'Id',
86  'd.ref'=>'Ref',
87  'd.lastname'=>'Lastname',
88  'd.firstname'=>'Firstname',
89 );
90 
91 
92 /*
93  * View
94  */
95 
96 $donationstatic = new Don($db);
97 $form = new Form($db);
98 if (!empty($conf->project->enabled)) {
99  $projectstatic = new Project($db);
100 }
101 
102 $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
103 
104 llxHeader('', $langs->trans("Donations"), $help_url);
105 
106 // Genere requete de liste des dons
107 $sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
108 $sql .= " d.amount, d.fk_statut as status,";
109 $sql .= " p.rowid as pid, p.ref, p.title, p.public";
110 $sql .= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
111 $sql .= " ON p.rowid = d.fk_projet";
112 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe AS s ON s.rowid = d.fk_soc";
113 $sql .= " WHERE d.entity IN (". getEntity('donation') . ")";
114 
115 if ($search_status != '' && $search_status != '-4') {
116  $sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
117 }
118 if (trim($search_ref) != '') {
119  $sql .= natural_search(['d.ref', "d.rowid"], $search_ref);
120 }
121 if (trim($search_all) != '') {
122  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
123 }
124 if (trim($search_company) != '') {
125  $sql .= natural_search('d.societe', $search_company);
126 }
127 if (trim($search_thirdparty) != '') {
128  $sql .= natural_search("s.nom", $search_thirdparty);
129 }
130 if (trim($search_name) != '') {
131  $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
132 }
133 if ($search_amount) {
134  $sql .= natural_search('d.amount', $search_amount, 1);
135 }
136 
137 $sql .= $db->order($sortfield, $sortorder);
138 
139 $nbtotalofrecords = '';
140 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
141  $result = $db->query($sql);
142  $nbtotalofrecords = $db->num_rows($result);
143  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
144  $page = 0;
145  $offset = 0;
146  }
147 }
148 
149 $sql .= $db->plimit($limit + 1, $offset);
150 
151 $resql = $db->query($sql);
152 if ($resql) {
153  $num = $db->num_rows($resql);
154  $i = 0;
155 
156  $param = '';
157  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
158  $param .= '&contextpage='.urlencode($contextpage);
159  }
160  if ($limit > 0 && $limit != $conf->liste_limit) {
161  $param .= '&limit='.urlencode($limit);
162  }
163  if ($optioncss != '') {
164  $param .= '&optioncss='.urlencode($optioncss);
165  }
166  if ($search_status && $search_status != -1) {
167  $param .= '&search_status='.urlencode($search_status);
168  }
169  if ($search_ref) {
170  $param .= '&search_ref='.urlencode($search_ref);
171  }
172  if ($search_company) {
173  $param .= '&search_company='.urlencode($search_company);
174  }
175  if ($search_name) {
176  $param .= '&search_name='.urlencode($search_name);
177  }
178  if ($search_amount) {
179  $param .= '&search_amount='.urlencode($search_amount);
180  }
181 
182  $newcardbutton = '';
183  if ($user->rights->don->creer) {
184  $newcardbutton .= dolGetButtonTitle($langs->trans('NewDonation'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/don/card.php?action=create');
185  }
186 
187  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
188  if ($optioncss != '') {
189  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
190  }
191  print '<input type="hidden" name="token" value="'.newToken().'">';
192  print '<input type="hidden" name="action" value="list">';
193  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
194  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
195  print '<input type="hidden" name="page" value="'.$page.'">';
196  print '<input type="hidden" name="type" value="'.$type.'">';
197 
198  print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_donation', 0, $newcardbutton, '', $limit, 0, 0, 1);
199 
200  if ($search_all) {
201  foreach ($fieldstosearchall as $key => $val) {
202  $fieldstosearchall[$key] = $langs->trans($val);
203  }
204  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
205  }
206 
207  print '<div class="div-table-responsive">';
208  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
209 
210  // Filters lines
211  print '<tr class="liste_titre_filter">';
212  print '<td class="liste_titre">';
213  print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
214  print '</td>';
215  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
216  print '<td class="liste_titre">';
217  print '<input class="flat" size="10" type="text" name="search_thirdparty" value="'.$search_thirdparty.'">';
218  print '</td>';
219  } else {
220  print '<td class="liste_titre">';
221  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
222  print '</td>';
223  }
224  print '<td class="liste_titre">';
225  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
226  print '</td>';
227  print '<td class="liste_titre left">';
228  print '&nbsp;';
229  print '</td>';
230  if (!empty($conf->project->enabled)) {
231  print '<td class="liste_titre right">';
232  print '&nbsp;';
233  print '</td>';
234  }
235  print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
236  print '<td class="liste_titre right">';
237  $liststatus = array(
238  Don::STATUS_DRAFT=>$langs->trans("DonationStatusPromiseNotValidated"),
239  Don::STATUS_VALIDATED=>$langs->trans("DonationStatusPromiseValidated"),
240  Don::STATUS_PAID=>$langs->trans("DonationStatusPaid"),
241  Don::STATUS_CANCELED=>$langs->trans("Canceled")
242  );
243  print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
244  print '</td>';
245  print '<td class="liste_titre maxwidthsearch">';
246  $searchpicto = $form->showFilterAndCheckAddButtons(0);
247  print $searchpicto;
248  print '</td>';
249  print "</tr>\n";
250 
251  print '<tr class="liste_titre">';
252  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
253  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
254  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "d.fk_soc", "", $param, "", $sortfield, $sortorder);
255  } else {
256  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "d.societe", "", $param, "", $sortfield, $sortorder);
257  }
258  print_liste_field_titre("Name", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
259  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.datedon", "", $param, '', $sortfield, $sortorder, 'center ');
260  if (!empty($conf->project->enabled)) {
261  $langs->load("projects");
262  print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "d.fk_projet", "", $param, "", $sortfield, $sortorder);
263  }
264  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "d.amount", "", $param, '', $sortfield, $sortorder, 'right ');
265  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
267  print "</tr>\n";
268 
269  while ($i < min($num, $limit)) {
270  $objp = $db->fetch_object($resql);
271 
272  print '<tr class="oddeven">';
273  $donationstatic->id = $objp->rowid;
274  $donationstatic->ref = $objp->rowid;
275  $donationstatic->lastname = $objp->lastname;
276  $donationstatic->firstname = $objp->firstname;
277  print "<td>".$donationstatic->getNomUrl(1)."</td>";
278  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
279  $company = new Societe($db);
280  $result = $company->fetch($objp->socid);
281  if (!empty($objp->socid) && $company->id > 0) {
282  print "<td>".$company->getNomUrl(1)."</td>";
283  } else {
284  print "<td>".$objp->societe."</td>";
285  }
286  } else {
287  print "<td>".$objp->societe."</td>";
288  }
289  print "<td>".$donationstatic->getFullName($langs)."</td>";
290  print '<td class="center">'.dol_print_date($db->jdate($objp->datedon), 'day').'</td>';
291  if (!empty($conf->project->enabled)) {
292  print "<td>";
293  if ($objp->pid) {
294  $projectstatic->id = $objp->pid;
295  $projectstatic->ref = $objp->ref;
296  $projectstatic->id = $objp->pid;
297  $projectstatic->public = $objp->public;
298  $projectstatic->title = $objp->title;
299  print $projectstatic->getNomUrl(1);
300  } else {
301  print '&nbsp;';
302  }
303  print "</td>\n";
304  }
305  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
306  print '<td class="right">'.$donationstatic->LibStatut($objp->status, 5).'</td>';
307  print '<td></td>';
308  print "</tr>";
309  $i++;
310  }
311  print "</table>";
312  print '</div>';
313  print "</form>\n";
314  $db->free($resql);
315 } else {
316  dol_print_error($db);
317 }
318 
319 llxFooter();
320 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Don
Class to manage donations.
Definition: don.class.php:38
$help_url
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
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
print_barre_liste
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.
Definition: functions.lib.php:5257
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
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
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
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