dolibarr  16.0.5
resource.lib.php
Go to the documentation of this file.
1 <?php
2 /* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM
3  * Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
4  * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.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 function resource_prepare_head($object)
33 {
34  global $langs, $conf, $user;
35  $h = 0;
36  $head = array();
37 
38  $head[$h][0] = dol_buildpath('/resource/card.php', 1).'?id='.$object->id;
39  $head[$h][1] = $langs->trans("ResourceCard");
40  $head[$h][2] = 'resource';
41  $h++;
42 
43  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && (empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER) || empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY))) {
44  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
45  $head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id;
46  $head[$h][1] = $langs->trans('ContactsAddresses');
47  if ($nbContact > 0) {
48  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
49  }
50  $head[$h][2] = 'contact';
51  $h++;
52  }
53 
54  // Show more tabs from modules
55  // Entries must be declared in modules descriptor with line
56  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
57  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
58  complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource');
59 
60  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
61  $nbNote = 0;
62  if (!empty($object->note_private)) {
63  $nbNote++;
64  }
65  if (!empty($object->note_public)) {
66  $nbNote++;
67  }
68  $head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id;
69  $head[$h][1] = $langs->trans('Notes');
70  if ($nbNote > 0) {
71  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
72  }
73  $head[$h][2] = 'note';
74  $h++;
75  }
76 
77  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
78  $upload_dir = $conf->resource->dir_output."/".dol_sanitizeFileName($object->ref);
79  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
80  $head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id;
81  $head[$h][1] = $langs->trans("Documents");
82  if ($nbFiles > 0) {
83  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
84  }
85  $head[$h][2] = 'documents';
86  $h++;
87 
88  $head[$h][0] = DOL_URL_ROOT.'/resource/agenda.php?id='.$object->id;
89  $head[$h][1] = $langs->trans("Events");
90  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
91  $head[$h][1] .= '/';
92  $head[$h][1] .= $langs->trans("Agenda");
93  }
94  $head[$h][2] = 'agenda';
95  $h++;
96 
97  /*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id;
98  $head[$h][1] = $langs->trans('Info');
99  $head[$h][2] = 'info';
100  $h++;*/
101 
102  complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'remove');
103 
104  return $head;
105 }
106 
113 {
114 
115  global $langs, $conf, $user;
116 
117  $h = 0;
118  $head = array();
119 
120  $head[$h][0] = DOL_URL_ROOT.'/admin/resource.php';
121  $head[$h][1] = $langs->trans("ResourceSetup");
122  $head[$h][2] = 'general';
123  $h++;
124 
125  // Show more tabs from modules
126  // Entries must be declared in modules descriptor with line
127  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
128  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
129  complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin');
130 
131  $head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php';
132  $head[$h][1] = $langs->trans("ExtraFields");
133  $head[$h][2] = 'attributes';
134  $h++;
135 
136  complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin', 'remove');
137 
138  return $head;
139 }
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
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
resource_admin_prepare_head
resource_admin_prepare_head()
Prepare head for admin tabs.
Definition: resource.lib.php:112
resource_prepare_head
resource_prepare_head($object)
Prepare head for tabs.
Definition: resource.lib.php:32
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105