dolibarr 22.0.5
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 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$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
57
58$object = new Fichinter($db);
59$result = $object->fetch($id, $ref);
60if (!$result) {
61 print 'Record not found';
62 exit;
63}
64
65$usercancreate = $user->hasRight('ficheinter', 'creer');
66
67
68/*
69 * Adding a new contact
70 */
71
72if ($action == 'addcontact' && $user->hasRight('ficheinter', 'creer')) {
73 if ($result > 0 && $id > 0) {
74 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
75 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
76 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
77 }
78
79 if ($result >= 0) {
80 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
81 exit;
82 } else {
83 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
84 $langs->load("errors");
85 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
86 } else {
87 $mesg = $object->error;
88 }
89
90 setEventMessages($mesg, null, 'errors');
91 }
92} elseif ($action == 'swapstatut' && $user->hasRight('ficheinter', 'creer')) {
93 // Toggle the status of a contact
94 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
95} elseif ($action == 'deletecontact' && $user->hasRight('ficheinter', 'creer')) {
96 // Deletes a contact
97 $result = $object->delete_contact(GETPOSTINT('lineid'));
98
99 if ($result >= 0) {
100 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
101 exit;
102 } else {
103 dol_print_error($db);
104 }
105}
106
107
108/*
109 * View
110 */
111
112$form = new Form($db);
113$formcompany = new FormCompany($db);
114$contactstatic = new Contact($db);
115$userstatic = new User($db);
116$formproject = new FormProjets($db);
117
118llxHeader('', $langs->trans("Intervention"), '', '', 0, 0, '', '', '', 'mod-fichinter page-card_contact');
119
120// Mode vue et edition
121
122if ($id > 0 || !empty($ref)) {
123 $object->fetch_thirdparty();
124
125 $head = fichinter_prepare_head($object);
126 print dol_get_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, 'intervention');
127
128
129 // Intervention card
130 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
131
132
133 $morehtmlref = '<div class="refidno">';
134 // Ref customer
135 //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', 0, 1);
136 //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
137 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
138 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
139 // Thirdparty
140 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
141 // Project
142 if (isModEnabled('project')) {
143 $langs->load("projects");
144 $morehtmlref .= '<br>';
145 if ($usercancreate && 0) {
146 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
147 if ($action != 'classify') {
148 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
149 }
150 $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');
151 } else {
152 if (!empty($object->fk_project)) {
153 $proj = new Project($db);
154 $proj->fetch($object->fk_project);
155 $morehtmlref .= $proj->getNomUrl(1);
156 if ($proj->title) {
157 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
158 }
159 }
160 }
161 }
162 $morehtmlref .= '</div>';
163
164 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
165
166 print dol_get_fiche_end();
167
168 print '<br>';
169
170 if (getDolGlobalString('FICHINTER_HIDE_ADD_CONTACT_USER')) {
171 $hideaddcontactforuser = 1;
172 }
173 if (getDolGlobalString('FICHINTER_HIDE_ADD_CONTACT_THIPARTY')) {
174 $hideaddcontactforthirdparty = 1;
175 }
176
177 // Contacts lines (modules that overwrite templates must declare this into descriptor)
178 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
179 foreach ($dirtpls as $reldir) {
180 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
181 if ($res) {
182 break;
183 }
184 }
185}
186
187
188llxFooter();
189$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.