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  * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
6 
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('resource', 'sendings', 'companies'));
36 
37 $id = GETPOST('id', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $action = GETPOST('action', 'aZ09');
40 
41 $object = new DolResource($db);
42 
43 // Load object
44 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
45 
46 // Security check
47 if ($user->socid) {
48  $socid = $user->socid;
49 }
50 $result = restrictedArea($user, 'resource', $object->id, 'resource');
51 
52 // Security check
53 if (!$user->rights->resource->read) {
55 }
56 
57 
58 /*
59  * Add a new contact
60  */
61 
62 if ($action == 'addcontact' && $user->rights->resource->write) {
63  if ($result > 0 && $id > 0) {
64  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
65  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
66  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
67  }
68 
69  if ($result >= 0) {
70  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
71  exit;
72  } else {
73  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
74  $langs->load("errors");
75  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
76  } else {
77  $mesg = $object->error;
78  }
79 
80  setEventMessages($mesg, null, 'errors');
81  }
82 } elseif ($action == 'swapstatut' && $user->rights->resource->write) {
83  // Toggle the status of a contact
84  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
85 } elseif ($action == 'deletecontact' && $user->rights->resource->write) {
86  // Erase a contact
87  $result = $object->delete_contact(GETPOST('lineid', 'int'));
88 
89  if ($result >= 0) {
90  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
91  exit;
92  } else {
93  dol_print_error($db);
94  }
95 }
96 
97 
98 /*
99  * View
100  */
101 
102 $form = new Form($db);
103 $formcompany = new FormCompany($db);
104 $contactstatic = new Contact($db);
105 $userstatic = new User($db);
106 
107 llxHeader('', $langs->trans("Resource"));
108 
109 // Mode vue et edition
110 
111 if ($id > 0 || !empty($ref)) {
112  $soc = new Societe($db);
113  $soc->fetch($object->socid);
114 
115 
116  $head = resource_prepare_head($object);
117  print dol_get_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource');
118 
119 
120  $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
121 
122 
123  $morehtmlref = '<div class="refidno">';
124  $morehtmlref .= '</div>';
125 
126 
127  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
128 
129 
130  print '<div class="fichecenter">';
131  print '<div class="underbanner clearboth"></div>';
132 
133 
134  // Object
135 
136  print '<table class="border tableforfield centpercent">';
137 
138  // Resource type
139  print '<tr>';
140  print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
141  print '<td>';
142  print $object->type_label;
143  print '</td>';
144  print '</tr>';
145 
146  print '</table>';
147  print '</div>';
148 
149  print dol_get_fiche_end();
150 
151  print '<br>';
152 
153  if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER)) {
154  $hideaddcontactforuser = 1;
155  }
156  if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY)) {
157  $hideaddcontactforthirdparty = 1;
158  }
159 
160  $permission = 1;
161  // Contacts lines
162  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
163 }
164 
165 // End of page
166 llxFooter();
167 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
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
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
$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
resource_prepare_head
resource_prepare_head($object)
Prepare head for tabs.
Definition: resource.lib.php:32
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
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
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
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