[task #218] [Hunt click] merge info tab in card

This commit is contained in:
Regis Houssin 2011-10-25 12:50:12 +02:00
parent 37cca4231a
commit 2f3aeefc4c
4 changed files with 235 additions and 400 deletions

View File

@ -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;
}
}

View File

@ -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 '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
print '<td valign="top" colspan="2">';
print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($objectsrc)) // Take value from source object
{
print $objectsrc->note;
print $objectsrc->note_private;
}
print '</textarea></td></tr>';
}
@ -244,198 +246,221 @@ if ($action == 'create')
print '</form>';
}
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 '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<table class="border" width="100%">';
// Ref
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $object->ref;
print '</td></tr>';
// Type
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0);
print '</td></tr>';
// Who
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0);
print '</td></tr>';
// Date
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
print $html->select_date($object->date,'','','','','update');
print '</td></tr>';
// Km
print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" class="flat" size="10" value="'.$object->km.'"></td></tr>';
// Where
print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
print $html->select_societes($soc->id,'socid','',1);
print '</td></tr>';
print '</table>';
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
print '</center>';
print '</form>';
print '</div>';
}
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 '<br>';
}
$soc = new Societe($db);
if ($object->socid) $soc->fetch($object->socid);
print '<table class="border" width="100%">';
// Ref
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($object,'id','',1,'rowid','ref','');
print '</td></tr>';
// Type
print '<tr><td>'.$langs->trans("Type").'</td><td>'.$langs->trans($object->type).'</td></tr>';
// Who
print '<tr><td>'.$langs->trans("Person").'</td><td>';
$userfee=new User($db);
$userfee->fetch($object->fk_user);
print $userfee->getNomUrl(1);
print '</td></tr>';
// Date
print '<tr><td>'.$langs->trans("Date").'</td><td>';
print dol_print_date($object->date,'day');
print '</td></tr>';
// Km/Price
print '<tr><td>'.$langs->trans("FeesKilometersOrAmout").'</td><td>'.$object->km.'</td></tr>';
// Where
print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
print '<td>';
if ($soc->id) print $soc->getNomUrl(1);
print '</td></tr>';
// Project
if ($conf->projet->enabled)
{
$langs->load('projects');
print '<tr>';
print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($_GET['action'] != 'classify')
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
print img_edit($langs->trans('SetProject'),1);
print '</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
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 '</td>';
print '</tr>';
}
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
print "</table>";
print '</div>';
$soc->fetch($object->socid);
}
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<table class="border" width="100%">';
// Ref
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $object->ref;
print '</td></tr>';
// Type
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0);
print '</td></tr>';
// Who
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0);
print '</td></tr>';
// Date
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
print $html->select_date($object->date,'','','','','update');
print '</td></tr>';
// Km
print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td>';
print '<input name="km" class="flat" size="10" value="'.$object->km.'">';
print '</td></tr>';
// Where
print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
print $html->select_societes($soc->id,'socid','',1);
print '</td></tr>';
// Public note
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="3">';
print '<textarea name="note_public" cols="80" rows="8">'.$object->note_public."</textarea><br>";
print "</td></tr>";
// Private note
if (! $user->societe_id)
{
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
print '<td valign="top" colspan="3">';
print '<textarea name="note_private" cols="80" rows="8">'.$object->note_private."</textarea><br>";
print "</td></tr>";
}
print '</table>';
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
print '</center>';
print '</form>';
print '</div>';
}
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 '<br>';
}
$soc = new Societe($db);
if ($object->socid) $soc->fetch($object->socid);
print '<table class="border" width="100%">';
// Ref
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($object,'id','',1,'rowid','ref','');
print '</td></tr>';
// Type
print '<tr><td>'.$langs->trans("Type").'</td><td>'.$langs->trans($object->type).'</td></tr>';
// Who
print '<tr><td>'.$langs->trans("Person").'</td><td>';
$userfee=new User($db);
$userfee->fetch($object->fk_user);
print $userfee->getNomUrl(1);
print '</td></tr>';
// Date
print '<tr><td>'.$langs->trans("Date").'</td><td>';
print dol_print_date($object->date,'day');
print '</td></tr>';
// Km/Price
print '<tr><td>'.$langs->trans("FeesKilometersOrAmout").'</td><td>'.$object->km.'</td></tr>';
// Where
print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
print '<td>';
if ($soc->id) print $soc->getNomUrl(1);
print '</td></tr>';
// Project
if ($conf->projet->enabled)
{
$langs->load('projects');
print '<tr>';
print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($action != 'classify')
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
print img_edit($langs->trans('SetProject'),1);
print '</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
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 '</td>';
print '</tr>';
}
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
// Public note
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="3">';
print ($object->note_public ? nl2br($object->note_public) : "&nbsp;");
print "</td></tr>";
// Private note
if (! $user->societe_id)
{
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
print '<td valign="top" colspan="3">';
print ($object->note_private ? nl2br($object->note_private) : "&nbsp;");
print "</td></tr>";
}
print "</table>";
print '</div>';
/*
* Barre d'actions
*/
print '<div class="tabsAction">';
if ($user->rights->deplacement->creer)
{
print '<a class="butAction" href="fiche.php?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
}
if ($user->rights->deplacement->supprimer)
{
print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$id.'">'.$langs->trans('Delete').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
}
print '</div>';
}
}
}
/*
* Barre d'actions
*
*/
print '<div class="tabsAction">';
if ($action != 'create' && $action != 'edit')
{
if ($user->rights->deplacement->creer)
{
print '<a class="butAction" href="fiche.php?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
}
if ($user->rights->deplacement->supprimer)
{
print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$id.'">'.$langs->trans('Delete').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
dol_print_error($db);
}
}
print '</div>';
$db->close();
llxFooter();

View File

@ -1,191 +0,0 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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='<div class="error">'.$object->error.'</div>';
$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='<div class="error">'.$object->error.'</div>';
$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 '<table class="border" width="100%">';
// Ref
print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
print '<td colspan="3">';
$morehtmlref='';
print $html->showrefnav($object,'ref','',1,'ref','ref',$morehtmlref);
print '</td></tr>';
// Type
print '<tr><td>'.$langs->trans("Type").'</td><td>'.$langs->trans($object->type).'</td></tr>';
// Who
print "<tr>";
print '<td>'.$langs->trans("Person").'</td><td>';
$userfee=new User($db);
$userfee->fetch($object->fk_user);
print $userfee->getNomUrl(1);
print '</td></tr>';
print '<tr><td width="20%">'.$langs->trans("CompanyVisited").'</td>';
print '<td>';
if ($soc->id) print $soc->getNomUrl(1);
print '</td></tr>';
// Note publique
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="3">';
if ($action == 'edit')
{
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update_public">';
print '<textarea name="note_public" cols="80" rows="8">'.$object->note_public."</textarea><br>";
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '</form>';
}
else
{
print ($object->note_public?nl2br($object->note_public):"&nbsp;");
}
print "</td></tr>";
// Note privee
if (! $user->societe_id)
{
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
print '<td valign="top" colspan="3">';
if ($action == 'edit')
{
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<textarea name="note" cols="80" rows="8">'.$object->note."</textarea><br>";
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '</form>';
}
else
{
print ($object->note?nl2br($object->note):"&nbsp;");
}
print "</td></tr>";
}
print "</table>";
/*
* Actions
*/
print '</div>';
print '<div class="tabsAction">';
if ($action <> 'edit' && $user->rights->deplacement->creer)
{
print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id .'&amp;action=edit">' . $langs->trans('Modify') . '</a>';
}
print "</div>";
}
$db->close();
llxFooter();
?>

View File

@ -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