dolibarr 20.0.0
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
33require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
36
37// Load translation files required by the page
38$langs->loadLangs(array('admin', 'errors'));
39
40if (!$user->admin) {
42}
43
44$action = GETPOST('action', 'aZ09');
45
46
47/*
48 * Actions
49 */
50
51if ($action == 'setvalue' && $user->admin) {
52 $error = 0;
53 $db->begin();
54
55 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_DN', GETPOST("membertype"), 'chaine', 0, '', $conf->entity)) {
56 $error++;
57 }
58 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_OBJECT_CLASS', GETPOST("objectclass"), 'chaine', 0, '', $conf->entity)) {
59 $error++;
60 }
61
62 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_FULLNAME', GETPOST("fieldfullname"), 'chaine', 0, '', $conf->entity)) {
63 $error++;
64 }
65 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_DESCRIPTION', GETPOST("fielddescription"), 'chaine', 0, '', $conf->entity)) {
66 $error++;
67 }
68 if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS', GETPOST("fieldmembertypemembers"), 'chaine', 0, '', $conf->entity)) {
69 $error++;
70 }
71
72 // This one must be after the others
73 $valkey = '';
74 $key = GETPOST("key");
75 if ($key) {
76 $valkey = getDolGlobalString($key);
77 }
78 if (!dolibarr_set_const($db, 'LDAP_KEY_MEMBERS_TYPES', $valkey, 'chaine', 0, '', $conf->entity)) {
79 $error++;
80 }
81
82 if (!$error) {
83 $db->commit();
84 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
85 } else {
86 $db->rollback();
87 dol_print_error($db);
88 }
89}
90
91
92
93/*
94 * View
95 */
96
97llxHeader('', $langs->trans("LDAPSetup"), 'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP', '', 0, 0, '', '', '', 'mod-admin page-ldap_members_types');
98$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
99
100print load_fiche_titre($langs->trans("LDAPSetup"), $linkback, 'title_setup');
101
102$head = ldap_prepare_head();
103
104// Test if the LDAP functions are enabled
105if (!function_exists("ldap_connect")) {
106 setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
107}
108
109print dol_get_fiche_head($head, 'memberstypes', '', -1);
110
111
112print '<span class="opacitymedium">'.$langs->trans("LDAPDescMembersTypes").'</span><br>';
113print '<br>';
114
115
116print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?action=setvalue&token='.newToken().'">';
117print '<input type="hidden" name="token" value="'.newToken().'">';
118
119$form = new Form($db);
120
121print '<table class="noborder centpercent">';
122
123print '<tr class="liste_titre">';
124print '<td colspan="4">'.$langs->trans("LDAPSynchronizeMembersTypes").'</td>';
125print "</tr>\n";
126
127// DN pour les types de membres
128print '<!-- LDAP_MEMBER_TYPE_DN -->';
129print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeDn").'</span></td><td>';
130print '<input size="48" type="text" name="membertype" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_DN').'">';
131print '</td><td>'.$langs->trans("LDAPMemberTypepDnExample").'</td>';
132print '<td>&nbsp;</td>';
133print '</tr>';
134
135// List of object class used to define attributes in structure
136print '<!-- LDAP_MEMBER_TYPE_OBJECT_CLASS -->';
137print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeObjectClassList").'</span></td><td>';
138print '<input size="48" type="text" name="objectclass" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS').'">';
139print '</td><td>'.$langs->trans("LDAPMemberTypeObjectClassListExample").'</td>';
140print '<td>&nbsp;</td>';
141print '</tr>';
142
143print '</table>';
144
145print '<br>';
146
147print '<table class="noborder centpercent">';
148
149print '<tr class="liste_titre">';
150print '<td>'.$langs->trans("LDAPDolibarrMapping").'</td>';
151print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
152print '<td class="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
153print "</tr>\n";
154
155// Filtre
156
157// Common name
158print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
159print '<input size="25" type="text" name="fieldfullname" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME').'">';
160print '</td><td>'.$langs->trans("LDAPFieldCommonNameExample").'</td>';
161print '<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>";
162print '</tr>';
163
164// Description
165print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldDescription").'</td><td>';
166print '<input size="25" type="text" name="fielddescription" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION').'">';
167print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
168print '<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>";
169print '</tr>';
170
171// User group
172print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupMembers").'</td><td>';
173print '<input size="25" type="text" name="fieldmembertypemembers" value="' . getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS').'">';
174print '</td><td>'.$langs->trans("LDAPFieldGroupMembersExample").'</td>';
175print '<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>";
176print '</tr>';
177
178print '</table>';
179
180print info_admin($langs->trans("LDAPDescValues"));
181
182print dol_get_fiche_end();
183
184print $form->buttonsSaveCancel("Modify", '');
185
186print '</form>';
187
188
189/*
190 * Test de la connection
191 */
192if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
193 $butlabel = $langs->trans("LDAPTestSynchroMemberType");
194 $testlabel = 'testmembertype';
195 $key = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES');
196 $dn = getDolGlobalString('LDAP_MEMBER_TYPE_DN');
197 $objectclass = getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS');
198
199 show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass);
200}
201
202if (function_exists("ldap_connect")) {
203 if ($action == 'testmembertype') {
204 // Create object
205 $object = new AdherentType($db);
206 $object->initAsSpecimen();
207
208 // Test synchro
209 $ldap = new Ldap();
210 $result = $ldap->connectBind();
211
212 if ($result > 0) {
213 $info = $object->_load_ldap_info();
214 $dn = $object->_load_ldap_dn($info);
215
216 // Get a gid number for objectclass PosixGroup
217 if (in_array('posixGroup', $info['objectclass'])) {
218 $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPES');
219 }
220
221 $result1 = $ldap->delete($dn); // To be sure to delete existing records
222 $result2 = $ldap->add($dn, $info, $user); // Now the test
223 $result3 = $ldap->delete($dn); // Clean what we did
224
225 if ($result2 > 0) {
226 print img_picto('', 'info').' ';
227 print '<span class="ok">'.$langs->trans("LDAPSynchroOK").'</span><br>';
228 } else {
229 print img_picto('', 'error').' ';
230 print '<span class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
231 print ': '.$ldap->error;
232 print '</span><br>';
233 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
234 }
235
236 print "<br>\n";
237 print "LDAP input file used for test:<br><br>\n";
238 print nl2br($ldap->dumpContent($dn, $info));
239 print "\n<br>";
240 } else {
241 print img_picto('', 'error').' ';
242 print '<span class="error">'.$langs->trans("LDAPSynchroKO");
243 print ': '.$ldap->error;
244 print '</span><br>';
245 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
246 }
247 }
248}
249
250// End of page
251llxFooter();
252$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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).
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 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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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:31
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition ldap.lib.php:102
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.