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