[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r485 - in trunk/rapport_avance: . include sql
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r485 - in trunk/rapport_avance: . include sql |
Date: |
Tue, 30 Apr 2013 23:25:43 +0200 (CEST) |
Author: danydb
Date: 2013-04-30 23:25:43 +0200 (Tue, 30 Apr 2013)
New Revision: 485
Modified:
trunk/rapport_avance/include/class_rapav_declaration.php
trunk/rapport_avance/include/class_rapport_avance_sql.php
trunk/rapport_avance/include/declaration.inc.php
trunk/rapport_avance/raw.php
trunk/rapport_avance/sql/upgrade3.sql
Log:
0000739: G?\195?\169n?\195?\169ration de d?\195?\169claration
Generate document : html, text, rtf
Modified: trunk/rapport_avance/include/class_rapav_declaration.php
===================================================================
--- trunk/rapport_avance/include/class_rapav_declaration.php 2013-04-30
19:47:19 UTC (rev 484)
+++ trunk/rapport_avance/include/class_rapav_declaration.php 2013-04-30
21:25:43 UTC (rev 485)
@@ -42,6 +42,11 @@
$this->form = new RAPAV_Formulaire();
parent::__construct();
}
+ /**
+ * @brief export a declaration to CSV
+ * @global $cn database conx
+ * @param $p_id pk of rapav_declaration
+ */
static function to_csv($p_id)
{
global $cn;
@@ -74,6 +79,159 @@
);
}
}
+ function get_file_to_parse()
+ {
+ global $cn;
+ // create a temp directory in /tmp to unpack file and to parse
it
+ $dirname=tempnam($_ENV['TMP'],'rapav_');
+
+
+ unlink($dirname);
+ mkdir ($dirname);
+ chdir($dirname);
+ // Retrieve the lob and save it into $dirname
+ $cn->start();
+
+
+ $filename=$this->d_filename;
+
$exp=$cn->lo_export($this->d_lob,$dirname.DIRECTORY_SEPARATOR.$filename);
+
+ if ( $exp === false ) echo_warning(
__FILE__.":".__LINE__."Export NOK $filename");
+
+ $type="n";
+ // if the doc is a OOo, we need to unzip it first
+ // and the name of the file to change is always content.xml
+ if ( strpos($this->d_mimetype,'vnd.oasis') != 0 )
+ {
+ ob_start();
+ $zip = new Zip_Extended;
+ if ($zip->open($filename) === TRUE) {
+ $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
+ $zip->close();
+ } else {
+ echo __FILE__.":".__LINE__."cannot unzip model
".$filename;
+ }
+
+ // Remove the file we do not need anymore
+ unlink($filename);
+ ob_end_clean();
+ $file_to_parse="content.xml";
+ $type="OOo";
+ }
+ else
+ $file_to_parse=$filename;
+
+ $cn->commit();
+ return array($file_to_parse,$dirname,$type);
+ }
+ function generate_document()
+ {
+ global $cn;
+ if ( $this->d_filename == "") return;
+
+ list($file_to_parse,$dirname,$type)=$this->get_file_to_parse();
+
+ // parse the document - return the doc number ?
+ $this->parse_document($dirname,$file_to_parse,$type);
+
+ // if the doc is a OOo, we need to re-zip it
+ if ($type=='OOo' )
+ {
+ ob_start();
+ $zip = new Zip_Extended;
+ $res = $zip->open($this->d_filename, ZipArchive::CREATE);
+ if($res !== TRUE)
+ {
+ echo __FILE__.":".__LINE__."cannot recreate
zip";
+ exit;
+ }
+ $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
+ $zip->close();
+
+ ob_end_clean();
+
+ $file_to_save=$this->d_filename;
+ }
+ else
+ {
+ $file_to_save=$file_to_parse;
+ }
+
+ $this->load_document($dirname.DIRECTORY_SEPARATOR.$file_to_save);
+ }
+ function parse_document($p_dir,$p_filename,$p_type)
+ {
+ global $cn;
+ // Retrieve all the code + amount
+ if ($p_type == "OOo") {
+ $array=$cn->get_array("select
'<<'||dr_code||'>>' as code,dr_amount from
rapport_advanced.declaration_row where d_id=$1 and
dr_type=3",array($this->d_id));
+ }
+ else {
+ $array=$cn->get_array("select '<<'||dr_code||'>>' as
code,dr_amount from rapport_advanced.declaration_row where d_id=$1 and
dr_type=3",array($this->d_id));
+ }
+
+ // open the files
+ $ifile=fopen($p_dir.'/'.$p_filename,'r');
+
+ // check if tmpdir exist otherwise create it
+ $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
+ if ( is_dir($temp_dir) == false )
+ {
+ if ( mkdir($temp_dir) == false )
+ {
+ echo "Ne peut pas créer le répertoire
".$temp_dir;
+ exit();
+ }
+ }
+ // Compute output_name
+ $oname=tempnam($temp_dir,"rapport_avance_");
+ $ofile=fopen($oname,"w+");
+
+ // read ifile
+ while (! feof ($ifile))
+ {
+ $buffer=fgets($ifile);
+ // for each code replace in p_filename the code
surrounded by << >> by the amount (value) or < or >
+ foreach ($array as $key=>$value)
+ {
+
$buffer=str_replace($value['code'],$value['dr_amount'],$buffer);
+ }
+ // write to output
+ fwrite($ofile,$buffer);
+ }
+
+ // copy the output to input
+ fclose($ifile);
+ fclose($ofile);
+
+ if ( ($ret=copy ($oname,$p_dir.'/'.$p_filename)) == FALSE )
+ {
+ echo _('Ne peut pas sauver '.$oname.' vers
'.$p_dir.'/'.$p_filename.' code d\'erreur ='.$ret);
+ }
+ /**
+ * @todo clean files
+ */
+ // unlink ($oname);
+
+ }
+ function load_document($p_file)
+ {
+ global $cn;
+ $cn->start();
+ $this->d_lob=$cn->lo_import($p_file);
+ if ( $this->d_lob == false )
+ {
+ echo "ne peut pas importer [$p_file]";
+ return 1;
+ }
+ $this->d_size= filesize($p_file);
+ $date=date('ymd-Hi');
+ $this->d_filename=$date.'-'.$this->d_filename;
+ $this->update();
+ $cn->commit();
+
+
+ }
function compute($p_id, $p_start, $p_end)
{
global $cn;
@@ -88,6 +246,10 @@
$this->d_start = $p_start;
$this->d_end = $p_end;
$this->to_keep = 'N';
+ $this->d_lob=$this->form->f_lob;
+ $this->d_filename=$this->form->f_filename;
+ $this->d_mimetype=$this->form->f_mimetype;
+ $this->d_size=$this->form->f_size;
$this->insert();
/*
* First we compute the formula and tva_code for each detail
@@ -128,7 +290,12 @@
$cn->commit();
}
-
+ function anchor_document()
+ {
+
$url=HtmlInput::request_to_string(array('gDossier','ac','plugin_code'));
+
$url='extension.raw.php'.$url.'&act=export_decla_document&id='.$this->d_id;
+ return HtmlInput::anchor($this->d_filename,$url);
+ }
function display()
{
global $cn;
Modified: trunk/rapport_avance/include/class_rapport_avance_sql.php
===================================================================
--- trunk/rapport_avance/include/class_rapport_avance_sql.php 2013-04-30
19:47:19 UTC (rev 484)
+++ trunk/rapport_avance/include/class_rapport_avance_sql.php 2013-04-30
21:25:43 UTC (rev 485)
@@ -171,6 +171,10 @@
"d_end"=>"d_end",
"to_keep"=>"to_keep",
"d_generated"=>"d_generated",
+ "d_lob"=>"d_lob",
+ "d_filename"=>"d_filename",
+ "d_mimetype"=>"d_mimetype",
+ "d_size"=>"d_size",
"f_id"=>"f_id"
);
@@ -181,7 +185,12 @@
"d_end"=>"date",
"to_keep"=>"text",
"d_generated"=>"date",
- "f_id"=>"numeric"
+ "f_id"=>"numeric",
+ "d_lob"=>"oid",
+ "d_filename"=>"text",
+ "d_mimetype"=>"text",
+ "d_size"=>"numeric",
+
);
$this->default = array(
Modified: trunk/rapport_avance/include/declaration.inc.php
===================================================================
--- trunk/rapport_avance/include/declaration.inc.php 2013-04-30 19:47:19 UTC
(rev 484)
+++ trunk/rapport_avance/include/declaration.inc.php 2013-04-30 21:25:43 UTC
(rev 485)
@@ -39,12 +39,14 @@
$decl->to_keep = 'Y';
$decl->f_id = $_POST['p_form'];
$decl->save();
+ $decl->generate_document();
$decl->display();
- echo '<h2 class="notice"> Sauvé</h2>';
+ echo '<h2 class="notice">'._(' Sauvé ').date('d-m-Y H:i').'</h2>';
- $ref = HtmlInput::array_to_string(array('gDossier', 'plugin_code',
'd_id'), $_REQUEST, 'extension.raw.php?');
- $ref.="&act=export_decla_csv";
- echo HtmlInput::button_anchor("Export CSV", $ref, 'export_id');
+ $ref_csv = HtmlInput::array_to_string(array('gDossier', 'plugin_code',
'd_id'), $_REQUEST, 'extension.raw.php?');
+ $ref_csv.="&act=export_decla_csv";
+ echo HtmlInput::button_anchor("Export CSV", $ref_csv, 'export_id');
+ if ( $decl->d_filename != '' ) echo $decl->anchor_document();
exit();
}
/*
Modified: trunk/rapport_avance/raw.php
===================================================================
--- trunk/rapport_avance/raw.php 2013-04-30 19:47:19 UTC (rev 484)
+++ trunk/rapport_avance/raw.php 2013-04-30 21:25:43 UTC (rev 485)
@@ -1,4 +1,5 @@
<?php
+
/*
* This file is part of PhpCompta.
*
@@ -15,23 +16,69 @@
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ */
/* $Revision$ */
// Copyright Author Dany De Bontridder address@hidden
-/*!\file
+/* !\file
* \brief raw file for PDF ewa
*/
require_once 'include/class_formulaire_param.php';
require_once 'include/class_rapav_declaration.php';
-extract ($_REQUEST);
-if ( $act=='rapav_form_export') {
+extract($_REQUEST);
+if ($act == 'rapav_form_export')
+{
Formulaire_Param::to_csv($d_id);
exit();
}
-if ($act=='export_decla_csv') {
- Rapav_Declaration::to_csv($d_id);
+if ($act == 'export_decla_csv')
+{
+ Rapav_Declaration::to_csv($d_id);
exit();
}
+if ($act == 'export_decla_document')
+{
+ $decl = new Rapav_Declaration();
+ $decl->d_id = $id;
+ $decl->load();
+
+ $cn->start();
+ if ($decl->d_filename == "")
+ {
+ ini_set('zlib.output_compression', 'Off');
+ header("Pragma: public");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+ header("Cache-Control: must-revalidate");
+ header('Content-type: ' . 'text/plain');
+ header('Content-Disposition: attachment;filename=vide.txt',
FALSE);
+ header("Accept-Ranges: bytes");
+ echo "******************";
+ echo _("Fichier effacé");
+ echo "******************";
+ exit();
+ }
+ $tmp = tempnam($_ENV['TMP'], 'document_');
+
+ $cn->lo_export($decl->d_lob, $tmp);
+
+ ini_set('zlib.output_compression', 'Off');
+ header("Pragma: public");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+ header("Cache-Control: must-revalidate");
+ header('Content-type: ' . $decl->d_mimetype);
+ header('Content-Disposition: attachment;filename="' . $decl->d_filename
. '"', FALSE);
+ header("Accept-Ranges: bytes");
+ $file = fopen($tmp, 'r');
+ while (!feof($file))
+ echo fread($file, 8192);
+
+ fclose($file);
+
+ unlink($tmp);
+
+ $cn->commit();
+}
?>
Modified: trunk/rapport_avance/sql/upgrade3.sql
===================================================================
--- trunk/rapport_avance/sql/upgrade3.sql 2013-04-30 19:47:19 UTC (rev
484)
+++ trunk/rapport_avance/sql/upgrade3.sql 2013-04-30 21:25:43 UTC (rev
485)
@@ -18,3 +18,15 @@
alter table rapport_advanced.formulaire_param drop p_info;
ALTER TABLE rapport_advanced.declaration_row DROP COLUMN dr_info ;
+
+ALTER TABLE rapport_advanced.declaration ADD COLUMN d_lob oid;
+COMMENT ON COLUMN rapport_advanced.declaration.d_lob IS 'OID for file';
+
+ALTER TABLE rapport_advanced.declaration ADD COLUMN d_filename text;
+COMMENT ON COLUMN rapport_advanced.declaration.d_filename IS 'filename';
+
+ALTER TABLE rapport_advanced.declaration ADD COLUMN d_mimetype text;
+COMMENT ON COLUMN rapport_advanced.declaration.d_mimetype IS 'Mimetype of the
file';
+
+ALTER TABLE rapport_advanced.declaration ADD COLUMN d_size bigint;
+COMMENT ON COLUMN rapport_advanced.declaration.d_size IS 'Size of the file';
---
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] r485 - in trunk/rapport_avance: . include sql,
phpcompta-dev <=