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

Language PHP Lines 676
MD5 Hash f9c660cad0d58ba5ee7b3e9acc591c71
Repository https://github.com/asterix14/dolibarr.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<?php
/* Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
 * Copyright (C) 2005-2007 Regis Houssin        <regis@dolibarr.fr>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 * or see http://www.gnu.org/
 */

/**
 *  \file		htdocs/core/lib/images.lib.php
 *  \brief		Set of function for manipulating images
 */

// Define size of logo small and mini
$maxwidthsmall=270;$maxheightsmall=150;
$maxwidthmini=128;$maxheightmini=72;
$quality = 80;



/**
 *      Return if a filename is file name of a supported image format
 *      @param      file        Filename
 *      @return     int         -1=Not image filename, 0=Image filename but format not supported by PHP, 1=Image filename with format supported
 */
function image_format_supported($file)
{
    // Case filename is not a format image
    if (! preg_match('/(\.gif|\.jpg|\.jpeg|\.png|\.bmp)$/i',$file,$reg)) return -1;

    // Case filename is a format image but not supported by this PHP
    $imgfonction='';
    if (strtolower($reg[1]) == '.gif')  $imgfonction = 'imagecreatefromgif';
    if (strtolower($reg[1]) == '.png')  $imgfonction = 'imagecreatefrompng';
    if (strtolower($reg[1]) == '.jpg')  $imgfonction = 'imagecreatefromjpeg';
    if (strtolower($reg[1]) == '.jpeg') $imgfonction = 'imagecreatefromjpeg';
    if (strtolower($reg[1]) == '.bmp')  $imgfonction = 'imagecreatefromwbmp';
    if ($imgfonction)
    {
        if (! function_exists($imgfonction))
        {
            // Fonctions de conversion non presente dans ce PHP
            return 0;
        }
    }

    // Filename is a format image and supported by this PHP
    return 1;
}


/**
 *    	Return size of image file on disk (Supported extensions are gif, jpg, png and bmp)
 * 		@param		$file		Full path name of file
 * 		@return		Array		array('width'=>width, 'height'=>height)
 */
function dol_getImageSize($file)
{
	$ret=array();

	if (image_format_supported($file) < 0) return $ret;

	$fichier = realpath($file); 	// Chemin canonique absolu de l'image
	$dir = dirname($file); 			// Chemin du dossier contenant l'image

	$infoImg = getimagesize($fichier); // Recuperation des infos de l'image
	$ret['width']=$infoImg[0]; // Largeur de l'image
	$ret['height']=$infoImg[1]; // Hauteur de l'image

	return $ret;
}


/**
 *    	Resize or crop an image file (Supported extensions are gif, jpg, png and bmp)
 *    	@param     	file           	Path of file to resize/crop
 * 		@param		mode			0=Resize, 1=Crop
 *    	@param     	newWidth       	Largeur maximum que dois faire l'image destination (0=keep ratio)
 *    	@param     	newHeight      	Hauteur maximum que dois faire l'image destination (0=keep ratio)
 * 		@param		src_x			Position of croping image in source image (not use if mode=0)
 * 		@param		src_y			Position of croping image in source image (not use if mode=0)
 *		@return		int				File name if OK, error message if KO
 */
