dolibarr/htdocs/core/lib/donation.lib.php

128 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2015-03-16 06:29:15 +01:00
<?php
2019-01-28 21:39:22 +01:00
/* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
2015-03-16 06:29:15 +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
* (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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2015-03-16 06:29:15 +01:00
*/
/**
* \file htdocs/core/lib/donation.lib.php
* \ingroup Donation
* \brief Library of donation functions
*/
2015-03-21 06:21:34 +01:00
/**
* Prepare array with list of admin tabs
*
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
2015-03-21 06:21:34 +01:00
*/
2015-06-02 20:41:02 +02:00
function donation_admin_prepare_head()
2015-03-21 06:21:34 +01:00
{
2022-09-15 20:42:26 +02:00
global $langs, $conf, $db;
$extrafields = new ExtraFields($db);
2022-09-16 09:13:36 +02:00
$extrafields->fetch_name_optionals_label('don');
2015-03-21 06:21:34 +01:00
$h = 0;
2015-06-03 05:49:43 +02:00
$head = array();
2015-03-21 06:21:34 +01:00
$head[$h][0] = DOL_URL_ROOT.'/don/admin/donation.php';
2015-03-21 06:21:34 +01:00
$head[$h][1] = $langs->trans("Miscellaneous");
$head[$h][2] = 'general';
$h++;
2015-03-21 06:21:34 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
2015-06-02 20:41:02 +02:00
complete_head_from_modules($conf, $langs, null, $head, $h, 'donation_admin');
2019-03-11 01:01:15 +01:00
$head[$h][0] = DOL_URL_ROOT.'/don/admin/donation_extrafields.php';
2015-03-21 06:21:34 +01:00
$head[$h][1] = $langs->trans("ExtraFields");
2022-09-16 09:38:24 +02:00
$nbExtrafields = $extrafields->attributes['don']['count'];
2022-09-15 20:42:26 +02:00
if ($nbExtrafields > 0) {
2022-09-22 14:42:58 +02:00
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
2022-09-15 20:42:26 +02:00
}
$head[$h][2] = 'attributes';
2015-03-21 06:21:34 +01:00
$h++;
2015-06-02 20:41:02 +02:00
complete_head_from_modules($conf, $langs, null, $head, $h, 'donation_admin', 'remove');
2015-03-21 06:21:34 +01:00
return $head;
}
2015-03-16 06:29:15 +01:00
/**
* Prepare array with list of tabs
*
2019-03-11 01:01:15 +01:00
* @param Don $object Donation
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
2015-03-16 06:29:15 +01:00
*/
function donation_prepare_head($object)
{
global $db, $langs, $conf;
2015-03-16 06:29:15 +01:00
$h = 0;
2015-06-03 05:49:43 +02:00
$head = array();
2015-03-16 06:29:15 +01:00
$head[$h][0] = DOL_URL_ROOT.'/don/card.php?id='.$object->id;
2020-05-17 13:34:16 +02:00
$head[$h][1] = $langs->trans("Donation");
2015-03-16 06:29:15 +01:00
$head[$h][2] = 'card';
$h++;
2015-03-16 06:29:15 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
2022-09-22 14:06:50 +02:00
complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'add', 'core');
2015-03-16 06:29:15 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
$upload_dir = $conf->don->dir_output.'/'.dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $object->element, $object->id);
$head[$h][0] = DOL_URL_ROOT.'/don/document.php?id='.$object->id;
$head[$h][1] = $langs->trans('Documents');
2021-02-23 22:03:23 +01:00
if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
}
$head[$h][2] = 'documents';
$h++;
2016-11-07 04:02:16 +01:00
$nbNote = 0;
2021-02-23 22:03:23 +01:00
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
2016-11-07 04:02:16 +01:00
$head[$h][0] = DOL_URL_ROOT.'/don/note.php?id='.$object->id;
$head[$h][1] = $langs->trans("Notes");
2021-02-23 22:03:23 +01:00
if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
}
2016-11-07 04:02:16 +01:00
$head[$h][2] = 'note';
$h++;
2019-03-11 01:01:15 +01:00
$head[$h][0] = DOL_URL_ROOT.'/don/info.php?id='.$object->id;
2015-03-16 06:29:15 +01:00
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
$h++;
2022-09-22 14:06:50 +02:00
complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'add', 'external');
2015-03-16 06:29:15 +01:00
complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'remove');
return $head;
}