stany.ferer 2 лет назад
Родитель
Сommit
3592cdd019

+ 2 - 1
access.inc.php

@@ -5,7 +5,8 @@
             "login",
             "login-salarie",
             "login-control",
-            "spash-screen"
+            "spash-screen",
+            "maintenance"
         ),
         "json" => array(
             "login",

+ 5 - 0
conf.inc.php

@@ -42,3 +42,8 @@ define("FICHE_SALARIE_PROWEB", "https://www.cse-invent.com/gestion/beneficiaire/
 
 // Emargement
 define("EMEMARGEMENT_END", 1800); // Possibilité de s'émarger 1800 secondes soit 30 minutes après l'évènements
+
+// Backup
+define("BACKUP_LIMIT", 15); // nombre de backup max
+define("FILE_MAINTENANCE", ".lock-maintenance");
+define("FILE_DEBUG", ".active-debug");

+ 21 - 9
core/class/backup.class.php

@@ -13,8 +13,10 @@ class backup
             $localZip = file::zip($newFolder, DIR_TEMP . $nameNewFolder);
             file::deleteFolder($newFolder);
             rename($localZip, DIR_BACKUP . $nameNewFolder . ".zip");
+            alert::recSuccess("BackUp OK :. " . $nameNewFolder . ".zip");
             return TRUE;
         } catch (Exception $ex) {
+            alert::recError("BackUp :. Erreur lors de la création");
             return FALSE;
         }
     }
@@ -32,9 +34,12 @@ class backup
                 file::deleteFolder(DIR_TEMP . $tmpDatas);
                 unlink($tmpZip);
                 file::deleteFolder(DIR_TEMP . $folder);
-            }
-            return TRUE;
+                $zipInfo = pathinfo($_zip);
+                alert::recSuccess("Restauration du backUp OK :. " . $zipInfo["filename"] . ".zip");
+                return TRUE;
+            } 
         }
+        alert::recError("Restauration du backUp :. Erreur lors du backup");
         return FALSE;
     }
 
@@ -61,13 +66,20 @@ class backup
         }
     }
 
-    public static function jsonRestore()
+    public static function scanFolder()
     {
-        json::create("salaries");
-        json::create("excel");
-        json::create("excel-proweb");
-        json::create("events");
-        json::create("users");
-        json::create("salaries-proweb");
+        $tempArray = array();
+        if ($scandir = scandir(DIR_BACKUP)) {
+            foreach ($scandir as $file) {
+                $tempFile = NULL;
+                if (is_file(DIR_BACKUP . $file) === TRUE and $file != "index.html") {
+                    $tempFile["file"] = $file;
+                    $tempFile["size"] = core::formatFileSize(filesize(DIR_BACKUP . $file), 2);
+                    $tempFile["date"] = core::dateFromTimestamp(filemtime(DIR_BACKUP . $file));
+                    $tempArray[] = $tempFile;
+                }
+            }
+        }
+        return $tempArray;
     }
 }

+ 30 - 0
core/class/core.class.php

@@ -171,4 +171,34 @@ class core
         $date = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
         return $date->format(time()) . " à " . date("H:m:s");
     }
+
+    public static function addFileMaintenance(){
+        $myfile = fopen(DOCUMENT_ROOT . FILE_MAINTENANCE, "w");
+        fclose($myfile);
+    }
+
+    public static function removeFileMaintenance(){
+        unlink(DOCUMENT_ROOT . FILE_MAINTENANCE);
+    }
+
+    public static function isMaintenance(){
+        return (file_exists(DOCUMENT_ROOT . FILE_MAINTENANCE)) ? TRUE : FALSE;
+    }
+
+    public static function addFileDebug(){
+        $myfile = fopen(DOCUMENT_ROOT . FILE_DEBUG, "w");
+        fclose($myfile);
+    }
+
+    public static function removeFileDebug(){
+        unlink(DOCUMENT_ROOT . FILE_DEBUG);
+    }
+
+    public static function isDebug(){
+        return (file_exists(DOCUMENT_ROOT . FILE_DEBUG)) ? TRUE : FALSE;
+    }
+
+    public static function checkboxSelecter(bool $_val){
+        echo ($_val == TRUE) ? "checked" : "";
+    }
 }

+ 10 - 5
core/controllers/header.php

