dolibarr/htdocs/core/lib/resource.lib.php

150 lines
5.3 KiB
PHP
Raw Permalink Normal View History

2014-03-23 22:12:48 +01:00
<?php
/* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM
* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Gilles Poirier <gilles.poirier@netlogic.fr>
* Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
2014-03-23 22:12:48 +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/>.
2014-03-23 22:12:48 +01:00
*/
/**
2014-05-14 12:19:45 +02:00
* \file htdocs/core/lib/resource.lib.php
2014-03-23 22:12:48 +01:00
* \ingroup resource
* \brief This file is library for resource module
*/
2014-05-14 12:19:45 +02:00
/**
* Prepare head for tabs
*
* @param Dolresource $object Object
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
2014-05-14 12:19:45 +02:00
*/
2016-01-31 12:23:05 +01:00
function resource_prepare_head($object)
2014-03-23 22:12:48 +01:00
{
global $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = dol_buildpath('/resource/card.php', 1).'?id='.$object->id;
2014-03-23 22:12:48 +01:00
$head[$h][1] = $langs->trans("ResourceCard");
$head[$h][2] = 'resource';
2014-03-23 22:12:48 +01:00
$h++;
2023-11-27 11:39:32 +01:00
if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && (!getDolGlobalString('RESOURCE_HIDE_ADD_CONTACT_USER') || !getDolGlobalString('RESOURCE_HIDE_ADD_CONTACT_THIPARTY'))) {
$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
$head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id;
2016-06-06 12:29:15 +02:00
$head[$h][1] = $langs->trans('ContactsAddresses');
2021-02-23 22:03:23 +01:00
if ($nbContact > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
}
2016-01-31 12:23:05 +01:00
$head[$h][2] = 'contact';
$h++;
}
2014-03-23 22:12:48 +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:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
2022-09-22 14:06:50 +02:00
complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'add', 'core');
2014-03-23 22:12:48 +01:00
2023-11-27 11:39:32 +01:00
if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
2016-01-31 12:23:05 +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-01-31 12:24:19 +01:00
$head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id;
2016-01-31 12:23:05 +01:00
$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-01-31 12:23:05 +01:00
$head[$h][2] = 'note';
$h++;
}
2016-01-31 12:24:19 +01:00
2016-01-31 12:23:05 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$upload_dir = $conf->resource->dir_output."/".dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
2016-01-31 12:24:19 +01:00
$head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id;
2016-01-31 12:23:05 +01:00
$head[$h][1] = $langs->trans("Documents");
2021-02-23 22:03:23 +01:00
if ($nbFiles > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
}
2016-01-31 12:23:05 +01:00
$head[$h][2] = 'documents';
$h++;
2016-01-31 12:24:19 +01:00
2018-10-03 21:13:02 +02:00
$head[$h][0] = DOL_URL_ROOT.'/resource/agenda.php?id='.$object->id;
$head[$h][1] = $langs->trans("Events");
2023-06-12 20:10:42 +02:00
if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
$head[$h][1] .= '/';
$head[$h][1] .= $langs->trans("Agenda");
2018-10-03 21:13:02 +02:00
}
$head[$h][2] = 'agenda';
$h++;
/*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id;
2016-01-31 12:23:05 +01:00
$head[$h][1] = $langs->trans('Info');
$head[$h][2] = 'info';
$h++;*/
2016-10-19 22:14:51 +02:00
2022-09-22 14:06:50 +02:00
complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'add', 'external');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'remove');
2014-03-23 22:12:48 +01:00
return $head;
}
2016-10-19 22:14:51 +02:00
2018-08-31 22:14:09 +02:00
/**
* Prepare head for admin tabs
*
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
2018-08-31 22:14:09 +02:00
*/
2018-08-15 17:34:35 +02:00
function resource_admin_prepare_head()
{
global $conf, $db, $langs, $user;
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label('resource');
2016-10-19 22:14:51 +02:00
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/admin/resource.php';
2016-10-19 22:24:04 +02:00
$head[$h][1] = $langs->trans("ResourceSetup");
2016-10-19 22:14:51 +02:00
$head[$h][2] = 'general';
$h++;
// 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:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin');
2016-10-19 22:14:51 +02:00
$head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFields");
$nbExtrafields = $extrafields->attributes['resource']['count'];
if ($nbExtrafields > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
}
2016-10-19 22:14:51 +02:00
$head[$h][2] = 'attributes';
$h++;
complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin', 'remove');
2016-10-19 22:14:51 +02:00
return $head;
}