From d8c52929dbadc733e9b06a5eae8076b914a05fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=88GUE?= <olivier.begue@ensiie.fr> Date: Sun, 12 May 2019 13:28:55 +0200 Subject: [PATCH] Correction MVC --- .../src/Controller/commande_form.php | 155 ----------------- .../src/{Model => Controller}/login.php | 0 .../src/{Model => Controller}/logout.php | 0 .../{Model => Controller}/set_commande.php | 0 .../{Model => Controller}/set_utilisateur.php | 6 +- .../src/{Controller => View}/arise_button.php | 0 ...{panel_commande.php => commande_finie.php} | 0 ensiie-project/src/View/commande_form.php | 161 ++++++++++++++++++ .../{Controller => View}/connexion_bouton.php | 4 +- .../{Controller => View}/connexion_form.php | 2 +- ensiie-project/src/View/not_connected.php | 8 +- ensiie-project/src/View/selection_repas.php | 10 -- ensiie-project/src/index.php | 11 +- 13 files changed, 178 insertions(+), 179 deletions(-) delete mode 100644 ensiie-project/src/Controller/commande_form.php rename ensiie-project/src/{Model => Controller}/login.php (100%) rename ensiie-project/src/{Model => Controller}/logout.php (100%) rename ensiie-project/src/{Model => Controller}/set_commande.php (100%) rename ensiie-project/src/{Model => Controller}/set_utilisateur.php (80%) rename ensiie-project/src/{Controller => View}/arise_button.php (100%) rename ensiie-project/src/View/{panel_commande.php => commande_finie.php} (100%) create mode 100644 ensiie-project/src/View/commande_form.php rename ensiie-project/src/{Controller => View}/connexion_bouton.php (87%) rename ensiie-project/src/{Controller => View}/connexion_form.php (81%) delete mode 100644 ensiie-project/src/View/selection_repas.php diff --git a/ensiie-project/src/Controller/commande_form.php b/ensiie-project/src/Controller/commande_form.php deleted file mode 100644 index 2150df9..0000000 --- a/ensiie-project/src/Controller/commande_form.php +++ /dev/null @@ -1,155 +0,0 @@ -<html> -<body> -<div class="panel-body"> - <form action="../Model/set_commande.php" method="POST"> - <?php - $current_commande['food_type_id'] = 0; - $current_commande['sauces_count'] = 0; - $current_commande['meats_choice'] = 0; - $current_commande['size_choice'] = 0; - - foreach ($foods as $food_id => $food) - { - if ($current_commande['food_type_id'] != $food['food_type_id']) - { - if ($current_commande['food_type_id'] != 0) - { - if ($current_commande['meats_choice'] != 0 || $current_commande['sauces_count'] != 0 || $current_commande['size_choice'] != 0) - {?> - <div id=<?php echo 'hidden-'.$current_commande['food_type_id']?> class="well" style="margin: 15px 10px;"> - <?php - if ($current_commande['sauces_count'] != 0) - display_sauces($current_commande['food_type_id'], $current_commande['sauces_count']); - if ($current_commande['meats_choice'] != 0 && $current_commande['sauces_count'] != 0) - echo '<br/>'; - if ($current_commande['meats_choice'] != 0) - display_meats($current_commande['food_type_id']); - if ($current_commande['size_choice'] != 0) - display_sizes($current_commande['food_type_id']); - echo '</div>'; - } - }?> - - <div class="input-group"> - <label for=<?php echo $food['food_type_id'] ?>:food class="input-group-addon"><?php echo $food['food_type_title']?></label> - <select name=<?php echo $food['food_type_id']?>:food class="form-control" data-food-type=<?php echo $food['food_type_id']?>> - <option value="0">Cliquez pour voir les choix</option> - <?php - $current_commande['food_type_id'] = $food['food_type_id']; - $current_commande['sauces_count'] = $food['sauces_count']; - $current_commande['meats_choice'] = $food['meats_choice']; - $current_commande['size_choice'] = $food['size_choice']; - } - if ($food['price'] != 0) - {?> - <option value=<?php echo $food_id?> data-max-meats=<?php echo $food['meats_count']?>><?php echo $food['food_title'].":".$food['price']."€"?></option>'; - <?php - } - else - {?> - <option value=<?php echo $food_id?> data-max-meats=<?php $food['meats_count']?>><?php echo $food['food_title']?></option> - <?php - } - echo '</div>'; - - if ($current_commande['meats_choice'] != 0 || $current_commande['sauces_count'] != 0 || $current_commande['size_choice'] != 0) - { - echo '<div id="hidden-'.$current_commande['food_type_id'].'" class="well" style="margin: 15px 10px;">'; - if ($current_commande['sauces_count'] != 0) - display_sauces($current_commande['food_type_id'], $current_commande['sauces_count']); - if ($current_commande['meats_choice'] != 0 && $current_commande['sauces_count'] != 0) - echo '<br/>'; - if ($current_commande['meats_choice'] != 0) - display_meats($current_commande['food_type_id']); - if ($current_commande['size_choice'] != 0) - display_sizes($current_commande['food_type_id']); - echo '</div>'; - echo '<hr/>';?> - <input type="hidden" name="submitted"/> - <button class="btn btn-primary btn-block btn-lg" type="submit">Commander</button> - <?php - } - }?> - </form> -</div> - - -<script type="text/javascript"> -var current_max_meats = 0; - -$('select').change(function () -{ - var food_type_id = $(this).attr('data-food-type'); - var parent_sauces = $('#sauce-checkboxes-'+food_type_id).attr('id'); - var parent_meats = $('#meat-checkboxes-'+food_type_id).attr('id'); - current_max_meats = parseInt($('select[name="'+$(this).attr('name')+'"] option:selected').attr('data-max-meats')); - - if ($(this).val() === "0") { - $("#hidden-"+food_type_id).slideUp(200); - refresh_sauce_checkboxes(parent_sauces, true); - refresh_meat_checkboxes(parent_meats, true); - } - else - $("#hidden-"+food_type_id).slideDown(200); - - if ($(this).val() === "0") - $('#meat-message-'+food_type_id).html('<strong>Choisissez votre ou vos viandes :</strong>'); - else - if (current_max_meats === 1) - $('#meat-message-'+food_type_id).html('<strong>Choisissez votre viande :</strong>'); - else - $('#meat-message-'+food_type_id).html('<strong>Choisissez vos viandes <span class="text-danger">('+current_max_meats+' au maximum)</span> :</strong>'); - - refresh_meat_checkboxes(parent_meats); -}) - -$('input[type="checkbox"]').click(function () -{ - var parent_sauces = $(this).parents('[id^="sauce-checkboxes-"]').attr('id'); - refresh_sauce_checkboxes(parent_sauces); - - var parent_meats = $(this).parents('[id^="meat-checkboxes-"]').attr('id'); - refresh_meat_checkboxes(parent_meats); -}) - -$('[id^="reset-sauces-"]').click(function () -{ - var id_div = $(this).attr('data-food-type'); - refresh_sauce_checkboxes('sauce-checkboxes-'+id_div, true); -}) - -$('[id^="reset-meats-"]').click(function () -{ - var id_div = $(this).attr('data-food-type'); - refresh_meat_checkboxes('meat-checkboxes-'+id_div, true); -}) - -function refresh_sauce_checkboxes(parent_sauces, clear=false) -{ - var number_checked_sauces = $('#'+parent_sauces+' input[type="checkbox"]:checked').length; - - if (number_checked_sauces > 2 || clear) - $('#'+parent_sauces+' input[type="checkbox"]').prop('checked', false).prop('disabled', false); - else if (number_checked_sauces === 2) - $('#'+parent_sauces+' input[type="checkbox"]').not(':checked').prop('disabled', true); - else - $('#'+parent_sauces+' input[type="checkbox"]').not(':checked').prop('disabled', false); -} - -function refresh_meat_checkboxes(parent_meats, clear=false) -{ - var number_checked_meats = $('#'+parent_meats+' input[type="checkbox"]:checked').length; - - if (number_checked_meats > current_max_meats || clear) - $('#'+parent_meats+' input[type="checkbox"]').prop('checked', false).prop('disabled', false); - else if (number_checked_meats === current_max_meats) - $('#'+parent_meats+' input[type="checkbox"]').not(':checked').prop('disabled', true); - else - $('#'+parent_meats+' input[type="checkbox"]').not(':checked').prop('disabled', false); -} - -$('[id^="hidden-"]').hide(); -</script> - -</body> -</html> \ No newline at end of file diff --git a/ensiie-project/src/Model/login.php b/ensiie-project/src/Controller/login.php similarity index 100% rename from ensiie-project/src/Model/login.php rename to ensiie-project/src/Controller/login.php diff --git a/ensiie-project/src/Model/logout.php b/ensiie-project/src/Controller/logout.php similarity index 100% rename from ensiie-project/src/Model/logout.php rename to ensiie-project/src/Controller/logout.php diff --git a/ensiie-project/src/Model/set_commande.php b/ensiie-project/src/Controller/set_commande.php similarity index 100% rename from ensiie-project/src/Model/set_commande.php rename to ensiie-project/src/Controller/set_commande.php diff --git a/ensiie-project/src/Model/set_utilisateur.php b/ensiie-project/src/Controller/set_utilisateur.php similarity index 80% rename from ensiie-project/src/Model/set_utilisateur.php rename to ensiie-project/src/Controller/set_utilisateur.php index f90bcdb..8c196a3 100644 --- a/ensiie-project/src/Model/set_utilisateur.php +++ b/ensiie-project/src/Controller/set_utilisateur.php @@ -3,8 +3,8 @@ if (isset($_SESSION['login'])) { //$db_utilisateur = NULL; // TODO Appel à la base pour récupérer l'utilisateur selon son ariseID = $_SESSION['login'] - //$utilisateur = new Utilisateur($db_utilisateur['ariseID'],$db_utilisateur['prenom'],$db_utilisateur['nom'],$db_utilisateur['pseudo'],$db_utilisateur['isAdmin']); - //$utilisateur->setCommandes($db_utilisateur['commandes']); + //$utilisateur = new Utilisateur($db_utilisateur['ariseID'],$db_utilisateur['prenom'],$db_utilisateur['nom'],$db_utilisateur['pseudo'],$db_utilisateur['isAdmin'],$db_utilisateur['commandes']); + if ($_SESSION['login'] == "begue2018") { $utilisateur = new Utilisateur($_SESSION['login'],"Olivier","BEGUE","Jed",FALSE,array()); @@ -15,7 +15,7 @@ if (isset($_SESSION['login'])) } elseif ($_SESSION['login'] == "invite") { - $utilisateur = new Utilisateur($_SESSION['login'],"Invité","","",FALSE,array()); + $utilisateur = new Utilisateur($_SESSION['login'],"","","Invité",FALSE,array()); } else { diff --git a/ensiie-project/src/Controller/arise_button.php b/ensiie-project/src/View/arise_button.php similarity index 100% rename from ensiie-project/src/Controller/arise_button.php rename to ensiie-project/src/View/arise_button.php diff --git a/ensiie-project/src/View/panel_commande.php b/ensiie-project/src/View/commande_finie.php similarity index 100% rename from ensiie-project/src/View/panel_commande.php rename to ensiie-project/src/View/commande_finie.php diff --git a/ensiie-project/src/View/commande_form.php b/ensiie-project/src/View/commande_form.php new file mode 100644 index 0000000..96b2e4a --- /dev/null +++ b/ensiie-project/src/View/commande_form.php @@ -0,0 +1,161 @@ +<!DOCTYPE html> +<html> +<body> +<div class="panel panel-default"> + <div class="panel-heading text-center"> + <strong>Choisissez votre repas ! • Plus de détails <a href="http://www.obigdelice.fr">ici</a></strong><br/> + <small>(Pour commander la même chose plusieurs fois, faites une nouvelle commande)</small> + </div> + <div class="panel-body"> + <form action="../Controller/set_commande.php" method="POST"> + <?php + $current_commande['food_type_id'] = 0; + $current_commande['sauces_count'] = 0; + $current_commande['meats_choice'] = 0; + $current_commande['size_choice'] = 0; + + foreach ($foods as $food_id => $food) + { + if ($current_commande['food_type_id'] != $food['food_type_id']) + { + if ($current_commande['food_type_id'] != 0) + { + if ($current_commande['meats_choice'] != 0 || $current_commande['sauces_count'] != 0 || $current_commande['size_choice'] != 0) + {?> + <div id=<?php echo 'hidden-'.$current_commande['food_type_id']?> class="well" style="margin: 15px 10px;"> + <?php + if ($current_commande['sauces_count'] != 0) + display_sauces($current_commande['food_type_id'], $current_commande['sauces_count']); + if ($current_commande['meats_choice'] != 0 && $current_commande['sauces_count'] != 0) + echo '<br/>'; + if ($current_commande['meats_choice'] != 0) + display_meats($current_commande['food_type_id']); + if ($current_commande['size_choice'] != 0) + display_sizes($current_commande['food_type_id']); + echo '</div>'; + } + }?> + + <div class="input-group"> + <label for=<?php echo $food['food_type_id'] ?>:food class="input-group-addon"><?php echo $food['food_type_title']?></label> + <select name=<?php echo $food['food_type_id']?>:food class="form-control" data-food-type=<?php echo $food['food_type_id']?>> + <option value="0">Cliquez pour voir les choix</option> + <?php + $current_commande['food_type_id'] = $food['food_type_id']; + $current_commande['sauces_count'] = $food['sauces_count']; + $current_commande['meats_choice'] = $food['meats_choice']; + $current_commande['size_choice'] = $food['size_choice']; + } + if ($food['price'] != 0) + {?> + <option value=<?php echo $food_id?> data-max-meats=<?php echo $food['meats_count']?>><?php echo $food['food_title'].":".$food['price']."€"?></option>'; + <?php + } + else + {?> + <option value=<?php echo $food_id?> data-max-meats=<?php $food['meats_count']?>><?php echo $food['food_title']?></option> + <?php + } + echo '</div>'; + + if ($current_commande['meats_choice'] != 0 || $current_commande['sauces_count'] != 0 || $current_commande['size_choice'] != 0) + { + echo '<div id="hidden-'.$current_commande['food_type_id'].'" class="well" style="margin: 15px 10px;">'; + if ($current_commande['sauces_count'] != 0) + display_sauces($current_commande['food_type_id'], $current_commande['sauces_count']); + if ($current_commande['meats_choice'] != 0 && $current_commande['sauces_count'] != 0) + echo '<br/>'; + if ($current_commande['meats_choice'] != 0) + display_meats($current_commande['food_type_id']); + if ($current_commande['size_choice'] != 0) + display_sizes($current_commande['food_type_id']); + echo '</div>'; + echo '<hr/>';?> + <input type="hidden" name="submitted"/> + <button class="btn btn-primary btn-block btn-lg" type="submit">Commander</button> + <?php + } + }?> + </form> + </div> +</div> + +<script type="text/javascript"> +var current_max_meats = 0; + +$('select').change(function () +{ + var food_type_id = $(this).attr('data-food-type'); + var parent_sauces = $('#sauce-checkboxes-'+food_type_id).attr('id'); + var parent_meats = $('#meat-checkboxes-'+food_type_id).attr('id'); + current_max_meats = parseInt($('select[name="'+$(this).attr('name')+'"] option:selected').attr('data-max-meats')); + + if ($(this).val() === "0") { + $("#hidden-"+food_type_id).slideUp(200); + refresh_sauce_checkboxes(parent_sauces, true); + refresh_meat_checkboxes(parent_meats, true); + } + else + $("#hidden-"+food_type_id).slideDown(200); + + if ($(this).val() === "0") + $('#meat-message-'+food_type_id).html('<strong>Choisissez votre ou vos viandes :</strong>'); + else + if (current_max_meats === 1) + $('#meat-message-'+food_type_id).html('<strong>Choisissez votre viande :</strong>'); + else + $('#meat-message-'+food_type_id).html('<strong>Choisissez vos viandes <span class="text-danger">('+current_max_meats+' au maximum)</span> :</strong>'); + + refresh_meat_checkboxes(parent_meats); +}) + +$('input[type="checkbox"]').click(function () +{ + var parent_sauces = $(this).parents('[id^="sauce-checkboxes-"]').attr('id'); + refresh_sauce_checkboxes(parent_sauces); + + var parent_meats = $(this).parents('[id^="meat-checkboxes-"]').attr('id'); + refresh_meat_checkboxes(parent_meats); +}) + +$('[id^="reset-sauces-"]').click(function () +{ + var id_div = $(this).attr('data-food-type'); + refresh_sauce_checkboxes('sauce-checkboxes-'+id_div, true); +}) + +$('[id^="reset-meats-"]').click(function () +{ + var id_div = $(this).attr('data-food-type'); + refresh_meat_checkboxes('meat-checkboxes-'+id_div, true); +}) + +function refresh_sauce_checkboxes(parent_sauces, clear=false) +{ + var number_checked_sauces = $('#'+parent_sauces+' input[type="checkbox"]:checked').length; + + if (number_checked_sauces > 2 || clear) + $('#'+parent_sauces+' input[type="checkbox"]').prop('checked', false).prop('disabled', false); + else if (number_checked_sauces === 2) + $('#'+parent_sauces+' input[type="checkbox"]').not(':checked').prop('disabled', true); + else + $('#'+parent_sauces+' input[type="checkbox"]').not(':checked').prop('disabled', false); +} + +function refresh_meat_checkboxes(parent_meats, clear=false) +{ + var number_checked_meats = $('#'+parent_meats+' input[type="checkbox"]:checked').length; + + if (number_checked_meats > current_max_meats || clear) + $('#'+parent_meats+' input[type="checkbox"]').prop('checked', false).prop('disabled', false); + else if (number_checked_meats === current_max_meats) + $('#'+parent_meats+' input[type="checkbox"]').not(':checked').prop('disabled', true); + else + $('#'+parent_meats+' input[type="checkbox"]').not(':checked').prop('disabled', false); +} + +$('[id^="hidden-"]').hide(); +</script> + +</body> +</html> \ No newline at end of file diff --git a/ensiie-project/src/Controller/connexion_bouton.php b/ensiie-project/src/View/connexion_bouton.php similarity index 87% rename from ensiie-project/src/Controller/connexion_bouton.php rename to ensiie-project/src/View/connexion_bouton.php index 3afe81a..8c59b69 100644 --- a/ensiie-project/src/Controller/connexion_bouton.php +++ b/ensiie-project/src/View/connexion_bouton.php @@ -26,10 +26,10 @@ else <script> function login() { - window.location.href = "Controller/connexion_form.php" + window.location.href = "View/connexion_form.php" } function logout() { - window.location.href = "Model/logout.php" + window.location.href = "Controller/logout.php" } </script> diff --git a/ensiie-project/src/Controller/connexion_form.php b/ensiie-project/src/View/connexion_form.php similarity index 81% rename from ensiie-project/src/Controller/connexion_form.php rename to ensiie-project/src/View/connexion_form.php index f4ecc6c..b4d991b 100644 --- a/ensiie-project/src/Controller/connexion_form.php +++ b/ensiie-project/src/View/connexion_form.php @@ -5,7 +5,7 @@ </head> <body> -<form action="../Model/login.php" method="post"> +<form action="../Controller/login.php" method="post"> Votre login : <input type="text" name="login"> <br/> Votre mot de passe : <input type="password" name="pwd"><br /> diff --git a/ensiie-project/src/View/not_connected.php b/ensiie-project/src/View/not_connected.php index fe4ec4c..ea1ff08 100644 --- a/ensiie-project/src/View/not_connected.php +++ b/ensiie-project/src/View/not_connected.php @@ -1,7 +1,11 @@ <html> <body> -<div class="text-center"> - <div><strong class="text-danger">Merci de vous identifier à AriseID pour commander !</strong></div> +<div class="panel panel-default"> + <div class="panel-body"> + <div class="text-center"> + <div><strong class="text-danger">Merci de vous identifier pour commander !</strong></div> + </div> + </div> </div> </body> </html> \ No newline at end of file diff --git a/ensiie-project/src/View/selection_repas.php b/ensiie-project/src/View/selection_repas.php deleted file mode 100644 index e7ef586..0000000 --- a/ensiie-project/src/View/selection_repas.php +++ /dev/null @@ -1,10 +0,0 @@ -<!DOCTYPE html> -<html> -<body> -<div class="panel panel-default"> - <div class="panel-heading text-center"> - <strong>Choisissez votre repas ! • Plus de détails <a href="http://www.obigdelice.fr">ici</a></strong><br/> - <small>(Pour commander la même chose plusieurs fois, faites une nouvelle commande)</small> - </div> -</body> -</html> \ No newline at end of file diff --git a/ensiie-project/src/index.php b/ensiie-project/src/index.php index 181dc8e..065c169 100644 --- a/ensiie-project/src/index.php +++ b/ensiie-project/src/index.php @@ -6,7 +6,7 @@ require_once('Model/Classes/Commande.php'); require_once('Model/Classes/Evenement.php'); require_once('Model/Classes/Menu.php'); require_once('Model/Classes/Special.php'); -require_once("Model/set_utilisateur.php"); +require_once("Controller/set_utilisateur.php"); require_once('Model/infos_njv.php'); include('View/page_titre.php'); @@ -15,15 +15,14 @@ include('View/head.php'); include('View/body_titre.php'); -include("Controller/connexion_bouton.php"); +include("View/connexion_bouton.php"); -include('View/accueil_utilisateur.php'); +include('View/deadline_commande.php'); if ($utilisateur != NULL) { - include('View/deadline_commande.php'); - include('View/panel_commande.php'); - include('Controller/commande_form.php'); + include('View/commande_finie.php'); + include('View/commande_form.php'); } else { -- GitLab