(1) Except as provided in subsection (2) of this section, if an inmate plaintiff files a pauper's affidavit in a civil action and the defendant is an employee of the department and the civil action pertains to the inmate's condition of confinement, the department shall pay, out of any funds available for such purpose, all costs of court assessed against the inmate in the civil action. However, the department shall not pay the costs of court if the inmate has on three (3) or more prior occasions, while incarcerated, brought an action or appeal that was dismissed on the grounds that it was frivolous, malicious, or failed to state a claim upon which relief could be granted. An inmate shall not bring a civil action or appeal a judgment in a civil action or proceeding in forma pauperis if the prisoner has, on three (3) or more prior occasions, while incarcerated or detained in any facility, brought an action or appeal in a court that was dismissed on the grounds that it was frivolous, malicious, or failed to state a claim upon which relief may be granted, unless the prisoner is under imminent danger of serious physical injury.