Nouveau fichier

This commit is contained in:
Rodolphe Quiedeville 2003-09-02 17:41:30 +00:00
parent 21c4bcd97a
commit d84623dc6a
3 changed files with 421 additions and 0 deletions

View File

@ -0,0 +1,128 @@
<?PHP
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
class Deplacement
{
var $db;
var $id;
var $user;
var $km;
var $note;
/*
* Initialistation automatique de la classe
*/
Function Deplacement($DB)
{
$this->db = $DB;
return 1;
}
/*
*
*/
Function create($user)
{
$sql = "INSERT INTO llx_deplacement (datec, fk_user_author) VALUES (now(), $user->id)";
$result = $this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id();
if ( $this->update($user) )
{
return $this->id;
}
}
}
/*
*
*/
Function update($user)
{
if (strlen($this->km)==0)
$this->km = 0;
$sql = "UPDATE llx_deplacement ";
$sql .= " SET km = $this->km";
$sql .= " , dated = '".$this->db->idate($this->date)."'";
$sql .= " , fk_user = $this->userid";
$sql .= " , fk_soc = $this->socid";
$sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
print $this->db->error();
print "<br>".$sql;
return 0;
}
}
/*
*
*/
Function fetch ($id)
{
$sql = "SELECT rowid, fk_user, km, fk_soc,".$this->db->pdate("dated")." as dated";
$sql .= " FROM llx_deplacement WHERE rowid = $id";
$result = $this->db->query($sql) ;
if ( $result )
{
$result = $this->db->fetch_array();
$this->id = $result["rowid"];
$this->date = $result["dated"];
$this->userid = $result["fk_user"];
$this->socid = $result["fk_soc"];
$this->km = $result["km"];
return 1;
}
}
/*
*
*/
Function delete()
{
$sql = "DELETE FROM llx_deplacement WHERE rowid = $this->id)";
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
return 0;
}
}
/*
*
*/
}
?>

View File

@ -0,0 +1,186 @@
<?PHP
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require("./pre.inc.php");
$mesg = '';
if ($HTTP_POST_VARS["action"] == 'add' && $HTTP_POST_VARS["cancel"] <> 'Annuler')
{
$deplacement = new Deplacement($db);
$deplacement->date = mktime(12, 1 , 1,
$HTTP_POST_VARS["remonth"],
$HTTP_POST_VARS["reday"],
$HTTP_POST_VARS["reyear"]);
$deplacement->km = $HTTP_POST_VARS["km"];
$deplacement->socid = $HTTP_POST_VARS["socid"];
$deplacement->userid = $user->id; //$HTTP_POST_VARS["km"];
$id = $deplacement->create($user);
if ($id > 0)
{
Header ( "Location: fiche.php?id=$id");
}
else
{
print "Error";
}
}
if ($HTTP_POST_VARS["action"] == 'update' && $HTTP_POST_VARS["cancel"] <> 'Annuler')
{
$deplacement = new Deplacement($db);
$result = $deplacement->fetch($id);
$deplacement->date = mktime(12, 1 , 1,
$HTTP_POST_VARS["remonth"],
$HTTP_POST_VARS["reday"],
$HTTP_POST_VARS["reyear"]);
$deplacement->km = $HTTP_POST_VARS["km"];
$result = $deplacement->update($user);
if ($result > 0)
{
Header ( "Location: fiche.php?id=$id");
}
else
{
print "Error";
}
}
llxHeader();
/*
*
*
*/
$html = new Form($db);
if ($action == 'create')
{
print "<form action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="socid" value="'.$socid.'">';
print '<div class="titre">Nouveau déplacement</div><br>';
print '<table border="1" width="100%" cellspacing="0" cellpadding="4">';
print '<tr><td width="20%">Personne</td><td>'.$user->fullname.'</td></tr>';
print "<tr>";
print '<td>Date du déplacement</td><td>';
print $html->select_date();
print '</td></tr>';
print '<tr><td>Kilomètres</td><TD><input name="km" size="10" value=""></td></tr>';
print '<tr><td>&nbsp;</td><td><input type="submit" value="Enregistrer">&nbsp;';
print '<input type="submit" name="cancel" value="Annuler"></td></tr>';
print '</table>';
print '</form>';
}
else
{
if ($id)
{
$deplacement = new Deplacement($db);
$result = $deplacement->fetch($id);
if ( $result )
{
if ($action == 'edit')
{
print_fiche_titre('Fiche déplacement : '.$product->ref, $mesg);
print "<form action=\"$PHP_SELF?id=$id\" method=\"post\">\n";
print '<input type="hidden" name="action" value="update">';
print '<table border="1" width="100%" cellspacing="0" cellpadding="4">';
$soc = new Societe($db);
$soc->fetch($deplacement->socid);
print '<tr><td width="20%">Personne</td><td>'.$user->fullname.'</td></tr>';
print '<tr><td width="20%">Société visitée</td><td>'.$soc->nom_url.'</td></tr>';
print '<tr><td>Date du déplacement</td><td>';
print $html->select_date($deplacement->date);
print strftime("%A %d %B %Y",$deplacement->date);
print '</td></tr>';
print '<tr><td>Kilomètres</td><td><input name="km" size="10" value="'.$deplacement->km.'"> '.$deplacement->km.'</td></tr>';
print '<tr><td>&nbsp;</td><td><input type="submit" value="Enregistrer">&nbsp;';
print '<input type="submit" name="cancel" value="Annuler"></td></tr>';
print '</table>';
print '</form>';
}
else
{
print_fiche_titre('Fiche déplacement : '.$product->ref, $mesg);
print '<table border="1" width="100%" cellspacing="0" cellpadding="4">';
$soc = new Societe($db);
$soc->fetch($deplacement->socid);
print '<tr><td width="20%">Personne</td><td>'.$user->fullname.'</td></tr>';
print '<tr><td width="20%">Société visitée</td><td>'.$soc->nom_url.'</td></tr>';
print '<tr><td>Date du déplacement</td><td>';
print strftime("%A %d %B %Y",$deplacement->date);
print '</td></tr>';
print '<tr><td>Kilomètres</td><td>'.$deplacement->km.'</td></tr>';
print "</table>";
}
}
else
{
print "Error";
}
}
}
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print '<br><table width="100%" border="1" cellspacing="0" cellpadding="3">';
print '<td width="20%" align="center">-</td>';
print '<td width="20%" align="center">-</td>';
print '<td width="20%" align="center">-</td>';
if ($action == 'create')
{
print '<td width="20%" align="center">-</td>';
}
else
{
print '<td width="20%" align="center">[<a href="fiche.php?action=edit&id='.$id.'">Editer</a>]</td>';
}
print '<td width="20%" align="center">-</td>';
print '</table><br>';
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>

