PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/fichinter/contact.php

https://github.com/zeert/dolibarr
PHP | 157 lines | 86 code | 33 blank | 38 comment | 22 complexity | 04da4cde5a2b1026850d2fc20426fd48 MD5 | raw file
  1<?php
  2/* Copyright (C) 2005-2012 Regis Houssin        <regis@dolibarr.fr>
  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 2 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 <http://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');
 31
 32$langs->load("interventions");
 33$langs->load("sendings");
 34$langs->load("companies");
 35
 36$id = GETPOST('id','int');
 37$ref = GETPOST('ref', 'alpha');
 38$action = GETPOST('action','alpha');
 39
 40// Security check
 41if ($user->societe_id) $socid=$user->societe_id;
 42$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
 43
 44$object = new Fichinter($db);
 45$result = $object->fetch($id,$ref);
 46
 47
 48/*
 49 * Ajout d'un nouveau contact
 50 */
 51
 52if ($action == 'addcontact' && $user->rights->ficheinter->creer)
 53{
 54    if ($result > 0 && $id > 0)
 55    {
 56    	$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
 57  		$result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha'));
 58    }
 59
 60	if ($result >= 0)
 61	{
 62		Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 63		exit;
 64	}
 65	else
 66	{
 67		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 68		{
 69			$langs->load("errors");
 70			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 71		}
 72		else
 73		{
 74			$mesg = '<div class="error">'.$object->error.'</div>';
 75		}
 76	}
 77}
 78
 79// bascule du statut d'un contact
 80else if ($action == 'swapstatut' && $user->rights->ficheinter->creer)
 81{
 82    $result=$object->swapContactStatus(GETPOST('ligne','int'));
 83}
 84
 85// Efface un contact
 86else if ($action == 'deletecontact' && $user->rights->ficheinter->creer)
 87{
 88	$result = $object->delete_contact(GETPOST('lineid','int'));
 89
 90	if ($result >= 0)
 91	{
 92		Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 93		exit;
 94	}
 95	else {
 96		dol_print_error($db);
 97	}
 98}
 99
100
101/*
102 * View
103 */
104
105$form = new Form($db);
106$formcompany = new FormCompany($db);
107$contactstatic=new Contact($db);
108$userstatic=new User($db);
109
110llxHeader();
111
112
113// Mode vue et edition
114dol_htmloutput_mesg($mesg);
115
116if ($id > 0 || ! empty($ref))
117{
118	$soc = new Societe($db);
119	$soc->fetch($object->socid);
120
121
122	$head = fichinter_prepare_head($object);
123	dol_fiche_head($head, 'contact', $langs->trans("InterventionCard"), 0, 'intervention');
124
125
126	/*
127	*   Fiche intervention synthese pour rappel
128	*/
129	print '<table class="border" width="100%">';
130
131	$linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
132
133	// Ref
134	print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
135    print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
136	print "</td></tr>";
137
138	// Customer
139	if ( is_null($object->client) )
140		$object->fetch_thirdparty();
141
142	print "<tr><td>".$langs->trans("Company")."</td>";
143	print '<td colspan="3">'.$object->client->getNomUrl(1).'</td></tr>';
144	print "</table>";
145
146	print '</div>';
147
148	print '<br>';
149
150	// Contacts lines
151	include(DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php');
152}
153
154
155llxFooter();
156$db->close();
157?>