
    Ex parte Houston County Sheriff Lamar GLOVER; and Michael W. Haley, Commissioner of the Alabama Department of Corrections. (Re Order of the Houston Circuit Court dated December 4, 2000).
    1000500.
    Supreme Court of Alabama.
    May 4, 2001.
    Bill Pryor, atty. gen., and Margaret L. Fleming and Charles Brinsfield Campbell, asst, attys. gen.; Edward A. Hosp, Legal Adviser to Governor Don Siegelman; and Albert S. Butler, asst, general counsel, Alabama Department of Corrections, for Sheriff Lamar Glover, Commissioner Michael W. Haley, and Governor Don Siegel-man.
    James W. Webb, Kendrick E. Webb, and Bart Harmon of Webb & Eley, P.C., Montgomery, for Sheriff Lamar Glover.
    Gary C. Sherrer and W. Davis Malone III of Farmer, Farmer, Malone & Sherrer, P.A., Dothan, for Judges Larry K. Anderson, Denny L. Holloway, S. Edward Jackson, and Charles L. Little.
    Frank C. Ellis, Jr., of Wallace, Ellis, Fowler & Head, Columbiana, for amici curiae Sheriff James Jones and Shelby County.
    
      Edwin A. Strickland and Charles S. Wagner, Jr., for amicus curiae Jefferson County Commission.
    Albert L. Jordan and Algert S. Agrícola, Jr., of Wallace, Jordan, Ratliff & Brandt, L.L.C., Birmingham, for amicus curiae Jefferson County Sheriff.
    J. Robert Faulk of McDowell, Faulk & McDowell, L.L.C., Prattville, for amici curiae James W. Johnson, Sheriff, and Au-tauga County.
    Robert M. Spence of Crownover, Stand-ridge & Spence, Tuscaloosa, for amici curiae Tuscaloosa County Commission and Sheriff Edmund M. “Ted” Sexton, Sr.
   SEE, Justice.

Michael W. Haley, commissioner of the Alabama Department of Corrections, acting by and through Attorney General Bill Pryor, petitions for a writ of mandamus directing the judges of the Houston Circuit Court to vacate their order of December 4, 2000, which directs the sheriff of Houston County to transfer certain inmates from the Houston County jail to the Department of Corrections (“DOC”) and, if the DOC refuses to accept the inmates, to secure the inmates to the DOC’s property. Governor Don Siegelman petitions this Court for permission to intervene in this mandamus proceeding, to join Commissioner Haley as a petitioner; we grant Governor Siegelman’s petition. See Ex parte Weaver, 570 So.2d 675, 683 (Ala.1990) (“[T]he Governor, as ‘chief magistrate’ of the State, may intervene in any ... litigation” in which the attorney general is representing the State.). For the reasons discussed below, we deny the petition for the writ of mandamus.

Facts and Procedural History

