MDL-12789 - dont unnecessarily iterate over all groups
[moodle.git] / iplookup / ipatlas / plot.php
CommitLineData
f4fb66d7 1<?php
2
3include("plotconf.inc");
4include("plot.inc");
5
6if (isset($user)) {
7 $user = get_record("user", "id", $user);
8 $fullname = fullname($user, true);
9 $username = "<b>$fullname</b> [$user->city, $user->country] : ";
10} else {
11 $username = "";
12}
13
f4fb66d7 14// cleanup
15if (isset($HTTP_GET_VARS["lastquery"])) {
16 $HTTP_GET_VARS["lastquery"] = clean_param($HTTP_GET_VARS["lastquery"], PARAM_HOST);
17}
18
19// check if it is the user's ip, or another host
20
21if(!isset($HTTP_GET_VARS["address"]) || ($HTTP_GET_VARS["address"] == "")) {
22 $address = $HTTP_SERVER_VARS['REMOTE_ADDR'];
23 $local = 1;
24} else {
25 $HTTP_GET_VARS["address"] = clean_param($HTTP_GET_VARS["address"], PARAM_HOST);
26 $address = $HTTP_GET_VARS["address"];
27 $local = 0;
28}
29
30// this is the most important function, gets lat/lon and description of location
31$values = getstuff($address, $local) or die("Error in plot.inc");
32
33if(isset($logging) && is_writable("plotlog.txt")) {
34 $log = @fopen("plotlog.txt", "a") or print "";
35 @fputs($log, $HTTP_SERVER_VARS["REMOTE_ADDR"] ."\t". date("F j, Y, g:i a") . "\t$address\t$values[address]\t$values[lat]\t$values[lon]\n") or print "";
36@fclose($log);
37}
38
39if(isset($HTTP_COOKIE_VARS["atlasprefs"]) && validcookie($HTTP_COOKIE_VARS["atlasprefs"])) {
40list( , , , $imagething) = split(":", $HTTP_COOKIE_VARS["atlasprefs"]);
41$imagething = clean_param($imagething, PARAM_FILE);
42$earthimage = isvalidimage($imagething, $earthimages, $defaultimage);
43} else {
44$earthimage = $earthimages[$defaultimage];
45}
46
47if(strstr($earthimage, ":")) {
48 list($earthimage, , , ) = split(":", $earthimage);
49}
50
51// check if we need to run it in css mode
52if(!shouldrun($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
53
54list($width, $height) = getimagecoords($earthimages, $earthimage);
55
56 // make sure some coords were found
57 if($values["lat"] == "" || $values["lon"] == "") {
58
59 $display = "&nbsp;";
60 $extracss = "";
61
62} else {
63
64list($x, $y) = getlocationcoords($values["lat"], $values["lon"], $width, $height);
65
66if(isset($HTTP_COOKIE_VARS["atlasprefs"])) {
67list( , , , , $dotname) = split(":", $HTTP_COOKIE_VARS["atlasprefs"]);
68$dotname = clean_param($dotname, PARAM_FILE);
69list($thedot, $dotwidth, $dotheight) = finddot($dotname, $cssdots, $defaultdot);
70} else {
71$dotname = $cssdots[$defaultdot];
72list($dotname, , , ) = split(":", $dotname);
73$dotname = clean_param($dotname, PARAM_FILE);
74list($thedot, $dotwidth, $dotheight) = finddot($dotname, $cssdots, $defaultdot);
75}
76
77// magical formula for placing the css dot
78$x = ($x - floor($dotwidth / 2));
79$y = ($y - floor($dotheight / 2));
80
81$extracss = "<style>
82#dotDiv { padding-left:$x; padding-top:$y; }
83</style>";
84$display = "<div id=\"dotDiv\"><img width=\"$dotwidth\" height=\"$dotheight\" src=\"$thedot\">";
85
86 }
87
88} else {
89
90 // gd mode
91
92list($width, $height) = getimagecoords($earthimages, $earthimage) or die("Unable to find width/height for image $earthimage in config file");
93$extracss = "";
94$display = "<img src=\"plotimage.php?lat=$values[lat]&amp;lon=$values[lon]\" width=\"$width\" height=\"$height\" alt=\"\" />";
95
96}
97
98# START HTML
99
100print '
101
102<html><head><title>'.t("Plotting").' '.$values["address"].'</title>
103'.$extracss.'
104
105<!-- your head tags here -->
106<link rel="Stylesheet" href="ip-atlas.css">
107</head><body bgcolor="#FFFFFF">
108
109
110<a name="map"></a>
111
112<table valign="top" cellpadding=0 cellspacing=0 border=0 background="'.$earthimage.'" width="'.$width.'" height="'.$height.'"><tr><td valign="top">'.$display.'</td></tr></table>
113
114
115<br />
116';
117
118if(isset($address)) {
119print "$username $values[desc]";
120}
121
122$PHP_SELF = 'plot.php';
123
124print '
125<br /><br />
126<form method="GET" action="'.$PHP_SELF.'#map">
127<table width="100%"><tr><td nowrap align="left">
60af2703 128'.t("IP/Hostname:").' <input value="'.$values["address"].'" type="text" size="30" name="address" /><input type="Submit" value="'.t("Submit").'" /></td><td align="right" width="100%">
f4fb66d7 129[ <a href="ip-atlas_prefs.php?lastquery='?><?php if(isset($HTTP_GET_VARS["address"])) { echo $HTTP_GET_VARS["address"]; } ?><?php echo '">'.t("preferences").'</a> ]
130[ <a href="'."$PHP_SELF".'">'.t("locate me").'</a> ]
131</td></tr></table>
132</form>
133';
134
135include("footer.inc");
136
137print "</body></html>";
138
139?>