dolibarr  16.0.5
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-2021 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) {
40  $socid = $user->socid;
41 }
42 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
43 
44 $object = new Contact($db);
45 if ($id > 0) {
46  $object->fetch($id, $user);
47 }
48 
49 
50 /*
51  * Actions
52  */
53 
54 if ($action == 'dolibarr2ldap') {
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  setEventMessages($langs->trans("ContactSynchronized"), null, 'mesgs');
68  $db->commit();
69  } else {
70  setEventMessages($ldap->error, $ldap->errors, 'errors');
71  $db->rollback();
72  }
73 }
74 
75 
76 /*
77  * View
78  */
79 
80 $form = new Form($db);
81 
82 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
83 
84 llxHeader('', $title, 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
85 
86 $head = contact_prepare_head($object);
87 
88 print dol_get_fiche_head($head, 'ldap', $title, -1, 'contact');
89 
90 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
91 
92 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
93 
94 print '<div class="fichecenter">';
95 
96 print '<div class="underbanner clearboth"></div>';
97 print '<table class="border centpercent">';
98 
99 // Company
100 if ($object->socid > 0) {
101  $thirdparty = new Societe($db);
102  $thirdparty->fetch($object->socid);
103 
104  print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
105 } else {
106  print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
107  print $langs->trans("ContactNotLinkedToCompany");
108  print '</td></tr>';
109 }
110 
111 // Civility
112 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
113 print $object->getCivilityLabel();
114 print '</td></tr>';
115 
116 // LDAP DN
117 print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_CONTACT_DN')."</td></tr>\n";
118 
119 // LDAP Cle
120 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_KEY_CONTACTS')."</td></tr>\n";
121 
122 // LDAP Server
123 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
124 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
125 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
126 
127 print '</table>';
128 
129 print '</div>';
130 
131 print dol_get_fiche_end();
132 
133 
134 /*
135  * Action bar
136  */
137 print '<div class="tabsAction">';
138 
139 if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && getDolGlobalInt('LDAP_CONTACT_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
140  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
141 }
142 
143 print "</div>\n";
144 
145 if (!empty($conf->global->LDAP_CONTACT_ACTIVE) && getDolGlobalInt('LDAP_CONTACT_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
146  print "<br>\n";
147 }
148 
149 
150 
151 // Affichage attributs LDAP
152 print load_fiche_titre($langs->trans("LDAPInformationsForThisContact"));
153 
154 print '<table width="100%" class="noborder">';
155 
156 print '<tr class="liste_titre">';
157 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
158 print '<td>'.$langs->trans("Value").'</td>';
159 print '</tr>';
160 
161 // Lecture LDAP
162 $ldap = new Ldap();
163 $result = $ldap->connect_bind();
164 if ($result > 0) {
165  $info = $object->_load_ldap_info();
166  $dn = $object->_load_ldap_dn($info, 1);
167  $search = "(".$object->_load_ldap_dn($info, 2).")";
168 
169  $records = $ldap->getAttribute($dn, $search);
170 
171  //var_dump($records);
172 
173  // Show tree
174  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
175  if (!is_array($records)) {
176  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
177  } else {
178  $result = show_ldap_content($records, 0, $records['count'], true);
179  }
180  } else {
181  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
182  }
183 
184  $ldap->unbind();
185 } else {
186  setEventMessages($ldap->error, $ldap->errors, 'errors');
187 }
188 
189 
190 print '</table>';
191 
192 llxFooter();
193 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
Ldap
Class to manage LDAP features.
Definition: ldap.class.php:34
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
$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
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
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
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
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
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
contact_prepare_head
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
Ldap\SYNCHRO_LDAP_TO_DOLIBARR
const SYNCHRO_LDAP_TO_DOLIBARR
Ldap to Dolibarr synchronization.
Definition: ldap.class.php:138
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