Suppression unset+fonction
Bonjour, je desire créer un tableau, rempli grace a une collection d'objet (un array donc). Jusqu'ici pas de probleme. Cependant j'ai ajouter une case a cocher a coté. Sur le click du bouton editer, tout objet cochés sont supprimé de la collection (du tableau).
J'ai d'abord tenter avec un unset, puis avec un array_splice. Mais rien n'y fait.
Si les j'arrive a supprimer les machines sur le premier click (avec le unset), si jen reselectionne une autre et que je la supprime, cette derniere disparait mais les autres reapparaisse ...
8O Pas compris ...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| if(isset($_POST['btn_edit'])){
if(isset($POST['affiche_t'])){
$cont = new control_modele;
foreach($_POST['affiche_t'] as $id_obj){
$obj=$cont->rechercher_collec($collec_type, $id_obj);
//$cont->supprimer_collec($collec_type, $obj->get_id());
unset($collec_type[$obj->get_id()]);
}
}
if(isset($_POST['affiche'])){
$cont = new control_modele;
foreach($_POST['affiche'] as $id_obj){
$obj=$cont->rechercher_collec($collec_machine, $id_obj);
//$cont->supprimer_collec($collec_machine[$obj->get_id()]);
unset($collec_machine[$obj->get_id()]);
}
}
if(isset($_POST['renom'])){
$cont = new control_modele;
foreach($_POST['renom'] as $id_obj){
$obj=$cont->rechercher_collec($collec_machine, $id_obj);
$obj=$cont->renommer_collec($obj, $_POST['renom_text_'.$obj->get_id()]);
}
}
}
require_once('../Interfaces/haut.php');
$entete = new entete();
$entete->afficher_entete('Modélisation', '2.Configuration');
echo '| <a href="import.php">1.Import</a> | <a href="configuration.php">2.Configuration</a> | 3.Modélisation | 4.Export |';
echo '<form action="configuration.php" enctype="multipart/form-data" method="post">';
echo '<table border="1">';
echo '<caption>Liaison(s)</caption>';
echo '<tr>';
echo '<th>Nom</th>';
echo '</tr>';
if(empty($collec_liaison)==false){
while(list($id, $obj) = each($collec_liaison)){
echo '<tr>';
echo '<td>'; echo $obj->get_nom(); echo '</td>';
echo '</tr>';
}
}
else{
echo '<tr>';
echo '<td>Pas de liaison</td>';
echo '</tr>';
}
echo '</table> ';
echo '<table border="1">';
echo '<caption>Réseau(x)</caption>';
echo '<tr>';
echo '<th>Réseau(x)</th>';
echo '<th>Type(s)</th>';
echo '<th>Machine(s)</th>';
echo '<th></th>';
echo '<th>Rennomer</th>';
echo '</tr>';
if(empty($collec_reseau)==false){
while(list($idr, $obj_res) = each($collec_reseau)){
echo '<tr>';
echo '<td>'; echo $obj_res->get_nom(); echo '</td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
$collec_type_bis=$collec_type;
if(empty($collec_type_bis)==false){
while(list($idt, $obj_type) = each($collec_type_bis)){
echo '<tr>';
echo '<td></td>';
echo '<td>'; echo $obj_type->get_nom(); echo '</td>';
echo '<td><input type="checkbox" name="affiche_t[]" value="'; echo $obj_type->get_id(); echo '" />Effacer</td>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
$collec_machine_bis=$collec_machine;
if(empty($collec_machine_bis)==false){
while(list($idm, $objm) = each($collec_machine_bis)){
if($objm->get_id_reseau()==$obj_res->get_id()){
if($objm->get_no_type()==$obj_type->get_id()){
echo '<tr>';
echo '<td></td>';
echo '<td></td>';
echo '<td>'; echo $objm->get_nom(); echo '</td>';
echo '<td><input type="checkbox" name="affiche[]" value="'; echo $objm->get_id(); echo '" />Effacer</td>';
echo '<td><input type="checkbox" name="renom[]" value="'; echo $objm->get_id(); echo '" /><input type="text" name="renom_text_'; echo $objm->get_id(); echo '" value="'; echo $objm->get_nom(); echo '" /></td>';
echo '</tr>';
}
}
}
}
else{
echo '<tr>';
echo '<td></td>';
echo '<td></td>';
echo '<td>Pas de machine(s)</td>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
}
}
}
else{
echo '<tr>';
echo '<td></td>';
echo '<td>Pas de type</td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
}
}
}
else{
echo '<tr>';
echo '<td>Pas de réseau</td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
}
echo '</table> ';
echo '<input type="submit" name="btn_edit" value="Editer" />';
echo '</form>'; |
Probleme de reapparition resolu, je reloadais la meme collection au debut dans mes variable session (normal), mais je ne les mettait pas a jour, donc le prog me relancer la collec initial a chaque fois...
Nouveau probleme: Le unset ne semble pas fonctionner dans une fonction ... ??
Probleme resolu... Je n'utilise pas unset, ni array_splice mais une fonction perso ...