diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 3886d55959..00fa4dd36f 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,11 @@
+2013-06-20 Miguel de Dios <miguel.dedios@artica.es>
+
+	* include/graphs/pChart/pPie.class.php, include/graphs/fgraph.php:
+	fixed the htmlentities in the pie chart legend, the border was
+	fixed for older commits.
+	
+	MERGED FROM THE BRANCH PANDORA_4.0
+
 2013-06-20  Junichi Satoh  <junichi@rworks.jp>
 
 	* include/help/ja/help_alerts_config.php: Added a new help.
diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php
index 053a7e48b6..bd2cb2d5ac 100755
--- a/pandora_console/include/graphs/fgraph.php
+++ b/pandora_console/include/graphs/fgraph.php
@@ -465,6 +465,13 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height,
 	// This library allows only 8 colors
 	$max_values = 8;
 	
+	//Remove the html_entities
+	$temp = array();
+	foreach ($chart_data as $key => $value) {
+		$temp[io_safe_output($key)] = $value;
+	}
+	$chart_data = $temp;
+	
 	if (count($chart_data) > $max_values) {
 		$chart_data_trunc = array();
 		$n = 1;
diff --git a/pandora_console/include/graphs/pChart/pPie.class.php b/pandora_console/include/graphs/pChart/pPie.class.php
index fe8dc4cf80..bea05181f3 100755
--- a/pandora_console/include/graphs/pChart/pPie.class.php
+++ b/pandora_console/include/graphs/pChart/pPie.class.php
@@ -512,54 +512,64 @@
        for($j=0;$j<count($Plots);$j=$j+2) { $Top[] = $Plots[$j]; $Top[] = $Plots[$j+1]- $SliceHeight; }
        $this->pChartObject->drawPolygon($Top,$Settings);
       }
-
-
-     /* Second pass to smooth the angles */
-     if ( $SecondPass )
-      {
-       $Step = 360 / (2 * PI * $Radius);
-       $Offset = 360; $ID = 0;
-       foreach($Values as $Key => $Value)
-        {
-         $FirstPoint = TRUE;
-         if ( $Shadow )
-          $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa);
-         else
-          {
-           if ( $Border )
-            { $Settings = array("R"=>$Palette[$ID]["R"]+30,"G"=>$Palette[$ID]["G"]+30,"B"=>$Palette[$ID]["B"]+30,"Alpha"=>$Palette[$ID]["Alpha"]); }
-           else
-            $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);
-          }
-
-         $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; }
-
-         if ($DataGapAngle == 0)
-          { $X0 = $X; $Y0 = $Y- $SliceHeight; }
-         else
-          {
-           $Angle = ($EndAngle - $Offset)/2 + $Offset;
-           $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X;
-           $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y - $SliceHeight;
-          }
-         $Plots[] = $X0; $Plots[] = $Y0;
-
-         for($i=$Offset;$i>=$EndAngle;$i=$i-$Step)
-          {
-           $Xc = cos(($i-90)*PI/180) * $Radius + $X;
-           $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight;
-
-           if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; }
-  
-           $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings);
-           if ($i < 270 && $i > 90 ) { $this->pChartObject->drawAntialiasPixel($Xc,$Yc+$SliceHeight,$Settings); }
-          }
-         $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings);
-
-         $Offset = $i - $DataGapAngle; $ID++;
-        }
-      }
-
+		
+		
+		/* Second pass to smooth the angles */
+		if ( $SecondPass )
+		{
+			$Step = 360 / (2 * PI * $Radius);
+			$Offset = 360; $ID = 0;
+			foreach($Values as $Key => $Value)
+			{
+				$FirstPoint = TRUE;
+				if ( $Shadow )
+					$Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa);
+				else
+				{
+					if ( $Border )
+					{
+						$Settings = array(
+							"R" => $Palette[$ID]["R"] + 30,
+							"G" => $Palette[$ID]["G"] + 30,
+							"B" => $Palette[$ID]["B"] + 30,
+							"Alpha" => $Palette[$ID]["Alpha"]);
+					}
+					else
+						$Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);
+				}
+				
+				$EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; }
+				
+				if ($DataGapAngle == 0)
+				{ $X0 = $X; $Y0 = $Y- $SliceHeight; }
+				else
+				{
+					$Angle = ($EndAngle - $Offset)/2 + $Offset;
+					$X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X;
+					$Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y - $SliceHeight;
+				}
+				$Plots[] = $X0; $Plots[] = $Y0;
+				
+				for ($i=$Offset;$i>=$EndAngle;$i=$i-$Step)
+				{
+					$Xc = cos(($i-90)*PI/180) * $Radius + $X;
+					$Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight;
+					
+					if ( $FirstPoint )
+					{ $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); }
+					else
+					{ $FirstPoint = FALSE; }
+					
+					$this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings);
+					if ($i < 270 && $i > 90 )
+					{ $this->pChartObject->drawAntialiasPixel($Xc,$Yc+$SliceHeight,$Settings); }
+				}
+				$this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings);
+				
+				$Offset = $i - $DataGapAngle; $ID++;
+			}
+		}
+		
      if ( $WriteValues != NULL )
       {
        $Step = 360 / (2 * PI * $Radius);