noalyss Version-9
Public Member Functions | Data Fields
Document_modele Class Reference

Class for the document template. More...

+ Collaboration diagram for Document_modele:

Public Member Functions

 __construct ($p_cn, $p_id=-1)
 
 Delete ()
 Remove a template. More...
 
 form ()
 show the form for loading a template More...
 
 load ()
 load the value of a document_modele,the ag_id variable must be set More...
 
 move_uploaded_file ($temporary_name, $target_path)
 
 myList ()
 : show all the stored document_modele. return a string containing all the data separate by TD & TR tag More...
 
 Save ()
 : Save a document_modele in the database, if the document_modele doesn't exist yet it will be first created (-> insert into document_modele) in that case the name and the type must be set set before calling Save, the name will be modified with sql_string More...
 
 update ($p_array)
 : update a document_modele in the database, More...
 

Data Fields

 $cn
 
 $md_affect
 
 $md_filename
 
 $md_id
 
 $md_lob
 
 $md_name
 
 $md_sequence
 
 $md_type
 
 $sequence
 
 $start
 

Detailed Description

Class for the document template.

Definition at line 26 of file document_modele.class.php.

Constructor & Destructor Documentation

◆ __construct()

Document_modele::__construct (   $p_cn,
  $p_id = -1 
)

< $md_filename is the filename of the template

Definition at line 39 of file document_modele.class.php.

40 {
41 $this->cn=$p_cn;
42 $this->md_id=$p_id;
43 $this->start=0;
44 }
$input_from cn
Definition: balance.inc.php:66

References $p_id, and cn.

Member Function Documentation

◆ Delete()

Document_modele::Delete ( )

Remove a template.

Returns
nothing

Definition at line 213 of file document_modele.class.php.

