Prepare module numberwords

This commit is contained in:
Laurent Destailleur 2010-01-13 16:26:19 +00:00
parent bb4ed2f9ab
commit 3608e50b07
9 changed files with 213 additions and 12 deletions

View File

@ -0,0 +1,181 @@
<?php
/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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 '<div class="error">'.$langs->trans("ErrorUnknownSyslogConstant",$_POST["facility"]).'</div>';
}
}
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 '<div class="error">'.$langs->trans("ErrorFailedToOpenFile",$_POST["filename"]).'</div>';
}
}
}
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='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("NumberWordsSetup"),$linkback,'setup');
print $langs->trans("DescNumberWords").'<br>';
print '<br>';
// Mode
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="test">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Example").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td>'.$langs->trans("Language").'</td>';
print '<td>&nbsp;</td>';
print '<td>'.$langs->trans("Result").'</td>';
print "</tr>\n";
$var=true;
$var=!$var;
print '<tr '.$bc[$var].'><td width="140">'.$langs->trans("Number").'</td>';
$val='989';
print '<td>'.$val.'</td>';
print '<td>'.$outputlangs->defaultlang.'</td>';
print '<td>&nbsp;</td>';
$object->number=$val;
$newval=make_substitutions('__NUMBER_WORDS__',array(),$outputlangs,$object);
print '<td>'.$newval.'</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td width="140">'.$langs->trans("Amount").'</td>';
$val='989.99';
print '<td>'.$val.'</td>';
print '<td>'.$outputlangs->defaultlang.'</td>';
print '<td>&nbsp;</td>';
$object->total_ttc=$val;
$newval=make_substitutions('__TOTAL_TTC_WORDS__',array(),$outputlangs,$object);
print '<td>'.$newval.'</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'>';
$val=$_POST["level"];
print '<td><select class="flat" name="level" '.$option.'>';
print '<option value="0" '.($_POST["level"]=='0'?'SELECTED':'').'>'.$langs->trans("Number").'</option>';
print '<option value="1" '.($_POST["level"]=='1'?'SELECTED':'').'>'.$langs->trans("Amount").'</option>';
print '</select>';
print '</td>';
print '<td><input type="text" name="value" class="flat" value="'.$_POST["value"].'"></td>';
print '<td>';
$htmlother->select_lang($_POST["lang_id"]?$_POST["lang_id"]:$langs->defaultlang,'lang_id');
print '</td>';
print '<td><input type="submit" class="button" '.$option.' value="'.$langs->trans("ToTest").'"></td>';
print '<td>'.$newvaltest.'</td>';
print '</tr>';
print '</table>';
print "</form>\n";
llxFooter('$Date$ - $Revision$');
?>

View File

@ -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');

View File

@ -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;

View File

@ -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 <b>free demo version</b> of the Maxmind GeoIP country file at %s.
YouCanDownloadAdvancedDatFileTo=You can also download a more <b>complete version, with updates,</b> of the Maxmind GeoIP country file at %s.
TestGeoIPResult=Test of a conversion IP -> country
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, ...)

View File

@ -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

View File

@ -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 <b>version demo gratuite</b> de la base Maxmind à l'adresse %s.
YouCanDownloadAdvancedDatFileTo=Vous pouvez aussi télécharger une <b>version plus complète avec mise à jours</b> de la base Maxmind à l'adresse %s.
TestGeoIPResult=Test de conversion IP -> Pays
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, ...)

View File

@ -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

View File

@ -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='')

View File

@ -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)