Gestion des categories
This commit is contained in:
parent
4fb78c7678
commit
ad5aa509b4
@ -39,12 +39,19 @@ if ($action == 'add') {
|
||||
$id = $livre->create($user);
|
||||
}
|
||||
|
||||
if ($action == 'addga') {
|
||||
if ($action == 'addga')
|
||||
{
|
||||
$livre = new Livre($db);
|
||||
|
||||
$livre->linkga($id, $coauteurid);
|
||||
}
|
||||
|
||||
if ($action == 'linkcat')
|
||||
{
|
||||
$livre = new Livre($db);
|
||||
$livre->fetch($id);
|
||||
$livre->linkcategorie( $catid);
|
||||
}
|
||||
|
||||
|
||||
if ($action == 'update' && !$cancel) {
|
||||
$livre = new Livre($db);
|
||||
@ -83,6 +90,14 @@ if ($action == 'create')
|
||||
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>';
|
||||
|
||||
$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 valign=\"top\">Description</td><td>";
|
||||
print '<textarea name="desc" rows="8" cols="50">';
|
||||
print "</textarea></td></tr>";
|
||||
@ -116,7 +131,6 @@ else
|
||||
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;
|
||||
@ -138,12 +152,7 @@ else
|
||||
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"> <input type="submit" value="Annuler" name="cancel"></td></tr>';
|
||||
print "</form>";
|
||||
@ -160,6 +169,15 @@ else
|
||||
print ' <input type="submit" value="Ajouter"></td></tr>';
|
||||
print "</form>";
|
||||
|
||||
print "<form action=\"$PHP_SELF?id=$id\" method=\"post\">\n";
|
||||
print '<input type="hidden" name="action" value="linkcat">';
|
||||
|
||||
$listecat = new Categorie($db);
|
||||
print '<td valign="top">Catégories</td><td>';
|
||||
$htmls->select_array("catid", $listecat->liste_array());
|
||||
print ' <input type="submit" value="Ajouter"></td></tr>';
|
||||
print "</form>";
|
||||
print "</td></tr>\n";
|
||||
|
||||
print '</table><hr>';
|
||||
|
||||
@ -169,11 +187,16 @@ else
|
||||
|
||||
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 '<td width="15%">Référence</td><td width="20%">'.$livre->ref.'</td>';
|
||||
print '<td width="50%" valign="top">Description</td>';
|
||||
print '<td valign="top">Catégories</td></tr>';
|
||||
print "<tr><td>Statut</td><td>$livre->status_text</td>\n";
|
||||
print '<td rowspan="6" valign="top">'.nl2br($livre->description)."</td>";
|
||||
|
||||
print '<td rowspan="6" valign="top">';
|
||||
$livre->listcategorie();
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>Titre</td><td>$livre->titre</td></tr>\n";
|
||||
print "<tr><td>Annee</td><td>$livre->annee</td></tr>\n";
|
||||
|
||||
@ -195,15 +218,6 @@ else
|
||||
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>";
|
||||
|
||||
|
||||
|
||||
@ -156,6 +156,78 @@ class Livre {
|
||||
print $this->db->error();
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
Function linkcategorie($categories_id)
|
||||
{
|
||||
|
||||
$sql = "INSERT INTO ".DB_NAME_OSC.".products_to_categories ";
|
||||
|
||||
$sql .= " (products_id, categories_id)";
|
||||
$sql .= " VALUES (".$this->oscid.",".$categories_id.")";
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
print $this->db->error() . ' in ' . $sql;
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
Function listcategorie()
|
||||
{
|
||||
$listecat = new Categorie($this->db);
|
||||
$cats = $listecat->liste_array();
|
||||
|
||||
$pcat = array();
|
||||
|
||||
$sql = "SELECT products_id, categories_id";
|
||||
$sql .= " FROM ".DB_NAME_OSC.".products_to_categories ";
|
||||
$sql .= " WHERE products_id = " . $this->oscid;
|
||||
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
$nump = $this->db->num_rows();
|
||||
|
||||
if ($nump)
|
||||
{
|
||||
$i = 0;
|
||||
while ($i < $nump)
|
||||
{
|
||||
$obj = $this->db->fetch_object($i);
|
||||
$pcat[$i] = $obj->categories_id;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($cats as $key => $value)
|
||||
{
|
||||
$test = 0;
|
||||
for ($i = 0 ; $i < $nump ; $i++)
|
||||
{
|
||||
if ($pcat[$i] == $key)
|
||||
{
|
||||
$test = 1;
|
||||
}
|
||||
}
|
||||
if ($test)
|
||||
{
|
||||
print "<b>$value</b><br>";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "$value<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*
|
||||
|
||||
@ -86,7 +86,7 @@ class Categorie {
|
||||
$sql = "SELECT c.categories_id, cd.categories_name ";
|
||||
$sql .= " FROM ".DB_NAME_OSC.".categories as c,".DB_NAME_OSC.".categories_description as cd";
|
||||
$sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID;
|
||||
$sql .= " AND c.parent_id = 0";
|
||||
$sql .= " AND c.parent_id = 0 ORDER BY cd.categories_name";
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
@ -96,9 +96,12 @@ class Categorie {
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $this->db->fetch_object( $i);
|
||||
|
||||
$cl[$objp->categories_id] = $objp->categories_name;
|
||||
|
||||
$var=!$var;
|
||||
$pc = array();
|
||||
$pc = $this->printc($objp->categories_id, 0);
|
||||
$pc = $this->printc($objp->categories_id, 1);
|
||||
foreach($pc as $key => $value)
|
||||
{
|
||||
$cl[$key] = $value;
|
||||
@ -109,36 +112,39 @@ class Categorie {
|
||||
return $cl;
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
Function printc($id, $level)
|
||||
{
|
||||
$cr = array();
|
||||
$cat = new Categorie($this->db);
|
||||
$cat->fetch($id);
|
||||
|
||||
|
||||
for ($i = 0 ; $i < $level ; $i++)
|
||||
{
|
||||
$string = " |--";
|
||||
$prefix .= " ";
|
||||
}
|
||||
|
||||
$string .= $cat->name;
|
||||
|
||||
|
||||
$cr[$cat->id] = $cat->name;
|
||||
|
||||
$childs = array();
|
||||
$childs = $cat->liste_childs_array();
|
||||
|
||||
|
||||
if (sizeof($childs))
|
||||
{
|
||||
foreach($childs as $key => $value)
|
||||
{
|
||||
$cr[$key] = $value;
|
||||
$this->printc($key, $level+1);
|
||||
$pc = array();
|
||||
$pc = $this->printc($key,$level+1);
|
||||
foreach($pc as $key => $value)
|
||||
{
|
||||
$cr[$key] = $prefix . $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $cr;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
@ -151,7 +157,7 @@ class Categorie {
|
||||
$sql .= " FROM ".DB_NAME_OSC.".categories as c,".DB_NAME_OSC.".categories_description as cd";
|
||||
$sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID;
|
||||
$sql .= " AND c.parent_id = " . $this->id;
|
||||
|
||||
$sql .= " ORDER BY cd.categories_name";
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
$nump = $this->db->num_rows();
|
||||
|
||||
@ -25,16 +25,6 @@ require("./pre.inc.php");
|
||||
llxHeader();
|
||||
|
||||
$db = new Db();
|
||||
if ($sortfield == "") {
|
||||
$sortfield="lower(cd.categories_name)";
|
||||
}
|
||||
if ($sortorder == "") {
|
||||
$sortorder="ASC";
|
||||
}
|
||||
|
||||
if ($page == -1) { $page = 0 ; }
|
||||
$limit = $conf->liste_limit;
|
||||
$offset = $limit * $page ;
|
||||
|
||||
print_barre_liste("Liste des catégories", $page, $PHP_SELF);
|
||||
|
||||
@ -42,8 +32,7 @@ $sql = "SELECT c.categories_id, cd.categories_name ";
|
||||
$sql .= " FROM ".DB_NAME_OSC.".categories as c,".DB_NAME_OSC.".categories_description as cd";
|
||||
$sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID;
|
||||
$sql .= " AND c.parent_id = 0";
|
||||
$sql .= " ORDER BY $sortfield $sortorder ";
|
||||
$sql .= $db->plimit( $limit ,$offset);
|
||||
$sql .= " ORDER BY cd.categories_name ASC ";
|
||||
|
||||
if ( $db->query($sql) )
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user