dolibarr  x.y.z
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 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
31 if (isModEnabled('project')) {
32  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
33 }
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('companies', 'donations'));
37 
38 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'sclist';
39 
40 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
41 $sortfield = GETPOST('sortfield', 'aZ09comma');
42 $sortorder = GETPOST('sortorder', 'aZ09comma');
43 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
44 $type = GETPOST('type', 'aZ');
45 if (empty($page) || $page == -1) {
46  $page = 0;
47 } // If $page is not defined, or '' or -1
48 $offset = $limit * $page;
49 $pageprev = $page - 1;
50 $pagenext = $page + 1;
51 if (!$sortorder) {
52  $sortorder = "DESC";
53 }
54 if (!$sortfield) {
55  $sortfield = "d.datedon";
56 }
57 
58 $search_status = (GETPOST("search_status", 'intcomma') != '') ? GETPOST("search_status", 'intcomma') : "-4";
59 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
60 $search_ref = GETPOST('search_ref', 'alpha');
61 $search_company = GETPOST('search_company', 'alpha');
62 $search_name = GETPOST('search_name', 'alpha');
63 $search_amount = GETPOST('search_amount', 'alpha');
64 $optioncss = GETPOST('optioncss', 'alpha');
65 $moreforfilter = GETPOST('moreforfilter', 'alpha');
66 if (!$user->rights->don->lire) {
68 }
69 
70 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
71  $search_all = "";
72  $search_ref = "";
73  $search_company = "";
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 // Security check
92 $result = restrictedArea($user, 'don');
93 
94 
95 
96 
97 /*
98  * View
99  */
100 
101 $donationstatic = new Don($db);
102 $form = new Form($db);
103 if (isModEnabled('project')) {
104  $projectstatic = new Project($db);
105 }
106 
107 $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
108 
109 llxHeader('', $langs->trans("Donations"), $help_url);
110 
111 // Genere requete de liste des dons
112 $sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
113 $sql .= " d.amount, d.fk_statut as status,";
114 $sql .= " p.rowid as pid, p.ref, p.title, p.public";
115 $sql .= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
116 $sql .= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
117 if ($search_status != '' && $search_status != '-4') {
118  $sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
119 }
120 if (trim($search_ref) != '') {
121  $sql .= natural_search('d.ref', $search_ref);
122 }
123 if (trim($search_all) != '') {
124  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
125 }
126 if (trim($search_company) != '') {
127  $sql .= natural_search('d.societe', $search_company);
128 }
129 if (trim($search_name) != '') {
130  $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
131 }
132 if ($search_amount) {
133  $sql .= natural_search('d.amount', $search_amount, 1);
134 }
135 
136 $sql .= $db->order($sortfield, $sortorder);
137 
138 $nbtotalofrecords = '';
139 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
140  $result = $db->query($sql);
141  $nbtotalofrecords = $db->num_rows($result);
142  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
143  $page = 0;
144  $offset = 0;
145  }
146 }
147 
148 $sql .= $db->plimit($limit + 1, $offset);
149 
150 $resql = $db->query($sql);
151 if ($resql) {
152  $num = $db->num_rows($resql);
153  $i = 0;
154 
155  $param = '';
156  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
157  $param .= '&contextpage='.urlencode($contextpage);
158  }
159  if ($limit > 0 && $limit != $conf->liste_limit) {
160  $param .= '&limit='.urlencode($limit);
161  }
162  if ($optioncss != '') {
163  $param .= '&optioncss='.urlencode($optioncss);
164  }
165  if ($search_status && $search_status != -1) {
166  $param .= '&search_status='.urlencode($search_status);
167  }
168  if ($search_ref) {
169  $param .= '&search_ref='.urlencode($search_ref);
170  }
171  if ($search_company) {
172  $param .= '&search_company='.urlencode($search_company);
173  }
174  if ($search_name) {
175  $param .= '&search_name='.urlencode($search_name);
176  }
177  if ($search_amount) {
178  $param .= '&search_amount='.urlencode($search_amount);
179  }
180 
181  $newcardbutton = '';
182  if ($user->rights->don->creer) {
183  $newcardbutton .= dolGetButtonTitle($langs->trans('NewDonation'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/don/card.php?action=create');
184  }
185 
186  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
187  if ($optioncss != '') {
188  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
189  }
190  print '<input type="hidden" name="token" value="'.newToken().'">';
191  print '<input type="hidden" name="action" value="list">';
192  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
193  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
194  print '<input type="hidden" name="page" value="'.$page.'">';
195  print '<input type="hidden" name="type" value="'.$type.'">';
196 
197  print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_donation', 0, $newcardbutton, '', $limit, 0, 0, 1);
198 
199  if ($search_all) {
200  foreach ($fieldstosearchall as $key => $val) {
201  $fieldstosearchall[$key] = $langs->trans($val);
202  }
203  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
204  }
205 
206  print '<div class="div-table-responsive">';
207  print '<table class="tagtable liste'.(!empty($moreforfilter) ? " listwithfilterbefore" : "").'">'."\n";
208 
209  // Filters lines
210  print '<tr class="liste_titre_filter">';
211  print '<td class="liste_titre">';
212  print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
213  print '</td>';
214  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
215  print '<td class="liste_titre">';
216  print '<input class="flat" size="10" type="text" name="search_thirdparty" value="'.$search_thirdparty.'">';
217  print '</td>';
218  } else {
219  print '<td class="liste_titre">';
220  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
221  print '</td>';
222  }
223  print '<td class="liste_titre">';
224  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
225  print '</td>';
226  print '<td class="liste_titre left">';
227  print '&nbsp;';
228  print '</td>';
229  if (isModEnabled('project')) {
230  print '<td class="liste_titre right">';
231  print '&nbsp;';
232  print '</td>';
233  }
234  print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
235  print '<td class="liste_titre right">';
236  $liststatus = array(
237  Don::STATUS_DRAFT=>$langs->trans("DonationStatusPromiseNotValidated"),
238  Don::STATUS_VALIDATED=>$langs->trans("DonationStatusPromiseValidated"),
239  Don::STATUS_PAID=>$langs->trans("DonationStatusPaid"),
240  Don::STATUS_CANCELED=>$langs->trans("Canceled")
241  );
242  print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100 onrightofpage');
243  print '</td>';
244  print '<td class="liste_titre maxwidthsearch">';
245  $searchpicto = $form->showFilterAndCheckAddButtons(0);
246  print $searchpicto;
247  print '</td>';
248  print "</tr>\n";
249 
250  print '<tr class="liste_titre">';
251  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
252  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
253  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "d.fk_soc", "", $param, "", $sortfield, $sortorder);
254  } else {
255  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "d.societe", "", $param, "", $sortfield, $sortorder);
256  }
257  print_liste_field_titre("Name", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
258  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.datedon", "", $param, '', $sortfield, $sortorder, 'center ');
259  if (isModEnabled('project')) {
260  $langs->load("projects");
261  print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "d.fk_projet", "", $param, "", $sortfield, $sortorder);
262  }
263  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "d.amount", "", $param, '', $sortfield, $sortorder, 'right ');
264  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
266  print "</tr>\n";
267 
268  while ($i < min($num, $limit)) {
269  $objp = $db->fetch_object($resql);
270 
271  print '<tr class="oddeven">';
272  $donationstatic->id = $objp->rowid;
273  $donationstatic->ref = $objp->rowid;
274  $donationstatic->lastname = $objp->lastname;
275  $donationstatic->firstname = $objp->firstname;
276  print "<td>".$donationstatic->getNomUrl(1)."</td>";
277  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
278  $company = new Societe($db);
279  $result = $company->fetch($objp->socid);
280  if (!empty($objp->socid) && $company->id > 0) {
281  print "<td>".$company->getNomUrl(1)."</td>";
282  } else {
283  print "<td>".$objp->societe."</td>";
284  }
285  } else {
286  print "<td>".$objp->societe."</td>";
287  }
288  print "<td>".$donationstatic->getFullName($langs)."</td>";
289  print '<td class="center">'.dol_print_date($db->jdate($objp->datedon), 'day').'</td>';
290  if (isModEnabled('project')) {
291  print "<td>";
292  if ($objp->pid) {
293  $projectstatic->id = $objp->pid;
294  $projectstatic->ref = $objp->ref;
295  $projectstatic->id = $objp->pid;
296  $projectstatic->public = $objp->public;
297  $projectstatic->title = $objp->title;
298  print $projectstatic->getNomUrl(1);
299  } else {
300  print '&nbsp;';
301  }
302  print "</td>\n";
303  }
304  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
305  print '<td class="right">'.$donationstatic->LibStatut($objp->status, 5).'</td>';
306  print '<td></td>';
307  print "</tr>";
308  $i++;
309  }
310  print "</table>";
311  print '</div>';
312  print "</form>\n";
313  $db->free($resql);
314 } else {
315  dol_print_error($db);
316 }
317 
318 llxFooter();
319 $db->close();
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:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage donations.
Definition: don.class.php:39
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.