[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 51/107: Code Cleaning split sendmail between
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 51/107: Code Cleaning split sendmail between sendmail_core (not related to noalyss) and sendmail which is used by noalyss |
Date: |
Mon, 26 Aug 2019 10:31:56 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 47f3b3e9430b2cd4b3f310d8dbc74b873dcffb39
Author: Dany De Bontridder <address@hidden>
Date: Sun Jul 28 13:22:36 2019 +0200
Code Cleaning split sendmail between sendmail_core
(not related to noalyss) and sendmail which is used by noalyss
---
include/class/sendmail.class.php | 132 +++++++++++++++++++++
include/lib/filetosend.class.php | 6 +-
...{sendmail.class.php => sendmail_core.class.php} | 110 +++--------------
include/recover.php | 5 +-
4 files changed, 154 insertions(+), 99 deletions(-)
diff --git a/include/class/sendmail.class.php b/include/class/sendmail.class.php
new file mode 100644
index 0000000..8c265a9
--- /dev/null
+++ b/include/class/sendmail.class.php
@@ -0,0 +1,132 @@
+<?php
+/*
+ * This file is part of NOALYSS.
+ *
+ * NOALYSS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * NOALYSS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NOALYSS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Send email for Noalyss after checking if it is possible : if cannot
be sent if the limit of max email
+ * is reached,
+ * @see sendmail_core
+ */
+require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
+require_once NOALYSS_INCLUDE."/lib/sendmail_core.class.php";
+
+class Sendmail extends Sendmail_Core
+{
+ /**
+ * Send the message
+ * @throws Exception
+ */
+ function send()
+ {
+ if ( $this->can_send() == false ) throw new
Exception(_('Email non envoyé'),EMAIL_LIMIT);
+
+ if (!mail($this->mailto, $this->subject, $this->content,$this->header))
+ {
+ throw new Exception('send failed');
+ }
+ // Increment email amount
+ $repo =new Database();
+ $date=date('Ymd');
+ $http=new HttpInput();
+ $dossier=$http->request("gDossier","string", -1);
+ $this->increment_mail($repo,$dossier,$date);
+ }
+ /**
+ * Check if email can be sent from a folder
+ * @return boolean
+ */
+ function can_send() {
+ /**
+ * if send from a dossier , then check limit of this dossier
+ * otherwise send true
+ */
+ $http=new HttpInput();
+ $dossier=$http->request("gDossier","string", -1);
+ if ($dossier == -1 ) return true;
+
+ /**
+ * Compare max value in repo
+ */
+ $repo =new Database();
+ $date=date('Ymd');
+ // get max email
+ $max_email = $this->get_max_email($repo,$dossier);
+ //
+ // This folder cannot send email
+ if ($max_email == 0 ) return false;
+ //
+ // This folder has unlimited email
+ if ($max_email == -1 ) return true;
+
+ // get email sent today from account_repository
+ $email_sent = $this->get_email_sent($repo,$dossier , $date);
+ //
+ if ( $email_sent >= $max_email) return false;
+
+ return true;
+ }
+ /**
+ * return max email the folder can send
+ * @param $p_repo Database
+ * @param $p_dossier_id int
+ */
+ function get_max_email(Database $p_repo,$p_dossier_id)
+ {
+ $max_email = $p_repo->get_value("select dos_email from ac_dossier
where dos_id=$1",
+ array($p_dossier_id));
+ return $max_email;
+ }
+ /**
+ * Return the amount of send emails for the date (YYYYMMDD)
+ * @param Database $p_repo
+ * @param $p_dossier_id int
+ * @param $p_date string YYYYMMDD
+ */
+ function get_email_sent(Database $p_repo,$p_dossier_id,$p_date)
+ {
+
+ $email_sent = $p_repo->get_value ('select de_sent_email from
dossier_sent_email where dos_id = $1 and de_date=$2',
+ array($p_dossier_id,$p_date));
+ return $email_sent;
+
+
+ }
+ /**
+ * Add $p_amount_email to email sent
+ * @param $p_repo Database
+ * @param $p_dossier int id of the folder (dossier.dos_id)
+ * @param $p_date string (YYYYMMDD)
+ */
+ function increment_mail(Database $p_repo,$p_dossier,$p_date)
+ {
+ if ( $p_dossier == -1) return ;
+ $email_sent = $this->get_email_sent($p_repo,$p_dossier,$p_date);
+ if ( $email_sent == 0 ){
+ $p_repo->exec_sql("insert into
public.dossier_sent_email(de_sent_email,dos_id,de_date) values($1,$2,$3)",
+ array(1,$p_dossier,$p_date));
+ return;
+ } else {
+ // update + sp_emaoun_email
+ $p_repo->exec_sql("update dossier_sent_email set
de_sent_email=de_sent_email+1 where dos_id=$1 and de_date=$2",
+ array($p_dossier,$p_date));
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/include/lib/filetosend.class.php b/include/lib/filetosend.class.php
index fa9b4e3..fc74799 100644
--- a/include/lib/filetosend.class.php
+++ b/include/lib/filetosend.class.php
@@ -16,19 +16,19 @@
* along with NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-// Copyright Author Dany De Bontridder address@hidden
+// Copyright Author Dany De Bontridder address@hidden
/**
*@file
* @brief file to add to a message
*
- * @see Sendmail
+ * @see Sendmail_Core
* @author dany
*/
/**
* @brief file to add to a message
*
- * @see Sendmail
+ * @see Sendmail_Core
* @author dany
*/
diff --git a/include/lib/sendmail.class.php
b/include/lib/sendmail_core.class.php
similarity index 58%
rename from include/lib/sendmail.class.php
rename to include/lib/sendmail_core.class.php
index c41c966..922bb74 100644
--- a/include/lib/sendmail.class.php
+++ b/include/lib/sendmail_core.class.php
@@ -29,9 +29,8 @@
* @author dany
*/
require_once NOALYSS_INCLUDE.'/lib/filetosend.class.php';
-require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
-class Sendmail
+class Sendmail_Core
{
private $mailto;
@@ -42,6 +41,10 @@ class Sendmail
private $content;
private $header;
+ function __construct()
+ {
+ }
+
/**
* set the from
* @param $p_from has the form name <address@hidden>
@@ -109,8 +112,8 @@ class Sendmail
function compose()
{
$this->verify();
- $this->header="";
- $this->content="";
+ $this->header="";
+ $this->content="";
// a random hash will be necessary to send mixed content
$separator = md5(time());
@@ -152,104 +155,23 @@ class Sendmail
$this->content .= "--" . $separator . "--";
}
+
/**
- * Send the message
+ * Send email
* @throws Exception
*/
function send()
{
- if ( $this->can_send() == false ) throw new
Exception(_('Email non envoyé'),EMAIL_LIMIT);
+ try {
+ $this->verify();
+
+ } catch (Exception $e) {
+ throw $e;
+ }
- if (!mail($this->mailto, $this->subject, $this->content,$this->header))
+ if (!mail($this->mailto, $this->subject, $this->content,$this->header))
{
throw new Exception('send failed');
}
- // Increment email amount
- $repo =new Database();
- $date=date('Ymd');
- $http=new HttpInput();
- $dossier=$http->request("gDossier","string", -1);
- $this->increment_mail($repo,$dossier,$date);
}
- /**
- * Check if email can be sent from a folder
- * @return boolean
- */
- function can_send() {
- /**
- * if send from a dossier , then check limit of this dossier
- * otherwise send true
- */
- $http=new HttpInput();
- $dossier=$http->request("gDossier","string", -1);
- if ($dossier == -1 ) return true;
-
- /**
- * Compare max value in repo
- */
- $repo =new Database();
- $date=date('Ymd');
- // get max email
- $max_email = $this->get_max_email($repo,$dossier);
- //
- // This folder cannot send email
- if ($max_email == 0 ) return false;
- //
- // This folder has unlimited email
- if ($max_email == -1 ) return true;
-
- // get email sent today from account_repository
- $email_sent = $this->get_email_sent($repo,$dossier , $date);
- //
- if ( $email_sent >= $max_email) return false;
-
- return true;
- }
- /**
- * return max email the folder can send
- * @param $p_repo Database
- * @param $p_dossier_id int
- */
- function get_max_email(Database $p_repo,$p_dossier_id)
- {
- $max_email = $p_repo->get_value("select dos_email from ac_dossier
where dos_id=$1",
- array($p_dossier_id));
- return $max_email;
- }
- /**
- * Return the amount of send emails for the date (YYYYMMDD)
- * @param Database $p_repo
- * @param $p_dossier_id int
- * @param $p_date string YYYYMMDD
- */
- function get_email_sent(Database $p_repo,$p_dossier_id,$p_date)
- {
-
- $email_sent = $p_repo->get_value ('select de_sent_email from
dossier_sent_email where dos_id = $1 and de_date=$2',
- array($p_dossier_id,$p_date));
- return $email_sent;
-
-
- }
- /**
- * Add $p_amount_email to email sent
- * @param $p_repo Database
- * @param $p_dossier int id of the folder (dossier.dos_id)
- * @param $p_date string (YYYYMMDD)
- */
- function increment_mail(Database $p_repo,$p_dossier,$p_date)
- {
- if ( $p_dossier == -1) return ;
- $email_sent = $this->get_email_sent($p_repo,$p_dossier,$p_date);
- if ( $email_sent == 0 ){
- $p_repo->exec_sql("insert into
public.dossier_sent_email(de_sent_email,dos_id,de_date) values($1,$2,$3)",
- array(1,$p_dossier,$p_date));
- return;
- } else {
- // update + sp_emaoun_email
- $p_repo->exec_sql("update dossier_sent_email set
de_sent_email=de_sent_email+1 where dos_id=$1 and de_date=$2",
- array($p_dossier,$p_date));
- }
- }
-
}
diff --git a/include/recover.php b/include/recover.php
index 2d20a5f..ec082d1 100644
--- a/include/recover.php
+++ b/include/recover.php
@@ -63,7 +63,7 @@ if ($action=="") :
</form>
<?php
elseif ($action=="send_email") :
- require_once NOALYSS_INCLUDE.'/lib/sendmail.class.php';
+ require_once NOALYSS_INCLUDE.'/lib/sendmail_core.class.php';
require_once NOALYSS_INCLUDE.'/class/database.class.php';
/*
* Check if user exists, if yes save a recover request
@@ -108,6 +108,7 @@ elseif ($action=="send_email") :
$mail->set_from(ADMIN_WEB);
$mail->mailto($user_email);
$mail->set_subject("NOALYSS : Réinitialisation de mot de passe");
+ $noalyss_url=NOALYSS_URL;
$message=<<<EOF
Bonjour,
@@ -120,7 +121,7 @@ Suivez ce lien pour activer le changement ou ignorer ce
message si vous n'êtes
Ce lien ne sera actif que 12 heures.
-
https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}?recover&id=req&req={$request_id}
+ {$noalyss_url}/index.php?recover&id=req&req={$request_id}
Merci d'utiliser NOALYSS
- [Noalyss-commit] [noalyss] 106/107: cosmetic, (continued)
- [Noalyss-commit] [noalyss] 106/107: cosmetic, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 64/107: Add demo for fontello, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 75/107: Task #0001731: Moyen de paiement, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 81/107: Task #0001733: Impression moyen paiement, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 56/107: New function PDF_Core:is_fill add documentation, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 38/107: load_all must always return an array, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 67/107: SQL : add constraint for payment_method, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 44/107: fixup! fixup! Code cleaning : split database into database (for noalyss) and databasecore , with the functions, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 36/107: Bug : card cannot use a attribute of the type "card", reason : the query was wrong and there were a confusion between this->name and this->id in "get_js_attr()", Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 47/107: Improve doxygen, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 51/107: Code Cleaning split sendmail between sendmail_core (not related to noalyss) and sendmail which is used by noalyss,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 54/107: Merge branch 'dev7109', Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 59/107: #0001729: Preference : ne plus recharger la page, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 85/107: Cosmetic : Icon_Trash in Todo_List, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 80/107: translation, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 82/107: DatabaseCore fix silent when not debug, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 72/107: Improve message progress bar + translation, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 94/107: Bug : Database::fetch_all returns an array or FALSE, because of pg_fetch_all, the version PHP7 cannot use anymore a boolean with count()., Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 63/107: remove background color, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 66/107: Code cleaning : rename table mod_payment to payment_method, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 53/107: Select_Box new Object, Dany De Bontridder, 2019/08/26