Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/iplookup/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00029 require('../config.php');
00030 require_once('lib.php');
00031 
00032 require_login();
00033 
00034 $ip   = optional_param('ip', getremoteaddr(), PARAM_HOST);
00035 $user = optional_param('user', 0, PARAM_INT);
00036 
00037 if (isset($CFG->iplookup)) {
00038     //clean up of old settings
00039     set_config('iplookup', NULL);
00040 }
00041 
00042 $PAGE->set_url('/iplookup/index.php', array('id'=>$ip, 'user'=>$user));
00043 $PAGE->set_pagelayout('popup');
00044 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
00045 
00046 $info = array($ip);
00047 $note = array();
00048 
00049 if (!preg_match('/(^\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $ip, $match)) {
00050     print_error('invalidipformat', 'error');
00051 }
00052 
00053 if ($match[1] > 255 or $match[2] > 255 or $match[3] > 255 or $match[4] > 255) {
00054     print_error('invalidipformat', 'error');
00055 }
00056 
00057 if ($match[1] == '127' or $match[1] == '10' or ($match[1] == '172' and $match[2] >= '16' and $match[2] <= '31') or ($match[1] == '192' and $match[2] == '168')) {
00058     print_error('iplookupprivate', 'error');
00059 }
00060 
00061 $info = iplookup_find_location($ip);
00062 
00063 if ($info['error']) {
00064     // can not display
00065     notice($info['error']);
00066 }
00067 
00068 if ($user) {
00069     if ($user = $DB->get_record('user', array('id'=>$user, 'deleted'=>0))) {
00070         // note: better not show full names to everybody
00071         if (has_capability('moodle/user:viewdetails', get_context_instance(CONTEXT_USER, $user->id))) {
00072             array_unshift($info['title'], fullname($user));
00073         }
00074     }
00075 }
00076 array_unshift($info['title'], $ip);
00077 
00078 $title = implode(' - ', $info['title']);
00079 $PAGE->set_title(get_string('iplookup', 'admin').': '.$title);
00080 $PAGE->set_heading($title);
00081 echo $OUTPUT->header();
00082 
00083 if (empty($CFG->googlemapkey)) {
00084     $imgwidth  = 620;
00085     $imgheight = 310;
00086     $dotwidth  = 18;
00087     $dotheight = 30;
00088 
00089     $dx = round((($info['longitude'] + 180) * ($imgwidth / 360)) - $imgwidth - $dotwidth/2);
00090     $dy = round((($info['latitude'] + 90) * ($imgheight / 180)));
00091 
00092     echo '<div id="map" style="width:'.($imgwidth+$dotwidth).'px; height:'.$imgheight.'px;">';
00093     echo '<img src="earth.jpeg" style="width:'.$imgwidth.'px; height:'.$imgheight.'px" alt="" />';
00094     echo '<img src="marker.gif" style="width:'.$dotwidth.'px; height:'.$dotheight.'px; margin-left:'.$dx.'px; margin-bottom:'.$dy.'px;" alt="" />';
00095     echo '</div>';
00096     echo '<div id="note">'.$info['note'].'</div>';
00097 
00098 } else {
00099     $PAGE->requires->js(new moodle_url("http://maps.google.com/maps?file=api&v=2&key=$CFG->googlemapkey"));
00100     $module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js');
00101     $PAGE->requires->js_init_call('M.core_iplookup.init', array($info['latitude'], $info['longitude']), true, $module);
00102 
00103     echo '<div id="map" style="width: 650px; height: 360px"></div>';
00104     echo '<div id="note">'.$info['note'].'</div>';
00105 }
00106 
00107 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations