Quadratic algebras and dynamics in curved spaces. I. Oscillator