From 3608e50b07fa7e3c02029a7b363722976955a903 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Jan 2010 16:26:19 +0000 Subject: [PATCH] Prepare module numberwords --- htdocs/admin/numberwords.php | 181 ++++++++++++++++++ .../install/mysql/migration/2.7.0-2.8.0.sql | 4 + .../install/mysql/tables/llx_c_currencies.sql | 1 + htdocs/langs/en_US/admin.lang | 5 +- htdocs/langs/en_US/main.lang | 2 + htdocs/langs/fr_FR/admin.lang | 5 +- htdocs/langs/fr_FR/main.lang | 2 + htdocs/lib/functions.lib.php | 9 +- htdocs/translate.class.php | 16 +- 9 files changed, 213 insertions(+), 12 deletions(-) create mode 100644 htdocs/admin/numberwords.php diff --git a/htdocs/admin/numberwords.php b/htdocs/admin/numberwords.php new file mode 100644 index 00000000000..a812114990a --- /dev/null +++ b/htdocs/admin/numberwords.php @@ -0,0 +1,181 @@ + + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2007 Rodolphe Quiedeville + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (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 + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file htdocs/admin/numberwords.php + * \ingroup numberwords + * \brief Setup page for numberwords module + * \version $Id$ + */ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/html.formadmin.class.php"); + +if (!$user->admin) +accessforbidden(); + +$langs->load("admin"); +$langs->load("other"); + +$newvaltest=''; +$outputlangs=new Translate('',$conf); +$outputlangs->setDefaultLang($langs->defaultlang); + + +/* + * Actions + */ +if (! empty($_POST["action"]) && $_POST["action"] == 'setlevel') +{ + dolibarr_set_const($db,"SYSLOG_LEVEL",$_POST["level"],'chaine',0,'',0); + dol_syslog("admin/syslog: level ".$_POST["level"]); +} + +if (! empty($_POST["action"]) && $_POST["action"] == 'set') +{ + $optionlogoutput=$_POST["optionlogoutput"]; + if ($optionlogoutput == "syslog") + { + if (defined($_POST["facility"])) + { + // Only LOG_USER supported on Windows + if (! empty($_SERVER["WINDIR"])) $_POST["facility"]='LOG_USER'; + + dolibarr_del_const($db,"SYSLOG_FILE",0); + dolibarr_set_const($db,"SYSLOG_FACILITY",$_POST["facility"],'chaine',0,'',0); + dol_syslog("admin/syslog: facility ".$_POST["facility"]); + } + else + { + print '
'.$langs->trans("ErrorUnknownSyslogConstant",$_POST["facility"]).'
'; + } + } + + if ($optionlogoutput == "file") + { + $filelog=$_POST["filename"]; + $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog); + $file=fopen($filelog,"a+"); + if ($file) + { + fclose($file); + dolibarr_del_const($db,"SYSLOG_FACILITY",0); + dolibarr_set_const($db,"SYSLOG_FILE",$_POST["filename"],'chaine',0,'',0); + dol_syslog("admin/syslog: file ".$_POST["filename"]); + } + else + { + print '
'.$langs->trans("ErrorFailedToOpenFile",$_POST["filename"]).'
'; + } + } +} + +if ($_POST["action"] == 'test' && trim($_POST["value"]) != '') +{ + if ($_POST["lang_id"]) $outputlangs->setDefaultLang($_POST["lang_id"]); + + if ($_POST["level"]) + { + $object->total_ttc=$_POST["value"]; + $source='__TOTAL_TTC_WORDS__'; + } + else + { + $object->number=$_POST["value"]; + $source='__NUMBER_WORDS__'; + } + $newvaltest=make_substitutions($source,array(),$outputlangs,$object); +} + + + +/* + * View + */ + +llxHeader(); + +$html=new Form($db); +$htmlother=new FormAdmin($db); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("NumberWordsSetup"),$linkback,'setup'); + +print $langs->trans("DescNumberWords").'
'; +print '
'; + +// Mode +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +$var=true; + +$var=!$var; +print ''; +$val='989'; +print ''; +print ''; +print ''; +$object->number=$val; +$newval=make_substitutions('__NUMBER_WORDS__',array(),$outputlangs,$object); +print ''; + +$var=!$var; +print ''; +$val='989.99'; +print ''; +print ''; +print ''; +$object->total_ttc=$val; +$newval=make_substitutions('__TOTAL_TTC_WORDS__',array(),$outputlangs,$object); +print ''; + +$var=!$var; +print ''; +$val=$_POST["level"]; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print '
'.$langs->trans("Example").''.$langs->trans("Value").''.$langs->trans("Language").' '.$langs->trans("Result").'
'.$langs->trans("Number").''.$val.''.$outputlangs->defaultlang.' '.$newval.'
'.$langs->trans("Amount").''.$val.''.$outputlangs->defaultlang.' '.$newval.'
'; +print ''; +$htmlother->select_lang($_POST["lang_id"]?$_POST["lang_id"]:$langs->defaultlang,'lang_id'); +print ''.$newvaltest.'
'; + +print "
\n"; + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/install/mysql/migration/2.7.0-2.8.0.sql b/htdocs/install/mysql/migration/2.7.0-2.8.0.sql index 8b9060aedb7..502fd90999b 100755 --- a/htdocs/install/mysql/migration/2.7.0-2.8.0.sql +++ b/htdocs/install/mysql/migration/2.7.0-2.8.0.sql @@ -35,6 +35,10 @@ ALTER TABLE llx_projet ADD COLUMN datee DATE AFTER dateo; ALTER TABLE llx_notify ADD COLUMN email VARCHAR(255); +ALTER TABLE llx_c_currencies ADD COLUMN labelsing varchar(64); +update llx_c_currencies set labelsing='Euro' where code_iso='EUR'; +update llx_c_currencies set labelsing='Dollar' where code_iso='USD'; + insert into llx_action_def (rowid,code,titre,description,objet_type) values (5,'NOTIFY_VAL_ORDER','Validation commande client','Executed when a customer order is validated','order'); insert into llx_action_def (rowid,code,titre,description,objet_type) values (6,'NOTIFY_VAL_PROPAL','Validation proposition client','Executed when a commercial proposal is validated','propal'); diff --git a/htdocs/install/mysql/tables/llx_c_currencies.sql b/htdocs/install/mysql/tables/llx_c_currencies.sql index fde0796a532..ddb45efe949 100644 --- a/htdocs/install/mysql/tables/llx_c_currencies.sql +++ b/htdocs/install/mysql/tables/llx_c_currencies.sql @@ -23,6 +23,7 @@ create table llx_c_currencies code varchar(2) PRIMARY KEY, code_iso varchar(3) NOT NULL, label varchar(64), + labelsing varchar(64), active tinyint DEFAULT 1 NOT NULL )type=innodb; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index e99221b3aa0..f897ec3e41c 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1144,4 +1144,7 @@ PathToGeoIPMaxmindCountryDataFile=Path to file containing Maxmind ip to country NoteOnPathLocation=Note that your ip to country data file must be inside a directory your PHP can read (Check your PHP open_basedir setup and filesystem permissions). YouCanDownloadFreeDatFileTo=You can download a free demo version of the Maxmind GeoIP country file at %s. YouCanDownloadAdvancedDatFileTo=You can also download a more complete version, with updates, of the Maxmind GeoIP country file at %s. -TestGeoIPResult=Test of a conversion IP -> country \ No newline at end of file +TestGeoIPResult=Test of a conversion IP -> country +##### NumberWords ##### +NumberWordsSetup=NumberWords module setup +DescNumberWords=This module provide functions to convert number or amount in full characters. It will also replace the following string occurences __TOTAL_TTC_WORDS__, __TOTAL_HT_WORDS__ or __TOTAL_VAT_WORDS__ by total incl. tax, total net of tax, or total of vat into all textes that use them (free text on invoices, ...) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index f134e8d680c..74b30dbaada 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -549,6 +549,8 @@ AccordingToGeoIPDatabase=(according to GeoIP convertion) Line=Line NotSupported=Not supported RequiredField=Required field +Result=Result +ToTest=Test # Week day Day1=Monday diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index e7be7d39715..1f5dae03b0c 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1145,4 +1145,7 @@ PathToGeoIPMaxmindCountryDataFile=Chemin du fichier Maxmind contenant les conver NoteOnPathLocation=Notez que ce fichier doit etre dans un répertoire accessible à votre PHP (Vérifiez le paramètre open_basedir de votre PHP et les permissions du fichier/répertoires). YouCanDownloadFreeDatFileTo=Vous pouvez téléchargez une version demo gratuite de la base Maxmind à l'adresse %s. YouCanDownloadAdvancedDatFileTo=Vous pouvez aussi télécharger une version plus complète avec mise à jours de la base Maxmind à l'adresse %s. -TestGeoIPResult=Test de conversion IP -> Pays \ No newline at end of file +TestGeoIPResult=Test de conversion IP -> Pays +##### NumberWords ##### +NumberWordsSetup=Configuration du module NumberWords +DescNumberWords=Ce module amène des fonctions de convertion de nombre ou montant en toute chaine. Il effectue aussi des remplacements de variables génériques __TOTAL_TTC_WORDS__, __TOTAL_HT_WORDS__ ou __TOTAL_VAT_WORDS__ par leur valeur du montant ttc, ht ou de la tva, en chaine dans les textes qui y font référence (texte libre des factures, ...) diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 78f5a00249a..5cc66d8d5c1 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -548,6 +548,8 @@ AccordingToGeoIPDatabase=(obtenu par conversion GeoIP) Line=Ligne NotSupported=Non supporté RequiredField=Champ obligatoire +Result=Résultat +ToTest=Tester # Week day Day1=Lundi diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index f634d843422..2afaa59d870 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2952,11 +2952,14 @@ function dol_textishtml($msg,$option=0) } /** - * \brief Add substitution required by external modules then make substitutions in array substitutionarray + * \brief Add substitution required by external modules then make substitutions. + * There is two type of substitions: + * From substitutionarray (oldval=>newval) + * From special constants (__XXX__=>f(objet->xxx)) * \param chaine Source string in which we must do substitution * \param substitutionarray Array substitution old value => new value value - * \param outputlangs If we want to add more substitution, we provide a language - * \param object If we want to add more substitution, we provide a source object + * \param outputlangs If we want substitution from special constants, we provide a language + * \param object If we want substitution from special constants, we provide data in a source object * \return string Output string after subsitutions */ function make_substitutions($chaine,$substitutionarray,$outputlangs,$object='') diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php index c1b943075f8..1dd1f322c42 100644 --- a/htdocs/translate.class.php +++ b/htdocs/translate.class.php @@ -194,12 +194,12 @@ class Translate { if ($filelangexists) { $found=false; - + // Enable cache of lang file in memory (faster but need more memory) // Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) $enablelangcacheinmemory=empty($conf->global->MAIN_OPTIMIZE_SPEED)?0:$conf->global->MAIN_OPTIMIZE_SPEED; //$enablelangcacheinmemory=true; - + if ($alt == 2 && $enablelangcacheinmemory) { require_once(DOL_DOCUMENT_ROOT ."/lib/memory.lib.php"); @@ -220,7 +220,7 @@ class Translate { if ($fp = @fopen($file_lang,"rt")) { if ($enablelangcacheinmemory) $tabtranslatedomain=array(); // To save lang in session - + while ($ligne = fgets($fp,4096)) // Ex: Need 225ms for all fgets on all lang file for Third party page. Same speed than file_get_contents { if ($ligne[0] != "\n" && $ligne[0] != " " && $ligne[0] != "#") @@ -261,7 +261,7 @@ class Translate { } fclose($fp); $fileread=1; - + // To save lang in session if ($alt == 2 && $enablelangcacheinmemory && sizeof($tabtranslatedomain)) { @@ -315,9 +315,9 @@ class Translate { if (empty($this->tab_loaded[$newdomain])) $this->tab_loaded[$newdomain]=2; // Marque ce fichier comme non trouve } - // Clear SeparatorDecimal, SeparatorThousand + // Clear SeparatorDecimal, SeparatorThousand if (! empty($this->tab_translate["SeparatorDecimal"]) && ! empty($this->tab_translate["SeparatorThousand"]) - && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) $this->tab_translate["SeparatorThousand"]=''; + && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) $this->tab_translate["SeparatorThousand"]=''; return 1; } @@ -547,7 +547,7 @@ class Translate { { if (is_readable(dol_osencode($searchdir."/langs/".$this->defaultlang."/".$filename))) return true; - if ($searchalt) + if ($searchalt) { // Test si fichier dans repertoire de la langue alternative if ($this->defaultlang != "en_US") $filenamealt = $searchdir."/langs/en_US/".$filename; @@ -574,10 +574,12 @@ class Translate { { global $conf; + /* $outlang=$this->defaultlang; // Output language we want $outlangarray=explode('_',$outlang,2); // If lang is xx_XX, then we use xx if (strtolower($outlangarray[0]) == strtolower($outlangarray[1])) $outlang=$outlangarray[0]; + */ $newnumber=$number; foreach ($conf->file->dol_document_root as $dirroot)