changement du fonctionnement
This commit is contained in:
parent
ce0b93edb1
commit
302515c3ff
@ -17,11 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require "./pre.inc.php";
|
require "./pre.inc.php";
|
||||||
|
$user->getrights();
|
||||||
|
|
||||||
|
if (!$user->rights->categorie->lire)
|
||||||
if (false && (!isset ($_REQUEST['id']) || !$user->rights->categories->lire))
|
|
||||||
accessforbidden();
|
accessforbidden();
|
||||||
// toujours pas trouvé comment mettre les droits qui vont bien
|
|
||||||
|
|
||||||
llxHeader("","",$langs->trans("Categories"));
|
llxHeader("","",$langs->trans("Categories"));
|
||||||
|
|
||||||
@ -31,152 +30,73 @@ print '<table border="0" width="100%">';
|
|||||||
|
|
||||||
print '<tr><td valign="top" width="30%">';
|
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'];
|
|
||||||
|
$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é";
|
||||||
}
|
}
|
||||||
else
|
if ($categorie->error =="")
|
||||||
{
|
{
|
||||||
$cats_meres = array ();
|
if ($categorie->update() > 0)
|
||||||
foreach ($c->get_meres () as $mere)
|
|
||||||
{
|
{
|
||||||
$cats_meres[] = $mere->id;
|
$_GET["action"] = 'confirmed';
|
||||||
|
$_POST["addcat"] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$label = isset ($_REQUEST['nom']) ? $_REQUEST['nom'] : $c->label;
|
}
|
||||||
$description = isset ($_REQUEST['description']) ? $_REQUEST['description'] : $c->description;
|
if($categorie->error != "")
|
||||||
$nbcats = isset ($_REQUEST['choix']) ? $_REQUEST['choix'] : sizeof ($cats_meres);
|
{
|
||||||
|
print '<div class="error">';
|
||||||
|
print $categorie->error;
|
||||||
|
print '</div>';
|
||||||
|
}
|
||||||
print '<tr><td valign="top" width="30%">';
|
print '<tr><td valign="top" width="30%">';
|
||||||
?>
|
?>
|
||||||
<form method="post" action="<?php print $_SERVER['REQUEST_URI']; ?>">
|
<form method="post" action="<?php print $_SERVER['REQUEST_URI']; ?>">
|
||||||
|
<input type="hidden" name="action" value="update">
|
||||||
<table class="border">
|
<table class="border">
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php print $langs->trans("Label"); ?> :</td>
|
<td><?php print $langs->trans("Label"); ?> :</td>
|
||||||
|
|
||||||
<td><input type='text' size='25' id='nom' name ='nom' value='<?php
|
<td><input type='text' size='25' id='nom' name ='nom' value='<?php
|
||||||
print htmlspecialchars (stripslashes ($label), ENT_QUOTES);
|
print $categorie->label;
|
||||||
?>' />
|
?>' />
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php print $langs->trans("Description"); ?> :</td>
|
<td><?php print $langs->trans("Description"); ?> :</td>
|
||||||
|
|
||||||
<td><textarea name='description' cols='40' rows='6' id='description'><?php
|
<td><textarea name='description' cols='40' rows='6' id='description'><?php
|
||||||
print htmlspecialchars (stripslashes ($description), ENT_QUOTES);
|
print $categorie->description;
|
||||||
?></textarea></td>
|
?></textarea></td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<?php print $langs->trans("In"); ?>
|
<?php print $langs->trans("In"); ?>
|
||||||
<select name="choix">
|
<?php print $html->select_all_categories($categorie->id_mere);?>
|
||||||
<?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";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<tr>
|
<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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php
|
<?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>';
|
print '</td></tr></table>';
|
||||||
|
|||||||
@ -46,111 +46,30 @@ $html = new Form($db);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Action ajout d'un produit ou service
|
// Action ajout d'une catégorie
|
||||||
if ($_POST["action"] == 'add' && $user->rights->produit->creer)
|
if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
|
||||||
{
|
{
|
||||||
$categorie = new Categorie($db);
|
$categorie = new Categorie($db);
|
||||||
|
|
||||||
$categorie->label = stripslashes($_POST["nom"]);
|
$categorie->label = stripslashes($_POST["nom"]);
|
||||||
$categorie->description = stripslashes($_POST["description"]);
|
$categorie->description = stripslashes($_POST["description"]);
|
||||||
$cats_meres = isset($_POST['catsMeres']) ? $_POST['catsMeres'] : array();
|
if($_POST['catMere'] != "-1")
|
||||||
$ok = true;
|
$categorie->id_mere = stripslashes($_POST['catMere']);
|
||||||
|
|
||||||
|
|
||||||
if (!$categorie->label || !$categorie->description)
|
if (!$categorie->label || !$categorie->description)
|
||||||
{
|
{
|
||||||
$_GET["action"] = 'create';
|
$_GET["action"] = 'create';
|
||||||
$ok = false;
|
$categorie->error = "Le libellé ou la description n'a pas été renseigné";
|
||||||
}
|
}
|
||||||
|
if ($categorie->error =="")
|
||||||
if ($ok)
|
|
||||||
{
|
{
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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';
|
$_GET["action"] = 'confirmed';
|
||||||
$_POST["addcat"] = '';
|
$_POST["addcat"] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Fiche en mode création
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ($user->rights->produit->creer)
|
|
||||||
{
|
|
||||||
if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat')
|
|
||||||
{
|
|
||||||
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 '<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
|
* Action confirmation de création de la catégorie
|
||||||
*/
|
*/
|
||||||
@ -179,79 +98,42 @@ if ($user->rights->produit->creer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($user->rights->produit->creer)
|
||||||
print '</table>';
|
{
|
||||||
/*
|
/*
|
||||||
|
* Fiche en mode création
|
||||||
|
|
||||||
<?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"); ?> ?
|
|
||||||
<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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
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.'">';
|
||||||
|
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.'">';
|
||||||
|
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 $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>';
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print '</table>';
|
||||||
|
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user