dolibarr  7.0.0-beta
ldap.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  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
31 
32 $langs->load("companies");
33 $langs->load("members");
34 $langs->load("ldap");
35 $langs->load("admin");
36 
37 $rowid = GETPOST('id','int');
38 $action = GETPOST('action','aZ09');
39 
40 // Protection
41 $socid=0;
42 if ($user->societe_id > 0)
43 {
44  $socid = $user->societe_id;
45 }
46 
47 $object = new Adherent($db);
48 $result=$object->fetch($rowid);
49 if (! $result)
50 {
51  dol_print_error($db,"Failed to get adherent: ".$object->error);
52  exit;
53 }
54 
55 
56 /*
57  * Actions
58  */
59 
60 if ($action == 'dolibarr2ldap')
61 {
62  $ldap=new Ldap();
63  $result=$ldap->connect_bind();
64 
65  if ($result > 0)
66  {
67  $info=$object->_load_ldap_info();
68  $dn=$object->_load_ldap_dn($info);
69  $olddn=$dn; // We can say that old dn = dn as we force synchro
70 
71  $result=$ldap->update($dn,$info,$user,$olddn);
72  }
73 
74  if ($result >= 0) {
75  setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
76  }
77  else {
78  setEventMessages($ldap->errors, $ldap->error, 'errors');
79  }
80 }
81 
82 
83 
84 /*
85  * View
86  */
87 
88 llxHeader('',$langs->trans("Member"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
89 
90 $form = new Form($db);
91 
92 $head = member_prepare_head($object);
93 
94 dol_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
95 
96 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
97 
98 dol_banner_tab($object, 'rowid', $linkback);
99 
100 print '<div class="fichecenter">';
101 
102 print '<div class="underbanner clearboth"></div>';
103 print '<table class="border centpercent">';
104 
105 // Login
106 print '<tr><td class="titlefield">'.$langs->trans("Login").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
107 
108 // Password not crypted
109 if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD))
110 {
111  print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
112  print '<td class="valeur">'.$object->pass.'</td>';
113  print "</tr>\n";
114 }
115 
116 // Password crypted
117 if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED))
118 {
119  print '<tr><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td>';
120  print '<td class="valeur">'.$object->pass_crypted.'</td>';
121  print "</tr>\n";
122 }
123 
124 // Type
125 print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$object->type."</td></tr>\n";
126 
127 $langs->load("admin");
128 
129 // LDAP DN
130 print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_DN."</td></tr>\n";
131 
132 // LDAP Cle
133 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS."</td></tr>\n";
134 
135 // LDAP Server
136 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
137 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
138 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
139 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
140 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
141 
142 print '</table>';
143 
144 print '</div>';
145 
146 dol_fiche_end();
147 
148 /*
149  * Barre d'actions
150  */
151 
152 print '<div class="tabsAction">';
153 
154 if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr')
155 {
156  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
157 }
158 
159 print "</div>\n";
160 
161 if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr') print "<br>\n";
162 
163 
164 
165 // Affichage attributs LDAP
166 print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
167 
168 print '<table width="100%" class="noborder">';
169 
170 print '<tr class="liste_titre">';
171 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
172 print '<td>'.$langs->trans("Value").'</td>';
173 print '</tr>';
174 
175 // Lecture LDAP
176 $ldap=new Ldap();
177 $result=$ldap->connect_bind();
178 if ($result > 0)
179 {
180  $info=$object->_load_ldap_info();
181  $dn=$object->_load_ldap_dn($info,1);
182  $search = "(".$object->_load_ldap_dn($info,2).")";
183 
184  if (empty($dn))
185  {
186  $langs->load("errors");
187  print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorModuleSetupNotComplete").'</font></td></tr>';
188  }
189  else
190  {
191  $records = $ldap->getAttribute($dn,$search);
192 
193  //print_r($records);
194 
195  // Affichage arbre
196  if ((! is_numeric($records) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
197  {
198  if (! is_array($records))
199  {
200  print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
201  }
202  else
203  {
204  $result=show_ldap_content($records,0,$records['count'],true);
205  }
206  }
207  else
208  {
209  print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
210  }
211  }
212 
213  $ldap->unbind();
214  $ldap->close();
215 }
216 else
217 {
218  setEventMessages($ldap->error, $ldap->errors, 'errors');
219 }
220 
221 
222 print '</table>';
223 
224 llxFooter();
225 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:33
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
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
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Class to manage members of a foundation.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:91