Fixing PHP warning.
Fixing document creation inside a group.
Adding group id to the function check_visibility_tree(). see BT#7870
Minor - format code.