$return['error'] = FALSE; $return['msg'] = _("Default map changed successfully"); return $return; } $login = Session::get_session_user(); $db = new ossim_db(); $conn = $db->connect(); $action = POST("action"); $data = POST("data"); ossim_valid($action, OSS_DIGIT, 'illegal:' . _('Action')); if (ossim_error()) { die(ossim_error()); } if ($action != '' && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { switch ($action) { case 1: $response = delete_map($conn, $data); break; case 2: $response = set_default_map($conn, $data); break; case 3: $response = change_map_title($conn, $data); break; default: $response['error'] = TRUE; $response['msg'] = _('Wrong Option Chosen'); } echo json_encode($response); $db->close(); }
// set default lang if current is not valid $lng = SiteConf::getSiteLanguage($lng); include 'languages/' . $lng . '.php'; // set default page if current is not valid $page = SiteConf::getSitePage($page); // initialize basic map variables $vars = array(); $vars['default_lan'] = SiteConf::$DEFAULT_CENTER_LAN; $vars['default_lng'] = SiteConf::$DEFAULT_CENTER_LNG; $vars['default_zoom'] = SiteConf::$DEFAULT_ZOOM; $vars['default_typeid'] = SiteConf::$DEFAULT_TYPEID; $vars['error_msg'] = ''; switch ($page) { case "maps": if (isset($_POST['map_id'])) { $vars_tmp = delete_map(intval($_POST['map_id'])); } $vars['html_title'] = $lang_msg['MAPS_TITLE']; $vars['page_title'] = $lang_msg['MAPS_PAGE_TITLE']; $vars['sitemaps'] = SiteMaps::getMaps(); break; case "map_view": if (isset($_GET['map_id'])) { $map_id = intval($_GET['map_id']); } if ($map_id > 0) { $vars_tmp = load_map(intval($map_id)); } else { $vars['error_msg'] .= 'Not valid map id'; } $vars['html_title'] = $lang_msg['MAP_VIEW_TITLE'];
if (is_array($json_arr)) { update_map($student_id, $map_id, $json_string); $map = get_user_maps($student_id, $map_id); $map = xml_maps_to_json($map); $map = json_decode($map, true); deliver_response(200, "The map has been updated", $map); } else { deliver_response(400, "The request cannot be fulfilled due to bad syntax"); } break; case "DELETE": if (!does_map_exist_by_id($student_id, $map_id)) { deliver_response(200, "Map with id={$map_id} does not exist"); break; } delete_map($student_id, $map_id); deliver_response(200, "The map has been deleted"); break; default: break; } } else { deliver_response(204); } } function deliver_response($status = null, $status_message = null, $data_value = null, $data_key = "map") { header("HTTP/1.1 {$status}"); header('Access-Control-Allow-Origin: *'); $response['status_message'] = $status_message; if ($data_value != null) {
function create_game($bdd2, $name, $id_type, $id_creator) { $name = protect_sql($name, "none"); $id_type = protect_sql($id_type, "intval"); $id_creator = protect_sql($id_creator, "intval"); $sql = "INSERT INTO `games` VALUES ('', '" . $name . "', NOW(), " . $id_type . ", 'En cours')"; if ($bdd2->query($sql)) { $last_id = $bdd2->last_id(); if ($type = select_tog($bdd2, $id_type)) { $sql2 = "INSERT INTO `play_in` VALUES ('" . $id_creator . "', '" . $last_id . "', '" . $type[0]['nbr_points'] . "', '1')"; if ($bdd2->query($sql2)) { if (create_map($bdd2, $last_id)) { if (create_event_table($bdd2, $last_id)) { return $last_id; } else { delete_map($bdd2, $last_id); return 0; } } else { return 0; } } else { return 0; } } else { return 0; } } else { return 0; } }
function update_map($student_id, $map_id, $json_string) { $json_arr = json_decode($json_string, true); $maps = get_user_maps($student_id); $maps = xml_maps_to_json($maps); $maps = json_decode($maps, true); foreach ($maps as &$map) { if ($map['id'] == $map_id) { foreach ($json_arr as $key => $value) { if (!empty($json_arr[$key])) { $map[$key] = $json_arr[$key]; } } delete_map($student_id, $map_id); $map = json_encode($map); add_map($student_id, $map); break; } } }
} if (isset($_POST['edit_map']) && $_POST['edit_map'] != "") { $map = $_POST['edit_map']; $map_name = $_POST['mapname' . $map]; $map_image = $_POST['mapimage' . $map]; $map_description = $_POST['mapdescription' . $map]; if ($map_image != "" && $map_name != "") { update_map($map, $map_image, $map_name, $map_description); } //dbg: echo "Update Map: $map, $map_image, $map_name, $map_description"; header("Location: admin_config.php?eb_games&gameid={$game_id}"); exit; } if (isset($_POST['del_map']) && $_POST['del_map'] != "") { $map = $_POST['del_map']; delete_map($map); header("Location: admin_config.php?eb_games&gameid={$game_id}"); exit; } exit; /*************************************************************************************** Functions ***************************************************************************************/ /** * deleteGame - Delete a game from the database */ function deleteGame($game_id) { global $sql; //fm: Should check if the game is used in a team or event? // Do not delete game 1 (unknown game)