From 686ee76b1c07164354752d7ac0682805b407c8d7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Sep 2007 01:47:43 +0000 Subject: [PATCH] =?UTF-8?q?Am=E9lioration=20gestion=20erreur=20pour=20faci?= =?UTF-8?q?liter=20debuggage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/fichinter/fiche.php | 36 +++++---- htdocs/fichinter/fichinter.class.php | 117 ++++++++++++++------------- 2 files changed, 83 insertions(+), 70 deletions(-) diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index e039ec11145..a08dfafc53a 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -35,7 +35,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/fichinter.lib.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/project.class.php"); if (defined("FICHEINTER_ADDON") && is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/".FICHEINTER_ADDON.".php")) { - require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/".FICHEINTER_ADDON.".php"); + require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/".FICHEINTER_ADDON.".php"); } $langs->load("companies"); @@ -75,7 +75,7 @@ if ($_POST["action"] == 'add') { $fichinter = new Fichinter($db); - $fichinter->date = $db->idate(dolibarr_mktime(12, 1 , 1, $_POST["pmonth"], $_POST["pday"], $_POST["pyear"])); + $fichinter->date = dolibarr_mktime(12, 0 , 0, $_POST["pmonth"], $_POST["pday"], $_POST["pyear"]); $fichinter->socid = $_POST["socid"]; $fichinter->duree = $_POST["duree"]; $fichinter->projet_id = $_POST["projetidp"]; @@ -84,16 +84,24 @@ if ($_POST["action"] == 'add') $fichinter->ref = $_POST["ref"]; $fichinter->modelpdf = $_POST["model"]; - $result = $fichinter->create(); - - if ($result > 0) + if ($fichinter->socid > 0) { - $_GET["id"]=$result; // Force raffraichissement sur fiche venant d'etre créée - $fichinterid=$result; + $result = $fichinter->create(); + if ($result > 0) + { + $_GET["id"]=$result; // Force raffraichissement sur fiche venant d'etre créée + $fichinterid=$result; + } + else + { + $mesg='
'.$fichinter->error.'
'; + $_GET["action"] = 'create'; + } } else { - $mesg='
'.$fichinter->error.'
'; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'
'; + $_GET["action"] = 'create'; } } @@ -225,7 +233,6 @@ if ($_POST['action'] == 'updateligne' && $user->rights->ficheinter->creer && $_P fichinter_pdf_create($db, $fichinter->id, $fichinter->modelpdf, $outputlangs); } - /* * Supprime une ligne d'intervention SANS confirmation */ @@ -310,14 +317,15 @@ if ($_GET["action"] == 'create') * Mode creation * Creation d'une nouvelle fiche d'intervention */ - - if ($_GET["socid"]) + if ($_GET["socid"] > 0) { $societe=new Societe($db); - $societe->fetch($_GET["socid"]); + $societe->fetch($_GET["socid"]); } print_titre($langs->trans("AddIntervention")); + + if ($mesg) print $mesg.'
'; if (! $conf->global->FICHEINTER_ADDON) { @@ -336,8 +344,6 @@ if ($_GET["action"] == 'create') print "
"; - $smonth = 1; - $syear = date("Y", time()); print ''; if ($_GET["socid"]) @@ -411,7 +417,7 @@ if ($_GET["action"] == 'create') } else { - print ''; + print ''; } print ''; diff --git a/htdocs/fichinter/fichinter.class.php b/htdocs/fichinter/fichinter.class.php index 58733599f76..4c109233fe8 100644 --- a/htdocs/fichinter/fichinter.class.php +++ b/htdocs/fichinter/fichinter.class.php @@ -78,52 +78,54 @@ class Fichinter extends CommonObject /* - * \brief Crée une fiche intervention en base - * + * \brief Crée une fiche intervention en base + * \return int <0 if KO, >0 if OK */ function create() - { - if (! is_numeric($this->duree)) { $this->duree = 0; } + { + dolibarr_syslog("Fichinter.class::create ref=".$this->ref); - // on vérifie si la ref n'est pas utilisée - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $this->verifyNumRef($soc); - - dolibarr_syslog("Fichinter.class::create ref=".$this->ref); - - $this->db->begin(); + if (! is_numeric($this->duree)) { $this->duree = 0; } + if ($this->socid <= 0) + { + $this->error='ErrorBadParameterForFunc'; + dolibarr_syslog("Fichinter::create ".$this->error,LOG_ERR); + return -1; + } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (fk_soc, datei, datec, ref, fk_user_author, description, model_pdf"; - if ($this->projet_id) { - $sql .= ", fk_projet"; - } - $sql .= ") "; - $sql .= " VALUES (".$this->socid.", ".$this->date.", now(), '".$this->ref."', ".$this->author; - $sql .= ", '".addslashes($this->description)."', '".$this->modelpdf."'"; - if ($this->projet_id) { - $sql .= ", ".$this->projet_id; - } - $sql .= ")"; - $sqlok = 0; + $this->db->begin(); - dolibarr_syslog("Fichinter::create sql=".$sql); - $result=$this->db->query($sql); - if ($result) - { - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); - $this->db->commit(); - return $this->id; - } - else - { - $this->error=$this->db->error(); - dolibarr_syslog("Fichinter::create ".$this->error); - $this->db->rollback(); - return -1; - } + // on vérifie si la ref n'est pas utilisée + $soc = new Societe($this->db); + $result=$soc->fetch($this->socid); + $this->verifyNumRef($soc); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (fk_soc, datei, datec, ref, fk_user_author, description, model_pdf"; + if ($this->projet_id) $sql .= ", fk_projet"; + $sql .= ") "; + $sql .= " VALUES (".$this->socid.", ".$this->date.", now(), '".$this->ref."', ".$this->author; + $sql .= ", '".addslashes($this->description)."', '".$this->modelpdf."'"; + if ($this->projet_id) $sql .= ", ".$this->projet_id; + $sql .= ")"; + $sqlok = 0; - } + dolibarr_syslog("Fichinter::create sql=".$sql); + $result=$this->db->query($sql); + if ($result) + { + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Fichinter::create ".$this->error,LOG_ERR); + $this->db->rollback(); + return -1; + } + + } /* * \brief Met a jour une intervention @@ -145,11 +147,13 @@ class Fichinter extends CommonObject $sql .= ", description = '".addslashes($this->description)."'"; $sql .= ", duree = ".$this->duree; $sql .= ", fk_projet = ".$this->projet_id; - $sql .= " WHERE rowid = $id"; + $sql .= " WHERE rowid = ".$id; - if (! $this->db->query($sql) ) + dolibarr_syslog("Fichinter::update sql=".$sql); + if (! $this->db->query($sql)) { - $this->error=$this->db->error().' sql='.$sql; + $this->error=$this->db->error(); + dolibarr_syslog("Fichinter::update error ".$this->error,LOG_ERR); return -1; } @@ -168,8 +172,7 @@ class Fichinter extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."fichinter"; $sql.= " WHERE rowid=".$rowid; - dolibarr_syslog("Fichinter.class::fetch rowid=$rowid sql=$sql"); - + dolibarr_syslog("Fichinter::fetch sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -196,7 +199,8 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error().' sql='.$sql; + $this->error=$this->db->error(); + dolibarr_syslog("Fichinter::update error ".$this->error,LOG_ERR); return -1; } } @@ -211,6 +215,8 @@ class Fichinter extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; $sql.= " SET fk_statut = 1, date_valid=now(), fk_user_valid=".$user->id; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + dolibarr_syslog("Fichinter::valid sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -224,7 +230,8 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error().' sql='.$sql; + $this->error=$this->db->error(); + dolibarr_syslog("Fichinter::update error ".$this->error,LOG_ERR); return -1; } } @@ -377,7 +384,7 @@ class Fichinter extends CommonObject $sql.= " SET ".$type." = '".addslashes($note)."'"; $sql.= " WHERE rowid =". $this->id; - dolibarr_syslog("Fichinter.class::update_note type=".$type." sql=".$sql); + dolibarr_syslog("Fichinter::update_note type=".$type." sql=".$sql); if ($this->db->query($sql)) { @@ -460,7 +467,7 @@ class Fichinter extends CommonObject else { - dolibarr_syslog("Fichinter.class::set_project Erreur SQL"); + dolibarr_syslog("Fichinter::set_project Erreur SQL"); } } } @@ -542,7 +549,7 @@ class Fichinter extends CommonObject else { $this->error=$this->db->error(); - dolibarr_syslog("Fichinter.class::set_date_delivery Erreur SQL"); + dolibarr_syslog("Fichinter::set_date_delivery Erreur SQL"); return -1; } } @@ -570,7 +577,7 @@ class Fichinter extends CommonObject else { $this->error=$this->db->error(); - dolibarr_syslog("Fichinter.class::set_description Erreur SQL"); + dolibarr_syslog("Fichinter::set_description Erreur SQL"); return -1; } } @@ -650,13 +657,13 @@ class Fichinter extends CommonObject { $this->error=$this->db->error(); $this->db->rollback(); - dolibarr_syslog("Fichinter.class::UpdateLine Erreur sql=$sql, error=".$this->error); + dolibarr_syslog("Fichinter::UpdateLine Erreur sql=$sql, error=".$this->error); return -1; } } else { - dolibarr_syslog("Fichinter.class::UpdateLigne Erreur -2 Fiche intervention en mode incompatible pour cette action"); + dolibarr_syslog("Fichinter::UpdateLigne Erreur -2 Fiche intervention en mode incompatible pour cette action"); return -2; } } @@ -953,7 +960,7 @@ class FichinterLigne */ function insert() { - dolibarr_syslog("FichinterLigne.class::insert rang=".$this->rang); + dolibarr_syslog("FichinterLigne::insert rang=".$this->rang); $this->db->begin(); $rangToUse=$this->rang; @@ -1021,7 +1028,7 @@ class FichinterLigne $sql.= ",rang='".$this->rang."'"; $sql.= " WHERE rowid = ".$this->rowid; - dolibarr_syslog("FichinterLigne::update sql=$sql"); + dolibarr_syslog("FichinterLigne::update sql=".$sql); $resql=$this->db->query($sql); if ($resql)