dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 */
9
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
34require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('companies', 'resource', 'sendings'));
48
49$id = GETPOSTINT('id');
50$ref = GETPOST('ref', 'alpha');
51$action = GETPOST('action', 'aZ09');
52
53$object = new Dolresource($db);
54
55// Load object
56include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
57
58// Security check
59if ($user->socid) {
60 $socid = $user->socid;
61}
62$result = restrictedArea($user, 'resource', $object->id, 'resource');
63
64// Security check
65if (!$user->hasRight('resource', 'read')) {
67}
68
69
70
71/*
72 * Actions
73 */
74
75// Add a new contact
76if ($action == 'addcontact' && $user->hasRight('resource', 'write')) {
77 if ($result > 0 && $id > 0) {
78 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
79 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
80 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
81 }
82
83 if ($result >= 0) {
84 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
85 exit;
86 } else {
87 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
88 $langs->load("errors");
89 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
90 } else {
91 $mesg = $object->error;
92 }
93
94 setEventMessages($mesg, null, 'errors');
95 }
96} elseif ($action == 'swapstatut' && $user->hasRight('resource', 'write')) {
97 // Toggle the status of a contact
98 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
99} elseif ($action == 'deletecontact' && $user->hasRight('resource', 'write')) {
100 // Erase a contact
101 $result = $object->delete_contact(GETPOSTINT('lineid'));
102
103 if ($result >= 0) {
104 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
105 exit;
106 } else {
107 dol_print_error($db);
108 }
109}
110
111
112/*
113 * View
114 */
115
116$form = new Form($db);
117$formcompany = new FormCompany($db);
118$contactstatic = new Contact($db);
119$userstatic = new User($db);
120
121$help_url = '';
122llxHeader('', $langs->trans("Resource"), $help_url, '', 0, 0, '', '', '', 'mod-resource page-card_contact');
123
124// View and edit mode
125
126if ($id > 0 || !empty($ref)) {
127 $head = resource_prepare_head($object);
128 print dol_get_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource');
129
130
131 $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
132
133
134 $morehtmlref = '<div class="refidno">';
135 $morehtmlref .= '</div>';
136
137
138 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
139
140
141 print '<div class="fichecenter">';
142 print '<div class="underbanner clearboth"></div>';
143
144
145 // Object
146
147 print '<table class="border tableforfield centpercent">';
148
149 // Resource type
150 print '<tr>';
151 print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
152 print '<td>';
153 print $object->type_label;
154 print '</td>';
155 print '</tr>';
156
157 print '</table>';
158 print '</div>';
159
160 print dol_get_fiche_end();
161
162 print '<br>';
163
164 if (getDolGlobalString('RESOURCE_HIDE_ADD_CONTACT_USER')) {
165 $hideaddcontactforuser = 1;
166 }
167 if (getDolGlobalString('RESOURCE_HIDE_ADD_CONTACT_THIPARTY')) {
168 $hideaddcontactforthirdparty = 1;
169 }
170
171 $permission = 1;
172 // Contacts lines
173 include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
174}
175
176// End of page
177llxFooter();
178$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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.
llxFooter()
Footer empty.
Definition document.php:107
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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 a 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.