dolibarr 20.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
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
33require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36
37// Load translation files required by the page
38$langs->loadLangs(array('companies', 'resource', 'sendings'));
39
40$id = GETPOSTINT('id');
41$ref = GETPOST('ref', 'alpha');
42$action = GETPOST('action', 'aZ09');
43
44$object = new Dolresource($db);
45
46// Load object
47include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
48
49// Security check
50if ($user->socid) {
51 $socid = $user->socid;
52}
53$result = restrictedArea($user, 'resource', $object->id, 'resource');
54
55// Security check
56if (!$user->hasRight('resource', 'read')) {
58}
59
60
61
62/*
63 * Actions
64 */
65
66// Add a new contact
67if ($action == 'addcontact' && $user->hasRight('resource', 'write')) {
68 if ($result > 0 && $id > 0) {
69 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
70 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
71 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
72 }
73
74 if ($result >= 0) {
75 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
76 exit;
77 } else {
78 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
79 $langs->load("errors");
80 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
81 } else {
82 $mesg = $object->error;
83 }
84
85 setEventMessages($mesg, null, 'errors');
86 }
87} elseif ($action == 'swapstatut' && $user->hasRight('resource', 'write')) {
88 // Toggle the status of a contact
89 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
90} elseif ($action == 'deletecontact' && $user->hasRight('resource', 'write')) {
91 // Erase a contact
92 $result = $object->delete_contact(GETPOSTINT('lineid'));
93
94 if ($result >= 0) {
95 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
96 exit;
97 } else {
98 dol_print_error($db);
99 }
100}
101
102
103/*
104 * View
105 */
106
107$form = new Form($db);
108$formcompany = new FormCompany($db);
109$contactstatic = new Contact($db);
110$userstatic = new User($db);
111
112$help_url = '';
113llxHeader('', $langs->trans("Resource"), $help_url, '', 0, 0, '', '', '', 'mod-resource page-card_contact');
114
115// View and edit mode
116
117if ($id > 0 || !empty($ref)) {
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
151 print dol_get_fiche_end();
152
153 print '<br>';
154
155 if (getDolGlobalString('RESOURCE_HIDE_ADD_CONTACT_USER')) {
156 $hideaddcontactforuser = 1;
157 }
158 if (getDolGlobalString('RESOURCE_HIDE_ADD_CONTACT_THIPARTY')) {
159 $hideaddcontactforthirdparty = 1;
160 }
161
162 $permission = 1;
163 // Contacts lines
164 include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
165}
166
167// End of page
168llxFooter();
169$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage contact/addresses.
DAO Resource object.
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 Dolibarr users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_get_fiche_end($notab=0)
Return tab footer of a card.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
resource_prepare_head($object)
Prepare head for tabs.
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.