';
@@ -89,12 +91,13 @@ if ( isset ($_POST["DATABASE"]) )
* Insert new dossier with description
*/
$desc=HtmlInput::default_value_post("DESCRIPTION","");
+ $max_email=HtmlInput::default_value_post("max_email", -1);
try
{
$repo->start();
-
- $Res=$repo->exec_sql("insert into ac_dossier(dos_name,dos_description)
- values ($1,$2)",array($dos,$desc));
+ if (isNumber($max_email) == 0) $max_email=-1;
+ $Res=$repo->exec_sql("insert into ac_dossier(dos_name,dos_description,dos_email)
+ values ($1,$2,$3)",array($dos,$desc,$max_email));
$l_id=$repo->get_current_seq('dossier_id');
$repo->commit();
}
@@ -334,6 +337,19 @@ if ( $sa == 'list' )
| |
+
+ |
+
+ |
+
+ prec=0;
+ $max_email_input->value=-1;
+ echo $max_email_input->input();
+ ?>
+ |
+
| |
diff --git a/include/lib/class_sendmail.php b/include/lib/class_sendmail.php
index d98e726e8..ae8f29757 100644
--- a/include/lib/class_sendmail.php
+++ b/include/lib/class_sendmail.php
@@ -93,7 +93,7 @@ class Sendmail
$name = $array[$i];
if (trim($this->$name) == "")
{
- throw new Exception($name ._(" est vide"));
+ throw new Exception( sprintf(_("%s est vide",$name)));
}
}
}
@@ -103,7 +103,6 @@ class Sendmail
function compose()
{
$this->verify();
- $uid = md5(uniqid(time()));
// a random hash will be necessary to send mixed content
$separator = md5(time());
@@ -150,11 +149,95 @@ class Sendmail
*/
function send()
{
+ if ( $this->can_send() == false ) throw new Exception(_('Email non envoyé'),EMAIL_LIMIT);
//SEND Mail
if (!mail($this->mailto, $this->subject, "", $this->content))
{
throw new Exception('send failed');
}
+ // Increment email amount
+ $repo =new Database();
+ $date=date('Ymd');
+ $dossier=Dossier::id();
+ $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
+ */
+ $dossier=HtmlInput::default_value_request("gDossier", -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)
+ {
+ $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/periode.inc.php b/include/periode.inc.php
index f23ecab0c..98eb8bda6 100644
--- a/include/periode.inc.php
+++ b/include/periode.inc.php
@@ -84,7 +84,7 @@ if ( $action== "delete_per" )
// Check if the periode is not used
if ( $cn->count_sql("select * from jrnx where j_tech_per=$p_per") != 0 )
{
- alert(' Désolé mais cette période est utilisée');
+ alert(_(' Désolé mais cette période est utilisée'));
}
else
{
@@ -93,7 +93,7 @@ if ( $action== "delete_per" )
$Res=$cn->exec_sql("delete from parm_periode where p_id=$p_per");
} else
{
- alert(' Désolé mais vous devez avoir au moins une période');
+ alert(_('Désolé mais vous devez avoir au moins une période'));
}
}
$choose="yes";
@@ -112,7 +112,7 @@ if ( $action == 'reopen')
if ( $choose=="yes" )
{
echo '
';
- echo HtmlInput::button_anchor('Autre Journal ?','?choose=no&ac='.$_REQUEST['ac'].'&gDossier='.dossier::id());
+ echo HtmlInput::button_anchor(_('Autre Journal ?'),'?choose=no&ac='.$_REQUEST['ac'].'&gDossier='.dossier::id());
echo '
';
$per=new Periode($cn);
$jrn=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
@@ -121,8 +121,8 @@ if ( $choose=="yes" )
$per->display_form_periode();
$nb_exercice=new ISelect("nb_exercice");
$nb_exercice->value=array(
- array('value'=>12,'label'=>"12 périodes"),
- array('value'=>13,'label'=>"13 périodes")
+ array('value'=>12,'label'=>_("12 périodes)")),
+ array('value'=>13,'label'=>_("13 périodes"))
);
require_once NOALYSS_TEMPLATE.'/periode_add_exercice.php';
@@ -133,15 +133,15 @@ else
echo dossier::hidden();
$sel_jrn=$cn->make_array("select jrn_def_id, jrn_def_name from ".
" jrn_def order by jrn_def_name");
- $sel_jrn[]=array('value'=>0,'label'=>'Global : periode pour tous les journaux');
+ $sel_jrn[]=array('value'=>0,'label'=>_('Global : periode pour tous les journaux'));
$wSel=new ISelect();
$wSel->value=$sel_jrn;
$wSel->name='jrn_def_id';
- echo "Choisissez global ou uniquement le journal à fermer".$wSel->input();
+ echo _("Choisissez global ou uniquement le journal à fermer").$wSel->input();
echo HtmlInput::submit('choose','Valider');
echo HtmlInput::hidden('ac',$_REQUEST['ac']);
echo "";
- echo '
Pour ajouter, effacer ou modifier une période, il faut choisir global
';
+ echo '
'._("Pour ajouter, effacer ou modifier une période, il faut choisir global").'
';
}
echo '
';
?>
diff --git a/include/sql/patch/ac-upgrade16.sql b/include/sql/patch/ac-upgrade16.sql
new file mode 100644
index 000000000..65933d5f0
--- /dev/null
+++ b/include/sql/patch/ac-upgrade16.sql
@@ -0,0 +1,20 @@
+begin;
+ALTER TABLE public.ac_dossier ADD dos_email int4 NULL DEFAULT -1;
+comment on column public.ac_dossier.dos_email is 'Max emails per day : 0 none , -1 unlimited or max value';
+
+CREATE TABLE public.dossier_sent_email (
+ id serial primary key,
+ de_date varchar(8) NOT NULL,
+ de_sent_email int4 NOT NULL,
+ dos_id int4 NOT NULL
+);
+comment on table public.dossier_sent_email is 'Count the sent email by folder';
+comment on column public.dossier_sent_email.id is 'primary key';
+comment on column public.dossier_sent_email.de_date is 'Date YYYYMMDD';
+comment on column public.dossier_sent_email.de_sent_email is 'Number of sent emails';
+comment on column public.dossier_sent_email.dos_id is 'Link to ac_dossier';
+
+alter table public.dossier_sent_email add constraint de_ac_dossier_fk foreign key (dos_id) references ac_dossier (dos_id ) on update cascade on delete cascade;
+alter table public.dossier_sent_email add constraint de_date_dos_id_ux unique (de_date,dos_id);
+select upgrade_repo(17);
+commit;