function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $src_y=0)
{
	require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");

	global $conf,$langs;

	dol_syslog("dol_imageResizeOrCrop file=".$file." mode=".$mode." newWidth=".$newWidth." newHeight=".$newHeight." src_x=".$src_x." src_y=".$src_y);

	// Clean parameters
	$file=trim($file);

	// Check parameters
	if (! $file)
	{
		// Si le fichier n'a pas ete indique
		return 'Bad parameter file';
	}
	elseif (! file_exists($file))
	{
		// Si le fichier passe en parametre n'existe pas
		return $langs->trans("ErrorFileNotFound",$file);
	}
	elseif(image_format_supported($file) < 0)
	{
		return 'This filename '.$file.' does not seem to be an image filename.';
	}
	elseif(!is_numeric($newWidth) && !is_numeric($newHeight))
	{
		return 'Wrong value for parameter newWidth or newHeight';
	}
	elseif ($mode == 0 && $newWidth <= 0 && $newHeight <= 0)
	{
		return 'At least newHeight or newWidth must be defined for resizing';
	}
	elseif ($mode == 1 && ($newWidth <= 0 || $newHeight <= 0))
	{
		return 'Both newHeight or newWidth must be defined for croping';
	}

	$fichier = realpath($file); 	// Chemin canonique absolu de l'image
	$dir = dirname($file); 			// Chemin du dossier contenant l'image

	$infoImg = getimagesize($fichier); // Recuperation des infos de l'image
	$imgWidth = $infoImg[0]; // Largeur de l'image
	$imgHeight = $infoImg[1]; // Hauteur de l'image

	if ($mode == 0)	// If resize, we check parameters
	{
		if ($newWidth  <= 0)
		{
			$newWidth=intval(($newHeight / $imgHeight) * $imgWidth);	// Keep ratio
		}
		if ($newHeight <= 0)
		{
			$newHeight=intval(($newWidth / $imgWidth) * $imgHeight);	// Keep ratio
		}
	}

	$imgfonction='';
	switch($infoImg[2])
	{
		case 1:	// IMG_GIF
			$imgfonction = 'imagecreatefromgif';
			break;
		case 2:	// IMG_JPG
			$imgfonction = 'imagecreatefromjpeg';
			break;
		case 3:	// IMG_PNG
			$imgfonction = 'imagecreatefrompng';
			break;
		case 4:	// IMG_WBMP
			$imgfonction = 'imagecreatefromwbmp';
			break;
	}
	if ($imgfonction)
	{
		if (! function_exists($imgfonction))
		{
			// Fonctions de conversion non presente dans ce PHP
			return 'Resize not possible. This PHP does not support GD functions '.$imgfonction;
		}
	}

	// Initialisation des variables selon l'extension de l'image
	switch($infoImg[2])
	{
		case 1:	// Gif
			$img = imagecreatefromgif($fichier);
			$extImg = '.gif';	// File name extension of image
			$newquality='NU';	// Quality is not used for this format
			break;
		case 2:	// Jpg
			$img = imagecreatefromjpeg($fichier);
			$extImg = '.jpg';
			$newquality=100;	// % quality maximum
			break;
		case 3:	// Png
			$img = imagecreatefrompng($fichier);
			$extImg = '.png';
			$newquality=0;		// No compression (0-9)
			break;
		case 4:	// Bmp
			$img = imagecreatefromwbmp($fichier);
			$extImg = '.bmp';
			$newquality='NU';	// Quality is not used for this format
			break;
	}

	// Create empty image
	if ($infoImg[2] == 1)
	{
		// Compatibilite image GIF
		$imgThumb = imagecreate($newWidth, $newHeight);
	}
	else
	{
		$imgThumb = imagecreatetruecolor($newWidth, $newHeight);
	}

	// Activate antialiasing for better quality
	if (function_exists('imageantialias'))
	{
		imageantialias($imgThumb, true);
	}

	// This is to keep transparent alpha channel if exists (PHP >= 4.2)
	if (function_exists('imagesavealpha'))
	{
		imagesavealpha($imgThumb, true);
	}

	// Initialisation des variables selon l'extension de l'image
	switch($infoImg[2])
	{
		case 1:	// Gif
			$trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF
			imagecolortransparent($imgThumb,$trans_colour);
			break;
		case 2:	// Jpg
			$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
			break;
		case 3:	// Png
			imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme
			$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127);	// Keep transparent channel
			break;
		case 4:	// Bmp
			$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
			break;
	}
	if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour);

	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");
	//imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
	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

	$imgThumbName = $file;

	// Check if permission are ok
	//$fp = fopen($imgThumbName, "w");
	//fclose($fp);

	// Create image on disk
	switch($infoImg[2])
	{
		case 1:	// Gif
			imagegif($imgThumb, $imgThumbName);
			break;
		case 2:	// Jpg
			imagejpeg($imgThumb, $imgThumbName, $newquality);
			break;
		case 3:	// Png
			imagepng($imgThumb, $imgThumbName, $newquality);
			break;
		case 4:	// Bmp
			image2wmp($imgThumb, $imgThumbName);
			break;
	}

	// Set permissions on file
	if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));

	// Free memory. This does not delete image.
    imagedestroy($img);
	imagedestroy($imgThumb);

	clearstatcache();	// File was replaced by a modified one, so we clear file caches.

	return $imgThumbName;
}


