Rev 32 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
/**
* PHP Version 5
*
* @category PHP
* @package annuaire
* @author aurelien <aurelien@tela-botanica.org>
* @copyright 2010 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/annuaire/
*/
class LettreControleur extends Controleur {
private $chemin_script_inscription_lettre = null;
private $commande_inscription_lettre = null;
private $commande_desinscription_lettre = null;
private $chemin_lettre = null;
private $adresse_inscription_lettre = null;
private $adresse_desinscription_lettre = null;
private $utilise_mail = false;
public function LettreControleur() {
$this->__construct();
if(Config::get('chemin_script_inscription_lettre') != null) {
$this->chemin_script_inscription_lettre = Config::get('chemin_script_inscription_lettre');
} else {
$this->utilise_mail = true;
}
if(Config::get('commande_inscription_lettre') != null) {
$this->commande_inscription = Config::get('commande_inscription_lettre');
} else {
$this->utilise_mail = true;
}
if(Config::get('commande_desinscription_lettre') != null) {
$this->commande_desinscription_lettre = Config::get('commande_desinscription_lettre');
} else{
$this->utilise_mail = true;
}
if(Config::get('chemin_lettre') != null) {
$this->chemin_lettre = Config::get('chemin_lettre');
} else {
$this->utilise_mail = true;
}
if(Config::get('adresse_inscription_lettre') != null) {
$this->adresse_inscription_lettre = Config::get('adresse_inscription_lettre');
}
if(Config::get('adresse_desinscription_lettre') != null) {
$this->adresse_desinscription_lettre = Config::get('adresse_desinscription_lettre');
}
}
private function envoyerMail($adresse, $inscrit, $sujet) {
// Pour envoyer un mail HTML, l'en-tête Content-type doit être défini
$entetes = 'MIME-Version: 1.0' . "\r\n";
$entetes .= 'Content-type: text/html; charset='.Config::get('appli_encodage'). "\r\n";
// En-têtes additionnels
$entetes .= 'To: '.$adresse."\r\n";
$entetes .= 'From: '.$inscrit."\r\n";
$contenu_mail = '';
return mail($adresse, $sujet, $contenu_mail, $entetes);
}
public function inscriptionLettreActualite($mail) {
if($this->utilise_mail) {
return $this->envoyerMail($this->adresse_inscription_lettre, $mail, 'inscription à la lettre d\'actualité');
} else {
//echo 'exec('.$this->commande_inscription_lettre.' '.$this->chemin_lettre.' '.$mail.')';
//return exec($this->commande_inscription_lettre.' '.$this->chemin_lettre.' '.$mail);
}
}
public function desinscriptionLettreActualite($mail) {
if($this->utilise_mail) {
return $this->envoyerMail($this->adresse_inscription_lettre, $mail, 'desinscription à la lettre d\'actualité');
} else {
//echo 'exec('.$this->commande_desinscription_lettre.' '.$this->chemin_lettre.' '.$mail.')';
//return exec($this->commande_desinscription_lettre.' '.$this->chemin_lettre.' '.$mail);
}
}
public function ModificationInscriptionLettreActualite($ancien_mail, $nouveau_mail) {
if($this->utilise_mail) {
$adresse_deinscription_lettre = Config::get('adresse_desinscription_lettre');
$suppression_ancien_mail = $this->envoyerMail($adresse_deinscription_lettre, $ancien_mail, 'desinscription à la lettre d\'actualité');
$adresse_inscription_lettre = Config::get('adresse_inscription_lettre');
$ajout_nouveau_mail = $this->envoyerMail($adresse_inscription_lettre, $nouveau_mail, 'inscription à la lettre d\'actualité');
return $suppression_ancien_mail && $ajout_nouveau_mail;
} else {
$desinscription = $this->desinscriptionLettreActualite($ancien_mail);
$inscription = $this->inscriptionLettreActualite($nouveau_mail);
return ($desinscription && $inscription);
}
}
}
?>