<?php
class Mail_messages {

  private $db;
  private $status;

  public function __construct() {
    $this->db = new Db_layer();
    $this->status = new Status_messages();
  }

  //---[CZ]: odeslání mailů
  public function send() {
    if ($_POST["from"]!="" AND $_POST["subject"]!="" AND $_POST["text"]!="") {
    $text="<p>".$_POST["text"]."</p>";
    $text=str_replace("\r\n\r\n", "</p>\n\n<p>", $text);
    $text=str_replace("\r\n", "<br />", $text);
    $sql=$this->db->query("SELECT mail FROM ".TABLE_USERS." WHERE mail!='' AND mail_messages=1");
    $i=0;
    while(list($mail)=$this->db->fetch_row($sql)) {
    $i++;
    mail($mail, $_POST["subject"], $text, "Content-Type: text/html; charset=\"utf-8\"\nFrom:".$_POST["from"]);
    }
    if ($sql) { $this->status->print_success(LANG_THE_EMAIL_WAS_SUCCESSFULLY_SENDED." (".$i."&times;)"); } else { $this->status->print_error(LANG_AN_ERROR_OCCURED); }
    }
  }

}
?>