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