Пример #1
0
/**
 * Can store more than one postions at once.
 *
 * @param type $user
 * @param type $group
 * @param type $positions multiline CSV, each line containing one postion
 *        Example
 *          lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2012-03-03T15:48:47.484'
 *          lat=44.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2012-03-03T15:48:47.484'
 * @param type $storeTrack store the track to
 * @return boolean true for success
 */
function writePostions($user, $group, $positions, $storeTrack)
{
    $storeTrack = checkConfigIsWritingTrack($user, $storeTrack);
    // Write the last request (does not write the password)
    if (!writeLastRequest($user)) {
        logMessage("Failed to write the request file for user {$user}.");
        return false;
    }
    if (isNullOrEmptyString($positions)) {
        logMessage("Missing parameter positions.");
        return false;
    }
    if (!isNullOrEmptyString($group)) {
        if (!writeGroupFile($user, $group)) {
            return false;
        }
    }
    // Try to guess the timestamp format
    $acceptedValues = '/(.*time=)([^;]+)(.*)/i';
    $dateString = '';
    $lines = explode(PHP_EOL, $positions);
    $count = count($lines);
    $lastLine = $lines[$count - 1];
    $lineBuffer = '';
    for ($i = 0; $i < $count; $i++) {
        $lastLine = trim($lines[$i]);
        if (preg_match($acceptedValues, $lastLine, $matches)) {
            $timeStringReceived = trim($matches[2]);
            $timeStringGuessed = getTimeFormatGuessed($timeStringReceived);
            $lastLine = $matches[1] . $timeStringGuessed . $matches[3];
            // Check wether the day (local user time) changed) > to split the track files later on
            $newDateString = getDateForTimezoneOffset($user, $timeStringReceived, true);
            if ($newDateString == '') {
                // take today
                $newDateString = getDateForTimezoneOffset($user, "", true);
            }
            if ($dateString == '') {
                $dateString = $newDateString;
            } else {
                if ($newDateString != $dateString) {
                    if (!isNullOrEmptyString($storeTrack)) {
                        // the date of the positions time changed > write the track
                        writePositionsCSVfile($user, $dateString, $lineBuffer);
                    }
                    // start a new track (line buffer)
                    $lineBuffer = '';
                    $dateString = $newDateString;
                }
            }
        }
        if ($lineBuffer != '') {
            $lineBuffer .= PHP_EOL;
        }
        $lineBuffer .= $lastLine;
    }
    $acceptedValues = '/true/i';
    if (preg_match($acceptedValues, $storeTrack)) {
        // Write CSV
        writePositionsCSVfile($user, $dateString, $lineBuffer);
    }
    // Write PGX
    //    $gpxFile = USER_DIR . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR . $dateString . ".gpx";
    //    if (!writeGPXfile(true, $gpxFile, $positions)) {
    //        return false;
    //    }
    //
    // write last position to position.csv
    return writePositionFile($user, $lastLine);
}
Пример #2
0
function test_writeGroupFile()
{
    appendTestMessage(NEW_LINE_LOG . " >> Tests writing of group file..." . NEW_LINE_LOG);
    appendTestMessage("Prepare: Create new user");
    $ret = checkUser("cUser", "cPassword");
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("New group for user");
    $ret = writeGroupFile("cUser", "cGroup");
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Same group for user");
    $ret = writeGroupFile("cUser", "cGroup");
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Changed group for user");
    $ret = writeGroupFile("cUser", "changedGroup");
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Cleanup this test method: Remove existing user");
    $ret = removeUser("cUser", "cPassword");
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    return true;
}
Пример #3
0
    $fileName = getParam('filename');
    $users = getUsersForDataFileName($user, $fileName);
    if (isNullOrEmptyString($getUsersForFileName)) {
        setServerError("Failed to get users for filename {$fileName} for user {$user}.");
        return;
    }
    setServerResponse($users);
    return;
}
// Get all users (of a group) that have a given data file(name)
$getLastPostionsAndTracks = getParam('getLastPostionsAndTracksIndividually');
if (!isNullOrEmptyString($getLastPostionsAndTracks)) {
    // 1. Write the group if given
    $group = getParam('group');
    //	if (!isNullOrEmptyString($group)) {
    if (!writeGroupFile($user, $group)) {
        setServerError("Failed to change group for user {$user}.");
        return;
    }
    //	}
    // 2. Get positionm and tracks
    $postions = getLastPostionsAndTracksIndividually($getLastPostionsAndTracks, getParam('track'), $user);
    if (isNullOrEmptyString($postions)) {
        // 		setServerError("Failed to get last postions and tracks for $getLastPostionsAndTracks");
        // 		return;
        // It might happen that a new user has nothing on the server
        $postions = '';
    }
    setServerResponse($postions);
    return;
}