214 {
215 $this->cn->start();
216 // first we unlink the document
217 $sql="select md_lob from document_modele where md_id=$1";
218 $res=$this->cn->exec_sql($sql,[$this->md_id]);
220 // if a lob is found
221 if ( !empty ($r['md_lob']) &&$this->cn->exist_blob($r['md_lob']) )
222 {
223 // we remove it first
224 $this->cn->lo_unlink($r['md_lob']);
225 }
226 // now we can delete the row
227 $sql="delete from document_modele where md_id =$1";
228 $res=$this->cn->exec_sql($sql,[$this->md_id]);
229 $this->cn->commit();
230 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array

References $r, $res, $sql, cn, and DatabaseCore\fetch_array().

+ Here is the call graph for this function:

◆ form()

Document_modele::form ( )

show the form for loading a template

Parameters
p_actionfor the field action = destination url
Returns
string containing the forms

Definition at line 239 of file document_modele.class.php.

240 {
241 $r='<p class="notice">';
242 $r.='Veuillez introduire les mod&egrave;les servant à g&eacute;n&eacute;rer vos documents';
243 $r.='</p>';
244 $r.='<form enctype="multipart/form-data" method="post" onsubmit="return check_file_size(this,'. MAX_FILE_SIZE.')">';
245 $r.=\HtmlInput::hidden("MAX_FILE_SIZE", MAX_FILE_SIZE);
246 $r.=dossier::hidden();
247 // we need to add the sub action as hidden
248 $h=new IHidden();
249 $h->name="sa";
250 $h->value="add_document";
251
252 $r.=$h->input();
253
254 $r.='<table>';
255 $t=new IText();
256 $t->name="md_name";
257 $r.="<tr><td> Nom </td><td>".$t->input()."</td>";
258
259 $r.="</tr>";
260 $r.="<tr><td>Catégorie de document </td>";
261 $w=new ISelect();
262 $w->name="md_type";
263
264 $w->value=$this->cn->make_array('select dt_id,dt_value from document_type order by dt_value');
265 $r.="<td>".$w->input()."</td></tr>";
266
267 $r.='<tr>';
268 $r.=td(_('Affectation'));
269 $waffect=new ISelect();
270 $waffect->name='md_affect';
271 $waffect->value=$this->cn->make_array("select dc_code,dc_comment from public.document_component order by dc_code");
272
273 $r.=td($waffect->input());
274 $r.='</tr>';
275
276 $f=new IFile();
277 $f->name="doc";
278 $f->setAlertOnSize(true);
279 $r.="<tr><td>fichier</td><td> ".$f->input()."</td></tr>";
280
281 $start=new IText();
282 $start->name="start_seq";
283 $start->size=9;
284 $start->value="0";
285
286 $r.="<tr><td> Numerotation commence a</td><td> ".$start->input()."</td>";
287 $r.='<td class="notice">Si vous laissez &agrave; 0, la num&eacute;rotation ne changera pas, la prochaine facture sera n+1, n étant le n° que vous avez donn&eacute;</td>';
288 $r.="</tr>";
289 $r.='</table>';
290 $r.='<ul class="aligned-block">';
291 $r.='<li>';
292 $r.=HtmlInput::submit('add_document','Ajout');
293 $r.='</li>';
294 $r.='<li>';
295 $r.=HtmlInput::button_hide("add_modele");
296 $r.='</li>';
297 $r.="</form></p>";
298 return $r;
299 }
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
foreach($array as $idx=> $m) $w
static button_hide($div_name)
Hide the HTML popup.
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input for uploading file, must be in a form with enctype="multipart/form-data".
Definition: ifile.class.php:31
Html Input.
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: itext.class.php:30

References $f, $r, $start, $w, HtmlInput\button_hide(), cn, HtmlInput\hidden(), HtmlInput\submit(), and td().

+ Here is the call graph for this function:

◆ load()

Document_modele::load ( )

load the value of a document_modele,the ag_id variable must be set

Definition at line 302 of file document_modele.class.php.

303 {
304 $array=$this->cn->get_array("SELECT md_id, md_name, md_lob, md_type, md_filename, md_mimetype,md_affect".
305 " FROM document_modele where md_id=$1",array($this->md_id));
306 if ( count($array) == 0 ) return null;
307 foreach ( array('md_name', 'md_lob','md_type', 'md_filename', 'md_mimetype','md_affect') as $idx)
308 {
309 $this->$idx=$array[0][$idx];
310 }
311 }
$idx

References $array, $idx, and cn.

Referenced by update().

◆ move_uploaded_file()

Document_modele::move_uploaded_file (   $temporary_name,
  $target_path 
)

Definition at line 205 of file document_modele.class.php.

206 {
207 return move_uploaded_file ($temporary_name, $target_path);
208 }
move_uploaded_file($temporary_name, $target_path)

References move_uploaded_file().

Referenced by move_uploaded_file(), Save(), and update().

+ Here is the call graph for this function:

◆ myList()

Document_modele::myList ( )

: show all the stored document_modele. return a string containing all the data separate by TD & TR tag

Returns
table in HTML Code

Definition at line 53 of file document_modele.class.php.

54 {
55 $dosid=dossier::id();
56 $sql="select md_id,md_name,md_affect,dt_value,md_filename from document_modele join document_type on(dt_id=md_type) order by md_name";
57 $Res=$this->cn->exec_sql($sql);
59 $r='';
60 if ( Database::num_row($Res) != 0 ) {
61
62 $r.='<p><form method="post">';
63 $r.=dossier::hidden();
64 $r.=\HtmlInput::filter_table("document_template_tb",'0,1,2',1);
65 $r.='<table id="document_template_tb" class="result" >';
66 $r.="<tr> ";
67 $r.=th(_('Nom'));
68 $r.=th(_('Catégorie'));
69 $r.=th(_('Affect.'));
70 $r.=th(_('Fichier'));
71 $r.=th(_('Effacer'));
72 $r.="</tr>";
73 $idx=0;
74 foreach ( $all as $row)
75 {
76 $even=($idx%2==0)?'class="odd"':'class="even"';
77 $idx++;
78 $r.="<tr $even>";
79 $r.="<td>";
80 $r.=h($row['md_name']);
81 $r.="</td>";
82 $r.="<td>";
83 $r.=$row['dt_value'];
84 $r.="</td>";
85 $r.=td(h($row['md_affect']));
86 $r.="<td>";
87 $href=http_build_query(array('gDossier'=>$dosid,'md_id'=>$row['md_id'],'act'=>'RAW:document_template'));
88 $r.='<A HREF="export.php?'.$href.'">'.h($row['md_filename']).'</a>';
89 $r.="</td>";
90 $r.="<TD>";
91 $c=new ICheckBox();
92 $c->name="dm_remove_".$row['md_id'];
93 $r.=$c->input();
94 $r.="</td>";
95 $r.=td(HtmlInput::detail_modele_document($row['md_id'],_('Modifier')));
96
97 $r.="</tr>";
98 }
99 $r.="</table>";
100
101 // need hidden parameter for subaction
102 $a=new IHidden();
103 $a->name="sa";
104 $a->value="rm_template";
105 $r.=$a->input();
106 $r.=HtmlInput::submit("rm_template",_("Effacer la sélection"));
107 } else {
108 echo h2(_("Aucun document"));
109 echo _("Il n'y a aucun document, cliquez sur Ajouter pour en ajouter un");
110 }
111 $b=new IButton('show');
112 $b->label="Ajout d'un document";
113 $b->javascript="$('add_modele').style.display='block';new Draggable('add_modele',{starteffect:function(){
114 new Effect.Highlight(obj.id,{scroll:window,queue:'end'});}});";
115 $r.=$b->input();
116 $r.="</form></p>";
117 return $r;
118 }
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
$href
Definition: adm.inc.php:31
h( $row[ 'oa_description'])
$input_from id
Definition: balance.inc.php:63
static fetch_all($ret)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
static detail_modele_document($p_id, $p_mesg)
return a string containing the html code for calling the modifyModeleDocument
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
Html Input.
Html Input.
$all
$Res

