changement du fonctionnement

This commit is contained in:
Andre Cianfarani 2006-03-13 16:40:34 +00:00
parent ce0b93edb1
commit 302515c3ff
2 changed files with 83 additions and 281 deletions

View File

@ -17,12 +17,11 @@
*/
require "./pre.inc.php";
$user->getrights();
if (false && (!isset ($_REQUEST['id']) || !$user->rights->categories->lire))
if (!$user->rights->categorie->lire)
accessforbidden();
// toujours pas trouvé comment mettre les droits qui vont bien
llxHeader("","",$langs->trans("Categories"));
print_titre($langs->trans("ModifCat"));
@ -31,152 +30,73 @@ print '<table border="0" width="100%">';
print '<tr><td valign="top" width="30%">';
$categorie = new Categorie ($db, $_REQUEST['id']);
$html = new Form($db);
$c = new Categorie ($db, $_REQUEST['id']);
if (isset ($_REQUEST['cats_meres']))
// Action mise à jour d'une catégorie
if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{
$cats_meres = $_REQUEST['cats_meres'];
}
else
{
$cats_meres = array ();
foreach ($c->get_meres () as $mere)
{
$cats_meres[] = $mere->id;
}
}
$label = isset ($_REQUEST['nom']) ? $_REQUEST['nom'] : $c->label;
$description = isset ($_REQUEST['description']) ? $_REQUEST['description'] : $c->description;
$nbcats = isset ($_REQUEST['choix']) ? $_REQUEST['choix'] : sizeof ($cats_meres);
$categorie->label = stripslashes($_POST["nom"]);
$categorie->description = stripslashes($_POST["description"]);
if($_POST['catMere'] != "-1")
$categorie->id_mere = stripslashes($_POST['catMere']);
if (!$categorie->label || !$categorie->description)
{
$_GET["action"] = 'create';
$categorie->error = "Le libellé ou la description n'a pas été renseigné";
}
if ($categorie->error =="")
{
if ($categorie->update() > 0)
{
$_GET["action"] = 'confirmed';
$_POST["addcat"] = '';
}
}
}
if($categorie->error != "")
{
print '<div class="error">';
print $categorie->error;
print '</div>';
}
print '<tr><td valign="top" width="30%">';
?>
<form method="post" action="<?php print $_SERVER['REQUEST_URI']; ?>">
<input type="hidden" name="action" value="update">
<table class="border">
<tr>
<td><?php print $langs->trans("Label"); ?>&nbsp;:</td>
<td><input type='text' size='25' id='nom' name ='nom' value='<?php
print htmlspecialchars (stripslashes ($label), ENT_QUOTES);
print $categorie->label;
?>' />
</tr>
<tr>
<td><?php print $langs->trans("Description"); ?>&nbsp;:</td>
<td><textarea name='description' cols='40' rows='6' id='description'><?php
print htmlspecialchars (stripslashes ($description), ENT_QUOTES);
print $categorie->description;
?></textarea></td>
</tr>
<tr>
<td>
<?php print $langs->trans("In"); ?>
<select name="choix">
<?php
// création d'un objet de type catégorie pour faire des requêtes sur la table
$c = new Categorie ($db);
$nb = $c->get_nb_categories ();
for ($i = 0 ; $i <= $nb ; $i++)
{
echo "<option value='$i' ";//creation d'une valeur dans la liste
if ($i == $nbcats)
echo 'selected="true"'; // permet de rendre le choix toujours selectionne
echo ">$i</option>";
}
?>
</select>
<?php print $langs->trans("categories"); ?>
</td>
<td>
<input type="submit" value="<?php print $langs->trans ("modify"); ?>" name="ok" id="ok" />
</td>
</tr>
<?php
$cats = $c->get_all_categories ();//on récupère toutes les catégories et leurs attributs
for ($i = 0 ; $i < $nbcats ; $i++)
{
print "<tr><td>";
print $langs->trans("Categorie")." ".($i+1)."</td><td><select name='cats_meres[".$i."]'>"; //creation des categories meres
echo "<option value='-1' id='choix'>".$langs->trans ("Choose")."</option>\n";
foreach ($cats as $id => $cat)
{ //ajout des categories dans la liste
echo "<option value='$id' id='$id'";
if ($cats_meres[$i] == $id)
echo ' selected="true"';
echo ">".$cat->label."</option>\n";
}
echo "</select></td></tr>\n";
}
?>
<?php print $langs->trans("In"); ?>
<?php print $html->select_all_categories($categorie->id_mere);?>
<tr>
<td colspan="2" align="center"><input type='submit' value='<?php print $langs->trans ("Modify"); ?>' id="modif" name="modif"/></td>
<td colspan="2" align="center"><input type='submit' value='<?php print $langs->trans ("Modify"); ?>'></td>
</tr>
</table>
</form>
<?php
if (isset ($_REQUEST['modif']))
{
// doit être à true pour valider la saisie de l'utilisateur
$OK = true;
if (sizeof ($cats_meres) > 1 && sizeof (array_unique ($cats_meres)) != sizeof ($cats_meres))
{ // alors il y a des valeurs en double
echo "<p>".$langs->trans ("ErrSameCatSelected")."</p>";
$OK = false;
}
// vérification des champs renseignés par l'utilisateur: si il y a un problème, on affiche un message d'erreur
if (sizeof ($cats_meres) > 0) foreach ($cats_meres as $nb => $cat_mere)
{
if ($cat_mere == -1)
{
echo "<p>".$langs->trans ("ErrForgotCat")."</p>";
$OK = false;
}
}
// si les champs de description sont mal renseignés
if ($label == '')
{
echo "<p>".$langs->trans ("ErrForgotField")."</p>";
$OK = false;
}
// vérification pour savoir si tous les champs sont corrects
if ($OK)
{
// creation de champs caches pour etre appele dans la classe de traitement
?>
<form method="post" action="domodif.php">
<p><?php print $langs->trans("ValidateFields"); ?> ? <input type='submit' value='<?php print $langs->trans("Valid"); ?>'/></p>
<input type='hidden' name='id' value="<?php print $_REQUEST['id']; ?>">
<input type='hidden' name='nom' value="<?php print $label; ?>">
<input type='hidden' name='description' value="<?php print $description; ?>">
<?php
foreach ($cats_meres as $id => $cat_mere)
{
echo "<input type='hidden' name='cats_meres[$id]' value='$cat_mere'>";
}
?>
</form>
<?php
}
}
print '</td></tr></table>';

