Browse Source

CRON Email config, block info callout, banque

stany.ferer 1 year ago
parent
commit
4c5a1ced4c

+ 1 - 0
conf.inc.php

@@ -52,6 +52,7 @@ define("DB_T_DOCUMENT_FILES", "documents_files");
 define("DB_T_DOCUMENT_TAGS", "documents_tags");
 define("DB_T_TAGS", "tags");
 
+define("DB_T_ALERTES_EMAILS", "alertesEmails");
 define("DB_T_TYPE_TAGS", "type_tags");
 define("DB_T_TYPE_USER", "type_user");
 define("DB_T_TYPE_DOCUMENT", "type_document");

+ 12 - 0
core/class/banque.class.php

@@ -3,6 +3,18 @@
 class banque
 {
 
+    public static function lastRecord(int $_id)
+    {
+        db::query("SELECT "
+            . "creer "
+            . "FROM " . DB_T_BANQUE_LIGNES . " "
+            . "WHERE " . DB_T_BANQUE_LIGNES . ".id_compte = :id "
+            . "ORDER BY creer DESC "
+            . "LIMIT 1");
+            db::bind(':id', $_id);
+            return db::single()["creer"];
+    }
+    
     public static function getInitial(int $_id)
     {
         $tmp = self::getInitialCompte($_id );

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

@@ -438,6 +438,7 @@ class core
         if((access::ifAccesss("documents") AND session::getType() == 5) OR session::getType() == 1){ // Membre du bureau ou Admin
             $nb = $badge["DOC"] > 0 ? '<span class="position-absolute badge rounded-pill bg-danger" style="right:-10px; margin-top:-10px;">' . $badge["DOC"] . '</span>' : NULL;
             echo '<a href="/documents-my-assign.html" class="dropdown-item">Vos assignations' . $nb . '</a>';
+            echo '<a href="/alertes-emails.html" class="dropdown-item">Vos règles d\'alertes</a>';
         }
         echo '<div class="dropdown-divider"></div>';
         echo '<a href="/submit.php?from=logout" class="dropdown-item">Se déconnecter</a>';

+ 61 - 1
core/class/cron.class.php

@@ -8,7 +8,67 @@ class cron
 
     public static function sendMailAssignDocument(){
         foreach (document::assignMailDocument() as $assign) {
-            document::sendEmailCronAssign($assign);
+            if(self::checkParameter($assign["id"])){
+                document::sendEmailCronAssign($assign);
+            }
         }
     }
+
+    public static function insertParameter(array $_array){
+
+        $userId = session::getId();
+
+        db::query("DELETE FROM " . DB_T_ALERTES_EMAILS . " WHERE id_user = :id_user");
+        db::bind(':id_user', $userId);
+        db::execute();
+        
+        foreach ($_array as $heure => $tmp) { 
+            foreach ($tmp as $jour => $value) {
+                db::query("INSERT INTO " . DB_T_ALERTES_EMAILS . " (id, id_user, heure, jour) VALUES (:id, :id_user, :heure, :jour)");
+                db::bind(':id', $userId."#".$heure."#".$jour);
+                db::bind(':id_user', $userId);
+                db::bind(':heure', $heure);
+                db::bind(':jour', $jour);
+                
+                try {
+                    db::execute();
+                } catch (Exception $ex) {
+                    alert::recError("Erreur d'enregistrement des alertes");
+                    return FALSE;
+                }
+            }
+        }
+        alert::recSuccess("Enregistrement des alertes");
+        return TRUE;
+    }
+
+    public static function getParameter(float $_id = NULL){
+        $userId = is_null($_id) ? session::getId() : $_id;
+
+        db::query("SELECT "
+            . "" . DB_T_ALERTES_EMAILS . ".heure, "
+            . "" . DB_T_ALERTES_EMAILS . ".jour "
+            . "FROM " . DB_T_ALERTES_EMAILS . " "
+            . "WHERE id_user = :id_user");
+        db::bind(':id_user', $userId);
+        $tmp = db::resultset();
+
+        if(isset($tmp)){
+            $return = [];
+            foreach ($tmp as $value) {
+                $return[$value["heure"]][$value["jour"]] = 1;
+            }
+            return $return;
+        } else {
+            return NULL;
+        }
+        
+    }
+
+    public static function checkParameter(float $_id){
+        $data = self::getParameter($_id);
+        $jourSemaineOriginal = date('w');
+        $jourSemaineAdjuste = ($jourSemaineOriginal + 6) % 7; // Pour que le Lundi soit le numéro 0
+        return isset($data[date('G')][$jourSemaineAdjuste]) ? TRUE : FALSE;
+    }
 }

+ 10 - 0
core/submit/cms.alertes-emails.php

@@ -0,0 +1,10 @@
+<?php
+
+if(core::ifPost("from") AND core::getPost("from") == "alertes-emails"){
+    cron::insertParameter(core::getPost("heure"));
+} else {
+    alert::recError("Erreur de sécurité au submit");
+}
+header("Location: /alertes-emails.html");
+exit();
+

+ 81 - 0
core/views/pages/cms.alertes-emails.php

@@ -0,0 +1,81 @@
+<?php 
+    $paramAlert = cron::getParameter();
+?>
+
+<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ètrer l'envoie des alertes emails</span>
+    </h2>
+</header>
+<?php
+echo core::filAriane(array(
+    "current" => "Paramétrage des jours/heures",
+    "arbo" => array(
+        "Vos règles d'alertes" => NULL,
+        "Paramétrage des jours/heures" => "/alertes.html"
+    )
+));
+?>
+<style>
+    .table thead th {
+        text-align: center;
+    }
+    .table td, .table th {
+        text-align: center;
+    }
+    .hour-column {
+        font-weight: bold;
+    }
+</style>
+
+<div class="bd-callout bd-callout-info">
+    <h4>Description</h4>
+    <p>Cet espace permet de sélectionner les moments ou vous voulez générer et recevoir les alertes emails provenant du CMS. A ce jour cela ne concerne que les <a href="/documents-my-assign.html">documents à traiter</a>.</p>
+</div>
+
+<div class="tab-content">
+    <div class="form-group">
+        <form method="post" action="/submit.php">
+            <input type="hidden" name="from" value="alertes-emails">
+            <table class="table table-bordered table-striped">
+                <thead>
+                    <tr>
+                        <th></th>
+                        <th>Lundi</th>
+                        <th>Mardi</th>
+                        <th>Mercredi</th>
+                        <th>Jeudi</th>
+                        <th>Vendredi</th>
+                        <th>Samedi</th>
+                        <th>Dimanche</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    <!-- Heures de 00:00 à 23:00 -->
+                    <?php for ($i = 0; $i < 24; $i++): ?>
+                        <tr>
+                            <td class="hour-column"><?= str_pad($i, 2, '0', STR_PAD_LEFT) ?>:00</td>
+                            <?php for ($j = 0; $j < 7; $j++): ?>
+                                <td>
+                                    <input type="checkbox" name="heure[<?= $i ?>][<?= $j ?>]" value="1" <?php if(isset($paramAlert[$i][$j])){ echo "checked"; } ?>>
+                                </td>
+                            <?php endfor; ?>
+                        </tr>
+                    <?php endfor; ?>
+                    <tr>
+                        <td></td>
+                        <td class="fw-bold">Lundi</th>
+                        <th class="fw-bold">Mardi</td>
+                        <td class="fw-bold">Mercredi</td>
+                        <td class="fw-bold">Jeudi</td>
+                        <td class="fw-bold">Vendredi</td>
+                        <td class="fw-bold">Samedi</td>
+                        <td class="fw-bold">Dimanche</td>
+                    </tr>
+                </tbody>
+            </table>
+            <button class="btn btn-primary btn-lg" style="width: 100%" type="submit">Enregistrer</button>
+        </form>
+    </div>
+</div>
+<br />

+ 7 - 3
core/views/pages/cms.compte.php

@@ -19,13 +19,18 @@
         $etatCompte = banque::getEtatCompte(core::getGet("id"));
 
         echo core::filAriane(array(
-            "current" => $banque["label"] . " (" . banque::getEuro($etatCompte["solde"]) . " au " . core::convertDate($etatCompte["date"], FALSE). ")", 
+            "current" => $banque["label"], 
             "arbo" => array( 
                 "Comptes bancaires" => NULL,
-                $banque["label"] . " (" . banque::getEuro($etatCompte["solde"]) . " au " . core::convertDate($etatCompte["date"], FALSE) . ")" => "/compte-". core::getGet("id") .".html")
+                $banque["label"] => "/compte-". core::getGet("id") .".html")
         )); 
 ?>
 