/**
 *    	Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
 *      If file is myfile.jpg, new file may be myfile_small.jpg
 *    	@param     file           	Path of source file to resize
 *    	@param     maxWidth       	Largeur maximum que dois faire la miniature (-1=unchanged, 160 by default)
 *    	@param     maxHeight      	Hauteur maximum que dois faire l'image (-1=unchanged, 120 by default)
 *    	@param     extName        	Extension to differenciate thumb file name ('_small', '_mini')
 *    	@param     quality        	Quality of compression (0=worst, 100=best)
 *      @param     outdir           Directory where to store thumb
 *      @param     targetformat     New format of target (1,2,3,4 or 0 to keep old format)
 *    	@return    string			Full path of thumb
 */
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
{
	require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");

	global $conf,$langs;

	dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality." outdir=".$outdir." targetformat=".$targetformat);

	// Clean parameters
	$file=trim($file);

	// Check parameters
	if (! $file)
	{
		// Si le fichier n'a pas ete indique
		return 'ErrorBadParameters';
	}
	elseif (! file_exists($file))
	{
		// Si le fichier passe en parametre n'existe pas
        dol_syslog($langs->trans("ErrorFileNotFound",$file),LOG_ERR);
	    return $langs->trans("ErrorFileNotFound",$file);
	}
	elseif(image_format_supported($file) < 0)
	{
        dol_syslog('This file '.$file.' does not seem to be an image format file name.',LOG_WARNING);
	    return 'ErrorBadImageFormat';
	}
	elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){
		// Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
        dol_syslog('Wrong value for parameter maxWidth',LOG_ERR);
	    return 'Error: Wrong value for parameter maxWidth';
	}
	elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){
		// Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
        dol_syslog('Wrong value for parameter maxHeight',LOG_ERR);
	    return 'Error: Wrong value for parameter maxHeight';
	}

	$fichier = realpath($file); 	// Chemin canonique absolu de l'image
	$dir = dirname($file); 			// Chemin du dossier contenant l'image

	$infoImg = getimagesize($fichier); // Recuperation des infos de l'image
	$imgWidth = $infoImg[0]; // Largeur de l'image
	$imgHeight = $infoImg[1]; // Hauteur de l'image

	if ($maxWidth  == -1) $maxWidth=$infoImg[0];	// If size is -1, we keep unchanged
	if ($maxHeight == -1) $maxHeight=$infoImg[1];	// If size is -1, we keep unchanged

	// Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette
	if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight)
	{
		// On cree toujours les vignettes
		dol_syslog("File size is smaller than thumb size",LOG_DEBUG);
		//return 'Le fichier '.$file.' ne necessite pas de creation de vignette';
	}

	$imgfonction='';
	switch($infoImg[2])
	{
		case 1:	// IMG_GIF
			$imgfonction = 'imagecreatefromgif';
			break;
		case 2:	// IMG_JPG
			$imgfonction = 'imagecreatefromjpeg';
			break;
		case 3:	// IMG_PNG
			$imgfonction = 'imagecreatefrompng';
			break;
		case 4:	// IMG_WBMP
			$imgfonction = 'imagecreatefromwbmp';
			break;
	}
	if ($imgfonction)
	{
		if (! function_exists($imgfonction))
		{
			// Fonctions de conversion non presente dans ce PHP
			return 'Error: Creation of thumbs not possible. This PHP does not support GD function '.$imgfonction;
		}
	}

	// On cree le repertoire contenant les vignettes
	$dirthumb = $dir.($outdir?'/'.$outdir:''); 	// Chemin du dossier contenant les vignettes
	create_exdir($dirthumb);

	// Initialisation des variables selon l'extension de l'image
	switch($infoImg[2])
	{
		case 1:	// Gif
			$img = imagecreatefromgif($fichier);
			$extImg = '.gif'; // Extension de l'image
			break;
		case 2:	// Jpg
			$img = imagecreatefromjpeg($fichier);
			$extImg = '.jpg'; // Extension de l'image
			break;
		case 3:	// Png
			$img = imagecreatefrompng($fichier);
			$extImg = '.png';
			break;
		case 4:	// Bmp
			$img = imagecreatefromwbmp($fichier);
			$extImg = '.bmp';
			break;
	}

	// Initialisation des dimensions de la vignette si elles sont superieures a l'original
	if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; }
	if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; }

	$whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette
	$imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original

	// Fixe les dimensions de la vignette
	if($whFact < $imgWhFact){
		// Si largeur determinante
		$thumbWidth  = $maxWidth;
		$thumbHeight = $thumbWidth / $imgWhFact;
	} else {
		// Si hauteur determinante
		$thumbHeight = $maxHeight;
		$thumbWidth  = $thumbHeight * $imgWhFact;
	}
	$thumbHeight=round($thumbHeight);
	$thumbWidth=round($thumbWidth);

    // Define target format
    if (empty($targetformat)) $targetformat=$infoImg[2];

	// Create empty image
	if ($targetformat == 1)
	{
		// Compatibilite image GIF
		$imgThumb = imagecreate($thumbWidth, $thumbHeight);
	}
	else
	{
		$imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
	}

	// Activate antialiasing for better quality
	if (function_exists('imageantialias'))
	{
		imageantialias($imgThumb, true);
	}

	// This is to keep transparent alpha channel if exists (PHP >= 4.2)
	if (function_exists('imagesavealpha'))
	{
		imagesavealpha($imgThumb, true);
	}

	// Initialisation des variables selon l'extension de l'image
	switch($targetformat)
	{
		case 1:	// Gif
			$trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF
			imagecolortransparent($imgThumb,$trans_colour);
            $extImgTarget = '.gif';
            $newquality='NU';
            break;
		case 2:	// Jpg
			$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
            $extImgTarget = '.jpg';
            $newquality=$quality;
            break;
		case 3:	// Png
			imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme
			$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127);	// Keep transparent channel
            $extImgTarget = '.png';
            $newquality=$quality-100;
            $newquality=round(abs($quality-100)*9/100);
            break;
		case 4:	// Bmp
			$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
            $extImgTarget = '.bmp';
            $newquality='NU';
            break;
	}
	if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour);

	dol_syslog("vignette: convert image from ($imgWidth x $imgHeight) to ($thumbWidth x $thumbHeight) as $extImg, newquality=$newquality");
	//imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
	imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee

	$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file);	// On enleve extension quelquesoit la casse
	$fileName = basename($fileName);
	$imgThumbName = $dirthumb.'/'.$fileName.$extName.$extImgTarget; // Chemin complet du fichier de la vignette

	// Check if permission are ok
	//$fp = fopen($imgThumbName, "w");
	//fclose($fp);

	// Create image on disk
	switch($targetformat)
	{
		case 1:	// Gif
			imagegif($imgThumb, $imgThumbName);
			break;
		case 2:	// Jpg
			imagejpeg($imgThumb, $imgThumbName, $newquality);
			break;
		case 3:	// Png
			imagepng($imgThumb, $imgThumbName, $newquality);
			break;
		case 4:	// Bmp
			image2wmp($imgThumb, $imgThumbName);
			break;
	}

	// Set permissions on file
	if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));

    // Free memory. This does not delete image.
    imagedestroy($img);
    imagedestroy($imgThumb);

	return $imgThumbName;
}