@@ -2,12 +2,17 @@
     setlocale(LC_TIME, 'fr_FR');
     date_default_timezone_set(TIME_ZONE);
     
-    if(isset($_SESSION["debug"])){
-        error_reporting(E_ALL);
-        ini_set("display_errors", 1);
-    }
-    
     spl_autoload_register(function ($class_name) {
         (file_exists(DIR_PHP_CLASS.'/'.$class_name.'.class.php'))?	
         require_once DIR_PHP_CLASS.'/'.$class_name.'.class.php' : '';
     });
+
+    if(core::isDebug()){
+        error_reporting(E_ALL);
+        ini_set("display_errors", 1);
+    }
+
+    if(core::isMaintenance() AND $_SERVER['HTTP_HOST'] != DOMAIN_CMS){
+        get::page("maintenance");
+        exit();
+    }

+ 4 - 0
core/json/cms.host-restore.php

@@ -0,0 +1,4 @@
+<?php 
+
+$row = backup::scanFolder();
+echo json_encode($row);

+ 13 - 2
core/submit/cms.dev-debug-activation.php

@@ -1,4 +1,15 @@
 <?php
-$_SESSION["debug"] = 1;
-header('Location: /');
+if(core::ifGet("actif")){
+    if(core::getGet("actif") == "true"){
+        core::addFileDebug();
+        echo json_encode(array("1"));
+        alert::recSuccess("Le mode debug est activé");
+    } else {
+        core::removeFileDebug();
+        echo json_encode(array("0"));
+        alert::recSuccess("Le mode debug est déactivé");
+    }
+}
+
+header("Location: /host-parametres.html");
 exit();

+ 15 - 0
core/submit/cms.dev-maintenance-activation.php

@@ -0,0 +1,15 @@
+<?php
+if(core::ifGet("actif")){
+    if(core::getGet("actif") == "true"){
+        core::addFileMaintenance();
+        echo json_encode(array("1"));
+        alert::recSuccess("Le mode maintenance est activé");
+    } else {
+        core::removeFileMaintenance();
+        echo json_encode(array("0"));
+        alert::recSuccess("Le mode maintenance est déactivé");
+    }
+}
+
+header("Location: /host-parametres.html");
+exit();

+ 12 - 0
core/submit/cms.host-add-backup.php

@@ -0,0 +1,12 @@
+<?php
+
+if (core::ifGet("from")) {
+    backup::create();
+    file::cleanFilesByOrder(DIR_BACKUP, BACKUP_LIMIT);
+    header("Location: /host-restore.html");
+    exit();
+
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}

+ 8 - 0
core/submit/cms.host-download-backup-zip.php

@@ -0,0 +1,8 @@
+<?php
+
+if(core::ifPost("from")){
+    header('Content-type: application/octet-stream;');
+    header('Content-Transfer-Encoding: base64');
+    header('Content-Disposition: attachment; filename="'.core::getPost("file").'"');
+    readfile(DIR_BACKUP.core::getPost("file"));
+}

+ 11 - 0
core/submit/cms.host-restore-backup-zip.php

@@ -0,0 +1,11 @@
+<?php
+
+if (core::ifPost("from")) {
+    backup::restore(DIR_BACKUP . core::getPost("file"));
+    header("Location: /host-restore.html");
+    exit();
+
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}

+ 0 - 2
core/submit/cms.it-restore.php

@@ -1,2 +0,0 @@
-<?php
-

+ 6 - 2
core/views/_cms.menu.php

@@ -34,13 +34,17 @@
                     core::elementMenuLink("https://corporatedirectory.capgemini.com/MyDirectory/portals/std/index-portal.jsp", "Corporate Directory", "link");
                     core::elementMenuLink("https://".URL_DEV_CMS, "CMS de recette", "link");
                 }
