* 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 3 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, see . * or see http://www.gnu.org/ */ /** * \file htdocs/numberwords/admin/numberwords.php * \ingroup numberwords * \brief Setup page for numberwords module */ // Load Dolibarr environment $res=0; // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; // Try main.inc.php into web root detected using web root caluclated from SCRIPT_FILENAME $tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; } if (! $res && $i > 0 && @file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include substr($tmp, 0, ($i+1))."/main.inc.php"; if (! $res && $i > 0 && @file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include dirname(substr($tmp, 0, ($i+1)))."/main.inc.php"; // Try main.inc.php using relative path if (! $res && file_exists("../../main.inc.php")) $res=@include "../../main.inc.php"; if (! $res && file_exists("../../../main.inc.php")) $res=@include "../../../main.inc.php"; if (! $res) die("Include of main fails"); require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; require_once DOL_DOCUMENT_ROOT."/core/class/html.formadmin.class.php"; if (!$user->admin) accessforbidden(); $langs->load("admin"); $langs->load("other"); $langs->load("numberwords@numberwords"); $newvaltest=''; $outputlangs=new Translate('', $conf); $outputlangs->setDefaultLang($langs->defaultlang); $action=GETPOST('action', 'aZ09'); $value=GETPOST('value', 'nohtml'); $valuetest=GETPOST('valuetest', 'nohtml'); $level=GETPOST('level', 'int'); if (!isModEnabled("numberwords")) { print "Error: Module is not enabled\n"; exit; } /* * Actions */ // Activate a model if ($action == 'set') { $ret = dolibarr_set_const($db, $value, 1, 'chaine', 0, '', $conf->entity); } elseif ($action == 'del') { $ret = dolibarr_del_const($db, $value, $conf->entity); } if ($action == 'test') { if (trim($valuetest) == '') { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Example")), 'errors'); } else { if ($_POST["lang_id"]) $outputlangs->setDefaultLang($_POST["lang_id"]); $object = new StdClass(); $object->id = 1; if ($level) { $object->total_ttc=price2num($valuetest); $source='__AMOUNT_TEXT__'; } else { $object->number=price2num($valuetest); $source='__NUMBER_WORDS__'; } $substitutionarray=array(); complete_substitutions_array($substitutionarray, $outputlangs, $object); $newvaltest=make_substitutions($source, $substitutionarray); } } /* * View */ $htmlother=new FormAdmin($db); llxHeader(); $object = new stdClass(); $object->id = 1; $object->number = '989'; $object->total_ht = '824.99'; $object->total_ttc = '989.99'; $object->total_tva = '165.00'; $object->multicurrency_total_ht = '824.99'; $object->multicurrency_total_ttc = '989.99'; $object->multicurrency_total_tva = '165.00'; $object->multicurrency_code = $conf->currency; $substitutionarray=array(); complete_substitutions_array($substitutionarray, $outputlangs, $object); $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("NumberWordsSetup"), $linkback, 'setup'); print ''.$langs->trans("DescNumberWords").'
'; print '
'; $h=0; $head[$h][0] = $_SERVER["PHP_SELF"]; $head[$h][1] = $langs->trans("Setup"); $head[$h][2] = 'tabsetup'; $h++; $head[$h][0] = 'about.php'; $head[$h][1] = $langs->trans("About"); $head[$h][2] = 'tababout'; $h++; dol_fiche_head($head, 'tabsetup', '', (((float) DOL_VERSION <= 8)?0:-1)); // Mode print '
'; print ''; print ''; print $langs->trans("NUMBERWORDS_USE_CURRENCY_SYMBOL").' '; // Active if (! empty($conf->global->NUMBERWORDS_USE_CURRENCY_SYMBOL)) { print ''; print img_picto($langs->trans("Enabled"), 'switch_on'); print ''; print '
'; print $langs->trans("NUMBERWORDS_USE_ADD_SHORTCODE_WITH_SYMBOL").' '; // Active if (! empty($conf->global->NUMBERWORDS_USE_ADD_SHORTCODE_WITH_SYMBOL)) { print ''; print img_picto($langs->trans("Enabled"), 'switch_on'); print ''; } else { print '' . img_picto($langs->trans("Disabled"), 'switch_off') . ''; } } else { print '' . img_picto($langs->trans("Disabled"), 'switch_off') . ''; } print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; print ''; print ''; print ''; $newval=make_substitutions('__NUMBER_WORDS__', $substitutionarray); print ''; print ''; print ''; print ''; print ''; $newval=make_substitutions('__AMOUNT_TEXT__', $substitutionarray); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Type").''.$langs->trans("Example").''.$langs->trans("Language").' '.$langs->trans("Result").'
'.$langs->trans("Number").''.$object->number.''.$outputlangs->defaultlang.' '.$newval.'
'.$langs->trans("Amount").''.$object->total_ttc.''.$outputlangs->defaultlang.' '.$newval.'
'; print ''; print $htmlother->select_language(GETPOST('lang_id', 'alpha')?GETPOST('lang_id', 'alpha'):$langs->defaultlang, 'lang_id'); print ''.$newvaltest.''; print '
'; print "
\n"; dol_fiche_end(); // Warning on accurancy list($whole, $decimal) = explode('.', $value); if ($level) { if (strlen($decimal) > $conf->global->MAIN_MAX_DECIMALS_TOT) { print ''.$langs->trans("Note").': '.$langs->trans("MAIN_MAX_DECIMALS_TOT").': ' . getDolGlobalString('MAIN_MAX_DECIMALS_TOT').''; print ' - '.$langs->trans("SetupToChange").''; } else { print ''.$langs->trans("Note").': '.$langs->trans("MAIN_MAX_DECIMALS_TOT").': ' . getDolGlobalString('MAIN_MAX_DECIMALS_TOT').''; print ' - '.$langs->trans("SetupToChange").''; } } print '
'; print ''.$langs->trans("CompanyCurrency").': '.$conf->currency.''; print ' - '.$langs->trans("SetupToChange").''; llxFooter(); $db->close();