/**
 * Saves a map location.  Will add or update.
 * @param object $data Information about the location
 */
function map_save_location($data)
{
    global $USER;
    $data->timemodified = time();
    if (!($cm = get_coursemodule_from_id('map', $data->id))) {
        error("Course Module ID was incorrect");
    }
    if (!($map = map_get_map($cm->instance))) {
        error("Course module is incorrect2");
    }
    $data->mapid = $map->id;
    if (!isset($data->userid)) {
        $data->userid = $USER->id;
    }
    if (isset($data->nolocation)) {
        $data->latitude = 0;
        $data->longitude = 0;
        $data->city = "";
        $data->state = "";
        $data->country = "";
        $data->showcode = 0;
    } else {
        if ($data->action != "resetlocation") {
            //longitude and latitude was given don't need to call to get location
            if (empty($data->latitude) && empty($data->longitude)) {
                if (!map_get_latlong($data, $map)) {
                    return "Error finding location";
                }
            }
            $data->showcode = 1;
        }
    }
    switch ($data->action) {
        case "insertlocation":
            $locationSuccess = insert_record("map_locations", $data);
            break;
        case "updatelocation":
            $data->id = $data->locationid;
            $locationSuccess = update_record("map_locations", $data);
            break;
        case "resetlocation":
            $locationSuccess = delete_records("map_locations", "id", $data->locationid);
    }
    if ($locationSuccess != false) {
        return true;
    } else {
        return "Could not update location";
    }
}
 * map_security_check.php
 * 
 * @package map
 * @author Ted Bowman <*****@*****.**>
 * @version 0.1
 * Makes sure the user is logged and should be able see the map
 *
*/
$id = required_param('id', PARAM_INT);
// Course Module ID
$action = optional_param('action', '', PARAM_ALPHA);
if (!($cm = get_coursemodule_from_id('map', $id))) {
    error("Course Module ID was incorrect");
}
if (!($course = get_record("course", "id", $cm->course))) {
    error("Course is misconfigured");
}
require_course_login($course, false, $cm);
if (!($map = map_get_map($cm->instance))) {
    error("Course module is incorrect");
}
$strmap = get_string('modulename', 'map');
$strmaps = get_string('modulenameplural', 'map');
if (!($context = get_context_instance(CONTEXT_MODULE, $cm->id))) {
    print_error('badcontext');
}
//check to make sure the module is set correcty
if (!map_config_ok()) {
    error(get_string("badconfig", "map"));
    exit;
}