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