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