Fix: Meilleur gestion erreur sur création projet
This commit is contained in:
parent
5fcdcc206f
commit
a691947a84
@ -21,66 +21,68 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
\file htdocs/project.class.php
|
\file htdocs/project.class.php
|
||||||
\ingroup projet
|
\ingroup projet
|
||||||
\brief Fichier de la classe de gestion des projets
|
\brief Fichier de la classe de gestion des projets
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
\class Project
|
\class Project
|
||||||
\brief Classe permettant la gestion des projets
|
\brief Classe permettant la gestion des projets
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Project {
|
class Project {
|
||||||
var $id;
|
var $id;
|
||||||
var $db;
|
var $db;
|
||||||
var $ref;
|
var $ref;
|
||||||
var $title;
|
var $title;
|
||||||
var $socidp;
|
var $socidp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructeur de la classe
|
* \brief Constructeur de la classe
|
||||||
* \param DB handler accès base de données
|
* \param DB handler accès base de données
|
||||||
*/
|
*/
|
||||||
function Project($DB)
|
function Project($DB)
|
||||||
{
|
{
|
||||||
$this->db = $DB;
|
$this->db = $DB;
|
||||||
$this->societe = new Societe($DB);
|
$this->societe = new Societe($DB);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* \brief Crée un projet en base
|
* \brief Crée un projet en base
|
||||||
* \param user id utilisateur qui crée
|
* \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))
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
|
||||||
|
$sql .= " VALUES ('$this->ref', '$this->title', $this->socidp, ".$user->id.",now()) ;";
|
||||||
|
|
||||||
function create($user)
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
if (strlen(trim($this->ref)) > 0)
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
|
||||||
{
|
$result = $this->id;
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
|
}
|
||||||
$sql .= " VALUES ('$this->ref', '$this->title', $this->socidp, ".$user->id.",now()) ;";
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog("Project::Create error -2");
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
$result = -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog("Project::Create error -1 ref null");
|
||||||
|
$result = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
return $result;
|
||||||
{
|
}
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_syslog($this->db->error());
|
|
||||||
$result = -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_syslog("Project::Create ref null");
|
|
||||||
$result = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function update($user)
|
function update($user)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -38,15 +38,21 @@ if (!$user->rights->projet->lire) accessforbidden();
|
|||||||
|
|
||||||
if ($_POST["action"] == 'add' && $user->rights->projet->creer)
|
if ($_POST["action"] == 'add' && $user->rights->projet->creer)
|
||||||
{
|
{
|
||||||
$pro = new Project($db);
|
$pro = new Project($db);
|
||||||
$pro->socidp = $_GET["socidp"];
|
$pro->socidp = $_GET["socidp"];
|
||||||
$pro->ref = $_POST["ref"];
|
$pro->ref = $_POST["ref"];
|
||||||
$pro->title = $_POST["title"];
|
$pro->title = $_POST["title"];
|
||||||
$result = $pro->create($user);
|
$result = $pro->create($user);
|
||||||
|
|
||||||
if ($result == 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
Header("Location:fiche.php?id=".$pro->id);
|
Header("Location:fiche.php?id=".$pro->id);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$pro->error.'</div>';
|
||||||
|
$_GET["action"] = 'create';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +92,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user-
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
llxHeader("",$langs->trans("Project"),"Projet");
|
llxHeader("",$langs->trans("Project"),"Projet");
|
||||||
|
|
||||||
|
|
||||||
@ -93,6 +100,8 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
|
|||||||
{
|
{
|
||||||
print_titre($langs->trans("NewProject"));
|
print_titre($langs->trans("NewProject"));
|
||||||
|
|
||||||
|
if ($mesg) print $mesg;
|
||||||
|
|
||||||
print '<form action="fiche.php?socidp='.$_GET["socidp"].'" method="post">';
|
print '<form action="fiche.php?socidp='.$_GET["socidp"].'" method="post">';
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user