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