Hello,
Le code précédemment proposé n'était pas très blindé. Alors, je
rectifie suivant l'exemple ci-après, à propos de la classe projet :
class Project
{
var $id;
var $db;
var $ref;
var $title;
var $socid;
var $mod_codeprojet = null;
/**
* \brief Constructeur de la classe
* \param DB handler accès base de données
*/
function Project($DB)
{
$this->db = $DB;
$this->societe = new Societe($DB);
// definit module code projet
if($conf->global->PROJET_CODEPROJET_ADDON)
{
$varprojet =
$conf->global->PROJET_CODEPROJET_ADDON;
require_once
DOL_DOCUMENT_ROOT.'/includes/modules/projet/'.$varprojet.'.php';
$this->mod_codeprojet = new $varprojet;
}
}
/*
* \brief Crée un projet en base
* \param user Id utilisateur qui crée
* \return int <0 si ko, id du projet crée si ok
*/
function create($user)
{
if (trim($this->ref))
{
$rescode = 0;
$this->mod_codeprojet != null && $rescode =
$this->mod_codeprojet->verif($this->db, $this->ref, $this);
if($rescode <> 0)
{
if ($rescode == -1)
{
$this->error .= "La syntaxe du code projet est
incorrecte.\n";
}
if ($rescode == -2)
{
$this->error .= "Vous devez saisir un code
projet.\n";
}
if ($rescode == -3)
{
$this->error .= "Ce code projet est déjà
utilisé.\n";
}
dolibarr_syslog("Project::Create : $this->error");
$result = -1;
}
else
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref,
title, fk_soc, fk_user_creat, dateo) ";
$sql .= " VALUES ('".addslashes($this->ref)."',
'".addslashes($this->title)."', $this->socid,
".$user->id.",now()) ;";
if ($this->db->query($sql) )
{
$this->id =
$this->db->last_insert_id(MAIN_DB_PREFIX."projet");
$result = $this->id;
}
else
{
dolibarr_syslog("Project::Create error -2");
$this->error=$this->db->error();
$result = -2;
}
}
Cordialement.
JR ATHANASE
|