dolibarr  17.0.4
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', 'add', 'core');
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', 'add', 'external');
103 
104  complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'remove');
105 
106  return $head;
107 }
108 
115 {
116 
117  global $langs, $conf, $user;
118 
119  $h = 0;
120  $head = array();
121 
122  $head[$h][0] = DOL_URL_ROOT.'/admin/resource.php';
123  $head[$h][1] = $langs->trans("ResourceSetup");
124  $head[$h][2] = 'general';
125  $h++;
126 
127  // Show more tabs from modules
128  // Entries must be declared in modules descriptor with line
129  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
130  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
131  complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin');
132 
133  $head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php';
134  $head[$h][1] = $langs->trans("ExtraFields");
135  $head[$h][2] = 'attributes';
136  $h++;
137 
138  complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin', 'remove');
139 
140  return $head;
141 }
dol_dir_list($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:61
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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).
isModEnabled($module)
Is Dolibarr module enabled.
resource_admin_prepare_head()
Prepare head for admin tabs.
resource_prepare_head($object)
Prepare head for tabs.