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