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_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 (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'); 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 varchar(2) PRIMARY KEY,
code_iso varchar(3) NOT NULL, code_iso varchar(3) NOT NULL,
label varchar(64), label varchar(64),
labelsing varchar(64),
active tinyint DEFAULT 1 NOT NULL active tinyint DEFAULT 1 NOT NULL
)type=innodb; )type=innodb;

View File

@ -1145,3 +1145,6 @@ NoteOnPathLocation=Note that your ip to country data file must be inside a direc
YouCanDownloadFreeDatFileTo=You can download a <b>free demo version</b> of the Maxmind GeoIP country file at %s. 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. 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 Line=Line
NotSupported=Not supported NotSupported=Not supported
RequiredField=Required field RequiredField=Required field
Result=Result
ToTest=Test
# Week day # Week day
Day1=Monday Day1=Monday

View File

@ -1146,3 +1146,6 @@ NoteOnPathLocation=Notez que ce fichier doit etre dans un répertoire accessible
YouCanDownloadFreeDatFileTo=Vous pouvez téléchargez une <b>version demo gratuite</b> de la base Maxmind à l'adresse %s. 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. 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 Line=Ligne
NotSupported=Non supporté NotSupported=Non supporté
RequiredField=Champ obligatoire RequiredField=Champ obligatoire
Result=Résultat
ToTest=Tester
# Week day # Week day
Day1=Lundi 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 chaine Source string in which we must do substitution
* \param substitutionarray Array substitution old value => new value value * \param substitutionarray Array substitution old value => new value value
* \param outputlangs If we want to add more substitution, we provide a language * \param outputlangs If we want substitution from special constants, we provide a language
* \param object If we want to add more substitution, we provide a source object * \param object If we want substitution from special constants, we provide data in a source object
* \return string Output string after subsitutions * \return string Output string after subsitutions
*/ */
function make_substitutions($chaine,$substitutionarray,$outputlangs,$object='') function make_substitutions($chaine,$substitutionarray,$outputlangs,$object='')

View File

@ -574,10 +574,12 @@ class Translate {
{ {
global $conf; global $conf;
/*
$outlang=$this->defaultlang; // Output language we want $outlang=$this->defaultlang; // Output language we want
$outlangarray=explode('_',$outlang,2); $outlangarray=explode('_',$outlang,2);
// If lang is xx_XX, then we use xx // If lang is xx_XX, then we use xx
if (strtolower($outlangarray[0]) == strtolower($outlangarray[1])) $outlang=$outlangarray[0]; if (strtolower($outlangarray[0]) == strtolower($outlangarray[1])) $outlang=$outlangarray[0];
*/
$newnumber=$number; $newnumber=$number;
foreach ($conf->file->dol_document_root as $dirroot) foreach ($conf->file->dol_document_root as $dirroot)