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
| <?php
//secure
$token = md5(uniqid(mt_rand(), true));
if(isset($_POST['tok']) && $_POST['tok'] === $token){
header("Location: http://www.example.com/page.php"); //ce qui rafraichira ta page... //après le submit
}
// Permet de créer un nouveau traitement
function creation_traitement($liste_param) {
// Info-bulles d'aide à la saisie
$info_nom = 'Veuillez rentrer le nom du nouveau traitement';
$info_chemin = 'Veuillez rentrer le chemin du traitement ou laisser vide si le chemin n\'est pas encore effectif';
$info_description = 'Veuillez rentrer la description du traitement ou laisser vide si aucune description à apporter';
echo '<form method="post" name="form_ajout_traitement">';
echo '<fieldset><input name="tok" type="hidden" value="' . $token . '"/>';
echo '<table><tr><td>';
echo '<label id="Nom du traitement" name="Nom du traitement">Nom du traitement</label>';
echo '</td><td>';
echo '<input id="nomTraitement" name="nomTraitement" title="'.$info_nom.'">';
echo '</td></tr>';
echo '<tr><td>';
echo '<label id="Chemin du traitement" name="Chemin du traitement">Chemin du traitement</label>';
echo '</td><td>';
echo '<input id="cheminTraitement" name="cheminTraitement" title="'.$info_chemin.'">';
echo '</td></tr>';
echo '<tr><td>';
echo '<label id="Description du traitement" name="Description du traitement">Description du traitement</label>';
echo '</td><td>';
echo '<input id="descriptionTraitement" name="descriptionTraitement" title="'.$info_description.'">';
echo '<tr><td>';
echo '<label id="Parametre du traitement" name="Parametre du traitement">Paramètres du traitement</label>';
echo '</td></tr>';
echo '<table>';
for ($i = 0; $i < count($liste_param); $i++) {
echo '<tr><td>';
echo '<input type="checkbox" name="params[]" id="params" value="'.$liste_param[$i][0].'">'.$liste_param[$i][2];
echo '</td><td>';
echo '<input type="radio" name="obli_creat_'.$i.'" id="obligatoire'.$i.'" value="obligatoire'.$i.'" checked>obligatoire';
echo '<input type="radio" name="obli_creat_'.$i.'" id="facultatif'.$i.'" value="facultatif'.$i.'">facultatif';
echo '</td></tr>';
}
echo '</table>';
echo '</table>';
echo '</br>';
echo '<input type="submit" value="valider_nouveau_traitement" name="Valider" onClick="return verif_form_ajout_traitement()">';
echo '</fieldset>';
echo '</form>';
// Vérification de l'appui sur le bouton 'valider'
if (isset($_POST['valider_nouveau_traitement'])) {
// Récupération du nom du traitement
$nom_traitement = $_POST['nomTraitement'];
// Récupération du chemin du traitement
$chemin_traitement = ($_POST['cheminTraitement'] == null ? "plustard" : $_POST['cheminTraitement']);
// Récupération de la description du traitement
$description_traitement = ($_POST['descriptionTraitement'] == null ? null : $_POST['descriptionTraitement']);
// Récupération du/des paramètre(s) du traitement
if (!empty($_POST['params'])) {
$oblig_facult = null;
$param = null;
$r_param = $_POST['params'];
$param_text = implode('&#', $r_param);
$lesParams = explode('&#', $param_text);
for ($i = 0; $i < count($lesParams); $i++) {
$param .= $lesParams[$i];
// Récupération de l'obligation ou non de remplir ce champ
$oblig_facult .= $_POST['obli_creat_'.$lesParams[$i]];
if (count($lesParams) > 1 AND $i < count($lesParams)-1) {
$param .= ';';
$oblig_facult .= ';';
}
}
} else {
$param = null;
$oblig_facult = null;
}
$resultat = $nom_traitement.'&#'.$chemin_traitement.'&#'.$description_traitement.'&#'.$param.'&#'.$oblig_facult;
} else {
$resultat = null;
}
return $resultat;
} |
Partager