dolibarr  13.0.2
asset.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Alexandre Spangaro <aspangaro@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:@assets:/asset/mypage.php?id=__ID__'
47  //); // to add new tab
48  //$this->tabs = array(
49  // 'entity:-tabname:Title:@assets:/asset/mypage.php?id=__ID__'
50  //); // to remove a tab
51  complete_head_from_modules($conf, $langs, null, $head, $h, 'assets_admin');
52 
53  $head[$h][0] = DOL_URL_ROOT.'/asset/admin/assets_extrafields.php';
54  $head[$h][1] = $langs->trans("ExtraFields");
55  $head[$h][2] = 'attributes';
56  $h++;
57 
58  $head[$h][0] = DOL_URL_ROOT.'/asset/admin/assets_type_extrafields.php';
59  $head[$h][1] = $langs->trans("ExtraFieldsAssetsType");
60  $head[$h][2] = 'attributes_type';
61  $h++;
62 
63  complete_head_from_modules($conf, $langs, null, $head, $h, 'assets_admin', 'remove');
64 
65  return $head;
66 }
67 
74 function asset_prepare_head(Asset $object)
75 {
76  global $db, $langs, $conf;
77 
78  $langs->load("assets");
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  // Show more tabs from modules
89  // Entries must be declared in modules descriptor with line
90  //$this->tabs = array(
91  // 'entity:+tabname:Title:@assets:/asset/mypage.php?id=__ID__'
92  //); // to add new tab
93  //$this->tabs = array(
94  // 'entity:-tabname:Title:@assets:/asset/mypage.php?id=__ID__'
95  //); // to remove a tab
96  complete_head_from_modules($conf, $langs, $object, $head, $h, 'assets');
97 
98  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
99  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
100  $upload_dir = $conf->assets->dir_output.'/'.dol_sanitizeFileName($object->ref);
101  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
102  $nbLinks = Link::count($db, $object->element, $object->id);
103  $head[$h][0] = DOL_URL_ROOT.'/asset/document.php?id='.$object->id;
104  $head[$h][1] = $langs->trans('Documents');
105  if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
106  $head[$h][2] = 'documents';
107  $h++;
108 
109  $nbNote = 0;
110  if (!empty($object->note_private)) $nbNote++;
111  if (!empty($object->note_public)) $nbNote++;
112  $head[$h][0] = DOL_URL_ROOT.'/asset/note.php?id='.$object->id;
113  $head[$h][1] = $langs->trans("Notes");
114  if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
115  $head[$h][2] = 'note';
116  $h++;
117 
118  $head[$h][0] = DOL_URL_ROOT.'/asset/info.php?id='.$object->id;
119  $head[$h][1] = $langs->trans("Info");
120  $head[$h][2] = 'info';
121  $h++;
122 
123  complete_head_from_modules($conf, $langs, $object, $head, $h, 'asset', 'remove');
124 
125  return $head;
126 }
127 
135 {
136  global $langs, $conf, $user;
137 
138  $h = 0;
139  $head = array();
140 
141  $head[$h][0] = DOL_URL_ROOT.'/asset/type.php?rowid='.$object->id;
142  $head[$h][1] = $langs->trans("Card");
143  $head[$h][2] = 'card';
144  $h++;
145 
146  // Show more tabs from modules
147  // Entries must be declared in modules descriptor with line
148  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
149  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
150  complete_head_from_modules($conf, $langs, $object, $head, $h, 'assettype');
151 
152  complete_head_from_modules($conf, $langs, $object, $head, $h, 'assettype', 'remove');
153 
154  return $head;
155 }
asset_admin_prepare_head()
Prepare admin pages header.
Definition: asset.lib.php:29
Class to manage asset type.
asset_type_prepare_head(AssetType $object)
Return array head with list of tabs to view object informations.
Definition: asset.lib.php:134
asset_prepare_head(Asset $object)
Prepare admin pages header.
Definition: asset.lib.php:74
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
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
Class for Asset.
Definition: asset.class.php:30
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).