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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
33{
34 global $langs, $conf, $user;
35
36 $langs->load("ldap");
37
38 // Onglets
39 $head = array();
40 $h = 0;
41
42 $head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
43 $head[$h][1] = $langs->trans("LDAPGlobalParameters");
44 $head[$h][2] = 'ldap';
45 $h++;
46
47 if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE')) {
48 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
49 $head[$h][1] = $langs->trans("LDAPUsersSynchro");
50 $head[$h][2] = 'users';
51 $h++;
52 }
53
54 if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE')) {
55 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_groups.php";
56 $head[$h][1] = $langs->trans("LDAPGroupsSynchro");
57 $head[$h][2] = 'groups';
58 $h++;
59 }
60
61 if (isModEnabled("societe") && getDolGlobalString('LDAP_CONTACT_ACTIVE')) {
62 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
63 $head[$h][1] = $langs->trans("LDAPContactsSynchro");
64 $head[$h][2] = 'contacts';
65 $h++;
66 }
67
68 if (isModEnabled('member') && getDolGlobalString('LDAP_MEMBER_ACTIVE')) {
69 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
70 $head[$h][1] = $langs->trans("LDAPMembersSynchro");
71 $head[$h][2] = 'members';
72 $h++;
73 }
74
75 if (isModEnabled('member') && getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE')) {
76 $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members_types.php";
77 $head[$h][1] = $langs->trans("LDAPMembersTypesSynchro");
78 $head[$h][2] = 'memberstypes';
79 $h++;
80 }
81
82 // Show more tabs from modules
83 // Entries must be declared in modules descriptor with line
84 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
85 // $this->tabs = array('entity:-tabname); to remove a tab
86 complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap');
87
88 complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap', 'remove');
89
90 return $head;
91}
92
103function show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
104{
105 global $langs, $conf, $user;
106 //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
107
108 print '<br>';
109 if (!function_exists("ldap_connect")) {
110 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
111 } elseif (!getDolGlobalString('LDAP_SERVER_HOST')) {
112 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPSetupNotComplete').'">'.$butlabel.'</a>';
113 } elseif (empty($key) || empty($dn) || empty($objectclass)) {
114 $langs->load("errors");
115 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
116 } else {
117 print '<a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
118 }
119 print '<br><br>';
120}
121
133function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount = 0)
134{
135 global $bc, $conf;
136
137 $count--;
138 if ($count == 0) {
139 return -1; // To stop loop
140 }
141 if (!is_array($result)) {
142 return -1;
143 }
144
145 $lastkey = array();
146
147 foreach ($result as $key => $val) {
148 if ("$key" == "objectclass") {
149 continue;
150 }
151 if ("$key" == "count") {
152 continue;
153 }
154 if ("$key" == "dn") {
155 continue;
156 }
157 if (!is_array($val) && "$val" == "objectclass") {
158 continue;
159 }
160
161 $lastkey[$level] = $key;
162
163 if (is_array($val)) {
164 $hide = 0;
165 if (!is_numeric($key)) {
166 print '<tr class="oddeven">';
167 print '<td>';
168 print $key;
169 print '</td><td>';
170 if (strtolower($key) == 'userpassword') {
171 $hide = 1;
172 }
173 }
174 show_ldap_content($val, $level + 1, $count, $var, $hide, $val["count"]);
175 } elseif ($subcount) {
176 $subcount--;
177 $newstring = dol_htmlentitiesbr($val);
178 if ($hide) {
179 print preg_replace('/./i', '*', $newstring);
180 } else {
181 print $newstring;
182 }
183 print '<br>';
184 }
185 if (!is_array($val) && "$val" != $lastkey[$level] && !$subcount) {
186 print '</td></tr>';
187 }
188 }
189 return 1;
190}
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:32
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition ldap.lib.php:103
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition ldap.lib.php:133