Commit bca31bca authored by Feu's avatar Feu
Browse files

code pour la gestion des mailing/club

parent 35c8c4ee
......@@ -261,6 +261,8 @@ class asso extends stdentity
)
);
$this->_ml_all_subscribe_user($id_utl,$role);
}
/** Ajoute un ancien membre de l'association
......@@ -300,6 +302,8 @@ class asso extends stdentity
if ( !$date_fin )
$date_fin = time();
$this->_ml_all_unsubscribe_user($id_utl);
$sql = new update ($this->dbrw,
"asso_membre",
array(
......@@ -351,6 +355,26 @@ class asso extends stdentity
return ($req->lines == 1);
}
function member_role ( $id_utl )
{
if ( is_null($id_utl) )
return false;
$req = new requete($this->db, "SELECT role FROM `asso_membre`
WHERE `id_asso` = '" . mysql_real_escape_string($this->id) . "'
AND `id_utilisateur` = '" . mysql_real_escape_string($id_utl) . "'
AND `date_fin` is NULL
LIMIT 1");
if ( $req->lines != 1 )
return NULL;
list($role) = $req->get_row();
return $role;
}
/** Enlève une 'participation' d'un membre de l'association actuelle
* @param $id_utl ID de l'utilisateur
* @param $date_debut Date de debut de la 'participation' (timestamp unix)
......@@ -359,6 +383,8 @@ class asso extends stdentity
{
if ( is_null($this->dbrw) ) return; // "Read Only" mode
$prevrole = $this->member_role($id_utl);
$sql = new delete ($this->dbrw,
"asso_membre",
array(
......@@ -367,6 +393,15 @@ class asso extends stdentity
"date_debut" => strftime("%Y-%m-%d", $date_debut)
)
);
$newrole = $this->member_role($id_utl);
if ( is_null($newrole) )
$this->_ml_all_unsubscribe_user($id_utl,$prevrole);
elseif ( $newrole != $prevrole )
{
$this->_ml_all_unsubscribe_user($id_utl,$prevrole);
$this->_ml_all_subscribe_user($id_utl,$newrole);
}
}
......@@ -434,6 +469,55 @@ class asso extends stdentity
return true;
}
function _ml_all_subscribe_user ( $id_utl, $role=null )
{
$user = new utilisateur($this->db);
$user->load_by_id($id_utl);
if ( !$user->is_valid() )
return;
if ( is_null($role) )
$role = $this->member_role($user->id);
if ( !is_null($this->id_parent) )
$this->_ml_subscribe_user($this->nom_unix."-membres",$user->email);
if ( $role > ROLEASSO_MEMBREACTIF )
$this->_ml_subscribe_user($this->nom_unix."-bureau",$user->email);
}
function _ml_all_unsubscribe_user ( $id_utl, $role=null )
{
$user = new utilisateur($this->db);
$user->load_by_id($id_utl);
if ( !$user->is_valid() )
return;
if ( is_null($role) )
$role = $this->member_role($user->id);
if ( !is_null($this->id_parent) )
$this->_ml_unsubscribe_user($this->nom_unix."-membres",$user->email);
if ( $role > ROLEASSO_MEMBREACTIF )
$this->_ml_unsubscribe_user($this->nom_unix."-bureau",$user->email);
}
static function _ml_subscribe ( $ml, $email )
{
//TODO: subscribe $email to $ml
}
static function _ml_unsubscribe ( $ml, $email )
{
//TODO: unsubscribe $email from $ml
}
}
......
......@@ -613,6 +613,41 @@ class utilisateur extends stdentity
$this->groupes[$this->promo_utbm+40000] = "promo".sprintf("%02d",$this->promo_utbm)."-membres";
}
function _update_mailings ( $oldemail, $newemail )
{
require_once($topdir."include/entities/asso.inc.php");
$req = new requete($this->db,
"SELECT ".
"`asso`.`nom_unix_asso`, ".
"`asso_membre`.`role`, ".
"`asso`.`id_asso_parent` " .
"FROM `asso_membre` " .
"INNER JOIN `asso` ON `asso`.`id_asso`=`asso_membre`.`id_asso` " .
"WHERE `asso_membre`.`id_utilisateur`='".$this->id."' " .
"AND `asso_membre`.`date_fin` is NULL " .
"AND (`asso`.`id_asso_parent` IS NOT NULL OR `asso_membre`.`role` > 1 ) " .
"ORDER BY `asso`.`nom_asso`");
while ( list($name,$role,$parent) = $req->get_row() )
{
if ( $role > 1 )
{
asso::_ml_unsubscribe($name."-bureau",$oldemail);
asso::_ml_subscribe($name."-bureau",$newemail);
}
if( !is_null($parent) )
{
asso::_ml_unsubscribe($name."-membres",$oldemail);
asso::_ml_subscribe($name."-membres",$newemail);
}
}
}
/** Determine si l'utilisateur est membre du groupe précisé.
* (Charge automatiquement les groupes)
* @param $name nom du groupe
......@@ -1204,6 +1239,8 @@ class utilisateur extends stdentity
function set_email ( $email, $admin=false )
{
$this->_update_mailings($this->email,$email);
$this->email = $email;
$req = new update($this->dbrw,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment