dolibarr 21.0.0-beta
ldap_members_types.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
7 * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
34require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('admin', 'errors'));
48
49if (!$user->admin) {
51}
52
53$action = GETPOST('action', 'aZ09');
54
55
56/*
57 * Actions
58 */
59
60if ($action == 'setvalue' && $user->admin) {
61 $error = 0;
62 $db->begin();
63
64 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_DN', GETPOST("membertype"), 'chaine', 0, '', $conf->entity)) {
65 $error++;
66 }
67 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_OBJECT_CLASS', GETPOST("objectclass"), 'chaine', 0, '', $conf->entity)) {
68 $error++;
69 }
70
71 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_FULLNAME', GETPOST("fieldfullname"), 'chaine', 0, '', $conf->entity)) {
72 $error++;
73 }
74 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_DESCRIPTION', GETPOST("fielddescription"), 'chaine', 0, '', $conf->entity)) {
75 $error++;
76 }
77 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS', GETPOST("fieldmembertypemembers"), 'chaine', 0, '', $conf->entity)) {
78 $error++;
79 }
80
81 // This one must be after the others
82 $valkey = '';
83 $key = GETPOST("key");
84 if ($key) {
85 $valkey = getDolGlobalString($key);
86 }
87 if (!dolibarr_set_const($db, 'LDAP_KEY_MEMBERS_TYPES', $valkey, 'chaine', 0, '', $conf->entity)) {
88 $error++;
89 }
90
91 if (!$error) {
92 $db->commit();
93 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
94 } else {
95 $db->rollback();
96 dol_print_error($db);
97 }
98}
99
100
101
102/*
103 * View
104 */
105
106llxHeader('', $langs->trans("LDAPSetup"), 'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP', '', 0, 0, '', '', '', 'mod-admin page-ldap_members_types');
107$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
108
109print load_fiche_titre($langs->trans("LDAPSetup"), $linkback, 'title_setup');
110
111$head = ldap_prepare_head();
112
113// Test if the LDAP functions are enabled
114if (!function_exists("ldap_connect")) {
115 setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
116}
117
118print dol_get_fiche_head($head, 'memberstypes', '', -1);
119
120
121print '<span class="opacitymedium">'.$langs->trans("LDAPDescMembersTypes").'</span><br>';
122print '<br>';
123
124
125print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?action=setvalue&token='.newToken().'">';
126print '<input type="hidden" name="token" value="'.newToken().'">';
127
128$form = new Form($db);
129
130print '<table class="noborder centpercent">';
131
132print '<tr class="liste_titre">';
133print '<td colspan="4">'.$langs->trans("LDAPSynchronizeMembersTypes").'</td>';
134print "</tr>\n";
135
136// DN pour les types de membres
137print '<!-- LDAP_MEMBER_TYPE_DN -->';
138print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeDn").'</span></td><td>';
139print '<input size="48" type="text" name="membertype" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_DN').'">';
140print '</td><td>'.$langs->trans("LDAPMemberTypepDnExample").'</td>';
141print '<td>&nbsp;</td>';
142print '</tr>';
143
144// List of object class used to define attributes in structure
145print '<!-- LDAP_MEMBER_TYPE_OBJECT_CLASS -->';
146print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeObjectClassList").'</span></td><td>';
147print '<input size="48" type="text" name="objectclass" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS').'">';
148print '</td><td>'.$langs->trans("LDAPMemberTypeObjectClassListExample").'</td>';
149print '<td>&nbsp;</td>';
150print '</tr>';
151
152print '</table>';
153
154print '<br>';
155
156print '<table class="noborder centpercent">';
157
158print '<tr class="liste_titre">';
159print '<td>'.$langs->trans("LDAPDolibarrMapping").'</td>';
160print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
161print '<td class="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
162print "</tr>\n";
163
164// Filtre
165
166// Common name
167print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
168print '<input size="25" type="text" name="fieldfullname" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME').'">';
169print '</td><td>'.$langs->trans("LDAPFieldCommonNameExample").'</td>';
170print '<td class="right"><input type="radio" name="key" value="LDAP_MEMBER_TYPE_FIELD_FULLNAME"'.(($conf->global->LDAP_KEY_MEMBERS_TYPES && $conf->global->LDAP_KEY_MEMBERS_TYPES == $conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME) ? ' checked' : '')."></td>";
171print '</tr>';
172
173// Description
174print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldDescription").'</td><td>';
175print '<input size="25" type="text" name="fielddescription" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION').'">';
176print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
177print '<td class="right"><input type="radio" name="key" value="LDAP_MEMBER_TYPE_FIELD_DESCRIPTION"'.(($conf->global->LDAP_KEY_MEMBERS_TYPES && $conf->global->LDAP_KEY_MEMBER_TYPES == $conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION) ? ' checked' : '')."></td>";
178print '</tr>';
179
180// User group
181print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupMembers").'</td><td>';
182print '<input size="25" type="text" name="fieldmembertypemembers" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS').'">';
183print '</td><td>'.$langs->trans("LDAPFieldGroupMembersExample").'</td>';
184print '<td class="right"><input type="radio" name="key" value="LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS"'.(($conf->global->LDAP_KEY_MEMBERS_TYPES && $conf->global->LDAP_KEY_MEMBERS_TYPES == $conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS) ? ' checked' : '')."></td>";
185print '</tr>';
186
187print '</table>';
188
189print info_admin($langs->trans("LDAPDescValues"));
190
191print dol_get_fiche_end();
192
193print $form->buttonsSaveCancel("Modify", '');
194
195print '</form>';
196
197
198/*
199 * Test de la connection
200 */
201if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
202 $butlabel = $langs->trans("LDAPTestSynchroMemberType");
203 $testlabel = 'testmembertype';
204 $key = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES');
205 $dn = getDolGlobalString('LDAP_MEMBER_TYPE_DN');
206 $objectclass = getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS');
207
208 show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass);
209}
210
211if (function_exists("ldap_connect")) {
212 if ($action == 'testmembertype') {
213 // Create object
214 $object = new AdherentType($db);
215 $object->initAsSpecimen();
216
217 // Test synchro
218 $ldap = new Ldap();
219 $result = $ldap->connectBind();
220
221 if ($result > 0) {
222 $info = $object->_load_ldap_info();
223 $dn = $object->_load_ldap_dn($info);
224
225 // Get a gid number for objectclass PosixGroup
226 if (in_array('posixGroup', $info['objectclass'])) {
227 $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPES');
228 }
229
230 $result1 = $ldap->delete($dn); // To be sure to delete existing records
231 $result2 = $ldap->add($dn, $info, $user); // Now the test
232 $result3 = $ldap->delete($dn); // Clean what we did
233
234 if ($result2 > 0) {
235 print img_picto('', 'info').' ';
236 print '<span class="ok">'.$langs->trans("LDAPSynchroOK").'</span><br>';
237 } else {
238 print img_picto('', 'error').' ';
239 print '<span class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
240 print ': '.$ldap->error;
241 print '</span><br>';
242 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
243 }
244
245 print "<br>\n";
246 print "LDAP input file used for test:<br><br>\n";
247 print nl2br($ldap->dumpContent($dn, $info));
248 print "\n<br>";
249 } else {
250 print img_picto('', 'error').' ';
251 print '<span class="error">'.$langs->trans("LDAPSynchroKO");
252 print ': '.$ldap->error;
253 print '</span><br>';
254 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
255 }
256 }
257}
258
259// End of page
260llxFooter();
261$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition ldap.lib.php:33
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition ldap.lib.php:104
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.