dolibarr 21.0.0-beta
ldap.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2006-2021 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
33
42// Load translation files required by the page
43$langs->loadLangs(array('companies', 'ldap'));
44$langs->load("admin");
45
46$action = GETPOST('action', 'aZ09');
47
48// Security check
49$id = GETPOSTINT('id');
50if ($user->socid) {
51 $socid = $user->socid;
52}
53$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
54
55$object = new Contact($db);
56if ($id > 0) {
57 $object->fetch($id, $user);
58}
59
60
61/*
62 * Actions
63 */
64
65if ($action == 'dolibarr2ldap') {
66 $db->begin();
67
68 $ldap = new Ldap();
69 $result = $ldap->connectBind();
70
71 $info = $object->_load_ldap_info();
72 $dn = $object->_load_ldap_dn($info);
73 $olddn = $dn; // We can say that old dn = dn as we force synchro
74
75 $result = $ldap->update($dn, $info, $user, $olddn);
76
77 if ($result >= 0) {
78 setEventMessages($langs->trans("ContactSynchronized"), null, 'mesgs');
79 $db->commit();
80 } else {
81 setEventMessages($ldap->error, $ldap->errors, 'errors');
82 $db->rollback();
83 }
84}
85
86
87/*
88 * View
89 */
90
91$form = new Form($db);
92
93$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
94$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
95
96llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card_ldap');
97
98$head = contact_prepare_head($object);
99
100print dol_get_fiche_head($head, 'ldap', $title, -1, 'contact');
101
102$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
103
104dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
105
106print '<div class="fichecenter">';
107
108print '<div class="underbanner clearboth"></div>';
109print '<table class="border centpercent">';
110
111// Company
112if ($object->socid > 0) {
113 $thirdparty = new Societe($db);
114 $thirdparty->fetch($object->socid);
115
116 print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
117} else {
118 print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
119 print $langs->trans("ContactNotLinkedToCompany");
120 print '</td></tr>';
121}
122
123// Civility
124print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
125print $object->getCivilityLabel();
126print '</td></tr>';
127
128// LDAP DN
129print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_CONTACT_DN')."</td></tr>\n";
130
131// LDAP Cle
132print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_KEY_CONTACTS')."</td></tr>\n";
133
134// LDAP Server
135print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
136print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
137print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
138
139print '</table>';
140
141print '</div>';
142
143print dol_get_fiche_end();
144
145
146/*
147 * Action bar
148 */
149print '<div class="tabsAction">';
150
151if (getDolGlobalString('LDAP_CONTACT_ACTIVE') && getDolGlobalInt('LDAP_CONTACT_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
152 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
153}
154
155print "</div>\n";
156
157if (getDolGlobalString('LDAP_CONTACT_ACTIVE') && getDolGlobalInt('LDAP_CONTACT_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
158 print "<br>\n";
159}
160
161
162
163// Affichage attributes LDAP
164print load_fiche_titre($langs->trans("LDAPInformationsForThisContact"));
165
166print '<table width="100%" class="noborder">';
167
168print '<tr class="liste_titre">';
169print '<td>'.$langs->trans("LDAPAttributes").'</td>';
170print '<td>'.$langs->trans("Value").'</td>';
171print '</tr>';
172
173// Lecture LDAP
174$ldap = new Ldap();
175$result = $ldap->connectBind();
176if ($result > 0) {
177 $info = $object->_load_ldap_info();
178 $dn = $object->_load_ldap_dn($info, 1);
179 $search = "(".$object->_load_ldap_dn($info, 2).")";
180
181 $records = $ldap->getAttribute($dn, $search);
182
183 //var_dump($records);
184
185 // Show tree
186 if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
187 if (!is_array($records)) {
188 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
189 } else {
190 $result = show_ldap_content($records, 0, $records['count'], true);
191 }
192 } else {
193 print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
194 }
195
196 $ldap->unbind();
197} else {
198 setEventMessages($ldap->error, $ldap->errors, 'errors');
199}
200
201
202print '</table>';
203
204llxFooter();
205$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.
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
Class to manage third parties objects (customers, suppliers, prospects...)
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition ldap.lib.php:134
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.