+<div class="bd-callout bd-callout-info">
+    <h4>Note</h4>
+    <p>La dernier import des données du compte a été réalisée le <span class="fw-bold"><?php echo core::convertDate(banque::lastRecord(core::getGet("id"))) ?></span> et à cette même date le solde était de <span class="fw-bold"><?php echo banque::getEuro($etatCompte["solde"]) ?></span></p>
+</div>
+
 <div>
     <table
         id="table"
@@ -34,7 +39,6 @@
         data-page-size="25"
         data-pagination="true"
         data-show-footer="true"
-        data-search="true"
         data-buttons-align="left"
         data-filter-control="true"
         data-flat="true"

+ 7 - 3
core/views/pages/cms.documents-my-assign.php

@@ -14,18 +14,22 @@
         echo core::filAriane(array(
             "current" => "Listes des documents à traiter", 
             "arbo" => array( 
-                "Documents" => NULL,
+                "Vos assignations" => NULL,
                 "Listes des documents à traiter" => "/documents-my-assign.html")
         )); 
 ?>
+
+<div class="bd-callout bd-callout-success">
+    <h4>Astuce</h4>
+    <p>Vous avez la possibilité de paramètrer vos alertes en <a href="/alertes-emails.html">cliquant ici</a> et ainsi recevoir cette liste par email quand vous le souhaitez. </p>
+</div>
+
 <div>
     <table
         id="table"
         class="table-striped table-hover table-sm" 
         data-page-size="25"
         data-toggle="table"
