dolibarr  17.0.4
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
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, see <https://www.gnu.org/licenses/>.
18  */
19 
26 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('interventions', 'sendings', 'companies'));
37 
38 $id = GETPOST('id', 'int');
39 $ref = GETPOST('ref', 'alpha');
40 $action = GETPOST('action', 'aZ09');
41 
42 // Security check
43 if ($user->socid) {
44  $socid = $user->socid;
45 }
46 $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
47 
48 $object = new Fichinter($db);
49 $result = $object->fetch($id, $ref);
50 if (!$result) {
51  print 'Record not found';
52  exit;
53 }
54 
55 /*
56  * Adding a new contact
57  */
58 
59 if ($action == 'addcontact' && $user->rights->ficheinter->creer) {
60  if ($result > 0 && $id > 0) {
61  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
62  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
63  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
64  }
65 
66  if ($result >= 0) {
67  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
68  exit;
69  } else {
70  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
71  $langs->load("errors");
72  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
73  } else {
74  $mesg = $object->error;
75  }
76 
77  setEventMessages($mesg, null, 'errors');
78  }
79 } elseif ($action == 'swapstatut' && $user->rights->ficheinter->creer) {
80  // Toggle the status of a contact
81  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
82 } elseif ($action == 'deletecontact' && $user->rights->ficheinter->creer) {
83  // Deletes a contact
84  $result = $object->delete_contact(GETPOST('lineid', 'int'));
85 
86  if ($result >= 0) {
87  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
88  exit;
89  } else {
90  dol_print_error($db);
91  }
92 }
93 
94 
95 /*
96  * View
97  */
98 
99 $form = new Form($db);
100 $formcompany = new FormCompany($db);
101 $contactstatic = new Contact($db);
102 $userstatic = new User($db);
103 $formproject = new FormProjets($db);
104 
105 llxHeader('', $langs->trans("Intervention"));
106 
107 // Mode vue et edition
108 
109 if ($id > 0 || !empty($ref)) {
110  $object->fetch_thirdparty();
111 
112  $head = fichinter_prepare_head($object);
113  print dol_get_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, 'intervention');
114 
115 
116  // Intervention card
117  $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
118 
119 
120  $morehtmlref = '<div class="refidno">';
121  // Ref customer
122  //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
123  //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
124  // Thirdparty
125  $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
126  // Project
127  if (isModEnabled('project')) {
128  $langs->load("projects");
129  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
130  if ($user->rights->ficheinter->creer) {
131  if ($action != 'classify') {
132  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
133  $morehtmlref .= ' : ';
134  }
135  if ($action == 'classify') {
136  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
137  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
138  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
139  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
140  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
141  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
142  $morehtmlref .= '</form>';
143  } else {
144  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
145  }
146  } else {
147  if (!empty($object->fk_project)) {
148  $proj = new Project($db);
149  $proj->fetch($object->fk_project);
150  $morehtmlref .= ' : '.$proj->getNomUrl(1);
151  if ($proj->title) {
152  $morehtmlref .= ' - '.$proj->title;
153  }
154  } else {
155  $morehtmlref .= '';
156  }
157  }
158  }
159  $morehtmlref .= '</div>';
160 
161  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
162 
163  print dol_get_fiche_end();
164 
165  print '<br>';
166 
167  if (!empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_USER)) {
168  $hideaddcontactforuser = 1;
169  }
170  if (!empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_THIPARTY)) {
171  $hideaddcontactforthirdparty = 1;
172  }
173 
174  // Contacts lines (modules that overwrite templates must declare this into descriptor)
175  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
176  foreach ($dirtpls as $reldir) {
177  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
178  if ($res) {
179  break;
180  }
181  }
182 }
183 
184 
185 llxFooter();
186 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage contact/addresses.
Class to manage interventions.
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 building of HTML components.
Class to manage projects.
Class to manage Dolibarr users.
Definition: user.class.php:47
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
fichinter_prepare_head($object)
Prepare array with list of tabs.
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='')
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.