$element){ ${"p_$key"}=$element; echo_debug("p_$key=$element;"); } $base=GetBaseFiche($p_cn,$p_type); $num=GetNextFiche($p_cn,$base); $sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent) values (%s,'%s',%d)", $num, $p_nom0, $base); echo_debug($sql); $Res=ExecSql($p_cn,$sql); $sql=sprintf("insert into fiche ( f_id,f_label,f_fd_id) values (%d,'%s',%d)", $num,$p_nom0,$p_type); $Res=ExecSql($p_cn,$sql); for ( $i = 1; $i < $p_inc;$i++) { $sql=sprintf("insert into isupp (is_f_id,is_isd_id,is_value) values ( %d,%d,'%s')", $num, ${"p_isd_id$i"},${"p_nom$i"}); echo_debug($sql); $Res=ExecSql($p_cn,$sql); } } /* function EncodeFiche * Purpose : Affiche les détails d'une fiche et propose * de mettre à jour * ou si array est a null, permet d'ajouter une * fiche * * parm : * - p_cn connexion * - p_type id du modele fichedef(fd_id) de la fiche SI array est null * sinon correspond au id d'une fiche fiche(f_id) * gen : * - none * return: * - none * */ function EncodeFiche($p_cn,$p_type,$p_array=null) { echo_debug("function EncodeFiche($p_cn,$p_type) "); $ch_col=""; $ch_li=''; echo '
'; echo ''; echo ""; if ($p_array == null) { echo '

'.getFicheName($p_cn,$p_type).'

'; $p_f_id=""; echo_debug("Array is null"); $sql="select isd_id,isd_label from isupp_def where isd_fd_id=".$p_type; $Res=ExecSql($p_cn,$sql); $Max=pg_NumRows($Res); echo ''; for ($i=0;$i < $Max;$i++) { $l_line=pg_fetch_array($Res,$i); $Hid=sprintf('', $i,$l_line['isd_id']); printf ('', $l_line['isd_label'], $i,$Hid); } echo ''; echo '
%s %s
'; echo ''; echo ''; echo '
'; }else { $sql="select f_label,f_fd_id from fiche where f_id=".$p_type; $Res=ExecSql($p_cn,$sql); $Max=pg_NumRows($Res); if ( $Max == 0 ) return; $l_line=pg_fetch_array($Res,0); echo '

'.getFicheName($p_cn,$l_line['f_fd_id']).'

