A disordered mean field model for multimode laser in open and irregular cavities is proposed and discussed within the replica analysis. The model includes the dynamics of the mode intensity and accounts also for the possible presence of a linear coupling between the modes, due, e.g., to the leakages from an open cavity. The complete phase diagram, in terms of disorder strength, source pumping and non-linearity, consists of four different optical regimes: incoherent fluorescence, standard mode locking, random lasing and the novel spontaneous phase locking. A replica symmetry breaking phase transition is predicted at the random lasing threshold. For a high enough strength of non-linearity, a whole region with nonvanishing complexity anticipates the transition, and the light modes in the disordered medium display typical discontinuous glassy behavior, i. e., the photonic glass has a multitude of metastable states that corresponds to different mode-locking processes in random lasers. The lasing regime is still present for very open cavities, though the transition becomes continuous at the lasing threshold. PACS numbers: 42.55.Zz, 42.60.Fc, 75.50.Lk Considering salient multimode laser theory properties, both in ordered and disordered amplifying media, in this paper we construct a general statistical mechanical model for interacting waves. We study the model, in particular, in the framework of nonlinear optics, focusing on applications to the random lasing phenomenon. The term "random lasing" embraces a number of phenomena related to light amplification by stimulated emission in systems characterized by a spatial distribution of the electromagnetic field which is much more irregular and complicated than for well-defined cavity modes of standard lasing structures. In any system, to produce a laser two ingredients are essential: optical amplification and feedback. Amplified spontaneous emission can occur even without an optical cavity, and then the spectrum is determined only by the gain curve of the active material. Historically, already in the late 60's Letokhov 1 theoretically discussed how light diffusion with gain can lead to the divergence of the intensity above a critical volume, and, if the gain depends on the wavelength, the emission spectrum narrows down close to the wavelength of maximum gain. These features were later observed in experiments. 2,3 When the multiple-scattering feedback dominates, instead, lasing occurs: a phenomenon known as Random Laser (RL). 4 The presence of feedback is associated with the existence of well-defined long-lived cavity modes and characterized by a definite spatial pattern of the electromagnetic field. A RL is, in other words, "mirror-less" but not "modeless" 5 .Among the most singular aspects of RLs is that, for systems composed by a large number of modes, a complex behavior in its temporal and spectral response is observed: if there is no specific frequency that dominates the others, the spectral resonances can change frequency from one excitation pulse to another, with emi...