dolibarr  16.0.5
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 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('admin', 'errors'));
38 
39 if (!$user->admin) {
41 }
42 
43 $action = GETPOST('action', 'aZ09');
44 
45 
46 /*
47  * Actions
48  */
49 
50 if ($action == 'setvalue' && $user->admin) {
51  $error = 0;
52  $db->begin();
53 
54  if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_DN', GETPOST("membertype"), 'chaine', 0, '', $conf->entity)) {
55  $error++;
56  }
57  if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_OBJECT_CLASS', GETPOST("objectclass"), 'chaine', 0, '', $conf->entity)) {
58  $error++;
59  }
60 
61  if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_FULLNAME', GETPOST("fieldfullname"), 'chaine', 0, '', $conf->entity)) {
62  $error++;
63  }
64  if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_DESCRIPTION', GETPOST("fielddescription"), 'chaine', 0, '', $conf->entity)) {
65  $error++;
66  }
67  if (!dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS', GETPOST("fieldmembertypemembers"), 'chaine', 0, '', $conf->entity)) {
68  $error++;
69  }
70 
71  // This one must be after the others
72  $valkey = '';
73  $key = GETPOST("key");
74  if ($key) {
75  $valkey = $conf->global->$key;
76  }
77  if (!dolibarr_set_const($db, 'LDAP_KEY_MEMBERS_TYPES', $valkey, 'chaine', 0, '', $conf->entity)) {
78  $error++;
79  }
80 
81  if (!$error) {
82  $db->commit();
83  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
84  } else {
85  $db->rollback();
86  dol_print_error($db);
87  }
88 }
89 
90 
91 
92 /*
93  * View
94  */
95 
96 llxHeader('', $langs->trans("LDAPSetup"), 'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP');
97 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
98 
99 print load_fiche_titre($langs->trans("LDAPSetup"), $linkback, 'title_setup');
100 
101 $head = ldap_prepare_head();
102 
103 // Test si fonction LDAP actives
104 if (!function_exists("ldap_connect")) {
105  setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
106 }
107 
108 print dol_get_fiche_head($head, 'memberstypes', $langs->trans("LDAPSetup"), -1);
109 
110 
111 print '<span class="opacitymedium">'.$langs->trans("LDAPDescMembersTypes").'</span><br>';
112 print '<br>';
113 
114 
115 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?action=setvalue&token='.newToken().'">';
116 print '<input type="hidden" name="token" value="'.newToken().'">';
117 
118 $form = new Form($db);
119 
120 print '<table class="noborder centpercent">';
121 
122 print '<tr class="liste_titre">';
123 print '<td colspan="4">'.$langs->trans("LDAPSynchronizeMembersTypes").'</td>';
124 print "</tr>\n";
125 
126 // DN pour les types de membres
127 print '<!-- LDAP_MEMBER_TYPE_DN -->';
128 print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeDn").'</span></td><td>';
129 print '<input size="48" type="text" name="membertype" value="'.$conf->global->LDAP_MEMBER_TYPE_DN.'">';
130 print '</td><td>'.$langs->trans("LDAPMemberTypepDnExample").'</td>';
131 print '<td>&nbsp;</td>';
132 print '</tr>';
133 
134 // List of object class used to define attributes in structure
135 print '<!-- LDAP_MEMBER_TYPE_OBJECT_CLASS -->';
136 print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeObjectClassList").'</span></td><td>';
137 print '<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS.'">';
138 print '</td><td>'.$langs->trans("LDAPMemberTypeObjectClassListExample").'</td>';
139 print '<td>&nbsp;</td>';
140 print '</tr>';
141 
142 print '</table>';
143 
144 print '<br>';
145 
146 print '<table class="noborder centpercent">';
147 
148 print '<tr class="liste_titre">';
149 print '<td>'.$langs->trans("LDAPDolibarrMapping").'</td>';
150 print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
151 print '<td class="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
152 print "</tr>\n";
153 
154 // Filtre
155 
156 // Common name
157 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
158 print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME.'">';
159 print '</td><td>'.$langs->trans("LDAPFieldCommonNameExample").'</td>';
160 print '<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>";
161 print '</tr>';
162 
163 // Description
164 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldDescription").'</td><td>';
165 print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION.'">';
166 print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
167 print '<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>";
168 print '</tr>';
169 
170 // User group
171 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupMembers").'</td><td>';
172 print '<input size="25" type="text" name="fieldmembertypemembers" value="'.$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS.'">';
173 print '</td><td>'.$langs->trans("LDAPFieldGroupMembersExample").'</td>';
174 print '<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>";
175 print '</tr>';
176 
177 print '</table>';
178 
179 print info_admin($langs->trans("LDAPDescValues"));
180 
181 print dol_get_fiche_end();
182 
183 print $form->buttonsSaveCancel("Modify", '');
184 
185 print '</form>';
186 
187 
188 /*
189  * Test de la connexion
190  */
191 if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
192  $butlabel = $langs->trans("LDAPTestSynchroMemberType");
193  $testlabel = 'testmembertype';
194  $key = $conf->global->LDAP_KEY_MEMBERS_TYPES;
195  $dn = $conf->global->LDAP_MEMBER_TYPE_DN;
196  $objectclass = $conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS;
197 
198  show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass);
199 }
200 
201 if (function_exists("ldap_connect")) {
202  if ($_GET["action"] == 'testmembertype') {
203  // Creation objet
204  $object = new AdherentType($db);
205  $object->initAsSpecimen();
206 
207  // Test synchro
208  $ldap = new Ldap();
209  $result = $ldap->connect_bind();
210 
211  if ($result > 0) {
212  $info = $object->_load_ldap_info();
213  $dn = $object->_load_ldap_dn($info);
214 
215  // Get a gid number for objectclass PosixGroup
216  if (in_array('posixGroup', $info['objectclass'])) {
217  $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPES');
218  }
219 
220  $result1 = $ldap->delete($dn); // To be sure to delete existing records
221  $result2 = $ldap->add($dn, $info, $user); // Now the test
222  $result3 = $ldap->delete($dn); // Clean what we did
223 
224  if ($result2 > 0) {
225  print img_picto('', 'info').' ';
226  print '<span class="ok">'.$langs->trans("LDAPSynchroOK").'</span><br>';
227  } else {
228  print img_picto('', 'error').' ';
229  print '<span class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
230  print ': '.$ldap->error;
231  print '</span><br>';
232  print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
233  }
234 
235  print "<br>\n";
236  print "LDAP input file used for test:<br><br>\n";
237  print nl2br($ldap->dump_content($dn, $info));
238  print "\n<br>";
239  } else {
240  print img_picto('', 'error').' ';
241  print '<span class="error">'.$langs->trans("LDAPSynchroKO");
242  print ': '.$ldap->error;
243  print '</span><br>';
244  print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
245  }
246  }
247 }
248 
249 // End of page
250 llxFooter();
251 $db->close();
Ldap
Class to manage LDAP features.
Definition: ldap.class.php:34
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Ldap\SYNCHRO_DOLIBARR_TO_LDAP
const SYNCHRO_DOLIBARR_TO_LDAP
Dolibarr to Ldap synchronization.
Definition: ldap.class.php:133
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
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).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
ldap_prepare_head
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition: ldap.lib.php:31
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
show_ldap_test_button
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition: ldap.lib.php:102