-        data-show-columns="true"
-        data-search="true"
         data-buttons-align="left"
         data-show-footer="true"
         data-pagination="true"

+ 16 - 0
maj/sql/maj.sql

@@ -0,0 +1,16 @@
+ALTER TABLE `banque_lignes` ADD `creer` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `md5`; 
+
+CREATE TABLE `alertesEmails` (
+  `id` varchar(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
+  `id_user` int NOT NULL,
+  `heure` tinyint NOT NULL,
+  `jour` tinyint NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+ALTER TABLE `alertesEmails`
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `id_user_alertes` (`id_user`);
+
+ALTER TABLE `alertesEmails`
+  ADD CONSTRAINT `id_user_alertes` FOREIGN KEY (`id_user`) REFERENCES `user` (`id`);
+COMMIT;

+ 25 - 28
public-cms/cron.php

@@ -8,38 +8,35 @@ require_once "../conf.inc.php";
 require_once DIR_PHP_LAYOUTS . "header.php";
 
 if (cron::ifLocalHost()) {
-
+    
     // Email d'assignation
     cron::sendMailAssignDocument();
-    
+
 } else {
     header('HTTP/1.0 401 Unauthorized');
     header('Content-Type: text/html; charset=utf-8');
-    echo '<!DOCTYPE html>
-<html lang="fr">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>403 Accès Interdit</title>
-    <style>
-        body {
-            font-family: Arial, sans-serif;
-            background-color: #f8d7da;
-            color: #721c24;
-            text-align: center;
-            padding: 50px;
-        }
-        h1 {
-            font-size: 2em;
-        }
-        p {
-            font-size: 1.2em;
-        }
-    </style>
-</head>
-<body>
-    <h1>403 Accès Interdit</h1>
-</body>
-</html>';
+    echo '  <!DOCTYPE html>
+            <html lang="fr">
+            <head>
+                <meta charset="UTF-8">
+                <meta name="viewport" content="width=device-width, initial-scale=1.0">
+                <title>403 Accès Interdit</title>
+                <style>
+                    body {
+                        font-family: Arial, sans-serif;
+                        background-color: #f8d7da;
+                        color: #721c24;
+                        text-align: center;
+                        padding: 50px;
+                    }
+                    h1 {
+                        font-size: 2em;
+                    }
+                </style>
+            </head>
+            <body>
+                <h1>403 Accès Interdit</h1>
+            </body>
+            </html>';
     exit();
 }

+ 87 - 4
public-cms/css/cms.css

@@ -1,15 +1,98 @@
-
 .bd-title {
-    float :left;
+    float: left;
 }
 
 .fix-container-button-nav {
     position: absolute;
-    right:0;
+    right: 0;
     margin-right: 45px;
 }
 
 .fix-button-nav {
-    float :right;
+    float: right;
     margin-left: 5px;
 }
+
+
+/* Callout */
+
+.bd-callout {
+    padding: 1.25rem;
+    margin-top: 1.25rem;
+    margin-bottom: 1.25rem;
+    border-left: 1px solid #eee;
+    border-left-width: .25rem;
+    border-radius: .25rem
+}
+
+.bd-callout h4 {
+    margin-top: 0;
+    margin-bottom: .25rem;
+    font-size: 1.2rem;
+}
+
+.bd-callout p:last-child {
+    margin-bottom: 0
+}
+
+.bd-callout code {
+    border-radius: .25rem
+}
+
+.bd-callout+.bd-callout {
+    margin-top: -.25rem
+}
+
+.bd-callout-info {
+    border-left-color: #5bc0de;
+    background-color: rgba(91, 192, 222, 0.1);
+}
+
+.bd-callout-info h4 {
+    color: #5bc0de
+}
+
+.bd-callout-warning {
+    border-left-color: #f0ad4e;
+    background-color: rgba(240, 173, 78, 0.1);
+}
+
+.bd-callout-warning h4 {
+    color: #f0ad4e
+}
+
+.bd-callout-danger {
+    border-left-color: #d9534f;
+    background-color: rgba(217, 83, 79, 0.1);
+}
+
+.bd-callout-danger h4 {
+    color: #d9534f
+}
+
+.bd-callout-primary {
+    border-left-color: #007bff;
+    background-color: rgba(0, 123, 255, 0.1);
+}
+
+.bd-callout-primary h4 {
+    color: #007bff
+}
+
+.bd-callout-success {
+    border-left-color: #28a745;
+    background-color: rgba(40, 167, 69, 0.1);
+}
+
+.bd-callout-success h4 {
+    color: #28a745
+}
+
+.bd-callout-default {
+    border-left-color: #6c757d;
+    background-color: rgba(108, 117, 125, 0.1);
+}
+
+.bd-callout-default h4 {
+    color: #6c757d
+}