dolibarr  20.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-2021 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 // Load Dolibarr environment
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("companies", "members", "ldap", "admin"));
35 
36 $id = GETPOSTINT('id');
37 $ref = GETPOST('ref', 'alphanohtml');
38 $action = GETPOST('action', 'aZ09');
39 
40 // Protection
41 $socid = 0;
42 if ($user->socid > 0) {
43  $socid = $user->socid;
44 }
45 
46 $object = new Adherent($db);
47 
48 // Fetch object
49 if ($id > 0 || !empty($ref)) {
50  // Load member
51  $result = $object->fetch($id, $ref);
52 
53  // Define variables to know what current user can do on users
54  $canadduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer'));
55  // Define variables to know what current user can do on properties of user linked to edited member
56  if ($object->user_id) {
57  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
58  $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer'))
59  || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer')));
60  $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password'))
61  || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password')));
62  }
63 }
64 
65 // Define variables to determine what the current user can do on the members
66 $canaddmember = $user->hasRight('adherent', 'creer');
67 // Define variables to determine what the current user can do on the properties of a member
68 if ($id) {
69  $caneditfieldmember = $user->hasRight('adherent', 'creer');
70 }
71 
72 // Security check
73 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
74 
75 
76 /*
77  * Actions
78  */
79 
80 if ($action == 'dolibarr2ldap') {
81  $ldap = new Ldap();
82  $result = $ldap->connectBind();
83 
84  if ($result > 0) {
85  $info = $object->_load_ldap_info();
86  $dn = $object->_load_ldap_dn($info);
87  $olddn = $dn; // We can say that old dn = dn as we force synchro
88 
89  $result = $ldap->update($dn, $info, $user, $olddn);
90  }
91 
92  if ($result >= 0) {
93  setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
94  } else {
95  setEventMessages($ldap->error, $ldap->errors, 'errors');
96  }
97 }
98 
99 
100 
101 /*
102  * View
103  */
104 
105 $form = new Form($db);
106 
107 llxHeader('', $langs->trans("Member"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder');
108 
110 
111 print dol_get_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
112 
113 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
114 
115 dol_banner_tab($object, 'rowid', $linkback);
116 
117 print '<div class="fichecenter">';
118 
119 print '<div class="underbanner clearboth"></div>';
120 print '<table class="border centpercent tableforfield">';
121 
122 // Login
123 print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'&nbsp;</td></tr>';
124 
125 // If there is a link to the unencrypted password, we show the value in database here so we can compare because it is shown nowhere else
126 // This is for very old situation. Password are now encrypted and $object->pass is empty.
127 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
128  print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
129  print '<td class="valeur">'.dol_escape_htmltag($object->pass).'</td>';
130  print "</tr>\n";
131 }
132 
133 $adht = new AdherentType($db);
134 $adht->fetch($object->typeid);
135 
136 // Type
137 print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
138 
139 // LDAP DN
140 print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_MEMBER_DN')."</td></tr>\n";
141 
142 // LDAP Cle
143 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_MEMBERS')."</td></tr>\n";
144 
145 // LDAP Server
146 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
147 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
148 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
149 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
150 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
151 
152 print '</table>';
153 
154 print '</div>';
155 
156 print dol_get_fiche_end();
157 
158 /*
159  * Action bar
160  */
161 print '<div class="tabsAction">';
162 
163 if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
164  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
165 }
166 
167 print "</div>\n";
168 
169 if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
170  print "<br>\n";
171 }
172 
173 
174 
175 // Affichage attributes LDAP
176 print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
177 
178 print '<table width="100%" class="noborder">';
179 
180 print '<tr class="liste_titre">';
181 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
182 print '<td>'.$langs->trans("Value").'</td>';
183 print '</tr>';
184 
185 // Lecture LDAP
186 $ldap = new Ldap();
187 $result = $ldap->connectBind();
188 if ($result > 0) {
189  $info = $object->_load_ldap_info();
190  $dn = $object->_load_ldap_dn($info, 1);
191  $search = "(".$object->_load_ldap_dn($info, 2).")";
192 
193  if (empty($dn)) {
194  $langs->load("errors");
195  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Member")).'</span></td></tr>';
196  } else {
197  $records = $ldap->getAttribute($dn, $search);
198 
199  //print_r($records);
200 
201  // Show tree
202  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
203  if (!is_array($records)) {
204  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
205  } else {
206  $result = show_ldap_content($records, 0, $records['count'], true);
207  }
208  } else {
209  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
210  }
211  }
212 
213  $ldap->unbind();
214 } else {
215  setEventMessages($ldap->error, $ldap->errors, 'errors');
216 }
217 
218 
219 print '</table>';
220 
221 // End of page
222 llxFooter();
223 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage members of a foundation.
Class to manage members type.
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
Definition: ldap.class.php:37
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition: ldap.lib.php:132
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object information.
Definition: member.lib.php:34
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.