dolibarr 21.0.0-alpha
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 *
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
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
29require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array("admin", "members", "ldap"));
35
36$id = GETPOSTINT('rowid');
37$action = GETPOST('action', 'aZ09');
38
39// Security check
40$result = restrictedArea($user, 'adherent', $id, 'adherent_type');
41
42$object = new AdherentType($db);
43$object->fetch($id);
44
45// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
46$hookmanager->initHooks(array('membertypeldapcard', 'globalcard'));
47
48/*
49 * Actions
50 */
51
52
53$parameters = array();
54$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
55if ($reshook < 0) {
56 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
57}
58
59if (empty($reshook)) {
60 if ($action == 'dolibarr2ldap') {
61 $ldap = new Ldap();
62 $result = $ldap->connectBind();
63
64 if ($result > 0) {
65 $object->listMembersForMemberType('', 1);
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("MemberTypeSynchronized"), null, 'mesgs');
76 } else {
77 setEventMessages($ldap->error, $ldap->errors, 'errors');
78 }
79 }
80}
81
82/*
83 * View
84 */
85
86$title = $langs->trans("MembersTypeSetup");
87$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
88
89llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-type_ldap');
90
91$form = new Form($db);
92
93$head = member_type_prepare_head($object);
94
95print dol_get_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
96
97$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
98
99dol_banner_tab($object, 'rowid', $linkback);
100
101print '<div class="fichecenter">';
102print '<div class="underbanner clearboth"></div>';
103
104print '<table class="border centpercent">';
105
106// LDAP DN
107print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">' . getDolGlobalString('LDAP_MEMBER_TYPE_DN')."</td></tr>\n";
108
109// LDAP Cle
110print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">' . getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')."</td></tr>\n";
111
112// LDAP Server
113print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
114print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
115print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
116print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
117print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">' . getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
118
119print '</table>';
120
121print '</div>';
122
123print dol_get_fiche_end();
124
125/*
126 * Action bar
127 */
128
129print '<div class="tabsAction">';
130
131if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
132 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
133}
134
135print "</div>\n";
136
137if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
138 print "<br>\n";
139}
140
141
142
143// Display LDAP attributes
144print load_fiche_titre($langs->trans("LDAPInformationsForThisMemberType"));
145
146print '<table width="100%" class="noborder">';
147
148print '<tr class="liste_titre">';
149print '<td>'.$langs->trans("LDAPAttributes").'</td>';
150print '<td>'.$langs->trans("Value").'</td>';
151print '</tr>';
152
153// LDAP reading
154$ldap = new Ldap();
155$result = $ldap->connectBind();
156if ($result > 0) {
157 $info = $object->_load_ldap_info();
158 $dn = $object->_load_ldap_dn($info, 1);
159 $search = "(".$object->_load_ldap_dn($info, 2).")";
160
161 $records = $ldap->getAttribute($dn, $search);
162
163 //print_r($records);
164
165 // Show tree
166 if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
167 if (!is_array($records)) {
168 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
169 } else {
170 $result = show_ldap_content($records, 0, $records['count'], true);
171 }
172 } else {
173 print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
174 }
175
176 $ldap->unbind();
177} else {
178 setEventMessages($ldap->error, $ldap->errors, 'errors');
179}
180
181print '</table>';
182
183// End of page
184llxFooter();
185$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage members type.
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
llxFooter()
Footer empty.
Definition document.php:107
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.
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.
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_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.