References $a, $all, $b, $href, $idx, $r, $Res, $row, $sql, cn, HtmlInput\detail_modele_document(), DatabaseCore\fetch_all(), HtmlInput\filter_table(), h, h2(), id, DatabaseCore\num_row(), HtmlInput\submit(), td(), and th().

+ Here is the call graph for this function:

◆ Save()

Document_modele::Save ( )

: Save a document_modele in the database, if the document_modele doesn't exist yet it will be first created (-> insert into document_modele) in that case the name and the type must be set set before calling Save, the name will be modified with sql_string

Definition at line 128 of file document_modele.class.php.

129 {
130 // if name is empty return immediately
131 if ( trim(strlen($this->md_name))==0)
132 return;
133 try
134 {
135 // Start transaction
136 $this->cn->start();
137 // Save data into the table document_modele
138 // if $this->md_id == -1 it means it is a new document model
139 // so first we have to insert it
140 // the name and the type must be set before calling save
141 if ( $this->md_id == -1)
142 {
143
144 // insert into the table document_modele
145 $this->md_id=$this->cn->get_next_seq('document_modele_md_id_seq');
146 $sql="insert into document_modele(md_id,md_name,md_type,md_affect)
147 values ($1,$2,$3,$4)";
148
149 $Ret=$this->cn->exec_sql($sql,array($this->md_id,$this->md_name,$this->md_type,$this->md_affect));
150 // create the sequence for this modele of document
151 $this->md_sequence="document_".$this->cn->get_next_seq("document_seq");
152 // if start is not equal to 0 and he's a number than the user
153 // request a number change
154
155 if ( $this->start != 0 && isNumber($this->start) == 1 )
156 {
157 $sql="alter sequence seq_doc_type_".$this->md_type." restart ".$this->start;
158 $this->cn->exec_sql($sql);
159 }
160
161 }
162 // Save the file
163 $new_name=tempnam($_ENV['TMP'],'document_');
164 if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
165 {
166 if ($this->move_uploaded_file($_FILES['doc']['tmp_name'],
167 $new_name))
168 {
169 // echo "Image saved";
170 $oid= $this->cn->lo_import($new_name);
171 if ( $oid == false )
172 {
173 echo_error('class/class_document_modele.php',__LINE__,"cannot upload document");
174 $this->cn->rollback();
175 return;
176 }
177 // Remove old document
178 $ret=$this->cn->exec_sql("select md_lob from document_modele where md_id=".$this->md_id);
179 if (Database::num_row($ret) != 0)
180 {
182 $old_oid=$r['md_lob'];
183 if (strlen(""??$old_oid) != 0)
184 $this->cn->lo_unlink($old_oid);
185 }
186 // Load new document
187 $this->cn->exec_sql("update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
188 $this->cn->commit();
189 }
190 else
191 {
192 echo "<H1>"._("Erreur opération annulée")."</H1>";
193 $this->cn->rollback();
194 throw new Exception("DM191 : error loading template".__FILE__.__LINE__);
195 }
196 }
197 }
198 catch (Exception $e)
199 {
200 record_log($e);
201 $this->cn->rollback();
202 return ;
203 }
204 }
isNumber($p_int)
Definition: ac_common.php:215
echo_error($p_log, $p_line="", $p_message="")
log error into the /tmp/noalyss_error.log it doesn't work on windows
Definition: ac_common.php:169
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
$new_name

References $e, $new_name, $r, $ret, $sql, $start, cn, echo_error(), DatabaseCore\fetch_array(), isNumber(), move_uploaded_file(), DatabaseCore\num_row(), record_log(), and return.

+ Here is the call graph for this function:

◆ update()

Document_modele::update (   $p_array)

: update a document_modele in the database,

Definition at line 315 of file document_modele.class.php.

316 {
317 $this->load();
318 // if name is empty return immediately
319 if ( trim(strlen($p_array['md_name']))==0)
320 return;
321 try
322 {
323 // Start transaction
324 $this->cn->start();
325 $sql="update document_modele set md_name=$1,md_type=$2,md_affect=$3 where md_id=$4";
326 $this->cn->exec_sql($sql,array(
327 $p_array['md_name'],
328 $p_array['md_type'],
329 $p_array['md_affect'],
330 $this->md_id
331 ));
332 if ( $p_array['seq'] != 0 )
333 $this->cn->alter_seq('seq_doc_type_'.$p_array['md_type'],$p_array['seq']);
334
335 // Save the file
336 $new_name=tempnam($_ENV['TMP'],'document_');
337 if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
338 {
339 if ($this->move_uploaded_file($_FILES['doc']['tmp_name'],
340 $new_name))
341 {
342 // echo "Image saved";
343 $oid= $this->cn->lo_import($new_name);
344 if ( $oid == false )
345 {
346 echo_error('class/class_document_modele.php',__LINE__,"cannot upload document");
347 $this->cn->rollback();
348 return;
349 }
350 // Remove old document
351 $ret=$this->cn->exec_sql("select md_lob from document_modele where md_id=".$this->md_id);
352 if (Database::num_row($ret) != 0)
353 {
355 $old_oid=$r['md_lob'];
356 if (strlen($old_oid) != 0)
357 $this->cn->lo_unlink($old_oid);
358 }
359 // Load new document
360
361 $this->cn->exec_sql("update document_modele
362 set md_lob=$1,
363 md_mimetype=$2,
364 md_filename=$3
365 where md_id=$4",[
366 $oid,
367 $_FILES['doc']['type'],
368 $_FILES['doc']['name'],
369 $this->md_id]);
370 $this->cn->commit();
371 }
372 else
373 {
374 echo "<H1>Error</H1>";
375 $this->cn->rollback();
376 throw new Exception("Erreur".__FILE__.__LINE__);
377 }
378 }
379 }
380 catch (Exception $e)
381 {
382 record_log($e);
383 $this->cn->rollback();
384 return ;
385 }
386 $this->cn->commit();
387 }
load()
load the value of a document_modele,the ag_id variable must be set

