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