+
+                if(session::accessUserByType(1)){ 
+                    core::elementMenuH6("Maintenance");
+                    core::elementMenu("host-restore", "/host-restore.html", "IT : Restauration des données", "tool");
+                    core::elementMenu("host-parametres", "/host-parametres.html", "IT : Paramètres", "tool"); 
+                }
                 
                 if(session::accessUserByType(1) AND session::getId() == 1 AND (ENVIRONNEMENT == "DEV" OR ENVIRONNEMENT == "PREPROD")){ 
                     core::elementMenuH6("Développement", "color:red");
-                    core::elementMenuLink("/submit.php?from=dev-debug-activation", "Activer la barre de débug", "tool", "color:red", "_top");
                     core::elementMenuLink("/submit.php?from=dev-reset-to-mysql", "Nettoyer les données", "tool", "color:red", "_top");
                     core::elementMenu("debug-info", "/dev-debug-info.html", "Informations de debug", "tool", "color:red");
-                    core::elementMenuLink("/test.php", "Page de test", "tool", "color:red");
                 }    
                     
                 

+ 16 - 4
core/views/_cms.nav.php

@@ -1,20 +1,32 @@
 <?php
 
     if(ENVIRONNEMENT == "DEV"){
-        $titleHead = "CSE Invent : Base des salariés <span class=\"badge\" style=\"background-color:red;\">DEV</span>";
+        $titleEnvironnement = "<a href=\"/\"><span class=\"badge\" style=\"background-color:red; margin-left:5px;\">DEV</span></a>";
         $classHead = "bg-secondary";
     } elseif(ENVIRONNEMENT == "PREPROD"){
-        $titleHead = "CSE Invent : Base des salariés <span class=\"badge\" style=\"background-color:red;\">PREPROD</span>";
+        $titleEnvironnement = "<a href=\"/\"><span class=\"badge\" style=\"background-color:red; margin-left:5px;\">PREPROD</span></a>";
         $classHead = "bg-secondary";
     } elseif(ENVIRONNEMENT == "PROD"){
-        $titleHead = "CSE Invent : Base des salariés";
+        $titleEnvironnement = "";
         $classHead = "bg-dark";
     }
+
+    if(core::isMaintenance()){
+        $titleMaintenance = "<a href=\"/host-parametres.html\"><span class=\"badge\" style=\"background-color:red; margin-left:5px;\">SITE EN MODE MAINTENANCE</span></a>";
+    } else {
+        $titleMaintenance = "";
+    }
+
+    if(core::isDebug()){
+        $titleDebug = "<a href=\"/host-parametres.html\"><span class=\"badge\" style=\"background-color:red; margin-left:5px;\">MODE DEBUG</span></a>";
+    } else {
+        $titleDebug = "";
+    }
     
 ?>
 <header class="navbar sticky-top <?php echo $classHead ?> navbar-expand-sm navbar-dark flex-md-nowrap p-0 shadow">
     <div class="container-fluid">
-        <a href="/" style="box-shadow: none;" class="navbar-brand <?php echo $classHead ?>"><?php echo $titleHead ?></a>
+        <a href="/" style="box-shadow: none;" class="navbar-brand <?php echo $classHead ?>">CSE Invent : Base des salariés</a><?php echo $titleEnvironnement . $titleMaintenance . $titleDebug; ?>
         <div id="navbarCollapse" class="collapse navbar-collapse p-0">
             <ul class="nav navbar-nav ms-auto">
                 <li class="nav-item dropdown">

+ 9 - 8
core/views/_events.head.php

@@ -1,13 +1,14 @@
 <!DOCTYPE html>
 <html lang="fr">
-    <head>
+
+<head>
         <meta charset="UTF-8">
         <title><?php echo TITLE ?></title>
-<?php 
-        require_once DIR_PHP_VIEWS . "_events.meta.php"; 
-?>  
+        <?php
+        require_once DIR_PHP_VIEWS . "_events.meta.php";
+        ?>
         <link rel="stylesheet" href="css/validator.css">
-        <link rel="stylesheet" href="libs/qrcode-reader/css/qrcode-reader.css"
-    </head>
-    <body class=" bg-info">
-        
+        <link rel="stylesheet" href="libs/qrcode-reader/css/qrcode-reader.css">
+</head>
+
+<body class=" bg-info">

+ 10 - 3
core/views/_events.nav.php

@@ -1,20 +1,27 @@
 <?php
     if(ENVIRONNEMENT == "DEV"){
-        $titleHead = "<span class=\"badge\" style=\"background-color:red; margin-left: -10px;\">DEV</span>";
+        $titleHead = "<span class=\"badge\" style=\"background-color:red; margin-left: 5px;\">DEV</span>";
     } elseif(ENVIRONNEMENT == "PREPROD"){
-        $titleHead = "<span class=\"badge\" style=\"background-color:red; margin-left: -10px;\">PREPROD</span>";
+        $titleHead = "<span class=\"badge\" style=\"background-color:red; margin-left: 5px;\">PREPROD</span>";
     } elseif(ENVIRONNEMENT == "PROD"){
         $titleHead = "";
     }