In the early 1990s, a class of counties and county sheriffs sued the commissioner of the DOC, arguing that he had a pattern of refusing, through his subordinates, to accept from county sheriffs inmates sentenced to serve time in the state penitentiary (“state inmates”) and that that refusal was a violation of § 14-3-30, Ala.Code 1975. The plaintiffs sought injunctive relief requiring the commissioner and his staff to accept state inmates in accordance with the plaintiffs’ interpretation of § 14-3-30. That Code section provides that when a defendant is sentenced to the penitentiary, the clerk of the sentencing court must notify the DOC, and, “[tjhereupon, the [DOC] shall direct where the inmate shall be taken for confinement or hard labor.” After a hearing, the circuit court issued an injunction requiring the DOC to accept state inmates from the plaintiff counties within 30 days of the DOC’s receipt of the notification required by § 14-3-30.

Several years later, apparently dissatisfied with the DOC’s efforts to comply with the trial court’s injunction, the plaintiffs moved the court for an order holding the commissioner in contempt of court. The parties, however, reached an agreement that the court approved, and the plaintiffs withdrew their contempt motion. Essentially, the DOC agreed to comply with the terms of the court’s earlier injunction.

On December 4, 2000, the judges of the Twentieth Judicial Circuit, in response to what they perceived to be “critical” overcrowding of the Houston County jail, issued the order that the commissioner challenges here. That order reads:

“ORDER
“After thorough review of the criminal justice system in Houston County, Alabama, by the Circuit Judges in Houston County, Alabama, it is apparent that there exists within the Houston County Jail a backlog of state inmates who have been sentenced to the custody of the Department of Corrections, and that the Department has refused to accept these inmates in compliance with state law. This has impeded the criminal justice system in Houston County, Alabama, slowing down and in certain circumstances obstructing the appropriate imposition of punishment of those convicted of a crime or held in contempt of court.
“THEREFORE, pursuant to Alabama Code § ■ 12-17-24, the Sheriff of Houston County, Alabama, is hereby ordered to effectuate the transfer to the Department of Corrections of any and all state inmates who have been housed in the Houston County Jail for thirty (30) or more days after the Clerk of the Court transmitted to the Department of Corrections a copy of the judgihent entry and sentence. The Sheriff is ordered to transport these state inmates to the Department’s receiving center at Kilby (for male inmates) or Tutwiler (for female inmates) and effectuate the transfer of the state inmates to the custody of the Department. In the event the Department refuses to accept any state inmate in compliance with state law, the Sheriff is ordered to secure any such inmate or inmates so refused to the property of the Department’s receiving center. This Order shall be continuing in nature.
“Done this 4th day of December, 2000.
“/s/Larry K. Anderson
“Presiding Circuit Judge
“/s/Denny L. Holloway
“Circuit Judge
“/s/Edward Jackson
“Circuit Judge
“/s/Lawson Little
“Circuit Judge”

This Court stayed implementation of the circuit judges’ order and ordered answers and briefs from the parties.

Discussion

The standard this Court applies in determining whether a petition for the writ of mandamus will issue is well settled. Mandamus is an extraordinary remedy; one seeking it must show: “(1) a clear legal right in the petitioner to the order sought; (2) an imperative duty upon the respondent to perform, accompanied by a refusal to do so; (3) the lack of another adequate remedy; and (4) properly invoked jurisdiction of the court.” Ex parte Alfab, Inc., 586 So.2d 889, 891 (Ala.1991). The petitioner bears the burden of proving each of these elements before the writ will issue. See Ex parte Consolidated Publ’g Co., 601 So.2d 423 (Ala.1992).

The respondent judges argue that the Commissioner is not entitled to the writ of mandamus because, they argue, the Commissioner has another adequate remedy. In Ex parte Galanos, 796 So.2d 390 (Ala.2000), the judges of the Mobile Circuit Court adopted a system for reviewing fee declarations by attorneys appointed to represent indigent defendants. Under that system, a committee composed of five members of the criminal-defense bar of Mobile County reviewed fee declarations and made recommendations to a circuit judge as to the proper fee to award. The judge reviewed the committee’s recommendation, independently reviewed the declaration, and then approved a fee. The responsibility of reviewing those declarations rotated among the judges of the circuit on an annual basis.

An attorney who had represented indigent defendants, and who had submitted 11 attorney-fee declarations, petitioned the Court of Criminal Appeals for a writ of mandamus, arguing that the system for reviewing attorney-fee declarations adopted by the judges of the Mobile Circuit Court violated § 15-12-21, Ala. Code 1975. The Court of Criminal Appeals issued the writ, holding the Code section required the judge who had presided over an indigent defendant’s case to review the fee declaration submitted by the attorney appointed to represent the defendant. The judges of the Mobile Circuit Court petitioned this Court for a writ of mandamus directing the Court of Criminal Appeals to vacate its judgment.

The petitioning judges argued that the attorney, Bush, had an adequate alternative remedy and that the Court of Criminal Appeals had therefore erred in issuing the writ. This Court agreed, holding that Bush could have sought relief through an action for a declaratory judgment. The Ex parte Galanos analysis applies to the case before us here. But cf. In re Ingram, 356 So.2d 618 (Ala.1978) (court conditionally issued writ of mandamus without discussing the possibility of the petitioner’s obtaining alternative relief through a declaratory-judgment proceeding).

Section 6-6-223, Ala.Code 1975, provides: “Any person ... whose rights, status, or other legal relations are affected by a statute ... may have determined any question of construction or validity arising under' the ... statute ... and obtain a declaration of rights, status or other legal relations thereunder.” We have long held that a declaratory-judgment action is the appropriate way to challenge the legality of an official action:

“[T]he declaratory judgment statute will be extended to cases involving public rights or important public matters and to controversies in which the legality of action of public officials or public agencies is challenged. We have said in effect that where official action done or threatened is challenged as unlawful, whether the lack of authority appears in the provisions of a statute or because of its unconstitutionally, the controversy can be determined under the declaratory-judgment statute.... ”

Morgan v. Board of School Comm’rs of Mobile County, 248 Ala. 22, 25, 26 So.2d 108, 110 (1946); see also Gibbs v. Cochran, 281 Ala. 22, 198 So.2d 607 (1967). Thus, the Commissioner may challenge the legality of the December 4, 2000, order through a declaratory-judgment action.

Accordingly, we conclude that the petition for the writ of mandamus is due to be denied. In denying the petition, we are not unmindful of the serious issues presented by this litigation. Should the party who does not prevail in any declaratory-judgment action seek appellate review from the circuit court’s judgment, this Court will be in a far better position to evaluate the merits of the parties’ arguments, having the benefit of a fully developed record, rather than the limited assertions and ex parte affidavits on which we would be forced to rely if the law allowed us to consider the merits of this issue at this stage.

Conclusion

We dissolve the stay we issued on January 3, 2001, and we deny the petition.

MOTION OF GOVERNOR DON SIE-GELMAN TO JOIN PETITION FOR THE WRIT OF MANDAMUS GRANTED; MOTION OF GOVERNOR DON SIEGELMAN AND ATTORNEY GENERAL BILL PRYOR TO STRIKE SHERIFF LAMAR GLOVER’S MOTION TO QUASH THE PETITION FOR THE WRIT OF MANDAMUS DENIED; MOTION OF SHERIFF LAMAR GLOVER TO QUASH THE PETITION FOR THE WRIT OF MANDAMUS DENIED; STAY DISSOLVED; PETITION DENIED.

HOUSTON, BROWN, JOHNSTONE, and STUART, JJ., concur.

MOORE, C.J., and LYONS,

HARWOOD, and WOODALL, JJ., concur in the result. 
      
      . The Attorney General also ostensibly filed the petition on behalf of Houston County Sheriff Lamar Glover. Sheriff Glover strenuously objects to the Attorney General's action, arguing that he did not authorize the Attorney General to file the petition on his behalf, and he moves this Court to quash the petition.
      The Attorney General, citing Ex parte Weaver, 570 So.2d 675 (Ala.1990), argues that he is authorized to control litigation on behalf of a county sheriff, regardless of whether the sheriff consents. Sheriff Glover argues that Weaver is distinguishable, and, in the alternative, urges this Court to overrule Weaver. We need not take up Sheriff Glover's invitation to distinguish or overturn Weaver, because the Attorney General also filed his petition on behalf of Commissioner Haley, and because the December 4, 2000, order affects the Commissioner's interests. Therefore, we deny Sheriff Glover's motion to quash the petition, but we nonetheless consider the petition as having been filed only on behalf of Commissioner Haley.
     
      
      . That litigation originated as two civil actions that the Montgomery Circuit Court consolidated. The consolidated action was styled Barbour County v. Thigpen, CV-92-388 and 92-399. Michael Haley, who currently serves as the commissioner of the DOC, has been automatically substituted as a defendant in place of Morris Thigpen, the former commissioner of the DOC, under the provisions of Rule 25(d), Ala.R.Civ.P.
      The certified class in that action included all counties and county sheriffs that were not then protected by court orders enjoining the DOC from refusing to accept state inmates from the custody of the county sheriff. From the materials currently before this Court, it appears that Houston County and the Houston County sheriff were members of the plaintiff class.
     
      
      . Section 14-3-30(a), Ala.Code 1975, provides, in full:
      "When any convict is sentenced to the penitentiary, the judge of the court in which the sentence is rendered shall order the inmate to be confined in the nearest secure jail. The clerk of the court shall at once notify the Department of Corrections as to the jail where the inmate is confined, forward to the department a copy of the judgment entry and sentence in the case, and inform the department if any special care is necessary to guard the inmate. Thereupon, the department shall direct where the inmate shall be taken for confinement or hard labor.”
     
      
      . The trial court's order provided:
      "ORDER ON PRELIMINARY INJUNCTION
      "This Order is pursuant to the Plaintiffs' Petition for Temporary Restraining Order/Preliminary and Permanent Injunction and Complaint filed in the Circuit Court of Barbour County, Alabama, Civil Action No. 91-048, which is now consolidated with this action. A Temporary Restraining Order was entered on February 21, 1992 and a hearing was held on February 24, 1992 on the Plaintiffs’ request for a preliminary injunction.
      "Upon showing that the Plaintiff class of counties and sheriffs would suffer immediate and irreparable injury should an order not be issued and for good cause shown, it is hereby ORDERED:
      "1. Defendant Morris Thigpen, Commissioner of the Alabama Department of Corrections is hereby restrained from refusing to accept state inmates incarcerated in county jails in the State of Alabama in violation of Alabama Code § 14-3-30 (1982 Repl.Vol.).
      "2. From and after the date of this Order, state inmates shall be accepted by Morris Thigpen, as Commissioner of the Alabama Department of Corrections, from the county jails within the class of counties within thirty (30) days of receipt of proper transcripts, or facsimile thereof, from said counties.
      "3. With respect to the current backlog of state inmates housed in the jails included in this class of counties, Defendants shall remove such state inmates referred to in paragraph 2 as follows:
      "(a) All such state inmates from each county jail whose jail population currently exceeds rated capacity such that that jail is within its capacity;
      "(b) Where the jail population in any county jail affected by this Order exceeds their rated capacity, the Defendants shall remove within two (2) days after notification of this event all such state inmates contributing to this excess capacity;
      "(c) All other state ready inmates shall be removed within ninety (90) days from the date of this Order.
      "Done this 25[th] day of February, 1992. "/s/ Randall Thomas "Circuit Judge”
     
      
      .The trial court's order relating to the settlement read:
      "ORDER
      "This matter comes before the Court on the Joint Motion to Approve Settlement Agreement and Continue Hearing. After a review of this matter, it is apparent that the Settlement Agreement entered into by the Plaintiff Class of Counties and Sheriffs in the State, of Alabama and the Commissioner of the Alabama Department of Corrections, and approved by the Attorney General of the State of Alabama, is in the best interest of all parties involved and is a reasonable and fair method for resolving these contempt proceedings.
      "NOW, THEREFORE, it is hereby ORDERED
      "1. The Settlement Agreement attached to this Order be and is hereby APPROVED and ADOPTED by this Court;
      "2. That the hearing set for September 28, 1998 will be continued to October 20, 1998 at 8:30 a.m. in Courtroom 3-A at the Montgomery County Courthouse, so that the Commissioner of the Department of Corrections may report to the Court that he has complied with this Agreement.
      "DONE and ORDERED this 9[th] day of September, 1998.
      "/s/ William A. Shashy "Circuit Judge”
      The settlement agreement provided as follows:
      "THIS SETTLEMENT AGREEMENT is mutually agreed to by the Plaintiff Class of Counties and Sheriffs in the State of Alabama and Defendant Joe Hopper, Commissioner of the Alabama Department of Corrections, to settle the contempt proceedings presently before the Circuit Court of Montgomery County, Alabama in this case.
      "The parties hereby jointly agree to the following:
      "1. That between October 1 and October 15, 1998[,] the Commissioner of the Alabama Department of Corrections will accept all state inmates whose transcripts have been received by the Department for thirty (30) days or longer.
      "2. That by October 15, 1998[,] all state inmates shall be accepted by the Department of Corrections from county jails within thirty (30) days of receipt of transcripts.
      "3. That the Commissioner of the Alabama Department of Corrections will thereafter accept state inmates in compliance with the Order on Preliminary Injunction entered in this case.
      "4. That the hearing scheduled for September 28, 1998[,] will be continued until October 20, 1998[,] so that the Defendant may report to the Court that he has complied with this Agreement.
      “5. That the Department of Corrections will provide to counsel for the Plaintiff Class a copy of the 'Weekly Report of County Jail Inmates’ which includes information as to whether any state inmates are housed in county jails in violation of this Court’s Order on Preliminary Injunction.
      "6. That, if at the hearing on October 20, 1998[,] it is established the Commissioner of the Alabama Department of Corrections has fully and completely complied with this Agreement, the Plaintiff Class of Counties and Sheriffs agree to dismiss without prejudice these contempt proceedings against the Commissioner of the Alabama Department of Corrections. It is understood and agreed that, in such dismissal, the Plaintiff Class will reserve the right to seek attorney’s fees, costs, expenses, damages, and sanctions for past noncompliance with the Order on Preliminary Injunction and may seek these if the Commissioner of the Alabama Department of Corrections should in the future violate the Order on Preliminary Injunction.
      
      "AGREED to on this 8th day of September, 1998.
      "ATTORNEY FOR THE PLAINTIFF CLASS OF COUNTIES AND SHERIFFS IN THE STATE OF ALABAMA "/s/Kendrick E. Webb "KENDRICK E. WEBB "ATTORNEY FOR JOE HOPPER, COMMISSIONER OF THE ALABAMA DEPARTMENT OF CORRECTIONS "/s/Andrew W. Redd "ANDREW W. REDD "APPROVED BY: /s/Bill Pryor
      "BILL PRYOR "ATTORNEY GENERAL”
     
      
      . In an affidavit filed with this Court, Circuit Judge Denny L. Holloway, who formerly was presiding judge of the Twentieth Judicial Circuit, states:
      "2. Every month, I and the other circuit judges receive a jail roster which shows how many inmates and pre-trial detainees are being incarcerated at the Houston County Jail. The roster contains a breakdown of inmates by sex, by whether the inmates are state or county responsibility. Much too frequently, the jail roster shows the jail to be seriously over capacity....
      "3. The Sheriff's problem, however, becomes my problem as well as the other circuit judges' problem when we have persons appearing before the Court who need to be incarcerated and there simply is no room. In many cases, it is in everyone’s best interest to put the person behind bars, including the person who is to be incarcerated. Many of these people will not take their conduct seriously until they are actually locked up; they see a mere admonition from the Court that they should follow the law or the conditions of their probation [as] a slap on the wrist. Sometimes these people are property offenders; sometimes these people are charged with drug possession; in other cases, the persons have failed to pay child support or other court-ordered fines or restitution. Without the threat of having the offender immediately incarcerated in cases of parole violation or failure to obey other orders of the Court, I do not feel that justice can adequately be served.
      "4. If the situation I have described above were infrequent or temporary, I could understand. However, it is getting to the point in Houston County that a jail filled to excess capacity, not only with county inmates who belong there but with state-ready inmates who do not belong there, is an everyday occurrence.
      “5. I cannot speak for other circuit judges in other counties, but I can state with certainty that the problem in Houston County is reaching a critical stage.”
     
      
      . This Court has also granted the motions of the following to file amici curiae briefs concerning the issues presented in this matter: Autauga County and its sheriff, James W. Johnson; Jefferson County and its sheriff, Jim Woodward; Shelby County and its sheriff, James Jones; and Tuscaloosa County and its sheriff, Edmund M. “Ted” Sexton, Sr.
     
      
      . Because "the prison system or the state on account of the prison system [would be] interested" in any such declaratory-judgment action, the action would have to be filed in the Montgomery Circuit Court. Section 6-3-9, Ala.Code 1975; and see Madison County v. James, 406 So.2d 398 (Ala.1981).
     