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