+
     if($_SERVER['HTTP_HOST'] == DOMAIN_EVENTS){
         $logoHead = "img/logo.png";
     } else {
         $logoHead = "img/logo-control.png";
     }
+
+    if(core::isDebug()){
+        $titleDebug = "<span class=\"badge\" style=\"background-color:red; margin-left:5px;\">MODE DEBUG</span>";
+    } else {
+        $titleDebug = "";
+    }
 ?>
 <nav class="navbar navbar-light bg-light lighten-4 shadow-lg">
+    <?php echo "<div style=\"margin: 0 0 0 120px; position: absolute;\">" . $titleHead . $titleDebug . "</div>"; ?>
     <img src="<?php echo $logoHead ?>" style="max-width: 80%;" id="icon" alt="CSE Invent" />
-    <?php echo $titleHead ?>
     <button class="navbar-toggler p-1" style="margin-right: 15px;" type="button" data-toggle="collapse" data-target="#navMenu" aria-controls="navbarSupportedContent1" aria-expanded="false">
         <span class="navbar-toggler-icon"></span>
     </button>

+ 1 - 2
core/views/pages/cms.evenements.php

@@ -1,6 +1,5 @@
 <?php
-    $json_file = new json();
-    $json_file->create("events");
+    json::create("events");
 ?>
 
 <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">

+ 41 - 0
core/views/pages/cms.host-parametres.php

