1 |
efrain |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
pDraw - pChart core class
|
|
|
4 |
|
|
|
5 |
Version : 2.1.4
|
|
|
6 |
Made by : Jean-Damien POGOLOTTI
|
|
|
7 |
Last Update : 19/01/2014
|
|
|
8 |
|
|
|
9 |
This file can be distributed under the license you can find at :
|
|
|
10 |
|
|
|
11 |
http://www.pchart.net/license
|
|
|
12 |
|
|
|
13 |
You can find the whole class documentation on the pChart web site.
|
|
|
14 |
*/
|
|
|
15 |
/* The GD extension is mandatory */
|
|
|
16 |
|
|
|
17 |
if (!extension_loaded('gd') && !extension_loaded('gd2')) {
|
|
|
18 |
echo "GD extension must be loaded. \r\n";
|
|
|
19 |
exit();
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
/* Image map handling */
|
|
|
23 |
define("IMAGE_MAP_STORAGE_FILE", 680001);
|
|
|
24 |
define("IMAGE_MAP_STORAGE_SESSION", 680002);
|
|
|
25 |
/* Last generated chart layout */
|
|
|
26 |
define("CHART_LAST_LAYOUT_REGULAR", 680011);
|
|
|
27 |
define("CHART_LAST_LAYOUT_STACKED", 680012);
|
|
|
28 |
/* ImageMap string delimiter */
|
|
|
29 |
define("IMAGE_MAP_DELIMITER", chr(1));
|
|
|
30 |
|
|
|
31 |
class pImage extends pDraw
|
|
|
32 |
{
|
|
|
33 |
/* Image settings, size, quality, .. */
|
|
|
34 |
var $XSize = NULL; // Width of the picture
|
|
|
35 |
var $YSize = NULL; // Height of the picture
|
|
|
36 |
var $Picture = NULL; // GD picture object
|
|
|
37 |
var $Antialias = TRUE; // Turn antialias on or off
|
|
|
38 |
var $AntialiasQuality = 0; // Quality of the antialiasing implementation (0-1)
|
|
|
39 |
|
|
|
40 |
// var $Mask = ""; // Already drawn pixels mask (Filled circle implementation) # UNUSED
|
|
|
41 |
|
|
|
42 |
var $TransparentBackground = FALSE; // Just to know if we need to flush the alpha channels when rendering
|
|
|
43 |
/* Graph area settings */
|
|
|
44 |
var $GraphAreaX1 = NULL; // Graph area X origin
|
|
|
45 |
var $GraphAreaY1 = NULL; // Graph area Y origin
|
|
|
46 |
var $GraphAreaX2 = NULL; // Graph area bottom right X position
|
|
|
47 |
var $GraphAreaY2 = NULL; // Graph area bottom right Y position
|
|
|
48 |
/* Scale settings */
|
|
|
49 |
var $ScaleMinDivHeight = 20; // Minimum height for scame divs
|
|
|
50 |
/* Font properties */
|
|
|
51 |
var $FontName = "fonts/GeosansLight.ttf"; // Default font file
|
|
|
52 |
var $FontSize = 12; // Default font size
|
|
|
53 |
var $FontBox = NULL; // Return the bounding box of the last written string
|
|
|
54 |
var $FontColorR = 0; // Default color settings
|
|
|
55 |
var $FontColorG = 0; // Default color settings
|
|
|
56 |
var $FontColorB = 0; // Default color settings
|
|
|
57 |
var $FontColorA = 100; // Default transparency
|
|
|
58 |
/* Shadow properties */
|
|
|
59 |
var $Shadow = FALSE; // Turn shadows on or off
|
|
|
60 |
var $ShadowX = NULL; // X Offset of the shadow
|
|
|
61 |
var $ShadowY = NULL; // Y Offset of the shadow
|
|
|
62 |
var $ShadowR = NULL; // R component of the shadow
|
|
|
63 |
var $ShadowG = NULL; // G component of the shadow
|
|
|
64 |
var $ShadowB = NULL; // B component of the shadow
|
|
|
65 |
var $Shadowa = NULL; // Alpha level of the shadow
|
|
|
66 |
/* Image map */
|
|
|
67 |
var $ImageMap = NULL; // Aray containing the image map
|
|
|
68 |
var $ImageMapIndex = "pChart"; // Name of the session array
|
|
|
69 |
var $ImageMapStorageMode = NULL; // Save the current imagemap storage mode
|
|
|
70 |
var $ImageMapAutoDelete = TRUE; // Automatic deletion of the image map temp files
|
|
|
71 |
/* Data Set */
|
|
|
72 |
var $DataSet = NULL; // Attached dataset
|
|
|
73 |
/* Last generated chart info */
|
|
|
74 |
var $LastChartLayout = CHART_LAST_LAYOUT_REGULAR; // Last layout : regular or stacked
|
|
|
75 |
|
|
|
76 |
/* Class constructor */
|
|
|
77 |
function __construct($XSize, $YSize, $DataSet = NULL, $TransparentBackground = FALSE)
|
|
|
78 |
{
|
|
|
79 |
$this->TransparentBackground = $TransparentBackground;
|
|
|
80 |
if ($DataSet != NULL) {
|
|
|
81 |
$this->DataSet = $DataSet;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$this->XSize = $XSize;
|
|
|
85 |
$this->YSize = $YSize;
|
|
|
86 |
$this->Picture = imagecreatetruecolor($XSize, $YSize);
|
|
|
87 |
if ($this->TransparentBackground) {
|
|
|
88 |
imagealphablending($this->Picture, FALSE);
|
|
|
89 |
imagefilledrectangle($this->Picture, 0, 0, $XSize, $YSize, imagecolorallocatealpha($this->Picture, 255, 255, 255, 127));
|
|
|
90 |
imagealphablending($this->Picture, TRUE);
|
|
|
91 |
imagesavealpha($this->Picture, true);
|
|
|
92 |
} else {
|
|
|
93 |
imagefilledrectangle($this->Picture, 0, 0, $XSize, $YSize, $this->AllocateColor(255, 255, 255));
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
function __destruct(){
|
|
|
98 |
imagedestroy($this->Picture);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/* Enable / Disable and set shadow properties */
|
|
|
102 |
function setShadow($Enabled = TRUE, array $Format = [])
|
|
|
103 |
{
|
|
|
104 |
$X = 2;
|
|
|
105 |
$Y = 2;
|
|
|
106 |
$R = 0;
|
|
|
107 |
$G = 0;
|
|
|
108 |
$B = 0;
|
|
|
109 |
$Alpha = 10;
|
|
|
110 |
|
|
|
111 |
/* Override defaults */
|
|
|
112 |
extract($Format);
|
|
|
113 |
|
|
|
114 |
$this->Shadow = $Enabled;
|
|
|
115 |
$this->ShadowX = $X;
|
|
|
116 |
$this->ShadowY = $Y;
|
|
|
117 |
$this->ShadowR = $R;
|
|
|
118 |
$this->ShadowG = $G;
|
|
|
119 |
$this->ShadowB = $B;
|
|
|
120 |
$this->Shadowa = $Alpha;
|
|
|
121 |
|
|
|
122 |
if ($this->ShadowX == 0 || $this->ShadowY == 0){
|
|
|
123 |
die("Invalid shadow specs");
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
/* Set the graph area position */
|
|
|
128 |
function setGraphArea($X1, $Y1, $X2, $Y2)
|
|
|
129 |
{
|
|
|
130 |
if ($X2 < $X1 || $X1 == $X2 || $Y2 < $Y1 || $Y1 == $Y2) {
|
|
|
131 |
return -1;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
$this->GraphAreaX1 = $X1;
|
|
|
135 |
$this->DataSet->Data["GraphArea"]["X1"] = $X1;
|
|
|
136 |
$this->GraphAreaY1 = $Y1;
|
|
|
137 |
$this->DataSet->Data["GraphArea"]["Y1"] = $Y1;
|
|
|
138 |
$this->GraphAreaX2 = $X2;
|
|
|
139 |
$this->DataSet->Data["GraphArea"]["X2"] = $X2;
|
|
|
140 |
$this->GraphAreaY2 = $Y2;
|
|
|
141 |
$this->DataSet->Data["GraphArea"]["Y2"] = $Y2;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
/* Return the width of the picture */
|
|
|
145 |
function getWidth()
|
|
|
146 |
{
|
|
|
147 |
return $this->XSize;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
/* Return the heigth of the picture */
|
|
|
151 |
function getHeight()
|
|
|
152 |
{
|
|
|
153 |
return $this->YSize;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
/* Render the picture to a file */
|
|
|
157 |
function render($FileName)
|
|
|
158 |
{
|
|
|
159 |
if ($this->TransparentBackground) {
|
|
|
160 |
imagealphablending($this->Picture, false);
|
|
|
161 |
imagesavealpha($this->Picture, true);
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
imagepng($this->Picture, $FileName);
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
/* Render the picture to a web browser stream */
|
|
|
168 |
function stroke($BrowserExpire = FALSE)
|
|
|
169 |
{
|
|
|
170 |
if ($this->TransparentBackground) {
|
|
|
171 |
imagealphablending($this->Picture, false);
|
|
|
172 |
imagesavealpha($this->Picture, true);
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
if ($BrowserExpire) {
|
|
|
176 |
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
|
177 |
header("Cache-Control: no-cache");
|
|
|
178 |
header("Pragma: no-cache");
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
header('Content-type: image/png');
|
|
|
182 |
imagepng($this->Picture);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
/* Automatic output method based on the calling interface */
|
|
|
186 |
function autoOutput($FileName = "output.png")
|
|
|
187 |
{
|
|
|
188 |
if (php_sapi_name() == "cli") {
|
|
|
189 |
$this->Render($FileName);
|
|
|
190 |
} else {
|
|
|
191 |
$this->Stroke();
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
/* Return the length between two points */
|
|
|
196 |
function getLength($X1, $Y1, $X2, $Y2)
|
|
|
197 |
{
|
|
|
198 |
return (sqrt(pow(max($X1, $X2) - min($X1, $X2), 2) + pow(max($Y1, $Y2) - min($Y1, $Y2), 2)));
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
/* Return the orientation of a line */
|
|
|
202 |
function getAngle($X1, $Y1, $X2, $Y2)
|
|
|
203 |
{
|
|
|
204 |
$Opposite = $Y2 - $Y1;
|
|
|
205 |
$Adjacent = $X2 - $X1;
|
|
|
206 |
$Angle = rad2deg(atan2($Opposite, $Adjacent));
|
|
|
207 |
|
|
|
208 |
return (($Angle > 0) ? $Angle : (360 - abs($Angle)));
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
/* Return the surrounding box of text area */
|
|
|
212 |
function getTextBox_deprecated($X, $Y, $FontName, $FontSize, $Angle, $Text)
|
|
|
213 |
{
|
|
|
214 |
$Size = imagettfbbox($FontSize, $Angle, realpath($FontName), $Text);
|
|
|
215 |
$Width = $this->getLength($Size[0], $Size[1], $Size[2], $Size[3]) + 1;
|
|
|
216 |
$Height = $this->getLength($Size[2], $Size[3], $Size[4], $Size[5]) + 1;
|
|
|
217 |
$RealPos[0]["X"] = $X;
|
|
|
218 |
$RealPos[0]["Y"] = $Y;
|
|
|
219 |
$RealPos[1]["X"] = cos((360 - $Angle) * PI / 180) * $Width + $RealPos[0]["X"];
|
|
|
220 |
$RealPos[1]["Y"] = sin((360 - $Angle) * PI / 180) * $Width + $RealPos[0]["Y"];
|
|
|
221 |
$RealPos[2]["X"] = cos((270 - $Angle) * PI / 180) * $Height + $RealPos[1]["X"];
|
|
|
222 |
$RealPos[2]["Y"] = sin((270 - $Angle) * PI / 180) * $Height + $RealPos[1]["Y"];
|
|
|
223 |
$RealPos[3]["X"] = cos((180 - $Angle) * PI / 180) * $Width + $RealPos[2]["X"];
|
|
|
224 |
$RealPos[3]["Y"] = sin((180 - $Angle) * PI / 180) * $Width + $RealPos[2]["Y"];
|
|
|
225 |
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"];
|
|
|
226 |
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
|
|
|
227 |
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"];
|
|
|
228 |
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
|
|
|
229 |
return $RealPos;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
/* Return the surrounding box of text area */
|
|
|
233 |
function getTextBox($X, $Y, $FontName, $FontSize, $Angle, $Text)
|
|
|
234 |
{
|
|
|
235 |
$coords = imagettfbbox($FontSize, 0, realpath($FontName), $Text);
|
|
|
236 |
$a = deg2rad($Angle);
|
|
|
237 |
$ca = cos($a);
|
|
|
238 |
$sa = sin($a);
|
|
|
239 |
$RealPos = [];
|
|
|
240 |
for ($i = 0; $i < 7; $i+= 2) {
|
|
|
241 |
$RealPos[$i / 2]["X"] = $X + round($coords[$i] * $ca + $coords[$i + 1] * $sa);
|
|
|
242 |
$RealPos[$i / 2]["Y"] = $Y + round($coords[$i + 1] * $ca - $coords[$i] * $sa);
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"];
|
|
|
246 |
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
|
|
|
247 |
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"];
|
|
|
248 |
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
|
|
|
249 |
$RealPos[TEXT_ALIGN_TOPLEFT]["X"] = $RealPos[3]["X"];
|
|
|
250 |
$RealPos[TEXT_ALIGN_TOPLEFT]["Y"] = $RealPos[3]["Y"];
|
|
|
251 |
$RealPos[TEXT_ALIGN_TOPRIGHT]["X"] = $RealPos[2]["X"];
|
|
|
252 |
$RealPos[TEXT_ALIGN_TOPRIGHT]["Y"] = $RealPos[2]["Y"];
|
|
|
253 |
$RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["X"] = ($RealPos[1]["X"] - $RealPos[0]["X"]) / 2 + $RealPos[0]["X"];
|
|
|
254 |
$RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["Y"] = ($RealPos[0]["Y"] - $RealPos[1]["Y"]) / 2 + $RealPos[1]["Y"];
|
|
|
255 |
$RealPos[TEXT_ALIGN_TOPMIDDLE]["X"] = ($RealPos[2]["X"] - $RealPos[3]["X"]) / 2 + $RealPos[3]["X"];
|
|
|
256 |
$RealPos[TEXT_ALIGN_TOPMIDDLE]["Y"] = ($RealPos[3]["Y"] - $RealPos[2]["Y"]) / 2 + $RealPos[2]["Y"];
|
|
|
257 |
$RealPos[TEXT_ALIGN_MIDDLELEFT]["X"] = ($RealPos[0]["X"] - $RealPos[3]["X"]) / 2 + $RealPos[3]["X"];
|
|
|
258 |
$RealPos[TEXT_ALIGN_MIDDLELEFT]["Y"] = ($RealPos[0]["Y"] - $RealPos[3]["Y"]) / 2 + $RealPos[3]["Y"];
|
|
|
259 |
$RealPos[TEXT_ALIGN_MIDDLERIGHT]["X"] = ($RealPos[1]["X"] - $RealPos[2]["X"]) / 2 + $RealPos[2]["X"];
|
|
|
260 |
$RealPos[TEXT_ALIGN_MIDDLERIGHT]["Y"] = ($RealPos[1]["Y"] - $RealPos[2]["Y"]) / 2 + $RealPos[2]["Y"];
|
|
|
261 |
$RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["X"] = ($RealPos[1]["X"] - $RealPos[3]["X"]) / 2 + $RealPos[3]["X"];
|
|
|
262 |
$RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["Y"] = ($RealPos[0]["Y"] - $RealPos[2]["Y"]) / 2 + $RealPos[2]["Y"];
|
|
|
263 |
return $RealPos;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
/* Set current font properties */
|
|
|
267 |
function setFontProperties(array $Format = [])
|
|
|
268 |
{
|
|
|
269 |
$R = -1;
|
|
|
270 |
$G = -1;
|
|
|
271 |
$B = -1;
|
|
|
272 |
$Alpha = 100;
|
|
|
273 |
$FontName = NULL;
|
|
|
274 |
$FontSize = NULL;
|
|
|
275 |
|
|
|
276 |
/* Override defaults */
|
|
|
277 |
extract($Format);
|
|
|
278 |
|
|
|
279 |
($R != - 1) AND $this->FontColorR = $R;
|
|
|
280 |
($G != - 1) AND $this->FontColorG = $G;
|
|
|
281 |
($B != - 1) AND $this->FontColorB = $B;
|
|
|
282 |
($Alpha != NULL) AND $this->FontColorA = $Alpha;
|
|
|
283 |
($FontName != NULL) AND $this->FontName = $FontName;
|
|
|
284 |
($FontSize != NULL) AND $this->FontSize = $FontSize;
|
|
|
285 |
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
/* Returns the 1st decimal values (used to correct AA bugs) */
|
|
|
289 |
function getFirstDecimal($Value)
|
|
|
290 |
{
|
|
|
291 |
$Values = explode(".", $Value);
|
|
|
292 |
return (isset($Values[1])) ? substr($Values[1], 0, 1) : 0;
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
/* Attach a dataset to your pChart Object */
|
|
|
296 |
function setDataSet(&$DataSet)
|
|
|
297 |
{
|
|
|
298 |
$this->DataSet = $DataSet;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
/* Print attached dataset contents to STDOUT */
|
|
|
302 |
function printDataSet()
|
|
|
303 |
{
|
|
|
304 |
print_r($this->DataSet);
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
/* Initialise the image map methods */
|
|
|
308 |
function initialiseImageMap($Name = "pChart", $StorageMode = IMAGE_MAP_STORAGE_SESSION, $UniqueID = "imageMap", $StorageFolder = "tmp")
|
|
|
309 |
{
|
|
|
310 |
$this->ImageMapIndex = $Name;
|
|
|
311 |
$this->ImageMapStorageMode = $StorageMode;
|
|
|
312 |
if ($StorageMode == IMAGE_MAP_STORAGE_SESSION) {
|
|
|
313 |
if (!isset($_SESSION)) {
|
|
|
314 |
session_start();
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
$_SESSION[$this->ImageMapIndex] = NULL;
|
|
|
318 |
} elseif ($StorageMode == IMAGE_MAP_STORAGE_FILE) {
|
|
|
319 |
$this->ImageMapFileName = $UniqueID;
|
|
|
320 |
$this->ImageMapStorageFolder = $StorageFolder;
|
|
|
321 |
if (file_exists($StorageFolder . "/" . $UniqueID . ".map")) {
|
|
|
322 |
unlink($StorageFolder . "/" . $UniqueID . ".map");
|
|
|
323 |
}
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
/* Add a zone to the image map */
|
|
|
328 |
function addToImageMap($Type, $Plots, $Color = NULL, $Title = NULL, $Message = NULL, $HTMLEncode = FALSE)
|
|
|
329 |
{
|
|
|
330 |
if ($this->ImageMapStorageMode == NULL) {
|
|
|
331 |
$this->initialiseImageMap();
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
/* Encode the characters in the imagemap in HTML standards */
|
|
|
335 |
$Title = str_replace("€", "\u20AC", $Title); # Momchil TODO TEST THIS
|
|
|
336 |
$Title = htmlentities($Title, ENT_QUOTES); #, "ISO-8859-15"); # As of PHP 5.6 The default value for the encoding parameter = the default_charset config option.
|
|
|
337 |
|
|
|
338 |
if ($HTMLEncode) {
|
|
|
339 |
$Message = htmlentities($Message, ENT_QUOTES); #, "ISO-8859-15");
|
|
|
340 |
#$Message = str_replace("<", "<", $Message); # Seems covered Example #1 A htmlentities() example
|
|
|
341 |
#$Message = str_replace(">", ">", $Message); # http://php.net/manual/en/function.htmlentities.php
|
|
|
342 |
}
|
|
|
343 |
|
|
|
344 |
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
|
|
|
345 |
if (!isset($_SESSION)) {
|
|
|
346 |
$this->initialiseImageMap();
|
|
|
347 |
}
|
|
|
348 |
$_SESSION[$this->ImageMapIndex][] = [$Type,$Plots,$Color,$Title,$Message];
|
|
|
349 |
|
|
|
350 |
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
|
|
|
351 |
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", 'a');
|
|
|
352 |
fwrite($Handle, $Type . IMAGE_MAP_DELIMITER . $Plots . IMAGE_MAP_DELIMITER . $Color . IMAGE_MAP_DELIMITER . $Title . IMAGE_MAP_DELIMITER . $Message . "\r\n");
|
|
|
353 |
fclose($Handle);
|
|
|
354 |
}
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
/* Remove VOID values from an imagemap custom values array */
|
|
|
358 |
function removeVOIDFromArray($SerieName, array $Values)
|
|
|
359 |
{
|
|
|
360 |
if (!isset($this->DataSet->Data["Series"][$SerieName])) {
|
|
|
361 |
return -1;
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
$Result = [];
|
|
|
365 |
foreach($this->DataSet->Data["Series"][$SerieName]["Data"] as $Key => $Value) {
|
|
|
366 |
if ($Value != VOID && isset($Values[$Key])) {
|
|
|
367 |
$Result[] = $Values[$Key];
|
|
|
368 |
}
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
return $Result;
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
/* Replace the title of one image map serie */
|
|
|
375 |
function replaceImageMapTitle($OldTitle, $NewTitle)
|
|
|
376 |
{
|
|
|
377 |
if ($this->ImageMapStorageMode == NULL) {
|
|
|
378 |
return -1;
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
if (is_array($NewTitle)) {
|
|
|
382 |
$NewTitle = $this->removeVOIDFromArray($OldTitle, $NewTitle);
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
|
|
|
386 |
if (!isset($_SESSION)) {
|
|
|
387 |
return -1;
|
|
|
388 |
}
|
|
|
389 |
|
|
|
390 |
if (is_array($NewTitle)) {
|
|
|
391 |
$ID = 0;
|
|
|
392 |
foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
|
|
|
393 |
if ($Settings[3] == $OldTitle && isset($NewTitle[$ID])) {
|
|
|
394 |
$_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle[$ID];
|
|
|
395 |
$ID++;
|
|
|
396 |
}
|
|
|
397 |
}
|
|
|
398 |
} else {
|
|
|
399 |
foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
|
|
|
400 |
if ($Settings[3] == $OldTitle) {
|
|
|
401 |
$_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle;
|
|
|
402 |
}
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
|
|
|
407 |
$TempArray = [];
|
|
|
408 |
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", "r");
|
|
|
409 |
if ($Handle) {
|
|
|
410 |
while (($Buffer = fgets($Handle, 4096)) !== false) {
|
|
|
411 |
$Fields = preg_split("/" . IMAGE_MAP_DELIMITER . "/", str_replace([chr(10), chr(13)], "", $Buffer));
|
|
|
412 |
$TempArray[] = [$Fields[0], $Fields[1], $Fields[2], $Fields[3], $Fields[4]];
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
fclose($Handle);
|
|
|
416 |
if (is_array($NewTitle)) {
|
|
|
417 |
$ID = 0;
|
|
|
418 |
foreach($TempArray as $Key => $Settings) {
|
|
|
419 |
if ($Settings[3] == $OldTitle && isset($NewTitle[$ID])) {
|
|
|
420 |
$TempArray[$Key][3] = $NewTitle[$ID];
|
|
|
421 |
$ID++;
|
|
|
422 |
}
|
|
|
423 |
}
|
|
|
424 |
} else {
|
|
|
425 |
foreach($TempArray as $Key => $Settings) {
|
|
|
426 |
if ($Settings[3] == $OldTitle) {
|
|
|
427 |
$TempArray[$Key][3] = $NewTitle;
|
|
|
428 |
}
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
|
|
|
432 |
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", 'w');
|
|
|
433 |
foreach($TempArray as $Key => $Settings) {
|
|
|
434 |
fwrite($Handle, $Settings[0] . IMAGE_MAP_DELIMITER . $Settings[1] . IMAGE_MAP_DELIMITER . $Settings[2] . IMAGE_MAP_DELIMITER . $Settings[3] . IMAGE_MAP_DELIMITER . $Settings[4] . "\r\n");
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
fclose($Handle);
|
|
|
438 |
}
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
/* Replace the values of the image map contents */
|
|
|
443 |
function replaceImageMapValues($Title, array $Values)
|
|
|
444 |
{
|
|
|
445 |
if ($this->ImageMapStorageMode == NULL) {
|
|
|
446 |
return -1;
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
$Values = $this->removeVOIDFromArray($Title, $Values);
|
|
|
450 |
$ID = 0;
|
|
|
451 |
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
|
|
|
452 |
if (!isset($_SESSION)) {
|
|
|
453 |
return -1;
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
|
|
|
457 |
if ($Settings[3] == $Title) {
|
|
|
458 |
if (isset($Values[$ID])) {
|
|
|
459 |
$_SESSION[$this->ImageMapIndex][$Key][4] = $Values[$ID];
|
|
|
460 |
}
|
|
|
461 |
$ID++;
|
|
|
462 |
}
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
|
|
|
466 |
$TempArray = [];
|
|
|
467 |
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", "r");
|
|
|
468 |
if ($Handle) {
|
|
|
469 |
while (($Buffer = fgets($Handle, 4096)) !== false) {
|
|
|
470 |
$Fields = preg_split("/" . IMAGE_MAP_DELIMITER . "/", str_replace([chr(10), chr(13)], "", $Buffer));
|
|
|
471 |
$TempArray[] = [$Fields[0], $Fields[1], $Fields[2], $Fields[3], $Fields[4]];
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
fclose($Handle);
|
|
|
475 |
foreach($TempArray as $Key => $Settings) {
|
|
|
476 |
if ($Settings[3] == $Title) {
|
|
|
477 |
if (isset($Values[$ID])) {
|
|
|
478 |
$TempArray[$Key][4] = $Values[$ID];
|
|
|
479 |
}
|
|
|
480 |
$ID++;
|
|
|
481 |
}
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", 'w');
|
|
|
485 |
foreach($TempArray as $Key => $Settings) {
|
|
|
486 |
fwrite($Handle, $Settings[0] . IMAGE_MAP_DELIMITER . $Settings[1] . IMAGE_MAP_DELIMITER . $Settings[2] . IMAGE_MAP_DELIMITER . $Settings[3] . IMAGE_MAP_DELIMITER . $Settings[4] . "\r\n");
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
fclose($Handle);
|
|
|
490 |
}
|
|
|
491 |
}
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
/* Dump the image map */
|
|
|
495 |
function dumpImageMap($Name = "pChart", $StorageMode = IMAGE_MAP_STORAGE_SESSION, $UniqueID = "imageMap", $StorageFolder = "tmp")
|
|
|
496 |
{
|
|
|
497 |
$this->ImageMapIndex = $Name;
|
|
|
498 |
$this->ImageMapStorageMode = $StorageMode;
|
|
|
499 |
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
|
|
|
500 |
if (!isset($_SESSION)) {
|
|
|
501 |
session_start();
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
if ($_SESSION[$Name] != NULL) {
|
|
|
505 |
foreach($_SESSION[$Name] as $Key => $Params) {
|
|
|
506 |
echo $Params[0] . IMAGE_MAP_DELIMITER . $Params[1] . IMAGE_MAP_DELIMITER . $Params[2] . IMAGE_MAP_DELIMITER . $Params[3] . IMAGE_MAP_DELIMITER . $Params[4] . "\r\n";
|
|
|
507 |
}
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
|
|
|
511 |
if (file_exists($StorageFolder . "/" . $UniqueID . ".map")) {
|
|
|
512 |
$Handle = fopen($StorageFolder . "/" . $UniqueID . ".map", "r");
|
|
|
513 |
if ($Handle) {
|
|
|
514 |
while (($Buffer = fgets($Handle, 4096)) !== false) {
|
|
|
515 |
echo $Buffer;
|
|
|
516 |
}
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
fclose($Handle);
|
|
|
520 |
if ($this->ImageMapAutoDelete) {
|
|
|
521 |
unlink($StorageFolder . "/" . $UniqueID . ".map");
|
|
|
522 |
}
|
|
|
523 |
}
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
/* When the image map is returned to the client, the script ends */
|
|
|
527 |
exit();
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
/* Return the HTML converted color from the RGB composite values */
|
|
|
531 |
function toHTMLColor($R, $G, $B) # Momchil: Not worth caching
|
|
|
532 |
{
|
|
|
533 |
|
|
|
534 |
$R = dechex(max(min(255, $R), 0));
|
|
|
535 |
$G = dechex(max(min(255, $G), 0));
|
|
|
536 |
$B = dechex(max(min(255, $B), 0));
|
|
|
537 |
|
|
|
538 |
$Color = "#" . (strlen($R) < 2 ? '0' : '') . $R;
|
|
|
539 |
$Color.= (strlen($G) < 2 ? '0' : '') . $G;
|
|
|
540 |
$Color.= (strlen($B) < 2 ? '0' : '') . $B;
|
|
|
541 |
|
|
|
542 |
return $Color;
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
/* Reverse an array of points */
|
|
|
546 |
function reversePlots($Plots)
|
|
|
547 |
{
|
|
|
548 |
$Result = [];
|
|
|
549 |
for ($i = count($Plots) - 2; $i >= 0; $i = $i - 2) {
|
|
|
550 |
$Result[] = $Plots[$i];
|
|
|
551 |
$Result[] = $Plots[$i + 1];
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
return $Result;
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
/* Mirror Effect */
|
|
|
558 |
function drawAreaMirror($X, $Y, $Width, $Height, array $Format = [])
|
|
|
559 |
{
|
|
|
560 |
$StartAlpha = isset($Format["StartAlpha"]) ? $Format["StartAlpha"] : 80;
|
|
|
561 |
$EndAlpha = isset($Format["EndAlpha"]) ? $Format["EndAlpha"] : 0;
|
|
|
562 |
$AlphaStep = ($StartAlpha - $EndAlpha) / $Height;
|
|
|
563 |
$Picture = imagecreatetruecolor($this->XSize, $this->YSize);
|
|
|
564 |
imagecopy($Picture, $this->Picture, 0, 0, 0, 0, $this->XSize, $this->YSize);
|
|
|
565 |
for ($i = 1; $i <= $Height; $i++) {
|
|
|
566 |
if ($Y + ($i - 1) < $this->YSize && $Y - $i > 0) {
|
|
|
567 |
imagecopymerge($Picture, $this->Picture, $X, $Y + ($i - 1), $X, $Y - $i, $Width, 1, $StartAlpha - $AlphaStep * $i);
|
|
|
568 |
}
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
imagecopy($this->Picture, $Picture, 0, 0, 0, 0, $this->XSize, $this->YSize);
|
|
|
572 |
|
|
|
573 |
imagedestroy($Picture);
|
|
|
574 |
}
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
?>
|