début restructuration du code
This commit is contained in:
parent
f575fc20ed
commit
dbfa477d25
@ -32,6 +32,7 @@ class Categorie
|
|||||||
var $id;
|
var $id;
|
||||||
var $label;
|
var $label;
|
||||||
var $description;
|
var $description;
|
||||||
|
var $statut;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructeur
|
* Constructeur
|
||||||
@ -52,7 +53,7 @@ class Categorie
|
|||||||
*/
|
*/
|
||||||
function fetch($id)
|
function fetch($id)
|
||||||
{
|
{
|
||||||
$sql = "SELECT rowid,label,description ";
|
$sql = "SELECT rowid, label, description, fk_statut";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."categorie WHERE rowid = ".$id;
|
$sql.= " FROM ".MAIN_DB_PREFIX."categorie WHERE rowid = ".$id;
|
||||||
|
|
||||||
$resql = $this->db->query ($sql);
|
$resql = $this->db->query ($sql);
|
||||||
@ -64,6 +65,7 @@ class Categorie
|
|||||||
$this->id = $res['rowid'];
|
$this->id = $res['rowid'];
|
||||||
$this->label = $res['label'];
|
$this->label = $res['label'];
|
||||||
$this->description = stripslashes($res['description']);
|
$this->description = stripslashes($res['description']);
|
||||||
|
$this->statut = $res['fk_statut'];
|
||||||
|
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
}
|
}
|
||||||
@ -128,6 +130,7 @@ class Categorie
|
|||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
|
||||||
$sql.= " SET label = '".trim($this->label)."'";
|
$sql.= " SET label = '".trim($this->label)."'";
|
||||||
|
|
||||||
if (strlen (trim($this->description)) > 0)
|
if (strlen (trim($this->description)) > 0)
|
||||||
{
|
{
|
||||||
$sql .= ", description = '".trim($this->description)."'";
|
$sql .= ", description = '".trim($this->description)."'";
|
||||||
@ -160,6 +163,7 @@ class Categorie
|
|||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_product ";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_product ";
|
||||||
$sql .= "WHERE fk_categorie = ".$this->id;
|
$sql .= "WHERE fk_categorie = ".$this->id;
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
if (!$this->db->query($sql))
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
@ -169,6 +173,7 @@ class Categorie
|
|||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association ";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association ";
|
||||||
$sql .= "WHERE fk_categorie_mere = ".$this->id;
|
$sql .= "WHERE fk_categorie_mere = ".$this->id;
|
||||||
$sql .= " OR fk_categorie_fille = ".$this->id;
|
$sql .= " OR fk_categorie_fille = ".$this->id;
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
if (!$this->db->query($sql))
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
@ -177,6 +182,7 @@ class Categorie
|
|||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie ";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie ";
|
||||||
$sql .= "WHERE rowid = ".$this->id;
|
$sql .= "WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
if (!$this->db->query($sql))
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
@ -477,32 +483,6 @@ class Categorie
|
|||||||
function get_main_categories ()
|
function get_main_categories ()
|
||||||
{
|
{
|
||||||
$allcats = $this->get_all_categories ();
|
$allcats = $this->get_all_categories ();
|
||||||
|
|
||||||
/* $sql = "SELECT rowid,label,description FROM ".MAIN_DB_PREFIX."categorie ";
|
|
||||||
$sql .= "WHERE ".MAIN_DB_PREFIX."categorie.rowid NOT IN (";
|
|
||||||
$sql .= "SELECT fk_categorie_fille FROM ".MAIN_DB_PREFIX."categorie_association)";
|
|
||||||
|
|
||||||
$res = $this->db->query ($sql);
|
|
||||||
|
|
||||||
if ($res)
|
|
||||||
{
|
|
||||||
$cats = array ();
|
|
||||||
while ($record = $this->db->fetch_array ($res))
|
|
||||||
{
|
|
||||||
$cat = array ("rowid" => $record['rowid'],
|
|
||||||
"label" => $record['label'],
|
|
||||||
"description" => $record['description']);
|
|
||||||
$cats[$record['rowid']] = $cat;
|
|
||||||
}
|
|
||||||
return $cats;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*/ // pas de NOT IN avec MySQL ?
|
|
||||||
|
|
||||||
|
|
||||||
$maincats = array ();
|
$maincats = array ();
|
||||||
$filles = array ();
|
$filles = array ();
|
||||||
|
|
||||||
|
|||||||
@ -72,9 +72,9 @@ print '<tr><td valign="top" width="30%" class="notopnoleft">';
|
|||||||
<td><?php print $langs->trans ("In"); ?> <select name="choix">
|
<td><?php print $langs->trans ("In"); ?> <select name="choix">
|
||||||
<?php
|
<?php
|
||||||
// création d'un objet de type catégorie pour faire des requêtes sur la table
|
// création d'un objet de type catégorie pour faire des requêtes sur la table
|
||||||
$c = new Categorie ($db);
|
$categorie = new Categorie ($db);
|
||||||
|
|
||||||
$nb = $c->get_nb_categories ();
|
$nb = $categorie->get_nb_categories();
|
||||||
|
|
||||||
for ($i = 0 ; $i <= $nb ; $i++)
|
for ($i = 0 ; $i <= $nb ; $i++)
|
||||||
{
|
{
|
||||||
@ -94,7 +94,7 @@ print '<tr><td valign="top" width="30%" class="notopnoleft">';
|
|||||||
<input type="submit" value="<?php print $langs->trans ("modify"); ?>" name="ok" id="ok" />
|
<input type="submit" value="<?php print $langs->trans ("modify"); ?>" name="ok" id="ok" />
|
||||||
</td>
|
</td>
|
||||||
<?php
|
<?php
|
||||||
$cats = $c->get_all_categories ();//on récupère toutes les catégories et leurs attributs
|
$all_categories = $categorie->get_all_categories();//on récupère toutes les catégories et leurs attributs
|
||||||
|
|
||||||
for ($i = 0; $i < $nbcats ; $i++)
|
for ($i = 0; $i < $nbcats ; $i++)
|
||||||
{
|
{
|
||||||
@ -102,7 +102,7 @@ print '<tr><td valign="top" width="30%" class="notopnoleft">';
|
|||||||
|
|
||||||
echo "<option value='-1' id='choix'>".$langs->trans ("Choose")."</option>\n";
|
echo "<option value='-1' id='choix'>".$langs->trans ("Choose")."</option>\n";
|
||||||
|
|
||||||
foreach ($cats as $id => $cat)
|
foreach ($all_categories as $id => $cat)
|
||||||
{ //ajout des categories dans la liste
|
{ //ajout des categories dans la liste
|
||||||
echo "<option value='$id' id='$id'";
|
echo "<option value='$id' id='$id'";
|
||||||
|
|
||||||
|
|||||||
@ -42,26 +42,28 @@ print '<table border="0" width="100%">';
|
|||||||
|
|
||||||
print '<tr><td valign="top" width="30%">';
|
print '<tr><td valign="top" width="30%">';
|
||||||
|
|
||||||
$cat = new Categorie ($db);
|
$categorie = new Categorie($db);
|
||||||
|
|
||||||
$cat->label = $_REQUEST["nom"];
|
$categorie->label = $_REQUEST["nom"];
|
||||||
$cat->description = $_REQUEST["description"];
|
$categorie->description = $_REQUEST["description"];
|
||||||
|
|
||||||
$cats_meres = isset($_REQUEST['cats_meres']) ? $_REQUEST['cats_meres'] : array ();
|
$cats_meres = isset($_REQUEST['cats_meres']) ? $_REQUEST['cats_meres'] : array ();
|
||||||
|
|
||||||
$res = $cat->create ();
|
$res = $categorie->create();
|
||||||
|
|
||||||
if ($res < 0)
|
if ($res < 0)
|
||||||
{
|
{
|
||||||
print "<p>Impossible d'ajouter la catégorie ".$cat->label.".</p>";
|
print "<p>Impossible d'ajouter la catégorie ".$categorie->label.".</p>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "<p>La catégorie ".$cat->label." a été ajoutée avec succčs.</p>";
|
print "<p>La catégorie ".$categorie->label." a été ajoutée avec succčs.</p>";
|
||||||
|
|
||||||
foreach ($cats_meres as $id)
|
foreach ($cats_meres as $id)
|
||||||
{
|
{
|
||||||
$mere = new Categorie($db, $id);
|
$mere = new Categorie($db, $id);
|
||||||
$res = $mere->add_fille ($cat);
|
$res = $mere->add_fille($categorie);
|
||||||
|
|
||||||
if ($res < 0)
|
if ($res < 0)
|
||||||
{
|
{
|
||||||
print "<p>Impossible d'associer la catégorie à \"".$mere->label."\" ($res).</p>";
|
print "<p>Impossible d'associer la catégorie à \"".$mere->label."\" ($res).</p>";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user