dolibarr  13.0.2
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->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("companies", "donations"));
34 
35 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'sclist';
36 
37 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
38 $sortfield = GETPOST("sortfield", 'alpha');
39 $sortorder = GETPOST("sortorder", 'alpha');
40 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
41 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
42 $offset = $limit * $page;
43 $pageprev = $page - 1;
44 $pagenext = $page + 1;
45 if (!$sortorder) $sortorder = "DESC";
46 if (!$sortfield) $sortfield = "d.datedon";
47 
48 $search_status = (GETPOST("search_status", 'intcomma') != '') ? GETPOST("search_status", 'intcomma') : "-4";
49 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
50 $search_ref = GETPOST('search_ref', 'alpha');
51 $search_company = GETPOST('search_company', 'alpha');
52 $search_name = GETPOST('search_name', 'alpha');
53 $search_amount = GETPOST('search_amount', 'alpha');
54 $optioncss = GETPOST('optioncss', 'alpha');
55 
56 if (!$user->rights->don->lire) accessforbidden();
57 
58 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
59 {
60  $search_all = "";
61  $search_ref = "";
62  $search_company = "";
63  $search_name = "";
64  $search_amount = "";
65  $search_status = '';
66 }
67 
68 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
69 $hookmanager->initHooks(array('orderlist'));
70 
71 
72 // List of fields to search into when doing a "search in all"
73 $fieldstosearchall = array(
74  'd.rowid'=>'Id',
75  'd.ref'=>'Ref',
76  'd.lastname'=>'Lastname',
77  'd.firstname'=>'Firstname',
78 );
79 
80 
81 /*
82  * View
83  */
84 
85 $donationstatic = new Don($db);
86 $form = new Form($db);
87 if (!empty($conf->projet->enabled)) $projectstatic = new Project($db);
88 
89 llxHeader('', $langs->trans("Donations"), 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
90 
91 // Genere requete de liste des dons
92 $sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
93 $sql .= " d.amount, d.fk_statut as status,";
94 $sql .= " p.rowid as pid, p.ref, p.title, p.public";
95 $sql .= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
96 $sql .= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
97 if ($search_status != '' && $search_status != '-4')
98 {
99  $sql .= " AND d.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
100 }
101 if (trim($search_ref) != '')
102 {
103  $sql .= natural_search('d.ref', $search_ref);
104 }
105 if (trim($search_all) != '')
106 {
107  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
108 }
109 if (trim($search_company) != '')
110 {
111  $sql .= natural_search('d.societe', $search_company);
112 }
113 if (trim($search_name) != '')
114 {
115  $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
116 }
117 if ($search_amount) $sql .= natural_search('d.amount', $search_amount, 1);
118 
119 $sql .= $db->order($sortfield, $sortorder);
120 
121 $nbtotalofrecords = '';
122 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
123 {
124  $result = $db->query($sql);
125  $nbtotalofrecords = $db->num_rows($result);
126  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
127  {
128  $page = 0;
129  $offset = 0;
130  }
131 }
132 
133 $sql .= $db->plimit($limit + 1, $offset);
134 
135 $resql = $db->query($sql);
136 if ($resql)
137 {
138  $num = $db->num_rows($resql);
139  $i = 0;
140 
141  $param = '';
142  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
143  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
144  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
145  if ($search_status && $search_status != -1) $param .= '&search_status='.urlencode($search_status);
146  if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
147  if ($search_company) $param .= '&search_company='.urlencode($search_company);
148  if ($search_name) $param .= '&search_name='.urlencode($search_name);
149  if ($search_amount) $param .= '&search_amount='.urlencode($search_amount);
150 
151  $newcardbutton = '';
152  if ($user->rights->don->creer)
153  {
154  $newcardbutton .= dolGetButtonTitle($langs->trans('NewDonation'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/don/card.php?action=create');
155  }
156 
157  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
158  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
159  print '<input type="hidden" name="token" value="'.newToken().'">';
160  print '<input type="hidden" name="action" value="list">';
161  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
162  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
163  print '<input type="hidden" name="page" value="'.$page.'">';
164  print '<input type="hidden" name="type" value="'.$type.'">';
165 
166  print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_donation', 0, $newcardbutton, '', $limit, 0, 0, 1);
167 
168  if ($search_all)
169  {
170  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
171  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
172  }
173 
174  print '<div class="div-table-responsive">';
175  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
176 
177  // Filters lines
178  print '<tr class="liste_titre_filter">';
179  print '<td class="liste_titre">';
180  print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
181  print '</td>';
182  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
183  print '<td class="liste_titre">';
184  print '<input class="flat" size="10" type="text" name="search_thirdparty" value="'.$search_thirdparty.'">';
185  print '</td>';
186  } else {
187  print '<td class="liste_titre">';
188  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
189  print '</td>';
190  }
191  print '<td class="liste_titre">';
192  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
193  print '</td>';
194  print '<td class="liste_titre left">';
195  print '&nbsp;';
196  print '</td>';
197  if (!empty($conf->projet->enabled))
198  {
199  print '<td class="liste_titre right">';
200  print '&nbsp;';
201  print '</td>';
202  }
203  print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
204  print '<td class="liste_titre right">';
205  $liststatus = array(
206  Don::STATUS_DRAFT=>$langs->trans("DonationStatusPromiseNotValidated"),
207  Don::STATUS_VALIDATED=>$langs->trans("DonationStatusPromiseValidated"),
208  Don::STATUS_PAID=>$langs->trans("DonationStatusPaid"),
209  Don::STATUS_CANCELED=>$langs->trans("Canceled")
210  );
211  print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
212  print '</td>';
213  print '<td class="liste_titre maxwidthsearch">';
214  $searchpicto = $form->showFilterAndCheckAddButtons(0);
215  print $searchpicto;
216  print '</td>';
217  print "</tr>\n";
218 
219  print '<tr class="liste_titre">';
220  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
221  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
222  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "d.fk_soc", "", $param, "", $sortfield, $sortorder);
223  } else {
224  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "d.societe", "", $param, "", $sortfield, $sortorder);
225  }
226  print_liste_field_titre("Name", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
227  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.datedon", "", $param, '', $sortfield, $sortorder, 'center ');
228  if (!empty($conf->projet->enabled))
229  {
230  $langs->load("projects");
231  print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "d.fk_projet", "", $param, "", $sortfield, $sortorder);
232  }
233  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "d.amount", "", $param, '', $sortfield, $sortorder, 'right ');
234  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
236  print "</tr>\n";
237 
238  while ($i < min($num, $limit))
239  {
240  $objp = $db->fetch_object($resql);
241 
242  print '<tr class="oddeven">';
243  $donationstatic->id = $objp->rowid;
244  $donationstatic->ref = $objp->rowid;
245  $donationstatic->lastname = $objp->lastname;
246  $donationstatic->firstname = $objp->firstname;
247  print "<td>".$donationstatic->getNomUrl(1)."</td>";
248  if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
249  $company = new Societe($db);
250  $result = $company->fetch($objp->socid);
251  if (!empty($objp->socid) && $company->id > 0) {
252  print "<td>".$company->getNomUrl(1)."</td>";
253  } else {
254  print "<td>".$objp->societe."</td>";
255  }
256  } else {
257  print "<td>".$objp->societe."</td>";
258  }
259  print "<td>".$donationstatic->getFullName($langs)."</td>";
260  print '<td class="center">'.dol_print_date($db->jdate($objp->datedon), 'day').'</td>';
261  if (!empty($conf->projet->enabled))
262  {
263  print "<td>";
264  if ($objp->pid)
265  {
266  $projectstatic->id = $objp->pid;
267  $projectstatic->ref = $objp->ref;
268  $projectstatic->id = $objp->pid;
269  $projectstatic->public = $objp->public;
270  $projectstatic->title = $objp->title;
271  print $projectstatic->getNomUrl(1);
272  } else print '&nbsp;';
273  print "</td>\n";
274  }
275  print '<td class="right">'.price($objp->amount).'</td>';
276  print '<td class="right">'.$donationstatic->LibStatut($objp->status, 5).'</td>';
277  print '<td></td>';
278  print "</tr>";
279  $i++;
280  }
281  print "</table>";
282  print '</div>';
283  print "</form>\n";
284  $db->free($resql);
285 } else {
286  dol_print_error($db);
287 }
288 
289 llxFooter();
290 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
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...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
Class to manage donations.
Definition: don.class.php:37
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
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:59