dolibarr 19.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
36function 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 (!getDolGlobalString('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 (!getDolGlobalString('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/agenda.php?id='.$object->id;
124 $head[$h][1] = $langs->trans('Events');
125 if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
126 $nbEvent = 0;
127 // Enable caching of thirdparty count actioncomm
128 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
129 $cachekey = 'count_events_fichinter_'.$object->id;
130 $dataretrieved = dol_getcache($cachekey);
131 if (!is_null($dataretrieved)) {
132 $nbEvent = $dataretrieved;
133 } else {
134 $sql = "SELECT COUNT(id) as nb";
135 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
136 $sql .= " WHERE fk_element = ".((int) $object->id);
137 $sql .= " AND elementtype = 'fichinter'";
138 $resql = $db->query($sql);
139 if ($resql) {
140 $obj = $db->fetch_object($resql);
141 $nbEvent = $obj->nb;
142 } else {
143 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
144 }
145 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
146 }
147
148 $head[$h][1] .= '/';
149 $head[$h][1] .= $langs->trans("Agenda");
150 if ($nbEvent > 0) {
151 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
152 }
153 }
154 $head[$h][2] = 'agenda';
155 $h++;
156
157 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'external');
158
159 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'remove');
160
161 return $head;
162}
163
170{
171 global $langs, $conf, $user, $db;
172
173 $extrafields = new ExtraFields($db);
174 $extrafields->fetch_name_optionals_label('fichinter');
175 $extrafields->fetch_name_optionals_label('fichinterdet');
176
177 $h = 0;
178 $head = array();
179
180 $h = 0;
181
182 $head[$h][0] = DOL_URL_ROOT."/admin/fichinter.php";
183 $head[$h][1] = $langs->trans("Interventions");
184 $head[$h][2] = 'ficheinter';
185 $h++;
186
187 // Show more tabs from modules
188 // Entries must be declared in modules descriptor with line
189 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
190 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
191 complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin');
192
193 $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php';
194 $head[$h][1] = $langs->trans("ExtraFields");
195 $nbExtrafields = $extrafields->attributes['fichinter']['count'];
196 if ($nbExtrafields > 0) {
197 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
198 }
199 $head[$h][2] = 'attributes';
200 $h++;
201
202 $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
203 $head[$h][1] = $langs->trans("ExtraFieldsLines");
204 $nbExtrafields = $extrafields->attributes['fichinterdet']['count'];
205 if ($nbExtrafields > 0) {
206 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
207 }
208 $head[$h][2] = 'attributesdet';
209 $h++;
210
211 complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin', 'remove');
212
213 return $head;
214}
215
223{
224 global $langs, $conf; //, $user;
225
226 $h = 0;
227 $head = array();
228
229 $head[$h][0] = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id;
230 $head[$h][1] = $langs->trans("CardFichinter");
231 $head[$h][2] = 'card';
232 $h++;
233
234 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec');
235
236 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec', 'remove');
237
238
239 return $head;
240}
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:62
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).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.