public static function mod_pref($name, $value, $userid = null, $type = 'string')
    {
        $db = self::db();

        if ($userid) {
            $query = '`user_id` = ' . intval($userid);
        }
        else {
            $query = '1=1';
        }

        $type = strtolower($type);

        if ($type == 'bool' || $type == 'boolean') {
            $value = rcube_utils::get_boolean($value);
        }
        else if ($type == 'int' || $type == 'integer') {
            $value = (int) $value;
        }

        // iterate over all users
        $sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE $query");

        while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
            echo "Updating prefs for user " . $sql_arr['user_id'] . "...";

            $user  = new rcube_user($sql_arr['user_id'], $sql_arr);
            $prefs = $old_prefs = $user->get_prefs();

            $prefs[$name] = $value;

            if ($prefs != $old_prefs) {
                $user->save_prefs($prefs, true);
                echo "saved.\n";
            }
            else {
                echo "nothing changed.\n";
            }
        }
    }