dolibarr  13.0.2
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-2017 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  {
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 (!empty($conf->global->LDAP_SYNCHRO_ACTIVE))
55  {
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 (!empty($conf->societe->enabled) && !empty($conf->global->LDAP_CONTACT_ACTIVE))
63  {
64  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
65  $head[$h][1] = $langs->trans("LDAPContactsSynchro");
66  $head[$h][2] = 'contacts';
67  $h++;
68  }
69 
70  if (!empty($conf->adherent->enabled) && !empty($conf->global->LDAP_MEMBER_ACTIVE))
71  {
72  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
73  $head[$h][1] = $langs->trans("LDAPMembersSynchro");
74  $head[$h][2] = 'members';
75  $h++;
76  }
77 
78  if (!empty($conf->adherent->enabled) && !empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE))
79  {
80  $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members_types.php";
81  $head[$h][1] = $langs->trans("LDAPMembersTypesSynchro");
82  $head[$h][2] = 'memberstypes';
83  $h++;
84  }
85 
86  // Show more tabs from modules
87  // Entries must be declared in modules descriptor with line
88  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
89  // $this->tabs = array('entity:-tabname); to remove a tab
90  complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap');
91 
92  complete_head_from_modules($conf, $langs, null, $head, $h, 'ldap', 'remove');
93 
94  return $head;
95 }
96 
97 
108 function show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
109 {
110  global $langs, $conf, $user;
111  //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
112 
113  print '<br>';
114  if (!function_exists("ldap_connect"))
115  {
116  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
117  } elseif (empty($conf->global->LDAP_SERVER_HOST))
118  {
119  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('LDAPSetupNotComplete').'">'.$butlabel.'</a>';
120  } elseif (empty($key) || empty($dn) || empty($objectclass))
121  {
122  $langs->load("errors");
123  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
124  } else {
125  print '<a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
126  }
127  print '<br><br>';
128 }
129 
130 
142 function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount = 0)
143 {
144  global $bc, $conf;
145 
146  $count--;
147  if ($count == 0) return -1; // To stop loop
148  if (!is_array($result)) return -1;
149 
150  foreach ($result as $key => $val)
151  {
152  if ("$key" == "objectclass") continue;
153  if ("$key" == "count") continue;
154  if ("$key" == "dn") continue;
155  if ("$val" == "objectclass") continue;
156 
157  $lastkey[$level] = $key;
158 
159  if (is_array($val))
160  {
161  $hide = 0;
162  if (!is_numeric($key))
163  {
164  print '<tr class="oddeven">';
165  print '<td>';
166  print $key;
167  print '</td><td>';
168  if (strtolower($key) == 'userpassword') $hide = 1;
169  }
170  show_ldap_content($val, $level + 1, $count, $var, $hide, $val["count"]);
171  } elseif ($subcount)
172  {
173  $subcount--;
174  $newstring = dol_htmlentitiesbr($val);
175  if ($hide) print preg_replace('/./i', '*', $newstring);
176  else print $newstring;
177  print '<br>';
178  }
179  if ("$val" != $lastkey[$level] && !$subcount) print '</td></tr>';
180  }
181  return 1;
182 }
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...
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition: ldap.lib.php:108
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition: ldap.lib.php:142
print
Draft customers invoices.
Definition: index.php:89
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition: ldap.lib.php:31
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).