dolibarr/htdocs/don/list.php

258 lines
9.3 KiB
PHP
Raw Normal View History

<?php
2012-07-11 10:14:56 +02:00
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
2013-09-10 16:43:06 +02:00
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
2002-12-19 19:59:23 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2002-12-19 19:59:23 +01:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2002-12-19 19:59:23 +01:00
*/
2005-08-11 22:28:11 +02:00
/**
2015-03-25 22:37:14 +01:00
* \file htdocs/don/list.php
2015-03-20 06:36:48 +01:00
* \ingroup donations
* \brief List of donations
2010-04-05 03:25:44 +02:00
*/
2015-03-20 06:36:48 +01:00
require '../main.inc.php';
2015-03-25 22:37:14 +01:00
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
2002-12-19 19:59:23 +01:00
$langs->load("companies");
$langs->load("donations");
2010-11-20 14:08:44 +01:00
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
2018-04-21 12:16:12 +02:00
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
2017-06-06 10:53:53 +02:00
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$offset = $limit * $page;
2010-11-20 14:08:44 +01:00
$pageprev = $page - 1;
$pagenext = $page + 1;
2011-06-13 12:24:06 +02:00
if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="d.datedon";
2010-11-20 14:08:44 +01:00
2017-09-06 18:17:57 +02:00
$statut=(GETPOST("statut",'intcomma')!='')?GETPOST("statut",'intcomma'):"-1";
$search_all=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
2014-11-01 15:06:46 +01:00
$search_ref=GETPOST('search_ref','alpha');
$search_company=GETPOST('search_company','alpha');
$search_name=GETPOST('search_name','alpha');
$search_amount = GETPOST('search_amount','alpha');
2015-10-04 10:45:57 +02:00
$optioncss = GETPOST('optioncss','alpha');
2012-02-01 14:20:22 +01:00
if (!$user->rights->don->lire) accessforbidden();
2002-12-19 19:59:23 +01:00
2017-07-13 00:35:10 +02:00
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
2014-11-01 15:06:46 +01:00
{
$search_all="";
$search_ref="";
2014-11-01 15:06:46 +01:00
$search_company="";
$search_name="";
$search_amount="";
}
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('orderlist'));
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array(
'd.rowid'=>'Id',
'd.ref'=>'Ref',
'd.lastname'=>'Lastname',
'd.firstname'=>'Firstname',
);
/*
2009-08-12 14:59:14 +02:00
* View
*/
2009-08-12 14:59:14 +02:00
$form=new Form($db);
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled)) $projectstatic=new Project($db);
2010-10-02 14:05:15 +02:00
llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
2010-04-05 03:25:44 +02:00
$donationstatic=new Don($db);
// Genere requete de liste des dons
2013-02-23 15:46:12 +01:00
$sql = "SELECT d.rowid, d.datedon, d.firstname, d.lastname, d.societe,";
$sql.= " d.amount, d.fk_statut as statut, ";
2010-10-02 14:05:15 +02:00
$sql.= " p.rowid as pid, p.ref, p.title, p.public";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
$sql.= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
2017-09-06 18:17:57 +02:00
if ($statut != '' && $statut != '-1')
2003-01-18 15:57:12 +01:00
{
2017-09-08 13:23:12 +02:00
$sql .= " AND d.fk_statut IN (".$db->escape($statut).")";
2003-01-18 15:57:12 +01:00
}
if (trim($search_ref) != '')
{
2017-09-08 13:23:12 +02:00
$sql.= natural_search('d.ref', $search_ref);
}
if (trim($search_all) != '')
{
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
if (trim($search_company) != '')
{
2013-09-13 10:52:04 +02:00
$sql .= natural_search('d.societe', $search_company);
}
if (trim($search_name) != '')
{
2013-09-10 16:43:06 +02:00
$sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
}
2017-09-06 18:17:57 +02:00
if ($search_amount) $sql.= natural_search('d.amount', $search_amount, 1);
2014-11-01 15:06:46 +01:00
2010-04-05 03:25:44 +02:00
$sql.= $db->order($sortfield,$sortorder);
$nbtotalofrecords = '';
2016-10-23 16:53:45 +02:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
$page = 0;
$offset = 0;
}
2016-10-23 16:53:45 +02:00
}
2011-06-13 12:24:06 +02:00
$sql.= $db->plimit($limit+1, $offset);
2002-12-19 19:59:23 +01:00
2012-07-11 10:14:56 +02:00
$resql = $db->query($sql);
if ($resql)
2002-12-19 19:59:23 +01:00
{
2012-07-11 10:14:56 +02:00
$num = $db->num_rows($resql);
2010-04-05 03:25:44 +02:00
$i = 0;
2015-10-04 10:45:57 +02:00
$param = '&statut='.$statut;
//if ($page > 0) $param.= '&page='.$page;
2015-10-04 10:45:57 +02:00
if ($optioncss != '') $param.='&optioncss='.$optioncss;
2011-06-12 17:47:10 +02:00
2018-04-15 17:37:49 +02:00
$newcardbutton='';
if ($user->rights->don->creer)
2018-04-15 17:37:49 +02:00
{
2018-06-13 22:57:41 +02:00
$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/don/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewDonation').'</span>';
$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
$newcardbutton.= '</a>';
2018-04-15 17:37:49 +02:00
}
2018-04-07 16:17:40 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
2015-10-04 12:31:32 +02:00
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="type" value="'.$type.'">';
2018-04-07 16:17:40 +02:00
print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num,$nbtotalofrecords, 'title_generic.png', 0, $newcardbutton);
if ($search_all)
{
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
2018-06-22 22:53:53 +02:00
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall).'</div>';
}
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
// Filters lines
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre_filter">';
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
print '</td>';
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
print '</td>';
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
print '</td>';
print '<td class="liste_titre" align="left">';
print '&nbsp;';
print '</td>';
2012-07-11 10:14:56 +02:00
if (! empty($conf->projet->enabled))
{
print '<td class="liste_titre" align="right">';
print '&nbsp;';
print '</td>';
}
2014-11-01 15:06:46 +01:00
print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
2016-02-16 00:41:30 +01:00
print '<td class="liste_titre" align="right"></td>';
2016-02-07 15:50:48 +01:00
print '<td class="liste_titre" align="right">';
2017-05-14 21:06:33 +02:00
$searchpicto=$form->showFilterAndCheckAddButtons(0);
print $searchpicto;
2016-02-07 15:50:48 +01:00
print '</td>';
print "</tr>\n";
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre">';
print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid","", $param,"",$sortfield,$sortorder);
print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"d.societe","", $param,"",$sortfield,$sortorder);
print_liste_field_titre("Name",$_SERVER["PHP_SELF"],"d.lastname","", $param,"",$sortfield,$sortorder);
print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"d.datedon","", $param,'align="center"',$sortfield,$sortorder);
2017-04-01 12:46:47 +02:00
if (! empty($conf->projet->enabled))
{
$langs->load("projects");
print_liste_field_titre("Project",$_SERVER["PHP_SELF"],"fk_projet","", $param,"",$sortfield,$sortorder);
2017-04-01 12:46:47 +02:00
}
print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"d.amount","", $param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.fk_statut","", $param,'align="right"',$sortfield,$sortorder);
2017-04-01 12:46:47 +02:00
print_liste_field_titre('');
print "</tr>\n";
2011-06-13 12:24:06 +02:00
while ($i < min($num,$limit))
2010-04-05 03:25:44 +02:00
{
2016-10-23 16:53:45 +02:00
$objp = $db->fetch_object($resql);
2017-04-01 12:46:47 +02:00
print '<tr class="oddeven">';
2010-04-05 03:25:44 +02:00
$donationstatic->id=$objp->rowid;
$donationstatic->ref=$objp->rowid;
2013-02-23 15:46:12 +01:00
$donationstatic->lastname=$objp->lastname;
$donationstatic->firstname=$objp->firstname;
2010-04-05 03:25:44 +02:00
print "<td>".$donationstatic->getNomUrl(1)."</td>\n";
2011-06-12 17:47:10 +02:00
print "<td>".$objp->societe."</td>\n";
print "<td>".$donationstatic->getFullName($langs)."</td>\n";
print '<td align="center">'.dol_print_date($db->jdate($objp->datedon),'day').'</td>';
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled))
2010-10-02 14:05:15 +02:00
{
print "<td>";
if ($objp->pid)
{
$projectstatic->id=$objp->pid;
$projectstatic->ref=$objp->ref;
$projectstatic->id=$objp->pid;
$projectstatic->public=$objp->public;
$projectstatic->title=$objp->title;
print $projectstatic->getNomUrl(1);
}
else print '&nbsp;';
print "</td>\n";
2010-04-05 03:25:44 +02:00
}
print '<td align="right">'.price($objp->amount).'</td>';
print '<td align="right">'.$donationstatic->LibStatut($objp->statut,5).'</td>';
2016-02-16 00:41:30 +01:00
print '<td></td>';
2010-04-05 03:25:44 +02:00
print "</tr>";
$i++;
}
print "</table>";
print '</div>';
print "</form>\n";
$db->free($resql);
2002-12-19 19:59:23 +01:00
}
else
{
2010-04-05 03:25:44 +02:00
dol_print_error($db);
2002-12-19 19:59:23 +01:00
}
llxFooter();
$db->close();