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