From 5899fa6eb7896f42369139f89bdf148c61d21395 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Oct 2011 16:04:50 +0200 Subject: [PATCH] Fix: add note public and private during create --- htdocs/fichinter/class/fichinter.class.php | 44 ++++++++++++---------- htdocs/fichinter/fiche.php | 31 +++++++++++---- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 1a3afead912..61b1776a279 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -87,14 +87,14 @@ class Fichinter extends CommonObject { global $conf; - dol_syslog("Fichinter.class::create ref=".$this->ref); + dol_syslog(get_class($this)."::create ref=".$this->ref); // Check parameters if (! is_numeric($this->duree)) { $this->duree = 0; } if ($this->socid <= 0) { $this->error='ErrorBadParameterForFunc'; - dol_syslog("Fichinter::create ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::create ".$this->error,LOG_ERR); return -1; } // on verifie si la ref n'est pas utilisee @@ -106,14 +106,14 @@ class Fichinter extends CommonObject if ($result > 0) { $this->error='ErrorRefAlreadyExists'; - dol_syslog("Fichinter::create ".$this->error,LOG_WARNING); + dol_syslog(get_class($this)."::create ".$this->error,LOG_WARNING); $this->db->rollback(); return -3; } else if ($result < 0) { $this->error=$this->db->error(); - dol_syslog("Fichinter::create ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::create ".$this->error,LOG_ERR); $this->db->rollback(); return -2; } @@ -133,6 +133,8 @@ class Fichinter extends CommonObject $sql.= ", model_pdf"; $sql.= ", fk_projet"; $sql.= ", fk_statut"; + $sql.= ", note_private"; + $sql.= ", note_public"; $sql.= ") "; $sql.= " VALUES ("; $sql.= $this->socid; @@ -144,9 +146,11 @@ class Fichinter extends CommonObject $sql.= ", '".$this->modelpdf."'"; $sql.= ", ".($this->fk_project ? $this->fk_project : 0); $sql.= ", ".$this->statut; + $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); + $sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); $sql.= ")"; - dol_syslog("Fichinter::create sql=".$sql); + dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); $result=$this->db->query($sql); if ($result) { @@ -157,7 +161,7 @@ class Fichinter extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Fichinter::create ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } @@ -170,30 +174,32 @@ class Fichinter extends CommonObject */ function update($user) { - global $conf; - if (! is_numeric($this->duree)) { $this->duree = 0; } if (! dol_strlen($this->fk_project)) { $this->fk_project = 0; } - /* - * Insertion dans la base - */ + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; $sql.= ", description = '".$this->db->escape($this->description)."'"; $sql.= ", duree = ".$this->duree; $sql.= ", fk_projet = ".$this->fk_project; + $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); + $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - dol_syslog("Fichinter::update sql=".$sql); - if (! $this->db->query($sql)) + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + $this->db->commit(); + return 1; + } + else { $this->error=$this->db->error(); - dol_syslog("Fichinter::update error ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::update error ".$this->error, LOG_ERR); + $this->db->rollback(); return -1; } - - return 1; } /** @@ -213,7 +219,7 @@ class Fichinter extends CommonObject if ($ref) $sql.= " WHERE f.ref='".$ref."'"; else $sql.= " WHERE f.rowid=".$rowid; - dol_syslog("Fichinter::fetch sql=".$sql); + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -252,7 +258,7 @@ class Fichinter extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Fichinter::fetch ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::fetch ".$this->error,LOG_ERR); return -1; } } diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index a41ee9fc1f9..e2632b4302c 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -118,8 +118,6 @@ if ($action == 'confirm_modify' && $confirm == 'yes') if ($action == 'add') { - $object = new Fichinter($db); - $object->socid = $socid; $object->duree = $_POST["duree"]; $object->fk_project = $_POST["projectid"]; @@ -127,6 +125,8 @@ if ($action == 'add') $object->description = $_POST["description"]; $object->ref = $ref; $object->modelpdf = $_POST["model"]; + $object->note_private = $_POST["note_private"]; + $object->note_public = $_POST["note_public"]; if ($object->socid > 0) { @@ -668,6 +668,12 @@ if ($action == 'create') // Ref print ''.$langs->trans("Ref").''; print ''."\n"; + + // Description (must be a textarea and not html must be allowed (used in list view) + print ''.$langs->trans("Description").''; + print ''; + print ''; + print ''; // Project if ($conf->projet->enabled) @@ -690,12 +696,23 @@ if ($action == 'create') $liste=ModelePDFFicheinter::liste_modeles($db); print $html->selectarray('model',$liste,$conf->global->FICHEINTER_ADDON_PDF); print ""; - - // Description (must be a textarea and not html must be allowed (used in list view) - print ''.$langs->trans("Description").''; - print ''; - print ''; + + // Public note + print ''; + print ''.$langs->trans('NotePublic').''; + print ''; + print ''; print ''; + + // Private note + if (! $user->societe_id) + { + print ''; + print ''.$langs->trans('NotePrivate').''; + print ''; + print ''; + print ''; + } print '';