[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r623 - in trunk/rapport_avance: . include include/templa
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r623 - in trunk/rapport_avance: . include include/template sql |
Date: |
Tue, 17 Dec 2013 20:43:05 +0100 (CET) |
Author: danydb
Date: 2013-12-17 20:43:05 +0100 (Tue, 17 Dec 2013)
New Revision: 623
Added:
trunk/rapport_avance/ajax_parameter_send_mail.php
trunk/rapport_avance/ajax_send_mail.php
trunk/rapport_avance/include/template/parameter_send_mail_input.php
Modified:
trunk/rapport_avance/ajax.php
trunk/rapport_avance/include/class_rapav_listing_compute.php
trunk/rapport_avance/include/class_rapav_listing_compute_fiche.php
trunk/rapport_avance/include/class_rapport_avance_sql.php
trunk/rapport_avance/index.php
trunk/rapport_avance/rapav_javascript.js
trunk/rapport_avance/raw.php
trunk/rapport_avance/sql/2-listing_compute_fiche.sql
Log:
Task #936 Envoi des documents PDF ou g?\195?\169n?\195?\169r?\195?\169 par email
Task #936 - Listing : envoi par email
Modified: trunk/rapport_avance/ajax.php
===================================================================
--- trunk/rapport_avance/ajax.php 2013-12-17 17:34:26 UTC (rev 622)
+++ trunk/rapport_avance/ajax.php 2013-12-17 19:43:05 UTC (rev 623)
@@ -1,12 +1,15 @@
<?php
extract($_GET);
+if ( ! isset($act)) {
+ die(_('act invalide'));
+}
global $cn;
$a_action=explode(',',
'mod_form,add_row_definition,mod_param,add_param_detail,'.
'rapav_search_code,save_param_detail,rapav_declaration_display,'.
'listing_modify,listing_remove_modele,listing_display_definition,'.
'listing_param_add,save_param_listing,listing_detail_remove,'.
- 'listing_search_code,rapav_listing_display');
+
'listing_search_code,rapav_listing_display,parameter_send_mail,send_mail');
if ( in_array($act,$a_action ) == true )
{
include 'ajax_'.$act.'.php';
Added: trunk/rapport_avance/ajax_parameter_send_mail.php
===================================================================
--- trunk/rapport_avance/ajax_parameter_send_mail.php
(rev 0)
+++ trunk/rapport_avance/ajax_parameter_send_mail.php 2013-12-17 19:43:05 UTC
(rev 623)
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Display form to enter parameters
+ */
+require_once 'include/class_rapav_listing_compute.php';
+require_once 'class_fiche_def.php';
+
+ob_start();
+$compute=new RAPAV_Listing_Compute();
+$compute->load($_GET['lc_id']);
+$fiche_def=new Fiche_Def($cn,$compute->listing->data->getp('fiche_def_id'));
+if ( $fiche_def->HasAttribute(ATTR_DEF_EMAIL) == false) {
+ echo '<p class="notice">';
+ echo _("Cette catégorie n'a pas d'attribut email");
+ echo '</p>';
+} else {
+ echo HtmlInput::title_box(_('Envoi par email'),
"parameter_send_mail_input");
+ $subject=new IText('p_subject');
+ $from=new IText('p_from');
+ $message=new ITextarea('p_message');
+ $attach=new ISelect('p_attach');
+ $attach->value=array (
+ array('value'=>0,'label'=>_('Aucun document')),
+ array('value'=>1,'label'=>_('Document en PDF')),
+ array('value'=>2,'label'=>_('Document généré'))
+ );
+ require_once 'include/template/parameter_send_mail_input.php';
+
+}
+$response = ob_get_clean();
+ob_end_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+?>
\ No newline at end of file
Added: trunk/rapport_avance/ajax_send_mail.php
===================================================================
--- trunk/rapport_avance/ajax_send_mail.php (rev 0)
+++ trunk/rapport_avance/ajax_send_mail.php 2013-12-17 19:43:05 UTC (rev
623)
@@ -0,0 +1,27 @@
+<?php
+require_once 'include/class_rapav_listing_compute.php';
+
+ob_start();
+$listing=new RAPAV_Listing_Compute();
+$listing->load($lc_id);
+$a_result=$listing->send_mail($p_from,$p_subject,$p_message,$p_attach);
+echo HtmlInput::title_box(_('Résultat'),'parameter_send_mail_result');
+echo '<ol>';
+for ($i=0;$i<count($a_result);$i++)
+{
+ echo '<li>'.$a_result[$i].'</li>';
+}
+echo '</ol>';
+echo HtmlInput::button_close('parameter_send_mail_result');
+$response = ob_get_clean();
+ob_end_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+?>
\ No newline at end of file
Modified: trunk/rapport_avance/include/class_rapav_listing_compute.php
===================================================================
--- trunk/rapport_avance/include/class_rapav_listing_compute.php
2013-12-17 17:34:26 UTC (rev 622)
+++ trunk/rapport_avance/include/class_rapav_listing_compute.php
2013-12-17 19:43:05 UTC (rev 623)
@@ -294,6 +294,22 @@
$fiche->generate_document();
}
}
+ function send_mail($p_from,$p_subject,$p_message,$p_attach)
+ {
+ global $cn;
+ $ofiche=new RAPAV_Listing_Compute_Fiche();
+ $r_fiche=$ofiche->seek (" where lc_id = $1",array($this->data->lc_id));
+ $nb_fiche=Database::num_row($r_fiche);
+ if (isNumber($p_id)==0) {$p_id=0;}
+ $a_result=array();
+ /* For each card */
+ for ($i = 0;$i < $nb_fiche;$i++)
+ {
+ $fiche=$ofiche->next($r_fiche,$i);
+
$a_result[]=$fiche->send_mail($p_from,$p_subject,$p_message,$p_attach);
+ }
+ return $a_result;
+ }
function create_pdf()
{
global $cn;
@@ -387,10 +403,10 @@
function propose_send_mail()
{
- echo '<form method="GET" action="extension.raw.php" class="noprint"
style="display:inline">';
+ echo '<form method="GET" action="ajax.php"
id="parameter_send_mail_frm" onsubmit="parameter_send_mail();return false;"
class="noprint" style="display:inline">';
echo
HtmlInput::array_to_hidden(array('ac','gDossier','plugin_code','sa'),
$_REQUEST);
echo HtmlInput::hidden('lc_id',$this->data->lc_id);
- echo HtmlInput::hidden('act','export_send_mail');
+ echo HtmlInput::hidden('act','parameter_send_mail');
echo HtmlInput::submit("export_send_mail", "Envoi par
email","","smallbutton");
echo '</form>';
return 0;
Modified: trunk/rapport_avance/include/class_rapav_listing_compute_fiche.php
===================================================================
--- trunk/rapport_avance/include/class_rapav_listing_compute_fiche.php
2013-12-17 17:34:26 UTC (rev 622)
+++ trunk/rapport_avance/include/class_rapav_listing_compute_fiche.php
2013-12-17 19:43:05 UTC (rev 623)
@@ -5,7 +5,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
-
+require_once 'class_sendmail.php';
/**
* Description of class_rapav_listing_compute_fiche
*
@@ -467,5 +467,97 @@
$cn->commit();
}
+ /**
+ *
+ * @global type $cn
+ * @param type $p_from
+ * @param type $p_subject
+ * @param type $p_message
+ * @param type $p_attach
+ * @return type
+ */
+ function send_mail($p_from, $p_subject, $p_message, $p_attach)
+ {
+ global $cn;
+ $fiche = new Fiche($cn, $this->f_id);
+ $email = $fiche->strAttribut(ATTR_DEF_EMAIL);
+ $result = "";
+ $this->lf_email_send_date = date('Y.m.d H:i');
+
+ if ($email == "")
+ {
+ $result = $fiche->strAttribut(ATTR_DEF_QUICKCODE) . " n'a pas
d'email ";
+
+ $this->lf_email_send_result = $result;
+ $this->update();
+
+ return $result;
+ }
+ $mail = new Sendmail();
+ $mail->set_from($p_from);
+ $mail->set_message($p_message);
+ $mail->set_subject($p_subject);
+ $mail->mailto($email);
+ switch ($p_attach)
+ {
+ case 0:
+ /* no attach */
+ break;
+ case 1:
+ /* -- PDF -- */
+ if ($this->lf_pdf_filename == "")
+ {
+ $result = $fiche->strAttribut(ATTR_DEF_QUICKCODE) . " n'a
pas de document en PDF";
+ $this->lf_email_send_result = $result;
+ $this->update();
+
+ return $result;
+ }
+ $cn->start();
+ $file = $this->lf_pdf_filename;
+ $dir = tempnam($_ENV['TMP'], 'mail');
+ unlink($dir);
+ mkdir($dir);
+ $cn->lo_export($this->lf_pdf, $dir . '/' . $file);
+ $ofile = new FileToSend($dir . '/' . $file);
+ $mail->add_file($ofile);
+ break;
+ case 2:
+ /* -- Doc généré -- */
+ if ($this->lf_filename == "")
+ {
+ $result = $fiche->strAttribut(ATTR_DEF_QUICKCODE) . " n'a
pas de document généré";
+ $this->lf_email_send_result = $result;
+ $this->update();
+
+ return $result;
+ }
+ $cn->start();
+ $file = $this->lf_filename;
+ $dir = tempnam($_ENV['TMP'], 'mail');
+ unlink($dir);
+ mkdir($dir);
+ $cn->lo_export($this->lf_lob, $dir . '/' . $file);
+ $ofile = new FileToSend($dir . '/' . $file);
+ $mail->add_file($ofile);
+ break;
+ }
+ $cn->commit();
+ try
+ {
+ $mail->send();
+ $result = $fiche->strAttribut(ATTR_DEF_QUICKCODE) . ' message
envoyé email : ' . $fiche->strAttribut(ATTR_DEF_EMAIL);
+ $this->lf_email_send_result=$result;
+ $this->update();
+ return $result;
+ } catch (Exception $ex)
+ {
+ $result = $fiche->strAttribut(ATTR_DEF_QUICKCODE) . " erreur mail
" . $ex->getMessage();
+ $this->lf_email_send_result=$result;
+ $this->update();
+ return $result;
+ }
+ }
+
}
Modified: trunk/rapport_avance/include/class_rapport_avance_sql.php
===================================================================
--- trunk/rapport_avance/include/class_rapport_avance_sql.php 2013-12-17
17:34:26 UTC (rev 622)
+++ trunk/rapport_avance/include/class_rapport_avance_sql.php 2013-12-17
19:43:05 UTC (rev 623)
@@ -486,6 +486,10 @@
var $lc_id;
var $lf_pdf;
var $lf_pdf_filename;
+ var $lf_action_included;
+ var $lf_email_send_date;
+ var $lf_email_send_result;
+
/* example private
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
*/
@@ -505,6 +509,9 @@
, "lf_mimetype" => "lf_mimetype"
, "lf_pdf" => "lf_pdf"
, "lf_pdf_filename" => "lf_pdf_filename"
+ ,'action_included'=>'lf_action_included'
+ , 'email_send_date'=>'lf_email_send_date'
+ , 'email_send_result'=>'lf_email_send_result'
);
$this->type = array(
@@ -516,6 +523,9 @@
, "lf_mimetype" => "text"
, "lf_pdf" => "oid"
, "lf_pdf_filename" => "text"
+ ,'lf_action_included'=>'text'
+ , 'lf_email_send_date'=>'text'
+ , 'lf_email_send_result'=>'text'
);
$this->default = array(
Added: trunk/rapport_avance/include/template/parameter_send_mail_input.php
===================================================================
--- trunk/rapport_avance/include/template/parameter_send_mail_input.php
(rev 0)
+++ trunk/rapport_avance/include/template/parameter_send_mail_input.php
2013-12-17 19:43:05 UTC (rev 623)
@@ -0,0 +1,23 @@
+<form onsubmit="send_email(); return false;"
id="parameter_send_email_input_frm">
+<?php
+ echo
HtmlInput::array_to_hidden(array('gDossier','plugin_code','ac','lc_id'),
$_REQUEST);
+ echo HtmlInput::hidden('act','send_mail');
+?>
+<p>
+ <label>De </label><?php echo $from->input();?>
+</p>
+<p>
+ <label>Sujet</label><?php echo $subject->input();?>
+</p>
+<p>
+ <label>Message</label><?php echo $message->input();?>
+</p>
+
+<p>
+ <label>Attache</label><?php echo $attach->input();?>
+</p>
+<?php
+echo HtmlInput::submit("send_mail", _('Envoi'), '', 'smallbutton');
+echo HtmlInput::button_close('parameter_send_mail_input');
+?>
+</form>
\ No newline at end of file
Modified: trunk/rapport_avance/index.php
===================================================================
--- trunk/rapport_avance/index.php 2013-12-17 17:34:26 UTC (rev 622)
+++ trunk/rapport_avance/index.php 2013-12-17 19:43:05 UTC (rev 623)
@@ -58,7 +58,7 @@
array($url . '&sa=li', _('Liste'), _('Création, modification, Paramètre
de listes, mailing list'), 0),
array($url . '&sa=fo', _('Formulaire'), _('Création, modification,
Paramètre'), 1),
// array($url . '&sa=de', _('Génération Déclaration '), _('Génération
Déclaration '), 2),
- array($url . '&sa=de', _('Génération Déclaration / listing'),
_('Génération Déclaration / listing'), 2),
+ array($url . '&sa=de', _('Génération'), _('Génération Déclaration /
listing'), 2),
array($url . '&sa=hi', _('Historique'), _('Historique des déclarations
faites'), 3)
);
Modified: trunk/rapport_avance/rapav_javascript.js
===================================================================
--- trunk/rapport_avance/rapav_javascript.js 2013-12-17 17:34:26 UTC (rev
622)
+++ trunk/rapport_avance/rapav_javascript.js 2013-12-17 19:43:05 UTC (rev
623)
@@ -906,5 +906,82 @@
catch (e)
{
alert(e.message);
+ return false;
}
+}
+function parameter_send_mail()
+{
+ try {
+ var qs = $('parameter_send_mail_frm').serialize(false);
+ waiting_box();
+ var action = new Ajax.Request(
+ "ajax.php",
+ {
+ method: 'get',
+ parameters: qs,
+ onFailure: ajax_misc_failure,
+ onSuccess: function(req) {
+ var answer = req.responseXML;
+ var a = answer.getElementsByTagName('ctl');
+ var html = answer.getElementsByTagName('code');
+ if (a.length == 0) {
+ var rec = req.responseText;
+ throw 'cannot find ctl element';
+ }
+ remove_waiting_box();
+ var code_html = getNodeText(html[0]);
+ code_html = unescape_xml(code_html);
+ console.log(code_html);
+ var position = fixed_position(451, 217) + ';width:50%';
+ add_div({'id': 'parameter_send_mail_input',
'cssclass': 'inner_box', 'drag': 1, 'style': position});
+ $('parameter_send_mail_input').innerHTML = code_html;
+ remove_waiting_box();
+ }
+ }
+ );
+ return false;
+ } catch (e)
+ {
+ alert(e.message);
+ return false;
+
+ }
+}
+function send_email()
+{
+ try {
+ var qs = $('parameter_send_email_input_frm').serialize(false);
+ waiting_box();
+ var action = new Ajax.Request(
+ "ajax.php",
+ {
+ method: 'get',
+ parameters: qs,
+ onFailure: ajax_misc_failure,
+ onSuccess: function(req) {
+ var answer = req.responseXML;
+ var a = answer.getElementsByTagName('ctl');
+ var html = answer.getElementsByTagName('code');
+ if (a.length == 0) {
+ var rec = req.responseText;
+ throw 'cannot find ctl element';
+ }
+ remove_waiting_box();
+ var code_html = getNodeText(html[0]);
+ code_html = unescape_xml(code_html);
+ console.log(code_html);
+ var position = fixed_position(451, 217) + ';width:50%';
+ add_div({'id': 'parameter_send_mail_result',
'cssclass': 'inner_box', 'drag': 1, 'style': position});
+ $('parameter_send_mail_result').innerHTML = code_html;
+ remove_waiting_box();
+ }
+ }
+ );
+ return false;
+ } catch (e)
+ {
+ alert(e.message);
+ return false;
+
+ }
}
\ No newline at end of file
Modified: trunk/rapport_avance/raw.php
===================================================================
--- trunk/rapport_avance/raw.php 2013-12-17 17:34:26 UTC (rev 622)
+++ trunk/rapport_avance/raw.php 2013-12-17 19:43:05 UTC (rev 623)
@@ -233,4 +233,5 @@
$cn->commit();
}
+
?>
Modified: trunk/rapport_avance/sql/2-listing_compute_fiche.sql
===================================================================
--- trunk/rapport_avance/sql/2-listing_compute_fiche.sql 2013-12-17
17:34:26 UTC (rev 622)
+++ trunk/rapport_avance/sql/2-listing_compute_fiche.sql 2013-12-17
19:43:05 UTC (rev 623)
@@ -12,6 +12,9 @@
lf_pdf_filename text, -- Generated file if any
lf_mimetype text, -- Same mimetype as in table listing
lc_id bigint,
+ lf_action_included text,
+ lf_email_send_date timestamp,
+ lf_email_send_result text,
CONSTRAINT listing_compute_fiche_pkey PRIMARY KEY (lf_id ),
CONSTRAINT fk_listing_compute_lc_id FOREIGN KEY (lc_id)
REFERENCES rapport_advanced.listing_compute (lc_id) MATCH SIMPLE
---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpcompta-dev] r623 - in trunk/rapport_avance: . include include/template sql,
phpcompta-dev <=