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