Thermodynamics of quenched random spin systems, and application to the problem of phase transitions in magnetic (spin) glasses