nouveaux fichiers

This commit is contained in:
Rodolphe Quiedeville 2003-03-12 19:08:19 +00:00
parent 19478d6545
commit 6b192a5d37
7 changed files with 590 additions and 0 deletions

View File

@ -0,0 +1,252 @@
<?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");
llxHeader();
$db = new Db();
if ($action == 'add') {
$livre = new Livre($db);
$livre->titre = $titre;
$livre->ref = $ref;
$livre->price = $price;
$livre->annee = $annee;
$livre->editeurid = $editeurid;
$livre->description = $desc;
$id = $livre->create($user);
}
if ($action == 'addga') {
$livre = new Livre($db);
$livre->linkga($id, $coauteurid);
}
if ($action == 'update' && !$cancel) {
$livre = new Livre($db);
$livre->titre = $titre;
$livre->ref = $ref;
$livre->price = $price;
$livre->annee = $annee;
$livre->editeurid = $editeurid;
$livre->description = $desc;
$livre->update($id, $user);
}
if ($action == 'updateosc') {
$livre = new Livre($db);
$result = $livre->fetch($id);
$livre->updateosc($user);
}
/*
*
*
*/
if ($action == 'create')
{
print "<form action=\"$PHP_SELF?id=$id\" method=\"post\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"add\">";
print '<div class="titre">Nouvel ouvrage</div><br>';
print '<table border="1" width="100%" cellspacing="0" cellpadding="4">';
print "<tr>";
print '<td>Référence</td><td><input name="ref" size="20" value=""></td></tr>';
print '<td>Titre</td><td><input name="titre" size="40" value=""></td></tr>';
print '<tr><td>Prix</td><TD><input name="price" size="10" value=""></td></tr>';
print "<tr><td valign=\"top\">Description</td><td>";
print '<textarea name="desc" rows="8" cols="50">';
print "</textarea></td></tr>";
print '<tr><td>&nbsp;</td><td><input type="submit" value="Créer"></td></tr>';
print '</table>';
print '</form>';
}
else
{
if ($id)
{
$livre = new Livre($db);
$result = $livre->fetch($id);
if ( $result )
{
$htmls = new Form($db);
$auteurs = $livre->liste_auteur();
if ($action == 'edit')
{
print '<div class="titre">Edition de la fiche Livre : '.$livre->titre.'</div><br>';
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">';
print "<tr>";
print '<td width="20%">Référence</td><td><input name="ref" size="20" value="'.$livre->ref.'"></td>';
print "<td valign=\"top\">Description</td></tr>";
print '<td>Titre</td><td><input name="titre" size="40" value="'.$livre->titre.'"></td>';
print '<td valign="top" width="50%" rowspan="5"><textarea name="desc" rows="14" cols="60">';
print $livre->description;
print "</textarea></td></tr>";
print '<tr><td>Année</td><TD><input name="annee" size="6" maxlenght="4" value="'.$livre->annee.'"></td></tr>';
print '<tr><td>Prix</td><TD><input name="price" size="10" value="'.price($livre->price).'"></td></tr>';
$htmls = new Form($db);
$edits = new Editeur($db);
print "<tr><td>Editeur</td><td>";
$htmls->select_array("editeurid", $edits->liste_array(), $livre->editeurid);
print "</td></tr>";
print '<tr><td>Co-Auteurs</td><td>';
foreach ($auteurs as $key => $value)
{
print '<a href="../auteur/fiche.php?id='.$key.'">'.$value."<br>\n";
}
print "</td></tr>";
/*
$c = new Categorie($db);
print "<tr><td>Editeur</td><td>";
$htmls->select_array("editeurid", $c->liste_array());
print "</td></tr>";
*/
print '<tr><td align="center" colspan="3"><input type="submit" value="Enregistrer">&nbsp;<input type="submit" value="Annuler" name="cancel"></td></tr>';
print "</form>";
print '</form>';
$auteur = new Auteur($db);
print "<form action=\"$PHP_SELF?id=$id\" method=\"post\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"addga\">";
print "<tr><td>Co-Auteur</td><td>";
$htmls->select_array("coauteurid", $auteur->liste_array());
print '&nbsp;<input type="submit" value="Ajouter"></td></tr>';
print "</form>";
print '</table><hr>';
}
print '<div class="titre">Fiche Livre : '.$livre->titre.'</div><br>';
print '<table border="1" width="100%" cellspacing="0" cellpadding="4">';
print "<tr>";
print '<td width="20%">Référence</td><td width="30%">'.$livre->ref.'</td>';
print '<td width="50%" valign="top">Description</td></tr>';
print "<tr><td>Statut</td><td>$livre->status_text</td>\n";
print '<td rowspan="6" valign="top">'.nl2br($livre->description)."</td>";
print "<tr><td>Titre</td><td>$livre->titre</td></tr>\n";
print "<tr><td>Annee</td><td>$livre->annee</td></tr>\n";
print '<tr><td>Editeur</td><TD>';
if ($livre->editeurid)
{
$editeur = new Editeur($db);
$editeur->fetch($livre->editeurid);
print $editeur->nom;
}
print '</td></tr>';
print '<tr><td>Co-Auteurs</td><td>';
foreach ($auteurs as $key => $value)
{
print '<a href="../auteur/fiche.php?id='.$key.'">'.$value."<br>\n";
}
print "</td></tr>";
print '<tr><td>Prix</td><TD>'.price($livre->price).'</td></tr>';
$listecat = new Categorie($db);
print '<td valign="top">Artiste/Groupe</td><td>';
$htmls->select_array("catd", $listecat->liste_array());
print "</td></tr>\n";
print "</table>";
}
else
{
print "Fetch failed";
}
}
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">[<a href="fiche.php?action=updateosc&id='.$id.'">Update Osc</a>]</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,338 @@
<?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 Livre {
var $db ;
var $id ;
var $oscid ;
var $ref;
var $price;
var $annee;
var $editeurid;
var $titre;
var $description;
var $price ;
var $status ;
Function Livre($DB, $id=0) {
$this->db = $DB;
$this->id = $id ;
}
/*
*
*
*
*/
Function create($user) {
if (strlen($this->annee))
{
$this->annee = 0;
}
$sql = "insert into ".DB_NAME_OSC.".products (products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_date_added) ";
$sql .= "values ('', '', 'Array', '', null, '', '0', '0', '8', now())";
if ($this->db->query($sql) )
{
$idosc = $this->db->last_insert_id();
$sql = "insert into ".DB_NAME_OSC.".products_to_categories (products_id, categories_id) values ($idosc, 0)";
if ($this->db->query($sql) )
{
$sql = "insert into ".DB_NAME_OSC.".products_description (products_name, products_description, products_url, products_id, language_id) values ('".trim($this->titre)."', '".trim($this->description)."', '', $idosc, '1')";
if ($this->db->query($sql) )
{
$sql = "INSERT INTO llx_livre (oscid, fk_user_author) VALUES ($idosc, ".$user->id.")";
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
if ( $this->update($id, $user) )
{
return $id;
}
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
Function linkga($id, $gaid)
{
$sql = "INSERT INTO llx_livre_to_auteur (fk_livre, fk_auteur) values ($id, $gaid)";
if ( $this->db->query($sql) )
{
return 1;
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*/
Function liste_auteur()
{
$ga = array();
$sql = "SELECT a.rowid, a.nom FROM llx_auteur as a, llx_livre_to_auteur as l";
$sql .= " WHERE a.rowid = l.fk_auteur AND l.fk_livre = ".$this->id;
$sql .= " ORDER BY a.nom";
if ($this->db->query($sql) )
{
$nump = $this->db->num_rows();
if ($nump)
{
$i = 0;
while ($i < $nump)
{
$obj = $this->db->fetch_object($i);
$ga[$obj->rowid] = $obj->nom;
$i++;
}
}
return $ga;
}
else
{
print $this->db->error();
}
}
/*
*
*
*
*/
Function updateosc()
{
$sql = "UPDATE ".DB_NAME_OSC.".products_description ";
$sql .= " SET products_name = '".$this->titre."'";
$desc .= '<br>Info supplémentaires';
$ga = array();
$ga = $this->liste_groupart();
if (sizeof($ga) == 1)
{
foreach ($ga as $key => $value)
{
$gaid = $key;
}
$groupart = new Groupart($this->db);
$result = $groupart->fetch($gaid);
if ( $result )
{
$desc = $groupart->nom."<p>";
$desc .= addslashes($this->description);
$desc .= "<p><b>Autres livres</b> : ";
$gas = $groupart->liste_livres();
$i = 0;
$sizegas = sizeof($gas) - 1;
foreach ($gas as $key => $value)
{
if ($key <> $this->id)
{
$otha = new Livre($this->db);
$otha->fetch($key);
$desc .= '<a href="'.OSC_CATALOG_URL.'product_info.php?products_id='.$otha->oscid.'">'.$value."</a>";
$i++;
if ($sizegas > $i)
{
$desc .= ", ";
}
}
}
}
}
$sql .= ", products_description = '$desc'";
$sql .= " WHERE products_id = " . $this->oscid;
if ( $this->db->query($sql) ) {
return 1;
} else {
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
Function update($id, $user)
{
if (strlen($this->annee)==0)
{
$this->annee = 0;
}
$sql = "UPDATE llx_livre ";
$sql .= " SET title = '" . trim($this->titre) ."'";
$sql .= ", ref = '" . trim(strtoupper($this->ref)) ."'";
$sql .= ", prix = " . $this->price ."";
$sql .= ", annee = " . $this->annee ;
$sql .= ", fk_editeur = " . $this->editeurid ;
$sql .= ", description = '" . trim($this->description) ."'";
$sql .= " WHERE rowid = " . $id;
if ( $this->db->query($sql) ) {
return 1;
} else {
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
Function fetch ($id) {
$sql = "SELECT rowid, fk_editeur, ref, prix, annee, oscid, title, description FROM llx_livre WHERE rowid = $id";
$result = $this->db->query($sql) ;
if ( $result )
{
$result = $this->db->fetch_array();
$this->id = $result["rowid"];
$this->ref = $result["ref"];
$this->price = $result["prix"];
$this->annee = $result["annee"];
$this->editeurid = $result["fk_editeur"];
$this->titre = stripslashes($result["title"]);
$this->description = stripslashes($result["description"]);
$this->oscid = $result["oscid"];
$this->db->free();
$sql = "SELECT products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_date_added";
$sql .= " FROM ".DB_NAME_OSC.".products WHERE products_id = " . $this->oscid;
$result = $this->db->query($sql) ;
if ( $result )
{
$result = $this->db->fetch_array();
$this->status = $result["products_status"];
if ($this->status)
{
$this->status_text = "En vente";
}
else
{
$this->status_text = "Cet article n'est pas en vente";
}
$this->db->free();
}
else
{
print $this->db->error();
}
}
else
{
print $this->db->error();
}
return $result;
}
/*
*
*
*/
Function delete($user) {
$sql = "DELETE FROM ".DB_NAME_OSC.".products WHERE products_id = $idosc ";
$sql = "DELETE FROM ".DB_NAME_OSC.".products_to_categories WHERE products_id = $idosc";
$sql = "DELETE FROM ".DB_NAME_OSC.".products_description WHERE products_id = $idosc";
$sql = "DELETE FROM llx_livre WHERE rowid = $id";
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B