Value // private $char_set; //!< string character set of message function __construct( protected \Database $cn , protected $name ) { $this->load(); } /** * @brief set the value in the array $a_value thkx the key * @param $key (string) key must be in Mail_Parameter::PARAMETER * @param $value (string) value * @return Mail_Parameter * @throws \Exception if the key doesn't exist */ function __set($key, $value) { if (in_array($key, Mail_Parameter::PARAMETER) == false) { throw new \Exception("MP72 : unknown $key"); } $this->a_value[$key] = $value; return $this; } /** * @brief get the value in the array $a_value thkx the key * @param $key (string) key must be in Mail_Parameter::PARAMETER * @param $value (string) value * @return a string or null if not found * @throws \Exception if the key doesn't exist */ function __get($key) { if (in_array($key, Mail_Parameter::PARAMETER) == false) { throw new \Exception("MP79 : unknown $key"); } if (isset($this->a_value[$key])) { return $this->a_value[$key]; } return null; } /** * @brief save into the database */ function save() { if ( $this->smtp_replyto!="" && filter_var($this->smtp_replyto, FILTER_VALIDATE_EMAIL) == false) { throw new \Exception (_("adresse réponse invalide"),140); ; } if ( $this->smtp_from!="" && filter_var($this->smtp_from, FILTER_VALIDATE_EMAIL) == false) { throw new \Exception (_("adresse expéditeur invalide"),146); } if ( $this->smtp_type=="sendmail" && defined("ALLOWED_EMAIL_DOMAIN")) { $a_allowed=explode(",", ALLOWED_EMAIL_DOMAIN); if ($this->smtp_replyto !="" ) { list($m,$domain)=explode("@",$this->smtp_replyto); if (!in_array($domain, $a_allowed)) { throw new \Exception (_("adresse réponse invalide"),153); } } if ($this->smtp_from !="" ) { list($m,$domain)=explode("@",$this->smtp_from); if (!in_array($domain, $a_allowed)) { throw new \Exception (_("adresse expéditeur invalide"),160); } } } foreach (self::PARAMETER as $key) { $id = $this->cn->get_value("select pe_id from parm_mail_server where pe_parameter=$1 and pe_name=$2", [$key, $this->name]); if ($id == "") { $record = new \Parm_Mail_Server_SQL($this->cn); $record->set("pe_name", $this->name); $record->set("pe_parameter", $key); $record->set("pe_value", $this->a_value[$key]); $record->insert(); } else { $record = new \Parm_Mail_Server_SQL($this->cn, $id); $record->set("pe_value", $this->a_value[$key]); $record->update(); } } } /** * @brief load from the database */ function load() { $a_value = array_column( $this->cn->get_array("select pe_parameter , pe_value from public.parm_mail_server where pe_name=$1" , [$this->name]) , "pe_value","pe_parameter" ); foreach (self::PARAMETER as $key) { $this->a_value[$key] = $a_value[$key] ?? ""; } } function get($key) { return $this->$key; } function set($key, $value): Mail_Parameter { $this->$key = $value; return $this; } /** * @brief display a form to input the parameter * */ function input() { include NOALYSS_TEMPLATE . "/mail_parameter-input.php"; } /** * @brief retrieve information from GET */ function from_get() { $http = new \HttpInput(); $this->smtp_user = $http->get('smtp_user'); $this->smtp_password = $http->get('smtp_password'); $this->smtp_host = $http->get('smtp_host'); $this->smtp_port = $http->get('smtp_port'); $this->smtp_replyto = $http->get('smtp_replyto'); $this->smtp_from = $http->get('smtp_from'); $this->smtp_type= $http->get('smtp_type'); $this->smtp_secure = $http->get('smtp_secure'); $this->smtp_auth_type = $http->get('smtp_auth_type'); $this->smtp_auth=1; } /** * @brief retrieve information from POST */ function from_post() { $http = new \HttpInput(); $this->smtp_user = $http->post('smtp_user'); $this->smtp_password = $http->post('smtp_password'); $this->smtp_host = $http->post('smtp_host'); $this->smtp_port = $http->post('smtp_port'); $this->smtp_replyto = $http->post('smtp_replyto'); $this->smtp_from = $http->post('smtp_from'); $this->smtp_type= $http->post('smtp_type'); $this->smtp_secure = $http->post('smtp_secure'); $this->smtp_auth_type = $http->post('smtp_auth_type'); $this->smtp_auth=1; } public static function Factory(\Database $cnx,$reply_to="", $blind_copy="",$mail_setting=MAIL_SETTING_NOALYSS) { $mail_parameter=new Mail_Parameter($cnx,MAIL_SETTING_NOALYSS); if ( $mail_parameter->smtp_type=="sendmail") { $mail=new \Sendmail(); $mail->setReplyTo($reply_to)->setBlindCopy($blind_copy); return $mail; } elseif ($mail_parameter->smtp_type=="smtp") { $phpmail= new SMTPMail($mail_parameter); $phpmail->setReplyTo($reply_to)->setBlindCopy($blind_copy); return $phpmail; } throw new \Exception("MP212 MAIL NOT CONFIGURED",212); } }