New: Ajout des triggers sur la gestion des adhrents

This commit is contained in:
Laurent Destailleur 2006-03-23 16:02:52 +00:00
parent 7ced62b0d5
commit 815e4eeec7
5 changed files with 281 additions and 266 deletions

View File

@ -54,7 +54,6 @@ class Adherent
var $pays_id;
var $pays_code;
var $pays;
var $typeid;
var $morphy;
var $email;
var $public;
@ -64,6 +63,10 @@ class Adherent
var $pass;
var $naiss;
var $photo;
var $typeid; // Id type adherent
var $type; // Libellé type adherent
// var $public;
var $array_options;
@ -307,12 +310,11 @@ class Adherent
/**
\brief Fonction qui crée l'adhérent
\param userid userid de l'adhérent
\return int <0 si ko, >0 si ok
*/
function create($userid)
function create()
{
global $conf,$langs;
global $conf,$langs,$user;
// Verification parametres
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email)) {
@ -330,7 +332,15 @@ class Adherent
if ($result)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
return $this->update();
$result=$this->update(1);
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('MEMBER_CREATE',$this,$user,$langs,$conf);
// Fin appel triggers
return 1;
}
else
{
@ -342,18 +352,23 @@ class Adherent
/**
\brief fonction qui met à jour l'adhérent
\return int <0 si ko, >0 si ok
\param disable_triggers 1=désactive le trigger UPDATE (quand appelé par creation)
\return int <0 si ko, >0 si ok
*/
function update()
function update($disable_trigger=0)
{
global $conf,$langs;
global $conf,$langs,$user;
dolibarr_syslog("Adherent.class.php::update $disable_trigger");
// Verification parametres
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email)) {
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email))
{
$this->error = $langs->trans("ErrorBadEMail",$this->email);
return -1;
}
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql .= " prenom = '".$this->prenom ."'";
@ -376,14 +391,14 @@ class Adherent
$sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
if (!$result)
if (! $result)
{
dolibarr_print_error($this->db);
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
if (sizeof($this->array_options) > 0 )
if (sizeof($this->array_options) > 0)
{
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = ".$this->id;
$this->db->query($sql_del);
@ -398,24 +413,29 @@ class Adherent
$sql .= ") VALUES ($this->id";
foreach($this->array_options as $key => $value)
{
$sql.=",'".$this->array_options[$key]."'";
}
$sql.=");";
$result = $this->db->query($sql);
if ($result)
if (! $result)
{
return 1;
}
else
{
dolibarr_print_error($this->db);
$this->error=$this->db->error();
$this->db->rollback();
return -2;
}
}
if (! $disable_trigger)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('MEMBER_MODIFY',$this,$user,$langs,$conf);
// Fin appel triggers
}
$this->db->commit();
return 1;
}
@ -625,12 +645,16 @@ class Adherent
/**
\brief Fonction qui insère la cotisation dans la base de données
et eventuellement liens dans banques, mailman, etc...
\param date Date cotisation
\param montant Montant cotisation
\return int rowid de l'entrée ajoutée, <0 si erreur
*/
function cotisation($date, $montant)
function cotisation($date, $montant, $accountid, $operation, $label, $num_chq)
{
global $conf,$langs,$user;
dolibarr_syslog("Adherent.class.php::cotisation $date, $montant, $accountid, $operation, $label, $num_chq");
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cotisation (fk_adherent, datec, dateadh, cotisation)";
@ -639,33 +663,77 @@ class Adherent
$result=$this->db->query($sql);
if ($result)
{
if ( $this->db->affected_rows($result) )
$rowid=$this->db->last_insert_id(MAIN_DB_PREFIX."cotisation");
// datefin = date + 1 an
$datefin = mktime(12, 0 , 0, strftime("%m",$date), strftime("%d",$date),
strftime("%Y",$date)+1) - (24 * 3600);
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin);
$sql.= " WHERE rowid =". $this->id;
$resql=$this->db->query( $sql);
if ($resql)
{
$rowid=$this->db->last_insert_id(MAIN_DB_PREFIX."cotisation");
$datefin = mktime(12, 0 , 0,
strftime("%m",$date),
strftime("%d",$date),
strftime("%Y",$date)+1) - (24 * 3600);
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin)." WHERE rowid =". $this->id;
if ( $this->db->query( $sql) )
{
$this->db->commit();
return $rowid;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -3;
}
// Rajout du nouveau cotisant dans les listes qui vont bien
if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin)
{
$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT);
}
// Insertion dans la gestion bancaire si configuré pour
if ($conf->global->ADHERENT_BANK_USE && $accountid)
{
$acct=new Account($this->db,$accountid);
$dateop=strftime("%Y%m%d",time());
$amount=$cotisation;
$insertid=$acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user);
if ($insertid > 0)
{
$inserturlid=$acct->add_url_line($insertid, $adh->id, DOL_URL_ROOT.'/adherents/fiche.php?rowid=', $adh->getFullname(), 'member');
if ($inserturlid > 0)
{
// Met a jour la table cotisation
$sql="UPDATE ".MAIN_DB_PREFIX."cotisation SET fk_bank=".$insertid." WHERE rowid=".$crowid;
$resql = $this->db->query($sql);
if (! $resql)
{
$this->error=$this->db->error();
$this->db->rollback();
return -5;
}
}
else
{
$this->error=$acct->error();
$this->db->rollback();
return -4;
}
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -3;
}
}
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('MEMBER_SUBSCRIPTION',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->commit();
return $rowid;
}
else
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -2;
}
}
}
else
{
@ -675,59 +743,76 @@ class Adherent
}
}
/**
\brief fonction qui vérifie que l'utilisateur est valide
\param userid userid de l'adhérent
*/
function validate($userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET ";
$sql .= "statut=1";
$sql .= ",fk_user_valid=".$userid;
$sql .= " WHERE rowid = $this->id";
$result = $this->db->query($sql);
if ($result)
/**
* \brief Fonction qui vérifie que l'utilisateur est valide
* \param userid userid adhérent à valider
* \return int <0 si ko, >0 si ok
*/
function validate($userid)
{
return 1;
global $user,$langs,$conf;
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql.= " statut=1,";
$sql.= " fk_user_valid=".$userid;
$sql.= " WHERE rowid = $this->id";
$result = $this->db->query($sql);
if ($result)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('MEMBER_VALIDATE',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
else
/**
* \brief Fonction qui résilie un adhérent
* \param userid userid adhérent à résilier
* \return int <0 si ko, >0 si ok
*/
function resiliate($userid)
{
dolibarr_print_error($this->db);
return 0;
global $user,$langs,$conf;
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET ";
$sql .= "statut=0";
$sql .= ",fk_user_valid=".$userid;
$sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
if ($result)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('MEMBER_RESILIATE',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
}
/**
\brief fonction qui résilie un adhérent
\param userid userid de de l'adhérent
*/
function resiliate($userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET ";
$sql .= "statut=0";
$sql .= ",fk_user_valid=".$userid;
$sql .= " WHERE rowid = $this->id";
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return 0;
}
}
/**

View File

@ -45,6 +45,7 @@ $errmsg='';
$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
$rowid=isset($_GET["rowid"])?$_GET["rowid"]:$_POST["rowid"];
$typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"];
@ -62,95 +63,56 @@ if ($_POST["action"] == 'sendinfo')
if ($_POST["action"] == 'cotisation')
{
$adh = new Adherent($db);
$adh->id = $rowid;
$adh->fetch($rowid);
$reday=$_POST["reday"];
$remonth=$_POST["remonth"];
$reyear=$_POST["reyear"];
$datecotisation=@mktime(12, 0 , 0, $remonth, $reday, $reyear);
$cotisation=$_POST["cotisation"];
if ($cotisation > 0)
$accountid=$_POST["accountid"];
$operation=$_POST["operation"];
$label=$_POST["label"];
$num_chq=$_POST["num_chq"];
if (! $datecotisation)
{
$errmsg=$langs->trans("BadDateFormat");
$action='';
}
if (! $cotisation > 0)
{
$errmsg=$langs->trans("ErrorFieldRequired",$langs->trans("Amount"));
$action='';
}
if ($action)
{
$db->begin();
$adh = new Adherent($db);
$adh->id = $rowid;
$adh->fetch($rowid);
// Rajout du nouveau cotisant dans les listes qui vont bien
// if (defined("ADHERENT_MAILMAN_LISTS_COTISANT") && ADHERENT_MAILMAN_LISTS_COTISANT!='' && $adh->datefin == "0000-00-00 00:00:00"){
if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && $adh->datefin == 0)
{
$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT);
}
$crowid=$adh->cotisation(mktime(12, 0 , 0, $remonth, $reday, $reyear), $cotisation);
$crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq);
if ($crowid > 0)
{
// Insertion dans la gestion banquaire si configuré pour
if ($conf->global->ADHERENT_BANK_USE)
{
$acct=new Account($db,$_POST["accountid"]);
$dateop=strftime("%Y%m%d",time());
$amount=$cotisation;
$insertid=$acct->addline($dateop, $_POST["operation"], $_POST["label"], $amount, $_POST["num_chq"], '', $user);
if ($insertid > 0)
{
$inserturlid=$acct->add_url_line($insertid, $adh->id, DOL_URL_ROOT.'/adherents/fiche.php?rowid=', $adh->getFullname(), 'member');
if ($inserturlid > 0)
{
// Met a jour la table cotisation
$sql="UPDATE ".MAIN_DB_PREFIX."cotisation SET fk_bank=".$insertid." WHERE rowid=".$crowid;
$resql = $db->query($sql);
if ($resql)
{
$db->commit();
//Header("Location: fiche.php");
}
else
{
$db->rollback();
dolibarr_print_error($db);
}
}
else
{
$db->rollback();
dolibarr_print_error($db,$acct->error);
}
}
else
{
$db->rollback();
dolibarr_print_error($db,$acct->error);
}
}
else
{
$db->commit();
}
$db->commit();
// Envoi mail
if ($conf->global->ADHERENT_MAIL_COTIS)
{
$adh->send_an_email($adh->email,$conf->global->ADHERENT_MAIL_COTIS,$conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
}
}
else
{
$db->rollback();
dolibarr_print_error($db);
}
// Envoi mail
if ($conf->global->ADHERENT_MAIL_COTIS)
{
$adh->send_an_email($adh->email,$conf->global->ADHERENT_MAIL_COTIS,$conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
dolibarr_print_error($db,$adh->error);
}
}
else
{
$adh = new Adherent($db);
$adh->id = $rowid;
$adh->fetch($rowid);
}
$errmsg=$langs->trans("FieldRequired",$langs->trans("Amount"));
$action = "edit";
}
if ($action == 'update')
@ -184,12 +146,14 @@ if ($action == 'update')
$adh->statut = $_POST["statut"];
$adh->public = $_POST["public"];
foreach($_POST as $key => $value){
if (ereg("^options_",$key)){
foreach($_POST as $key => $value)
{
if (ereg("^options_",$key))
{
$adh->array_options[$key]=$_POST[$key];
}
}
if ($adh->update($user->id)>=0)
if ($adh->update(0) >= 0)
{
Header("Location: fiche.php?rowid=".$adh->id);
exit;
@ -463,7 +427,7 @@ if ($_POST["action"] == 'confirm_add_spip' && $_POST["confirm"] == 'yes')
llxHeader();
if ($errmsg != '')
if ($errmsg)
{
print '<div class="error">'.$errmsg.'</div>';
print "\n";
@ -590,7 +554,7 @@ if ($action == 'create')
print '<tr><td width="15%">'.$langs->trans("MemberType").'</td><td width="35%">';
$listetype=$adht->liste_array();
if (sizeof($listetype)) {
$htmls->select_array("type", $listetype);
$htmls->select_array("type", $listetype, $typeid);
} else {
print '<font class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</font>';
}
@ -686,6 +650,7 @@ if ($rowid && $action != 'edit')
$html = new Form($db);
/*
* Affichage onglets
*/

View File

@ -153,7 +153,9 @@ if (! $rowid && $_GET["action"] != 'create' && $_GET["action"] != 'edit') {
*
*/
print '<div class="tabsAction">';
print "<a class=\"tabAction\" href=\"type.php?action=create\">".$langs->trans("NewType")."</a>";
print "<a class=\"butAction\" href=\"type.php?action=create\">".$langs->trans("NewType")."</a>";
print "</div>";
}
@ -230,11 +232,11 @@ if ($rowid > 0)
print '<tr><td width="15%">'.$langs->trans("Label").'</td><td>'.$adht->libelle.'</td></tr>';
print '<tr><td>'.$langs->trans("SubscriptionRequired").'</td><td>';
print $adht->cotisation;
print yn($adht->cotisation);
print '</tr>';
print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
print $adht->vote;
print yn($adht->vote);
print '</tr>';
print '<tr><td valign="top">'.$langs->trans("Comments").'</td><td>';
@ -252,7 +254,11 @@ if ($rowid > 0)
*
*/
print '<div class="tabsAction">';
print "<a class=\"tabAction\" href=\"type.php?action=edit&amp;rowid=".$adht->id."\">".$langs->trans("Edit")."</a>";
print "<a class=\"butAction\" href=\"type.php?action=edit&amp;rowid=".$adht->id."\">".$langs->trans("Edit")."</a>";
print "<a class=\"butAction\" href=\"fiche.php?action=create&typeid=".$adht->id."\">".$langs->trans("AddMember")."</a>";
print "</div>";
}

View File

@ -1,7 +1,8 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,9 +22,10 @@
* $Source$
*/
/*! \file htdocs/admin/boutique.php
/**
\file htdocs/admin/boutique.php
\ingroup boutique
\brief Page d'administration/configuration du module Boutique
\brief Page d'administration/configuration du module OsCommerce
\version $Revision$
*/
@ -35,103 +37,35 @@ if (!$user->admin)
accessforbidden();
llxHeader();
$dir = "../includes/modules/facture/";
//
// \todo mettre cette section dans la base de données
//
$modules["BOUTIQUE_LIVRE"][0] = "Livres";
$modules["BOUTIQUE_LIVRE"][1] = "BOUTIQUE_LIVRE";
$modules["BOUTIQUE_LIVRE"][2] = BOUTIQUE_LIVRE;
$modules["BOUTIQUE_LIVRE"][3] = "Module de gestion des livres";
$modules["BOUTIQUE_ALBUM"][0] = "Albums";
$modules["BOUTIQUE_ALBUM"][1] = "BOUTIQUE_ALBUM";
$modules["BOUTIQUE_ALBUM"][2] = BOUTIQUE_ALBUM;
$modules["BOUTIQUE_ALBUM"][3] = "Module de gestion des albums";
/*
* Actions
*/
if ($action == 'set')
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$value."';";
$db->query($sql);
$sql ='';
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES ('".$value."','1',0) ; ";
//$sql = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = '".$value."', value='1', visible = 0";
if ($db->query($sql))
{
$modules[$value][2] = 1;
}
dolibarr_set_const($db,'XXX',$value);
}
if ($action == 'reset')
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$value."';";
$db->query($sql);
$sql = '';
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES ('".$value."','0',0) ; ";
//$sql = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = '".$value."', value='0', visible = 0";
if ($db->query($sql))
{
$modules[$value][2] = 0;
}
dolibarr_del_const($db,'XXX');
}
/*
* Affichage page
*/
llxHeader();
print_titre($langs->trans("OSCommerceSetup"));
print $langs->trans("ToDo");
$db->close();
print_titre("Boutique");
print '<table border="1" cellpadding="3" cellspacing="0">';
print '<TR class="liste_titre">';
print '<td>Nom</td>';
print '<td>Info</td>';
print '<td align="center">Activé</td>';
print '<td>&nbsp;</td>';
print "</TR>\n";
foreach ($modules as $key => $value)
{
$titre = $modules[$key][0];
$const_name = $modules[$key][1];
$const_value = $modules[$key][2];
$desc = $modules[$key][3];
print '<tr><td>';
echo "$titre";
print "</td><td>\n";
echo "$desc";
print '</td><td align="center">';
if ($const_value == 1)
{
print img_tick();
}
else
{
print "&nbsp;";
}
print '</td><td align="center">';
if ($const_value == 1)
{
print '<a href="boutique.php?action=reset&value='.$const_name.'">'.$langs->trans("Disable").'</a>';
}
else
{
print '<a href="boutique.php?action=set&value='.$const_name.'">'.$langs->trans("Activate").'</a>';
}
print '</td></tr>';
}
print '</table>';
llxFooter();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -219,6 +219,31 @@ class InterfaceDemo
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
}
// Members
elseif ($action == 'MEMBER_CREATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
}
elseif ($action == 'MEMBER_VALIDATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
}
elseif ($action == 'MEMBER_SUBSCRIPTION')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
}
elseif ($action == 'MEMBER_MODIFY')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
}
elseif ($action == 'MEMBER_RESILIATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
}
elseif ($action == 'MEMBER_DELETE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
}
else
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' was ran but no handler found for this action.");