dolibarr 21.0.0-beta
type_ldap.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2006-2017 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
30require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
33
42// Load translation files required by the page
43$langs->loadLangs(array("admin", "members", "ldap"));
44
45$id = GETPOSTINT('rowid');
46$action = GETPOST('action', 'aZ09');
47
48// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
49$hookmanager->initHooks(array('membertypeldapcard', 'globalcard'));
50
51// Security check
52$result = restrictedArea($user, 'adherent', $id, 'adherent_type');
53
54$object = new AdherentType($db);
55$object->fetch($id);
56
57/*
58 * Actions
59 */
60
61
62$parameters = array();
63$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
64if ($reshook < 0) {
65 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
66}
67
68if (empty($reshook)) {
69 if ($action == 'dolibarr2ldap') {
70 $ldap = new Ldap();
71 $result = $ldap->connectBind();
72
73 if ($result > 0) {
74 $object->listMembersForMemberType('', 1);
75
76 $info = $object->_load_ldap_info();
77 $dn = $object->_load_ldap_dn($info);
78 $olddn = $dn; // We can say that old dn = dn as we force synchro
79
80 $result = $ldap->update($dn, $info, $user, $olddn);
81 }
82
83 if ($result >= 0) {
84 setEventMessages($langs->trans("MemberTypeSynchronized"), null, 'mesgs');
85 } else {
86 setEventMessages($ldap->error, $ldap->errors, 'errors');
87 }
88 }
89}
90
91/*
92 * View
93 */
94
95$title = $langs->trans("MembersTypeSetup");
96$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
97
98llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-type_ldap');
99
100$form = new Form($db);
101
102$head = member_type_prepare_head($object);
103
104print dol_get_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
105
106$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
107
108dol_banner_tab($object, 'rowid', $linkback);
109
110print '<div class="fichecenter">';
111print '<div class="underbanner clearboth"></div>';
112
113print '<table class="border centpercent">';
114
115// LDAP DN
116print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">' . getDolGlobalString('LDAP_MEMBER_TYPE_DN')."</td></tr>\n";
117
118// LDAP Cle
119print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">' . getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')."</td></tr>\n";
120
121// LDAP Server
122print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
123print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
124print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
125print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
126print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
127
128print '</table>';
129
130print '</div>';
131
132print dol_get_fiche_end();
133
134/*
135 * Action bar
136 */
137
138print '<div class="tabsAction">';
139
140if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
141 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
142}
143
144print "</div>\n";
145
146if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
147 print "<br>\n";
148}
149
150
151
152// Display LDAP attributes
153print load_fiche_titre($langs->trans("LDAPInformationsForThisMemberType"));
154
155print '<table width="100%" class="noborder">';
156
157print '<tr class="liste_titre">';
158print '<td>'.$langs->trans("LDAPAttributes").'</td>';
159print '<td>'.$langs->trans("Value").'</td>';
160print '</tr>';
161
162// LDAP reading
163$ldap = new Ldap();
164$result = $ldap->connectBind();
165if ($result > 0) {
166 $info = $object->_load_ldap_info();
167 $dn = $object->_load_ldap_dn($info, 1);
168 $search = "(".$object->_load_ldap_dn($info, 2).")";
169
170 $records = $ldap->getAttribute($dn, $search);
171
172 //print_r($records);
173
174 // Show tree
175 if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
176 if (!is_array($records)) {
177 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
178 } else {
179 $result = show_ldap_content($records, 0, $records['count'], true);
180 }
181 } else {
182 print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
183 }
184
185 $ldap->unbind();
186} else {
187 setEventMessages($ldap->error, $ldap->errors, 'errors');
188}
189
190print '</table>';
191
192// End of page
193llxFooter();
194$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage members type.
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a 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:134
member_type_prepare_head(AdherentType $object)
Return array head with list of tabs to view object information.
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.