dolibarr  7.0.0-beta
ldap_users.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2005 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
7  * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
35 
36 $langs->load("admin");
37 $langs->load("errors");
38 
39 if (!$user->admin)
41 
42 $action = GETPOST('action','aZ09');
43 
44 /*
45  * Actions
46  */
47 
48 if ($action == 'setvalue' && $user->admin)
49 {
50  $error=0;
51  $db->begin();
52 
53  if (! dolibarr_set_const($db, 'LDAP_USER_DN',GETPOST("user"),'chaine',0,'',$conf->entity)) $error++;
54  if (! dolibarr_set_const($db, 'LDAP_USER_OBJECT_CLASS',GETPOST("objectclass"),'chaine',0,'',$conf->entity)) $error++;
55  if (! dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION',GETPOST("filterconnection"),'chaine',0,'',$conf->entity)) $error++;
56  if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',GETPOST("fieldfullname"),'chaine',0,'',$conf->entity)) $error++;
57  if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',GETPOST("fieldlogin"),'chaine',0,'',$conf->entity)) $error++;
58  if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',GETPOST("fieldloginsamba"),'chaine',0,'',$conf->entity)) $error++;
59  if (! dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD',GETPOST("fieldpassword"),'chaine',0,'',$conf->entity)) $error++;
60  if (! dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD_CRYPTED',GETPOST("fieldpasswordcrypted"),'chaine',0,'',$conf->entity)) $error++;
61  if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',GETPOST("fieldname"),'chaine',0,'',$conf->entity)) $error++;
62  if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',GETPOST("fieldfirstname"),'chaine',0,'',$conf->entity)) $error++;
63  if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',GETPOST("fieldmail"),'chaine',0,'',$conf->entity)) $error++;
64  if (! dolibarr_set_const($db, 'LDAP_FIELD_PHONE',GETPOST("fieldphone"),'chaine',0,'',$conf->entity)) $error++;
65  if (! dolibarr_set_const($db, 'LDAP_FIELD_MOBILE',GETPOST("fieldmobile"),'chaine',0,'',$conf->entity)) $error++;
66  if (! dolibarr_set_const($db, 'LDAP_FIELD_SKYPE',GETPOST("fieldskype"),'chaine',0,'',$conf->entity)) $error++;
67  if (! dolibarr_set_const($db, 'LDAP_FIELD_FAX',GETPOST("fieldfax"),'chaine',0,'',$conf->entity)) $error++;
68  if (! dolibarr_set_const($db, 'LDAP_FIELD_COMPANY',GETPOST("fieldcompany"),'chaine',0,'',$conf->entity)) $error++;
69  if (! dolibarr_set_const($db, 'LDAP_FIELD_ADDRESS',GETPOST("fieldaddress"),'chaine',0,'',$conf->entity)) $error++;
70  if (! dolibarr_set_const($db, 'LDAP_FIELD_ZIP',GETPOST("fieldzip"),'chaine',0,'',$conf->entity)) $error++;
71  if (! dolibarr_set_const($db, 'LDAP_FIELD_TOWN',GETPOST("fieldtown"),'chaine',0,'',$conf->entity)) $error++;
72  if (! dolibarr_set_const($db, 'LDAP_FIELD_COUNTRY',GETPOST("fieldcountry"),'chaine',0,'',$conf->entity)) $error++;
73  if (! dolibarr_set_const($db, 'LDAP_FIELD_DESCRIPTION',GETPOST("fielddescription"),'chaine',0,'',$conf->entity)) $error++;
74  if (! dolibarr_set_const($db, 'LDAP_FIELD_SID',GETPOST("fieldsid"),'chaine',0,'',$conf->entity)) $error++;
75  if (! dolibarr_set_const($db, 'LDAP_FIELD_TITLE',GETPOST("fieldtitle"),'chaine',0,'',$conf->entity)) $error++;
76 
77  // This one must be after the others
78  $valkey='';
79  $key=GETPOST("key");
80  if ($key) $valkey=$conf->global->$key;
81  if (! dolibarr_set_const($db, 'LDAP_KEY_USERS',$valkey,'chaine',0,'',$conf->entity)) $error++;
82 
83  if (! $error)
84  {
85  $db->commit();
86  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
87  }
88  else
89  {
90  $db->rollback();
91  dol_print_error($db);
92  }
93 }
94 
95 
96 
97 /*
98  * Visu
99  */
100 
101 $form=new Form($db);
102 
103 llxHeader('',$langs->trans("LDAPSetup"),'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP');
104 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
105 
106 print load_fiche_titre($langs->trans("LDAPSetup"),$linkback,'title_setup');
107 
108 $head = ldap_prepare_head();
109 
110 // Test si fonction LDAP actives
111 if (! function_exists("ldap_connect"))
112 {
113  setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
114 }
115 
116 
117 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
118 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
119 
120 
121 dol_fiche_head($head, 'users', $langs->trans("LDAPSetup"), -1);
122 
123 print $langs->trans("LDAPDescUsers").'<br>';
124 print '<br>';
125 
126 
127 
128 
129 print '<table class="noborder" width="100%">';
130 $var=true;
131 
132 print '<tr class="liste_titre">';
133 print '<td colspan="4">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
134 print "</tr>\n";
135 
136 // DN Pour les utilisateurs
137 
138 print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserDn").'</span></td><td>';
139 print '<input size="48" type="text" name="user" value="'.$conf->global->LDAP_USER_DN.'">';
140 print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>';
141 print '<td>&nbsp;</td>';
142 print '</tr>';
143 
144 // List of object class used to define attributes in structure
145 
146 print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserObjectClassList").'</span></td><td>';
147 print '<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_USER_OBJECT_CLASS.'">';
148 print '</td><td>'.$langs->trans("LDAPUserObjectClassListExample").'</td>';
149 print '<td>&nbsp;</td>';
150 print '</tr>';
151 
152 // Filter, used to filter search
153 
154 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFilterConnection").'</td><td>';
155 print '<input size="48" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">';
156 print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
157 print '<td></td>';
158 print '</tr>';
159 
160 print '</table>';
161 print '<br>';
162 print '<table class="noborder" width="100%">';
163 $var=true;
164 
165 print '<tr class="liste_titre">';
166 print '<td width="25%">'.$langs->trans("LDAPDolibarrMapping").'</td>';
167 print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
168 print '<td align="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
169 print "</tr>\n";
170 
171 // Common name
172 
173 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
174 print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_FIELD_FULLNAME.'">';
175 print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
176 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FULLNAME)?' checked':'')."></td>";
177 print '</tr>';
178 
179 // Name
180 
181 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
182 print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
183 print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
184 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_NAME)?' checked':'')."></td>";
185 print '</tr>';
186 
187 // Firstname
188 
189 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
190 print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
191 print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
192 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FIRSTNAME)?' checked':'')."></td>";
193 print '</tr>';
194 
195 // Login unix
196 
197 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
198 print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">';
199 print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
200 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN)?' checked':'')."></td>";
201 print '</tr>';
202 
203 // Login samba
204 
205 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
206 print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">';
207 print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
208 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN_SAMBA"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN_SAMBA)?' checked':'')."></td>";
209 print '</tr>';
210 
211 // Password not crypted
212 
213 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td><td>';
214 print '<input size="25" type="text" name="fieldpassword" value="'.$conf->global->LDAP_FIELD_PASSWORD.'">';
215 print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
216 print '<td align="right">&nbsp;</td>';
217 print '</tr>';
218 
219 // Password crypted
220 
221 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td><td>';
222 print '<input size="25" type="text" name="fieldpasswordcrypted" value="'.$conf->global->LDAP_FIELD_PASSWORD_CRYPTED.'">';
223 print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
224 print '<td align="right">&nbsp;</td>';
225 print '</tr>';
226 
227 // Mail
228 
229 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
230 print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
231 print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
232 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MAIL)?' checked':'')."></td>";
233 print '</tr>';
234 
235 // Phone
236 
237 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
238 print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
239 print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
240 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PHONE)?' checked':'')."></td>";
241 print '</tr>';
242 
243 // Mobile
244 
245 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
246 print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
247 print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
248 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MOBILE)?' checked':'')."></td>";
249 print '</tr>';
250 
251 // Skype
252 
253 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSkype").'</td><td>';
254 print '<input size="25" type="text" name="fieldskype" value="'.$conf->global->LDAP_FIELD_SKYPE.'">';
255 print '</td><td>'.$langs->trans("LDAPFieldSkypeExample").'</td>';
256 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_SKYPE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_SKYPE)?' checked':'')."></td>";
257 print '</tr>';
258 
259 // Fax
260 
261 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
262 print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
263 print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
264 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FAX)?' checked':'')."></td>";
265 print '</tr>';
266 
267 // Company
268 
269 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCompany").'</td><td>';
270 print '<input size="25" type="text" name="fieldcompany" value="'.$conf->global->LDAP_FIELD_COMPANY.'">';
271 print '</td><td>'.$langs->trans("LDAPFieldCompanyExample").'</td>';
272 print '<td align="right">&nbsp;</td>';
273 print '</tr>';
274 
275 // Address
276 
277 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldAddress").'</td><td>';
278 print '<input size="25" type="text" name="fieldaddress" value="'.$conf->global->LDAP_FIELD_ADDRESS.'">';
279 print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td>';
280 print '<td align="right">&nbsp;</td>';
281 print '</tr>';
282 
283 // ZIP
284 
285 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldZip").'</td><td>';
286 print '<input size="25" type="text" name="fieldzip" value="'.$conf->global->LDAP_FIELD_ZIP.'">';
287 print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td>';
288 print '<td align="right">&nbsp;</td>';
289 print '</tr>';
290 
291 // TOWN
292 
293 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTown").'</td><td>';
294 print '<input size="25" type="text" name="fieldtown" value="'.$conf->global->LDAP_FIELD_TOWN.'">';
295 print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td>';
296 print '<td align="right">&nbsp;</td>';
297 print '</tr>';
298 
299 // COUNTRY
300 
301 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCountry").'</td><td>';
302 print '<input size="25" type="text" name="fieldcountry" value="'.$conf->global->LDAP_FIELD_COUNTRY.'">';
303 print '</td><td>&nbsp;</td>';
304 print '<td align="right">&nbsp;</td>';
305 print '</tr>';
306 
307 // Title
308 
309 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTitle").'</td><td>';
310 print '<input size="25" type="text" name="fieldtitle" value="'.$conf->global->LDAP_FIELD_TITLE.'">';
311 print '</td><td>'.$langs->trans("LDAPFieldTitleExample").'</td>';
312 print '<td align="right">&nbsp;</td>';
313 print '</tr>';
314 
315 // Note
316 
317 print '<tr class="oddeven"><td>'.$langs->trans("Note").'</td><td>';
318 print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_FIELD_DESCRIPTION.'">';
319 print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
320 print '<td align="right">&nbsp;</td>';
321 print '</tr>';
322 
323 // Sid
324 
325 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSid").'</td><td>';
326 print '<input size="25" type="text" name="fieldsid" value="'.$conf->global->LDAP_FIELD_SID.'">';
327 print '</td><td>'.$langs->trans("LDAPFieldSidExample").'</td>';
328 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_SID)?' checked':'')."></td>";
329 print '</tr>';
330 
331 print '</table>';
332 
333 print info_admin($langs->trans("LDAPDescValues"));
334 
335 dol_fiche_end();
336 
337 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
338 
339 print '</form>';
340 
341 
342 /*
343  * Test de la connexion
344  */
345 if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
346 {
347  $butlabel=$langs->trans("LDAPTestSynchroUser");
348  $testlabel='testuser';
349  $key=$conf->global->LDAP_KEY_USERS;
350  $dn=$conf->global->LDAP_USER_DN;
351  $objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
352 
353  show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
354 }
355 elseif ($conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')
356 {
357  $butlabel=$langs->trans("LDAPTestSearch");
358  $testlabel='testsearchuser';
359  $key=$conf->global->LDAP_KEY_USERS;
360  $dn=$conf->global->LDAP_USER_DN;
361  $objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
362  show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
363 }
364 
365 if (function_exists("ldap_connect"))
366 {
367  if ($action == 'testuser')
368  {
369  // Creation objet
370  $object=new User($db);
371  $object->initAsSpecimen();
372 
373  // TODO Mutualize code following with other ldap_xxxx.php pages
374 
375  // Test synchro
376  $ldap=new Ldap();
377  $result=$ldap->connect_bind();
378 
379  if ($result > 0)
380  {
381  $info=$object->_load_ldap_info();
382  $dn=$object->_load_ldap_dn($info);
383 
384  $result1=$ldap->delete($dn); // To be sure to delete existing records
385  $result2=$ldap->add($dn,$info,$user); // Now the test
386  $result3=$ldap->delete($dn); // Clean what we did
387 
388  if ($result2 > 0)
389  {
390  print img_picto('','info').' ';
391  print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
392  }
393  else
394  {
395  print img_picto('','error').' ';
396  print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
397  print ': '.$ldap->error;
398  print '</font><br>';
399  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
400  }
401 
402  print "<br>\n";
403  print "LDAP input file used for test:<br><br>\n";
404  print nl2br($ldap->dump_content($dn,$info));
405  print "\n<br>";
406  }
407  else
408  {
409  print img_picto('','error').' ';
410  print '<font class="error">'.$langs->trans("LDAPSynchroKO");
411  print ': '.$ldap->error;
412  print '</font><br>';
413  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
414  }
415  }
416 
417  if ($action == 'testsearchuser')
418  {
419  // Creation objet
420  $object=new User($db);
421  $object->initAsSpecimen();
422 
423  // TODO Mutualize code following with other ldap_xxxx.php pages
424 
425  // Test synchro
426  $ldap=new Ldap();
427  $result=$ldap->connect_bind();
428 
429  if ($result > 0)
430  {
431  $required_fields = array(
432  $conf->global->LDAP_KEY_USERS,
433  $conf->global->LDAP_FIELD_FULLNAME,
434  $conf->global->LDAP_FIELD_NAME,
435  $conf->global->LDAP_FIELD_FIRSTNAME,
436  $conf->global->LDAP_FIELD_LOGIN,
437  $conf->global->LDAP_FIELD_LOGIN_SAMBA,
438  $conf->global->LDAP_FIELD_PASSWORD,
439  $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
440  $conf->global->LDAP_FIELD_PHONE,
441  $conf->global->LDAP_FIELD_FAX,
442  $conf->global->LDAP_FIELD_SKYPE,
443  $conf->global->LDAP_FIELD_MOBILE,
444  $conf->global->LDAP_FIELD_MAIL,
445  $conf->global->LDAP_FIELD_TITLE,
446  $conf->global->LDAP_FIELD_DESCRIPTION,
447  $conf->global->LDAP_FIELD_SID
448  );
449 
450  // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
451  $required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
452 
453  // Get from LDAP database an array of results
454  $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
455  //$ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, '', 1);
456 
457  if (is_array($ldapusers))
458  {
459  $liste=array();
460  foreach ($ldapusers as $key => $ldapuser)
461  {
462  // Define the label string for this user
463  $label='';
464  foreach ($required_fields as $value)
465  {
466  if ($value)
467  {
468  $label.=$value."=".$ldapuser[$value]." ";
469  }
470  }
471  $liste[$key] = $label;
472  }
473 
474  }
475  else
476  {
477  setEventMessages($ldap->error, $ldap->errors, 'errors');
478  }
479 
480  print "<br>\n";
481  print "LDAP search for user:<br>\n";
482  print "search: *<br>\n";
483  print "userDN: ".$conf->global->LDAP_USER_DN."<br>\n";
484  print "useridentifier: ".$conf->global->LDAP_KEY_USERS."<br>\n";
485  print "required_fields: ".implode(',',$required_fields)."<br>\n";
486  print "=> ".count($liste)." records<br>\n";
487  print "\n<br>";
488  }
489  else
490  {
491  print img_picto('','error').' ';
492  print '<font class="error">'.$langs->trans("LDAPSynchroKO");
493  print ': '.$ldap->error;
494  print '</font><br>';
495  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
496  }
497  }
498 }
499 
500 llxFooter();
501 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
Class to manage Dolibarr users.
Definition: user.class.php:39
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:485
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition: ldap.lib.php:106
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:91
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition: ldap.lib.php:31