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