PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

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