dolibarr  16.0.5
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 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("companies", "members", "ldap", "admin"));
34 
35 $id = GETPOST('id', 'int');
36 $ref = GETPOST('ref', 'alphanohtml');
37 $action = GETPOST('action', 'aZ09');
38 
39 // Protection
40 $socid = 0;
41 if ($user->socid > 0) {
42  $socid = $user->socid;
43 }
44 
45 $object = new Adherent($db);
46 
47 // Fetch object
48 if ($id > 0 || !empty($ref)) {
49  // Load member
50  $result = $object->fetch($id, $ref);
51 
52  // Define variables to know what current user can do on users
53  $canadduser = (!empty($user->admin) || !empty($user->rights->user->user->creer));
54  // Define variables to know what current user can do on properties of user linked to edited member
55  if ($object->user_id) {
56  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
57  $caneditfielduser = ((($user->id == $object->user_id) && !empty($user->rights->user->self->creer))
58  || (($user->id != $object->user_id) && !empty($user->rights->user->user->creer)));
59  $caneditpassworduser = ((($user->id == $object->user_id) && $user->rights->user->self->password)
60  || (($user->id != $object->user_id) && !empty($user->rights->user->user->password)));
61  }
62 }
63 
64 // Define variables to determine what the current user can do on the members
65 $canaddmember = $user->rights->adherent->creer;
66 // Define variables to determine what the current user can do on the properties of a member
67 if ($id) {
68  $caneditfieldmember = $user->rights->adherent->creer;
69 }
70 
71 // Security check
72 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
73 
74 
75 /*
76  * Actions
77  */
78 
79 if ($action == 'dolibarr2ldap') {
80  $ldap = new Ldap();
81  $result = $ldap->connect_bind();
82 
83  if ($result > 0) {
84  $info = $object->_load_ldap_info();
85  $dn = $object->_load_ldap_dn($info);
86  $olddn = $dn; // We can say that old dn = dn as we force synchro
87 
88  $result = $ldap->update($dn, $info, $user, $olddn);
89  }
90 
91  if ($result >= 0) {
92  setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
93  } else {
94  setEventMessages($ldap->error, $ldap->errors, 'errors');
95  }
96 }
97 
98 
99 
100 /*
101  * View
102  */
103 
104 $form = new Form($db);
105 
106 llxHeader('', $langs->trans("Member"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
107 
108 $head = member_prepare_head($object);
109 
110 print dol_get_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
111 
112 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
113 
114 dol_banner_tab($object, 'rowid', $linkback);
115 
116 print '<div class="fichecenter">';
117 
118 print '<div class="underbanner clearboth"></div>';
119 print '<table class="border centpercent tableforfield">';
120 
121 // Login
122 print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
123 
124 // 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
125 if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
126  print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
127  print '<td class="valeur">'.$object->pass.'</td>';
128  print "</tr>\n";
129 }
130 
131 $adht = new AdherentType($db);
132 $adht->fetch($object->typeid);
133 
134 // Type
135 print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
136 
137 // LDAP DN
138 print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_MEMBER_DN')."</td></tr>\n";
139 
140 // LDAP Cle
141 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_MEMBERS')."</td></tr>\n";
142 
143 // LDAP Server
144 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
145 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
146 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
147 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
148 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
149 
150 print '</table>';
151 
152 print '</div>';
153 
154 print dol_get_fiche_end();
155 
156 /*
157  * Action bar
158  */
159 print '<div class="tabsAction">';
160 
161 if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
162  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
163 }
164 
165 print "</div>\n";
166 
167 if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
168  print "<br>\n";
169 }
170 
171 
172 
173 // Affichage attributs LDAP
174 print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
175 
176 print '<table width="100%" class="noborder">';
177 
178 print '<tr class="liste_titre">';
179 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
180 print '<td>'.$langs->trans("Value").'</td>';
181 print '</tr>';
182 
183 // Lecture LDAP
184 $ldap = new Ldap();
185 $result = $ldap->connect_bind();
186 if ($result > 0) {
187  $info = $object->_load_ldap_info();
188  $dn = $object->_load_ldap_dn($info, 1);
189  $search = "(".$object->_load_ldap_dn($info, 2).")";
190 
191  if (empty($dn)) {
192  $langs->load("errors");
193  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Member")).'</span></td></tr>';
194  } else {
195  $records = $ldap->getAttribute($dn, $search);
196 
197  //print_r($records);
198 
199  // Show tree
200  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
201  if (!is_array($records)) {
202  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
203  } else {
204  $result = show_ldap_content($records, 0, $records['count'], true);
205  }
206  } else {
207  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
208  }
209  }
210 
211  $ldap->unbind();
212 } else {
213  setEventMessages($ldap->error, $ldap->errors, 'errors');
214 }
215 
216 
217 print '</table>';
218 
219 // End of page
220 llxFooter();
221 $db->close();
Ldap
Class to manage LDAP features.
Definition: ldap.class.php:34
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
member_prepare_head
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:33
dol_banner_tab
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.
Definition: functions.lib.php:2046
show_ldap_content
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
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
Ldap\SYNCHRO_LDAP_TO_DOLIBARR
const SYNCHRO_LDAP_TO_DOLIBARR
Ldap to Dolibarr synchronization.
Definition: ldap.class.php:138
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59