A man is in a stable condition in hospital after being attacked by a shark on the Great Barrier Reef.