'; printf('
', $l_line['f_label']); echo ''; $sql="select isd_fd_id,isd_id,isd_label,is_value,is_id,is_f_id from isupp left join isupp_def on isd_id=is_isd_id where is_f_id=".$p_type; $Res=ExecSql($p_cn,$sql); $Max=pg_NumRows($Res); echo_debug("Max ==== $Max"); echo ''; echo ''; for ($i=0;$i < $Max;$i++) { $l_line=pg_fetch_array($Res,$i); $Hid=sprintf('', $i,$l_line['is_id']); printf (' %s %s', $l_line['isd_label'], $i, $l_line['is_value'],$Hid); } echo ''; echo ''; echo ''; echo ''; } } /* function GetBaseFiche * Purpose : donne la classe comptable de base d'une fiche * * parm : * - p_cn connexion * - p_type fiche id * gen : * - none * return: * - return la classe id ou rien * */ function GetBaseFiche($p_cn,$p_type) { $base=null; $Res=ExecSql($p_cn,"select fd_class_base from fichedef where fd_id=".$p_type); if ( pg_NumRows($Res) == 0 ) return; $base=pg_fetch_array($Res,0); return $base['fd_class_base']; } /* function ViewFiche * Purpose : Montre les fiches d'une rubrique * * parm : * - p_cn connexion * - $p_type f_id * gen : * - none * return: * - none * */ function ViewFiche($p_cn,$p_type) { echo '

'.getFicheName($p_cn,$p_type).'

'; $Res=ExecSql($p_cn,"select f_id,f_label from fiche where f_fd_id='".$p_type."' order by f_id"); $Max=pg_NumRows($Res); for ( $i = 0; $i < $Max; $i++) { $l_line=pg_fetch_array($Res,$i); $div="
"; $span_mod=' Modifie'; $span_del=''. ' delete'; $span_id=''.$l_line['f_id'].""; if ( $i %2 == 0 ) $div='
'; echo $div.$span_del.' '.' '.' '.' '.' '.' '. $span_mod." "." "." ".$span_id." "." "." ".$l_line['f_label']."
"; } echo '
'; echo ''; echo ''; echo '
'; } /* function GetNextFiche * Purpose : Crée le poste suivant pour une fiche en fonction * de la classe de base (fichedef(fd_class_base)) * * parm : * - p_cn connexion * - p_base * gen : * - * return: * - * */ function GetNextFiche($p_cn,$p_base) { $Res=ExecSql($p_cn,"select max(pcm_val) as maxcode from tmp_pcmn where pcm_val_parent = $p_base"); $Max=pg_NumRows($Res); echo_debug("$Max=pg_NumRows"); $l_line=pg_fetch_array($Res,0); $ret=$l_line['maxcode']; if ( $ret == "" ) { $ret=sprintf("%d%04d",$p_base,0); return $ret+1; } echo_debug("ret $ret"); return $ret+1; } /* function * Purpose : * * parm : * - * gen : * - * return: * - * */ function GetDataFiche($p_cn,$p_fiche_id) { } /* function ViewFicheDetail * Purpose : Montre le detail d'une fiche * et ajoute les lignes manquantes * dans le cas où le modèle à changer * * parm : * - p_cn * - id de la fiche fiche(f_id) * gen : * - * return: * - * */ function ViewFicheDetail($p_cn,$p_id) { $sql="insert into isupp (is_f_id,is_isd_id) select". " '".$p_id."',isd_id from isupp_def ". " where isd_id not in ". "(select is_isd_id from isupp where is_f_id=".$p_id.") ". " and isd_fd_id=(select distinct f_fd_id from fiche ". " where f_id=".$p_id.")"; $Res=ExecSql($p_cn,$sql); EncodeFiche ($p_cn,$p_id,1); } /* function UpdateFiche * Purpose : Met a jour une fiche * change dans le plan comptable, fiche,et isupp * * parm : * - p_cn * - p_array * gen : * - * return: * - * */ function UpdateFiche($p_cn,$p_array) { foreach ( $p_array as $key=> $element) { echo_debug("$key => $element"); ${"$key"}=$element; } $sql=sprintf("update tmp_pcmn set pcm_lib='%s' where pcm_val=%s", $f_label, $f_id); echo_debug($sql); $Res=ExecSql($p_cn,$sql); $sql=sprintf("update fiche set f_label='%s' where f_id=%s", $f_label, $f_id); echo_debug($sql); $Res=ExecSql($p_cn,$sql); for ( $i =0 ; $i < $max ; $i++) { $sql=sprintf("update isupp set is_value='%s' where is_id=%d", ${"nom$i"}, ${"is_id$i"}); echo_debug($sql); $Res=ExecSql($p_cn,$sql); } } /* function EncodeModele * Purpose : * * parm : * - * gen : * - * return: * - * */ function EncodeModele($p_js) { echo '

Ajout d\'un modèle

'; echo '
'; echo '
Libellé '; echo '
Classe de base '; echo $p_js; echo ''; echo '
'; echo '
'; } /* function * Purpose : * * parm : * - * gen : * - * return: * - * */ function DefModele ($p_js,$p_array=null,$p_ligne=1) { echo_debug("DefModele ($p_array,$p_ligne=1) "); for ($i=0; $i < $p_ligne; $i++) { ${"p_LABEL$i"}=""; ${"p_inform$i"}=""; ${"p_isd_id$i"}=""; } if ($p_array != null) { foreach ( $p_array as $key => $element){ ${"p_$key"}=$element; echo_debug ("p_$key $element"); }//foreach }else { $p_nom_mod=""; $p_class_base=""; } echo '
'; echo ''; // echo ''; echo '
Label'; echo '
classe'.$p_js; if ( isset($p_fd_id) ) { echo ''; } for ( $i=0; $i < $p_ligne ; $i++ ) { if ( isset($p_fd_id) ) { echo ''; } printf( '
Libellé ', $i, ${"p_LABEL$i"} ); if ( ${"p_inform$i"} == "on" || ${"p_inform$i"}=='t' ) { $val="checked"; } else { $val=""; } printf('Dans les formulaires ', $i, $val ); } echo '
'; if ( isset($p_fd_id) ){ echo '
'; }else { echo '
'; }//if isset p_fd_id else echo ''; } /* function AddModele * Purpose : Add a modele into the database * * parm : * - connection * - array * gen : * - none * return: * - none * */ function AddModele($p_cn,$p_array) { echo_debug("AddModele"); $p_ligne=$p_array['inc']; for ($i=0; $i < $p_ligne; $i++) { ${"p_inform$i"}=""; } foreach ( $p_array as $key=>$element ) { echo_debug("p_$key $element"); ${"p_$key"}=$element; } $p_nom_mod=FormatString($p_nom_mod); $p_class_base=FormatString($p_class_base); $sql=sprintf("insert into fichedef(fd_label,fd_class_base) values ('%s','%s')", $p_nom_mod,$p_class_base); $Res=ExecSql($p_cn,$sql); $f_id=GetSequence($p_cn,"s_fdef"); for ( $i=0; $i < $p_inc; $i++) { if ( ${"p_inform$i"} == "on" ) { $valform="true"; }else { $valform="false"; } ${"p_LABEL$i"}=FormatString(${"p_LABEL$i"}); if ( ${"p_LABEL$i"} != null ) { $sql=sprintf("insert into isupp_def(isd_label,isd_fd_id,isd_form) values ('%s',%d,%s)", ${"p_LABEL$i"},$f_id,$valform); $Res=ExecSql($p_cn,$sql); } } } /* function UpdateModele * Purpose : * * parm : * - p_cn connexion * - p_fiche fichedef(f_id) * - p_js * gen : * - none * return: * - none * */ function UpdateModele($p_cn,$p_fiche,$p_js) { $array=GetDataModele($p_cn,$p_fiche); if ($array==null) { echo_error ("fiche_inc:UpdateModele Fiche non trouvée"); return; } echo '

'.getFicheName($p_cn,$p_fiche).'

'; foreach ( $array as $key=>$element) echo_debug("$key => $element"); DefModele($p_js,$array,$array['ligne']); } /* function GetDataModele * Purpose : Return the info of an fiche identified by * p_fiche * * parm : * - connection * - fiche id * gen : * - none * return: * - array with all the data * */ function GetDataModele($p_cn,$p_fiche) { $Res=ExecSql($p_cn,"select fd_id,fd_label,fd_class_base, isd_id,isd_label,isd_form from fichedef inner join isupp_def on isd_fd_id=fd_id where fd_id=$p_fiche"); $Max=pg_NumRows($Res); if ($Max==0) return null; for ($i=0; $i < $Max;$i++) { $line=pg_fetch_array($Res,$i); if ($i == 0 ) { $array["nom_mod"]=$line['fd_label']; $array["class_base"]=$line['fd_class_base']; $array["fd_id"]=$line['fd_id']; }//if $i == 0 //inform $text=sprintf("inform%d",$i); $array[$text]=$line['isd_form']; //Label $text=sprintf("LABEL%d",$i); $array[$text]=$line['isd_label']; //isd_id $text=sprintf("isd_id%d",$i); $array[$text]=$line['isd_id']; }//for $array['ligne']=$Max; return $array; } /* function SaveModele * Purpose : Sauve un modele de fiche * * parm : * - connexion * - tableau de valeurs * gen : * - none * return: * - none * */ function SaveModele($p_cn,$p_array) { for ($i=0; $i < $p_array['inc']; $i++) { ${"inform$i"}=""; } foreach ($p_array as $key=>$element){ echo_debug("$key => $element"); ${"$key"}=$element; }//foreach $nom_mod=FormatString($nom_mod); $class_base=FormatString($class_base); if ( $nom_mod != null ) { $sql=sprintf("update fichedef set fd_label='%s', fd_class_base='%s' where fd_id=%d", $nom_mod,$class_base,$fd_id); $Res=ExecSql($p_cn,$sql); } for ($i=1;$i<$inc;$i++){ if ( ${"inform$i"} != null) { $valform='true'; }else { $valform='false'; } //if ( ${"inform$d") != null) if ( ${"isd_id$i"} != null ) { ${"LABEL$i"}=FormatString(${"LABEL$i"}); if ( ${"LABEL$i"} != null ) { $sql=sprintf("update isupp_def set isd_label='%s',isd_form=%s where isd_id=%d", ${"LABEL$i"},$valform,${"isd_id$i"}); } } // if ( ${"p_isd_id$i"} != null ) else { ${"LABEL$i"}=FormatString(${"LABEL$i"}); if ( ${"LABEL$i"} != null ) { $sql=sprintf("insert into isupp_def( isd_label,isd_fd_id,isd_form) values ('%s',%d,%s)", ${"LABEL$i"},$fd_id,$valform); }// if ( ${"LABEL$i"} != null ) }//else if ( ${"p_isd_id$i"} != null ) $Res=ExecSql($p_cn,$sql); }//for } /* function Remove * Purpose : enleve une fiche dans isupp et fiche * a la condition que ce poste n'aie jamais * été utilisé * parm : * - p_cn * - p_fid fiche(f_id) * gen : * - none * return: * - none */ function Remove ($p_cn, $p_fid) { if ( ! isset ($p_cn) || ! isset ($p_fid) ) { echo_error ("Remove Missing Parameter p_cn = $p_cn p_fid=$p_fid"); return; } if ( CountSql($p_cn,"select * from jrnx where j_poste=$p_fid") == 0 ) { $Res=ExecSql($p_cn,"delete from isupp where is_f_id=$p_fid"); $Res=ExecSql($p_cn,"delete from fiche where f_id=$p_fid"); } else { echo ""; } } /* function getFicheName * Purpose : retourne le nom de la fiche * * parm : * - p_cn connexion * - p_id fiche id * gen : * - none * return: * - string avec nom fiche */ function getFicheName($p_cn,$p_id) { $Res=ExecSql($p_cn,"select fd_label from fichedef where fd_id='".$p_id."'"); if ( pg_NumRows($Res) == 0 ) return "Unknown"; $st=pg_fetch_array($Res,0); return $st['fd_label']; } /* function GetFicheJrn * Purpose : Get all the fiche related to a "journal" * * parm : * - p_cn connextion * - j_jrn journal_id * - $p_type : deb or cred * gen : * - none * return: array containing the fiche(f_id),fiche(f_label) */ function GetFicheJrn($p_cn,$p_jrn,$p_type) { $get=""; if ( $p_type == 'deb' ) { $get='jrn_def_fiche_deb'; } if ( $p_type == 'cred' ) { $get='jrn_def_fiche_cred'; } if ( $get == "" ) { echo_error("Invalid p_type function GetFicheJrn($p_cn,$p_jrn,$p_type)"); exit -1; } $Res=ExecSql($p_cn,"select $get as fiche from jrn_def where jrn_def_id=$p_jrn"); $Max=pg_NumRows($Res); if ( $Max==0) { echo_warning("No rows"); return null; } // Normally Max must be == 1 $list=pg_fetch_array($Res,0); if ( $list['fiche']=="") { echo_warning("No fiche"); return null; } $sql="select f_id, f_label from fiche where f_fd_id in (".$list['fiche'].") order by f_label"; $Res=ExecSql($p_cn,$sql); $Max=pg_NumRows($Res); if ($Max==0 ) return null; // Get The result and put it into an array for ($i=0;$i<$Max;$i++) { $line=pg_fetch_array($Res,$i); $f_id=$line['f_id']; $f_label=$line['f_label']; $a[$i]=array($f_id,$f_label); } return $a; } ?>