clean code : remove code for exporting a report definition and use the export mechanism

This commit is contained in:
Dany De Bontridder 2012-01-10 18:02:03 +00:00
parent 1a5b46d40d
commit a76dd15827
7 changed files with 44 additions and 172 deletions

View file

@ -1,76 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta 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.
*
* PhpCompta 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 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 ddebontridder@yahoo.fr
/*!\file
* \brief export definition of a report
*/
require_once ("constant.php");
require_once('class_database.php');
require_once ("user_common.php");
require_once('class_dossier.php');
require_once('class_acc_report.php');
require_once('class_user.php');
if ( ! isset($_GET['gDossier']) ||
! isset($_GET['f']) )
{
$a='{"answer":"nok"}';
header("Content-type: text/html; charset: utf8",true);
print $a;
exit();
}
$cn=new Database(dossier::id());
$User=new User($cn);
$User->Check();
$User->check_dossier(dossier::id());
$gDossier=dossier::id();
if ( ! is_dir('tmp') )
{
mkdir ('tmp');
}
$cn=new Database($gDossier);
if ( isset($_SESSION['isValid']) && $_SESSION['isValid'] == 1)
{
$rap=new Acc_Report($cn,$_GET['f']);
$name=tempnam('tmp','report_').'.bin';
$file= fopen($name,"a+");
$rap->export($file);
fclose ($file);
$name='tmp'.DIRECTORY_SEPARATOR.basename($name);
$name=dirname($_SERVER['REQUEST_URI']).DIRECTORY_SEPARATOR.$name;
$a='{"answer":"ok","link":"'.$name.'"}';
}
else
$a='{"answer":"nok"}';
header("Content-type: text/html; charset: utf8",true);
print $a;
?>

View file

@ -158,6 +158,9 @@ if ( $action=='X' || ! isset($_GET['act']) || $g_user->check_print($_GET['act'])
case 'CSV:AncGrandLivre':
require_once 'export_anc_grandlivre_csv.php';
break;
case 'CSV:reportinit':
require_once('export_reportinit_csv.php');
break;
default:
alert('Action inconnue '.$_GET['act']);
exit();

View file

@ -1,84 +0,0 @@
/*
* This file is part of PhpCompta.
*
* PhpCompta 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.
*
* PhpCompta 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 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 ddebontridder@yahoo.fr
/*!\file
* \brief javascript script for the report (in accountancy)
*
*/
/**
* @brief add a line in the form for the report
* @param p_dossier dossier id to connect
*/
function rapport_add_row(p_dossier)
{
style='style="border: 1px solid blue;"';
var table=$("rap1");
var line=table.rows.length;
var row=table.insertRow(line);
// left cell
var cellPos = row.insertCell(0);
cellPos.innerHTML='<input type="text" '+style+' size="3" id="pos'+line+'" name="pos'+line+'" value="'+line+'">';
// right cell
var cellName = row.insertCell(1);
cellName.innerHTML='<input type="text" '+style+' size="40" id="text'+line+'" name="text'+line+'">';
// button + formula
var cellbutton = row.insertCell(2);
var but_html=table.rows[1].cells[2].innerHTML;
but_html=but_html.replace(/form0/g,"form"+line);
cellbutton.innerHTML=but_html;
but_html.evalScripts();
g('form'+line).value='';
}
/**
* @brief create a file to export a report
* @param p_dossier the dossier id
*/
function report_export(p_dossier,p_fr_id)
{
var queryString="?&gDossier="+p_dossier+"&f="+p_fr_id;
var action=new Ajax.Request(
"ajax_report.php",
{
method:'get',
parameters:queryString,
onSuccess:report_export_success
}
);
}
/**
* @brief callback function for exporting a report
* @param request object request
* @param json json answer
*/
function report_export_success(request,json)
{
var answer = request.responseText.evalJSON(true);
var ok=answer.answer;
var link=answer.link;
$('export').hide();
$('export_link').innerHTML='<a class="mtitle" href="'+link+'"> Cliquez ici pour télécharger le rapport</a>';
}

View file

@ -1351,3 +1351,31 @@ function get_properties(obj)
}
alert(s_type+a_array.join(","));
}
/**
* @brief add a line in the form for the report
* @param p_dossier dossier id to connect
*/
function rapport_add_row(p_dossier)
{
style='style="border: 1px solid blue;"';
var table=$("rap1");
var line=table.rows.length;
var row=table.insertRow(line);
// left cell
var cellPos = row.insertCell(0);
cellPos.innerHTML='<input type="text" '+style+' size="3" id="pos'+line+'" name="pos'+line+'" value="'+line+'">';
// right cell
var cellName = row.insertCell(1);
cellName.innerHTML='<input type="text" '+style+' size="40" id="text'+line+'" name="text'+line+'">';
// button + formula
var cellbutton = row.insertCell(2);
var but_html=table.rows[1].cells[2].innerHTML;
but_html=but_html.replace(/form0/g,"form"+line);
cellbutton.innerHTML=but_html;
but_html.evalScripts();
g('form'+line).value='';
}

View file

@ -100,7 +100,7 @@ class Acc_Report
}
/*!
* \brief Display a form for encoding a new report or update one
*
*
* \param $p_line number of line
*
*/
@ -346,7 +346,7 @@ class Acc_Report
}
/*!\brief To make a SELECT button with the needed value, it is used
*by the SELECT widget
*\return string with html code
*\return string with html code
*/
function make_array()
{
@ -356,9 +356,9 @@ class Acc_Report
/*!\brief write to a file the definition of a report
* \param p_file is the file name
* \param p_file is the file name (default php://output)
*/
function export($p_file)
function export_csv($p_file)
{
$this->load();

View file

@ -2743,7 +2743,6 @@ function load_all_script()
echo js_include('slider.js');
echo js_include('acc_ledger.js');
echo js_include('accounting_item.js');
echo js_include('acc_report.js');
echo js_include('ajax_fiche.js');
echo js_include('anc_script.js');
echo js_include('builder.js');

View file

@ -128,20 +128,22 @@ if ( isset ($_REQUEST["action"]) )
{
echo '<DIV class="redcontent">';
$rap->id=$_REQUEST ['fr_id'];
echo '<form method="post">';
echo '<form method="post" style="display:inline">';
$rap->load();
echo $rap->form();
echo HtmlInput::hidden("fr_id",$rap->id);
echo HtmlInput::hidden("action","record");
echo HtmlInput::submit("update",_("Mise a jour"));
echo HtmlInput::submit("del_form",_("Effacement"));
$w=new IButton();
$w->name="export";
$w->javascript="report_export('".$gDossier."','".$rap->id."')";
$w->label='Export';
echo $w->input();
echo '<span id="export_link"></span>';
echo '</form>';
echo '<form method="get" action="export.php" style="display:inline">';
echo dossier::hidden();
echo HtmlInput::hidden("act","CSV:reportinit");
echo HtmlInput::hidden('f',$rap->id);
echo HtmlInput::submit('bt_csv',"Export CSV");
echo HtmlInput::request_to_hidden(array('ac','action','p_action','fr_id'));
echo '</form>';
echo '<span class="notice">'._("Les lignes vides seront effacées").'</span>';
echo "</DIV>";
}