if (application_userisvalid()) {
    $usr = application_getvaliduser();
    if ($usr != null) {
        $df = new DirectoryFactory();
        $ff = new FileFactory();
        global $gl_filedir;
        //msg_updatefilelist
        //TODO delete file from db if the file does not exist in directory
        if ($action == msg_updatefilelist) {
            //$ff->updateFiles($usr->getUid());
            $ff->setInvalid($usr->getUid());
            $lst1 = $df->listFiles_Dir($usr->getUid(), $gl_filedir, array("gpx", "xml"));
            if ($lst1 != null) {
                for ($i = 0; $i < count($lst1); $i++) {
                    $fn = $lst1[$i];
                    if (!$ff->fileExists($usr->getUid(), basename($fn))) {
                        $path = dirname($fn) . "/";
                        $filename = basename($fn);
                        $ff->createFile($usr->getUid(), $path, $filename, NULL);
                    } else {
                        $ff->setValid($usr->getUid(), basename($fn));
                    }
                }
            }
            $ff->deleteInvalid($usr->getUid());
        }
        //$files = array();
        if ($action == msg_getfiles) {
            $lst1 = $ff->getFiles($usr->getUid(), 0);
            if ($lst1 != null) {
                $fc = new FileContainer();