dolibarr 20.0.0
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
38{
39 global $db, $langs, $conf, $user;
40 $langs->load("fichinter");
41
42 $h = 0;
43 $head = array();
44
45 $head[$h][0] = DOL_URL_ROOT.'/fichinter/card.php?id='.$object->id;
46 $head[$h][1] = $langs->trans("Intervention");
47 $head[$h][2] = 'card';
48 $h++;
49
50 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
51 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
52 $head[$h][0] = DOL_URL_ROOT.'/fichinter/contact.php?id='.$object->id;
53 $head[$h][1] = $langs->trans('InterventionContact');
54 if ($nbContact > 0) {
55 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
56 }
57 $head[$h][2] = 'contact';
58 $h++;
59 }
60
61 // Show more tabs from modules
62 // Entries must be declared in modules descriptor with line
63 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
64 // $this->tabs = array('entity:-tabname); to remove a tab
65 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'core');
66
67 // Tab to link resources
68 if (isModEnabled('resource')) {
69 require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
70 $objectres = new Dolresource($db);
71 $linked_resources = $objectres->getElementResources('fichinter', $object->id);
72 $nbResource = (is_array($linked_resources) ? count($linked_resources) : 0);
73 // if (is_array($objectres->available_resources))
74 // {
75 // foreach ($objectres->available_resources as $modresources => $resources)
76 // {
77 // $resources=(array) $resources; // To be sure $resources is an array
78 // foreach($resources as $resource_obj)
79 // {
80 // $linked_resources = $object->getElementResources('fichinter', $object->id, $resource_obj);
81 // }
82 // }
83 // }
84
85 $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=fichinter&element_id='.$object->id;
86 $head[$h][1] = $langs->trans("Resources");
87 if ($nbResource > 0) {
88 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbResource.'</span>';
89 }
90 $head[$h][2] = 'resource';
91 $h++;
92 }
93
94 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
95 $nbNote = 0;
96 if (!empty($object->note_private)) {
97 $nbNote++;
98 }
99 if (!empty($object->note_public)) {
100 $nbNote++;
101 }
102 $head[$h][0] = DOL_URL_ROOT.'/fichinter/note.php?id='.$object->id;
103 $head[$h][1] = $langs->trans('Notes');
104 if ($nbNote > 0) {
105 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
106 }
107 $head[$h][2] = 'note';
108 $h++;
109 }
110
111 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
112 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
113 $upload_dir = $conf->ficheinter->dir_output."/".dol_sanitizeFileName($object->ref);
114 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
115 $nbLinks = Link::count($db, $object->element, $object->id);
116 $head[$h][0] = DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id;
117 $head[$h][1] = $langs->trans("Documents");
118 if (($nbFiles + $nbLinks) > 0) {
119 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
120 }
121 $head[$h][2] = 'documents';
122 $h++;
123
124 $head[$h][0] = DOL_URL_ROOT.'/fichinter/agenda.php?id='.$object->id;
125 $head[$h][1] = $langs->trans('Events');
126 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
127 $nbEvent = 0;
128 // Enable caching of thirdparty count actioncomm
129 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
130 $cachekey = 'count_events_fichinter_'.$object->id;
131 $dataretrieved = dol_getcache($cachekey);
132 if (!is_null($dataretrieved)) {
133 $nbEvent = $dataretrieved;
134 } else {
135 $sql = "SELECT COUNT(id) as nb";
136 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
137 $sql .= " WHERE fk_element = ".((int) $object->id);
138 $sql .= " AND elementtype = 'fichinter'";
139 $resql = $db->query($sql);
140 if ($resql) {
141 $obj = $db->fetch_object($resql);
142 $nbEvent = $obj->nb;
143 } else {
144 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
145 }
146 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
147 }
148
149 $head[$h][1] .= '/';
150 $head[$h][1] .= $langs->trans("Agenda");
151 if ($nbEvent > 0) {
152 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
153 }
154 }
155 $head[$h][2] = 'agenda';
156 $h++;
157
158 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'external');
159
160 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'remove');
161
162 return $head;
163}
164
171{
172 global $langs, $conf, $user, $db;
173
174 $extrafields = new ExtraFields($db);
175 $extrafields->fetch_name_optionals_label('fichinter');
176 $extrafields->fetch_name_optionals_label('fichinterdet');
177
178 $h = 0;
179 $head = array();
180
181 $head[$h][0] = DOL_URL_ROOT."/admin/fichinter.php";
182 $head[$h][1] = $langs->trans("Interventions");
183 $head[$h][2] = 'ficheinter';
184 $h++;
185
186 // Show more tabs from modules
187 // Entries must be declared in modules descriptor with line
188 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
189 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
190 complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin');
191
192 $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php';
193 $head[$h][1] = $langs->trans("ExtraFields");
194 $nbExtrafields = $extrafields->attributes['fichinter']['count'];
195 if ($nbExtrafields > 0) {
196 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
197 }
198 $head[$h][2] = 'attributes';
199 $h++;
200
201 $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
202 $head[$h][1] = $langs->trans("ExtraFieldsLines");
203 $nbExtrafields = $extrafields->attributes['fichinterdet']['count'];
204 if ($nbExtrafields > 0) {
205 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
206 }
207 $head[$h][2] = 'attributesdet';
208 $h++;
209
210 complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin', 'remove');
211
212 return $head;
213}
214
222{
223 global $langs, $conf; //, $user;
224
225 $h = 0;
226 $head = array();
227
228 $head[$h][0] = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id;
229 $head[$h][1] = $langs->trans("CardFichinter");
230 $head[$h][2] = 'card';
231 $h++;
232
233 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec');
234
235 complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec', 'remove');
236
237
238 return $head;
239}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
DAO Resource object.
Class to manage standard extra fields.
fichinter_admin_prepare_head()
Return array head with list of tabs to view object information.
fichinter_rec_prepare_head($object)
Prepare array with list of tabs.
fichinter_prepare_head($object)
Prepare array with list of tabs.
dol_dir_list($utf8_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:63
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.