dolibarr  19.0.0-dev
ldap.lib.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  * or see https://www.gnu.org/
18  */
19 
32 {
33  global $langs, $conf, $user;
34 
35  $langs->load("ldap");
36 
37  // Onglets
38  $head = array();
39  $h = 0;
40 
41  $head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
42  $head[$h][1] = $langs->trans("LDAPGlobalParameters");
43  $head[$h][2] = 'ldap';
44  $h++;
45 
46  if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE)) {
47  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
48  $head[$h][1] = $langs->trans("LDAPUsersSynchro");
49  $head[$h][2] = 'users';
50  $h++;
51  }
52 
53  if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE)) {
54  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_groups.php";
55  $head[$h][1] = $langs->trans("LDAPGroupsSynchro");
56  $head[$h][2] = 'groups';
57  $h++;
58  }
59 
60  if (isModEnabled("societe") && !empty($conf->global->LDAP_CONTACT_ACTIVE)) {
61  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
62  $head[$h][1] = $langs->trans("LDAPContactsSynchro");
63  $head[$h][2] = 'contacts';
64  $h++;
65  }
66 
67  if (isModEnabled('adherent') && !empty($conf->global->LDAP_MEMBER_ACTIVE)) {
68  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
69  $head[$h][1] = $langs->trans("LDAPMembersSynchro");
70  $head[$h][2] = 'members';
71  $h++;
72  }
73 
74  if (isModEnabled('adherent') && !empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE)) {
75  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members_types.php";
76  $head[$h][1] = $langs->trans("LDAPMembersTypesSynchro");
77  $head[$h][2] = 'memberstypes';
78  $h++;
79  }
80 
81  // Show more tabs from modules
82  // Entries must be declared in modules descriptor with line
83  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
84  // $this->tabs = array('entity:-tabname); to remove a tab
85  complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap');
86 
87  complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap', 'remove');
88 
89  return $head;
90 }
91 
102 function show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
103 {
104  global $langs, $conf, $user;
105  //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
106 
107  print '<br>';
108  if (!function_exists("ldap_connect")) {
109  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
110  } elseif (empty($conf->global->LDAP_SERVER_HOST)) {
111  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPSetupNotComplete').'">'.$butlabel.'</a>';
112  } elseif (empty($key) || empty($dn) || empty($objectclass)) {
113  $langs->load("errors");
114  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
115  } else {
116  print '<a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
117  }
118  print '<br><br>';
119 }
120 
132 function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount = 0)
133 {
134  global $bc, $conf;
135 
136  $count--;
137  if ($count == 0) {
138  return -1; // To stop loop
139  }
140  if (!is_array($result)) {
141  return -1;
142  }
143 
144  foreach ($result as $key => $val) {
145  if ("$key" == "objectclass") {
146  continue;
147  }
148  if ("$key" == "count") {
149  continue;
150  }
151  if ("$key" == "dn") {
152  continue;
153  }
154  if (!is_array($val) && "$val" == "objectclass") {
155  continue;
156  }
157 
158  $lastkey[$level] = $key;
159 
160  if (is_array($val)) {
161  $hide = 0;
162  if (!is_numeric($key)) {
163  print '<tr class="oddeven">';
164  print '<td>';
165  print $key;
166  print '</td><td>';
167  if (strtolower($key) == 'userpassword') {
168  $hide = 1;
169  }
170  }
171  show_ldap_content($val, $level + 1, $count, $var, $hide, $val["count"]);
172  } elseif ($subcount) {
173  $subcount--;
174  $newstring = dol_htmlentitiesbr($val);
175  if ($hide) {
176  print preg_replace('/./i', '*', $newstring);
177  } else {
178  print $newstring;
179  }
180  print '<br>';
181  }
182  if (!is_array($val) && "$val" != $lastkey[$level] && !$subcount) {
183  print '</td></tr>';
184  }
185  }
186  return 1;
187 }
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition: ldap.lib.php:31
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition: ldap.lib.php:102
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