dolibarr/htdocs/categories/domodif.php

120 lines
3 KiB
PHP
Raw Normal View History

2005-04-13 11:54:55 +00:00
<?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.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.
*/
2007-05-04 22:44:40 +00:00
/**
\file htdocs/categories/domodif.php
\ingroup category
\brief Page de modification categorie
\version $Revision$
*/
2005-04-13 11:54:55 +00:00
require "./pre.inc.php";
if (!isset ($_REQUEST["id"]) || !isset ($_REQUEST["nom"]) || !isset ($_REQUEST["description"]))
accessforbidden();
/**
* Affichage page accueil
*/
llxHeader("","",$langs->trans("Categories"));
print_titre($langs->trans("CatCreated"));
print '<table border="0" width="100%">';
print '<tr><td valign="top" width="30%">';
$cat = new Categorie ($db, $_REQUEST['id']);
$cat->label = $_REQUEST["nom"];
$cat->description = $_REQUEST["description"];
$new_cats_meres = isset ($_REQUEST['cats_meres']) ? $_REQUEST['cats_meres'] : array ();
2005-04-13 12:06:26 +00:00
// tableau d'id de cat<61>gories
2005-04-13 11:54:55 +00:00
$old_objs_meres = $cat->get_meres ();
2005-04-13 12:06:26 +00:00
// tableau d'objets cat<61>gorie
2005-04-13 11:54:55 +00:00
$old_cats_meres = array ();
foreach ($old_objs_meres as $old_obj_mere)
2005-04-13 12:06:26 +00:00
{ // transformation en tableau d'id
$old_cats_meres[] = $old_obj_mere->id;
}
2005-04-13 11:54:55 +00:00
$asupprimer = array (); // tableaux des cat<61>gories m<>res
$aajouter = array (); // <20> ajouter ou <20> supprimer
foreach ($old_cats_meres as $old_cat)
2005-04-13 12:06:26 +00:00
{
if (!in_array ($old_cat, $new_cats_meres))
{
$asupprimer[] = new Categorie ($db, $old_cat);
}
}
2005-04-13 11:54:55 +00:00
foreach ($new_cats_meres as $new_cat)
2005-04-13 12:06:26 +00:00
{
if (!in_array ($new_cat, $old_cats_meres))
{
$aajouter[] = new Categorie ($db, $new_cat);
}
}
2005-04-13 11:54:55 +00:00
$res = $cat->update ();
if ($res < 0)
2005-04-13 12:06:26 +00:00
{
print "<p>Impossible de modifier la cat<61>gorie ".$cat->label.".</p>";
}
else
{
print "<p>La cat<61>gorie ".$cat->label." a <20>t<EFBFBD> modifi<66>e avec succ<63>s.</p>";
foreach ($asupprimer as $old_mere)
{
$res = $old_mere->del_fille ($cat);
if ($res < 0)
2005-04-13 11:54:55 +00:00
{
2005-04-13 12:06:26 +00:00
print "<p>Impossible d'enlever la cat<61>gorie de \"".$old_mere->label."\" ($res).</p>\n";
2005-04-13 11:54:55 +00:00
}
2005-04-13 12:06:26 +00:00
else
{
print "<p>La cat<61>gorie ne fait plus partie de ".$old_mere->label.".</p>\n";
}
}
foreach ($aajouter as $new_mere)
{
$res = $new_mere->add_fille ($cat);
if ($res < 0)
{
print "<p>Impossible d'ajouter la cat<61>gorie <20> \"".$new_mere->label."\" ($res).</p>";
}
else
2005-04-13 11:54:55 +00:00
{
2005-04-13 12:06:26 +00:00
print "<p>La cat<61>gorie fait maintenant partie de ".$new_mere->label.".</p>\n";
2005-04-13 11:54:55 +00:00
}
2005-04-13 12:06:26 +00:00
}
}
2005-04-13 11:54:55 +00:00
print '</td></tr></table>';
$db->close();
?>