MDL-12789 - dont unnecessarily iterate over all groups
[moodle.git] / iplookup / ipatlas / plotimage.php
CommitLineData
f4fb66d7 1<?php
2
3include("plotconf.inc");
4include("plot.inc");
5
6$form_vars = ${"HTTP_".$HTTP_SERVER_VARS["REQUEST_METHOD"]."_VARS"};
7$lat = $form_vars['lat'];
8$lon = $form_vars['lon'];
9
10if(isset($HTTP_COOKIE_VARS["atlasprefs"]) && validcookie($HTTP_COOKIE_VARS["atlasprefs"])) {
11 list($setshape, $setcolor, $setsize, $earthimage, , ) = split(":", $HTTP_COOKIE_VARS["atlasprefs"]);
12} else {
13 $setshape = "Diamond";
14 $setcolor = "red";
15 $setsize = "3";
16 $earthimage = $earthimages[$defaultimage];
17 list($earthimage, , , ) = split(":", $earthimage);
18}
19
20$earthimage = isvalidimage($earthimage, $earthimages, $defaultimage);
21
22if(strstr($earthimage, ":")) {
23 list($earthimage, , , ) = split(":", $earthimage);
24}
25
26list($width, $height) = getimagecoords($earthimages, $earthimage);
27
28if($setsize > 8 || $setsize < 2) {
29 $setsize = 2;
30}
31
32$im = @ImageCreate ($width, $height)
33 or die ("Cannot Initialize new GD image stream");
34$background_color = ImageColorAllocate ($im, 255, 255, 255);
35
36
37// color table
38if($setcolor == "red") { $r = "255"; $g = "0"; $b = "0"; }
39elseif($setcolor == "white") { $r = "255"; $g = "255"; $b = "254"; }
40elseif($setcolor == "yellow") { $r = "255"; $g = "255"; $b = "0"; }
41elseif($setcolor == "magenta") { $r = "255"; $g = "0"; $b = "255"; }
42elseif($setcolor == "cyan") { $r = "0"; $g = "255"; $b = "255"; }
43elseif($setcolor == "green") { $r = "0"; $g = "225"; $b = "0"; }
44elseif($setcolor == "violet") { $r = "191"; $g = "0"; $b = "255"; }
45else { $r = "255"; $g = "0"; $b = "0"; }
46
47$loc_color = ImageColorAllocate ($im, $r, $g, $b);
48
49if($lat == "" && $lon == "") { } else {
50
51list($x, $y) = getlocationcoords($lat, $lon, $width, $height);
52
53if($setshape == "Diamond") {
54 ImageLine($im, ($x - $setsize), $y, $x, ($y + $setsize), $loc_color);
55 ImageLine($im, ($x - $setsize), $y, $x, ($y - $setsize), $loc_color);
56 ImageLine($im, ($x + $setsize), $y, $x, ($y + $setsize), $loc_color);
57 ImageLine($im, ($x + $setsize), $y, $x, ($y - $setsize), $loc_color);
58 ImageFill($im, $x, $y, $loc_color);
59} elseif($setshape == "Diamond Outline") {
60 ImageLine($im, ($x - $setsize), $y, $x, ($y + $setsize), $loc_color);
61 ImageLine($im, ($x - $setsize), $y, $x, ($y - $setsize), $loc_color);
62 ImageLine($im, ($x + $setsize), $y, $x, ($y + $setsize), $loc_color);
63 ImageLine($im, ($x + $setsize), $y, $x, ($y - $setsize), $loc_color);
64} elseif($setshape == "Square") {
65 ImageFilledRectangle($im, ($x - $setsize), ($y - $setsize), ($x + $setsize), ($y + $setsize), $loc_color);
66} elseif($setshape == "Square Outline") {
67 ImageRectangle($im, ($x - $setsize), ($y - $setsize), ($x + $setsize), ($y + $setsize), $loc_color);
68} elseif($setshape == "Cross") {
69 ImageLine($im, ($x - $setsize), $y, ($x + $setsize), $y, $loc_color);
70 ImageLine($im, $x, ($y - $setsize), $x, ($y + $setsize), $loc_color);
71} else {
72// draw a diamond if error
73 ImageLine($im, ($x - $setsize), $y, $x, ($y + $setsize), $loc_color);
74 ImageLine($im, ($x - $setsize), $y, $x, ($y - $setsize), $loc_color);
75 ImageLine($im, ($x + $setsize), $y, $x, ($y + $setsize), $loc_color);
76 ImageLine($im, ($x + $setsize), $y, $x, ($y - $setsize), $loc_color);
77 ImageFill($im, $x, $y, $loc_color);
78}
79
80}
81
82
83ImageColorTransparent ($im, $background_color);
84Header("Pragma: no-cache");
85Header("Expires: Thu, 26-Oct-1972 12:00:00");
86Header("Content-type: image/png");
87ImagePng ($im);
88ImageDestroy($im);
89
90
91?>