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