View File

@ -46,213 +46,95 @@ $html = new Form($db);
// Action ajout d'un produit ou service
if ($_POST["action"] == 'add' && $user->rights->produit->creer)
// Action ajout d'une catégorie
if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
{
$categorie = new Categorie($db);
$categorie->label = stripslashes($_POST["nom"]);
$categorie->description = stripslashes($_POST["description"]);
$cats_meres = isset($_POST['catsMeres']) ? $_POST['catsMeres'] : array();
$ok = true;
if($_POST['catMere'] != "-1")
$categorie->id_mere = stripslashes($_POST['catMere']);
if (!$categorie->label || !$categorie->description)
{
$_GET["action"] = 'create';
$ok = false;
$categorie->error = "Le libellé ou la description n'a pas été renseigné";
}
if ($ok)
if ($categorie->error =="")
{
if (sizeof($cats_meres) > 1 && sizeof(array_unique($cats_meres)) != sizeof($cats_meres))
if ($categorie->create() > 0)
{
// alors il y a des valeurs en double
print '<p>'.$langs->trans("ErrSameCatSelected").'</p>';
$_GET["action"] = 'create';
$ok = false;
$_GET["action"] = 'confirmed';
$_POST["addcat"] = '';
}
}
/*
* Action confirmation de création de la catégorie
*/
if ($ok)
{
$res = $categorie->create();
if ($res < 0)
{
$_error = 3;
}
else
{
foreach ($cats_meres as $id)
{
$mere = new Categorie($db, $id);
$res = $mere->add_fille($categorie);
if ($res < 0)
{
$_error = 2;
}
else
{
$_GET["action"] = 'confirmed';
$_POST["addcat"] = '';
}
}
}
}
if ($_GET["action"] == 'confirmed')
{
print_titre($langs->trans("CatCreated"));
print '<table border="0" width="100%">';
print '<tr><td valign="top" width="30%">';
if ($_error == 3)
{
print '<p>'.$langs->trans("ImpossibleAddCat").' '.$categorie->label.'</p>';
}
else
{
print '<p>'.$langs->trans("TheCategorie").' '.$categorie->label.' '.$langs->trans("WasAddedSuccessfully").'</p>';
if ($_error == 2)
{
print '<p>'.$langs->trans("TheCategorie").' '.$mere->label.' ('.$res.').</p>';
}
}
print '</td></tr></table>';
}
}
/*
* Fiche en mode création
*/
if ($user->rights->produit->creer)
{
/*
* Fiche en mode création
*/
if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat')
{
if($categorie->error != "")
{
print '<div class="error">';
print $categorie->error;
print '</div>';
}
print '<form action="fiche.php" method="post">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="addcat" value="addcat">';
print '<input type="hidden" name="nom" value="'.$nom.'">';
print '<input type="hidden" name="description" value="'.$description.'">';
$catsMeres = isset($_POST['catsMeres']) ? $_POST['catsMeres'] : array();
foreach ($catsMeres as $id => $cat_mere)
{
print '<input type="hidden" name="catsMeres[$id]" value="'.$cat_mere.'">';
}
print_fiche_titre($langs->trans("CreateCat"));
print '<table class="border" width="100%" class="notopnoleftnoright">';
print '<tr>';
print '<td>'.$langs->trans("Label").'</td><td><input name="nom" size"25" value="'.$categorie->label.'">';
if ($_error == 1)
{
print $lang->trans("ErrCatAlreadyExists");
}
print'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
print '<textarea name="description" rows="6" cols="50">';
print $categorie->description.'</textarea></td></tr>';
print '<tr><td>';
print $langs->trans("AddIn").' ';
print $html->select_nombre_sous_categorie($nbcats,"choix").' ';
print $langs->trans("categories");
print '</td><td>';
print '<input type="submit" class="button" value="'.$langs->trans("modify").'" name="choicenbcats" id="choicenbcats"/>';
print '</td></tr>';
print $html->select_all_categories($nbcats);
print $html->select_all_categories();
print '<tr><td colspan="2" align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("CreateThisCat").'" name="creation" id="creation"/>';
print '</td></tr></form>';
}
/*
* Action confirmation de création de la catégorie
*/
if ($_GET["action"] == 'confirmed')
{
print_titre($langs->trans("CatCreated"));
print '<table border="0" width="100%">';
print '<tr><td valign="top" width="30%">';
if ($_error == 3)
{
print '<p>'.$langs->trans("ImpossibleAddCat").' '.$categorie->label.'</p>';
}
else
{
print '<p>'.$langs->trans("TheCategorie").' '.$categorie->label.' '.$langs->trans("WasAddedSuccessfully").'</p>';
if ($_error == 2)
{
print '<p>'.$langs->trans("TheCategorie").' '.$mere->label.' ('.$res.').</p>';
}
}
print '</td></tr></table>';
}
}
print '</table>';
/*
<?php
if (isset ($_REQUEST['creation']))
{
// doit être à true pour valider la saisie de l'utilisateur
$OK = true;
$cats_meres = isset ($_REQUEST['catsMeres']) ? $_REQUEST['catsMeres'] : array ();
if (sizeof ($cats_meres) > 1 && sizeof (array_unique ($cats_meres)) != sizeof ($cats_meres))
{ // alors il y a des valeurs en double
echo "<p>".$langs->trans ("ErrSameCatSelected")."</p>";
$OK = false;
}
// vérification des champs renseignés par l'utilisateur: si il y a un problème, on affiche un message d'erreur
foreach ($cats_meres as $nb => $cat_mere)
{
if ($cat_mere == -1)
{
echo "<p>".$langs->trans ("ErrForgotCat")." ".($nb+1)."</p>";
$OK = false;
}
}
// si les champs de description sont mal renseignés
if ($_POST["nom"] == '')
{
echo "<p>".$langs->trans ("ErrForgotField")." \"".$langs->trans ("Label")."\"</p>";
$OK = false;
}
else if ($categorie->already_exists($_POST["nom"],$cat_mere)) // on regarde si le nom n'existe pas déjà en tant que catégorie ou sous-catégorie
{
echo "<p>".$langs->trans ("ErrCatAlreadyExists")."</p>";
$OK = false;
}
if ($_POST["description"] == '')
{
echo "<p>".$langs->trans ("ErrForgotField")." \"".$langs->trans ("Description")."\"</p>";
$OK = false;
}
// vérification pour savoir si tous les champs sont corrects
if ($OK)
{
$nom = htmlspecialchars(stripslashes($_REQUEST['nom']) ,ENT_QUOTES);
$description = htmlspecialchars(stripslashes($_REQUEST['description']),ENT_QUOTES);
// creation de champs caches pour etre appele dans la classe de traitement
?>
<table class="noborder"><tr><td>
<form method="post" action="docreate.php">
<p><?php print $langs->trans ("ValidateFields"); ?>&nbsp;?
<input type='submit' value='<?php print $langs->trans ("Valid"); ?>'/>
<input type='hidden' name='nom' value="<?php print $nom; ?>">
<input type='hidden' name='description' value="<?php print $description; ?>">
<?php
foreach ($cats_meres as $id => $cat_mere)
{
echo "<input type='hidden' name='cats_meres[$id]' value='$cat_mere'>";
}
?>
</form></p>
</td></tr></table>
<?php
}
}
*/
$db->close();
llxFooter('$Date$ - $Revision$');