dolibarr 21.0.0-alpha
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 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30
31require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
33
34require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
35require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
36require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
38if (isModEnabled('project')) {
39 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
40 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
41 include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
42}
43
44// Load translation files required by the page
45$langs->loadLangs(array('companies', 'ticket'));
46
47// Get parameters
48$socid = GETPOSTINT("socid");
49$action = GETPOST("action", 'alpha');
50$track_id = GETPOST("track_id", 'alpha');
51$id = GETPOSTINT("id");
52$ref = GETPOST('ref', 'alpha');
53
54$type = GETPOST('type', 'alpha');
55$source = GETPOST('source', 'alpha');
56
57$ligne = GETPOSTINT('ligne');
58$lineid = GETPOSTINT('lineid');
59
60
61// Store current page url
62$url_page_current = DOL_URL_ROOT.'/ticket/contact.php';
63
64$hookmanager->initHooks(array('contactticketcard', 'globalcard'));
65$object = new Ticket($db);
66if ($id > 0 || $ref || $track_id) {
67 $result = $object->fetch($id, $ref, $track_id);
68}
69
70// Security check
71$id = GETPOSTINT("id");
72if ($user->socid > 0) {
73 $socid = $user->socid;
74}
75$result = restrictedArea($user, 'ticket', $object->id, '');
76
77// restrict access for externals users
78if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
80}
81// or for unauthorized internals users
82if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) {
84}
85
86$permissiontoadd = $user->hasRight('ticket', 'write');
87
88
89/*
90 * Actions
91 */
92$parameters = array();
93$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
94if ($reshook < 0) {
95 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
96}
97
98if ($action == 'addcontact' && $user->hasRight('ticket', 'write')) {
99 $result = $object->fetch($id, '', $track_id);
100
101 if ($result > 0 && ($id > 0 || (!empty($track_id)))) {
102 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
103 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
104
105 $error = 0;
106
107 $codecontact = dol_getIdFromCode($db, $typeid, 'c_type_contact', 'rowid', 'code');
108 if ($codecontact == 'SUPPORTTEC') {
109 $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
110 foreach ($internal_contacts as $key => $contact) {
111 if ($contact['id'] !== $contactid) {
112 //print "user à effacer : ".$useroriginassign;
113 $result = $object->delete_contact($contact['rowid']);
114 if ($result < 0) {
115 $error++;
116 setEventMessages($object->error, $object->errors, 'errors');
117 }
118 }
119 }
120 $ret = $object->assignUser($user, $contactid);
121 if ($ret < 0) {
122 $error++;
123 setEventMessages($object->error, $object->errors, 'errors');
124 }
125 }
126
127 if (empty($error)) {
128 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
129 }
130 }
131
132 if ($result >= 0) {
133 header("Location: ".$url_page_current."?id=".$object->id);
134 exit;
135 } else {
136 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
137 $langs->load("errors");
138 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
139 } else {
140 setEventMessages($object->error, $object->errors, 'errors');
141 }
142 }
143}
144
145// bascule du statut d'un contact
146if ($action == 'swapstatut' && $user->hasRight('ticket', 'write')) {
147 if ($object->fetch($id, '', $track_id)) {
148 $result = $object->swapContactStatus($ligne);
149 } else {
150 dol_print_error($db, $object->error);
151 }
152}
153
154// Efface un contact
155if ($action == 'deletecontact' && $user->hasRight('ticket', 'write')) {
156 if ($object->fetch($id, '', $track_id)) {
157 $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
158 foreach ($internal_contacts as $key => $contact) {
159 if ($contact['rowid'] == $lineid && $object->fk_user_assign == $contact['id']) {
160 $ret = $object->assignUser($user, 0);
161 if ($ret < 0) {
162 $error++;
163 setEventMessages($object->error, $object->errors, 'errors');
164 }
165 }
166 }
167 $result = $object->delete_contact($lineid);
168
169 if ($result >= 0) {
170 header("Location: ".$url_page_current."?id=".$object->id);
171 exit;
172 }
173 }
174}
175
176// Set parent company
177if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
178 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
179 $result = $object->setCustomer(GETPOSTINT('editcustomer'));
180 $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
181 header("Location: ".$url);
182 exit();
183 }
184}
185
186
187/*
188 * View
189 */
190
191$help_url = 'FR:DocumentationModuleTicket';
192llxHeader('', $langs->trans("TicketContacts"), $help_url, '', 0, 0, '', '', '', 'mod-ticket page-card_contacts');
193
194$form = new Form($db);
195$formcompany = new FormCompany($db);
196$contactstatic = new Contact($db);
197$userstatic = new User($db);
198
199if ($id > 0 || !empty($track_id) || !empty($ref)) {
200 if ($object->fetch($id, $ref, $track_id) > 0) {
201 if ($socid > 0) {
202 $object->fetch_thirdparty();
203 $head = societe_prepare_head($object->thirdparty);
204 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
205 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
206 print dol_get_fiche_end();
207 }
208
209 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
210 $object->next_prev_filter = "te.fk_user_assign ='".((int) $user->id);
211 } elseif ($user->socid > 0) {
212 $object->next_prev_filter = "te.fk_soc = ".((int) $user->socid);
213 }
214
215 $head = ticket_prepare_head($object);
216
217 print dol_get_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket');
218
219 $morehtmlref = '<div class="refidno">';
220 $morehtmlref .= $object->subject;
221 // Author
222 if ($object->fk_user_create > 0) {
223 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
224
225 $fuser = new User($db);
226 $fuser->fetch($object->fk_user_create);
227 $morehtmlref .= $fuser->getNomUrl(-1);
228 } elseif (!empty($object->email_msgid)) {
229 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
230 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
231 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
232 } elseif (!empty($object->origin_email)) {
233 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
234 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
235 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
236 }
237
238 // Thirdparty
239 if (isModEnabled("societe")) {
240 $morehtmlref .= '<br>';
241 $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
242 if ($action != 'editcustomer' && $permissiontoadd) {
243 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
244 }
245 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
246 }
247
248 // Project
249 if (isModEnabled('project')) {
250 $langs->load("projects");
251 if (0) {
252 $morehtmlref .= '<br>';
253 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
254 if ($action != 'classify') {
255 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
256 }
257 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
258 } else {
259 if (!empty($object->fk_project)) {
260 $morehtmlref .= '<br>';
261 $proj = new Project($db);
262 $proj->fetch($object->fk_project);
263 $morehtmlref .= $proj->getNomUrl(1);
264 if ($proj->title) {
265 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
266 }
267 }
268 }
269 }
270
271 $morehtmlref .= '</div>';
272
273 $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
274
275 dol_banner_tab($object, 'ref', $linkback, (empty($user->socid) ? 1 : 0), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1, '');
276
277 print dol_get_fiche_end();
278
279 //print '<br>';
280
281 $permission = $user->hasRight('ticket', 'write');
282
283 // Contacts lines (modules that overwrite templates must declare this into descriptor)
284 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
285 foreach ($dirtpls as $reldir) {
286 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
287 if ($res) {
288 break;
289 }
290 }
291 } else {
292 print "ErrorRecordNotFound";
293 }
294}
295
296// End of page
297llxFooter();
298$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
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)
Return array of tabs to used on pages for third parties cards.
llxFooter()
Footer empty.
Definition document.php:107
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)
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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.
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.