dolibarr  20.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  *
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 (getDolGlobalString('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 (getDolGlobalString('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") && getDolGlobalString('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('member') && getDolGlobalString('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('member') && getDolGlobalString('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 (!getDolGlobalString('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  $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 dolibarr global constant string value.
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