From 9ad62d0f66218483d099d26f6a4a76cb29b59700 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Aug 2009 17:58:25 +0000 Subject: [PATCH] New: Enhance log reports New: Add a warning if email syntaxt is not valid Fix: Synchro of contact to a LDAP --- htdocs/contact/fiche.php | 2 + htdocs/lib/functions.lib.php | 38 ++++++++++++++++--- htdocs/lib/functions2.lib.php | 21 ---------- .../company/sync_contacts_dolibarr2ldap.php | 1 + 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 8fcd3afcc6f..dd24431599d 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -393,6 +393,7 @@ if ($user->rights->societe->contact->creer) print ''.$langs->trans("PhoneMobile").''; print ''.$langs->trans("Fax").''; + // EMail print ''.$langs->trans("EMail").''; if ($conf->mailing->enabled) { @@ -547,6 +548,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit') print ''.$langs->trans("PhoneMobile").''.dol_print_phone($contact->phone_mobile,$contact->pays_code,$contact->id,$contact->socid,'AC_TEL').''; print ''.$langs->trans("Fax").''.dol_print_phone($contact->fax,$contact->pays_code,$contact->id,$contact->socid,'AC_FAX').''; + // Email print ''.$langs->trans("EMail").''.dol_print_email($contact->email,$contact->id,$contact->socid,'AC_EMAIL').''; if ($conf->mailing->enabled) { diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 84c502023d0..d195c58ddbb 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -206,8 +206,12 @@ function dol_syslog($message, $level=LOG_INFO) if ($message != $langs->trans($message)) $message = $langs->trans($message); } + // Add page/script name to log message + $script=isset($_SERVER['PHP_SELF'])?basename($_SERVER['PHP_SELF'],'.php').' ':''; + $message=$script.$message; + // Add user to log message - $login='???'; + $login=isset($_SERVER['USERNAME'])?$_SERVER['USERNAME']:'nologin'; if (is_object($user) && $user->id) $login=$user->login; $message=sprintf("%-8s",$login)." ".$message; @@ -221,15 +225,14 @@ function dol_syslog($message, $level=LOG_INFO) if ($file) { - - $ip='unknown_ip'; + $ip=$_SERVER['COMPUTERNAME']; if (! empty($_SERVER["REMOTE_ADDR"])) $ip=$_SERVER["REMOTE_ADDR"]; $liblevelarray=array(LOG_ERR=>'ERROR',LOG_WARNING=>'WARN',LOG_INFO=>'INFO',LOG_DEBUG=>'DEBUG'); $liblevel=$liblevelarray[$level]; if (! $liblevel) $liblevel='UNDEF'; - $message=strftime("%Y-%m-%d %H:%M:%S",time())." ".sprintf("%-5s",$liblevel)." ".$ip." ".$message; + $message=strftime("%Y-%m-%d %H:%M:%S",time())." ".sprintf("%-5s",$liblevel)." ".sprintf("%-15s",$ip)." ".$message; fwrite($file,$message."\n"); fclose($file); @@ -692,14 +695,14 @@ function dol_print_url($url,$target='_blank',$max=32) /** * \brief Show EMail link - * \param email EMail to show + * \param email EMail to show (only email without ) * \param cid Id of contact if known * \param socid Id of third party if known * \param addlink 0=no link to create action * \param max Max number of characters to show * \return string HTML Link */ -function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64) +function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64,$showinvalid=1) { global $conf,$user,$langs; @@ -715,6 +718,7 @@ function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64) $newemail.='">'; $newemail.=dol_trunc($email,$max); $newemail.=''; + if ($showinvalid && ! isValidEmail($email)) $newemail.=img_warning($langs->trans("ErrorBadEMail",$email)); if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create) { @@ -801,6 +805,28 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ= return $newphone; } +/** + * \brief Return true if email syntax is ok + * \param address email (Ex: "toto@titi.com", "John Do ") + * \return boolean true if email syntax is OK, false if KO + */ +function isValidEmail($address) +{ + if (eregi(".*<(.+)>", $address, $regs)) { + $address = $regs[1]; + } + // 2 letters domains extensions are for countries + // 3 letters domains extensions: biz|com|edu|gov|int|mil|net|org|pro|... + if (eregi("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2,3}|asso|aero|coop|info|name)\$",$address)) + { + return true; + } + else + { + return false; + } +} + /** * Make a strlen call. Works even in mbstring module not enabled diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php index 4585af5a788..716fe8e7e0c 100644 --- a/htdocs/lib/functions2.lib.php +++ b/htdocs/lib/functions2.lib.php @@ -203,27 +203,6 @@ function dol_print_object_info($object) } -/** - * \brief Return true if email syntax is ok - * \param address email (Ex: "toto@titi.com", "John Do ") - * \return boolean true if email syntax is OK, false if KO - */ -function isValidEmail($address) -{ - if (eregi(".*<(.+)>", $address, $regs)) { - $address = $regs[1]; - } - // 3 letters domains extensions: biz|com|edu|gov|int|mil|net|org|pro - if (eregi("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2,3}|asso|aero|coop|info|name)\$",$address)) - { - return true; - } - else - { - return false; - } -} - /** * \brief Return true if email has a domain name that can't be resolved * \param mail adresse email (Ex: "toto@titi.com", "John Do ") diff --git a/scripts/company/sync_contacts_dolibarr2ldap.php b/scripts/company/sync_contacts_dolibarr2ldap.php index affd1e9cda1..e3001859e95 100644 --- a/scripts/company/sync_contacts_dolibarr2ldap.php +++ b/scripts/company/sync_contacts_dolibarr2ldap.php @@ -47,6 +47,7 @@ $path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]); require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/user.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/ldap.class.php"); $error=0;