dolibarr 24.0.0-beta
contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2016 Jean-François Ferry <hello@librethic.io>
3 * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
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, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31
32require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
34
35require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
36require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
37require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39if (isModEnabled('project')) {
40 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
41 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
42 include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
43}
44
53// Load translation files required by the page
54$langs->loadLangs(array('companies', 'ticket'));
55
56// Get parameters
57$socid = GETPOSTINT("socid");
58$action = GETPOST("action", 'alpha');
59$track_id = GETPOST("track_id", 'alpha');
60$id = GETPOSTINT("id");
61$ref = GETPOST('ref', 'alpha');
62
63$type = GETPOST('type', 'alpha');
64$source = GETPOST('source', 'alpha');
65
66$ligne = GETPOSTINT('ligne');
67$lineid = GETPOSTINT('lineid');
68
69
70// Store current page url
71$url_page_current = DOL_URL_ROOT.'/ticket/contact.php';
72
73$hookmanager->initHooks(array('contactticketcard', 'globalcard'));
74$object = new Ticket($db);
75if ($id > 0 || $ref || $track_id) {
76 $result = $object->fetch($id, $ref, $track_id);
77}
78
79$permissiontoadd = $user->hasRight('ticket', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
80$permissiontomanage = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ticket', 'write')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'ticket', 'manage_advance'))); // What is this permission for ?
81
82// Security check
83$id = GETPOSTINT("id");
84if ($user->socid > 0) {
85 $socid = $user->socid;
86}
87$result = restrictedArea($user, 'ticket', $object->id, '');
88
89// restrict access for externals users
90if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
92}
93// or for unauthorized internals users
94if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$permissiontomanage) {
96}
97
98
99/*
100 * Actions
101 */
102$error = 0;
103$parameters = array();
104$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
105if ($reshook < 0) {
106 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107}
108
109if ($action == 'addcontact' && $user->hasRight('ticket', 'write')) {
110 $result = $object->fetch($id, '', $track_id);
111
112 if ($result > 0 && ($id > 0 || (!empty($track_id)))) {
113 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
114 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
115
116 $codecontact = dol_getIdFromCode($db, $typeid, 'c_type_contact', 'rowid', 'code');
117 if ($codecontact == 'SUPPORTTEC') {
118 $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
119 foreach ($internal_contacts as $key => $contact) {
120 if ($contact['id'] !== $contactid) {
121 //print "user à effacer : ".$useroriginassign;
122 $result = $object->delete_contact($contact['rowid']);
123 if ($result < 0) {
124 $error++;
125 setEventMessages($object->error, $object->errors, 'errors');
126 }
127 }
128 }
129 $ret = $object->assignUser($user, $contactid);
130 if ($ret < 0) {
131 $error++;
132 setEventMessages($object->error, $object->errors, 'errors');
133 }
134 }
135
136 if (empty($error)) {
137 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
138 }
139 }
140
141 if ($result >= 0) {
142 header("Location: ".$url_page_current."?id=".$object->id);
143 exit;
144 } else {
145 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
146 $langs->load("errors");
147 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
148 } else {
149 setEventMessages($object->error, $object->errors, 'errors');
150 }
151 }
152}
153
154// bascule du statut d'un contact
155if ($action == 'swapstatut' && $user->hasRight('ticket', 'write')) {
156 if ($object->fetch($id, '', $track_id)) {
157 $result = $object->swapContactStatus($ligne);
158 } else {
159 dol_print_error($db, $object->error);
160 }
161}
162
163// Efface un contact
164if ($action == 'deletecontact' && $user->hasRight('ticket', 'write')) {
165 if ($object->fetch($id, '', $track_id)) {
166 $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
167 foreach ($internal_contacts as $key => $contact) {
168 if ($contact['rowid'] == $lineid && $object->fk_user_assign == $contact['id']) {
169 $ret = $object->assignUser($user, 0);
170 if ($ret < 0) {
171 $error++;
172 setEventMessages($object->error, $object->errors, 'errors');
173 }
174 }
175 }
176 $result = $object->delete_contact($lineid);
177
178 if ($result >= 0) {
179 header("Location: ".$url_page_current."?id=".$object->id);
180 exit;
181 }
182 }
183}
184
185// Set parent company
186if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
187 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
188 $result = $object->setCustomer(GETPOSTINT('editcustomer'));
189 $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
190 header("Location: ".$url);
191 exit();
192 }
193}
194
195
196/*
197 * View
198 */
199
200$help_url = 'FR:DocumentationModuleTicket';
201llxHeader('', $langs->trans("TicketContacts"), $help_url, '', 0, 0, '', '', '', 'mod-ticket page-card_contacts');
202
203$form = new Form($db);
204$formcompany = new FormCompany($db);
205$contactstatic = new Contact($db);
206$userstatic = new User($db);
207
208if ($id > 0 || !empty($track_id) || !empty($ref)) {
209 if ($object->fetch($id, $ref, $track_id) > 0) {
210 if ($socid > 0) {
211 $object->fetch_thirdparty();
212 $head = societe_prepare_head($object->thirdparty);
213 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
214 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
215 print dol_get_fiche_end();
216 }
217
218 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
219 $object->next_prev_filter = "te.fk_user_assign:=:'".((int) $user->id);
220 } elseif ($user->socid > 0) {
221 $object->next_prev_filter = "te.fk_soc:=:".((int) $user->socid);
222 }
223
224 $head = ticket_prepare_head($object);
225
226 print dol_get_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket');
227
228 $morehtmlref = '<div class="refidno">';
229 $morehtmlref .= $object->subject;
230 // Author
231 if ($object->fk_user_create > 0) {
232 $morehtmlref .= '<br>';
233 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
234
235 $fuser = new User($db);
236 $fuser->fetch($object->fk_user_create);
237 $morehtmlref .= $fuser->getNomUrl(-1);
238 } elseif (!empty($object->email_msgid)) {
239 $morehtmlref .= '<br>';
240 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
241 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
242 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
243 } elseif (!empty($object->origin_email)) {
244 $morehtmlref .= '<br>';
245 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
246 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
247 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
248 }
249
250 // Thirdparty
251 if (isModEnabled("societe")) {
252 $morehtmlref .= '<br>';
253 $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
254 if ($action != 'editcustomer' && $permissiontoadd) {
255 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
256 }
257 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, (string) $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
258 }
259
260 // Project
261 if (isModEnabled('project')) {
262 $langs->load("projects");
263 if (0) { // @phpstan-ignore-line
264 $morehtmlref .= '<br>';
265 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
266 if ($action != 'classify') {
267 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
268 }
269 $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');
270 } else {
271 if (!empty($object->fk_project)) {
272 $morehtmlref .= '<br>';
273 $proj = new Project($db);
274 $proj->fetch($object->fk_project);
275 $morehtmlref .= $proj->getNomUrl(1);
276 if ($proj->title) {
277 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
278 }
279 }
280 }
281 }
282
283 $morehtmlref .= '</div>';
284
285 $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
286
287 dol_banner_tab($object, 'ref', $linkback, (empty($user->socid) ? 1 : 0), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1, '');
288
289 print dol_get_fiche_end();
290
291 //print '<br>';
292
293 $permission = $user->hasRight('ticket', 'write');
294
295 // Contacts lines (modules that overwrite templates must declare this into descriptor)
296 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
297 foreach ($dirtpls as $reldir) {
298 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
299 if ($res) {
300 break;
301 }
302 }
303 } else {
304 print "ErrorRecordNotFound";
305 }
306}
307
308// End of page
309llxFooter();
310$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 projects.
Class to manage Dolibarr users.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
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.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
Class to generate the form for creating a new ticket.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
ticket_prepare_head($object)
Build tabs for a Ticket object.