dolibarr 20.0.2
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 = GETPOSTINT("socid");
48$action = GETPOST("action", 'alpha');
49$track_id = GETPOST("track_id", 'alpha');
50$id = GETPOSTINT("id");
51$ref = GETPOST('ref', 'alpha');
52
53$type = GETPOST('type', 'alpha');
54$source = GETPOST('source', 'alpha');
55
56$ligne = GETPOSTINT('ligne');
57$lineid = GETPOSTINT('lineid');
58
59
60// Store current page url
61$url_page_current = DOL_URL_ROOT.'/ticket/contact.php';
62
63$hookmanager->initHooks(array('contactticketcard', 'globalcard'));
64$object = new Ticket($db);
65if ($id > 0 || $ref || $track_id) {
66 $result = $object->fetch($id, $ref, $track_id);
67}
68
69// Security check
70$id = GETPOSTINT("id");
71if ($user->socid > 0) {
72 $socid = $user->socid;
73}
74$result = restrictedArea($user, 'ticket', $object->id, '');
75
76// restrict access for externals users
77if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
79}
80// or for unauthorized internals users
81if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) {
83}
84
85$permissiontoadd = $user->hasRight('ticket', 'write');
86
87
88/*
89 * Actions
90 */
91$parameters = array();
92$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
93if ($reshook < 0) {
94 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
95}
96
97if ($action == 'addcontact' && $user->hasRight('ticket', 'write')) {
98 $result = $object->fetch($id, '', $track_id);
99
100 if ($result > 0 && ($id > 0 || (!empty($track_id)))) {
101 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
102 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
103
104 $error = 0;
105
106 $codecontact = dol_getIdFromCode($db, $typeid, 'c_type_contact', 'rowid', 'code');
107 if ($codecontact=='SUPPORTTEC') {
108 $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
109 foreach ($internal_contacts as $key => $contact) {
110 if ($contact['id'] !== $contactid) {
111 //print "user à effacer : ".$useroriginassign;
112 $result = $object->delete_contact($contact['rowid']);
113 if ($result<0) {
114 $error ++;
115 setEventMessages($object->error, $object->errors, 'errors');
116 }
117 }
118 }
119 $ret = $object->assignUser($user, $contactid);
120 if ($ret < 0) {
121 $error ++;
122 setEventMessages($object->error, $object->errors, 'errors');
123 }
124 }
125
126 if (empty($error)) {
127 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
128 }
129 }
130
131 if ($result >= 0) {
132 header("Location: ".$url_page_current."?id=".$object->id);
133 exit;
134 } else {
135 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
136 $langs->load("errors");
137 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
138 } else {
139 setEventMessages($object->error, $object->errors, 'errors');
140 }
141 }
142}
143
144// bascule du statut d'un contact
145if ($action == 'swapstatut' && $user->hasRight('ticket', 'write')) {
146 if ($object->fetch($id, '', $track_id)) {
147 $result = $object->swapContactStatus($ligne);
148 } else {
149 dol_print_error($db, $object->error);
150 }
151}
152
153// Efface un contact
154if ($action == 'deletecontact' && $user->hasRight('ticket', 'write')) {
155 if ($object->fetch($id, '', $track_id)) {
156 $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
157 foreach ($internal_contacts as $key => $contact) {
158 if ($contact['rowid'] == $lineid && $object->fk_user_assign==$contact['id']) {
159 $ret = $object->assignUser($user, null);
160 if ($ret < 0) {
161 $error ++;
162 setEventMessages($object->error, $object->errors, 'errors');
163 }
164 }
165 }
166 $result = $object->delete_contact($lineid);
167
168 if ($result >= 0) {
169 header("Location: ".$url_page_current."?id=".$object->id);
170 exit;
171 }
172 }
173}
174
175// Set parent company
176if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
177 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
178 $result = $object->setCustomer(GETPOSTINT('editcustomer'));
179 $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
180 header("Location: ".$url);
181 exit();
182 }
183}
184
185
186/*
187 * View
188 */
189
190$help_url = 'FR:DocumentationModuleTicket';
191llxHeader('', $langs->trans("TicketContacts"), $help_url, '', 0, 0, '', '', '', 'mod-ticket page-card_contacts');
192
193$form = new Form($db);
194$formcompany = new FormCompany($db);
195$contactstatic = new Contact($db);
196$userstatic = new User($db);
197
198if ($id > 0 || !empty($track_id) || !empty($ref)) {
199 if ($object->fetch($id, $ref, $track_id) > 0) {
200 if ($socid > 0) {
201 $object->fetch_thirdparty();
202 $head = societe_prepare_head($object->thirdparty);
203 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
204 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
205 print dol_get_fiche_end();
206 }
207
208 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
209 $object->next_prev_filter = "te.fk_user_assign ='".((int) $user->id);
210 } elseif ($user->socid > 0) {
211 $object->next_prev_filter = "te.fk_soc = ".((int) $user->socid);
212 }
213
214 $head = ticket_prepare_head($object);
215
216 print dol_get_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket');
217
218 $morehtmlref = '<div class="refidno">';
219 $morehtmlref .= $object->subject;
220 // Author
221 if ($object->fk_user_create > 0) {
222 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
223
224 $fuser = new User($db);
225 $fuser->fetch($object->fk_user_create);
226 $morehtmlref .= $fuser->getNomUrl(-1);
227 } elseif (!empty($object->email_msgid)) {
228 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
229 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
230 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
231 } elseif (!empty($object->origin_email)) {
232 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
233 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
234 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
235 }
236
237 // Thirdparty
238 if (isModEnabled("societe")) {
239 $morehtmlref .= '<br>';
240 $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
241 if ($action != 'editcustomer' && $permissiontoadd) {
242 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
243 }
244 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
245 }
246
247 // Project
248 if (isModEnabled('project')) {
249 $langs->load("projects");
250 if (0) {
251 $morehtmlref .= '<br>';
252 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
253 if ($action != 'classify') {
254 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
255 }
256 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
257 } else {
258 if (!empty($object->fk_project)) {
259 $morehtmlref .= '<br>';
260 $proj = new Project($db);
261 $proj->fetch($object->fk_project);
262 $morehtmlref .= $proj->getNomUrl(1);
263 if ($proj->title) {
264 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
265 }
266 }
267 }
268 }
269
270 $morehtmlref .= '</div>';
271
272 $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
273
274 dol_banner_tab($object, 'ref', $linkback, (empty($user->socid) ? 1 : 0), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1, '');
275
276 print dol_get_fiche_end();
277
278 //print '<br>';
279
280 $permission = $user->hasRight('ticket', 'write');
281
282 // Contacts lines (modules that overwrite templates must declare this into descriptor)
283 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
284 foreach ($dirtpls as $reldir) {
285 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
286 if ($res) {
287 break;
288 }
289 }
290 } else {
291 print "ErrorRecordNotFound";
292 }
293}
294
295// End of page
296llxFooter();
297$db->close();
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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
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.
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.
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 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.