noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
fiche_def.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
20require_once NOALYSS_INCLUDE.'/lib/user_common.php';
21
22/*! \file
23 * \brief define Class fiche and fiche def, those class are using
24 * class attribut
25 */
26/*!
27 * \brief define Class fiche and fiche def, those class are using
28 * class attribut
29 */
31{
32 var $cn; //!< database connection
33 var $id; //!< id (fiche_def.fd_id
34 var $label; //!< fiche_def.fd_label
35 var $class_base; //!< fiche_def.fd_class_base
36 var $fiche_def; //!< fiche_def.frd_id = fiche_def_ref.frd_id
37 var $create_account; //!< fd_create_account: flag
38 var $all;
39 var $attribut; //!< get from attr_xxx tables
40 var $fd_description; //!< Description of the Card Category
41
42 function __construct($cn,$id = 0)
43 {
44 $this->cn=$cn;
45 $this->id=$id;
46
47
48 }
49
50 public function __toString(): string
51 {
52 return "fiche_def".print_r($this,true);
53 }
54
55 /*!\brief show the content of the form to create a new Fiche_Def_Ref
56 */
57 function input ()
58 {
59
60 return;
61 }
62 /**
63 * @brief replace by load_attribute
64 * @deprecated since version 9.3.12
65 * @return type
66 */
67 function getAttribut() {
68 return $this->load_attribute();
69 }
70 /*!
71 * \brief Get attribute of a fiche_def
72 *
73 * \return array of Card_Property
74 */
75 function load_attribute()
76 {
77 $sql="select * from jnt_fic_attr ".
78 " natural join attr_def where fd_id= $1".
79 " order by jnt_order";
80
81 $Ret=$this->cn->exec_sql($sql,[$this->id]);
82
83 if ( ($Max=Database::num_row($Ret)) == 0 )
84 return ;
85 for ($i=0;$i < $Max;$i++)
86 {
88 $t = new Card_Property($this->cn);
89 $t->ad_id=$row['ad_id'];
90 $t->ad_text=$row['ad_text'];
91 $t->av_text="";
92 $t->jnt_order=$row['jnt_order'];
93 $t->ad_size=$row['ad_size'];
94 $t->ad_type=$row['ad_type'];
95 $t->ad_extra=$row['ad_extra'];
96 $this->attribut[$i]=clone $t;
97 }
98 return $this->attribut;
99 }
100
101 /**
102 * @brief alias for Fiche_Def->get(),
103 * @return void
104 */
105 function load():void
106 {
107 $this->get();
108 }
109 /*!
110 * \brief Get attribut of the fiche_def
111 *
112 */
113 function get()
114 {
115 if ( $this->id == 0 )
116 return 0;
117 /* $this->cn->exec_sql('select fiche_attribut_synchro($1)',
118 array($this->id));
119 */
120 $sql="select * from fiche_def ".
121 " where fd_id= $1";
122 $Ret=$this->cn->exec_sql($sql,[$this->id]);
123 if ( ($Max=Database::num_row($Ret)) == 0 )
124 return ;
126 $this->label=$row['fd_label'];
127 $this->class_base=$row['fd_class_base'];
128 $this->fiche_def=$row['frd_id'];
129 $this->create_account=($row['fd_create_account']=='f')?false:true;
130 $this->fd_description=$row['fd_description'];
131 }
132 /*!
133 * \brief Get all the fiche_def
134 *
135 * \return an array of fiche_def object
136 */
137 function get_all()
138 {
139 $sql="select * from fiche_def ";
140
141 $Ret=$this->cn->exec_sql($sql);
142 if ( ($Max=Database::num_row($Ret)) == 0 )
143 return array();
144 $all=array();
145 for ( $i = 0; $i < $Max;$i++)
146 {
148 $all[$i]=new Fiche_Def($this->cn,$row['fd_id']);
149 $all[$i]->label=$row['fd_label'];
150 $all[$i]->class_base=$row['fd_class_base'];
151 $all[$i]->fiche_def=$row['frd_id'];
152 $all[$i]->create_account=$row['fd_create_account'];
153 }
154 return $all;
155 }
156 /*!
157 **************************************************
158 * \brief Check in vw_fiche_def if a fiche has
159 * a attribut X
160 *
161 *
162 * \param $p_attr attribut to check
163 * \return true or false
164 */
165 function HasAttribute($p_attr)
166 {
167 return ($this->cn->count_sql("select * from vw_fiche_def where ad_id=$p_attr and fd_id=".$this->id)>0)?true:false;
168
169 }
170 /*!
171 **************************************************
172 * \brief Display all card categories into a table
173 *
174 * \return HTML row
175 */
176 function display()
177 {
178 $tab = new Sort_Table();
179
180 $url = HtmlInput::get_to_string(array('ac', 'gDossier'));
181 $tab->add(_("Nom de fiche"), $url, "order by fd_label asc", "order by fd_label desc", "na", "nd");
182 $tab->add(_("Basé sur le poste comptable"), $url, "order by fd_class_base asc", "order by fd_class_base desc", "pa", "pd");
183 $tab->add(_("Calcul automatique du poste comptable"), $url, "order by fd_create_account asc", "order by fd_create_account desc", "ca", "cd");
184 $tab->add(_("Basé sur le modèle"), $url, "order by frd_text asc", "order by frd_text desc", "ma", "md");
185
186 $order = (isset($_GET['ord'])) ? $tab->get_sql_order($_GET["ord"]) : $tab->get_sql_order("na");
187
188
189 $res = $this->cn->exec_sql("SELECT fd_id, fd_class_base, fd_label, fd_create_account, fiche_def_ref.frd_id,
190frd_text , fd_description FROM fiche_def join fiche_def_ref on (fiche_def.frd_id=fiche_def_ref.frd_id)
191$order
192");
193
194 require_once NOALYSS_TEMPLATE.'/fiche_def-display.php';
195 }
196 /*!
197 * \brief Add a fiche category thanks the element from the array
198 * you cannot add twice the same cat. name
199 * table : insert into fiche_def
200 * insert into attr_def
201 *
202 * \param $array array
203 * index FICHE_REF
204 * nom_mod
205 * class_base
206 * fd_description
207 * create
208 */
209 function Add($array)
210 {
211 /**
212 * Check needed info
213 */
214 $http=new HttpInput();
215 $http->set_array($array);
216 $p_nom_mod = $http->extract('nom_mod',"string","");
217 $p_fd_description = $http->extract('fd_description',"string", "");
218
219 $p_fiche_def= $http->extract('FICHE_REF',"string", "");
220 $p_create= $http->extract('create',"string", "off");
221
222 // If there is no description then add a empty one
223 if ( ! isset ($p_fd_description)) {
224 $p_fd_description="";
225 }
226 // Format correctly the name of the cat. of card
227 $p_nom_mod=sql_string($p_nom_mod);
228
229
230 // Name can't be empty
231 if ( noalyss_strlentrim($p_nom_mod) == 0 )
232 {
233 alert (_('Le nom de la catégorie ne peut pas être vide'));
234 return 1;
235 }
236 // $p_fiche_def can't be empty
237 if ( noalyss_strlentrim($p_fiche_def) == 0 )
238 {
239 alert (_('Un modéle de catégorie est obligatoire'));
240 return 1;
241 }
242
243 /* check if the cat. name already exists */
244 $sql="select count(*) from fiche_Def where upper(fd_label)=upper($1)";
245 $count=$this->cn->get_value($sql,array(trim($p_nom_mod)));
246
247 if ($count != 0 ) {
248 alert (_('Catégorie existante'));
249 return 1;
250 }
251 $default_acc=$this->cn->get_value("select frd_class_base from fiche_def_ref where frd_id=$1",[$p_fiche_def]);
252
253 // if the account is empty, takes the account of the template from fiche_def_ref
254 $p_class_base=$http->extract('class_base',"string", "");
255 $p_class_base=(noalyss_trim($p_class_base)=='')?$default_acc:$p_class_base;
256
257 // Set the value of fiche_def.fd_create_account
258 // automatic creation for 'poste comptable'
259 if ( $p_create == "on" && noalyss_strlentrim($p_class_base) != 0)
260 $p_create='true';
261 else
262 $p_create='false';
263 $add_accounting=false;
264 // Class is valid ?
265 if ( sql_string($p_class_base) != null || ( $p_class_base !='' && strpos(',',$p_class_base) != 0 ))
266 {
267 // p_class is a valid number
268 $sql="insert into fiche_def(fd_label,fd_class_base,frd_id,fd_create_account,fd_description)
269 values ($1,$2,$3,$4,$5) returning fd_id";
270
271 $this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_fiche_def,$p_create,$p_fd_description));
272
273 // p_class must be added to tmp_pcmn if it is a single accounting
274 if ( strpos(',',$p_class_base) ==0)
275 {
276 $sql="select account_add($1,$2)";
277 $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
278 }
279 // Get the fd_id
280 $fd_id=$this->cn->get_current_seq('s_fdef');
281
282// // update jnt_fic_attr
283// $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
284// values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
285// $Res=$this->cn->exec_sql($sql);
286 $add_accounting=true;
287 }
288 else
289 {
290 //There is no class base not even as default
291 $sql="insert into fiche_def(fd_label,frd_id,fd_create_account,fd_description) values ($1,$2,$3,$4) returning fd_id";
292
293
294 $this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_fiche_def,$p_create,$p_fd_description));
295
296 // Get the fd_id
297 $fd_id=$this->cn->get_current_seq('s_fdef');
298
299 }
300
301 // Get the default attr_def from attr_min
302 $def_attr=$this->get_attr_min($p_fiche_def);
303
304 //if defaut attr not null
305 // build the sql insert for the table attr_def
306 $add_qcode=true;
307 if (sizeof($def_attr) != 0 )
308 {
309 // insert all the mandatory fields into jnt_fiche_attr
310 foreach ( $def_attr as $row)
311 {
312
313 $count=$this->cn->get_value("select count(*) from jnt_fic_attr where fd_id=$1 and ad_id=$2",array($fd_id,$row['ad_id']));
314 if ($count == 0)
315 {
316 $sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id,jnt_order)
317 values (%d,%s,%d)",
318 $fd_id,$row['ad_id'],$row['ad_default_order']);
319 $this->cn->exec_sql($sql);
320 }
321 // if there is an accounting , then not needed to add one
322 if ( $row['ad_id']==ATTR_DEF_ACCOUNT) $add_accounting=FALSE;
323 if ( $row['ad_id']==ATTR_DEF_QUICKCODE) $add_qcode=FALSE;
324 }
325 }
326 // if there is an base accounting, and the accounting is not in ATTR_MIN,
327 // then it is needed to add it
328 if ( $add_accounting) {
329 $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
330 values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
331 $Res=$this->cn->exec_sql($sql);
332 }
333 // if there is no quick code in attr_min, it is added
334 if ( $add_qcode) {
335 $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
336 values (%d,%d,10000)",$fd_id,ATTR_DEF_QUICKCODE);
337 $Res=$this->cn->exec_sql($sql);
338 }
339 $this->id=$fd_id;
340 return 0;
341
342 }//--------------end function Add ----------------------------
343 /*!
344 * \brief Get all the card where the fiche_def.fd_id is given in parameter
345 * \param $step = 0 we don't use the offset, page_size,...
346 * $step = 1 we use the jnr_bar_nav
347 * \param $inactive int possible values : 1 = inactive included, 0 = only active ones (default 1)
348 * \return array ('f_id'=>..,'ad_value'=>..)
349 *\see fiche
350 */
352 {
353 // var $cond_active string SQL cond for filtering active or not
354 $cond_active=($inactive == 1)?"":" and f_enable='1' ";
355 $sql="select f_id,ad_value
356 from
357 fiche join fiche_detail using(f_id)
358 where ad_id=1 and fd_id=$1 $cond_active order by 2";
359
360 // we use navigation_bar
361 if ($step == 1 && $_SESSION[SESSION_KEY.'g_pagesize'] != -1 )
362 {
363 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
364 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
365 $sql.=" offset $offset limit $step";
366 }
367
368 $Ret=$this->cn->get_array($sql,array($this->id));
369
370 return $Ret;
371 }
372 /*!
373 * \brief Get all the card where the fiche_def.frd_id is given in parameter, it is the template for category
374 *\param $inactive int possible values : 1 = inactive included, 0 = only active ones (default 1)
375 * \param $template_category int FICHE_DEF_REF.FRD_ID
376 * \return array of Fiche or null is nothing is found
377 *
378 */
379 function get_by_category($template_category,$inactive=1)
380 {
381 // var $cond_active string SQL cond for filtering active or not
382 $cond_active=($inactive == 1)?"":" and f_enable='1' ";
383 $sql="select f_id,ad_value
384 from
385 fiche join fiche_def using(fd_id)
386 join fiche_detail using(f_id)
387 where ad_id=1 and frd_id=$1 $cond_active
388 order by 2 ";
389
390 $Ret=$this->cn->exec_sql($sql,array($template_category));
391 if ( ($Max=Database::num_row($Ret)) == 0 )
392 return null;
393 $all[0]=new Fiche($this->cn);
394
395 for ($i=0;$i<$Max;$i++)
396 {
398 $t=new Fiche($this->cn,$row['f_id']);
399 $t->load_attribute();
400 $all[$i]=$t;
401
402 }
403 return $all;
404 }
405
406 /*!\brief list the card of a fd_id
407 */
408 function myList()
409 {
410 $this->get();
411 echo '<H2 class="info">'.$this->id." ".$this->label.'</H2>';
412
413 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
414 $sql_limit="";
415 $sql_offset="";
416 $bar="";
417 if ( $step != -1 )
418 {
419
420 $page=(isset($_GET['page']))?$_GET['page']:1;
421 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
422 $max_line=$this->cn->count_sql("select f_id,ad_value from
423 fiche join fiche_detail using (f_id)
424 where fd_id='".$this->id."' and ad_id=".ATTR_DEF_NAME." order by f_id");
425 $sql_limit=" limit ".$step;
426 $sql_offset=" offset ".$offset;
428 }
429
430 // Get all name the cards of the select category
431 // 1 for attr_def.ad_id is always the name
432 $Res=$this->cn->exec_sql("select f_id,vw_name,quick_code from ".
433 " vw_fiche_attr ".
434 " where fd_id='".$this->id.
435 "' order by f_id $sql_offset $sql_limit ");
437 echo $bar;
438 $str="";
439 // save the url
440 // with offet &offset=15&step=15&page=2&size=15
441 if ( $_SESSION[SESSION_KEY.'g_pagesize'] != -1)
442 {
443 $str=sprintf("&offset=%s&step=%s&page=%s&size=%s",
444 $offset,
445 $step,
446 $page,
447 $max_line);
448 }
449
450
451 echo '<FORM METHOD="POST" action="?p_action=fiche&action=vue'.$str.'">';
452 echo HtmlInput::hidden('ac',$_REQUEST['ac']);
453 echo dossier::hidden();
454 echo HtmlInput::hidden("fiche",$this->id);
455 echo HtmlInput::submit('add','Ajout fiche');
456 echo '</FORM>';
457 $str_dossier=dossier::get();
458 echo '<table>';
459 for ( $i = 0; $i < $Max; $i++)
460 {
462 if ( $i%2 == 0)
463 echo '<TR class="odd">';
464 else
465 echo '<TR class="even">';
466
467 $span_mod='<TD><A href="?p_action=fiche&'.$str_dossier.
468 '&action=detail&fiche_id='.$l_line['f_id'].$str.'&fiche='.
469 $_REQUEST['fiche'].'&ac='.$_REQUEST['ac'].'">'.$l_line['quick_code']
470 .'</A></TD>';
471
472 echo $span_mod.'<TD>'.h($l_line['vw_name'])."</TD>";
473 echo '</tr>';
474 }
475 echo '</table>';
476 echo '<FORM METHOD="POST" action="?p_action=fiche&action=vue'.$str.'">';
477 echo HtmlInput::hidden('ac',$_REQUEST['ac']);
478 echo dossier::hidden();
479 echo HtmlInput::hidden("fiche",$this->id);
480 echo HtmlInput::submit('add','Ajout fiche');
481 echo '</FORM>';
482 echo $bar;
483
484 }
485
486 /*!\brief Display all the attribut of the fiche_def
487 *\param $str give the action possible values are remove, empty
488 */
490 {
491 if ( $this->id == 0 )
492 return ;
493 $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($this->id));
494
495 $MaxLine=sizeof($this->attribut);
496 $r="<TABLE>";
497 $r.="<tr>".th('Nom attribut').th('').th('Ordre','style="text-align:right"').'</tr>';
498 // Display each attribute
499 $add_action="";
500 for ($i=0;$i<$MaxLine;$i++)
501 {
502 $class="even";
503 if ( $i % 2 == 0 )
504 $class="odd";
505
506 $r.='<TR class="'.$class.'"><td>';
507 // Can change the name
508 if ( $this->attribut[$i]->ad_id == ATTR_DEF_NAME )
509 {
510 continue;
511 }
512 else
513 {
514 if ( $str == "remove" )
515 {
516 //Only for the not mandatory attribute (not defined in attr_min)
517 if ( $this->cn->count_sql("select * from attr_min where frd_id=".
518 $this->fiche_def." and ad_id = ".$this->attribut[$i]->ad_id) == 0
519 && $this->attribut[$i]->ad_id != ATTR_DEF_QUICKCODE
520 && $this->attribut[$i]->ad_id != ATTR_DEF_ACCOUNT
521 )
522 {
523 $add_action=sprintf( '</TD><TD> Supprimer <input type="checkbox" name="chk_remove[]" value="%d">',
524 $this->attribut[$i]->ad_id);
525 }
526 else
527 $add_action="</td><td>";
528 }
529 // The attribut.
530 $a=sprintf('%s ', $this->attribut[$i]->ad_text);
531 $r.=$a.$add_action;
532 /*---------------------------------------- */
533 /* ORDER OF THE CARD */
534 /*---------------------------------------- */
535 $order=new IText();
536 $order->name='jnt_order'.$this->attribut[$i]->ad_id;
537 $order->size=3;
538 $order->value=$this->attribut[$i]->jnt_order;
539 $r.='</td><td> '.$order->input();
540 }
541 $r.= '</td></tr>';
542 }
543
544 // Show the possible attribute which are not already attribute of the model
545 // of card
546 $Res=$this->cn->exec_sql("select ad_id,ad_text from attr_def
547 where
548 ad_id not in (select ad_id from fiche_def natural join jnt_fic_attr
549 where fd_id=$1) order by ad_text",array($this->id) );
551
552 // Show the unused attribute
553 $r.='<TR> <TD>';
554 $r.= '<SELECT NAME="ad_id">';
555 for ($i=0;$i<$M;$i++)
556 {
558 $a=sprintf('<OPTION VALUE="%s"> %s',
559 $l['ad_id'],$l['ad_text']);
560 $r.=$a;
561 }
562 $r.='</SELECT>';
563
564 $r.="</TABLE>";
565 return $r;
566 }
567 /*!\brief Save the label of the fiche_def
568 * \param $p_label label
569 */
570 function SaveLabel($p_label)
571 {
572 if ( $this->id == 0 ) return;
573 $p_label=sql_string($p_label);
574 if (strlen(trim ($p_label)) == 0 )
575 {
576 return;
577 }
578 $sql=sprintf("update fiche_def set fd_label='%s' ".
579 "where fd_id=%d",
580 $p_label,$this->id);
581 $Res=$this->cn->exec_sql($sql);
582
583 }
584 /*!\brief set the auto create accounting item for each card and
585 * save it into the database
586 * \param $p_label true or false
587 */
588 function set_autocreate($p_label)
589 {
590 if ( $this->id == 0 ) return;
591 if ($p_label==true)
592 $t='t';
593 if ($p_label==false)
594 $t='f';
595
596 $sql="update fiche_def set fd_create_account=$1 ".
597 "where fd_id=$2";
598
599 $Res=$this->cn->exec_sql($sql,array($t,$this->id));
600
601
602 }
603 /*!\brief Save the class base
604 * \param $p_label label
605 */
606 function save_class_base($p_label)
607 {
608 if ( $this->id == 0 ) return;
609 $p_label=sql_string($p_label);
610
611 $sql="update fiche_def set fd_class_base=$1 ".
612 "where fd_id=$2";
613
614 $Res=$this->cn->exec_sql($sql,array($p_label,$this->id));
615 }
616 function save_description($p_description)
617 {
618 if ( $this->id == 0) return;
619 $this->cn->exec_sql("update fiche_def set fd_description=$1 where fd_id=$2",array($p_description,$this->id));
620 }
621
622
623 /*!\brief insert a new attribut for this fiche_def
624 * \param $p_ad_id id of the attribut
625 * \param int $p_order order of the attribut if -1 then computed
626 */
627 function insertAttribut($p_ad_id,$p_order=-1)
628 {
629 if ( $this->id == 0 ) return;
630 /* ORDER */
631 $this->load_attribute();
633 if ( $p_order == -1 ) {
634 $order = $this->cn->get_value("select ad_default_order from attr_def where ad_id=$1",[$p_ad_id]);
635 if ( $order == 0 || empty($order)) {
636 $max=$this->cn->get_value("select count(*) from jnt_fic_attr where fd_id=$1",[$this->id]);
637 $order=$max*15;
638 }
639 }
640 // Insert a new attribute for the model
641 // it means insert a row in jnt_fic_attr
642 $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (%d,%d,%d)",
643 $this->id,$p_ad_id,$order);
644 $Res=$this->cn->exec_sql($sql);
645 }
646 /*!\brief remove an attribut for this fiche_def
647 * \param array of ad_id to remove
648 * \remark you can't remove the attribut defined in attr_min
649 */
651 {
652 foreach ($array as $ch)
653 {
654 $this->cn->start();
655 $sql="delete from jnt_fic_attr where fd_id=$1 ".
656 " and ad_id=$2";
657 $this->cn->exec_sql($sql,array($this->id,$ch));
658
659 $sql="delete from fiche_detail where jft_id in ( select ".
660 " jft_id from fiche_Detail ".
661 " join fiche using(f_id) ".
662 " where ".
663 "fd_id = $1 and ".
664 "ad_id=$2)";
665 $this->cn->exec_sql($sql,array($this->id,$ch));
666
667 $this->cn->commit();
668 }
669 }
670
671 /*!\brief save the order of a card, update the column jnt_fic_attr.jnt_order
672 *\param $p_array containing the order
673 */
675 {
676 extract($p_array, EXTR_SKIP);
677 $this->load_attribute();
678 foreach ($this->attribut as $row)
679 {
680 if ( $row->ad_id == 1 ) continue;
681 if ( ${'jnt_order'.$row->ad_id} <= 0 ) continue;
682 $sql='update jnt_fic_attr set jnt_order=$1 where fd_id=$2 and ad_id=$3';
683 $this->cn->exec_sql($sql,array(${'jnt_order'.$row->ad_id},
684 $this->id,
685 $row->ad_id));
686
687 }
688 /* correct the order */
689 $this->cn->exec_sql('select attribute_correct_order()');
690 }
691
692
693 /*!\brief remove all the card from a categorie after having verify
694 *that the card is not used and then remove also the category
695 *\return the remains items, not equal to 0 if a card remains and
696 *then the category is not removed
697 */
698 function remove()
699 {
700 if ( $this->id >= 500000 ) {
701 throw new Exception(_('Catégorie verrouillée '));
702 }
703 $remain=0;
704 /* get all the card */
705 $aFiche=fiche::get_fiche_def($this->cn,$this->id);
706 if ( $aFiche != null )
707 {
708 /* check if the card is used */
709 foreach ($aFiche as $dfiche)
710 {
711 $fiche=new Fiche($this->cn,$dfiche['f_id']);
712
713 /* if the card is not used then remove it otherwise increment remains */
714 if ( $fiche->is_used() == false )
715 {
716 $fiche->delete();
717 }
718 else
719 $remain++;
720 }
721 }
722 /* if remains == 0 then remove cat */
723 if ( $remain == 0 )
724 {
725 $sql='delete from jnt_fic_attr where fd_id=$1';
726 $this->cn->exec_sql($sql,array($this->id));
727 $sql='delete from fiche_def where fd_id=$1';
728 $this->cn->exec_sql($sql,array($this->id));
729 }
730
731 return $remain;
732
733 }
734 /*!
735 * \brief retrieve the mandatory field of the card model
736 *
737 * \param $p_fiche_def_ref
738 * \return array of ad_id (attr_min.ad_id) and labels (attr_def.ad_text)
739 */
740 function get_attr_min($p_fiche_def_ref)
741 {
742
743 // find the min attr for the fiche_def_ref
744 $Sql="select ad_id,ad_text ,attr_min.ad_default_order
745 from attr_min
746 join attr_def using(ad_id)
747 join fiche_def_ref using(frd_id)
748 where
749 frd_id= $1 order by ad_default_order";
750 $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
752
753 // test the number of returned rows
754 if ($Num == 0 ) return null;
755
756 // Get Results & Store them in a array
757 for ($i=0;$i<$Num;$i++)
758 {
760 $array[$i]['ad_id']=$f['ad_id'];
761 $array[$i]['ad_text']=$f['ad_text'];
762 $array[$i]['ad_default_order']=$f['ad_default_order'];
763 }
764 return $array;
765 }
766 /*!
767 * \brief count the number of fiche_def (category) which has the frd_id (type of category)
768 *\param $p_frd_id is the frd_id in constant.php the FICHE_TYPE_
769 *\return the number of cat. of card of the given type
770 *\see constant.php
771 */
772 function count_category($p_frd_id)
773 {
774 $ret=$this->cn->count_sql("select fd_id from fiche_def where frd_id=$1",array($p_frd_id));
775 return $ret;
776 }
777
778 /**
779 * @brief ask for detail
780 * @return string
781 */
782 function input_detail()
783 {
784 $r = "";
785 // Save the label
786
787 $this->get();
788 $this->load_attribute();
789 $r.= '<H2 class="info">' . $this->id . " " . h($this->label) . '</H2>';
790 $r.='<fieldset><legend>'._('Données générales').'</legend>';
791
792 $nom_mod=$this->label;
793 /* the accounting item */
794 $class_base=new IPoste('class_base');
795 $class_base->set_attribute('ipopup','ipop_account');
796 $class_base->set_attribute('account','class_base');
797 $class_base->set_attribute('label','acc_label');
799 $f_class_base=$class_base->input();
800 $fd_description=new ITextarea('fd_description');
801 $fd_description->width=80;
802 $fd_description->heigh=4;
803 $fd_description->style='class="itextarea form-control input_text" style="margin-left:0px;vertical-align:text-top"';
805 $r.='<form method="post" style="display:inline">';
806 $r.=\HtmlInput::hidden('fd_id',$this->id);
807 ob_start();
808 require_once NOALYSS_TEMPLATE.'/fiche_def_input.php';
809 $r.=ob_get_contents();
810 ob_clean();
811 $r.=HtmlInput::submit('change_name', _('Sauver'));
812 $r.='</form>';
813 $r.='<form method="post" style="display:inline" id="catcard_remove" onsubmit="return confirm_box(this,\'Effacer?\')">';
814 $r.=HtmlInput::hidden("action", "remove_cat");
815 $r.=HtmlInput::hidden('fd_id',$this->id);
816 $r.=HtmlInput::submit('remove_cat', _('Effacer'));
817 $r.='</form>';
818
819
820
821 $r.='</fieldset>';
822 $r.='<hr>';
823 /* attributes */
824 $r.='<fieldset><legend>'._('Détails').'</legend>';
825
826 $r.= '<FORM id="input_detail_frm" method="POST">';
827 $r.=dossier::hidden();
828 $r.=HtmlInput::hidden("fd_id", $this->id);
829 $r.=HtmlInput::hidden("action", "");
830 // $r.= $this->DisplayAttribut("remove");
831 ob_start();
832 require NOALYSS_TEMPLATE."/fiche_def-input_detail-2.php";
833 $r.=ob_get_contents();
834 ob_clean();
835
836 $r.= "</form>";
837
838 $r.='</fieldset>';
839 return $r;
840 }
841
842
843 /**
844 * @brief input for creating a new category
845 * @return void
846 */
847 function input_new()
848 {
849 $single=new Single_Record("dup");
850 echo '<form method="post" style="display:inline" onsubmit="return check_new_category()">';
851 echo $single->hidden();
852 echo HtmlInput::hidden("p_action","fiche");
853 echo dossier::hidden();
854 $ref=$this->cn->get_array("select * from fiche_def_ref order by frd_text");
855 $iradio=new IRadio();
856 $nom_mod="";
857 /* the accounting item */
858 $class_base=new IPoste('class_base');
859 $class_base->set_attribute('ipopup','ipop_account');
860 $class_base->set_attribute('account','class_base');
861 $class_base->set_attribute('label','acc_label');
862 $f_class_base=$class_base->input();
863 $fd_description=new ITextarea('fd_description');
864 $fd_description->width=80;
865 $fd_description->heigh=4;
866 $fd_description->style='class="itextarea form-control input_text" style="margin-left:0px;vertical-align:text-top"';
867 require_once NOALYSS_TEMPLATE.'/fiche_def_input.php';
868 require_once NOALYSS_TEMPLATE.'/fiche_def-input_new.php';
869
870 echo HtmlInput::submit("add_modele" ,_("Sauve"));
871 echo '</FORM>';
872 }
873 /**
874 * @brief make an array of attributes of the category of card (FICHE_DEF.FD_ID)
875 *The array can be used with the function insert, it will return a struct like this :
876 * in the first key (av_textX), X is the ATTR_DEF::AD_ID
877 \verbatim
878 Example
879 Array
880 (
881 [av_text1] => Nom
882 [av_text12] => Personne de contact
883 [av_text5] => Poste Comptable
884 [av_text13] => numéro de tva
885 [av_text14] => Adresse
886 [av_text15] => code postal
887 [av_text24] => Ville
888 [av_text16] => pays
889 [av_text17] => téléphone
890 [av_text18] => email
891 [av_text23] => Quick Code
892 )
893
894 \endverbatim
895 *\param $pfd_id FICHE_DEF::FD_ID
896 *\return an array of attribute
897 *\exception Exception if the cat of card doesn't exist, Exception.getCode()=1
898 *\see fiche::insert()
899 */
900 function to_array()
901 {
902 $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
903 " ad_text ".
904 " from fiche_def join jnt_fic_attr using (fd_id)".
905 " join attr_def using (ad_id) ".
906 " where fd_id=$1 order by jnt_order";
907 $ret=$this->cn->get_array($sql,array($this->id));
908 if ( empty($ret)) throw new Exception(_('Cette categorie de card n\'existe pas').' '.$this->id,1);
909 $array=array();
910 foreach($ret as $idx=>$val)
911 {
912 $a=noalyss_str_replace(' ','',$val['key']);
913 $array[$a]=$val['ad_text'];
914 }
915 return $array;
916
917 }
918
919 /**
920 * @brief display existing attribut
921 * @param $attribut_id int SQL attr_def.ad_id
922 * @param $attribut_text SQL attr_def.ad_text
923 * @return void
924 */
925 public static function print_existing_attribut($attribut_id,$attribut_text)
926 {
927 include NOALYSS_TEMPLATE.'/fiche_def-print_existing_attribut.php';
928 }
929
930 /**
931 * @brief display available attribut
932 * @param $attribut_id int SQL attr_def.ad_id
933 * @param $attribut_text SQL attr_def.ad_text
934 * @return void
935 */
936 public static function print_available_attribut($attribut_id,$attribut_text,$class)
937 {
938 include NOALYSS_TEMPLATE.'/fiche_def-print_available_attribut.php';
939 }
940}
941?>
noalyss_strlentrim($p_string)
noalyss_str_replace($search, $replace, $string)
sql_string($p_string)
Fix the problem with the quote char for the database.
noalyss_trim($p_string)
alert($p_msg, $buffer=false)
alert in javascript
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
$ret label
$_REQUEST['ac']
$str_dossier
$input_from cn
_("actif, passif,charge,...")
$_GET['qcode']
$class
Display the Plugin and for each profile were it is installed or not.
contains the attributes of a card , manage them, save them , ...
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
define Class fiche and fiche def, those class are using class attribut
static print_existing_attribut($attribut_id, $attribut_text)
display existing attribut
get_by_category($template_category, $inactive=1)
Get all the card where the fiche_def.frd_id is given in parameter, it is the template for category.
save_description($p_description)
input()
show the content of the form to create a new Fiche_Def_Ref
load()
alias for Fiche_Def->get(),
$id
id (fiche_def.fd_id
getAttribut()
replace by load_attribute
save_class_base($p_label)
Save the class base.
Add($array)
Add a fiche category thanks the element from the array you cannot add twice the same cat....
DisplayAttribut($str="")
Display all the attribut of the fiche_def.
$cn
database connection
to_array()
make an array of attributes of the category of card (FICHE_DEF.FD_ID) The array can be used with the ...
myList()
list the card of a fd_id
display()
Display all card categories into a table.
count_category($p_frd_id)
count the number of fiche_def (category) which has the frd_id (type of category)
get_attr_min($p_fiche_def_ref)
retrieve the mandatory field of the card model
$attribut
get from attr_xxx tables
$fiche_def
fiche_def.frd_id = fiche_def_ref.frd_id
removeAttribut($array)
remove an attribut for this fiche_def
insertAttribut($p_ad_id, $p_order=-1)
insert a new attribut for this fiche_def
$fd_description
Description of the Card Category.
get_by_type($step=0, $inactive=1)
Get all the card where the fiche_def.fd_id is given in parameter.
$create_account
fd_create_account: flag
$class_base
fiche_def.fd_class_base
HasAttribute($p_attr)
Check in vw_fiche_def if a fiche has a attribut X.
load_attribute()
Get attribute of a fiche_def.
input_new()
input for creating a new category
set_autocreate($p_label)
set the auto create accounting item for each card and save it into the database
input_detail()
ask for detail
save_order($p_array)
save the order of a card, update the column jnt_fic_attr.jnt_order
static print_available_attribut($attribut_id, $attribut_text, $class)
display available attribut
get_all()
Get all the fiche_def.
$label
fiche_def.fd_label
__construct($cn, $id=0)
SaveLabel($p_label)
Save the label of the fiche_def.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
manage the http input (get , post, request) and extract from an array
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input.
Html Input Text member :
Manage the TEXTAREA html element.
Objec to check a double insert into the database, this duplicate occurs after a refresh of the web pa...
Description of class_syn_sort_table.
$t
Definition compute.php:46
const ATTR_DEF_NAME
Definition constant.php:223
const ATTR_DEF_QUICKCODE
Definition constant.php:244
const ATTR_DEF_ACCOUNT
Definition constant.php:222
$count
$fd_id
catch(\Exception $e) $bar
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)