set_charset("utf8"); if ($pt_mysqli->connect_errno) { echo "Can't connect to $pt_dbname database: (" . $pt_mysqli->errno . ") " . $pt_mysqli->error . "\n"; exit(1); } if (!empty($uloggerPath) && $uloggerPath[0] == ".") { $uloggerPath = $path . "/" . $uloggerPath; } $uloggerConfig = $uloggerPath . "/config.php"; if (!is_readable($uloggerConfig)) { echo "Can't find μlogger config fiel: $uloggerConfige\n"; exit(1); } include ($uloggerConfig); $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname); $mysqli->set_charset("utf8"); if ($mysqli->connect_errno) { echo "Can't connect to $dbname database : (" . $mysqli->errno . ") " . $mysqli->error . "\n"; exit(1); } // import data if (!$users_result = $pt_mysqli->query("SELECT * FROM users ORDER BY ID")) { echo "Query failed\n"; exit(1); } if (!($user_insert = $mysqli->prepare("INSERT INTO users (login, password) VALUES (?, ?)"))) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error . "\n"; exit(1); } $pt_user = null; $pt_pass = null; if (!$user_insert->bind_param("ss", $pt_user, $pt_pass)) { echo "Binding parameters failed: (" . $user_insert->errno . ") " . $user_insert->error . "\n"; exit(1); } while ($user = $users_result->fetch_assoc()) { $pt_user = $user['username']; $pt_pass = $user['password']; $pt_id = $user['ID']; if (!$user_insert->execute()) { echo "Execute failed: (" . $user_insert->errno . ") " . $user_insert->error . "\n"; exit(1); } $user_id = $user_insert->insert_id; process_user_tracks($user_id); } function process_user_tracks($user_id) { global $pt_mysqli, $mysqli; $sql = "SELECT * FROM trips WHERE FK_Users_ID = ? ORDER BY ID"; if (!($tracks_select = $pt_mysqli->prepare($sql))) { echo "Prepare failed: (" . $pt_mysqli->errno . ") " . $pt_mysqli->error . "\n"; exit(1); } if (!$tracks_select->bind_param('i', $user_id)) { echo "Binding parameters failed: (" . $tracks_select->errno . ") " . $tracks_select->error . "\n"; exit(1); } if (!$tracks_select->execute()) { echo "Execute failed: (" . $tracks_select->errno . ") " . $tracks_select->error . "\n"; exit(1); } if (!($track_insert = $mysqli->prepare("INSERT INTO tracks (user_id, name, comment) VALUES (?, ?, ?)"))) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error . "\n"; exit(1); } $pt_name = null; $pt_comment = null; if (!$track_insert->bind_param("iss", $user_id, $pt_name, $pt_comment)) { echo "Binding parameters failed: (" . $track_insert->errno . ") " . $track_insert->error . "\n"; exit(1); } $result = $tracks_select->get_result(); while ($track = $result->fetch_assoc()) { $pt_name = $track['Name']; $pt_comment = $track['Comments']; if (!$track_insert->execute()) { echo "Execute failed: (" . $track_insert->errno . ") " . $track_insert->error . "\n"; exit(1); } $track_id = $track_insert->insert_id; process_track($user_id, $track_id); } } function process_track($user_id, $track_id) { global $pt_mysqli, $mysqli; $sql = "SELECT * FROM positions WHERE FK_Users_ID = ? AND FK_Trips_ID = ? ORDER BY DateOccurred"; if (!($pos_select = $pt_mysqli->prepare($sql))) { echo "Prepare failed: (" . $pt_mysqli->errno . ") " . $pt_mysqli->error . "\n"; exit(1); } if (!$pos_select->bind_param('ii', $user_id, $track_id)) { echo "Binding parameters failed: (" . $pos_select->errno . ") " . $pos_select->error . "\n"; exit(1); } if (!$pos_select->execute()) { echo "Execute failed: (" . $pos_select->errno . ") " . $pos_select->error . "\n"; exit(1); } if (!($pos_insert = $mysqli->prepare("INSERT INTO positions (time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error . "\n"; exit(1); } $provider = $comment = $time = $imageid = null; $lat = $lon = 0; $altitude = $speed = $bearing = $accuracy = null; if (!$pos_insert->bind_param('siiddddddssi', $time, $user_id, $track_id, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageid)) { echo "Binding parameters failed: (" . $pos_insert->errno . ") " . $pos_insert->error . "\n"; exit(1); } $result = $pos_select->get_result(); while ($track = $result->fetch_assoc()) { $provider = null; $comment = $track['Comments']; $time = $track['DateOccurred']; $lat = $track['Latitude']; $lon = $track['Longitude']; $altitude = $track['Altitude']; $speed = $track['Speed']; $bearing = $track['Angle']; if (!$pos_insert->execute()) { echo "Execute failed: (" . $pos_insert->errno . ") " . $pos_insert->error . "\n"; exit(1); } } } echo "Import finished successfully\n"; exit(0); ?>