dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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 * or see https://www.gnu.org/
20 */
21
34{
35 global $langs, $conf, $user;
36
37 $langs->load("ldap");
38
39 // Onglets
40 $head = array();
41 $h = 0;
42
43 $head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
44 $head[$h][1] = $langs->trans("LDAPGlobalParameters");
45 $head[$h][2] = 'ldap';
46 $h++;
47
48 if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE')) {
49 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
50 $head[$h][1] = $langs->trans("LDAPUsersSynchro");
51 $head[$h][2] = 'users';
52 $h++;
53 }
54
55 if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE')) {
56 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_groups.php";
57 $head[$h][1] = $langs->trans("LDAPGroupsSynchro");
58 $head[$h][2] = 'groups';
59 $h++;
60 }
61
62 if (isModEnabled("societe") && getDolGlobalString('LDAP_CONTACT_ACTIVE')) {
63 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
64 $head[$h][1] = $langs->trans("LDAPContactsSynchro");
65 $head[$h][2] = 'contacts';
66 $h++;
67 }
68
69 if (isModEnabled('member') && getDolGlobalString('LDAP_MEMBER_ACTIVE')) {
70 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
71 $head[$h][1] = $langs->trans("LDAPMembersSynchro");
72 $head[$h][2] = 'members';
73 $h++;
74 }
75
76 if (isModEnabled('member') && getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE')) {
77 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members_types.php";
78 $head[$h][1] = $langs->trans("LDAPMembersTypesSynchro");
79 $head[$h][2] = 'memberstypes';
80 $h++;
81 }
82
83 // Show more tabs from modules
84 // Entries must be declared in modules descriptor with line
85 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
86 // $this->tabs = array('entity:-tabname); to remove a tab
87 complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap');
88
89 complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap', 'remove');
90
91 return $head;
92}
93
104function show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
105{
106 global $langs, $conf, $user;
107 //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
108
109 print '<br>';
110 if (!function_exists("ldap_connect")) {
111 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
112 } elseif (!getDolGlobalString('LDAP_SERVER_HOST')) {
113 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPSetupNotComplete').'">'.$butlabel.'</a>';
114 } elseif (empty($key) || empty($dn) || empty($objectclass)) {
115 $langs->load("errors");
116 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
117 } else {
118 print '<a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
119 }
120 print '<br><br>';
121}
122
134function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount = 0)
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 $lastkey = array();
145
146 foreach ($result as $key => $val) {
147 if ("$key" == "objectclass") {
148 continue;
149 }
150 if ("$key" == "count") {
151 continue;
152 }
153 if ("$key" == "dn") {
154 continue;
155 }
156 if (!is_array($val) && "$val" == "objectclass") {
157 continue;
158 }
159
160 $lastkey[$level] = $key;
161
162 if (is_array($val)) {
163 $hide = 0;
164 if (!is_numeric($key)) {
165 print '<tr class="oddeven">';
166 print '<td>';
167 print $key;
168 print '</td><td>';
169 if (strtolower($key) == 'userpassword') {
170 $hide = 1;
171 }
172 }
173 show_ldap_content($val, $level + 1, $count, $var, $hide, $val["count"]);
174 } elseif ($subcount) {
175 $subcount--;
176 $newstring = dol_htmlentitiesbr($val);
177 if ($hide) {
178 print preg_replace('/./i', '*', $newstring);
179 } else {
180 print $newstring;
181 }
182 print '<br>';
183 }
184 if (!is_array($val) && "$val" != $lastkey[$level] && !$subcount) {
185 print '</td></tr>';
186 }
187 }
188 return 1;
189}
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition ldap.lib.php:33
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition ldap.lib.php:104
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