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