@@ -0,0 +1,41 @@
+<?php
+$checkMaintenance = core::isMaintenance();
+$checkDebug = core::isDebug();
+?>
+
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+    <h2 class="bd-title" id="content">
+        <span>Paramètres</span>
+    </h2>
+</header>
+<?php
+echo core::filAriane(array(
+    "current" => "Paramètres",
+    "arbo" => array(
+        "Maintenance" => NULL,
+        "Paramètres" => "/host-parametres.html"
+    )
+));
+?>
+
+<h4>Général</h4>
+<div class="form-check form-switch">
+    <input class="form-check-input" type="checkbox" role="switch" id="checkMaintenance" <?php core::checkboxSelecter($checkMaintenance) ?>>
+    <label class="form-check-label" for="checkMaintenance">Site en mode maintenance (les salariés ne pourront plus faire d'action sur le site)</label>
+</div>
+<div class="form-check form-switch">
+    <input class="form-check-input" type="checkbox" role="switch" id="checkDebug" <?php core::checkboxSelecter($checkDebug) ?>>
+    <label class="form-check-label" for="checkDebug">Afficher les erreurs (débug)</label>
+</div>
+
+<script>
+    $(document).ready(function() {
+        $('#checkMaintenance').on('change', function() {
+            window.location.href = "/submit.php?from=dev-maintenance-activation&actif=" + $("#checkMaintenance").prop('checked');
+        });
+
+        $('#checkDebug').on('change', function() {
+            window.location.href = "/submit.php?from=dev-debug-activation&actif=" + $("#checkDebug").prop('checked');
+        });
+    });
+</script>

+ 50 - 0
core/views/pages/cms.host-restore.php

@@ -0,0 +1,50 @@
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+<h2 class="bd-title" id="content">
+    <span>Restauration des données</span>
+    <a href="/submit.php?from=host-add-backup" style="position: absolute; right: 0; margin: 0 40px 0 0;"><button type="submit" class="btn btn-outline-success btn-sm"><span data-feather="plus-square"></span> Créer un nouveau backup</button></a>
+</h2>
+</header>
+<?php   
+        echo core::filAriane(array(
+            "current" => "Restauration des données", 
+            "arbo" => array( 
+                "Maintenance" => NULL,
+                "Restauration des données" => "/host-restore.html")
+        )); 
+?>
+<div>
+    <table 
+        id="table" 
+        class="table-striped table-hover table-sm" 
+        data-toggle="table" 
+        data-sort-name="date" 
+        data-sort-order="desc" 
+        data-url="/json.php?jsonData=host-restore">
+        <thead>
+            <tr>
+                <th data-formatter="downloadFile" data-sortable="true" data-field="file" data-filter-control="input" data-align="left">Nom</th>
+                <th data-sortable="true" data-field="size" data-filter-control="input" data-width="100">Taille</th>
+                <th data-sortable="true" data-field="date" data-filter-control="input" data-width="170">Date de création</th>
+                <th data-formatter="restoreBackup" data-width="130"></th>
+            </tr>
+        </thead>
+    </table>
+</div>
+
+<script>
+    function downloadFile(value, row) {
+        return '<form method="post" action="/submit.php">\n\
+        <input type="hidden" name="from" value="host-download-backup-zip">\n\
+        <input type="hidden" name="file" value="' + row.file + '">\n\
+        <button type="submit" style="border:none; background:none;" title="Télécharger le fichier : ' + row.file + '">' + row.file + '</button>\n\
+        </form>';
+    }
+
+    function restoreBackup(value, row) {
+        return '<form method="post" action="/submit.php">\n\
+        <input type="hidden" name="from" value="host-restore-backup-zip">\n\
+        <input type="hidden" name="file" value="' + row.file + '">\n\
+        <button type="submit" onclick="return confirm(\'Etes-vous certain de vouloir restaurer cette version (données et fichiers) ?\')" class="btn btn-outline-danger btn-sm">Restaurer</button>\n\
+        </form>';
+    }
+</script>

+ 9 - 3
core/views/pages/events.login-salarie.php

@@ -1,17 +1,23 @@
 <?php
     if(ENVIRONNEMENT == "DEV"){
-        $titleHead = "<span class=\"badge\" style=\"background-color:red; position:fixed; margin: -30px 0 0 2em;\">DEV</span>";
+        $titleHead = "<span class=\"badge\" style=\"background-color:red;\">DEV</span>";
     } elseif(ENVIRONNEMENT == "PREPROD"){
-        $titleHead = "<span class=\"badge\" style=\"background-color:red; position:fixed; margin: -30px 0 0 2em;\">PREPROD</span>";
+        $titleHead = "<span class=\"badge\" style=\"background-color:red;\">PREPROD</span>";
     } elseif(ENVIRONNEMENT == "PROD"){
         $titleHead = "";
     }
+
+    if(core::isDebug()){
+        $titleDebug = "<span class=\"badge\" style=\"background-color:red; margin-top:5px;\">MODE DEBUG</span>";
+    } else {
+        $titleDebug = "";
+    }
 ?>
 <main class="login">
     <div class="login-form">
         <img src="img/logo.png" alt="logo">
         <form id="formLogin">
-            <?php echo $titleHead ?>
+            <?php echo "<div style=\"margin: -65px 0 0 2em; position: fixed;\">" . $titleHead . $titleDebug . "</div>"; ?>
             <div style="margin-bottom: -20px; display: none;" id="divAlerte"></div>
             <input type="hidden" id="from" name="from" value="login">
             <input type="hidden" id="event" name="event" value="<?php echo (core::ifGet("e")) ? core::getGet("e") : ""; ?>">

+ 18 - 0
core/views/pages/events.maintenance.php

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="fr">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+    <title>CSE Invent :. En maintenance</title>
+
+</head>
+
+<body>
+    <div style="width:100%; text-align:center; margin-top:150px;">
+        <img src="img/mini.png" alt="logo">
+        <div style="margin-top:20px; font-weight: bold; font-size:x-large;">EN MAINTENANCE</div>
+    </div>
+</body>
+
+</html>

+ 4 - 3
public-cms/test.php

@@ -9,11 +9,12 @@ require_once DIR_PHP_LAYOUTS . "header.php";
 error_reporting(E_ALL);
 ini_set('display_errors', 1);
 
-//echo backup::create();
+core::removeFileMaintenance();
+echo core::isMaintenance();
 
-echo backup::restore("/var/www/dev.cms.cse-invent.com/backups/20230503-124717.zip");
+// echo backup::create();
 
-//db::restoreBackupMysql(DIR_BACKUP."20230428161012.Mysql.gz");
+// echo backup::restore("/var/www/dev.cms.cse-invent.com/backups/20230503-124717.zip");
 
 /*
 function test($_host) {