dolibarr/htdocs/docs/document.class.php

90 lines
2.2 KiB
PHP
Raw Normal View History

2007-04-13 14:05:21 +02:00
<?PHP
/* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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.
*/
/**
2009-10-19 21:54:27 +02:00
* \file htdocs/docs/document.class.php
* \ingroup editeurs
* \brief Classe de generation des courriers pour les editeurs
* \version $Id$
2007-04-13 14:05:21 +02:00
*/
class Document
{
/**
\brief Constructeur
2009-10-19 21:54:27 +02:00
\param db Handler acc<EFBFBD>s base de donn<EFBFBD>e
2007-04-13 14:05:21 +02:00
*/
function Document ($db)
{
$this->db = $db;
}
2009-02-11 16:09:59 +01:00
2007-04-13 14:05:21 +02:00
/**
2009-10-19 21:54:27 +02:00
\brief G<EFBFBD>n<EFBFBD>re le document
2007-04-13 14:05:21 +02:00
\return int 0= ok, <> 0 = ko
*/
function Generate ($id)
{
2007-04-13 17:43:30 +02:00
$errno = 0;
dol_syslog("Document::Generate id=$id", LOG_DEBUG );
2007-04-13 14:05:21 +02:00
$this->id = $id;
2009-02-11 16:09:59 +01:00
$class = $id;
$classfile = 'docs/class/'.$class.'.class.php';
2007-04-13 14:05:21 +02:00
require DOL_DOCUMENT_ROOT.'/'.$classfile;
$obj = new $class($this->db);
2007-04-13 17:43:30 +02:00
$this->db->begin();
2007-04-13 14:05:21 +02:00
2007-04-13 17:43:30 +02:00
$sql = "DELETE FROM ".MAIN_DB_PREFIX."document";
$sql.= " WHERE name='".$obj->name."';";
2009-02-11 16:09:59 +01:00
2007-04-13 17:43:30 +02:00
$resql=$this->db->query($sql);
2009-02-11 16:09:59 +01:00
2007-04-13 14:05:21 +02:00
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document";
2007-04-13 17:43:30 +02:00
$sql.= " (name,file_name,file_extension,date_generation) VALUES";
$sql.= " ('".$obj->name."','".$obj->file."','".$obj->extension."',".$this->db->idate(mktime()).")";
2009-02-11 16:09:59 +01:00
2007-04-13 14:05:21 +02:00
$resql=$this->db->query($sql);
2009-02-11 16:09:59 +01:00
2007-04-13 17:43:30 +02:00
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."document");
2009-02-11 16:09:59 +01:00
2007-04-13 17:43:30 +02:00
$err = $obj->Generate($id);
2009-02-11 16:09:59 +01:00
2007-04-13 17:43:30 +02:00
if ($err === 0)
{
$this->db->commit();
dol_syslog("Document::Generate COMMIT", LOG_DEBUG );
2007-04-13 17:43:30 +02:00
}
else
{
$this->db->rollback();
dol_syslog("Document::Generate ROLLBACK", LOG_ERR );
2007-04-13 17:43:30 +02:00
}
2009-02-11 16:09:59 +01:00
2007-04-13 17:43:30 +02:00
return $errno;
2007-04-13 14:05:21 +02:00
}
}
?>