Fix: UTF8 support for LDAP module

This commit is contained in:
Laurent Destailleur 2008-12-09 20:14:04 +00:00
parent ddd8102a47
commit 6abe23f15c
14 changed files with 753 additions and 695 deletions

View File

@ -346,7 +346,7 @@ class Adherent extends CommonObject
$nbrowsaffected=0;
$error=0;
dolibarr_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser);
dolibarr_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", email=".$this->email);
// Verification parametres
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email))

View File

@ -125,26 +125,26 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"])
if ($result > 0)
{
// Modifie valeures
$adh->prenom = $_POST["prenom"];
$adh->nom = $_POST["nom"];
$adh->prenom = trim($_POST["prenom"]);
$adh->nom = trim($_POST["nom"]);
$adh->fullname = trim($adh->prenom.' '.$adh->nom);
$adh->login = $_POST["login"];
$adh->pass = $_POST["pass"];
$adh->login = trim($_POST["login"]);
$adh->pass = trim($_POST["pass"]);
$adh->societe = $_POST["societe"];
$adh->adresse = $_POST["adresse"];
$adh->cp = $_POST["cp"];
$adh->ville = $_POST["ville"];
$adh->societe = trim($_POST["societe"]);
$adh->adresse = trim($_POST["adresse"]);
$adh->cp = trim($_POST["cp"]);
$adh->ville = trim($_POST["ville"]);
$adh->pays_id = $_POST["pays"];
$adh->phone = $_POST["phone"];
$adh->phone_perso = $_POST["phone_perso"];
$adh->phone_mobile= $_POST["phone_mobile"];
$adh->email = $_POST["email"];
$adh->phone = trim($_POST["phone"]);
$adh->phone_perso = trim($_POST["phone_perso"]);
$adh->phone_mobile= trim($_POST["phone_mobile"]);
$adh->email = trim($_POST["email"]);
$adh->naiss = $datenaiss;
$adh->typeid = $_POST["type"];
$adh->note = $_POST["comment"];
$adh->note = trim($_POST["comment"]);
$adh->morphy = $_POST["morphy"];
$adh->amount = $_POST["amount"];

View File

@ -50,6 +50,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
if (! dolibarr_set_const($db, 'LDAP_CONTACT_DN',$_POST["contactdn"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_CONTACT_OBJECT_CLASS',$_POST["objectclass"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',$_POST["fieldfirstname"])) $error++;
@ -252,17 +253,13 @@ print info_admin($langs->trans("LDAPDescValues"));
/*
* Test de la connexion
*/
print '<br>';
if (! function_exists("ldap_connect"))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$langs->trans("LDAPTestSynchroContact").'</a>';
}
else if (empty($conf->global->LDAP_SERVER_HOST))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('SetupNotComplete').'">'.$langs->trans("LDAPTestSynchroContact").'</a>';
}
else print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test">'.$langs->trans("LDAPTestSynchroContact").'</a>';
print '<br><br>';
$butlabel=$langs->trans("LDAPTestSynchroContact");
$testlabel='test';
$key=$conf->global->LDAP_KEY_CONTACTS;
$dn=$conf->global->LDAP_CONTACT_DN;
$objectclass=$conf->global->LDAP_CONTACT_OBJECT_CLASS;
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
if (function_exists("ldap_connect"))
@ -270,8 +267,8 @@ if (function_exists("ldap_connect"))
if ($_GET["action"] == 'test')
{
// Creation objet
$contact=new Contact($db);
$contact->initAsSpecimen();
$object=new Contact($db);
$object->initAsSpecimen();
// Test synchro
$ldap=new Ldap();
@ -279,8 +276,8 @@ if (function_exists("ldap_connect"))
if ($result > 0)
{
$info=$contact->_load_ldap_info();
$dn=$contact->_load_ldap_dn($info);
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result2=$ldap->update($dn,$info,$user);
$result3=$ldap->delete($dn);
@ -296,6 +293,7 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
}
else
@ -304,8 +302,13 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKO");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
print "<br>\n";
print "LDAP input file used for test:<br><br>\n";
print nl2br($ldap->dump_content($dn,$info));
print "\n<br>";
}
}

View File

