dolibarr/htdocs/comm/mailing/mailing.class.php

228 lines
5.8 KiB
PHP
Raw Normal View History

2005-01-05 16:26:05 +01:00
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
2005-01-05 16:26:05 +01:00
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
/** \file htdocs/comm/mailing/mailing.class.php
\brief Fichier de la classe de gestion des mailings
\version $Revision$
*/
2005-01-05 16:26:05 +01:00
/** \class Mailing
\brief Classe permettant la gestion des mailings
2005-01-05 16:26:05 +01:00
*/
class Mailing
{
var $id;
/**
* \brief Constructeur de la classe
* \param DB handler acc<EFBFBD>s base de donn<EFBFBD>es
*/
2005-01-23 03:22:06 +01:00
function Mailing($DB)
2005-01-05 16:26:05 +01:00
{
2005-01-23 03:22:06 +01:00
global $langs;
$langs->load("mails");
$this->db = $DB ;
$this->db_table = MAIN_DB_PREFIX."mailing";
$this->statuts[0] = $langs->trans("MailingStatusDraft");
$this->statuts[1] = $langs->trans("MailingStatusValidated");
$this->statuts[2] = $langs->trans("MailingStatusApproved");
$this->statuts[3] = $langs->trans("MailingStatusSent");
2005-01-05 16:26:05 +01:00
}
/**
* \brief Cr<EFBFBD>ation du mailing
* \param user object utilisateur qui cr<EFBFBD>e
*
*/
function create($user)
{
dolibarr_syslog("Mailing::Create");
$sql = "INSERT INTO ".$this->db_table;
$sql .= " (date_creat, fk_user_creat)";
$sql .= " VALUES (now(), ".$user->id.")";
if (strlen(trim($this->titre)) == 0)
{
$this->titre = "Sans titre";
}
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
return $this->update();
}
else
{
dolibarr_syslog("Mailing::Create Erreur -1");
return -1;
}
}
2005-01-23 03:22:06 +01:00
2005-01-05 16:26:05 +01:00
/**
2005-01-23 03:22:06 +01:00
* \brief Update les infos du mailing
2005-01-05 16:26:05 +01:00
*/
function update()
{
dolibarr_syslog("Mailing::Update");
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
$sql .= " SET titre = '".$this->titre."'";
$sql .= " , sujet = '".$this->sujet."'";
$sql .= " , body = '".$this->body."'";
$sql .= " WHERE rowid = ".$this->id;
if ($this->db->query($sql) )
{
return 0;
}
else
{
dolibarr_syslog("Mailing::Update Erreur -1");
return -1;
}
}
2005-01-23 03:22:06 +01:00
2005-01-05 16:26:05 +01:00
/**
* \brief Recup<EFBFBD>re l'objet mailing
* \param rowid id du mailing
*/
function fetch($rowid)
{
$sql = "SELECT m.rowid, m.titre, m.sujet, m.body";
$sql .= " , m.email_from, m.email_replyto, m.email_errorsto";
$sql .= " , m.statut, m.nbemail";
$sql .= ", m.fk_user_creat, m.fk_user_valid, m.fk_user_appro";
$sql .= ", ".$this->db->pdate("m.date_creat") . " as date_creat";
$sql .= ", ".$this->db->pdate("m.date_valid") . " as date_valid";
$sql .= ", ".$this->db->pdate("m.date_appro") . " as date_appro";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
$sql .= " WHERE m.rowid = ".$rowid;
if ($this->db->query($sql) )
{
if ($this->db->num_rows())
{
$obj = $this->db->fetch_object();
$this->id = $obj->rowid;
$this->statut = $obj->statut;
$this->nbemail = $obj->nbemail;
$this->titre = stripslashes($obj->titre);
$this->sujet = stripslashes($obj->sujet);
$this->body = stripslashes($obj->body);
$this->email_from = $obj->email_from;
$this->email_replyto = $obj->email_replyto;
$this->email_errorsto = $obj->email_errorsto;
$this->user_creat = $obj->fk_user_creat;
$this->user_valid = $obj->fk_user_valid;
$this->user_appro = $obj->fk_user_appro;
$this->date_creat = $obj->date_creat;
$this->date_valid = $obj->date_valid;
$this->date_appro = $obj->date_appro;
return 0;
}
else
{
dolibarr_syslog("Mailing::Fetch Erreur -1");
return -1;
}
}
else
{
dolibarr_syslog("Mailing::Fetch Erreur -2");
return -2;
}
}
/**
2005-01-23 03:22:06 +01:00
* \brief Valide le mailing
* \param user objet user qui valide
2005-01-05 16:26:05 +01:00
*/
function valid($user)
{
dolibarr_syslog("Mailing::Valid");
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
$sql .= " SET statut = 1, date_valid = now(), fk_user_valid=".$user->id;
$sql .= " WHERE rowid = ".$this->id." AND statut = 0 ;";
if ($this->db->query($sql) )
{
return 0;
}
else
{
dolibarr_syslog("Mailing::Valid Erreur -1");
return -1;
}
}
/**
2005-01-23 03:22:06 +01:00
* \brief Approuve le mailing
* \param user objet user qui approuve
2005-01-05 16:26:05 +01:00
*/
function approve($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
$sql .= " SET statut = 2, date_appro = now(), fk_user_appro=".$user->id;
$sql .= " WHERE rowid = ".$this->id." AND statut = 1 ;";
if ($this->db->query($sql) )
{
return 0;
}
else
{
dolibarr_syslog("Mailing::Valid Erreur -1");
return -1;
}
}
/**
2005-01-23 03:22:06 +01:00
* \brief Supprime le mailing
* \param rowid id du mailing <EFBFBD> supprimer
2005-01-05 16:26:05 +01:00
*/
function delete($rowid)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing";
$sql .= " WHERE fk_facture = ".$rowid;
2005-01-23 03:22:06 +01:00
$this->db->query($sql);
2005-01-05 16:26:05 +01:00
}
2005-01-23 03:22:06 +01:00
2005-01-05 16:26:05 +01:00
}
?>