dolibarr/htdocs/notify.class.php

132 lines
3.8 KiB
PHP
Raw Normal View History

2004-10-20 23:06:45 +02:00
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2005-01-09 19:30:34 +01:00
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
2003-06-30 19:33:53 +02: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$
*/
/**
2005-07-14 15:03:20 +02:00
\file htdocs/notify.class.php
\brief Fichier de la classe de gestion des notifications
\version $Revision$
2005-01-09 19:30:34 +01:00
*/
2005-07-14 15:03:20 +02:00
/**
\class Notify
\brief Classe de gestion des notifications
2005-01-09 19:30:34 +01:00
*/
class Notify
2003-06-30 19:33:53 +02:00
{
2005-07-14 15:03:20 +02:00
var $id;
var $db;
var $error;
var $author;
var $ref;
var $date;
var $duree;
var $note;
var $projet_id;
/**
* \brief Constructeur
* \param DB Handler acc<EFBFBD>s base
*/
function Notify($DB)
2003-06-30 19:33:53 +02:00
{
2005-07-14 15:03:20 +02:00
$this->db = $DB ;
include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
2003-06-30 19:33:53 +02:00
}
2005-07-14 15:03:20 +02:00
/**
* \brief Envoi mail et sauve trace
*
*/
function send($action, $socid, $texte, $objet_type, $objet_id, $file="")
2003-06-30 19:33:53 +02:00
{
2005-07-14 15:03:20 +02:00
global $conf,$langs;
$sql = "SELECT s.nom, c.email, c.idp, c.name, c.firstname, a.titre,n.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE n.fk_contact = c.idp AND a.rowid = n.fk_action";
$sql .= " AND n.fk_soc = s.idp AND n.fk_action = ".$action;
$sql .= " AND s.idp = ".$socid;
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$sendto = $obj->firstname . " " . $obj->name . " <".$obj->email.">";
if (strlen($sendto))
{
$subject = $langs->trans("DolibarrNotififcation");
$message = $texte;
$filename = split("/",$file);
$replyto = $conf->email_from;
$mailfile = new CMailFile($subject,
$sendto,
$replyto,
$message,
array($file),
array("application/pdf"),
array($filename[sizeof($filename)-1])
);
if ( $mailfile->sendfile() )
{
$sendto = htmlentities($sendto);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id)";
$sql .= " VALUES (now(), $action ,$obj->idp , '$objet_type', $objet_id);";
2005-12-01 00:15:20 +01:00
if (! $this->db->query($sql) )
2005-07-14 15:03:20 +02:00
{
dolibarr_print_error($db);
}
}
else
{
$this->error=$mailfile->error;
}
}
$i++;
}
}
else
{
$this->error=$this->db->error();
}
2003-06-30 19:33:53 +02:00
}
2005-07-14 15:03:20 +02:00
}
2003-06-30 19:33:53 +02:00
?>