}
    } elseif ($location_type_id == FED) {
        foreach ($location_array as $galaxy_id => $checked) {
            // ignore this sector if it already got a hq
            if ($id[GOVERNMENT][$galaxy_id] > 1) {
                continue;
            }
            // create fed
            if ($checked == 'on') {
                create_fed($var['game_id'], $galaxy_id);
            }
        }
    } elseif ($location_type_id == UNDERGROUND) {
        foreach ($location_array as $galaxy_id => $checked) {
            if ($checked == 'on') {
                create_location($var['game_id'], $galaxy_id, UNDERGROUND);
            }
        }
    } else {
        foreach ($location_array as $galaxy_id => $amount) {
            for ($i = 0; $i < $amount; $i++) {
                create_location($var['game_id'], $galaxy_id, $location_type_id);
            }
        }
    }
}
$container = array();
$container['url'] = 'skeleton.php';
$container['body'] = 'universe_create_ports.php';
$container['game_id'] = $var['game_id'];
forward($container);
Пример #2
0
/**
 * Creates a new ride and returns the result.
 */
function create_ride($data)
{
    $link = db_connect();
    // Add rows to the location table as needed.
    $loc_origin_name = create_location($link, $data['loc_origin_name'], $data['loc_origin_address_components'], $data['loc_origin_lat'], $data['loc_origin_lng']);
    $loc_dest_name = create_location($link, $data['loc_dest_name'], $data['loc_dest_address_components'], $data['loc_dest_lat'], $data['loc_dest_lng']);
    // Default pickup location to origin location if not specified
    if (isset($data['loc_pickup_name']) && $data['loc_pickup_name'] !== $loc_origin_name) {
        $loc_pickup_name = create_location($link, $data['loc_pickup_name'], $data['loc_pickup_address_components'], $data['loc_pickup_lat'], $data['loc_pickup_lng']);
    } else {
        $loc_pickup_name = $loc_origin_name;
    }
    // Default dropoff location to destination location if not specified
    if (isset($data['loc_dropoff_name']) && $data['loc_dropoff_name'] !== $loc_dest_name) {
        $loc_dropoff_name = create_location($link, $data['loc_dropoff_name'], $data['loc_dropoff_address_components'], $data['loc_dropoff_lat'], $data['loc_dropoff_lng']);
    } else {
        $loc_dropoff_name = $loc_dest_name;
    }
    // Escape string variables (location names are already escaped by create_location)
    $region = mysqli_real_escape_string($link, $data['region']);
    $ride_type = mysqli_real_escape_string($link, $data['ride_type']);
    $costs = mysqli_real_escape_string($link, $data['costs']);
    $note = mysqli_real_escape_string($link, $data['note']);
    $departure = mysqli_real_escape_string($link, $data['departure']);
    $user_id = $data['user_id'];
    $seats_available = $data['seats_available'];
    if (isset($data['round_trip'])) {
        $round_trip = $data['round_trip'];
    } else {
        $round_trip = 'NULL';
    }
    $query = "INSERT INTO ride (id, user_id, region, ride_type, round_trip, loc_origin_name, loc_dest_name, " . "loc_pickup_name, loc_dropoff_name, costs, note, seats_available, departure, created_at, updated_at) " . "VALUES (NULL, {$user_id}, '{$region}', '{$ride_type}', {$round_trip}, '{$loc_origin_name}', '{$loc_dest_name}', " . "'{$loc_pickup_name}', '{$loc_dropoff_name}', '{$costs}', '{$note}', {$seats_available}, '{$departure}', NULL, NULL);";
    mysqli_query($link, $query);
    $ride_id = mysqli_insert_id($link);
    mysqli_close($link);
    return get_ride($ride_id);
}