dolibarr/htdocs/resource/contact.php

168 lines
4.6 KiB
PHP
Raw Normal View History

2016-01-31 12:26:12 +01:00
<?php
2018-10-27 14:43:12 +02:00
/* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
2016-01-31 12:26:12 +01:00
* Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
2018-07-27 10:06:56 +02:00
* Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
2016-01-31 12:26:12 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2016-01-31 12:26:12 +01:00
*/
/**
* \file htdocs/resource/contact.php
* \ingroup resource
* \brief Onglet de gestion des contacts des resources
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
2016-01-31 12:26:12 +01:00
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
2018-05-26 18:41:16 +02:00
// Load translation files required by the page
$langs->loadLangs(array('resource', 'sendings', 'companies'));
2016-01-31 12:26:12 +01:00
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
2020-09-16 19:39:50 +02:00
$action = GETPOST('action', 'aZ09');
2016-01-31 12:26:12 +01:00
2021-10-25 15:32:10 +02:00
$object = new DolResource($db);
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
2016-01-31 12:26:12 +01:00
// Security check
2021-02-26 20:53:03 +01:00
if ($user->socid) {
$socid = $user->socid;
}
2021-10-25 15:32:10 +02:00
$result = restrictedArea($user, 'resource', $object->id, 'resource');
2016-01-31 12:26:12 +01:00
2021-10-25 15:32:10 +02:00
// Security check
if (!$user->rights->resource->read) {
accessforbidden();
}
2016-01-31 12:26:12 +01:00
/*
2018-07-27 10:06:56 +02:00
* Add a new contact
2016-01-31 12:26:12 +01:00
*/
2021-02-26 20:53:03 +01:00
if ($action == 'addcontact' && $user->rights->resource->write) {
if ($result > 0 && $id > 0) {
$contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
}
2016-01-31 12:26:12 +01:00
2021-02-26 20:53:03 +01:00
if ($result >= 0) {
2016-01-31 12:26:12 +01:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
2020-05-21 15:05:19 +02:00
} else {
2016-01-31 12:26:12 +01:00
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
$mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
} else {
$mesg = $object->error;
}
2018-07-27 10:06:56 +02:00
setEventMessages($mesg, null, 'errors');
2016-01-31 12:26:12 +01:00
}
2021-02-26 20:53:03 +01:00
} elseif ($action == 'swapstatut' && $user->rights->resource->write) {
// Toggle the status of a contact
$result = $object->swapContactStatus(GETPOST('ligne', 'int'));
2021-02-26 20:53:03 +01:00
} elseif ($action == 'deletecontact' && $user->rights->resource->write) {
// Erase a contact
$result = $object->delete_contact(GETPOST('lineid', 'int'));
2016-01-31 12:26:12 +01:00
2021-02-26 20:53:03 +01:00
if ($result >= 0) {
2016-01-31 12:26:12 +01:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
2020-05-21 15:05:19 +02:00
} else {
2016-01-31 12:26:12 +01:00
dol_print_error($db);
}
}
/*
* View
*/
$form = new Form($db);
$formcompany = new FormCompany($db);
$contactstatic = new Contact($db);
$userstatic = new User($db);
2016-01-31 12:26:12 +01:00
llxHeader('', $langs->trans("Resource"));
2016-01-31 12:26:12 +01:00
// Mode vue et edition
2021-02-26 20:53:03 +01:00
if ($id > 0 || !empty($ref)) {
2016-01-31 12:26:12 +01:00
$soc = new Societe($db);
$soc->fetch($object->socid);
$head = resource_prepare_head($object);
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource');
2017-05-23 13:38:48 +02:00
$linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2017-10-20 23:48:42 +02:00
$morehtmlref = '<div class="refidno">';
$morehtmlref .= '</div>';
2017-10-20 23:48:42 +02:00
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
2017-05-23 13:38:48 +02:00
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
2017-10-20 23:48:42 +02:00
2017-05-23 13:38:48 +02:00
// Object
2016-01-31 12:26:12 +01:00
2019-06-05 12:16:55 +02:00
print '<table class="border tableforfield centpercent">';
2016-01-31 12:26:12 +01:00
// Resource type
print '<tr>';
print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
2016-01-31 12:26:12 +01:00
print '<td>';
print $object->type_label;
print '</td>';
print '</tr>';
print '</table>';
print '</div>';
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2017-10-20 23:48:42 +02:00
2016-01-31 12:26:12 +01:00
print '<br>';
2021-02-26 20:53:03 +01:00
if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER)) {
$hideaddcontactforuser = 1;
}
if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY)) {
$hideaddcontactforthirdparty = 1;
}
2016-01-31 12:26:12 +01:00
$permission = 1;
2016-01-31 12:26:12 +01:00
// Contacts lines
include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
}
2018-08-06 11:53:33 +02:00
// End of page
2016-01-31 12:26:12 +01:00
llxFooter();
$db->close();