2006-11-19 05:56:10 +01:00
|
|
|
<?php
|
2012-01-10 17:16:17 +01:00
|
|
|
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
2017-09-15 18:02:52 +02:00
|
|
|
* Copyright (C) 2006-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
2006-11-19 05:56:10 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-11-19 05:56:10 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2011-08-01 01:54:11 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-11-19 05:56:10 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2009-08-12 01:42:21 +02:00
|
|
|
* \file htdocs/contact/ldap.php
|
|
|
|
|
* \ingroup ldap
|
|
|
|
|
* \brief Page fiche LDAP contact
|
|
|
|
|
*/
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../main.inc.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2018-05-26 20:32:23 +02:00
|
|
|
// Load translation files required by the page
|
|
|
|
|
$langs->loadLangs(array('companies', 'ldap'));
|
2007-11-05 19:35:45 +01:00
|
|
|
$langs->load("admin");
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2017-05-16 13:27:32 +02:00
|
|
|
$action=GETPOST('action','aZ09');
|
2012-05-12 12:32:24 +02:00
|
|
|
|
2008-02-25 17:30:43 +01:00
|
|
|
// Security check
|
2013-04-26 12:35:31 +02:00
|
|
|
$id = GETPOST('id', 'int');
|
2008-02-25 21:03:21 +01:00
|
|
|
if ($user->societe_id) $socid=$user->societe_id;
|
2013-04-26 12:35:31 +02:00
|
|
|
$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
$object = new Contact($db);
|
2015-07-19 11:21:21 +02:00
|
|
|
if ($id > 0)
|
|
|
|
|
{
|
2015-10-15 14:13:31 +02:00
|
|
|
$object->fetch($id, $user);
|
2015-07-19 12:04:30 +02:00
|
|
|
}
|
2009-08-11 22:16:58 +02:00
|
|
|
|
|
|
|
|
|
2009-08-12 01:42:21 +02:00
|
|
|
/*
|
|
|
|
|
* Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2012-05-12 12:32:24 +02:00
|
|
|
if ($action == 'dolibarr2ldap')
|
2009-08-12 01:42:21 +02:00
|
|
|
{
|
|
|
|
|
$db->begin();
|
|
|
|
|
|
|
|
|
|
$ldap=new Ldap();
|
|
|
|
|
$result=$ldap->connect_bind();
|
|
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
$info=$object->_load_ldap_info();
|
|
|
|
|
$dn=$object->_load_ldap_dn($info);
|
2009-08-12 01:42:21 +02:00
|
|
|
$olddn=$dn; // We can say that old dn = dn as we force synchro
|
|
|
|
|
|
|
|
|
|
$result=$ldap->update($dn,$info,$user,$olddn);
|
|
|
|
|
|
|
|
|
|
if ($result >= 0)
|
|
|
|
|
{
|
2015-11-18 16:05:41 +01:00
|
|
|
setEventMessages($langs->trans("ContactSynchronized"), null, 'mesgs');
|
2009-08-12 01:42:21 +02:00
|
|
|
$db->commit();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-18 16:05:41 +01:00
|
|
|
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
2009-08-12 01:42:21 +02:00
|
|
|
$db->rollback();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-11 22:16:58 +02:00
|
|
|
|
2006-11-19 05:56:10 +01:00
|
|
|
|
|
|
|
|
/*
|
2009-08-12 01:42:21 +02:00
|
|
|
* View
|
|
|
|
|
*/
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2013-04-26 12:35:31 +02:00
|
|
|
$title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
|
|
|
|
|
|
|
|
|
|
llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:Módulo_Empresas');
|
2006-11-19 05:56:10 +01:00
|
|
|
|
|
|
|
|
$form = new Form($db);
|
|
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
$head = contact_prepare_head($object);
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2017-05-23 01:32:19 +02:00
|
|
|
dol_fiche_head($head, 'ldap', $title, -1, 'contact');
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2017-10-03 16:00:52 +02:00
|
|
|
$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
|
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
|
2017-09-15 18:02:52 +02:00
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
print '<div class="fichecenter">';
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
print '<div class="underbanner clearboth"></div>';
|
|
|
|
|
print '<table class="border centpercent">';
|
2007-11-05 19:35:45 +01:00
|
|
|
|
|
|
|
|
// Company
|
2015-10-15 14:13:31 +02:00
|
|
|
if ($object->socid > 0)
|
2006-11-19 05:56:10 +01:00
|
|
|
{
|
2015-10-15 14:13:31 +02:00
|
|
|
$thirdparty = new Societe($db);
|
|
|
|
|
$thirdparty->fetch($object->socid);
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
|
2006-11-19 05:56:10 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-15 14:13:31 +02:00
|
|
|
print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
|
2009-08-12 01:42:21 +02:00
|
|
|
print $langs->trans("ContactNotLinkedToCompany");
|
|
|
|
|
print '</td></tr>';
|
2006-11-19 05:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
2007-11-05 19:35:45 +01:00
|
|
|
// Civility
|
2015-10-15 14:13:31 +02:00
|
|
|
print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
|
|
|
|
|
print $object->getCivilityLabel();
|
2006-11-19 05:56:10 +01:00
|
|
|
print '</td></tr>';
|
|
|
|
|
|
2006-11-20 03:10:47 +01:00
|
|
|
// LDAP DN
|
2007-11-05 19:35:45 +01:00
|
|
|
print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
|
2006-11-20 03:10:47 +01:00
|
|
|
|
2009-08-11 22:16:58 +02:00
|
|
|
// LDAP Cle
|
2007-11-05 19:35:45 +01:00
|
|
|
print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
|
2006-11-20 02:13:13 +01:00
|
|
|
|
|
|
|
|
// LDAP Server
|
2007-11-05 19:35:45 +01:00
|
|
|
print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
|
|
|
|
|
print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
|
|
|
|
|
print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
|
2006-11-20 02:13:13 +01:00
|
|
|
|
2006-11-19 05:56:10 +01:00
|
|
|
print '</table>';
|
|
|
|
|
|
2015-10-15 14:13:31 +02:00
|
|
|
print '</div>';
|
|
|
|
|
|
2015-07-19 12:04:30 +02:00
|
|
|
dol_fiche_end();
|
2009-08-12 01:42:21 +02:00
|
|
|
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2009-08-12 01:42:21 +02:00
|
|
|
/*
|
|
|
|
|
* Barre d'actions
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
print '<div class="tabsAction">';
|
|
|
|
|
|
2010-01-17 15:11:54 +01:00
|
|
|
if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
|
2009-08-12 01:42:21 +02:00
|
|
|
{
|
2015-10-15 14:13:31 +02:00
|
|
|
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
|
2009-08-12 01:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print "</div>\n";
|
|
|
|
|
|
2010-01-17 15:11:54 +01:00
|
|
|
if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
|
2009-08-12 01:42:21 +02:00
|
|
|
|
2006-11-19 05:56:10 +01:00
|
|
|
|
|
|
|
|
|
2009-08-11 22:16:58 +02:00
|
|
|
// Affichage attributs LDAP
|
2015-09-24 18:27:13 +02:00
|
|
|
print load_fiche_titre($langs->trans("LDAPInformationsForThisContact"));
|
2006-11-19 05:56:10 +01:00
|
|
|
|
|
|
|
|
print '<table width="100%" class="noborder">';
|
|
|
|
|
|
|
|
|
|
print '<tr class="liste_titre">';
|
2006-11-19 17:02:53 +01:00
|
|
|
print '<td>'.$langs->trans("LDAPAttributes").'</td>';
|
2006-11-19 05:56:10 +01:00
|
|
|
print '<td>'.$langs->trans("Value").'</td>';
|
|
|
|
|
print '</tr>';
|
|
|
|
|
|
|
|
|
|
// Lecture LDAP
|
2006-11-21 17:57:36 +01:00
|
|
|
$ldap=new Ldap();
|
2006-11-21 23:51:05 +01:00
|
|
|
$result=$ldap->connect_bind();
|
|
|
|
|
if ($result > 0)
|
2006-11-19 05:56:10 +01:00
|
|
|
{
|
2015-10-15 14:13:31 +02:00
|
|
|
$info=$object->_load_ldap_info();
|
|
|
|
|
$dn=$object->_load_ldap_dn($info,1);
|
|
|
|
|
$search = "(".$object->_load_ldap_dn($info,2).")";
|
2016-05-29 11:20:12 +02:00
|
|
|
$records = $ldap->getAttribute($dn,$search);
|
2007-05-02 00:13:34 +02:00
|
|
|
|
2009-12-22 17:02:54 +01:00
|
|
|
//var_dump($records);
|
2006-11-19 05:56:10 +01:00
|
|
|
|
2006-11-21 23:51:05 +01:00
|
|
|
// Affichage arbre
|
2016-05-29 11:20:12 +02:00
|
|
|
if ((! is_numeric($records) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
|
2006-11-19 05:56:10 +01:00
|
|
|
{
|
2007-05-02 00:13:34 +02:00
|
|
|
if (! is_array($records))
|
|
|
|
|
{
|
2009-08-05 19:49:12 +02:00
|
|
|
print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
|
2007-05-02 00:13:34 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-12-22 16:44:57 +01:00
|
|
|
$result=show_ldap_content($records,0,$records['count'],true);
|
2007-05-02 00:13:34 +02:00
|
|
|
}
|
2006-11-19 05:56:10 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-05-02 00:13:34 +02:00
|
|
|
print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
|
2006-11-19 05:56:10 +01:00
|
|
|
}
|
2006-11-21 23:51:05 +01:00
|
|
|
|
|
|
|
|
$ldap->unbind();
|
2006-11-20 02:13:13 +01:00
|
|
|
$ldap->close();
|
2006-11-19 05:56:10 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-09-15 18:02:52 +02:00
|
|
|
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
2006-11-19 05:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
2006-11-21 23:51:05 +01:00
|
|
|
|
2006-11-19 05:56:10 +01:00
|
|
|
print '</table>';
|
|
|
|
|
|
2011-08-27 16:24:16 +02:00
|
|
|
llxFooter();
|
2015-07-19 12:04:30 +02:00
|
|
|
$db->close();
|