References $e, $new_name, $p_array, $r, $ret, $sql, cn, echo_error(), DatabaseCore\fetch_array(), load(), move_uploaded_file(), DatabaseCore\num_row(), record_log(), and return.

+ Here is the call graph for this function:

Field Documentation

◆ $cn

Document_modele::$cn

$cn database connection

Definition at line 28 of file document_modele.class.php.

◆ $md_affect

Document_modele::$md_affect

$md_affect if you can use it in VEN for sale, ACH for purchase or GES for follow-up

Definition at line 35 of file document_modele.class.php.

◆ $md_filename

Document_modele::$md_filename

Definition at line 36 of file document_modele.class.php.

◆ $md_id

Document_modele::$md_id

$md_id pk

Definition at line 29 of file document_modele.class.php.

◆ $md_lob

Document_modele::$md_lob

$md_lob Document file

Definition at line 32 of file document_modele.class.php.

◆ $md_name

Document_modele::$md_name

$md_name template's name

Definition at line 30 of file document_modele.class.php.

◆ $md_sequence

Document_modele::$md_sequence

$md_sequence sequence name (autogenerate)

Definition at line 33 of file document_modele.class.php.

◆ $md_type

Document_modele::$md_type

$md_type template's type (letter, invoice, order...)

Definition at line 31 of file document_modele.class.php.

◆ $sequence

Document_modele::$sequence

$sequence sequence number used by the create sequence start with

Definition at line 34 of file document_modele.class.php.

◆ $start

Document_modele::$start

< $md_filename is the filename of the template

Definition at line 37 of file document_modele.class.php.

Referenced by form(), and Save().


The documentation for this class was generated from the following file: