123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- <?php
- /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
- * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
- * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
- *
- * 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
- * (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
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/don/list.php
- * \ingroup donations
- * \brief List of donations
- */
- // Load Dolibarr environment
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
- if (isModEnabled('project')) {
- require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
- }
- // Load translation files required by the page
- $langs->loadLangs(array('companies', 'donations'));
- $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
- $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
- $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'sclist';
- $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
- $sortfield = GETPOST('sortfield', 'aZ09comma');
- $sortorder = GETPOST('sortorder', 'aZ09comma');
- $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
- $type = GETPOST('type', 'aZ');
- $mode = GETPOST('mode', 'alpha');
- if (empty($page) || $page == -1) {
- $page = 0;
- } // If $page is not defined, or '' or -1
- $offset = $limit * $page;
- $pageprev = $page - 1;
- $pagenext = $page + 1;
- if (!$sortorder) {
- $sortorder = "DESC";
- }
- if (!$sortfield) {
- $sortfield = "d.datedon";
- }
- $search_status = (GETPOST("search_status", 'intcomma') != '') ? GETPOST("search_status", 'intcomma') : "-4";
- $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
- $search_ref = GETPOST('search_ref', 'alpha');
- $search_company = GETPOST('search_company', 'alpha');
- $search_thirdparty = GETPOST('search_thirdparty', 'alpha');
- $search_name = GETPOST('search_name', 'alpha');
- $search_amount = GETPOST('search_amount', 'alpha');
- $optioncss = GETPOST('optioncss', 'alpha');
- $moreforfilter = GETPOST('moreforfilter', 'alpha');
- 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
- $search_all = "";
- $search_ref = "";
- $search_company = "";
- $search_thirdparty = "";
- $search_name = "";
- $search_amount = "";
- $search_status = '';
- }
- // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
- $hookmanager->initHooks(array('donationlist'));
- // 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',
- );
- // Security check
- $result = restrictedArea($user, 'don');
- $permissiontoread = $user->hasRight('don', 'read');
- $permissiontoadd = $user->hasRight('don', 'write');
- $permissiontodelete = $user->hasRight('don', 'delete');
- /*
- * Actions
- */
- if (GETPOST('cancel', 'alpha')) {
- $action = 'list';
- $massaction = '';
- }
- if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
- $massaction = '';
- }
- /*
- * View
- */
- $form = new Form($db);
- $donationstatic = new Don($db);
- if (isModEnabled('project')) {
- $projectstatic = new Project($db);
- }
- $title = $langs->trans("Donations");
- $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Donaciones|DE:Modul_Spenden';
- // Build and execute select
- // --------------------------------------------------------------------
- $sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
- $sql .= " d.amount, d.fk_statut as status,";
- $sql .= " p.rowid as pid, p.ref, p.title, p.public";
- $sqlfields = $sql; // $sql fields to remove for count total
- $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').")";
- if ($search_status != '' && $search_status != '-4') {
- $sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
- }
- if (trim($search_ref) != '') {
- $sql .= natural_search('d.ref', $search_ref);
- }
- if (trim($search_all) != '') {
- $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
- }
- if (trim($search_company) != '') {
- $sql .= natural_search('d.societe', $search_company);
- }
- if (trim($search_name) != '') {
- $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
- }
- if ($search_amount) {
- $sql .= natural_search('d.amount', $search_amount, 1);
- }
- // Count total nb of records
- $nbtotalofrecords = '';
- if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
- /* The fast and low memory method to get and count full list converts the sql into a sql count */
- $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
- $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
- $resql = $db->query($sqlforcount);
- if ($resql) {
- $objforcount = $db->fetch_object($resql);
- $nbtotalofrecords = $objforcount->nbtotalofrecords;
- } else {
- dol_print_error($db);
- }
- if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
- $page = 0;
- $offset = 0;
- }
- $db->free($resql);
- }
- // Complete request and execute it with limit
- $sql .= $db->order($sortfield, $sortorder);
- if ($limit) {
- $sql .= $db->plimit($limit + 1, $offset);
- }
- $resql = $db->query($sql);
- if (!$resql) {
- dol_print_error($db);
- exit;
- }
- $num = $db->num_rows($resql);
- // Direct jump if only one record found
- if ($num == 1 && !getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
- $obj = $db->fetch_object($resql);
- $id = $obj->rowid;
- header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id);
- exit;
- }
- // Output page
- // --------------------------------------------------------------------
- llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
- // Example : Adding jquery code
- // print '<script type="text/javascript">
- // jQuery(document).ready(function() {
- // function init_myfunc()
- // {
- // jQuery("#myid").removeAttr(\'disabled\');
- // jQuery("#myid").attr(\'disabled\',\'disabled\');
- // }
- // init_myfunc();
- // jQuery("#mybutton").click(function() {
- // init_myfunc();
- // });
- // });
- // </script>';
- $arrayofselected = is_array($toselect) ? $toselect : array();
- $param = '';
- if (!empty($mode)) {
- $param .= '&mode='.urlencode($mode);
- }
- if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
- $param .= '&contextpage='.urlencode($contextpage);
- }
- if ($limit > 0 && $limit != $conf->liste_limit) {
- $param .= '&limit='.((int) $limit);
- }
- if ($optioncss != '') {
- $param .= '&optioncss='.urlencode($optioncss);
- }
- if ($search_status && $search_status != -1) {
- $param .= '&search_status='.urlencode($search_status);
- }
- if ($search_ref) {
- $param .= '&search_ref='.urlencode($search_ref);
- }
- if ($search_company) {
- $param .= '&search_company='.urlencode($search_company);
- }
- if ($search_name) {
- $param .= '&search_name='.urlencode($search_name);
- }
- if ($search_amount) {
- $param .= '&search_amount='.urlencode($search_amount);
- }
- // List of mass actions available
- $arrayofmassactions = array(
- //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
- //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
- //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
- //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
- );
- if (!empty($permissiontodelete)) {
- $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
- }
- if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
- $arrayofmassactions = array();
- }
- $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
- print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
- if ($optioncss != '') {
- print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
- }
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
- print '<input type="hidden" name="action" value="list">';
- print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
- print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
- print '<input type="hidden" name="page" value="'.$page.'">';
- print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
- print '<input type="hidden" name="page_y" value="">';
- print '<input type="hidden" name="mode" value="'.$mode.'">';
- print '<input type="hidden" name="type" value="'.$type.'">';
- $newcardbutton = '';
- $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
- $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
- if ($user->rights->don->creer) {
- $newcardbutton .= dolGetButtonTitle($langs->trans('NewDonation'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/don/card.php?action=create');
- }
- print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_donation', 0, $newcardbutton, '', $limit, 0, 0, 1);
- if ($search_all) {
- $setupstring = '';
- foreach ($fieldstosearchall as $key => $val) {
- $fieldstosearchall[$key] = $langs->trans($val);
- $setupstring .= $key."=".$val.";";
- }
- print '<!-- Search done like if DONATION_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
- print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
- }
- $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
- $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
- $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
- print '<div class="div-table-responsive">';
- print '<table class="tagtable nobottomiftotal liste'.(!empty($moreforfilter) ? " listwithfilterbefore" : "").'">'."\n";
- // Fields title search
- // --------------------------------------------------------------------
- print '<tr class="liste_titre_filter">';
- // Action column
- if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td class="liste_titre center maxwidthsearch">';
- $searchpicto = $form->showFilterButtons('left');
- print $searchpicto;
- print '</td>';
- }
- print '<td class="liste_titre">';
- print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
- print '</td>';
- if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
- print '<td class="liste_titre">';
- print '<input class="flat" size="10" type="text" name="search_thirdparty" value="'.$search_thirdparty.'">';
- print '</td>';
- } else {
- 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 left">';
- print ' ';
- print '</td>';
- if (isModEnabled('project')) {
- print '<td class="liste_titre right">';
- print ' ';
- print '</td>';
- }
- print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
- print '<td class="liste_titre right parentonrightofpage">';
- $liststatus = array(
- Don::STATUS_DRAFT=>$langs->trans("DonationStatusPromiseNotValidated"),
- Don::STATUS_VALIDATED=>$langs->trans("DonationStatusPromiseValidated"),
- Don::STATUS_PAID=>$langs->trans("DonationStatusPaid"),
- Don::STATUS_CANCELED=>$langs->trans("Canceled")
- );
- print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'search_status maxwidth100 onrightofpage');
- print '</td>';
- if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td class="liste_titre center maxwidthsearch">';
- $searchpicto = $form->showFilterButtons();
- print $searchpicto;
- print '</td>';
- }
- print '</tr>'."\n";
- $totalarray = array();
- $totalarray['nbfield'] = 0;
- // Fields title label
- // --------------------------------------------------------------------
- print '<tr class="liste_titre">';
- // Action column
- if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print_liste_field_titre('');
- $totalarray['nbfield']++;
- }
- print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
- $totalarray['nbfield']++;
- if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
- print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "d.fk_soc", "", $param, "", $sortfield, $sortorder);
- $totalarray['nbfield']++;
- } else {
- print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "d.societe", "", $param, "", $sortfield, $sortorder);
- $totalarray['nbfield']++;
- }
- print_liste_field_titre("Name", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
- $totalarray['nbfield']++;
- print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.datedon", "", $param, '', $sortfield, $sortorder, 'center ');
- $totalarray['nbfield']++;
- if (isModEnabled('project')) {
- $langs->load("projects");
- print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "d.fk_projet", "", $param, "", $sortfield, $sortorder);
- $totalarray['nbfield']++;
- }
- print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "d.amount", "", $param, '', $sortfield, $sortorder, 'right ');
- $totalarray['nbfield']++;
- print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
- $totalarray['nbfield']++;
- if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print_liste_field_titre('');
- $totalarray['nbfield']++;
- }
- print '</tr>'."\n";
- $i = 0;
- $savnbfield = $totalarray['nbfield'];
- $totalarray = array();
- $totalarray['nbfield'] = 0;
- $imaxinloop = ($limit ? min($num, $limit) : $num);
- while ($i < $imaxinloop) {
- $obj = $db->fetch_object($resql);
- $donationstatic->setVarsFromFetchObj($obj);
- $company = new Societe($db);
- $result = $company->fetch($obj->socid);
- if ($mode == 'kanban') {
- if ($i == 0) {
- print '<tr><td colspan="'.$savnbfield.'">';
- print '<div class="box-flex-container kanban">';
- }
- // Output Kanban
- $donationstatic->amount = $obj->amount;
- $donationstatic->date = $obj->datedon;
- $donationstatic->labelStatus = $obj->status;
- $donationstatic->id = $obj->rowid;
- $donationstatic->ref = $obj->rowid;
- if (!empty($obj->socid) && $company->id > 0) {
- $donationstatic->societe = $company->getNomUrl(1);
- } else {
- $donationstatic->societe = $obj->societe;
- }
- $object = $donationstatic;
- $selected = -1;
- if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
- $selected = 0;
- if (in_array($object->id, $arrayofselected)) {
- $selected = 1;
- }
- }
- print $donationstatic->getKanbanView('', array('selected' => $selected));
- if ($i == ($imaxinloop - 1)) {
- print '</div>';
- print '</td></tr>';
- }
- } else {
- print '<tr class="oddeven">';
- if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td></td>';
- }
- $donationstatic->id = $obj->rowid;
- $donationstatic->ref = $obj->rowid;
- $donationstatic->lastname = $obj->lastname;
- $donationstatic->firstname = $obj->firstname;
- print "<td>".$donationstatic->getNomUrl(1)."</td>";
- if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
- if (!empty($obj->socid) && $company->id > 0) {
- print "<td>".$company->getNomUrl(1)."</td>";
- } else {
- print "<td>".$obj->societe."</td>";
- }
- } else {
- print "<td>".$obj->societe."</td>";
- }
- print "<td>".$donationstatic->getFullName($langs)."</td>";
- print '<td class="center">'.dol_print_date($db->jdate($obj->datedon), 'day').'</td>';
- if (isModEnabled('project')) {
- print "<td>";
- if ($obj->pid) {
- $projectstatic->id = $obj->pid;
- $projectstatic->ref = $obj->ref;
- $projectstatic->id = $obj->pid;
- $projectstatic->public = $obj->public;
- $projectstatic->title = $obj->title;
- print $projectstatic->getNomUrl(1);
- } else {
- print ' ';
- }
- print "</td>\n";
- }
- print '<td class="right"><span class="amount">'.price($obj->amount).'</span></td>';
- print '<td class="right">'.$donationstatic->LibStatut($obj->status, 5).'</td>';
- if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td></td>';
- }
- print "</tr>";
- }
- $i++;
- }
- print "</table>";
- print '</div>';
- print "</form>\n";
- $db->free($resql);
- llxFooter();
- $db->close();
|