dolibarr  17.0.4
fichinter.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
6  * Copyright (C) 2018 charlene Benke <charlie@patas-monkey.com>
7 
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  * or see https://www.gnu.org/
22  */
23 
36 function fichinter_prepare_head($object)
37 {
38  global $db, $langs, $conf, $user;
39  $langs->load("fichinter");
40 
41  $h = 0;
42  $head = array();
43 
44  $head[$h][0] = DOL_URL_ROOT.'/fichinter/card.php?id='.$object->id;
45  $head[$h][1] = $langs->trans("Intervention");
46  $head[$h][2] = 'card';
47  $h++;
48 
49  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
50  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
51  $head[$h][0] = DOL_URL_ROOT.'/fichinter/contact.php?id='.$object->id;
52  $head[$h][1] = $langs->trans('InterventionContact');
53  if ($nbContact > 0) {
54  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
55  }
56  $head[$h][2] = 'contact';
57  $h++;
58  }
59 
60  // Show more tabs from modules
61  // Entries must be declared in modules descriptor with line
62  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
63  // $this->tabs = array('entity:-tabname); to remove a tab
64  complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'core');
65 
66  // Tab to link resources
67  if (isModEnabled('resource')) {
68  require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
69  $objectres = new Dolresource($db);
70  $linked_resources = $objectres->getElementResources('fichinter', $object->id);
71  $nbResource = (is_array($linked_resources) ?count($linked_resources) : 0);
72  // if (is_array($objectres->available_resources))
73  // {
74  // foreach ($objectres->available_resources as $modresources => $resources)
75  // {
76  // $resources=(array) $resources; // To be sure $resources is an array
77  // foreach($resources as $resource_obj)
78  // {
79  // $linked_resources = $object->getElementResources('fichinter', $object->id, $resource_obj);
80  // }
81  // }
82  // }
83 
84  $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=fichinter&element_id='.$object->id;
85  $head[$h][1] = $langs->trans("Resources");
86  if ($nbResource > 0) {
87  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbResource.'</span>';
88  }
89  $head[$h][2] = 'resource';
90  $h++;
91  }
92 
93  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
94  $nbNote = 0;
95  if (!empty($object->note_private)) {
96  $nbNote++;
97  }
98  if (!empty($object->note_public)) {
99  $nbNote++;
100  }
101  $head[$h][0] = DOL_URL_ROOT.'/fichinter/note.php?id='.$object->id;
102  $head[$h][1] = $langs->trans('Notes');
103  if ($nbNote > 0) {
104  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
105  }
106  $head[$h][2] = 'note';
107  $h++;
108  }
109 
110  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
111  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
112  $upload_dir = $conf->ficheinter->dir_output."/".dol_sanitizeFileName($object->ref);
113  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
114  $nbLinks = Link::count($db, $object->element, $object->id);
115  $head[$h][0] = DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id;
116  $head[$h][1] = $langs->trans("Documents");
117  if (($nbFiles + $nbLinks) > 0) {
118  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
119  }
120  $head[$h][2] = 'documents';
121  $h++;
122 
123  $head[$h][0] = DOL_URL_ROOT.'/fichinter/info.php?id='.$object->id;
124  $head[$h][1] = $langs->trans('Info');
125  $head[$h][2] = 'info';
126  $h++;
127 
128  complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'external');
129 
130  complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'remove');
131 
132  return $head;
133 }
134 
141 {
142  global $langs, $conf, $user, $db;
143 
144  $extrafields = new ExtraFields($db);
145  $extrafields->fetch_name_optionals_label('fichinter');
146  $extrafields->fetch_name_optionals_label('fichinterdet');
147 
148  $h = 0;
149  $head = array();
150 
151  $h = 0;
152 
153  $head[$h][0] = DOL_URL_ROOT."/admin/fichinter.php";
154  $head[$h][1] = $langs->trans("Interventions");
155  $head[$h][2] = 'ficheinter';
156  $h++;
157 
158  // Show more tabs from modules
159  // Entries must be declared in modules descriptor with line
160  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
161  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
162  complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin');
163 
164  $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php';
165  $head[$h][1] = $langs->trans("ExtraFields");
166  $nbExtrafields = $extrafields->attributes['fichinter']['count'];
167  if ($nbExtrafields > 0) {
168  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
169  }
170  $head[$h][2] = 'attributes';
171  $h++;
172 
173  $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
174  $head[$h][1] = $langs->trans("ExtraFieldsLines");
175  $nbExtrafields = $extrafields->attributes['fichinterdet']['count'];
176  if ($nbExtrafields > 0) {
177  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
178  }
179  $head[$h][2] = 'attributesdet';
180  $h++;
181 
182  complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin', 'remove');
183 
184  return $head;
185 }
186 
193 function fichinter_rec_prepare_head($object)
194 {
195  global $langs, $conf; //, $user;
196 
197  $h = 0;
198  $head = array();
199 
200  $head[$h][0] = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id;
201  $head[$h][1] = $langs->trans("CardFichinter");
202  $head[$h][2] = 'card';
203  $h++;
204 
205  complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec');
206 
207  complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec', 'remove');
208 
209 
210  return $head;
211 }
DAO Resource object.
Class to manage standard extra fields.
fichinter_admin_prepare_head()
Return array head with list of tabs to view object informations.
fichinter_rec_prepare_head($object)
Prepare array with list of tabs.
fichinter_prepare_head($object)
Prepare array with list of tabs.
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_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.