dolibarr  16.0.1
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 require '../main.inc.php';
28 
29 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
31 
32 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33 require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
34 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('companies', 'ticket'));
39 
40 // Get parameters
41 $socid = GETPOST("socid", 'int');
42 $action = GETPOST("action", 'alpha');
43 $track_id = GETPOST("track_id", 'alpha');
44 $id = GETPOST("id", 'int');
45 $ref = GETPOST('ref', 'alpha');
46 
47 $type = GETPOST('type', 'alpha');
48 $source = GETPOST('source', 'alpha');
49 
50 $ligne = GETPOST('ligne', 'int');
51 $lineid = GETPOST('lineid', 'int');
52 
53 
54 // Store current page url
55 $url_page_current = DOL_URL_ROOT.'/ticket/contact.php';
56 
57 $object = new Ticket($db);
58 
59 
60 $permissiontoadd = $user->rights->ticket->write;
61 
62 // Security check
63 $id = GETPOST("id", 'int');
64 if ($user->socid > 0) $socid = $user->socid;
65 $result = restrictedArea($user, 'ticket', $object->id, '');
66 
67 // restrict access for externals users
68 if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
70 }
71 // or for unauthorized internals users
72 if (!$user->socid && (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
74 }
75 
76 
77 /*
78  * Actions
79  */
80 
81 if ($action == 'addcontact' && $user->rights->ticket->write) {
82  $result = $object->fetch($id, '', $track_id);
83 
84  if ($result > 0 && ($id > 0 || (!empty($track_id)))) {
85  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
86  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
87 
88  $error = 0;
89 
90  $codecontact = dol_getIdFromCode($db, $typeid, 'c_type_contact', 'rowid', 'code');
91  if ($codecontact=='SUPPORTTEC') {
92  $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
93  foreach ($internal_contacts as $key => $contact) {
94  if ($contact['id'] !== $contactid) {
95  //print "user à effacer : ".$useroriginassign;
96  $result = $object->delete_contact($contact['rowid']);
97  if ($result<0) {
98  $error ++;
99  setEventMessages($object->error, $object->errors, 'errors');
100  }
101  }
102  }
103  $ret = $object->assignUser($user, $contactid);
104  if ($ret < 0) {
105  $error ++;
106  setEventMessages($object->error, $object->errors, 'errors');
107  }
108  }
109 
110  if (empty($error)) {
111  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
112  }
113  }
114 
115  if ($result >= 0) {
116  Header("Location: ".$url_page_current."?id=".$object->id);
117  exit;
118  } else {
119  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
120  $langs->load("errors");
121  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
122  } else {
123  setEventMessages($object->error, $object->errors, 'errors');
124  }
125  }
126 }
127 
128 // bascule du statut d'un contact
129 if ($action == 'swapstatut' && $user->rights->ticket->write) {
130  if ($object->fetch($id, '', $track_id)) {
131  $result = $object->swapContactStatus($ligne);
132  } else {
133  dol_print_error($db, $object->error);
134  }
135 }
136 
137 // Efface un contact
138 if ($action == 'deletecontact' && $user->rights->ticket->write) {
139  if ($object->fetch($id, '', $track_id)) {
140  $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
141  foreach ($internal_contacts as $key => $contact) {
142  if ($contact['rowid'] == $lineid && $object->fk_user_assign==$contact['id']) {
143  $ret = $object->assignUser($user, null);
144  if ($ret < 0) {
145  $error ++;
146  setEventMessages($object->error, $object->errors, 'errors');
147  }
148  }
149  }
150  $result = $object->delete_contact($lineid);
151 
152  if ($result >= 0) {
153  Header("Location: ".$url_page_current."?id=".$object->id);
154  exit;
155  }
156  }
157 }
158 
159 
160 
161 /*
162  * View
163  */
164 
165 $help_url = 'FR:DocumentationModuleTicket';
166 llxHeader('', $langs->trans("TicketContacts"), $help_url);
167 
168 $form = new Form($db);
169 $formcompany = new FormCompany($db);
170 $contactstatic = new Contact($db);
171 $userstatic = new User($db);
172 
173 if ($id > 0 || !empty($track_id) || !empty($ref)) {
174  if ($object->fetch($id, $ref, $track_id) > 0) {
175  if ($socid > 0) {
176  $object->fetch_thirdparty();
177  $head = societe_prepare_head($object->thirdparty);
178  print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
179  dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
180  print dol_get_fiche_end();
181  }
182 
183  if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
184  $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
185  } elseif ($user->socid > 0) {
186  $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
187  }
188 
189  $head = ticket_prepare_head($object);
190 
191  print dol_get_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket');
192 
193  $morehtmlref = '<div class="refidno">';
194  $morehtmlref .= $object->subject;
195  // Author
196  if ($object->fk_user_create > 0) {
197  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
198 
199  $fuser = new User($db);
200  $fuser->fetch($object->fk_user_create);
201  $morehtmlref .= $fuser->getNomUrl(-1);
202  } elseif (!empty($object->email_msgid)) {
203  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
204  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
205  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
206  } elseif (!empty($object->origin_email)) {
207  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
208  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
209  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
210  }
211 
212  // Thirdparty
213  if (isModEnabled('societe')) {
214  $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
215  /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
216  $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token='.newToken().'&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
217  }*/
218  $morehtmlref .= ' : ';
219  if ($action == 'editcustomer') {
220  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
221  } else {
222  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
223  }
224  }
225 
226  // Project
227  if (isModEnabled('project')) {
228  $langs->load("projects");
229  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
230  if ($user->rights->ticket->write) {
231  if ($action != 'classify') {
232  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
233  $morehtmlref .= ' : ';
234  }
235  if ($action == 'classify') {
236  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
237  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
238  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
239  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
240  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
241  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
242  $morehtmlref .= '</form>';
243  } else {
244  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
245  }
246  } else {
247  if (!empty($object->fk_project)) {
248  $proj = new Project($db);
249  $proj->fetch($object->fk_project);
250  $morehtmlref .= $proj->getNomUrl(1);
251  } else {
252  $morehtmlref .= '';
253  }
254  }
255  }
256 
257  $morehtmlref .= '</div>';
258 
259  $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
260 
261  dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, $param, 0, '', '', 1, '');
262 
263  print dol_get_fiche_end();
264 
265  //print '<br>';
266 
267  $permission = $user->rights->ticket->write;
268 
269  // Contacts lines (modules that overwrite templates must declare this into descriptor)
270  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
271  foreach ($dirtpls as $reldir) {
272  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
273  if ($res) {
274  break;
275  }
276  }
277  } else {
278  print "ErrorRecordNotFound";
279  }
280 }
281 
282 // End of page
283 llxFooter();
284 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
ticket_prepare_head($object)
Build tabs for a Ticket object.
Definition: ticket.lib.php:76
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0, $filters= '')
Return an id or code from a code or id.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
Class to manage ticket.
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
restrictedArea($user, $features, $objectid=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.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:73