diff --git a/htdocs/compta/deplacement/class/deplacement.class.php b/htdocs/compta/deplacement/class/deplacement.class.php
index 1060a853a9f..eb5551e2a82 100644
--- a/htdocs/compta/deplacement/class/deplacement.class.php
+++ b/htdocs/compta/deplacement/class/deplacement.class.php
@@ -44,7 +44,8 @@ class Deplacement extends CommonObject
var $fk_user_author;
var $fk_user;
var $km;
- var $note;
+ var $note; // TODO obsolete
+ var $note_private;
var $note_public;
var $socid;
var $statut; // 0=draft, 1=validated
@@ -55,7 +56,7 @@ class Deplacement extends CommonObject
*
* @param DoliDB $db Database handler
*/
- function Deplacement($db)
+ function __construct($db)
{
$this->db = $db;
@@ -106,13 +107,13 @@ class Deplacement extends CommonObject
$sql.= ", ".$user->id;
$sql.= ", ".$this->fk_user;
$sql.= ", '".$this->type."'";
- $sql.= ", ".($this->note?"'".$this->db->escape($this->note)."'":"null");
+ $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
$sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
$sql.= ", ".($this->fk_project > 0? $this->fk_project : 0);
$sql.= ", ".($this->fk_soc > 0? $this->fk_soc : "null");
$sql.= ")";
- dol_syslog("Deplacement::create sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
@@ -125,6 +126,7 @@ class Deplacement extends CommonObject
}
else
{
+ $this->error=$this->db->error();
$this->db->rollback();
return $result;
}
@@ -178,12 +180,12 @@ class Deplacement extends CommonObject
$sql .= " , fk_user = ".$this->fk_user;
$sql .= " , fk_user_modif = ".$user->id;
$sql .= " , fk_soc = ".($this->socid > 0?$this->socid:'null');
- $sql .= " , note = ".($this->note?"'".$this->db->escape($this->note)."'":"null");
+ $sql .= " , note = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
$sql .= " , note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
$sql .= " , fk_projet = ".($this->fk_project>0?$this->fk_project:0);
$sql .= " WHERE rowid = ".$this->id;
- dol_syslog("Deplacement::update sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
@@ -192,8 +194,8 @@ class Deplacement extends CommonObject
}
else
{
- $this->db->rollback();
$this->error=$this->db->lasterror();
+ $this->db->rollback();
return -1;
}
}
@@ -210,23 +212,23 @@ class Deplacement extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."deplacement";
$sql.= " WHERE rowid = ".$id;
- dol_syslog("Deplacement::fetch sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ( $result )
{
$obj = $this->db->fetch_object($result);
- $this->id = $obj->rowid;
- $this->ref = $obj->rowid;
- $this->date = $this->db->jdate($obj->dated);
- $this->fk_user = $obj->fk_user;
- $this->socid = $obj->fk_soc;
- $this->km = $obj->km;
- $this->type = $obj->type;
- $this->fk_statut = $obj->fk_statut;
- $this->note = $obj->note;
- $this->note_public = $obj->note_public;
- $this->fk_project = $obj->fk_projet;
+ $this->id = $obj->rowid;
+ $this->ref = $obj->rowid;
+ $this->date = $this->db->jdate($obj->dated);
+ $this->fk_user = $obj->fk_user;
+ $this->socid = $obj->fk_soc;
+ $this->km = $obj->km;
+ $this->type = $obj->type;
+ $this->fk_statut = $obj->fk_statut;
+ $this->note_private = $obj->note;
+ $this->note_public = $obj->note_public;
+ $this->fk_project = $obj->fk_projet;
return 1;
}
@@ -245,17 +247,21 @@ class Deplacement extends CommonObject
*/
function delete($id)
{
+ $this->db->begin();
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = ".$id;
- dol_syslog("Deplacement::delete sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
+ $this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
+ $this->db->rollback();
return -1;
}
}
diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php
index 9142f3dc28e..fe0a2b6382a 100644
--- a/htdocs/compta/deplacement/fiche.php
+++ b/htdocs/compta/deplacement/fiche.php
@@ -75,7 +75,7 @@ if ($action == 'add' && $user->rights->deplacement->creer)
$object->type = $_POST["type"];
$object->socid = $_POST["socid"];
$object->fk_user = $_POST["fk_user"];
- $object->note = $_POST["note"];
+ $object->note_private = $_POST["note_private"];
$object->note_public = $_POST["note_public"];
if (! $object->date)
@@ -127,11 +127,13 @@ if ($action == 'update' && $user->rights->deplacement->creer)
{
$result = $object->fetch($id);
- $object->date = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
- $object->km = $_POST["km"];
- $object->type = $_POST["type"];
- $object->fk_user = $_POST["fk_user"];
- $object->socid = $_POST["socid"];
+ $object->date = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
+ $object->km = $_POST["km"];
+ $object->type = $_POST["type"];
+ $object->fk_user = $_POST["fk_user"];
+ $object->socid = $_POST["socid"];
+ $object->note_private = $_POST["note_private"];
+ $object->note_public = $_POST["note_public"];
$result = $object->update($user);
@@ -229,10 +231,10 @@ if ($action == 'create')
print '
';
print ''.$langs->trans('NotePrivate').' ';
print '';
- print ' ';
}
@@ -244,198 +246,221 @@ if ($action == 'create')
print '';
}
-else
+else if ($id)
{
- if ($id)
+ $result = $object->fetch($id);
+ if ($result > 0)
{
- $result = $object->fetch($id);
- if ($result > 0)
+ dol_htmloutput_mesg($mesg);
+
+ $head = trip_prepare_head($object);
+
+ dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
+
+ if ($action == 'edit')
{
- dol_htmloutput_mesg($mesg);
-
- $head = trip_prepare_head($object);
-
- dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
-
- if ($_GET["action"] == 'edit')
+ $soc = new Societe($db);
+ if ($object->socid)
{
- $soc = new Societe($db);
- if ($object->socid)
- {
- $soc->fetch($object->socid);
- }
-
- print '' . "\n";
- print ' ';
- print ' ';
- print ' ';
-
- print '';
-
- // Ref
- print "";
- print ''.$langs->trans("Ref").' ';
- print $object->ref;
- print ' ';
-
- // Type
- print "";
- print ''.$langs->trans("Type").' ';
- print $html->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0);
- print ' ';
-
- // Who
- print "";
- print ''.$langs->trans("Person").' ';
- print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0);
- print ' ';
-
- // Date
- print ''.$langs->trans("Date").' ';
- print $html->select_date($object->date,'','','','','update');
- print ' ';
-
- // Km
- print ''.$langs->trans("FeesKilometersOrAmout").' ';
-
- // Where
- print "";
- print ''.$langs->trans("CompanyVisited").' ';
- print $html->select_societes($soc->id,'socid','',1);
- print ' ';
-
- print '
';
-
- print ' ';
- print ' ';
- print ' ';
-
- print ' ';
-
- print '';
- }
- else
- {
- /*
- * Confirmation de la suppression du deplacement
- */
- if ($action == 'delete')
- {
- $ret=$html->form_confirm("fiche.php?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
- if ($ret == 'html') print ' ';
- }
-
- $soc = new Societe($db);
- if ($object->socid) $soc->fetch($object->socid);
-
- print '';
-
- // Ref
- print "";
- print ''.$langs->trans("Ref").' ';
- print $html->showrefnav($object,'id','',1,'rowid','ref','');
- print ' ';
-
- // Type
- print ''.$langs->trans("Type").' '.$langs->trans($object->type).' ';
-
- // Who
- print ''.$langs->trans("Person").' ';
- $userfee=new User($db);
- $userfee->fetch($object->fk_user);
- print $userfee->getNomUrl(1);
- print ' ';
-
- // Date
- print ''.$langs->trans("Date").' ';
- print dol_print_date($object->date,'day');
- print ' ';
-
- // Km/Price
- print ''.$langs->trans("FeesKilometersOrAmout").' '.$object->km.' ';
-
- // Where
- print ''.$langs->trans("CompanyVisited").' ';
- print '';
- if ($soc->id) print $soc->getNomUrl(1);
- print ' ';
-
- // Project
- if ($conf->projet->enabled)
- {
- $langs->load('projects');
- print '';
- print '';
-
- print '';
- print ' ';
- if ($_GET['action'] == 'classify')
- {
- $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid');
- }
- else
- {
- $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none');
- }
- print ' ';
- print ' ';
- }
-
- // Statut
- print ''.$langs->trans("Status").' '.$object->getLibStatut(4).' ';
-
- print "
";
-
- print '';
+ $soc->fetch($object->socid);
}
+ print '' . "\n";
+ print ' ';
+ print ' ';
+ print ' ';
+
+ print '';
+
+ // Ref
+ print "";
+ print ''.$langs->trans("Ref").' ';
+ print $object->ref;
+ print ' ';
+
+ // Type
+ print "";
+ print ''.$langs->trans("Type").' ';
+ print $html->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0);
+ print ' ';
+
+ // Who
+ print "";
+ print ''.$langs->trans("Person").' ';
+ print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0);
+ print ' ';
+
+ // Date
+ print ''.$langs->trans("Date").' ';
+ print $html->select_date($object->date,'','','','','update');
+ print ' ';
+
+ // Km
+ print ''.$langs->trans("FeesKilometersOrAmout").' ';
+ print ' ';
+ print ' ';
+
+ // Where
+ print "";
+ print ''.$langs->trans("CompanyVisited").' ';
+ print $html->select_societes($soc->id,'socid','',1);
+ print ' ';
+
+ // Public note
+ print ''.$langs->trans("NotePublic").' ';
+ print '';
+ print ''.$object->note_public." ";
+ print " ";
+
+ // Private note
+ if (! $user->societe_id)
+ {
+ print ''.$langs->trans("NotePrivate").' ';
+ print '';
+ print ''.$object->note_private." ";
+ print " ";
+ }
+
+ print '
';
+
+ print ' ';
+ print ' ';
+ print ' ';
+
+ print ' ';
+
+ print '';
}
else
{
- dol_print_error($db);
+ /*
+ * Confirmation de la suppression du deplacement
+ */
+ if ($action == 'delete')
+ {
+ $ret=$html->form_confirm("fiche.php?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
+ if ($ret == 'html') print ' ';
+ }
+
+ $soc = new Societe($db);
+ if ($object->socid) $soc->fetch($object->socid);
+
+ print '';
+
+ // Ref
+ print "";
+ print ''.$langs->trans("Ref").' ';
+ print $html->showrefnav($object,'id','',1,'rowid','ref','');
+ print ' ';
+
+ // Type
+ print ''.$langs->trans("Type").' '.$langs->trans($object->type).' ';
+
+ // Who
+ print ''.$langs->trans("Person").' ';
+ $userfee=new User($db);
+ $userfee->fetch($object->fk_user);
+ print $userfee->getNomUrl(1);
+ print ' ';
+
+ // Date
+ print ''.$langs->trans("Date").' ';
+ print dol_print_date($object->date,'day');
+ print ' ';
+
+ // Km/Price
+ print ''.$langs->trans("FeesKilometersOrAmout").' '.$object->km.' ';
+
+ // Where
+ print ''.$langs->trans("CompanyVisited").' ';
+ print '';
+ if ($soc->id) print $soc->getNomUrl(1);
+ print ' ';
+
+ // Project
+ if ($conf->projet->enabled)
+ {
+ $langs->load('projects');
+ print '';
+ print '';
+
+ print '';
+ print ' ';
+ if ($action == 'classify')
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid');
+ }
+ else
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none');
+ }
+ print ' ';
+ print ' ';
+ }
+
+ // Statut
+ print ''.$langs->trans("Status").' '.$object->getLibStatut(4).' ';
+
+ // Public note
+ print ''.$langs->trans("NotePublic").' ';
+ print '';
+ print ($object->note_public ? nl2br($object->note_public) : " ");
+ print " ";
+
+ // Private note
+ if (! $user->societe_id)
+ {
+ print ''.$langs->trans("NotePrivate").' ';
+ print '';
+ print ($object->note_private ? nl2br($object->note_private) : " ");
+ print " ";
+ }
+
+ print "
";
+
+ print '';
+
+ /*
+ * Barre d'actions
+ */
+
+ print '';
}
}
-}
-
-
-/*
- * Barre d'actions
- *
- */
-
-print '';
-
$db->close();
llxFooter();
diff --git a/htdocs/compta/deplacement/note.php b/htdocs/compta/deplacement/note.php
deleted file mode 100644
index d0a81e9e950..00000000000
--- a/htdocs/compta/deplacement/note.php
+++ /dev/null
@@ -1,191 +0,0 @@
-
- * Copyright (C) 2004-2011 Laurent Destailleur
- *
- * 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, see .
- */
-
-/**
- * \file htdocs/compta/deplacement/note.php
- * \ingroup trip
- * \brief Notes on a trip card
- */
-
-require("../../main.inc.php");
-require_once(DOL_DOCUMENT_ROOT."/core/lib/trip.lib.php");
-require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php");
-
-$langs->load("companies");
-$langs->load("trips");
-
-$id = GETPOST('id');
-$ref = GETPOST('ref');
-$action = GETPOST('action');
-$confirm = GETPOST('confirm');
-
-// Security check
-if ($user->societe_id) $socid=$user->societe_id;
-$result = restrictedArea($user, 'deplacement', $id, '');
-
-$object = new Deplacement($db);
-
-
-/******************************************************************************/
-/* Actions */
-/******************************************************************************/
-
-if ($action == 'update_public' && $user->rights->deplacement->creer)
-{
- $db->begin();
-
- $object->fetch($id);
-
- $res=$object->update_note_public($_POST["note_public"]);
- if ($res < 0)
- {
- $mesg=''.$object->error.'
';
- $db->rollback();
- }
- else
- {
- $db->commit();
- }
-}
-
-if ($action == 'update' && $user->rights->deplacement->creer)
-{
- $db->begin();
-
- $object->fetch($id);
-
- $res=$object->update_note($_POST["note"]);
- if ($res < 0)
- {
- $mesg=''.$object->error.'
';
- $db->rollback();
- }
- else
- {
- $db->commit();
- }
-}
-
-
-
-/******************************************************************************/
-/* Affichage fiche */
-/******************************************************************************/
-
-llxHeader();
-
-$html = new Form($db);
-
-if ($id > 0 || ! empty($ref))
-{
- $object->fetch($id, $ref);
-
- $soc = new Societe($db);
- $soc->fetch($object->socid);
-
- $head = trip_prepare_head($object);
-
- dol_fiche_head($head, 'note', $langs->trans("TripCard"), 0, 'trip');
-
- print '";
-
-
- /*
- * Actions
- */
- print '';
- print '";
-
-
-}
-
-$db->close();
-
-llxFooter();
-?>
diff --git a/htdocs/core/lib/trip.lib.php b/htdocs/core/lib/trip.lib.php
index d7918e98ea6..265d9e8df46 100644
--- a/htdocs/core/lib/trip.lib.php
+++ b/htdocs/core/lib/trip.lib.php
@@ -39,11 +39,6 @@ function trip_prepare_head($object)
$head[$h][2] = 'card';
$h++;
- $head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/note.php?id=' . $object->id;
- $head[$h][1] = $langs->trans("Note");
- $head[$h][2] = 'note';
- $h++;
-
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab