noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_fiche_def.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00020 include_once("class_fiche_attr.php");
00021 require_once("class_itext.php");
00022 require_once('class_fiche_def_ref.php');
00023 require_once('class_fiche.php');
00024 require_once('user_common.php');
00025 require_once('class_iradio.php');
00026 
00027 /*! \file
00028  * \brief define Class fiche and fiche def, those class are using
00029  *        class attribut
00030  */
00031 /*!
00032  * \brief define Class fiche and fiche def, those class are using
00033  *        class attribut
00034  */
00035 class Fiche_Def
00036 {
00037     var $cn;           // database connection
00038     var $id;                    // id (fiche_def.fd_id
00039     var $label;                 // fiche_def.fd_label
00040     var $class_base;            // fiche_def.fd_class_base
00041     var $fiche_def;             // fiche_def.frd_id = fiche_def_ref.frd_id
00042     var $create_account;                // fd_create_account: flag
00043     var $all;
00044     var $attribut;              // get from attr_xxx tables
00045     function __construct($p_cn,$p_id = 0)
00046     {
00047         $this->cn=$p_cn;
00048         $this->id=$p_id;
00049     }
00050     /*!\brief show the content of the form to create  a new Fiche_Def_Ref
00051     */
00052     function input ()
00053     {
00054         $ref=$this->cn->get_array("select * from fiche_def_ref order by frd_text");
00055         $iradio=new IRadio();
00056         /* the accounting item */
00057         $class_base=new IPoste('class_base');
00058         $class_base->set_attribute('ipopup','ipop_account');
00059         $class_base->set_attribute('account','class_base');
00060         $class_base->set_attribute('label','acc_label');
00061         $f_class_base=$class_base->input();
00062                 $fd_description=new ITextarea('fd_description');
00063                 $fd_description->width=80;
00064                 $fd_description->heigh=4;
00065                 $fd_description->style='style="vertical-align:text-top"';
00066         require_once ('template/fiche_def_input.php');
00067         return;
00068     }
00069 
00070     /*!
00071      *  \brief  Get attribut of a fiche_def
00072      *
00073      * \return string value of the attribute
00074      */
00075     function getAttribut()
00076     {
00077         $sql="select * from jnt_fic_attr ".
00078              " natural join attr_def where fd_id=".$this->id.
00079              " order by jnt_order";
00080 
00081         $Ret=$this->cn->exec_sql($sql);
00082 
00083         if ( ($Max=Database::num_row($Ret)) == 0 )
00084             return ;
00085         for ($i=0;$i < $Max;$i++)
00086         {
00087             $row=Database::fetch_array($Ret,$i);
00088             $t = new Fiche_Attr($this->cn);
00089             $t->ad_id=$row['ad_id'];
00090             $t->ad_text=$row['ad_text'];
00091             $t->jnt_order=$row['jnt_order'];
00092             $t->ad_size=$row['ad_size'];
00093             $t->ad_type=$row['ad_type'];
00094             $t->ad_extra=$row['ad_extra'];
00095             $this->attribut[$i]=clone $t;
00096         }
00097         return $this->attribut;
00098     }
00099 
00100     /*!
00101     * \brief  Get attribut of the fiche_def
00102     *
00103     */
00104     function get()
00105     {
00106         if ( $this->id == 0 )
00107             return 0;
00108         /*    $this->cn->exec_sql('select fiche_attribut_synchro($1)',
00109         array($this->id));
00110         */
00111         $sql="select * from fiche_def ".
00112              " where fd_id=".$this->id;
00113         $Ret=$this->cn->exec_sql($sql);
00114         if ( ($Max=Database::num_row($Ret)) == 0 )
00115             return ;
00116         $row=Database::fetch_array($Ret,0);
00117         $this->label=$row['fd_label'];
00118         $this->class_base=$row['fd_class_base'];
00119         $this->fiche_def=$row['frd_id'];
00120         $this->create_account=$row['fd_create_account'];
00121         $this->fd_description=$row['fd_description'];
00122     }
00123     /*!
00124      **************************************************
00125      * \brief  Get all the fiche_def
00126      *
00127      * \return an array of fiche_def object
00128      */
00129     function get_all()
00130     {
00131         $sql="select * from fiche_def ";
00132 
00133         $Ret=$this->cn->exec_sql($sql);
00134         if ( ($Max=Database::num_row($Ret)) == 0 )
00135             return ;
00136 
00137         for ( $i = 0; $i < $Max;$i++)
00138         {
00139             $row=Database::fetch_array($Ret,$i);
00140             $this->all[$i]=new Fiche_Def($this->cn,$row['fd_id']);
00141             $this->all[$i]->label=$row['fd_label'];
00142             $this->all[$i]->class_base=$row['fd_class_base'];
00143             $this->all[$i]->fiche_def=$row['frd_id'];
00144             $this->all[$i]->create_account=$row['fd_create_account'];
00145         }
00146     }
00147     /*!
00148      **************************************************
00149      * \brief  Check in vw_fiche_def if a fiche has
00150      *           a attribut X
00151      *
00152      *
00153      * \param  $p_attr attribut to check
00154      * \return  true or false
00155      */
00156     function HasAttribute($p_attr)
00157     {
00158         return ($this->cn->count_sql("select * from vw_fiche_def where ad_id=$p_attr and fd_id=".$this->id)>0)?true:false;
00159 
00160     }
00161     /*!
00162      **************************************************
00163      * \brief  Display category into a table
00164      *
00165      * \return HTML row
00166      */
00167     function Display()
00168     {
00169                 $tab = new Sort_Table();
00170 
00171                 $url = HtmlInput::get_to_string(array('ac', 'gDossier'));
00172                 $tab->add("Nom de fiche", $url, "order by fd_label asc", "order by fd_label desc", "na", "nd");
00173                 $tab->add("Basé sur le poste comptable", $url, "order by fd_class_base asc", "order by fd_class_base desc", "pa", "pd");
00174                 $tab->add("Calcul automatique du poste comptable", $url, "order by fd_create_account asc", "order by fd_create_account desc", "ca", "cd");
00175                 $tab->add("Basé sur le modèle", $url, "order by frd_text asc", "order by frd_text  desc", "ma", "md");
00176 
00177                 $order = (isset($_GET['ord'])) ? $tab->get_sql_order($_GET["ord"]) : $tab->get_sql_order("na");
00178 
00179 
00180                 $res = $this->cn->exec_sql("SELECT fd_id, fd_class_base, fd_label, fd_create_account, fiche_def_ref.frd_id,
00181 frd_text , fd_description FROM fiche_def join fiche_def_ref on (fiche_def.frd_id=fiche_def_ref.frd_id)
00182 $order
00183 ");
00184 
00185                 require_once 'template/fiche_def_list.php';
00186         }
00187     /*!\brief Add a fiche category thanks the element from the array
00188      * you cannot add twice the same cat. name
00189      * table : insert into fiche_def
00190      *         insert into attr_def
00191      *
00192      * \param $array array
00193      *        index FICHE_REF
00194      *              nom_mod
00195      *              class_base
00196      */
00197     function Add($array)
00198     {
00199         foreach ( $array as $key=>$element )
00200         {
00201             ${"p_$key"}=$element;
00202         }
00203         // Format correctly the name of the cat. of card
00204         $p_nom_mod=sql_string($p_nom_mod);
00205 
00206 
00207         // Name can't be empty
00208         if ( strlen(trim($p_nom_mod)) == 0 )
00209                 {
00210                         alert (_('Le nom de la catégorie ne peut pas être vide'));
00211             return 1;
00212                 }
00213         /**!! (== fiche_def_ref.frd_id
00214         if (! isset ($p_FICHE_REF) || strlen($p_FICHE_REF) == 0 )
00215         {
00216             echo alert (_('Vous devez choisir une categorie'));
00217             return 1;
00218         }
00219         $fiche_Def_ref=new Fiche_Def_Ref($this->cn,$p_FICHE_REF);
00220         $fiche_Def_ref->Get();
00221 
00222         // build the sql request for fiche_def
00223         // and insert into fiche_def
00224         // if p_class_base is null get the default class base from
00225         // fiche_def_ref
00226         if ( sql_string($p_class_base) == null )
00227         { // p_class is null
00228             // So we take the default one
00229             $p_class_base=$fiche_Def_ref->frd_class_base;
00230         }
00231         /* check if the cat. name already exists */
00232         $sql="select count(*) from fiche_Def where upper(fd_label)=upper($1)";
00233         $count=$this->cn->get_value($sql,array(trim($p_nom_mod)));
00234 
00235         if ($count != 0 ) {
00236                          echo alert (_('Catégorie existante'));
00237                         return 1;
00238                 }
00239         // Set the value of fiche_def.fd_create_account
00240         // automatic creation for 'poste comptable'
00241         if ( isset($p_create) && strlen(trim($p_class_base)) != 0)
00242             $p_create='true';
00243         else
00244             $p_create='false';
00245 
00246         // Class is valid ?
00247         if ( sql_string($p_class_base) != null || strpos(',',$p_class_base) != 0 )
00248         {
00249             // p_class is a valid number
00250             $sql="insert into fiche_def(fd_label,fd_class_base,frd_id,fd_create_account,fd_description)
00251                  values ($1,$2,$3,$4,$5) returning fd_id";
00252 
00253             $fd_id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_FICHE_REF,$p_create,$p_fd_description));
00254 
00255             // p_class must be added to tmp_pcmn if it is a single accounting
00256             if ( strpos(',',$p_class_base) ==0)
00257             {
00258                 $sql="select account_add($1,$2)";
00259                 $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
00260             }
00261                         // Get the fd_id
00262                         $fd_id=$this->cn->get_current_seq('s_fdef');
00263 
00264                         // update jnt_fic_attr
00265                         $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
00266                                          values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
00267                         $Res=$this->cn->exec_sql($sql);
00268         }
00269         else
00270         {
00271             //There is no class base not even as default
00272             $sql="insert into fiche_def(fd_label,frd_id,fd_create_account,fd_description) values ($1,$2,$3,$4) returning fd_id";
00273 
00274 
00275             $this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_FICHE_REF,$p_create,$p_fd_description));
00276 
00277             // Get the fd_id
00278             $fd_id=$this->cn->get_current_seq('s_fdef');
00279 
00280         }
00281 
00282         // Get the default attr_def from attr_min
00283         $def_attr=$this->get_attr_min($p_FICHE_REF);
00284 
00285         //if defaut attr not null
00286         // build the sql insert for the table attr_def
00287         if (sizeof($def_attr) != 0 )
00288         {
00289             // insert all the mandatory fields into jnt_fiche_attr
00290             $jnt_order=10;
00291             foreach ( $def_attr as $i=>$v)
00292             {
00293                                 $order=$jnt_order;
00294                 if ( $v['ad_id'] == ATTR_DEF_NAME )
00295                     $order=0;
00296                                 $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']));
00297                                 if ($count == 0)
00298                                 {
00299                                         $sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id,jnt_order)
00300                              values (%d,%s,%d)",
00301                              $fd_id,$v['ad_id'],$order);
00302                                         $this->cn->exec_sql($sql);
00303                                         $jnt_order+=10;
00304                                 }
00305             }
00306         }
00307         $this->id=$fd_id;
00308         return 0;
00309 
00310     }//--------------end function Add ----------------------------
00311     /*!
00312      * \brief Get all the card where the fiche_def.fd_id is given in parameter
00313      * \param $step = 0 we don't use the offset, page_size,...
00314      *        $step = 1 we use the jnr_bar_nav
00315      *
00316      * \return array ('f_id'=>..,'ad_value'=>..)
00317      *\see fiche
00318      */
00319     function get_by_type($step=0)
00320     {
00321         $sql="select f_id,ad_value
00322              from
00323              fiche join fiche_detail using(f_id)
00324              where ad_id=1 and fd_id=$1 order by 2";
00325 
00326         // we use navigation_bar
00327         if ($step == 1  && $_SESSION['g_pagesize'] != -1   )
00328         {
00329             $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00330             $step=$_SESSION['g_pagesize'];
00331             $sql.=" offset $offset limit $step";
00332         }
00333 
00334         $Ret=$this->cn->get_array($sql,array($this->id));
00335 
00336         return $Ret;
00337     }
00338     /*!
00339      * \brief Get all the card where the fiche_def.frd_id is given in parameter
00340      * \return array of fiche or null is nothing is found
00341      */
00342     function get_by_category($p_cat)
00343     {
00344         $sql="select f_id,ad_value
00345              from
00346              fiche join fiche_def  using(fd_id)
00347              join fiche_detail using(f_id)
00348              where ad_id=1 and frd_id=$1 order by 2 ";
00349 
00350         $Ret=$this->cn->exec_sql($sql,array($p_cat));
00351         if ( ($Max=Database::num_row($Ret)) == 0 )
00352             return null;
00353         $all[0]=new Fiche($this->cn);
00354 
00355         for ($i=0;$i<$Max;$i++)
00356         {
00357             $row=Database::fetch_array($Ret,$i);
00358             $t=new Fiche($this->cn,$row['f_id']);
00359             $t->getAttribut();
00360             $all[$i]=$t;
00361 
00362         }
00363         return $all;
00364     }
00365 
00366     /*!\brief list the card of a fd_id
00367      */
00368     function myList()
00369     {
00370         $this->get();
00371         echo '<H2 class="info">'.$this->id." ".$this->label.'</H2>';
00372 
00373         $step=$_SESSION['g_pagesize'];
00374         $sql_limit="";
00375         $sql_offset="";
00376         $bar="";
00377         if ( $step != -1 )
00378         {
00379 
00380             $page=(isset($_GET['page']))?$_GET['page']:1;
00381             $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00382             $max_line=$this->cn->count_sql("select f_id,ad_value  from
00383                                            fiche join fiche_detail using (f_id)
00384                                            where fd_id='".$this->id."' and ad_id=".ATTR_DEF_NAME." order by f_id");
00385             $sql_limit=" limit ".$step;
00386             $sql_offset=" offset ".$offset;
00387             $bar=navigation_bar($offset,$max_line,$step,$page);
00388         }
00389 
00390         // Get all name the cards of the select category
00391         // 1 for attr_def.ad_id is always the name
00392         $Res=$this->cn->exec_sql("select f_id,vw_name,quick_code  from ".
00393                                  " vw_fiche_attr ".
00394                                  " where fd_id='".$this->id.
00395                                  "' order by f_id $sql_offset $sql_limit ");
00396         $Max=Database::num_row($Res);
00397         echo $bar;
00398         $str="";
00399         // save the url
00400         // with offet &offset=15&step=15&page=2&size=15
00401         if ( $_SESSION['g_pagesize'] != -1)
00402         {
00403             $str=sprintf("&offset=%s&step=%s&page=%s&size=%s",
00404                          $offset,
00405                          $step,
00406                          $page,
00407                          $max_line);
00408         }
00409 
00410 
00411         echo '<FORM METHOD="POST" action="?p_action=fiche&action=vue'.$str.'">';
00412         echo HtmlInput::hidden('ac',$_REQUEST['ac']);
00413         echo dossier::hidden();
00414         echo HtmlInput::hidden("fiche",$this->id);
00415         echo HtmlInput::submit('add','Ajout fiche');
00416         echo '</FORM>';
00417         $str_dossier=dossier::get();
00418         echo '<table>';
00419         for ( $i = 0; $i < $Max; $i++)
00420         {
00421             $l_line=Database::fetch_array($Res,$i);
00422             if ( $i%2 == 0)
00423                 echo '<TR class="odd">';
00424             else
00425                 echo '<TR class="even">';
00426 
00427             $span_mod='<TD><A href="?p_action=fiche&'.$str_dossier.
00428                     '&action=detail&fiche_id='.$l_line['f_id'].$str.'&fiche='.
00429                     $_REQUEST['fiche'].'&ac='.$_REQUEST['ac'].'">'.$l_line['quick_code']
00430                     .'</A></TD>';
00431 
00432             echo $span_mod.'<TD>'.h($l_line['vw_name'])."</TD>";
00433             echo '</tr>';
00434         }
00435         echo '</table>';
00436         echo '<FORM METHOD="POST" action="?p_action=fiche&action=vue'.$str.'">';
00437         echo HtmlInput::hidden('ac',$_REQUEST['ac']);
00438         echo dossier::hidden();
00439         echo HtmlInput::hidden("fiche",$this->id);
00440         echo HtmlInput::submit('add','Ajout fiche');
00441         echo '</FORM>';
00442         echo $bar;
00443 
00444     }
00445     /*!\brief show input for the basic attribute : label, class_base, create_account
00446      * use only when we want to update
00447      *
00448      *\return HTML string with the form
00449      */
00450     function input_base()
00451     {
00452         $r="";
00453         $r.=_('Label');
00454         $label=new IText('label',$this->label);
00455         $r.=$label->input();
00456         $r.='<br>';
00457         /* the accounting item */
00458         $class_base=new IPoste('class_base',$this->class_base);
00459         $class_base->set_attribute('ipopup','ipop_account');
00460         $class_base->set_attribute('account','class_base');
00461         $class_base->set_attribute('label','acc_label');
00462                 $fd_description=new ITextarea('fd_description',$this->fd_description);
00463                 $fd_description->width=80;
00464                 $fd_description->heigh=4;
00465                 $fd_description->style='style="vertical-align:text-top"';
00466         $r.=_('Poste Comptable de base').' : ';
00467         $r.=$class_base->input();
00468         $r.='<span id="acc_label"></span><br>';
00469                 $r.='<br/>';
00470                 $r.=" Description ".$fd_description->input();
00471         /* auto Create */
00472                 $r.='<br/>';
00473         $ck=new ICheckBox('create');
00474         $ck->selected=($this->create_account=='f')?false:true;
00475         $r.=_('Chaque fiche aura automatiquement son propre poste comptable : ');
00476         $r.=$ck->input();
00477         return $r;
00478     }
00479     /*!\brief Display all the attribut of the fiche_def
00480      *\param $str give the action possible values are remove, empty
00481      */
00482     function DisplayAttribut($str="")
00483     {
00484         if ( $this->id == 0 )
00485             return ;
00486            $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($this->id));
00487 
00488                    $MaxLine=sizeof($this->attribut);
00489         $r="<TABLE>";
00490         $r.="<tr>".th('Nom attribut').th('').th('Ordre','style="text-align:right"').'</tr>';
00491         // Display each attribute
00492         $add_action="";
00493         for ($i=0;$i<$MaxLine;$i++)
00494         {
00495             $class="even";
00496             if ( $i % 2 == 0 )
00497                 $class="odd";
00498 
00499             $r.='<TR class="'.$class.'"><td>';
00500             // Can change the name
00501             if ( $this->attribut[$i]->ad_id == ATTR_DEF_NAME )
00502             {
00503                 continue;
00504             }
00505             else
00506             {
00507                 if ( $str == "remove" )
00508                 {
00509                     //Only for the not mandatory attribute (not defined in attr_min)
00510                     if ( $this->cn->count_sql("select * from attr_min where frd_id=".
00511                                               $this->fiche_def." and ad_id = ".$this->attribut[$i]->ad_id) == 0
00512                             && $this->attribut[$i]->ad_id != ATTR_DEF_QUICKCODE
00513                             && $this->attribut[$i]->ad_id != ATTR_DEF_ACCOUNT
00514                        )
00515                     {
00516                         $add_action=sprintf( '</TD><TD> Supprimer <input type="checkbox" name="chk_remove[]" value="%d">',
00517                                              $this->attribut[$i]->ad_id);
00518                     }
00519                     else
00520                         $add_action="</td><td>";
00521                 }
00522                 // The attribut.
00523                 $a=sprintf('%s ',  $this->attribut[$i]->ad_text);
00524                 $r.=$a.$add_action;
00525                 /*----------------------------------------  */
00526                 /*  ORDER OF THE CARD */
00527                 /*----------------------------------------  */
00528                 $order=new IText();
00529                 $order->name='jnt_order'.$this->attribut[$i]->ad_id;
00530                 $order->size=3;
00531                 $order->value=$this->attribut[$i]->jnt_order;
00532                 $r.='</td><td> '.$order->input();
00533             }
00534             $r.= '</td></tr>';
00535         }
00536 
00537         // Show the possible attribute which are not already attribute of the model
00538         // of card
00539         $Res=$this->cn->exec_sql("select ad_id,ad_text from attr_def
00540                                  where
00541                                  ad_id not in (select ad_id from fiche_def natural join jnt_fic_attr
00542                                  where fd_id=$1) order by ad_text",array($this->id) );
00543         $M=Database::num_row($Res);
00544 
00545         // Show the unused attribute
00546         $r.='<TR> <TD>';
00547         $r.= '<SELECT NAME="ad_id">';
00548         for ($i=0;$i<$M;$i++)
00549         {
00550             $l=Database::fetch_array($Res,$i);
00551             $a=sprintf('<OPTION VALUE="%s"> %s',
00552                        $l['ad_id'],$l['ad_text']);
00553             $r.=$a;
00554         }
00555         $r.='</SELECT>';
00556 
00557         $r.="</TABLE>";
00558         return $r;
00559     }
00560     /*!\brief Save the label of the fiche_def
00561      * \param $p_label label
00562      */
00563     function SaveLabel($p_label)
00564     {
00565         if ( $this->id == 0 ) return;
00566         $p_label=sql_string($p_label);
00567         if (strlen(trim ($p_label)) == 0 )
00568         {
00569             return;
00570         }
00571         $sql=sprintf("update   fiche_def set fd_label='%s' ".
00572                      "where                    fd_id=%d",
00573                      $p_label,$this->id);
00574         $Res=$this->cn->exec_sql($sql);
00575 
00576     }
00577     /*!\brief set the auto create accounting item for each card and
00578      * save it into the database
00579      * \param $p_label true or false
00580      */
00581     function set_autocreate($p_label)
00582     {
00583         if ( $this->id == 0 ) return;
00584         if ($p_label==true)
00585             $t='t';
00586         if ($p_label==false)
00587             $t='f';
00588 
00589         $sql="update   fiche_def set fd_create_account=$1 ".
00590              "where                    fd_id=$2";
00591 
00592         $Res=$this->cn->exec_sql($sql,array($t,$this->id));
00593 
00594     }
00595     /*!\brief Save the class base
00596      * \param $p_label label
00597      */
00598     function save_class_base($p_label)
00599     {
00600         if ( $this->id == 0 ) return;
00601         $p_label=sql_string($p_label);
00602 
00603         $sql="update   fiche_def set fd_class_base=$1 ".
00604              "where                    fd_id=$2";
00605 
00606         $Res=$this->cn->exec_sql($sql,array($p_label,$this->id));
00607     }
00608         function save_description($p_description)
00609         {
00610                 if ( $this->id == 0)                    return;
00611                 $this->cn->exec_sql("update fiche_def set fd_description=$1 where fd_id=$2",array($p_description,$this->id));
00612         }
00613 
00614 
00615     /*!\brief insert a new attribut for this fiche_def
00616      * \param $p_ad_id id of the attribut
00617      */
00618     function InsertAttribut($p_ad_id)
00619     {
00620         if ( $this->id == 0 ) return;
00621         /* ORDER */
00622         $this->GetAttribut();
00623         $max=sizeof($this->attribut)*15;
00624         // Insert a new attribute for the model
00625         // it means insert a row in jnt_fic_attr
00626         $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (%d,%d,%d)",
00627                      $this->id,$p_ad_id,$max);
00628         $Res=$this->cn->exec_sql($sql);
00629         // update all the existing card
00630 
00631     }
00632     /*!\brief remove an attribut for this fiche_def
00633      * \param array of ad_id to remove
00634      * \remark you can't remove the attribut defined in attr_min
00635      */
00636     function RemoveAttribut($array)
00637     {
00638         foreach ($array as $ch)
00639         {
00640             $this->cn->start();
00641             $sql="delete from jnt_fic_attr where fd_id=$1 ".
00642                  "   and ad_id=$2";
00643             $this->cn->exec_sql($sql,array($this->id,$ch));
00644 
00645             $sql="delete from fiche_detail  where jft_id in ( select ".
00646                  " jft_id from fiche_Detail ".
00647                  " join fiche using(f_id) ".
00648                  " where ".
00649                  "fd_id = $1 and ".
00650                  "ad_id=$2)";
00651             $this->cn->exec_sql($sql,array($this->id,$ch));
00652 
00653             $this->cn->commit();
00654         }
00655     }
00656 
00657     /*!\brief save the order of a card, update the column jnt_fic_attr.jnt_order
00658      *\param $p_array containing the order
00659      */
00660     function save_order($p_array)
00661     {
00662         extract($p_array);
00663         $this->GetAttribut();
00664         foreach ($this->attribut as $row)
00665         {
00666             if ( $row->ad_id == 1 ) continue;
00667             if ( ${'jnt_order'.$row->ad_id} <= 0 ) continue;
00668             $sql='update jnt_fic_attr set jnt_order=$1 where fd_id=$2 and ad_id=$3';
00669             $this->cn->exec_sql($sql,array(${'jnt_order'.$row->ad_id},
00670                                            $this->id,
00671                                            $row->ad_id));
00672 
00673         }
00674         /* correct the order */
00675         $this->cn->exec_sql('select attribute_correct_order()');
00676     }
00677 
00678 
00679     /*!\brief remove all the card from a categorie after having verify
00680      *that the card is not used and then remove also the category
00681      *\return the remains items, not equal to 0 if a card remains and
00682      *then the category is not removed
00683      */
00684     function remove()
00685     {
00686         $remain=0;
00687         /* get all the card */
00688         $aFiche=fiche::get_fiche_def($this->cn,$this->id);
00689         if ( $aFiche != null )
00690         {
00691             /* check if the card is used */
00692             foreach ($aFiche as $dfiche)
00693             {
00694               $fiche=new Fiche($this->cn,$dfiche['f_id']);
00695 
00696                 /* if the card is not used then remove it otherwise increment remains */
00697                 if ( $fiche->is_used() == false )
00698                 {
00699                     $fiche->delete();
00700                 }
00701                 else
00702                     $remain++;
00703             }
00704         }
00705         /* if remains == 0 then remove cat */
00706         if ( $remain == 0 )
00707         {
00708             $sql='delete from jnt_fic_attr where fd_id=$1';
00709             $this->cn->exec_sql($sql,array($this->id));
00710             $sql='delete from fiche_def where fd_id=$1';
00711             $this->cn->exec_sql($sql,array($this->id));
00712         }
00713 
00714         return $remain;
00715 
00716     }
00717     /*!
00718      * \brief  retrieve the mandatory field of the card model
00719      *
00720      * \param $p_fiche_def_ref
00721      * \return array of ad_id  (attr_min.ad_id) and  labels (attr_def.ad_text)
00722      */
00723     function get_attr_min($p_fiche_def_ref)
00724     {
00725 
00726         // find the min attr for the fiche_def_ref
00727         $Sql="select ad_id,ad_text from attr_min natural join attr_def
00728              natural join fiche_def_ref
00729              where
00730              frd_id= $1";
00731         $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
00732         $Num=Database::num_row($Res);
00733 
00734         // test the number of returned rows
00735         if ($Num == 0 ) return null;
00736 
00737         // Get Results & Store them in a array
00738         for ($i=0;$i<$Num;$i++)
00739         {
00740             $f=Database::fetch_array($Res,$i);
00741             $array[$i]['ad_id']=$f['ad_id'];
00742             $array[$i]['ad_text']=$f['ad_text'];
00743         }
00744         return $array;
00745     }
00746     /*!\brief count the number of fiche_def (category) which has the frd_id (type of category)
00747      *\param $p_frd_id is the frd_id in constant.php the FICHE_TYPE_
00748      *\return the number of cat. of card of the given type
00749      *\see constant.php
00750      */
00751     function count_category($p_frd_id)
00752     {
00753         $ret=$this->cn->count_sql("select fd_id from fiche_def where frd_id=$1",array($p_frd_id));
00754         return $ret;
00755     }
00756         function input_detail()
00757         {
00758                 $r = "";
00759                 // Save the label
00760 
00761                 $this->get();
00762                 $this->GetAttribut();
00763                 $r.= '<H2 class="info">' . $this->id . " " . h($this->label) . '</H2>';
00764                 $r.='<fieldset><legend>Données générales</legend>';
00765 
00766                 /* show the values label class_base and create account */
00767                 $r.='<form method="post">';
00768                 $r.=dossier::hidden();
00769                 $r.=HtmlInput::hidden("fd_id", $this->id);
00770                 $r.=HtmlInput::hidden("p_action", "fiche");
00771                 $r.= $this->input_base();
00772                 $r.='<hr>';
00773                 $r.=HtmlInput::submit('change_name', _('Sauver'));
00774                 $r.='</form>';
00775                 $r.='</fieldset>';
00776                 /* attributes */
00777                 $r.='<fieldset><legend>Détails</legend>';
00778 
00779                 $r.= '<FORM  method="POST">';
00780                 $r.=dossier::hidden();
00781                 $r.=HtmlInput::hidden("fd_id", $this->id);
00782                 $r.= $this->DisplayAttribut("remove");
00783                 $r.= HtmlInput::submit('add_line', _('Ajoutez cet élément'));
00784                 $r.= HtmlInput::submit("save_line", _("Sauvez"));
00785                 $r.=HtmlInput::submit('remove_cat', _('Effacer cette catégorie'), 'onclick="return confirm(\'' . _('Vous confirmez ?') . '\')"');
00786                 // if there is nothing to remove then hide the button
00787                 if (strpos($r, "chk_remove") != 0)
00788                 {
00789                         $r.=HtmlInput::submit('remove_line', _("Enleve les éléments cochés"), "onclick=\"return confirm('Vous confirmez?')\"");
00790                 }
00791                 $r.= "</form>";
00792                 $r.=" <p class=\"notice\"> " . _("Attention : il n'y aura pas de demande de confirmation pour enlever les
00793                                    attributs sélectionnés. Il ne sera pas possible de revenir en arrière") . "</p>";
00794                 $r.='</fieldset>';
00795                 return $r;
00796         }
00797         function input_new()
00798         {
00799                 $single=new Tool_Uos("dup");
00800                 echo '<form method="post" style="display:inline">';
00801                 echo $single->hidden();
00802                 echo HtmlInput::hidden("p_action","fiche");
00803                 echo dossier::hidden();
00804                 echo $this->input(); //    CreateCategory($cn,$search);
00805                 echo HtmlInput::submit("add_modele" ,"Sauve");
00806                 echo '</FORM>';
00807         }
00808 
00809 }
00810 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations