Browse Source

CRON Email & mode debug send email

stany.ferer 1 year ago
parent
commit
0fc3059ae9

+ 1 - 0
access.inc.php

@@ -16,4 +16,5 @@
     define("OFF_LINE", array(
         "authenticator",
         "login",
+        "cron",
     ));

+ 2 - 2
conf.inc.php

@@ -94,8 +94,8 @@ define("BACKUP_LIMIT", 15); // nombre de backup max
 define("EMAIL_SMTP_HOST", "ssl0.ovh.net");
 define("EMAIL_SMTP_USER", "cms@cse-invent.com");
 define("EMAIL_SMTP_PASSWORD", "3gK!LYj&9xa!Y");
-define("EMAIL_SMTP_PORT", 465); // TLS par défaut, pour SSL utiliser 465
-define("EMAIL_SMTP_SECURE", "ssl"); // TLS par défaut, pour SSL utiliser 465
+define("EMAIL_SMTP_PORT", 465); // TLS par défaut 587, pour SSL utiliser 465
+define("EMAIL_SMTP_SECURE", "ssl"); // TLS par défaut en port 587, pour SSL utiliser 465
 
 define("EMAIL_FROM_EMAIL", "cms@cse-invent.com");
 define("EMAIL_FROM_NAME", "CMS CSE Invent");

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

@@ -4,7 +4,7 @@ class cron
 {
     public static function sendMailAssignDocument(){
         foreach (document::assignMailDocument() as $assign) {
-            document::sendEmailAssign($assign);
+            document::sendEmailCronAssign($assign);
         }
     }
 }

+ 14 - 0
core/class/debug.class.php

@@ -264,6 +264,10 @@ class debug
                     <input class=\"form-check-input\" type=\"checkbox\" id=\"checkIsEmail\" " . core::checkboxSelecter(self::isFile("email"), 0) . " >
                     <label class=\"form-check-label\" for=\"checkIsEmail\">Intercepter les <span style=\"font-weight: bold;\">Email</span></label>
                 </div>
+                <div>
+                    <input class=\"form-check-input\" type=\"checkbox\" id=\"checkSendIsEmail\" " . core::checkboxSelecter(self::isFile("send-email"), 0) . " >
+                    <label class=\"form-check-label\" for=\"checkSendIsEmail\">Afficher le mode debug lors de l'<span style=\"font-weight: bold;\">envoie d'email</span></label>
+                </div>
             </div>";
 
             foreach (self::$logs as $log) {
@@ -363,6 +367,16 @@ class debug
                 "txt" => "DEBUG EMAIL"
             ]);
         }
+        if(self::isFile("send-email")){
+            $return .= self::buildBadge([
+                "icon" => "bi bi-envelope-fill",
+                "class" => "toggle-logs",
+                "link" => "#", 
+                "background-color" => "orange",  
+                "color" => "black", 
+                "txt" => "DEBUG SEND EMAIL"
+            ]);
+        }
         if(self::isFile("submit")){
             $return .= self::buildBadge([
                 "icon" => "bi bi-send-fill",

+ 8 - 1
core/class/document.class.php

@@ -507,7 +507,7 @@ class document
         return db::resultset();
     }
 
-    public static function sendEmailAssign(array $_data){
+    public static function sendEmailCronAssign(array $_data){
         $list = self::getAssign($_data["id"]);
         $nb = count($list);
         
@@ -533,6 +533,13 @@ class document
 
         try {
             email::send($data);
+            historique::recRef("script");
+            historique::add(array(
+                "idType" => historique::getIdRef("CRON"),
+                "idUser" => NULL,
+                "idPage" => historique::getIdRef("script"),
+                "log" => "Email d'assignation envoyé à " . $data["name"])
+            );
         } catch (\Throwable $th) {
             debug::log($th);
         }

+ 32 - 27
core/class/email.class.php

@@ -45,40 +45,45 @@ class Email
         // Créer une instance de PHPMailer
         $mail = new PHPMailer(true);
 
-        try {
-            // Paramètres du serveur
-            self::configureMailer($mail);
+        
+        // Paramètres du serveur
+        self::configureMailer($mail);
 
-            // Si debug
-            if(debug::isFile("email")){
-                $mail->SMTPDebug = 1;
-            }
+        // Si debug send email
+        if(debug::isFile("send-email")){
+            $mail->SMTPDebug = 2;
+        }
 
-            // Destinataires
-            $mail->setFrom(self::$fromEmail, self::$fromName);
-            $mail->addAddress($to, $name);
+        // Destinataires
+        $mail->setFrom(self::$fromEmail, self::$fromName);
+        $mail->addAddress($to, $name);
 
-            $mail->CharSet = 'UTF-8';
+        $mail->CharSet = 'UTF-8';
 
-            // Contenu de l'email
-            $mail->isHTML(true);
-            $mail->Subject = "CSE Invent :. ". $subject;
-            $mail->Body    = $template;
+        // Contenu de l'email
+        $mail->isHTML(true);
+        $mail->Subject = "CSE Invent :. ". $subject;
+        $mail->Body    = $template;
 
-            if(!debug::isFile("email")){
+        if(!debug::isFile("email")){
+            try {
                 $mail->send();
+                return true;
+            } catch (Exception $e) {
+                $idSession = session::getId();
+                if(empty($idSession)){
+                    $idSession = NULL;
+                }
+    
+                historique::recRef("script");
+                historique::add(array(
+                    "idType" => historique::getIdRef("ERROR"),
+                    "idUser" => $idSession,
+                    "idPage" => historique::getIdRef("script"),
+                    "log" => $mail->ErrorInfo
+                ));
+                return false;
             }
-
-            return true;
-        } catch (Exception $e) {
-            historique::recRef("script");
-            historique::add(array(
-                "idType" => historique::getIdRef("ERROR"),
-                "idUser" => session::getId(),
-                "idPage" => historique::getIdRef("script"),
-                "log" => $mail->ErrorInfo
-            ));
-            return false;
         }
     }
 

+ 2 - 2
core/class/historique.class.php

@@ -26,11 +26,11 @@ class historique
                 . "" . DB_T_HISTORIQUE . ".idPage, "
                 . "HISTO_PAGE.name AS page, "
                 . "" . DB_T_HISTORIQUE . ".idUser ,"
-                . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user' ,"
+                . "COALESCE(CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom), 'CMS System') AS 'user' ,"
                 . "" . DB_T_HISTORIQUE . ".log, "
                 . "" . DB_T_HISTORIQUE . ".addDate "
                 . "FROM " . DB_T_HISTORIQUE . " "
-                . "INNER JOIN " . DB_T_USER . " ON " . DB_T_HISTORIQUE . ".idUser = " . DB_T_USER . ".id "
+                . "LEFT JOIN " . DB_T_USER . " ON " . DB_T_HISTORIQUE . ".idUser = " . DB_T_USER . ".id "
                 . "INNER JOIN " . DB_T_HISTORIQUE_REF . " HISTO_TYPE ON " . DB_T_HISTORIQUE . ".idType = HISTO_TYPE.id "
                 . "INNER JOIN " . DB_T_HISTORIQUE_REF . " HISTO_PAGE ON " . DB_T_HISTORIQUE . ".idPage = HISTO_PAGE.id ");
         return db::resultset();

+ 4 - 0
core/javascript/cms.debug.php

@@ -13,6 +13,10 @@
             window.location.href = '/submit.php?from=parametres-debug&target=email&actif=' + $('#checkIsEmail').prop('checked');
         });
 
+        $('#checkSendIsEmail').on('change', function() {
+            window.location.href = '/submit.php?from=parametres-debug&target=send-email&actif=' + $('#checkSendIsEmail').prop('checked');
+        });
+
         $('.toggle-logs').click(function() {
             $('#debugger-logs').slideToggle();
         });

+ 2 - 1
core/submit/cms.parametres-debug.php

@@ -4,7 +4,8 @@ if(core::ifGet("actif") AND core::ifGet("target")){
         "debug",
         "sql",
         "submit",
-        "email"
+        "email",
+        "send-email"
     ];
 
     if(in_array(core::getGet("target"), $filter)){