dolibarr 23.0.4
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-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
31require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
35require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array('interventions', 'sendings', 'companies'));
47
48$id = GETPOSTINT('id');
49$ref = GETPOST('ref', 'alpha');
50$action = GETPOST('action', 'aZ09');
51
52// Security check
53if ($user->socid) {
54 $socid = $user->socid;
55}
56
57$object = new Fichinter($db);
58$resultfetch = $object->fetch($id, $ref);
59if ($object->id > 0) {
60 $id = $object->id; // The page may be called with the ref only: the security check must be done on the object found
61}
62$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
63if (!$resultfetch) {
64 print 'Record not found';
65 exit;
66}
67
68$usercancreate = $user->hasRight('ficheinter', 'creer');
69
70
71/*
72 * Adding a new contact
73 */
74
75if ($action == 'addcontact' && $user->hasRight('ficheinter', 'creer')) {
76 if ($result > 0 && $id > 0) {
77 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
78 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
79 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
80 }
81
82 if ($result >= 0) {
83 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
84 exit;
85 } else {
86 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
87 $langs->load("errors");
88 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
89 } else {
90 $mesg = $object->error;
91 }
92
93 setEventMessages($mesg, null, 'errors');
94 }
95} elseif ($action == 'swapstatut' && $user->hasRight('ficheinter', 'creer')) {
96 // Toggle the status of a contact
97 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
98} elseif ($action == 'deletecontact' && $user->hasRight('ficheinter', 'creer')) {
99 // Deletes a contact
100 $result = $object->delete_contact(GETPOSTINT('lineid'));
101
102 if ($result >= 0) {
103 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
104 exit;
105 } else {
106 dol_print_error($db);
107 }
108}
109
110
111/*
112 * View
113 */
114
115$form = new Form($db);
116$formcompany = new FormCompany($db);
117$contactstatic = new Contact($db);
118$userstatic = new User($db);
119$formproject = new FormProjets($db);
120
121llxHeader('', $langs->trans("Intervention"), '', '', 0, 0, '', '', '', 'mod-fichinter page-card_contact');
122
123// Mode vue et edition
124
125if ($id > 0 || !empty($ref)) {
126 $object->fetch_thirdparty();
127
128 $head = fichinter_prepare_head($object);
129 print dol_get_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, $object->picto);
130
131
132 // Intervention card
133 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
134
135
136 $morehtmlref = '<div class="refidno">';
137 // Ref customer
138 //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', 0, 1);
139 //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
140 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
141 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
142 // Thirdparty
143 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
144 // Project
145 if (isModEnabled('project')) {
146 $langs->load("projects");
147 $morehtmlref .= '<br>';
148 if ($usercancreate && 0) {
149 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
150 if ($action != 'classify') {
151 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
152 }
153 $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');
154 } else {
155 if (!empty($object->fk_project)) {
156 $proj = new Project($db);
157 $proj->fetch($object->fk_project);
158 $morehtmlref .= $proj->getNomUrl(1);
159 if ($proj->title) {
160 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
161 }
162 }
163 }
164 }
165 $morehtmlref .= '</div>';
166
167 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
168
169 print dol_get_fiche_end();
170
171 print '<br>';
172
173 if (getDolGlobalString('FICHINTER_HIDE_ADD_CONTACT_USER')) {
174 $hideaddcontactforuser = 1;
175 }
176 if (getDolGlobalString('FICHINTER_HIDE_ADD_CONTACT_THIPARTY')) {
177 $hideaddcontactforthirdparty = 1;
178 }
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 $file = dol_buildpath($reldir.'/contacts.tpl.php');
184 if (file_exists($file)) {
185 $res = @include $file;
186 if ($res) {
187 break;
188 }
189 }
190 }
191}
192
193
194llxFooter();
195$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.
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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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)
Return value of a param into GET or POST supervariable.
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, $mode=0)
Check permissions of a user to show a page and an object.