Updated version with bug fixes (see bug 2179)
[moodle.git] / lib / ipatlas / plot.php
blob37984a54d46158a324bb58a4a94a33a55b8bee27
1 <?php
3 include("plotconf.inc");
4 include("plot.inc");
6 if (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 = "";
14 if($warnings == "1") {
15 error_reporting(E_ALL);
16 } else {
17 error_reporting(E_ERROR);
20 // check if it is the user's ip, or another host
22 if(!isset($HTTP_GET_VARS["address"]) || ($HTTP_GET_VARS["address"] == "")) {
23 $address = $HTTP_SERVER_VARS['REMOTE_ADDR'];
24 $local = 1;
25 } else {
26 $address = $HTTP_GET_VARS["address"];
27 $local = 0;
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");
33 if(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);
39 if(isset($HTTP_COOKIE_VARS["atlasprefs"]) && validcookie($HTTP_COOKIE_VARS["atlasprefs"])) {
40 list( , , , $imagething) = split(":", $HTTP_COOKIE_VARS["atlasprefs"]);
41 $earthimage = isvalidimage($imagething, $earthimages, $defaultimage);
42 } else {
43 $earthimage = $earthimages[$defaultimage];
46 if(strstr($earthimage, ":")) {
47 list($earthimage, , , ) = split(":", $earthimage);
50 // check if we need to run it in css mode
51 if(!shouldrun($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
53 list($width, $height) = getimagecoords($earthimages, $earthimage);
55 // make sure some coords were found
56 if($values["lat"] == "" || $values["lon"] == "") {
58 $display = "&nbsp;";
59 $extracss = "";
61 } else {
63 list($x, $y) = getlocationcoords($values["lat"], $values["lon"], $width, $height);
65 if(isset($HTTP_COOKIE_VARS["atlasprefs"])) {
66 list( , , , , $dotname) = split(":", $HTTP_COOKIE_VARS["atlasprefs"]);
67 list($thedot, $dotwidth, $dotheight) = finddot($dotname, $cssdots, $defaultdot);
68 } else {
69 $dotname = $cssdots[$defaultdot];
70 list($dotname, , , ) = split(":", $dotname);
71 list($thedot, $dotwidth, $dotheight) = finddot($dotname, $cssdots, $defaultdot);
74 // magical formula for placing the css dot
75 $x = ($x - floor($dotwidth / 2));
76 $y = ($y - floor($dotheight / 2));
78 $extracss = "<style>
79 #dotDiv { padding-left:$x; padding-top:$y; }
80 </style>";
81 $display = "<div id=\"dotDiv\"><img width=\"$dotwidth\" height=\"$dotheight\" src=\"$thedot\">";
85 } else {
87 // gd mode
89 list($width, $height) = getimagecoords($earthimages, $earthimage) or die("Unable to find width/height for image $earthimage in config file");
90 $extracss = "";
91 $display = "<img src=\"plotimage.php?lat=$values[lat]&lon=$values[lon]\" width=\"$width\" height=\"$height\">";
95 # START HTML
97 print '
99 <html><head><title>'.t("Plotting").' '.$values["address"].'</title>
100 '.$extracss.'
102 <!-- your head tags here -->
103 <link rel="Stylesheet" href="ip-atlas.css">
104 </head><body bgcolor="'.$THEME->body.'">
107 <a name="map"></a>
109 <table valign="top" cellpadding=0 cellspacing=0 border=0 background="'.$earthimage.'" width="'.$width.'" height="'.$height.'"><tr><td valign="top">'.$display.'</td></tr></table>
112 <br>
115 if(isset($address)) {
116 print "$username $values[desc]";
119 $PHP_SELF = 'plot.php';
121 print '
122 <br><br>
123 <form method="GET" action="'.$PHP_SELF.'#map">
124 <table width="100%"><tr><td nowrap align="left">
125 '.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%">
126 [ <a href="ip-atlas_prefs.php?lastquery='?><?php if(isset($HTTP_GET_VARS["address"])) { echo $HTTP_GET_VARS["address"]; } ?><?php echo '">'.t("preferences").'</a> ]
127 [ <a href="'."$PHP_SELF".'">'.t("locate me").'</a> ]
128 </td></tr></table>
129 </form>
132 include("footer.inc");
134 print "</body></html>";