dolibarr 22.0.5
asset.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018-2022 OpenDSI <support@open-dsi.fr>
3 * Copyright (C) 2022-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
33{
34 global $langs, $conf, $db;
35
36 $extrafields = new ExtraFields($db);
37 $extrafields->fetch_name_optionals_label('asset');
38 $extrafields->fetch_name_optionals_label('asset_model');
39
40 $langs->load("assets");
41
42 $h = 0;
43 $head = array();
44
45 $head[$h][0] = DOL_URL_ROOT.'/asset/admin/setup.php';
46 $head[$h][1] = $langs->trans("Settings");
47 $head[$h][2] = 'settings';
48 $h++;
49
50 // Show more tabs from modules
51 // Entries must be declared in modules descriptor with line
52 //$this->tabs = array(
53 // 'entity:+tabname:Title:@asset:/asset/mypage.php?id=__ID__'
54 //); // to add new tab
55 //$this->tabs = array(
56 // 'entity:-tabname:Title:@asset:/asset/mypage.php?id=__ID__'
57 //); // to remove a tab
58 complete_head_from_modules($conf, $langs, null, $head, $h, 'asset_admin');
59
60 $head[$h][0] = DOL_URL_ROOT.'/asset/admin/asset_extrafields.php';
61 $head[$h][1] = $langs->trans("ExtraFields");
62 $nbExtrafields = $extrafields->attributes['asset']['count'];
63 if ($nbExtrafields > 0) {
64 $head[$h][1] .= ' <span class="badge">'.$nbExtrafields.'</span>';
65 }
66 $head[$h][2] = 'asset_extrafields';
67 $h++;
68
69 $head[$h][0] = DOL_URL_ROOT.'/asset/admin/assetmodel_extrafields.php';
70 $head[$h][1] = $langs->trans("ExtraFieldsAssetModel");
71 $nbExtrafields = $extrafields->attributes['asset_model']['count'];
72 if ($nbExtrafields > 0) {
73 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
74 }
75 $head[$h][2] = 'assetmodel_extrafields';
76 $h++;
77
78 complete_head_from_modules($conf, $langs, null, $head, $h, 'asset_admin', 'remove');
79
80 return $head;
81}
82
90{
91 global $db, $langs, $conf;
92
93 $langs->loadLangs(array("assets", "admin"));
94
95 $h = 0;
96 $head = array();
97
98 $head[$h][0] = DOL_URL_ROOT . '/asset/card.php?id=' . $object->id;
99 $head[$h][1] = $langs->trans("Asset");
100 $head[$h][2] = 'card';
101 $h++;
102
103 if (empty($object->not_depreciated)) {
104 $head[$h][0] = DOL_URL_ROOT . '/asset/depreciation_options.php?id=' . $object->id;
105 $head[$h][1] = $langs->trans("AssetDepreciationOptions");
106 $head[$h][2] = 'depreciation_options';
107 $h++;
108 }
109
110 $head[$h][0] = DOL_URL_ROOT . '/asset/accountancy_codes.php?id=' . $object->id;
111 $head[$h][1] = $langs->trans("AssetAccountancyCodes");
112 $head[$h][2] = 'accountancy_codes';
113 $h++;
114
115 if (empty($object->not_depreciated)) {
116 $head[$h][0] = DOL_URL_ROOT . '/asset/depreciation.php?id=' . $object->id;
117 $head[$h][1] = $langs->trans("AssetDepreciation");
118 $head[$h][2] = 'depreciation';
119 $h++;
120 }
121
122 if (isset($object->disposal_date) && $object->disposal_date !== "") {
123 $head[$h][0] = DOL_URL_ROOT . '/asset/disposal.php?id=' . $object->id;
124 $head[$h][1] = $langs->trans("AssetDisposal");
125 $head[$h][2] = 'disposal';
126 $h++;
127 }
128
129 if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
130 $nbNote = 0;
131 if (!empty($object->note_private)) {
132 $nbNote++;
133 }
134 if (!empty($object->note_public)) {
135 $nbNote++;
136 }
137 $head[$h][0] = DOL_URL_ROOT . '/asset/note.php?id=' . $object->id;
138 $head[$h][1] = $langs->trans('Notes');
139 if ($nbNote > 0) {
140 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
141 }
142 $head[$h][2] = 'note';
143 $h++;
144 }
145
146 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
147 require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
148 $upload_dir = $conf->asset->dir_output . "/asset/" . dol_sanitizeFileName($object->ref);
149 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
150 $nbLinks = Link::count($db, $object->element, $object->id);
151 $head[$h][0] = DOL_URL_ROOT . '/asset/document.php?id=' . $object->id;
152 $head[$h][1] = $langs->trans('Documents');
153 if (($nbFiles + $nbLinks) > 0) {
154 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
155 }
156 $head[$h][2] = 'document';
157 $h++;
158
159 $head[$h][0] = DOL_URL_ROOT . '/asset/agenda.php?id=' . $object->id;
160 $head[$h][1] = $langs->trans("Events");
161 $head[$h][2] = 'agenda';
162 $h++;
163
164 // Show more tabs from modules
165 // Entries must be declared in modules descriptor with line
166 //$this->tabs = array(
167 // 'entity:+tabname:Title:@asset:/asset/mypage.php?id=__ID__'
168 //); // to add new tab
169 //$this->tabs = array(
170 // 'entity:-tabname:Title:@asset:/asset/mypage.php?id=__ID__'
171 //); // to remove a tab
172 complete_head_from_modules($conf, $langs, $object, $head, $h, 'asset');
173
174 complete_head_from_modules($conf, $langs, $object, $head, $h, 'asset', 'remove');
175
176 return $head;
177}
178
186{
187 global $langs, $conf;
188
189 $langs->loadLangs(array("assets", "admin"));
190
191 $h = 0;
192 $head = array();
193
194 $head[$h][0] = DOL_URL_ROOT . '/asset/model/card.php?id=' . $object->id;
195 $head[$h][1] = $langs->trans("Card");
196 $head[$h][2] = 'card';
197 $h++;
198
199 if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
200 $nbNote = 0;
201 if (!empty($object->note_private)) {
202 $nbNote++;
203 }
204 if (!empty($object->note_public)) {
205 $nbNote++;
206 }
207 $head[$h][0] = DOL_URL_ROOT . '/asset/model/note.php?id=' . $object->id;
208 $head[$h][1] = $langs->trans('Notes');
209 if ($nbNote > 0) {
210 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
211 }
212 $head[$h][2] = 'note';
213 $h++;
214 }
215
216 $head[$h][0] = DOL_URL_ROOT . '/asset/model/agenda.php?id=' . $object->id;
217 $head[$h][1] = $langs->trans("Events");
218 $head[$h][2] = 'agenda';
219 $h++;
220
221
222 // Show more tabs from modules
223 // Entries must be declared in modules descriptor with line
224 //$this->tabs = array(
225 // 'entity:+tabname:Title:@asset:/asset/mypage.php?id=__ID__'
226 //); // to add new tab
227 //$this->tabs = array(
228 // 'entity:-tabname:Title:@asset:/asset/mypage.php?id=__ID__'
229 //); // to remove a tab
230 complete_head_from_modules($conf, $langs, $object, $head, $h, 'assetmodel');
231
232 complete_head_from_modules($conf, $langs, $object, $head, $h, 'assetmodel', 'remove');
233
234 return $head;
235}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
assetAdminPrepareHead()
Prepare admin pages header.
Definition asset.lib.php:32
assetPrepareHead(Asset $object)
Prepare array of tabs for Asset.
Definition asset.lib.php:89
assetModelPrepareHead($object)
Prepare array of tabs for AssetModel.
Class for Asset.
Class to manage standard extra fields.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79