dolibarr  7.0.0-beta
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@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.'/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 $langs->load("companies");
32 $langs->load("ldap");
33 $langs->load("admin");
34 
35 $action=GETPOST('action','aZ09');
36 
37 // Security check
38 $id = GETPOST('id', 'int');
39 if ($user->societe_id) $socid=$user->societe_id;
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  }
71  else
72  {
73  setEventMessages($ldap->error, $ldap->errors, 'errors');
74  $db->rollback();
75  }
76 }
77 
78 
79 /*
80  * View
81  */
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 $form = new Form($db);
88 
89 $head = contact_prepare_head($object);
90 
91 dol_fiche_head($head, 'ldap', $title, -1, 'contact');
92 
93 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
94 
95 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
96 
97 print '<div class="fichecenter">';
98 
99 print '<div class="underbanner clearboth"></div>';
100 print '<table class="border centpercent">';
101 
102 // Company
103 if ($object->socid > 0)
104 {
105  $thirdparty = new Societe($db);
106  $thirdparty->fetch($object->socid);
107 
108  print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
109 }
110 else
111 {
112  print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
113  print $langs->trans("ContactNotLinkedToCompany");
114  print '</td></tr>';
115 }
116 
117 // Civility
118 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
119 print $object->getCivilityLabel();
120 print '</td></tr>';
121 
122 // LDAP DN
123 print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
124 
125 // LDAP Cle
126 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
127 
128 // LDAP Server
129 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
130 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
131 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
132 
133 print '</table>';
134 
135 print '</div>';
136 
137 dol_fiche_end();
138 
139 
140 /*
141  * Barre d'actions
142  */
143 
144 print '<div class="tabsAction">';
145 
146 if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
147 {
148  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
149 }
150 
151 print "</div>\n";
152 
153 if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
154 
155 
156 
157 // Affichage attributs LDAP
158 print load_fiche_titre($langs->trans("LDAPInformationsForThisContact"));
159 
160 print '<table width="100%" class="noborder">';
161 
162 print '<tr class="liste_titre">';
163 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
164 print '<td>'.$langs->trans("Value").'</td>';
165 print '</tr>';
166 
167 // Lecture LDAP
168 $ldap=new Ldap();
169 $result=$ldap->connect_bind();
170 if ($result > 0)
171 {
172  $info=$object->_load_ldap_info();
173  $dn=$object->_load_ldap_dn($info,1);
174  $search = "(".$object->_load_ldap_dn($info,2).")";
175  $records = $ldap->getAttribute($dn,$search);
176 
177  //var_dump($records);
178 
179  // Affichage arbre
180  if ((! is_numeric($records) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
181  {
182  if (! is_array($records))
183  {
184  print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
185  }
186  else
187  {
188  $result=show_ldap_content($records,0,$records['count'],true);
189  }
190  }
191  else
192  {
193  print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
194  }
195 
196  $ldap->unbind();
197  $ldap->close();
198 }
199 else
200 {
201  setEventMessages($ldap->error, $ldap->errors, 'errors');
202 }
203 
204 
205 print '</table>';
206 
207 llxFooter();
208 $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.
Class to manage contact/addresses.
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.
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.
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:144
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
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 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.