dolibarr  7.0.0-beta
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@capnetworks.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 <http://www.gnu.org/licenses/>.
17  * or see http://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,'',$head,$h,'ldap');
91 
92  return $head;
93 }
94 
95 
106 function show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass)
107 {
108  global $langs, $conf, $user;
109  //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
110 
111  print '<br>';
112  if (! function_exists("ldap_connect"))
113  {
114  print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
115  }
116  else if (empty($conf->global->LDAP_SERVER_HOST))
117  {
118  print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPSetupNotComplete').'">'.$butlabel.'</a>';
119  }
120  else if (empty($key) || empty($dn) || empty($objectclass))
121  {
122  $langs->load("errors");
123  print '<a class="butActionRefused" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
124  }
125  else
126  {
127  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
128  }
129  print '<br><br>';
130 }
131 
132 
144 function show_ldap_content($result,$level,$count,$var,$hide=0,$subcount=0)
145 {
146  global $bc, $conf;
147 
148  $count--;
149  if ($count == 0) return -1; // To stop loop
150  if (! is_array($result)) return -1;
151 
152  foreach($result as $key => $val)
153  {
154  if ("$key" == "objectclass") continue;
155  if ("$key" == "count") continue;
156  if ("$key" == "dn") continue;
157  if ("$val" == "objectclass") continue;
158 
159  $lastkey[$level]=$key;
160 
161  if (is_array($val))
162  {
163  $hide=0;
164  if (! is_numeric($key))
165  {
166 
167  print '<tr '.$bc[$var].' valign="top">';
168  print '<td>';
169  print $key;
170  print '</td><td>';
171  if (strtolower($key) == 'userpassword') $hide=1;
172  }
173  show_ldap_content($val,$level+1,$count,$var,$hide,$val["count"]);
174  }
175  else if ($subcount)
176  {
177  $subcount--;
178  $newstring=dol_htmlentitiesbr($val);
179  if ($hide) print preg_replace('/./i','*',$newstring);
180  else print $newstring;
181  print '<br>';
182  }
183  if ("$val" != $lastkey[$level] && !$subcount) print '</td></tr>';
184  }
185  return 1;
186 }
187 
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition: ldap.lib.php:106
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition: ldap.lib.php:144
print
Draft customers invoices.
Definition: index.php:91
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...
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition: ldap.lib.php:31