View File

@ -0,0 +1,107 @@
<?PHP
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require("./pre.inc.php");
require("../../tva.class.php3");
/*
*
*
*/
/*
*
*/
llxHeader();
/*
* Liste
*
*/
if ($sortorder == "")
{
$sortorder="DESC";
}
if ($sortfield == "")
{
$sortfield="d.dated";
}
if ($page == -1) { $page = 0 ; }
$limit = $conf->liste_limit;
$offset = $limit * $page ;
$pageprev = $page - 1;
$pagenext = $page + 1;
$sql = "SELECT s.nom,s.idp, d.km,".$db->pdate("d.dated")." as dd, u.name, u.firstname, d.rowid";
$sql .= " FROM llx_societe as s, llx_deplacement as d, llx_user as u ";
$sql .= " WHERE d.fk_soc = s.idp AND d.fk_user = u.rowid";
if ($user->societe_id > 0)
{
$sql .= " AND s.idp = " . $user->societe_id;
}
$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit + 1 ,$offset);
if ( $db->query($sql) )
{
$num = $db->num_rows();
print_barre_liste("Liste des déplacements", $page, $PHP_SELF,"&socidp=$socidp",$sortfield,$sortorder,'',$num);
$i = 0;
print '<TABLE border="0" width="100%" cellspacing="0" cellpadding="4">';
print "<TR class=\"liste_titre\">";
print_liste_field_titre_new ("Date",$PHP_SELF,"d.dated","","&socidp=$socidp",'',$sortfield);
print_liste_field_titre_new ("Société",$PHP_SELF,"s.nom","","&socidp=$socidp",'',$sortfield);
print '<TD align="center">Utilisateur</TD>';
print "</TR>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print '<td><a href="fiche.php?id='.$objp->rowid.'">'.strftime("%d %B %Y",$objp->dd).'</a></td>';
print "<TD><a href=\"../comm/fiche.php3?socid=$objp->idp\">$objp->nom</a></TD>\n";
print '<TD align="center">'.$objp->firstname.' '.$objp->name.'</td>';
print "</TR>\n";
$i++;
}
print "</TABLE>";
$db->free();
}
else
{
print $db->error();
print "<p>$sql";
}
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>