How to get an array of group names to which the user belongs

Hello everybody.
I need some help.

In several tasks it’s necessary to check to which group user belongs. In one case there is js script, in the other there is php file of template of some application.
For example,
apps/files/templates/list.php
It’s necessary to check whether the user belongs to a certain group and then hide or show the corresponding messages or buttons.
apps/files/js/fileactions.js
It’s necessary to check whether the user belongs to a certain group and then hide or show the corresponding messages or buttons.

I’m asking for some hints!