diff --git a/server_static/assets/js/gestion_entreprises.js b/server_static/assets/js/gestion_entreprises.js index 90c682c..671435e 100644 --- a/server_static/assets/js/gestion_entreprises.js +++ b/server_static/assets/js/gestion_entreprises.js @@ -1,9 +1,11 @@ +var ID_company=0; + $(document).ready(function(){ $("#li_gestion_entreprises").delay(2000).addClass("hover"); $(".logo_add").click(function() { - $(".modal").show(); + $("#modal_add_edit").show(); $(".title_modal").html("Ajout d'une entreprise"); $("input[type='hidden']").attr("value","add"); $("input[name='name']").attr("value",""); @@ -14,24 +16,28 @@ $(document).ready(function(){ $(".info_message").css("display", "none"); }); - $(".close:eq(0)").click(function() { - $(".modal").hide(); + $("#close_add_edit").click(function() { + $("#modal_add_edit").hide(); }); window.onclick = function(event) { if (event.target == document.getElementById("modal_add_edit")) { - $(".modal").hide(); + $("#modal_add_edit").hide(); + } + if (event.target == document.getElementById("modal_stat")) { + $("#modal_stat").hide(); } } $('.form_add_edit').on('submit',(function(){ - $(".form_postuler").append(''); + $(".form_add_edit").append(''); return true; })); $(".logo_edit").click(function() { - $(".modal").show(); + $("#modal_add_edit").show(); + window.ID_company = $(this).attr("ID_company"); $(".title_modal").html("Modification d'une entreprise"); $("input[type='hidden']").attr("value","edit"); $("input[name='name']").attr("value",$(this).attr("name")); @@ -64,6 +70,14 @@ $(document).ready(function(){ ); }); + $(".logo_stat").click(function() { + console.log($(this).attr("ID_company")); + $("#modal_stat").show(); + }); + + $("#close_stat").click(function() { + $("#modal_stat").hide(); + }); diff --git a/website/controller/Manage_companies.php b/website/controller/Manage_companies.php index 21a733f..8c5a551 100644 --- a/website/controller/Manage_companies.php +++ b/website/controller/Manage_companies.php @@ -1,6 +1,7 @@ prepare('SELECT * FROM users NATURAL JOIN roles NATURAL JOIN roles_has_permissions NATURAL JOIN permissions WHERE code_permission="SFx1" AND username=:user AND password_user=:password_user;'); @@ -18,8 +19,9 @@ if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) { echo "false"; } } - } else if (isset($_POST["action"]) && isset($_POST["name"]) && isset($_POST["activity_sector"]) && isset($_POST["nb_intern_cesi"]) && isset($_POST["email"]) && isset($_POST["note"]) && isset($_POST["localisation"]) && isset($_POST["visibility"])) { - if ($_POST["action"] == "add"){ + } + if (isset($_POST["action"]) && isset($_POST["name"]) && isset($_POST["activity_sector"]) && isset($_POST["nb_intern_cesi"]) && isset($_POST["email"]) && isset($_POST["note"]) && isset($_POST["localisation"]) && isset($_POST["visibility"])) { + if ($_POST["action"] == "add"){ try { $query_add_company = $bdd->prepare('INSERT INTO companies VALUES (NULL, :name, :activity_sector, :nb_intern_CESI, :visibility, :email);'); $query_add_company->execute(['name' => $_POST["name"], 'activity_sector' => $_POST["activity_sector"], 'nb_intern_CESI' => $_POST["nb_intern_cesi"], 'visibility' => $_POST["visibility"], 'email' => $_POST["email"]]); @@ -28,14 +30,35 @@ if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) { $ID_add_company = $query_add_company->fetchALL(PDO::FETCH_OBJ)[0]->ID_company; $query_add_company = $bdd->prepare('INSERT INTO companies_located VALUES (:ID_localisation, :ID_company);'); $query_add_company->execute(['ID_localisation' => $_POST["localisation"], 'ID_company' => $ID_add_company]); - $query_add_company = $bdd->prepare('INSERT INTO companies_located VALUES (:ID_localisation, :ID_company);'); - $query_add_company->execute(['ID_localisation' => $_POST["localisation"], 'ID_company' => $ID_add_company]); + $query_add_company = $bdd->prepare('INSERT INTO evaluate VALUES (:ID_company, (SELECT ID_user FROM users WHERE username = :user), :note);'); + $query_add_company->execute(['ID_company' => $ID_add_company, 'user' => $_COOKIE['username'], 'note' => $_POST['note']]); echo ""; } catch (Exception $e) { echo "false"; } } } + if (isset($_POST["action"]) && isset($_POST["name"]) && isset($_POST["activity_sector"]) && isset($_POST["nb_intern_cesi"]) && isset($_POST["email"]) && isset($_POST["note"]) && isset($_POST["localisation"]) && isset($_POST["visibility"]) && isset($_POST["ID_company"])){ + if ($_POST["action"] == "edit"){ + try { + $ID_company = $_POST["ID_company"]; + $query_edit_company = $bdd->prepare('UPDATE evaluate SET note = :note WHERE ID_company = :ID_company;'); + $query_edit_company->execute(['note' => $_POST['note'], 'ID_company' => $ID_company]); + + $query_edit_company = $bdd->prepare('UPDATE companies_located SET ID_localisation = :localisation WHERE ID_company = :ID_company;'); + $query_edit_company->execute(['localisation' => $_POST['localisation'], 'ID_company' => $ID_company]); + + $query_edit_company = $bdd->prepare('UPDATE companies SET name_company = :name, activity_sector_company = :sector, nb_intern_cesi_company = :nb_intern, visibility_company = :visibility, email_company = :email WHERE ID_company=:ID_company;'); + $query_edit_company->execute(['name'=> $_POST['name'], 'sector' => $_POST['activity_sector'], 'nb_intern' => $_POST['nb_intern_cesi'], 'visibility' => $_POST['visibility'], 'email' => $_POST['email'], 'ID_company' => $ID_company]); + + echo ""; + } catch (Exception $e) { + echo $e; + } + } else { + echo "error"; + } + } } } } \ No newline at end of file diff --git a/website/gestion_entreprises.php b/website/gestion_entreprises.php index 3427a43..13816ac 100644 --- a/website/gestion_entreprises.php +++ b/website/gestion_entreprises.php @@ -29,7 +29,7 @@ if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) { + +
diff --git a/website/sw.js b/website/sw.js index 3502a1d..b0fe0e4 100644 --- a/website/sw.js +++ b/website/sw.js @@ -42,22 +42,31 @@ self.addEventListener('activate', evt => { ); }); -/*self.addEventListener('fetch', evt => { +self.addEventListener('fetch', evt => { evt.respondWith( caches.match(evt.request).then(cacheRes => { console.log(evt.request); - return cacheRes || fetch(evt.request).then(fetchRes => { - return caches.open(dynamicCacheName).then(cache => { - if (evt.request.url.indexOf('favoris') > -1){ + if(evt.request.url.indexOf("favoris") > -1){ + return fetch(evt.request).then(fetchRes => { + return caches.open(dynamicCacheName).then(cache => { cache.put(evt.request.url, fetchRes.clone()); - } - return fetchRes; - }) - }); + return cacheRes; + }) + }).catch(() => { + console.log("BLAAAAA", evt.request.url) + return cacheRes; + }); + } else { + return cacheRes || fetch(evt.request).then(fetchRes => { + return caches.open(dynamicCacheName).then(cache => { + return fetchRes; + }) + }); + } + }).catch(() => { console.log("Erreur d'accès à :", evt.request.url) return caches.match('/fallback.php'); }) ); -}); -*/ \ No newline at end of file +}); \ No newline at end of file