dolibarr 24.0.2
contact.php
Go to the documentation of this file.
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 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
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 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
40require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
44require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array('interventions', 'sendings', 'companies'));
48
49$id = GETPOSTINT('id');
50$ref = GETPOST('ref', 'alpha');
51$action = GETPOST('action', 'aZ09');
52
53// Security check
54if ($user->isExternalUser()) {
55 $socid = $user->isExternalUser();
56}
57
58$object = new Fichinter($db);
59$resultfetch = $object->fetch($id, $ref);
60if ($object->id > 0) {
61 $id = $object->id; // The page may be called with the ref only: the security check must be done on the object found
62}
63$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
64if (!$resultfetch) {
65 print 'Record not found';
66 exit;
67}
68
69$usercancreate = $user->hasRight('ficheinter', 'creer');
70
71
72/*
73 * Adding a new contact
74 */
75
76if ($action == 'addcontact' && $user->hasRight('ficheinter', 'creer')) {
77 if ($result > 0 && $id > 0) {
78 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
79 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
80 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
81 }
82
83 if ($result >= 0) {
84 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
85 exit;
86 } else {
87 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
88 $langs->load("errors");
89 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
90 } else {
91 $mesg = $object->error;
92 }
93
94 setEventMessages($mesg, null, 'errors');
95 }
96} elseif ($action == 'swapstatut' && $user->hasRight('ficheinter', 'creer')) {
97 // Toggle the status of a contact
98 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
99} elseif ($action == 'deletecontact' && $user->hasRight('ficheinter', 'creer')) {
100 // Deletes a contact
101 $result = $object->delete_contact(GETPOSTINT('lineid'));
102
103 if ($result >= 0) {
104 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
105 exit;
106 } else {
108 }
109}
110
111
112/*
113 * View
114 */
115
116$form = new Form($db);
117$formcompany = new FormCompany($db);
118$contactstatic = new Contact($db);
119$userstatic = new User($db);
120$formproject = new FormProjets($db);
121
122$title = $object->ref . " - " . $langs->trans('ContactsAddresses');
123$help_url = 'EN:Module_Interventions|FR:Module_Fiches_d\'interventions';
124
125llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-fichinter page-card_contact');
126
127// Mode vue et edition
128
129if ($id > 0 || !empty($ref)) {
130 $object->fetch_thirdparty();
131
132 $head = fichinter_prepare_head($object);
133 print dol_get_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, $object->picto);
134
135
136 // Intervention card
137 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
138
139
140 $morehtmlref = '<div class="refidno">';
141 // Ref customer
142 //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', 0, 1);
143 //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
144 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
145 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
146 // Thirdparty
147 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
148 // Project
149 if (isModEnabled('project')) {
150 $langs->load("projects");
151 $morehtmlref .= '<br>';
152 if ($usercancreate && 0) {
153 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
154 if ($action != 'classify') {
155 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
156 }
157 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
158 } else {
159 if (!empty($object->fk_project)) {
160 $proj = new Project($db);
161 $proj->fetch($object->fk_project);
162 $morehtmlref .= $proj->getNomUrl(1);
163 if ($proj->title) {
164 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
165 }
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 (getDolGlobalString('FICHINTER_HIDE_ADD_CONTACT_USER')) {
178 $hideaddcontactforuser = 1;
179 }
180 if (getDolGlobalString('FICHINTER_HIDE_ADD_CONTACT_THIPARTY')) {
181 $hideaddcontactforthirdparty = 1;
182 }
183
184 // Contacts lines (modules that overwrite templates must declare this into descriptor)
185 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
186 foreach ($dirtpls as $reldir) {
187 $file = dol_buildpath($reldir.'/contacts.tpl.php');
188 if (file_exists($file)) {
189 $res = @include $file;
190 if ($res) {
191 break;
192 }
193 }
194 }
195}
196
197
198llxFooter();
199$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage contact/addresses.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage projects.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
fichinter_prepare_head($object)
Prepare array with list of tabs.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.