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