noalyss Version-9
acc_report.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20/*! \file
21 * \brief Create, view, modify and parse report
22 */
23
24require_once NOALYSS_INCLUDE.'/database/form_detail_sql.class.php';
25require_once NOALYSS_INCLUDE.'/database/form_definition_sql.class.php';
26
27/*!
28 * \class Acc_Report
29 * \brief Class rapport Create, view, modify and parse report
30 */
31
33{
34
35 private $form_definition; /*!< form_definition_sql */
36 var $row;
37 var $nb;
38 /*!
39 \brief Constructor
40 */
41 function __construct($p_cn,$p_id=-1)
42 {
43 $this->form_definition=new Form_Definition_SQL($p_cn,$p_id);
44 }
45 public function get_form_definition()
46 {
48 }
49
51 {
52 $this->form_definition=$form_definition;
53 }
54
55 /*!\brief Return the report's name
56 */
57 function get_name()
58 {
59 return $this->form_definition->getp("fr_label");
60 }
61 /*!
62 * \brief return all the row and parse formula
63 * from a report
64 * \param $p_start start periode
65 * \param $p_end end periode
66 * \param $p_type_date type of the date : periode (or 0) or calendar (or 1)
67 */
68 function get_row($p_start,$p_end,$p_type_date)
69 {
70 if (DEBUGNOALYSS > 1) {
71 tracedebug("impress.debug.log",__FILE__."71.get_row({$p_start},{$p_end},{$p_type_date})");
72 }
73 $Res=$this->form_definition->cn->exec_sql("select fo_id ,
74 fo_fr_id,
75 fo_pos,
76 fo_label,
77 fo_formula,
78 fr_label from form_detail
79 inner join form_definition on fr_id=fo_fr_id
80 where fr_id =$1
81 order by fo_pos",array($this->form_definition->getp("fr_id")));
83 if ($Max==0)
84 {
85 $this->row=0;
86 return null;
87 }
88 $col=array();
89
90 if ( $p_type_date == '0' || $p_type_date=="periode") {
91 $type_date=0;
92 } elseif ($p_type_date == '1' || $p_type_date=="calendar") {
93 $type_date=1;
94 } else {
95 throw new Exception("ACR93:invalid type_date [ {$p_type_date} ] ");
96 }
97
98
99 for ($i=0;$i<$Max;$i++)
100 {
102
103 $col[]=Impress::parse_formula($this->form_definition->cn,
104 $l_line['fo_label'],
105 $l_line['fo_formula'],
106 $p_start,
107 $p_end,
108 true,
109 $type_date
110 );
111
112 } //for ($i
113 $this->row=$col;
114 return $col;
115 }
116
117 /*!
118 * \brief save into form and form_def
119 */
120 function save()
121 {
122 $this->form_definition->save();
123 }
124
125 /*!
126 * \brief the fr_id MUST be set before calling
127 */
128 function load():void
129 {
130 $this->form_definition->load();
131
132 }
133 function delete()
134 {
135 $this->form_definition->delete();
136 }
137 /*!
138 * \brief get a list from form_definition of all defined form
139 *
140 *\return array of object rapport
141 *
142 */
143 function get_list()
144 {
145 $sql="select fr_id,fr_label from form_definition order by fr_label";
146 $ret=$this->form_definition->cn->exec_sql($sql);
147 if ( Database::num_row($ret) == 0 ) return array();
149 $obj=array();
150 foreach ($array as $row)
151 {
152 $tmp=new Acc_Report($this->form_definition->cn);
153 $tmp->id=$row['fr_id'];
154 $tmp->name=$row['fr_label'];
155 $obj[]=clone $tmp;
156 }
157 return $obj;
158 }
159 /*!\brief To make a SELECT button with the needed value, it is used
160 *by the SELECT widget
161 *\return string with html code
162 */
163 function make_array()
164 {
165 $sql=$this->form_definition->cn->make_array("select fr_id,fr_label from form_definition order by fr_label");
166 return $sql;
167 }
168
169
170 /*!\brief write to a file the definition of a report
171 * \param p_file is the file name (default php://output)
172 */
173 function export_csv($p_file)
174 {
175 $this->load();
176
177 fputcsv($p_file,array($this->form_definition->getp("fr_label")));
178 $array=$this->form_definition->get_cn()->get_array("select fo_label,fo_pos,fo_formula
179 from form_detail
180 where fo_fr_id=$1
181 order by fo_pos"
182 ,array($this->form_definition->getp("fr_id"))
183 );
184
185 foreach ($array as $row)
186 {
187 fputcsv($p_file,array($row["fo_label"],
188 $row["fo_pos"],
189 $row["fo_formula"])
190 );
191 }
192
193 }
194 /*!\brief upload a definition of a report and insert it into the
195 * database
196 */
197 function upload()
198 {
199 if ( empty ($_FILES) ) return;
200 if ( noalyss_strlentrim($_FILES['report']['tmp_name'])== 0 )
201 {
202 alert("Nom de fichier est vide");
203 return;
204 }
205 $file_report=tempnam('tmp','file_report');
206 if ( move_uploaded_file($_FILES['report']['tmp_name'],$file_report))
207 {
208 // File is uploaded now we can try to parse it
209 $file=fopen($file_report,'r');
210 $data=fgetcsv($file);
211 if ( empty($data) ) return;
212 $array=array();
213 $cn=$this->form_definition->cn;
214 $id=$this->form_definition->getp("fr_id");
215 while($data=fgetcsv($file))
216 {
218 $obj->setp("fo_label",$data[0]);
219 $obj->setp("fo_pos",$data[1]);
220 $obj->set("fo_formula",$data[2]);
221 $obj->setp("fo_fr_id",$id);
222 $obj->insert();
223 }
224 }
225 }
226 /**
227 *@brief check if a report exist
228 *@param $p_id, optional, if given check the report with this fr_id
229 *@return return true if the report exist otherwise false
230 */
231 function exist($p_id=0)
232 {
233 $c=$this->form_definition->getp("fr_id");
234 if ( $p_id != 0 ) $c=$p_id;
235 $ret=$this->form_definition->cn->exec_sql("select fr_label from form_definition where fr_id=$1",array($c));
236 if (Database::num_row($ret) == 0) return false;
237 return true;
238 }
239 /**
240 * @brief display a form for creating a new report by importing it or set manually
241 */
242 function create()
243 {
244 require_once NOALYSS_INCLUDE."/template/acc_report-create.php";
245 }
246 /**
247 * @brief
248 * @param IText $name
249 */
251 {
252 $name=new IText("fr_name",$name);
253 $name->id="fr_name_inplace";
254
255 $iName=new Inplace_Edit($name);
256 $iName->set_callback("ajax_misc.php");
257 $iName->add_json_param("op", "report_definition");
258 $iName->add_json_param("sa", "change_name");
259 $iName->add_json_param("gDossier", Dossier::id());
260 $iName->add_json_param("p_id", $this->form_definition->getp("fr_id"));
261 return $iName;
262 }
263}
264
265?>
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
Class rapport Create, view, modify and parse report.
exist($p_id=0)
check if a report exist
__construct($p_cn, $p_id=-1)
Constructor.
load()
the fr_id MUST be set before calling
save()
save into form and form_def
upload()
upload a definition of a report and insert it into the database
get_list()
get a list from form_definition of all defined form
get_name()
Return the report's name.
set_form_definition($form_definition)
export_csv($p_file)
write to a file the definition of a report
make_array()
To make a SELECT button with the needed value, it is used by the SELECT widget.
get_row($p_start, $p_end, $p_type_date)
return all the row and parse formula from a report
create()
display a form for creating a new report by importing it or set manually
static fetch_all($ret)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
static id()
return the 'gDossier' value after a check
ORM abstract of the table public.form_definition.
ORM abstract of the table public.form_detail.
Html Input.
Definition: itext.class.php:30
static parse_formula($p_cn, $p_label, $p_formula, $p_start, $p_end, $p_eval=true, $p_type_date=0, $p_sql="")
Inplace_edit class for ajax update of HtmlInput object.
$Res
$p_end
$p_start
if( $delta< 0) elseif( $delta==0)