@ -51,6 +51,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
if (! dolibarr_set_const($db, 'LDAP_GROUP_DN',$_POST["group"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_GROUP_OBJECT_CLASS',$_POST["objectclass"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_DESCRIPTION',$_POST["fielddescription"])) $error++;
@ -172,19 +173,15 @@ print info_admin($langs->trans("LDAPDescValues"));
/*
* Test de la connexion
*/
print '<br>';
if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
if (! function_exists("ldap_connect"))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$langs->trans("LDAPTestSynchroGroup").'</a>';
}
else if (empty($conf->global->LDAP_SERVER_HOST))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('SetupNotComplete').'">'.$langs->trans("LDAPTestSynchroGroup").'</a>';
}
else print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testgroup">'.$langs->trans("LDAPTestSynchroGroup").'</a>';
print '<br><br>';
$butlabel=$langs->trans("LDAPTestSynchroGroup");
$testlabel='testgroup';
$key=$conf->global->LDAP_KEY_GROUPS;
$dn=$conf->global->LDAP_GROUP_DN;
$objectclass=$conf->global->LDAP_GROUP_OBJECT_CLASS;
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
}
if (function_exists("ldap_connect"))
@ -192,8 +189,8 @@ if (function_exists("ldap_connect"))
if ($_GET["action"] == 'testgroup')
{
// Creation objet
$fgroup=new UserGroup($db);
$fgroup->initAsSpecimen();
$object=new UserGroup($db);
$object->initAsSpecimen();
// Test synchro
$ldap=new Ldap();
@ -201,8 +198,8 @@ if (function_exists("ldap_connect"))
if ($result > 0)
{
$info=$fgroup->_load_ldap_info();
$dn=$fgroup->_load_ldap_dn($info);
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result2=$ldap->update($dn,$info,$user);
$result3=$ldap->delete($dn);
@ -218,6 +215,7 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
}
else
@ -226,12 +224,17 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKO");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
print "<br>\n";
print "LDAP input file used for test:<br><br>\n";
print nl2br($ldap->dump_content($dn,$info));
print "\n<br>";
}
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -48,6 +48,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
{
$error=0;
if (! dolibarr_set_const($db, 'LDAP_KEY_MEMBERS',$_POST["key"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_MEMBER_DN',$_POST["user"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_MEMBER_OBJECT_CLASS',$_POST["objectclass"])) $error++;
// Members
@ -366,17 +367,13 @@ print info_admin($langs->trans("LDAPDescValues"));
*/
if ($conf->global->LDAP_MEMBER_ACTIVE)
{
print '<br>';
if (! function_exists("ldap_connect"))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$langs->trans("LDAPTestSynchroMember").'</a>';
}
else if (empty($conf->global->LDAP_SERVER_HOST))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('SetupNotComplete').'">'.$langs->trans("LDAPTestSynchroMember").'</a>';
}
else print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testmember">'.$langs->trans("LDAPTestSynchroMember").'</a>';
print '<br><br>';
$butlabel=$langs->trans("LDAPTestSynchroMember");
$testlabel='testmember';
$key=$conf->global->LDAP_KEY_MEMBERS;
$dn=$conf->global->LDAP_MEMBER_DN;
$objectclass=$conf->global->LDAP_MEMBER_OBJECT_CLASS;
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
}
if (function_exists("ldap_connect"))
@ -384,8 +381,8 @@ if (function_exists("ldap_connect"))
if ($_GET["action"] == 'testmember')
{
// Creation objet
$adherent=new Adherent($db);
$adherent->initAsSpecimen();
$object=new Adherent($db);
$object->initAsSpecimen();
// Test synchro
$ldap=new Ldap();
@ -393,8 +390,8 @@ if (function_exists("ldap_connect"))
if ($result > 0)
{
$info=$adherent->_load_ldap_info();
$dn=$adherent->_load_ldap_dn($info);
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result2=$ldap->update($dn,$info,$user);
$result3=$ldap->delete($dn);
@ -410,6 +407,7 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
}
else
@ -418,6 +416,7 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKO");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
print "<br>\n";

View File

@ -51,6 +51,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
if (! dolibarr_set_const($db, 'LDAP_USER_DN',$_POST["user"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_USER_OBJECT_CLASS',$_POST["objectclass"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION',$_POST["filterconnection"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++;
if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"])) $error++;
@ -266,17 +267,13 @@ print info_admin($langs->trans("LDAPDescValues"));
*/
if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
print '<br>';
if (! function_exists("ldap_connect"))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$langs->trans("LDAPTestSynchroUser").'</a>';
}
else if (empty($conf->global->LDAP_SERVER_HOST))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('SetupNotComplete').'">'.$langs->trans("LDAPTestSynchroUser").'</a>';
}
else print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testuser">'.$langs->trans("LDAPTestSynchroUser").'</a>';
print '<br><br>';
$butlabel=$langs->trans("LDAPTestSynchroUser");
$testlabel='testuser';
$key=$conf->global->LDAP_KEY_USERS;
$dn=$conf->global->LDAP_USER_DN;
$objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
}
if (function_exists("ldap_connect"))
@ -284,17 +281,19 @@ if (function_exists("ldap_connect"))
if ($_GET["action"] == 'testuser')
{
// Creation objet
$fuser=new User($db);
$fuser->initAsSpecimen();
$object=new User($db);
$object->initAsSpecimen();
// TODO Mutualize code following with other ldap_xxxx.php pages
// Test synchro
$ldap=new Ldap();
$result=$ldap->connect_bind();
if ($result > 0)
{
$info=$fuser->_load_ldap_info();
$dn=$fuser->_load_ldap_dn($info);
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result2=$ldap->update($dn,$info,$user);
$result3=$ldap->delete($dn);
@ -310,6 +309,7 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
}
else
@ -318,8 +318,13 @@ if (function_exists("ldap_connect"))
print '<font class="error">'.$langs->trans("LDAPSynchroKO");
print ': '.$ldap->error;
print '</font><br>';
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
}
print "<br>\n";
print "LDAP input file used for test:<br><br>\n";
print nl2br($ldap->dump_content($dn,$info));
print "\n<br>";
}
}
@ -327,5 +332,4 @@ if (function_exists("ldap_connect"))
$db->close();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -38,18 +38,19 @@ class Conf
{
/** \public */
//! Object with database handler
var $db;
//! Charset for HTML output
var $character_set_client; // UTF8, ISO-8859-1
var $db;
//! Charset for HTML output and for storing data in memory
var $character_set_client='UTF-8'; // UTF-8, ISO-8859-1
var $dol_document_root;
var $monnaie; // Used to store current currency
var $css; // Used to store current css (from theme)
var $css_modules=array();
var $tabs_modules=array();
/**
* \brief Positionne toutes les variables de configuration

View File

@ -36,4 +36,6 @@ WarningBuildScriptNotRunned=Script <b>%s</b> was not yet ran to build graphics,
WarningBookmarkAlreadyExists=A bookmark with this title or this target (URL) already exists.
WarningPassIsEmpty=Warning, database password is empty. This is a security hole. You should add a password to your database and change your conf.php file to reflect this.
ErrorNoAccountancyModuleLoaded=No accountancy module activated
ErrorExportDuplicateProfil=This profil name already exists for this export set.
ErrorExportDuplicateProfil=This profil name already exists for this export set.
ErrorLDAPSetupNotComplete=Dolibarr-LDAP matching is not complete.
ErrorLDAPMakeManualTest=A .ldif file has been generated in directory %s. Try to load it manually from command line to have more informations on errors.

View File

@ -37,3 +37,5 @@ WarningBookmarkAlreadyExists=Un marque-page avec ce titre ou cette destination (
WarningPassIsEmpty=Attention, le mot de passe de la base de donnée Dolibarr est vide. Cela représente une faille de sécurité. Il est recommandé d'ajouter manuellement un mot de passe à la base et de modifier le fichier conf.php pour refléter ce changement.
ErrorNoAccountancyModuleLoaded=Aucun module de comptabilité activé
ErrorExportDuplicateProfil=Ce nom de profil existe déjà pour ce lot d'export.
ErrorLDAPSetupNotComplete=Le matching Dolibarr-LDAP est incomplet.
ErrorLDAPMakeManualTest=Un fichier .ldif a été généré dans le répertoire %s. Essayer de charger ce fichier en manuel depuis la ligne de commande pour plus de détail sur l'erreur.

View File

@ -419,5 +419,4 @@ function security_prepare_head()
return $head;
}
?>

View File

@ -44,10 +44,10 @@ if (! defined('ADODB_DATE_VERSION')) include_once(DOL_DOCUMENT_ROOT."/includes/a
*/
function ValidEmail($address)
{
if (ereg( ".*<(.+)>", $address, $regs)) {
if (eregi(".*<(.+)>", $address, $regs)) {
$address = $regs[1];
}
if (ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|coop|aero|biz|com|edu|gov|info|int|mil|name|net|org)\$",$address))
if (eregi("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|coop|aero|biz|com|edu|gov|info|int|mil|name|net|org)\$",$address))
{
return true;
}

File diff suppressed because it is too large Load Diff

View File

@ -79,6 +79,46 @@ function ldap_prepare_head()
}
/**
* \brief Show button test LDAP synchro
*/
function show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass)
{
global $langs, $conf, $user;
//print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
print '<br>';
if (! function_exists("ldap_connect"))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
}
else if (empty($conf->global->LDAP_SERVER_HOST))
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans('SetupNotComplete').'">'.$butlabel.'</a>';
}
else if (empty($key) || empty($dn) || empty($objectclass))
{
$langs->load("errors");
print '<a class="butActionRefused" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
}
else
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
}
print '<br><br>';
}
/**
* Show an LDAP array in an HTML to records.
*
* @param unknown_type $result Array to show. This array is already encoded into charset_output
* @param unknown_type $level
* @param unknown_type $count
* @param unknown_type $var
* @param unknown_type $hide
* @return unknown
*/
function show_ldap_content($result,$level,$count,$var,$hide=0)
{
global $bc, $conf;
@ -113,8 +153,8 @@ function show_ldap_content($result,$level,$count,$var,$hide=0)
}
else
{
if ($hide) print eregi_replace('.','*',utf8_decode("$val"));
else print utf8_decode($val);
if ($hide) print eregi_replace('.','*',$val);
else print $val;
print '</td></tr>';
}
}

View File

@ -42,8 +42,8 @@ class Translate {
var $cache_labels=array(); // Cache for labels
var $charset_inputfile='ISO-8859-1'; // Codage used by default to encode lang files (used if CHARSET not found in file)
var $charset_output='UTF-8'; // Codage used by default for "trans" method output if $conf->character_set_client not defined (character_set_client in conf.php)
var $charset_inputfile='ISO-8859-1'; // Codage used by default to encode/decode lang files (used if CHARSET not found in file)
var $charset_output='UTF-8'; // Codage used by default for "trans" method output if $conf->character_set_client not defined (should never happen)
/**