/**
 *	\brief	This function returns the html for the moneymeter.
 *	\param	actualValue: amount of actual money
 *	\param	pendingValue: amount of money of pending memberships
 *	\param	intentValue: amount of intended money (that's without the amount of actual money)
 *	\return thermometer htmlLegenda
 */
function moneyMeter($actualValue=0, $pendingValue=0, $intentValue=0)
{
	global $langs;

	// variables
	$height="200";
	$maximumValue=125000;

	$imageDir = "http://eucd.info/images/therm/";

	$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";

	$formThermTop = '
        <!-- Thermometer Begin -->
        <table cellpadding="0" cellspacing="4" border="0">
        <tr><td>
        <table cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td colspan="2"><img src="' . $imageTop . '" width="58" height="6" border="0"></td>
          </tr>
          <tr>
            <td>
              <table cellpadding="0" cellspacing="0" border="0">';

	$formSection = '
          <tr><td><img src="{image}" width="26" height="{height}" border="0"></td></tr>';

	$formThermbottom = '
              </table>
            </td>
            <td><img src="' . $imageIndex . '" width="32" height="200" border="0"></td>
          </tr>
          <tr>
            <td colspan="2"><img src="' . $imageBottom . '" width="58" height="32" border="0"></td>
          </tr>
        </table>
        </td>
      </tr></table>';

	// legenda

	$legendaActual = "&euro; " . round($actualValue);
	$legendaPending = "&euro; " . round($pendingValue);
	$legendaIntent = "&euro; " . round($intentValue);
	$legendaTotal = "&euro; " . round($actualValue + $pendingValue + $intentValue);
	$formLegenda = '

        <table cellpadding="0" cellspacing="0" border="0">
          <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>
          <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>
          <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>
          <tr><td>&nbsp;</td><td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Total:<br>' . $legendaTotal . '</font></td></tr>
        </table>

        <!-- Thermometer End -->';

	// 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<br>\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 = $formThermbottom;

	// actual
	$sectionHeight = round(($actualValue / $maximumValue) * $height);
	$totalHeight = $totalHeight + $sectionHeight;
	if ( $sectionHeight > 0 )
	{
		$section = $formSection;
		$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 = $formSection;
		$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 = $formSection;
		$section = str_replace("{image}", $imageMiddleIntent, $section);
		$section = str_replace("{height}", $sectionHeight, $section);
		$thermometer = $section . $thermometer;
	}

	// goal
	$sectionHeight = $height- $totalHeight;
	if ( $sectionHeight > 0 )
	{
		$section = $formSection;
		$section = str_replace("{image}", $imageMiddleGoal, $section);
		$section = str_replace("{height}", $sectionHeight, $section);
		$thermometer = $section . $thermometer;
	}

	// top
	$thermometer = $formThermTop . $thermometer;

	return $thermometer . $formLegenda;
}

?>
Back to Top