public static function get_default_backup_filename($format, $type, $id, $users, $anonymised, $useidonly = false) {
        global $DB;

        // Calculate backup word
        $backupword = str_replace(' ', '_', core_text::strtolower(get_string('backupfilename')));
        $backupword = trim(clean_filename($backupword), '_');

        // Not $useidonly, lets fetch the name
        $shortname = '';
        if (!$useidonly) {
            // Calculate proper name element (based on type)
            switch ($type) {
                case backup::TYPE_1COURSE:
                    $shortname = $DB->get_field('course', 'shortname', array('id' => $id));
                    $context = context_course::instance($id);
                    $shortname = format_string($shortname, true, array('context' => $context));
                    break;
                case backup::TYPE_1SECTION:
                    if (!$shortname = $DB->get_field('course_sections', 'name', array('id' => $id))) {
                        $shortname = $DB->get_field('course_sections', 'section', array('id' => $id));
                    }
                    break;
                case backup::TYPE_1ACTIVITY:
                    $cm = get_coursemodule_from_id(null, $id);
                    $shortname = $cm->modname . $id;
                    break;
            }
            $shortname = str_replace(' ', '_', $shortname);
            $shortname = core_text::strtolower(trim(clean_filename($shortname), '_'));
        }

        // The name will always contain the ID, but we append the course short name if requested.
        $name = $id;
        if (!$useidonly && $shortname != '') {
            $name .= '-' . $shortname;
        }

        // Calculate date
        $backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig'));
        $date = userdate(time(), $backupdateformat, 99, false);
        $date = core_text::strtolower(trim(clean_filename($date), '_'));

        // Calculate info
        $info = '';
        if (!$users) {
            $info = '-nu';
        } else if ($anonymised) {
            $info = '-an';
        }

        return $backupword . '-' . $format . '-' . $type . '-' .
               $name . '-' . $date . $info . '.mbz';
    }