1<?php
2/* Copyright (C) 2006-2010  Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2010-2017  Regis Houssin       <regis.houssin@inodbox.com>
4 * Copyright (C) 2015       Frederic France     <frederic.france@free.fr>
5 * Copyright (C) 2015       Raphaël Doursenaud  <rdoursenaud@gpcsolutions.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
22/**
23 *	    \file       htdocs/core/lib/contact.lib.php
24 *		\brief      Ensemble de fonctions de base pour les contacts
25 */
26
27/**
28 * Prepare array with list of tabs
29 *
30 * @param   Contact	$object		Object related to tabs
31 * @return  array				Array of tabs to show
32 */
33function contact_prepare_head(Contact $object)
34{
35	global $db, $langs, $conf, $user;
36
37	$tab = 0;
38	$head = array();
39
40	$head[$tab][0] = DOL_URL_ROOT.'/contact/card.php?id='.$object->id;
41	$head[$tab][1] = $langs->trans("Contact");
42	$head[$tab][2] = 'card';
43	$tab++;
44
45	if ((!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_CONTACT_ACTIVE))
46		&& (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || !empty($user->admin)))
47	{
48		$langs->load("ldap");
49
50		$head[$tab][0] = DOL_URL_ROOT.'/contact/ldap.php?id='.$object->id;
51		$head[$tab][1] = $langs->trans("LDAPCard");
52		$head[$tab][2] = 'ldap';
53		$tab++;
54	}
55
56	$head[$tab][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$object->id;
57	$head[$tab][1] = $langs->trans("PersonalInformations");
58	$head[$tab][2] = 'perso';
59	$tab++;
60
61	// Related items
62	if (!empty($conf->commande->enabled) || !empty($conf->propal->enabled) || !empty($conf->facture->enabled) || !empty($conf->ficheinter->enabled) || !empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
63	{
64		$head[$tab][0] = DOL_URL_ROOT.'/contact/consumption.php?id='.$object->id;
65		$head[$tab][1] = $langs->trans("Referers");
66		$head[$tab][2] = 'consumption';
67		$tab++;
68	}
69
70	// Show more tabs from modules
71	// Entries must be declared in modules descriptor with line
72	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
73	// $this->tabs = array('entity:-tabname);   												to remove a tab
74	complete_head_from_modules($conf, $langs, $object, $head, $tab, 'contact');
75
76	// Notes
77	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
78		$nbNote = (empty($object->note_private) ? 0 : 1) + (empty($object->note_public) ? 0 : 1);
79		$head[$tab][0] = DOL_URL_ROOT.'/contact/note.php?id='.$object->id;
80		$head[$tab][1] = $langs->trans("Note");
81		if ($nbNote > 0) $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
82		$head[$tab][2] = 'note';
83		$tab++;
84	}
85
86	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
87	require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
88	$upload_dir = $conf->societe->dir_output."/contact/".dol_sanitizeFileName($object->ref);
89	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
90	$nbLinks = Link::count($db, $object->element, $object->id);
91	$head[$tab][0] = DOL_URL_ROOT.'/contact/document.php?id='.$object->id;
92	$head[$tab][1] = $langs->trans("Documents");
93	if (($nbFiles + $nbLinks) > 0) $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
94	$head[$tab][2] = 'documents';
95	$tab++;
96
97	// Agenda / Events
98	$head[$tab][0] = DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id;
99	$head[$tab][1] .= $langs->trans("Events");
100	if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
101	{
102		$head[$tab][1] .= '/';
103		$head[$tab][1] .= $langs->trans("Agenda");
104	}
105	$head[$tab][2] = 'agenda';
106	$tab++;
107
108	// Log
109	/*
110    $head[$tab][0] = DOL_URL_ROOT.'/contact/info.php?id='.$object->id;
111	$head[$tab][1] = $langs->trans("Info");
112	$head[$tab][2] = 'info';
113	$tab++;*/
114
115	complete_head_from_modules($conf, $langs, $object, $head, $tab, 'contact', 'remove');
116
117	return $head;
118}
119