dolibarr  13.0.2
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 <https://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->socid > 0) {
41  $socid = $user->socid;
42 }
43 
44 $object = new Adherent($db);
45 $result = $object->fetch($rowid);
46 if (!$result) {
47  dol_print_error($db, "Failed to get adherent: ".$object->error);
48  exit;
49 }
50 
51 
52 /*
53  * Actions
54  */
55 
56 if ($action == 'dolibarr2ldap') {
57  $ldap = new Ldap();
58  $result = $ldap->connect_bind();
59 
60  if ($result > 0) {
61  $info = $object->_load_ldap_info();
62  $dn = $object->_load_ldap_dn($info);
63  $olddn = $dn; // We can say that old dn = dn as we force synchro
64 
65  $result = $ldap->update($dn, $info, $user, $olddn);
66  }
67 
68  if ($result >= 0) {
69  setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
70  } else {
71  setEventMessages($ldap->error, $ldap->errors, 'errors');
72  }
73 }
74 
75 
76 
77 /*
78  * View
79  */
80 
81 $form = new Form($db);
82 
83 llxHeader('', $langs->trans("Member"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
84 
85 $head = member_prepare_head($object);
86 
87 print dol_get_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
88 
89 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
90 
91 dol_banner_tab($object, 'rowid', $linkback);
92 
93 print '<div class="fichecenter">';
94 
95 print '<div class="underbanner clearboth"></div>';
96 print '<table class="border centpercent tableforfield">';
97 
98 // Login
99 print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
100 
101 // If there is a link to password not crypted, we show value in database here so we can compare because it is shown nowhere else
102 if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
103  print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
104  print '<td class="valeur">'.$object->pass.'</td>';
105  print "</tr>\n";
106 }
107 
108 $adht = new AdherentType($db);
109 $adht->fetch($object->typeid);
110 
111 // Type
112 print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
113 
114 // LDAP DN
115 print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_DN."</td></tr>\n";
116 
117 // LDAP Cle
118 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS."</td></tr>\n";
119 
120 // LDAP Server
121 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
122 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
123 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
124 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
125 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
126 
127 print '</table>';
128 
129 print '</div>';
130 
132 
133 /*
134  * Barre d'actions
135  */
136 
137 print '<div class="tabsAction">';
138 
139 if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr') {
140  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
141 }
142 
143 print "</div>\n";
144 
145 if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr') print "<br>\n";
146 
147 
148 
149 // Affichage attributs LDAP
150 print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
151 
152 print '<table width="100%" class="noborder">';
153 
154 print '<tr class="liste_titre">';
155 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
156 print '<td>'.$langs->trans("Value").'</td>';
157 print '</tr>';
158 
159 // Lecture LDAP
160 $ldap = new Ldap();
161 $result = $ldap->connect_bind();
162 if ($result > 0) {
163  $info = $object->_load_ldap_info();
164  $dn = $object->_load_ldap_dn($info, 1);
165  $search = "(".$object->_load_ldap_dn($info, 2).")";
166 
167  if (empty($dn)) {
168  $langs->load("errors");
169  print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Member")).'</font></td></tr>';
170  } else {
171  $records = $ldap->getAttribute($dn, $search);
172 
173  //print_r($records);
174 
175  // Show tree
176  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
177  if (!is_array($records)) {
178  print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
179  } else {
180  $result = show_ldap_content($records, 0, $records['count'], true);
181  }
182  } else {
183  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
184  }
185  }
186 
187  $ldap->unbind();
188  $ldap->close();
189 } else {
190  setEventMessages($ldap->error, $ldap->errors, 'errors');
191 }
192 
193 
194 print '</table>';
195 
196 // End of page
197 llxFooter();
198 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:33
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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:142
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage members of a foundation.
Class to manage members type.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer 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.
llxFooter()
Empty footer.
Definition: wrapper.php:59