dolibarr  13.0.2
ldap.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2010 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.'/contact/class/contact.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('companies', 'ldap'));
33 $langs->load("admin");
34 
35 $action = GETPOST('action', 'aZ09');
36 
37 // Security check
38 $id = GETPOST('id', 'int');
39 if ($user->socid) $socid = $user->socid;
40 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
41 
42 $object = new Contact($db);
43 if ($id > 0)
44 {
45  $object->fetch($id, $user);
46 }
47 
48 
49 /*
50  * Actions
51  */
52 
53 if ($action == 'dolibarr2ldap')
54 {
55  $db->begin();
56 
57  $ldap = new Ldap();
58  $result = $ldap->connect_bind();
59 
60  $info = $object->_load_ldap_info();
61  $dn = $object->_load_ldap_dn($info);
62  $olddn = $dn; // We can say that old dn = dn as we force synchro
63 
64  $result = $ldap->update($dn, $info, $user, $olddn);
65 
66  if ($result >= 0)
67  {
68  setEventMessages($langs->trans("ContactSynchronized"), null, 'mesgs');
69  $db->commit();
70  } else {
71  setEventMessages($ldap->error, $ldap->errors, 'errors');
72  $db->rollback();
73  }
74 }
75 
76 
77 /*
78  * View
79  */
80 
81 $form = new Form($db);
82 
83 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
84 
85 llxHeader('', $title, 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
86 
87 $head = contact_prepare_head($object);
88 
89 print dol_get_fiche_head($head, 'ldap', $title, -1, 'contact');
90 
91 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
92 
93 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
94 
95 print '<div class="fichecenter">';
96 
97 print '<div class="underbanner clearboth"></div>';
98 print '<table class="border centpercent">';
99 
100 // Company
101 if ($object->socid > 0)
102 {
103  $thirdparty = new Societe($db);
104  $thirdparty->fetch($object->socid);
105 
106  print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
107 } else {
108  print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
109  print $langs->trans("ContactNotLinkedToCompany");
110  print '</td></tr>';
111 }
112 
113 // Civility
114 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
115 print $object->getCivilityLabel();
116 print '</td></tr>';
117 
118 // LDAP DN
119 print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
120 
121 // LDAP Cle
122 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
123 
124 // LDAP Server
125 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
126 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
127 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
128 
129 print '</table>';
130 
131 print '</div>';
132 
134 
135 
136 /*
137  * Barre d'actions
138  */
139 
140 print '<div class="tabsAction">';
141 
142 if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
143 {
144  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
145 }
146 
147 print "</div>\n";
148 
149 if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
150 
151 
152 
153 // Affichage attributs LDAP
154 print load_fiche_titre($langs->trans("LDAPInformationsForThisContact"));
155 
156 print '<table width="100%" class="noborder">';
157 
158 print '<tr class="liste_titre">';
159 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
160 print '<td>'.$langs->trans("Value").'</td>';
161 print '</tr>';
162 
163 // Lecture LDAP
164 $ldap = new Ldap();
165 $result = $ldap->connect_bind();
166 if ($result > 0)
167 {
168  $info = $object->_load_ldap_info();
169  $dn = $object->_load_ldap_dn($info, 1);
170  $search = "(".$object->_load_ldap_dn($info, 2).")";
171 
172  $records = $ldap->getAttribute($dn, $search);
173 
174  //var_dump($records);
175 
176  // Show tree
177  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0))
178  {
179  if (!is_array($records))
180  {
181  print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
182  } else {
183  $result = show_ldap_content($records, 0, $records['count'], true);
184  }
185  } else {
186  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
187  }
188 
189  $ldap->unbind();
190  $ldap->close();
191 } else {
192  setEventMessages($ldap->error, $ldap->errors, 'errors');
193 }
194 
195 
196 print '</table>';
197 
198 llxFooter();
199 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage contact/addresses.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition: ldap.lib.php:142
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer 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.
llxFooter()
Empty footer.
Definition: wrapper.php:59