dolibarr  13.0.2
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 // Security check
42 if ($user->socid) $socid = $user->socid;
43 $result = restrictedArea($user, 'resource', $id, 'resource');
44 
45 $object = new DolResource($db);
46 $result = $object->fetch($id, $ref);
47 
48 
49 /*
50  * Add a new contact
51  */
52 
53 if ($action == 'addcontact' && $user->rights->resource->write)
54 {
55  if ($result > 0 && $id > 0)
56  {
57  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
58  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
59  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
60  }
61 
62  if ($result >= 0)
63  {
64  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
65  exit;
66  } else {
67  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
68  $langs->load("errors");
69  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
70  } else {
71  $mesg = $object->error;
72  }
73 
74  setEventMessages($mesg, null, 'errors');
75  }
76 }
77 
78 // Toggle the status of a contact
79 elseif ($action == 'swapstatut' && $user->rights->resource->write)
80 {
81  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
82 }
83 
84 // Erase a contact
85 elseif ($action == 'deletecontact' && $user->rights->resource->write)
86 {
87  $result = $object->delete_contact(GETPOST('lineid', 'int'));
88 
89  if ($result >= 0)
90  {
91  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
92  exit;
93  } else {
94  dol_print_error($db);
95  }
96 }
97 
98 
99 /*
100  * View
101  */
102 
103 $form = new Form($db);
104 $formcompany = new FormCompany($db);
105 $contactstatic = new Contact($db);
106 $userstatic = new User($db);
107 
108 llxHeader('', $langs->trans("Resource"));
109 
110 // Mode vue et edition
111 
112 if ($id > 0 || !empty($ref))
113 {
114  $soc = new Societe($db);
115  $soc->fetch($object->socid);
116 
117 
118  $head = resource_prepare_head($object);
119  print dol_get_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource');
120 
121 
122  $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
123 
124 
125  $morehtmlref = '<div class="refidno">';
126  $morehtmlref .= '</div>';
127 
128 
129  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
130 
131 
132  print '<div class="fichecenter">';
133  print '<div class="underbanner clearboth"></div>';
134 
135 
136  // Object
137 
138  print '<table class="border tableforfield centpercent">';
139 
140  // Resource type
141  print '<tr>';
142  print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
143  print '<td>';
144  print $object->type_label;
145  print '</td>';
146  print '</tr>';
147 
148  print '</table>';
149  print '</div>';
150 
152 
153  print '<br>';
154 
155  if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER)) $hideaddcontactforuser = 1;
156  if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY)) $hideaddcontactforthirdparty = 1;
157 
158  $permission = 1;
159  // Contacts lines
160  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
161 }
162 
163 // End of page
164 llxFooter();
165 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
resource_prepare_head($object)
Prepare head for tabs.
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 third parties objects (customers, suppliers, prospects...)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
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.
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:59