dolibarr 18.0.6
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array('companies', 'ldap'));
34$langs->load("admin");
35
36$action = GETPOST('action', 'aZ09');
37
38// Security check
39$id = GETPOST('id', 'int');
40if ($user->socid) {
41 $socid = $user->socid;
42}
43$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
44
45$object = new Contact($db);
46if ($id > 0) {
47 $object->fetch($id, $user);
48}
49
50
51/*
52 * Actions
53 */
54
55if ($action == 'dolibarr2ldap') {
56 $db->begin();
57
58 $ldap = new Ldap();
59 $result = $ldap->connect_bind();
60
61 $info = $object->_load_ldap_info();
62 $dn = $object->_load_ldap_dn($info);
63 $olddn = $dn; // We can say that old dn = dn as we force synchro
64
65 $result = $ldap->update($dn, $info, $user, $olddn);
66
67 if ($result >= 0) {
68 setEventMessages($langs->trans("ContactSynchronized"), null, 'mesgs');
69 $db->commit();
70 } else {
71 setEventMessages($ldap->error, $ldap->errors, 'errors');
72 $db->rollback();
73 }
74}
75
76
77/*
78 * View
79 */
80
81$form = new Form($db);
82
83$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
84
85llxHeader('', $title, 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
86
87$head = contact_prepare_head($object);
88
89print dol_get_fiche_head($head, 'ldap', $title, -1, 'contact');
90
91$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
92
93dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
94
95print '<div class="fichecenter">';
96
97print '<div class="underbanner clearboth"></div>';
98print '<table class="border centpercent">';
99
100// Company
101if ($object->socid > 0) {
102 $thirdparty = new Societe($db);
103 $thirdparty->fetch($object->socid);
104
105 print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
106} else {
107 print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
108 print $langs->trans("ContactNotLinkedToCompany");
109 print '</td></tr>';
110}
111
112// Civility
113print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
114print $object->getCivilityLabel();
115print '</td></tr>';
116
117// LDAP DN
118print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_CONTACT_DN')."</td></tr>\n";
119
120// LDAP Cle
121print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_KEY_CONTACTS')."</td></tr>\n";
122
123// LDAP Server
124print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
125print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
126print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
127
128print '</table>';
129
130print '</div>';
131
132print dol_get_fiche_end();
133
134
135/*
136 * Action bar
137 */
138print '<div class="tabsAction">';
139
140if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && getDolGlobalInt('LDAP_CONTACT_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
141 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
142}
143
144print "</div>\n";
145
146if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && getDolGlobalInt('LDAP_CONTACT_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
147 print "<br>\n";
148}
149
150
151
152// Affichage attributs LDAP
153print load_fiche_titre($langs->trans("LDAPInformationsForThisContact"));
154
155print '<table width="100%" class="noborder">';
156
157print '<tr class="liste_titre">';
158print '<td>'.$langs->trans("LDAPAttributes").'</td>';
159print '<td>'.$langs->trans("Value").'</td>';
160print '</tr>';
161
162// Lecture LDAP
163$ldap = new Ldap();
164$result = $ldap->connect_bind();
165if ($result > 0) {
166 $info = $object->_load_ldap_info();
167 $dn = $object->_load_ldap_dn($info, 1);
168 $search = "(".$object->_load_ldap_dn($info, 2).")";
169
170 $records = $ldap->getAttribute($dn, $search);
171
172 //var_dump($records);
173
174 // Show tree
175 if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
176 if (!is_array($records)) {
177 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
178 } else {
179 $result = show_ldap_content($records, 0, $records['count'], true);
180 }
181 } else {
182 print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
183 }
184
185 $ldap->unbind();
186} else {
187 setEventMessages($ldap->error, $ldap->errors, 'errors');
188}
189
190
191print '</table>';
192
193llxFooter();
194$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
const SYNCHRO_LDAP_TO_DOLIBARR
Ldap to Dolibarr synchronization.
Class to manage third parties objects (customers, suppliers, prospects...)
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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 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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return 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:132
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.