dolibarr 19.0.3
ldap.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006 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.'/core/lib/member.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
30require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
31require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array("companies", "members", "ldap", "admin"));
35
36$id = GETPOST('id', 'int');
37$ref = GETPOST('ref', 'alphanohtml');
38$action = GETPOST('action', 'aZ09');
39
40// Protection
41$socid = 0;
42if ($user->socid > 0) {
43 $socid = $user->socid;
44}
45
46$object = new Adherent($db);
47
48// Fetch object
49if ($id > 0 || !empty($ref)) {
50 // Load member
51 $result = $object->fetch($id, $ref);
52
53 // Define variables to know what current user can do on users
54 $canadduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer'));
55 // Define variables to know what current user can do on properties of user linked to edited member
56 if ($object->user_id) {
57 // $User is the user who edits, $object->user_id is the id of the related user in the edited member
58 $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer'))
59 || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer')));
60 $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password'))
61 || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password')));
62 }
63}
64
65// Define variables to determine what the current user can do on the members
66$canaddmember = $user->hasRight('adherent', 'creer');
67// Define variables to determine what the current user can do on the properties of a member
68if ($id) {
69 $caneditfieldmember = $user->hasRight('adherent', 'creer');
70}
71
72// Security check
73$result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
74
75
76/*
77 * Actions
78 */
79
80if ($action == 'dolibarr2ldap') {
81 $ldap = new Ldap();
82 $result = $ldap->connect_bind();
83
84 if ($result > 0) {
85 $info = $object->_load_ldap_info();
86 $dn = $object->_load_ldap_dn($info);
87 $olddn = $dn; // We can say that old dn = dn as we force synchro
88
89 $result = $ldap->update($dn, $info, $user, $olddn);
90 }
91
92 if ($result >= 0) {
93 setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
94 } else {
95 setEventMessages($ldap->error, $ldap->errors, 'errors');
96 }
97}
98
99
100
101/*
102 * View
103 */
104
105$form = new Form($db);
106
107llxHeader('', $langs->trans("Member"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder');
108
109$head = member_prepare_head($object);
110
111print dol_get_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
112
113$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
114
115dol_banner_tab($object, 'rowid', $linkback);
116
117print '<div class="fichecenter">';
118
119print '<div class="underbanner clearboth"></div>';
120print '<table class="border centpercent tableforfield">';
121
122// Login
123print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
124
125// If there is a link to password not crypted, we show value in database here so we can compare because it is shown nowhere else
126if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
127 print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
128 print '<td class="valeur">'.$object->pass.'</td>';
129 print "</tr>\n";
130}
131
132$adht = new AdherentType($db);
133$adht->fetch($object->typeid);
134
135// Type
136print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
137
138// LDAP DN
139print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_MEMBER_DN')."</td></tr>\n";
140
141// LDAP Cle
142print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_MEMBERS')."</td></tr>\n";
143
144// LDAP Server
145print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
146print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
147print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
148print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
149print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
150
151print '</table>';
152
153print '</div>';
154
155print dol_get_fiche_end();
156
157/*
158 * Action bar
159 */
160print '<div class="tabsAction">';
161
162if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
163 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
164}
165
166print "</div>\n";
167
168if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
169 print "<br>\n";
170}
171
172
173
174// Affichage attributs LDAP
175print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
176
177print '<table width="100%" class="noborder">';
178
179print '<tr class="liste_titre">';
180print '<td>'.$langs->trans("LDAPAttributes").'</td>';
181print '<td>'.$langs->trans("Value").'</td>';
182print '</tr>';
183
184// Lecture LDAP
185$ldap = new Ldap();
186$result = $ldap->connect_bind();
187if ($result > 0) {
188 $info = $object->_load_ldap_info();
189 $dn = $object->_load_ldap_dn($info, 1);
190 $search = "(".$object->_load_ldap_dn($info, 2).")";
191
192 if (empty($dn)) {
193 $langs->load("errors");
194 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Member")).'</span></td></tr>';
195 } else {
196 $records = $ldap->getAttribute($dn, $search);
197
198 //print_r($records);
199
200 // Show tree
201 if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
202 if (!is_array($records)) {
203 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
204 } else {
205 $result = show_ldap_content($records, 0, $records['count'], true);
206 }
207 } else {
208 print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
209 }
210 }
211
212 $ldap->unbind();
213} else {
214 setEventMessages($ldap->error, $ldap->errors, 'errors');
215}
216
217
218print '</table>';
219
220// End of page
221llxFooter();
222$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage members of a foundation.
Class to manage members type.
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.
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.
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
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object informations.
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.