Theory of adsorption of macromolecules. 2. Phase transitions in adsorption: general approach