PageRenderTime 44ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/lib/images.lib.php

https://github.com/asterix14/dolibarr
PHP | 675 lines | 468 code | 85 blank | 122 comment | 70 complexity | f9c660cad0d58ba5ee7b3e9acc591c71 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/lib/images.lib.php
  21. * \brief Set of function for manipulating images
  22. */
  23. // Define size of logo small and mini
  24. $maxwidthsmall=270;$maxheightsmall=150;
  25. $maxwidthmini=128;$maxheightmini=72;
  26. $quality = 80;
  27. /**
  28. * Return if a filename is file name of a supported image format
  29. * @param file Filename
  30. * @return int -1=Not image filename, 0=Image filename but format not supported by PHP, 1=Image filename with format supported
  31. */
  32. function image_format_supported($file)
  33. {
  34. // Case filename is not a format image
  35. if (! preg_match('/(\.gif|\.jpg|\.jpeg|\.png|\.bmp)$/i',$file,$reg)) return -1;
  36. // Case filename is a format image but not supported by this PHP
  37. $imgfonction='';
  38. if (strtolower($reg[1]) == '.gif') $imgfonction = 'imagecreatefromgif';
  39. if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng';
  40. if (strtolower($reg[1]) == '.jpg') $imgfonction = 'imagecreatefromjpeg';
  41. if (strtolower($reg[1]) == '.jpeg') $imgfonction = 'imagecreatefromjpeg';
  42. if (strtolower($reg[1]) == '.bmp') $imgfonction = 'imagecreatefromwbmp';
  43. if ($imgfonction)
  44. {
  45. if (! function_exists($imgfonction))
  46. {
  47. // Fonctions de conversion non presente dans ce PHP
  48. return 0;
  49. }
  50. }
  51. // Filename is a format image and supported by this PHP
  52. return 1;
  53. }
  54. /**
  55. * Return size of image file on disk (Supported extensions are gif, jpg, png and bmp)
  56. * @param $file Full path name of file
  57. * @return Array array('width'=>width, 'height'=>height)
  58. */
  59. function dol_getImageSize($file)
  60. {
  61. $ret=array();
  62. if (image_format_supported($file) < 0) return $ret;
  63. $fichier = realpath($file); // Chemin canonique absolu de l'image
  64. $dir = dirname($file); // Chemin du dossier contenant l'image
  65. $infoImg = getimagesize($fichier); // Recuperation des infos de l'image
  66. $ret['width']=$infoImg[0]; // Largeur de l'image
  67. $ret['height']=$infoImg[1]; // Hauteur de l'image
  68. return $ret;
  69. }
  70. /**
  71. * Resize or crop an image file (Supported extensions are gif, jpg, png and bmp)
  72. * @param file Path of file to resize/crop
  73. * @param mode 0=Resize, 1=Crop
  74. * @param newWidth Largeur maximum que dois faire l'image destination (0=keep ratio)
  75. * @param newHeight Hauteur maximum que dois faire l'image destination (0=keep ratio)
  76. * @param src_x Position of croping image in source image (not use if mode=0)
  77. * @param src_y Position of croping image in source image (not use if mode=0)
  78. * @return int File name if OK, error message if KO
  79. */
  80. function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $src_y=0)
  81. {
  82. require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
  83. global $conf,$langs;
  84. dol_syslog("dol_imageResizeOrCrop file=".$file." mode=".$mode." newWidth=".$newWidth." newHeight=".$newHeight." src_x=".$src_x." src_y=".$src_y);
  85. // Clean parameters
  86. $file=trim($file);
  87. // Check parameters
  88. if (! $file)
  89. {
  90. // Si le fichier n'a pas ete indique
  91. return 'Bad parameter file';
  92. }
  93. elseif (! file_exists($file))
  94. {
  95. // Si le fichier passe en parametre n'existe pas
  96. return $langs->trans("ErrorFileNotFound",$file);
  97. }
  98. elseif(image_format_supported($file) < 0)
  99. {
  100. return 'This filename '.$file.' does not seem to be an image filename.';
  101. }
  102. elseif(!is_numeric($newWidth) && !is_numeric($newHeight))
  103. {
  104. return 'Wrong value for parameter newWidth or newHeight';
  105. }
  106. elseif ($mode == 0 && $newWidth <= 0 && $newHeight <= 0)
  107. {
  108. return 'At least newHeight or newWidth must be defined for resizing';
  109. }
  110. elseif ($mode == 1 && ($newWidth <= 0 || $newHeight <= 0))
  111. {
  112. return 'Both newHeight or newWidth must be defined for croping';
  113. }
  114. $fichier = realpath($file); // Chemin canonique absolu de l'image
  115. $dir = dirname($file); // Chemin du dossier contenant l'image
  116. $infoImg = getimagesize($fichier); // Recuperation des infos de l'image
  117. $imgWidth = $infoImg[0]; // Largeur de l'image
  118. $imgHeight = $infoImg[1]; // Hauteur de l'image
  119. if ($mode == 0) // If resize, we check parameters
  120. {
  121. if ($newWidth <= 0)
  122. {
  123. $newWidth=intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio
  124. }
  125. if ($newHeight <= 0)
  126. {
  127. $newHeight=intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio
  128. }
  129. }
  130. $imgfonction='';
  131. switch($infoImg[2])
  132. {
  133. case 1: // IMG_GIF
  134. $imgfonction = 'imagecreatefromgif';
  135. break;
  136. case 2: // IMG_JPG
  137. $imgfonction = 'imagecreatefromjpeg';
  138. break;
  139. case 3: // IMG_PNG
  140. $imgfonction = 'imagecreatefrompng';
  141. break;
  142. case 4: // IMG_WBMP
  143. $imgfonction = 'imagecreatefromwbmp';
  144. break;
  145. }
  146. if ($imgfonction)
  147. {
  148. if (! function_exists($imgfonction))
  149. {
  150. // Fonctions de conversion non presente dans ce PHP
  151. return 'Resize not possible. This PHP does not support GD functions '.$imgfonction;
  152. }
  153. }
  154. // Initialisation des variables selon l'extension de l'image
  155. switch($infoImg[2])
  156. {
  157. case 1: // Gif
  158. $img = imagecreatefromgif($fichier);
  159. $extImg = '.gif'; // File name extension of image
  160. $newquality='NU'; // Quality is not used for this format
  161. break;
  162. case 2: // Jpg
  163. $img = imagecreatefromjpeg($fichier);
  164. $extImg = '.jpg';
  165. $newquality=100; // % quality maximum
  166. break;
  167. case 3: // Png
  168. $img = imagecreatefrompng($fichier);
  169. $extImg = '.png';
  170. $newquality=0; // No compression (0-9)
  171. break;
  172. case 4: // Bmp
  173. $img = imagecreatefromwbmp($fichier);
  174. $extImg = '.bmp';
  175. $newquality='NU'; // Quality is not used for this format
  176. break;
  177. }
  178. // Create empty image
  179. if ($infoImg[2] == 1)
  180. {
  181. // Compatibilite image GIF
  182. $imgThumb = imagecreate($newWidth, $newHeight);
  183. }
  184. else
  185. {
  186. $imgThumb = imagecreatetruecolor($newWidth, $newHeight);
  187. }
  188. // Activate antialiasing for better quality
  189. if (function_exists('imageantialias'))
  190. {
  191. imageantialias($imgThumb, true);
  192. }
  193. // This is to keep transparent alpha channel if exists (PHP >= 4.2)
  194. if (function_exists('imagesavealpha'))
  195. {
  196. imagesavealpha($imgThumb, true);
  197. }
  198. // Initialisation des variables selon l'extension de l'image
  199. switch($infoImg[2])
  200. {
  201. case 1: // Gif
  202. $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF
  203. imagecolortransparent($imgThumb,$trans_colour);
  204. break;
  205. case 2: // Jpg
  206. $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
  207. break;
  208. case 3: // Png
  209. imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme
  210. $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel
  211. break;
  212. case 4: // Bmp
  213. $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
  214. break;
  215. }
  216. if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour);
  217. dol_syslog("dol_imageResizeOrCrop: convert image from ($imgWidth x $imgHeight) at position ($src_x x $src_y) to ($newWidth x $newHeight) as $extImg, newquality=$newquality");
  218. //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
  219. imagecopyresampled($imgThumb, $img, 0, 0, $src_x, $src_y, $newWidth, $newHeight, ($mode==0?$imgWidth:$newWidth), ($mode==0?$imgHeight:$newHeight)); // Insere l'image de base redimensionnee
  220. $imgThumbName = $file;
  221. // Check if permission are ok
  222. //$fp = fopen($imgThumbName, "w");
  223. //fclose($fp);
  224. // Create image on disk
  225. switch($infoImg[2])
  226. {
  227. case 1: // Gif
  228. imagegif($imgThumb, $imgThumbName);
  229. break;
  230. case 2: // Jpg
  231. imagejpeg($imgThumb, $imgThumbName, $newquality);
  232. break;
  233. case 3: // Png
  234. imagepng($imgThumb, $imgThumbName, $newquality);
  235. break;
  236. case 4: // Bmp
  237. image2wmp($imgThumb, $imgThumbName);
  238. break;
  239. }
  240. // Set permissions on file
  241. if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
  242. // Free memory. This does not delete image.
  243. imagedestroy($img);
  244. imagedestroy($imgThumb);
  245. clearstatcache(); // File was replaced by a modified one, so we clear file caches.
  246. return $imgThumbName;
  247. }
  248. /**
  249. * Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
  250. * If file is myfile.jpg, new file may be myfile_small.jpg
  251. * @param file Path of source file to resize
  252. * @param maxWidth Largeur maximum que dois faire la miniature (-1=unchanged, 160 by default)
  253. * @param maxHeight Hauteur maximum que dois faire l'image (-1=unchanged, 120 by default)
  254. * @param extName Extension to differenciate thumb file name ('_small', '_mini')
  255. * @param quality Quality of compression (0=worst, 100=best)
  256. * @param outdir Directory where to store thumb
  257. * @param targetformat New format of target (1,2,3,4 or 0 to keep old format)
  258. * @return string Full path of thumb
  259. */
  260. function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
  261. {
  262. require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
  263. global $conf,$langs;
  264. dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality." outdir=".$outdir." targetformat=".$targetformat);
  265. // Clean parameters
  266. $file=trim($file);
  267. // Check parameters
  268. if (! $file)
  269. {
  270. // Si le fichier n'a pas ete indique
  271. return 'ErrorBadParameters';
  272. }
  273. elseif (! file_exists($file))
  274. {
  275. // Si le fichier passe en parametre n'existe pas
  276. dol_syslog($langs->trans("ErrorFileNotFound",$file),LOG_ERR);
  277. return $langs->trans("ErrorFileNotFound",$file);
  278. }
  279. elseif(image_format_supported($file) < 0)
  280. {
  281. dol_syslog('This file '.$file.' does not seem to be an image format file name.',LOG_WARNING);
  282. return 'ErrorBadImageFormat';
  283. }
  284. elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){
  285. // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
  286. dol_syslog('Wrong value for parameter maxWidth',LOG_ERR);
  287. return 'Error: Wrong value for parameter maxWidth';
  288. }
  289. elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){
  290. // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
  291. dol_syslog('Wrong value for parameter maxHeight',LOG_ERR);
  292. return 'Error: Wrong value for parameter maxHeight';
  293. }
  294. $fichier = realpath($file); // Chemin canonique absolu de l'image
  295. $dir = dirname($file); // Chemin du dossier contenant l'image
  296. $infoImg = getimagesize($fichier); // Recuperation des infos de l'image
  297. $imgWidth = $infoImg[0]; // Largeur de l'image
  298. $imgHeight = $infoImg[1]; // Hauteur de l'image
  299. if ($maxWidth == -1) $maxWidth=$infoImg[0]; // If size is -1, we keep unchanged
  300. if ($maxHeight == -1) $maxHeight=$infoImg[1]; // If size is -1, we keep unchanged
  301. // Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette
  302. if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight)
  303. {
  304. // On cree toujours les vignettes
  305. dol_syslog("File size is smaller than thumb size",LOG_DEBUG);
  306. //return 'Le fichier '.$file.' ne necessite pas de creation de vignette';
  307. }
  308. $imgfonction='';
  309. switch($infoImg[2])
  310. {
  311. case 1: // IMG_GIF
  312. $imgfonction = 'imagecreatefromgif';
  313. break;
  314. case 2: // IMG_JPG
  315. $imgfonction = 'imagecreatefromjpeg';
  316. break;
  317. case 3: // IMG_PNG
  318. $imgfonction = 'imagecreatefrompng';
  319. break;
  320. case 4: // IMG_WBMP
  321. $imgfonction = 'imagecreatefromwbmp';
  322. break;
  323. }
  324. if ($imgfonction)
  325. {
  326. if (! function_exists($imgfonction))
  327. {
  328. // Fonctions de conversion non presente dans ce PHP
  329. return 'Error: Creation of thumbs not possible. This PHP does not support GD function '.$imgfonction;
  330. }
  331. }
  332. // On cree le repertoire contenant les vignettes
  333. $dirthumb = $dir.($outdir?'/'.$outdir:''); // Chemin du dossier contenant les vignettes
  334. create_exdir($dirthumb);
  335. // Initialisation des variables selon l'extension de l'image
  336. switch($infoImg[2])
  337. {
  338. case 1: // Gif
  339. $img = imagecreatefromgif($fichier);
  340. $extImg = '.gif'; // Extension de l'image
  341. break;
  342. case 2: // Jpg
  343. $img = imagecreatefromjpeg($fichier);
  344. $extImg = '.jpg'; // Extension de l'image
  345. break;
  346. case 3: // Png
  347. $img = imagecreatefrompng($fichier);
  348. $extImg = '.png';
  349. break;
  350. case 4: // Bmp
  351. $img = imagecreatefromwbmp($fichier);
  352. $extImg = '.bmp';
  353. break;
  354. }
  355. // Initialisation des dimensions de la vignette si elles sont superieures a l'original
  356. if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; }
  357. if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; }
  358. $whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette
  359. $imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original
  360. // Fixe les dimensions de la vignette
  361. if($whFact < $imgWhFact){
  362. // Si largeur determinante
  363. $thumbWidth = $maxWidth;
  364. $thumbHeight = $thumbWidth / $imgWhFact;
  365. } else {
  366. // Si hauteur determinante
  367. $thumbHeight = $maxHeight;
  368. $thumbWidth = $thumbHeight * $imgWhFact;
  369. }
  370. $thumbHeight=round($thumbHeight);
  371. $thumbWidth=round($thumbWidth);
  372. // Define target format
  373. if (empty($targetformat)) $targetformat=$infoImg[2];
  374. // Create empty image
  375. if ($targetformat == 1)
  376. {
  377. // Compatibilite image GIF
  378. $imgThumb = imagecreate($thumbWidth, $thumbHeight);
  379. }
  380. else
  381. {
  382. $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
  383. }
  384. // Activate antialiasing for better quality
  385. if (function_exists('imageantialias'))
  386. {
  387. imageantialias($imgThumb, true);
  388. }
  389. // This is to keep transparent alpha channel if exists (PHP >= 4.2)
  390. if (function_exists('imagesavealpha'))
  391. {
  392. imagesavealpha($imgThumb, true);
  393. }
  394. // Initialisation des variables selon l'extension de l'image
  395. switch($targetformat)
  396. {
  397. case 1: // Gif
  398. $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF
  399. imagecolortransparent($imgThumb,$trans_colour);
  400. $extImgTarget = '.gif';
  401. $newquality='NU';
  402. break;
  403. case 2: // Jpg
  404. $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
  405. $extImgTarget = '.jpg';
  406. $newquality=$quality;
  407. break;
  408. case 3: // Png
  409. imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme
  410. $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel
  411. $extImgTarget = '.png';
  412. $newquality=$quality-100;
  413. $newquality=round(abs($quality-100)*9/100);
  414. break;
  415. case 4: // Bmp
  416. $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
  417. $extImgTarget = '.bmp';
  418. $newquality='NU';
  419. break;
  420. }
  421. if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour);
  422. dol_syslog("vignette: convert image from ($imgWidth x $imgHeight) to ($thumbWidth x $thumbHeight) as $extImg, newquality=$newquality");
  423. //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
  424. imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
  425. $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse
  426. $fileName = basename($fileName);
  427. $imgThumbName = $dirthumb.'/'.$fileName.$extName.$extImgTarget; // Chemin complet du fichier de la vignette
  428. // Check if permission are ok
  429. //$fp = fopen($imgThumbName, "w");
  430. //fclose($fp);
  431. // Create image on disk
  432. switch($targetformat)
  433. {
  434. case 1: // Gif
  435. imagegif($imgThumb, $imgThumbName);
  436. break;
  437. case 2: // Jpg
  438. imagejpeg($imgThumb, $imgThumbName, $newquality);
  439. break;
  440. case 3: // Png
  441. imagepng($imgThumb, $imgThumbName, $newquality);
  442. break;
  443. case 4: // Bmp
  444. image2wmp($imgThumb, $imgThumbName);
  445. break;
  446. }
  447. // Set permissions on file
  448. if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
  449. // Free memory. This does not delete image.
  450. imagedestroy($img);
  451. imagedestroy($imgThumb);
  452. return $imgThumbName;
  453. }
  454. /**
  455. * \brief This function returns the html for the moneymeter.
  456. * \param actualValue: amount of actual money
  457. * \param pendingValue: amount of money of pending memberships
  458. * \param intentValue: amount of intended money (that's without the amount of actual money)
  459. * \return thermometer htmlLegenda
  460. */
  461. function moneyMeter($actualValue=0, $pendingValue=0, $intentValue=0)
  462. {
  463. global $langs;
  464. // variables
  465. $height="200";
  466. $maximumValue=125000;
  467. $imageDir = "http://eucd.info/images/therm/";
  468. $imageTop = $imageDir . "therm_top.png";
  469. $imageMiddleActual = $imageDir . "therm_actual.png";
  470. $imageMiddlePending = $imageDir . "therm_pending.png";
  471. $imageMiddleIntent = $imageDir . "therm_intent.png";
  472. $imageMiddleGoal = $imageDir . "therm_goal.png";
  473. $imageIndex = $imageDir . "therm_index.png";
  474. $imageBottom = $imageDir . "therm_bottom.png";
  475. $imageColorActual = $imageDir . "therm_color_actual.png";
  476. $imageColorPending = $imageDir . "therm_color_pending.png";
  477. $imageColorIntent = $imageDir . "therm_color_intent.png";
  478. $formThermTop = '
  479. <!-- Thermometer Begin -->
  480. <table cellpadding="0" cellspacing="4" border="0">
  481. <tr><td>
  482. <table cellpadding="0" cellspacing="0" border="0">
  483. <tr>
  484. <td colspan="2"><img src="' . $imageTop . '" width="58" height="6" border="0"></td>
  485. </tr>
  486. <tr>
  487. <td>
  488. <table cellpadding="0" cellspacing="0" border="0">';
  489. $formSection = '
  490. <tr><td><img src="{image}" width="26" height="{height}" border="0"></td></tr>';
  491. $formThermbottom = '
  492. </table>
  493. </td>
  494. <td><img src="' . $imageIndex . '" width="32" height="200" border="0"></td>
  495. </tr>
  496. <tr>
  497. <td colspan="2"><img src="' . $imageBottom . '" width="58" height="32" border="0"></td>
  498. </tr>
  499. </table>
  500. </td>
  501. </tr></table>';
  502. // legenda
  503. $legendaActual = "&euro; " . round($actualValue);
  504. $legendaPending = "&euro; " . round($pendingValue);
  505. $legendaIntent = "&euro; " . round($intentValue);
  506. $legendaTotal = "&euro; " . round($actualValue + $pendingValue + $intentValue);
  507. $formLegenda = '
  508. <table cellpadding="0" cellspacing="0" border="0">
  509. <tr><td><img src="' . $imageColorActual . '" width="9" height="9">&nbsp;</td><td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>'.$langs->trans("Paid").':<br>' . $legendaActual . '</b></font></td></tr>
  510. <tr><td><img src="' . $imageColorPending . '" width="9" height="9">&nbsp;</td><td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">'.$langs->trans("Waiting").':<br>' . $legendaPending . '</font></td></tr>
  511. <tr><td><img src="' . $imageColorIntent . '" width="9" height="9">&nbsp;</td><td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">'.$langs->trans("Promesses").':<br>' . $legendaIntent . '</font></td></tr>
  512. <tr><td>&nbsp;</td><td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Total:<br>' . $legendaTotal . '</font></td></tr>
  513. </table>
  514. <!-- Thermometer End -->';
  515. // check and edit some values
  516. $error = 0;
  517. if ( $maximumValue <= 0 || $height <= 0 || $actualValue < 0 || $pendingValue < 0 || $intentValue < 0)
  518. {
  519. return "The money meter could not be processed<br>\n";
  520. }
  521. if ( $actualValue > $maximumValue )
  522. {
  523. $actualValue = $maximumValue;
  524. $pendingValue = 0;
  525. $intentValue = 0;
  526. }
  527. else
  528. {
  529. if ( ($actualValue + $pendingValue) > $maximumValue )
  530. {
  531. $pendingValue = $maximumValue - $actualValue;
  532. $intentValue = 0;
  533. }
  534. else
  535. {
  536. if ( ($actualValue + $pendingValue + $intentValue) > $maximumValue )
  537. {
  538. $intentValue = $maximumValue - $actualValue - $pendingValue;
  539. }
  540. }
  541. }
  542. // start writing the html (from bottom to top)
  543. // bottom
  544. $thermometer = $formThermbottom;
  545. // actual
  546. $sectionHeight = round(($actualValue / $maximumValue) * $height);
  547. $totalHeight = $totalHeight + $sectionHeight;
  548. if ( $sectionHeight > 0 )
  549. {
  550. $section = $formSection;
  551. $section = str_replace("{image}", $imageMiddleActual, $section);
  552. $section = str_replace("{height}", $sectionHeight, $section);
  553. $thermometer = $section . $thermometer;
  554. }
  555. // pending
  556. $sectionHeight = round(($pendingValue / $maximumValue) * $height);
  557. $totalHeight = $totalHeight + $sectionHeight;
  558. if ( $sectionHeight > 0 )
  559. {
  560. $section = $formSection;
  561. $section = str_replace("{image}", $imageMiddlePending, $section);
  562. $section = str_replace("{height}", $sectionHeight, $section);
  563. $thermometer = $section . $thermometer;
  564. }
  565. // intent
  566. $sectionHeight = round(($intentValue / $maximumValue) * $height);
  567. $totalHeight = $totalHeight + $sectionHeight;
  568. if ( $sectionHeight > 0 )
  569. {
  570. $section = $formSection;
  571. $section = str_replace("{image}", $imageMiddleIntent, $section);
  572. $section = str_replace("{height}", $sectionHeight, $section);
  573. $thermometer = $section . $thermometer;
  574. }
  575. // goal
  576. $sectionHeight = $height- $totalHeight;
  577. if ( $sectionHeight > 0 )
  578. {
  579. $section = $formSection;
  580. $section = str_replace("{image}", $imageMiddleGoal, $section);
  581. $section = str_replace("{height}", $sectionHeight, $section);
  582. $thermometer = $section . $thermometer;
  583. }
  584. // top
  585. $thermometer = $formThermTop . $thermometer;
  586. return $thermometer . $formLegenda;
  587. }
  588. ?>