dolibarr  7.0.0-beta
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@capnetworks.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 <http://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 $langs->load("members");
33 $langs->load("admin");
34 $langs->load("ldap");
35 
36 $id = GETPOST('rowid', 'int');
37 $action = GETPOST('action','alpha');
38 
39 // Security check
40 $result=restrictedArea($user,'adherent',$id,'adherent_type');
41 
42 $object = new AdherentType($db);
43 $object->fetch($id);
44 
45 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
46 $hookmanager->initHooks(array('membertypeldapcard','globalcard'));
47 
48 /*
49  * Actions
50  */
51 
52 
53 $parameters=array();
54 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
55 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
56 
57 if (empty($reshook))
58 {
59  if ($action == 'dolibarr2ldap')
60  {
61  $ldap = new Ldap();
62  $result = $ldap->connect_bind();
63 
64  if ($result > 0)
65  {
66  $object->listMembersForMemberType();
67 
68  $info = $object->_load_ldap_info();
69  $dn = $object->_load_ldap_dn($info);
70  $olddn = $dn; // We can say that old dn = dn as we force synchro
71 
72  $result = $ldap->update($dn, $info, $user, $olddn);
73  }
74 
75  if ($result >= 0) {
76  setEventMessages($langs->trans("MemberTypeSynchronized"), null, 'mesgs');
77  }
78  else {
79  setEventMessages($ldap->error, $ldap->errors, 'errors');
80  }
81  }
82 }
83 
84 /*
85  * View
86  */
87 
88 llxHeader();
89 
90 $form = new Form($db);
91 
92 $head = member_type_prepare_head($object);
93 
94 dol_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
95 
96 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
97 
98 dol_banner_tab($object, 'rowid', $linkback);
99 
100 print '<div class="fichecenter">';
101 print '<div class="underbanner clearboth"></div>';
102 
103 print '<table class="border" width="100%">';
104 
105 // LDAP DN
106 print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_TYPE_DN."</td></tr>\n";
107 
108 // LDAP Cle
109 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS_TYPES."</td></tr>\n";
110 
111 // LDAP Server
112 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
113 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
114 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
115 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
116 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
117 
118 print '</table>';
119 
120 print '</div>';
121 
122 dol_fiche_end();
123 
124 /*
125  * Barre d'actions
126  */
127 
128 print '<div class="tabsAction">';
129 
130 if ($conf->global->LDAP_MEMBER_TYPE_ACTIVE == 1)
131 {
132  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
133 }
134 
135 print "</div>\n";
136 
137 if ($conf->global->LDAP_MEMBER_TYPE_ACTIVE == 1) print "<br>\n";
138 
139 
140 
141 // Affichage attributs LDAP
142 print load_fiche_titre($langs->trans("LDAPInformationsForThisMemberType"));
143 
144 print '<table width="100%" class="noborder">';
145 
146 print '<tr class="liste_titre">';
147 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
148 print '<td>'.$langs->trans("Value").'</td>';
149 print '</tr>';
150 
151 // Lecture LDAP
152 $ldap=new Ldap();
153 $result=$ldap->connect_bind();
154 if ($result > 0)
155 {
156  $info=$object->_load_ldap_info();
157  $dn=$object->_load_ldap_dn($info,1);
158  $search = "(".$object->_load_ldap_dn($info,2).")";
159  $records = $ldap->getAttribute($dn,$search);
160 
161  //print_r($records);
162 
163  // Affichage arbre
164  if ((! is_numeric($records) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
165  {
166  if (! is_array($records))
167  {
168  print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
169  }
170  else
171  {
172  $result=show_ldap_content($records,0,$records['count'],true);
173  }
174  }
175  else
176  {
177  print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
178  }
179 
180  $ldap->unbind();
181  $ldap->close();
182 }
183 else
184 {
185  setEventMessages($ldap->error, $ldap->errors, 'errors');
186 }
187 
188 print '</table>';
189 
190 llxFooter();
191 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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.
member_type_prepare_head(AdherentType $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:117
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition: ldap.lib.php:144
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage members type.
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:91
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.