Theory of Inelastic Scattering and Absorption of X-rays