dolibarr  16.0.5
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 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("admin", "members", "ldap"));
34 
35 $id = GETPOST('rowid', 'int');
36 $action = GETPOST('action', 'aZ09');
37 
38 // Security check
39 $result = restrictedArea($user, 'adherent', $id, 'adherent_type');
40 
41 $object = new AdherentType($db);
42 $object->fetch($id);
43 
44 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
45 $hookmanager->initHooks(array('membertypeldapcard', 'globalcard'));
46 
47 /*
48  * Actions
49  */
50 
51 
52 $parameters = array();
53 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
54 if ($reshook < 0) {
55  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
56 }
57 
58 if (empty($reshook)) {
59  if ($action == 'dolibarr2ldap') {
60  $ldap = new Ldap();
61  $result = $ldap->connect_bind();
62 
63  if ($result > 0) {
64  $object->listMembersForMemberType('', 1);
65 
66  $info = $object->_load_ldap_info();
67  $dn = $object->_load_ldap_dn($info);
68  $olddn = $dn; // We can say that old dn = dn as we force synchro
69 
70  $result = $ldap->update($dn, $info, $user, $olddn);
71  }
72 
73  if ($result >= 0) {
74  setEventMessages($langs->trans("MemberTypeSynchronized"), null, 'mesgs');
75  } else {
76  setEventMessages($ldap->error, $ldap->errors, 'errors');
77  }
78  }
79 }
80 
81 /*
82  * View
83  */
84 
85 llxHeader();
86 
87 $form = new Form($db);
88 
89 $head = member_type_prepare_head($object);
90 
91 print dol_get_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
92 
93 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
94 
95 dol_banner_tab($object, 'rowid', $linkback);
96 
97 print '<div class="fichecenter">';
98 print '<div class="underbanner clearboth"></div>';
99 
100 print '<table class="border centpercent">';
101 
102 // LDAP DN
103 print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_TYPE_DN."</td></tr>\n";
104 
105 // LDAP Cle
106 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS_TYPES."</td></tr>\n";
107 
108 // LDAP Server
109 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
110 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
111 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
112 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
113 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
114 
115 print '</table>';
116 
117 print '</div>';
118 
119 print dol_get_fiche_end();
120 
121 /*
122  * Action bar
123  */
124 
125 print '<div class="tabsAction">';
126 
127 if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
128  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
129 }
130 
131 print "</div>\n";
132 
133 if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
134  print "<br>\n";
135 }
136 
137 
138 
139 // Display LDAP attributes
140 print load_fiche_titre($langs->trans("LDAPInformationsForThisMemberType"));
141 
142 print '<table width="100%" class="noborder">';
143 
144 print '<tr class="liste_titre">';
145 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
146 print '<td>'.$langs->trans("Value").'</td>';
147 print '</tr>';
148 
149 // LDAP reading
150 $ldap = new Ldap();
151 $result = $ldap->connect_bind();
152 if ($result > 0) {
153  $info = $object->_load_ldap_info();
154  $dn = $object->_load_ldap_dn($info, 1);
155  $search = "(".$object->_load_ldap_dn($info, 2).")";
156 
157  $records = $ldap->getAttribute($dn, $search);
158 
159  //print_r($records);
160 
161  // Show tree
162  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
163  if (!is_array($records)) {
164  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
165  } else {
166  $result = show_ldap_content($records, 0, $records['count'], true);
167  }
168  } else {
169  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
170  }
171 
172  $ldap->unbind();
173 } else {
174  setEventMessages($ldap->error, $ldap->errors, 'errors');
175 }
176 
177 print '</table>';
178 
179 // End of page
180 llxFooter();
181 $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
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
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
member_type_prepare_head
member_type_prepare_head(AdherentType $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:137
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
Ldap\SYNCHRO_DOLIBARR_TO_LDAP
const SYNCHRO_DOLIBARR_TO_LDAP
Dolibarr to Ldap synchronization.
Definition: ldap.class.php:133
show_ldap_content
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
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
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
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