1<?php
2/* Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@inodbox.com>
3 * Copyright (C) 2007-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
4 * Copyright (C) 2012      Juanjo Menent        <jmenent@2byte.es>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20/**
21 *       \file       htdocs/fichinter/contact.php
22 *       \ingroup    fichinter
23 *       \brief      Onglet de gestion des contacts de fiche d'intervention
24 */
25
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
28require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
32require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array('interventions', 'sendings', 'companies'));
36
37$id = GETPOST('id', 'int');
38$ref = GETPOST('ref', 'alpha');
39$action = GETPOST('action', 'aZ09');
40
41// Security check
42if ($user->socid) $socid = $user->socid;
43$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
44
45$object = new Fichinter($db);
46$result = $object->fetch($id, $ref);
47if (!$result)
48{
49	print 'Record not found';
50	exit;
51}
52
53/*
54 * Adding a new contact
55 */
56
57if ($action == 'addcontact' && $user->rights->ficheinter->creer)
58{
59	if ($result > 0 && $id > 0)
60	{
61		$contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
62		$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
63		$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
64	}
65
66	if ($result >= 0)
67	{
68		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
69		exit;
70	} else {
71		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
72			$langs->load("errors");
73			$mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
74		} else {
75			$mesg = $object->error;
76		}
77
78		setEventMessages($mesg, null, 'errors');
79	}
80}
81
82// Toggle the status of a contact
83elseif ($action == 'swapstatut' && $user->rights->ficheinter->creer)
84{
85	$result = $object->swapContactStatus(GETPOST('ligne', 'int'));
86}
87
88// Deletes a contact
89elseif ($action == 'deletecontact' && $user->rights->ficheinter->creer)
90{
91	$result = $object->delete_contact(GETPOST('lineid', 'int'));
92
93	if ($result >= 0)
94	{
95		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
96		exit;
97	} else {
98		dol_print_error($db);
99	}
100}
101
102
103/*
104 * View
105 */
106
107$form = new Form($db);
108$formcompany = new FormCompany($db);
109$contactstatic = new Contact($db);
110$userstatic = new User($db);
111$formproject = new FormProjets($db);
112
113llxHeader('', $langs->trans("Intervention"));
114
115// Mode vue et edition
116
117if ($id > 0 || !empty($ref))
118{
119	$object->fetch_thirdparty();
120
121	$head = fichinter_prepare_head($object);
122	print dol_get_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, 'intervention');
123
124
125	// Intervention card
126	$linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
127
128
129	$morehtmlref = '<div class="refidno">';
130	// Ref customer
131	//$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
132	//$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
133	// Thirdparty
134	$morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
135	// Project
136	if (!empty($conf->projet->enabled))
137	{
138		$langs->load("projects");
139		$morehtmlref .= '<br>'.$langs->trans('Project').' ';
140		if ($user->rights->ficheinter->creer)
141		{
142			if ($action != 'classify') {
143				//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
144				$morehtmlref .= ' : ';
145			}
146			if ($action == 'classify') {
147				//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
148				$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
149				$morehtmlref .= '<input type="hidden" name="action" value="classin">';
150				$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
151				$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
152				$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
153				$morehtmlref .= '</form>';
154			} else {
155				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
156			}
157		} else {
158			if (!empty($object->fk_project)) {
159				$proj = new Project($db);
160				$proj->fetch($object->fk_project);
161				$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
162				$morehtmlref .= $proj->ref;
163				$morehtmlref .= '</a>';
164			} else {
165				$morehtmlref .= '';
166			}
167		}
168	}
169	$morehtmlref .= '</div>';
170
171	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
172
173	print dol_get_fiche_end();
174
175	print '<br>';
176
177	if (!empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_USER))     $hideaddcontactforuser = 1;
178	if (!empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_THIPARTY)) $hideaddcontactforthirdparty = 1;
179
180	// Contacts lines (modules that overwrite templates must declare this into descriptor)
181	$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
182	foreach ($dirtpls as $reldir)
183	{
184		$res = @include dol_buildpath($reldir.'/contacts.tpl.php');
185		if ($res) break;
186	}
187}
188
189
190llxFooter();
191$db->close();
192