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
24/**
25 *	\file       htdocs/core/lib/fichinter.lib.php
26 *	\brief      Ensemble de fonctions de base pour le module fichinter
27 *	\ingroup    fichinter
28 */
29
30/**
31 * Prepare array with list of tabs
32 *
33 * @param   Object	$object		Object related to tabs
34 * @return  array				Array of tabs to show
35 */
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 (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
50	{
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) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
55		$head[$h][2] = 'contact';
56		$h++;
57	}
58
59	// Show more tabs from modules
60	// Entries must be declared in modules descriptor with line
61	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
62	// $this->tabs = array('entity:-tabname);   												to remove a tab
63	complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention');
64
65	// Tab to link resources
66	if ($conf->resource->enabled)
67	{
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) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbResource.'</span>';
87		$head[$h][2] = 'resource';
88		$h++;
89	}
90
91	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
92	{
93		$nbNote = 0;
94		if (!empty($object->note_private)) $nbNote++;
95		if (!empty($object->note_public)) $nbNote++;
96		$head[$h][0] = DOL_URL_ROOT.'/fichinter/note.php?id='.$object->id;
97		$head[$h][1] = $langs->trans('Notes');
98		if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
99		$head[$h][2] = 'note';
100		$h++;
101	}
102
103	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
104	require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
105	$upload_dir = $conf->ficheinter->dir_output."/".dol_sanitizeFileName($object->ref);
106	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
107	$nbLinks = Link::count($db, $object->element, $object->id);
108	$head[$h][0] = DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id;
109	$head[$h][1] = $langs->trans("Documents");
110	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
111	$head[$h][2] = 'documents';
112	$h++;
113
114	$head[$h][0] = DOL_URL_ROOT.'/fichinter/info.php?id='.$object->id;
115	$head[$h][1] = $langs->trans('Info');
116	$head[$h][2] = 'info';
117	$h++;
118
119	complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'remove');
120
121	return $head;
122}
123
124/**
125 *  Return array head with list of tabs to view object informations.
126 *
127 *  @return	array   	        head array with tabs
128 */
129function fichinter_admin_prepare_head()
130{
131	global $langs, $conf, $user;
132
133	$h = 0;
134	$head = array();
135
136	$h = 0;
137
138	$head[$h][0] = DOL_URL_ROOT."/admin/fichinter.php";
139	$head[$h][1] = $langs->trans("Interventions");
140	$head[$h][2] = 'ficheinter';
141	$h++;
142
143	// Show more tabs from modules
144	// Entries must be declared in modules descriptor with line
145	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
146	// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
147	complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin');
148
149	$head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php';
150	$head[$h][1] = $langs->trans("ExtraFields");
151	$head[$h][2] = 'attributes';
152	$h++;
153
154	$head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
155	$head[$h][1] = $langs->trans("ExtraFieldsLines");
156	$head[$h][2] = 'attributesdet';
157	$h++;
158
159
160
161	complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin', 'remove');
162
163		return $head;
164}
165
166/**
167 * Prepare array with list of tabs
168 *
169 * @param   Object  $object     Object related to tabs
170 * @return  array               Array of tabs to show
171 */
172function fichinter_rec_prepare_head($object)
173{
174	global $langs, $conf; //, $user;
175
176	$h = 0;
177	$head = array();
178
179	$head[$h][0] = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id;
180	$head[$h][1] = $langs->trans("CardFichinter");
181	$head[$h][2] = 'card';
182	$h++;
183
184	complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec');
185
186	complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec', 'remove');
187
188
189	return $head;
190}
191