<?php
// +-------------------------------------------------+
// | 2002-2007 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: alerts_mails_configuration.class.php,v 1.3.4.1 2025/07/03 06:57:20 dgoron Exp $

if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access");

class alerts_mails_configuration extends alerts {

    protected $domains = [];
    
	protected function get_module() {
		return 'admin';
	}

	protected function get_section() {
		return 'mails_configuration';
	}

	protected function is_validated_domain($domain) {
	    if (!isset($this->domains[$domain])) {
	        $this->domains[$domain] = [];
	    }
	    if (!isset($this->domains[$domain]['validated'])) {
    	    $query = "SELECT count(*) FROM mails_configuration 
                WHERE name_mail_configuration = '".addslashes($domain)."' AND mail_configuration_validated = 0 AND mail_configuration_type = 'domain'";
    	    $result = pmb_mysql_query($query);
            $this->domains[$domain]['validated'] = pmb_mysql_result($result, 0, 0);
	    }
	    return $this->domains[$domain]['validated'];
	}
	
	protected function fetch_data() {
		$this->data = array();

		//pour les mails non configurés
		$number = 0;
		$query = "SELECT * FROM mails_configuration WHERE mail_configuration_validated = 0 AND mail_configuration_type = 'address'";
		$result = pmb_mysql_query($query);
		if (pmb_mysql_num_rows($result)) {
		    while ($row = pmb_mysql_fetch_object($result)) {
		        if (empty($row->mail_configuration_hote) || $row->mail_configuration_validated == 0) {
		            $domain = substr($row->name_mail_configuration, strpos($row->name_mail_configuration, '@')+1);
		            if (!$this->is_validated_domain($domain)) {
    		            $number++;
		            }
		        }
		    }
		}
		if ($number) {
			$this->add_data('mails', 'mail_configuration_unvalidated', 'configuration', '', $number);
		}
	}
}