From abe025686bfe1bcec496b0fc0042dd60ebb13157 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 20 Apr 2008 04:31:31 +0000 Subject: [PATCH] Qual: Move graphic thermometer function to images.lib.php library. --- htdocs/lib/images.lib.php | 159 ++++++++++++++++++++++++++++ htdocs/lib/thermometer.php | 198 ----------------------------------- htdocs/public/dons/therm.php | 87 ++++----------- 3 files changed, 181 insertions(+), 263 deletions(-) delete mode 100644 htdocs/lib/thermometer.php diff --git a/htdocs/lib/images.lib.php b/htdocs/lib/images.lib.php index d32095635c5..49984407c2e 100644 --- a/htdocs/lib/images.lib.php +++ b/htdocs/lib/images.lib.php @@ -241,4 +241,163 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $ return $imgThumbName; } + +/** + \brief permet d'afficher un thermometre monetaire. + \param actualValue + \param pendingValue + \param intentValue + \return thermometer htmlLegenda + This function returns the html for the moneymeter. + cachedValue: amount of actual money + pendingValue: amount of money of pending memberships + intentValue: amount of intended money (that's without the amount of actual money) +*/ +function moneyMeter($actualValue=0, $pendingValue=0, $intentValue=0) +{ + + // variables + $height="200"; + $maximumValue=125000; + + $imageDir = "http://eucd.info/images/"; + + $imageTop = $imageDir . "therm_top.png"; + $imageMiddleActual = $imageDir . "therm_actual.png"; + $imageMiddlePending = $imageDir . "therm_pending.png"; + $imageMiddleIntent = $imageDir . "therm_intent.png"; + $imageMiddleGoal = $imageDir . "therm_goal.png"; + $imageIndex = $imageDir . "therm_index.png"; + $imageBottom = $imageDir . "therm_bottom.png"; + $imageColorActual = $imageDir . "therm_color_actual.png"; + $imageColorPending = $imageDir . "therm_color_pending.png"; + $imageColorIntent = $imageDir . "therm_color_intent.png"; + + $htmlThermTop = ' + + + +
+ + + + + + + + + + + +
+ '; + + $htmlSection = ' + '; + + $htmlThermbottom = ' +
+
+
'; + + // legenda + + $legendaActual = "€ " . round($actualValue); + $legendaPending = "€ " . round($pendingValue); + $legendaIntent = "€ " . round($intentValue); + $legendaTotal = "€ " . round($actualValue + $pendingValue + $intentValue); + $htmlLegenda = ' + + + + + + +
 Payé:
' . $legendaActual . '
 En attente:
' . $legendaPending . '
 Promesses:
' . $legendaIntent . '
 Total:
' . $legendaTotal . '
+ + '; + + // check and edit some values + + $error = 0; + if ( $maximumValue <= 0 || $height <= 0 || $actualValue < 0 || $pendingValue < 0 || $intentValue < 0) + { + return "The money meter could not be processed
\n"; + } + if ( $actualValue > $maximumValue ) + { + $actualValue = $maximumValue; + $pendingValue = 0; + $intentValue = 0; + } + else + { + if ( ($actualValue + $pendingValue) > $maximumValue ) + { + $pendingValue = $maximumValue - $actualValue; + $intentValue = 0; + } + else + { + if ( ($actualValue + $pendingValue + $intentValue) > $maximumValue ) + { + $intentValue = $maximumValue - $actualValue - $pendingValue; + } + } + } + + // start writing the html (from bottom to top) + + // bottom + $thermometer = $htmlThermbottom; + + // actual + $sectionHeight = round(($actualValue / $maximumValue) * $height); + $totalHeight = $totalHeight + $sectionHeight; + if ( $sectionHeight > 0 ) + { + $section = $htmlSection; + $section = str_replace("{image}", $imageMiddleActual, $section); + $section = str_replace("{height}", $sectionHeight, $section); + $thermometer = $section . $thermometer; + } + + // pending + $sectionHeight = round(($pendingValue / $maximumValue) * $height); + $totalHeight = $totalHeight + $sectionHeight; + if ( $sectionHeight > 0 ) + { + $section = $htmlSection; + $section = str_replace("{image}", $imageMiddlePending, $section); + $section = str_replace("{height}", $sectionHeight, $section); + $thermometer = $section . $thermometer; + } + + // intent + $sectionHeight = round(($intentValue / $maximumValue) * $height); + $totalHeight = $totalHeight + $sectionHeight; + if ( $sectionHeight > 0 ) + { + $section = $htmlSection; + $section = str_replace("{image}", $imageMiddleIntent, $section); + $section = str_replace("{height}", $sectionHeight, $section); + $thermometer = $section . $thermometer; + } + + // goal + $sectionHeight = $height- $totalHeight; + if ( $sectionHeight > 0 ) + { + $section = $htmlSection; + $section = str_replace("{image}", $imageMiddleGoal, $section); + $section = str_replace("{height}", $sectionHeight, $section); + $thermometer = $section . $thermometer; + } + + // top + $thermometer = $htmlThermTop . $thermometer; + + return $thermometer . $htmlLegenda; +} + ?> diff --git a/htdocs/lib/thermometer.php b/htdocs/lib/thermometer.php deleted file mode 100644 index 860dabc5f48..00000000000 --- a/htdocs/lib/thermometer.php +++ /dev/null @@ -1,198 +0,0 @@ - - * - * 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. - * - * $Id$ - * $Source$ - * - */ - - /*! \file htdocs/lib/thermometer.php - \brief Classe permettant d'afficher un thermometre. - \author Rodolphe Quiedeville. - \author Timothy Kanters. - \version $Revision$ - - Ensemble des fonctions permettant d'afficher un thermometre monetaire. -*/ - - -/*! - \brief permet d'afficher un thermometre monetaire. - \param actualValue - \param pendingValue - \param intentValue - \return thermometer htmlLegenda -*/ -function moneyMeter($actualValue=0, $pendingValue=0, $intentValue=0) - - /* - This function returns the html for the moneymeter. - cachedValue: amount of actual money - pendingValue: amount of money of pending memberships - intentValue: amount of intended money (that's without the amount of actual money) - */ -{ - - // variables - $height="200"; - $maximumValue=125000; - - $imageDir = "http://eucd.info/images/"; - - $imageTop = $imageDir . "therm_top.png"; - $imageMiddleActual = $imageDir . "therm_actual.png"; - $imageMiddlePending = $imageDir . "therm_pending.png"; - $imageMiddleIntent = $imageDir . "therm_intent.png"; - $imageMiddleGoal = $imageDir . "therm_goal.png"; - $imageIndex = $imageDir . "therm_index.png"; - $imageBottom = $imageDir . "therm_bottom.png"; - $imageColorActual = $imageDir . "therm_color_actual.png"; - $imageColorPending = $imageDir . "therm_color_pending.png"; - $imageColorIntent = $imageDir . "therm_color_intent.png"; - - $htmlThermTop = ' - - - -
- - - - - - - - - - - -
- '; - - $htmlSection = ' - '; - - $htmlThermbottom = ' -
-
-
'; - - // legenda - - $legendaActual = "€ " . round($actualValue); - $legendaPending = "€ " . round($pendingValue); - $legendaIntent = "€ " . round($intentValue); - $legendaTotal = "€ " . round($actualValue + $pendingValue + $intentValue); - $htmlLegenda = ' - - - - - - -
 Payé:
' . $legendaActual . '
 En attente:
' . $legendaPending . '
 Promesses:
' . $legendaIntent . '
 Total:
' . $legendaTotal . '
- - '; - - // check and edit some values - - $error = 0; - if ( $maximumValue <= 0 || $height <= 0 || $actualValue < 0 || $pendingValue < 0 || $intentValue < 0) - { - return "The money meter could not be processed
\n"; - } - if ( $actualValue > $maximumValue ) - { - $actualValue = $maximumValue; - $pendingValue = 0; - $intentValue = 0; - } - else - { - if ( ($actualValue + $pendingValue) > $maximumValue ) - { - $pendingValue = $maximumValue - $actualValue; - $intentValue = 0; - } - else - { - if ( ($actualValue + $pendingValue + $intentValue) > $maximumValue ) - { - $intentValue = $maximumValue - $actualValue - $pendingValue; - } - } - } - - // start writing the html (from bottom to top) - - // bottom - $thermometer = $htmlThermbottom; - - // actual - $sectionHeight = round(($actualValue / $maximumValue) * $height); - $totalHeight = $totalHeight + $sectionHeight; - if ( $sectionHeight > 0 ) - { - $section = $htmlSection; - $section = str_replace("{image}", $imageMiddleActual, $section); - $section = str_replace("{height}", $sectionHeight, $section); - $thermometer = $section . $thermometer; - } - - // pending - $sectionHeight = round(($pendingValue / $maximumValue) * $height); - $totalHeight = $totalHeight + $sectionHeight; - if ( $sectionHeight > 0 ) - { - $section = $htmlSection; - $section = str_replace("{image}", $imageMiddlePending, $section); - $section = str_replace("{height}", $sectionHeight, $section); - $thermometer = $section . $thermometer; - } - - // intent - $sectionHeight = round(($intentValue / $maximumValue) * $height); - $totalHeight = $totalHeight + $sectionHeight; - if ( $sectionHeight > 0 ) - { - $section = $htmlSection; - $section = str_replace("{image}", $imageMiddleIntent, $section); - $section = str_replace("{height}", $sectionHeight, $section); - $thermometer = $section . $thermometer; - } - - // goal - $sectionHeight = $height- $totalHeight; - if ( $sectionHeight > 0 ) - { - $section = $htmlSection; - $section = str_replace("{image}", $imageMiddleGoal, $section); - $section = str_replace("{height}", $sectionHeight, $section); - $thermometer = $section . $thermometer; - } - - // top - $thermometer = $htmlThermTop . $thermometer; - - return $thermometer . $htmlLegenda; -} - -?> - - - diff --git a/htdocs/public/dons/therm.php b/htdocs/public/dons/therm.php index 94332b80804..1b7c5b377d7 100644 --- a/htdocs/public/dons/therm.php +++ b/htdocs/public/dons/therm.php @@ -1,5 +1,6 @@ + * Copyright (C) 2008 Laurent Destailleur * * 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 @@ -14,78 +15,34 @@ * 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. - * - * $Id$ */ -$thermlib = "../../lib/thermometer.php"; +/** + \file htdocs/public/dons/therm.php + \ingroup donation + \brief Screen with thermometer + \version $Id$ +*/ -if (file_exists ($thermlib)) -{ - include($thermlib); - - if (1) - { +require("../../master.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php"); - $dons_file = "/var/run/dolibarr.don.eucd"; +/* +* Read Values +*/ +$dontherm = new Don($db); + +$intentValue = $dontherm->sum_donations(1); +$pendingValue = $dontherm->sum_donations(2); +$actualValue = $dontherm->sum_donations(3); - /* - * Read Values - */ - - if (file_exists ($dons_file)) - { - - $fp = fopen($dons_file, 'r' ); - - - if ($fp) - { - $intentValue = fgets( $fp, 10 ); - $pendingValue = fgets( $fp, 10 ); - $actualValue = fgets( $fp, 10 ); - fclose( $fp ); - } - - } - - } - else - { +$dbt->close(); +/* +* Graph thermometer +*/ +print moneyMeter($actualValue, $pendingValue, $intentValue); - /* - * Read Values - */ - - $conf = new Conf(); - $conf->db->type = $dolibarr_main_db_type; - $conf->db->port = $dolibarr_main_db_port; - $conf->db->host = $dolibarr_main_db_host; - $conf->db->name = $dolibarr_main_db_name; - $conf->db->user = $dolibarr_main_db_user; - $conf->db->pass = $dolibarr_main_db_pass; - - $dbt = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port); - - $dontherm = new Don($dbt); - - $intentValue = $dontherm->sum_donations(1); - $pendingValue = $dontherm->sum_donations(2); - $actualValue = $dontherm->sum_donations(3); - - $dbt->close(); - } - - - /* - * Graph thermometer - */ - - print moneyMeter($actualValue, $pendingValue, $intentValue); - - -} ?>