00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00038 function AddFiche($p_cn,$p_type,$p_array) {
00039
00040 echo_debug('fiche_inc.php',__LINE__," AddFiche($p_cn,$p_type,$p_array) ");
00041
00042
00043 foreach ($p_array as $key=>$element){
00044 ${"p_$key"}=$element;
00045 echo_debug('fiche_inc.php',__LINE__,"p_$key=$element;");
00046 }
00047
00048
00049 if ( strlen(trim($p_av_text0 )) ==0 )
00050 return;
00051
00052
00053 $field=Get_attr_def($p_cn,$p_fd_id);
00054
00055 $flag=1;
00056
00057
00058 $Sql="insert into fiche (fd_id) values (".$p_fd_id.")";
00059 $Res=ExecSql($p_cn,$Sql);
00060
00061
00062 $l_f_id=GetSequence($p_cn,'s_fiche');
00063
00064
00065 $create=GetCreateAccount($p_cn,$p_fd_id);
00066
00067
00068
00069 for ( $i = 0; $i < $p_inc;$i++) {
00070
00071 if ( ${"p_ad_id$i"} == ATTR_DEF_ACCOUNT ) {
00072 if (strlen (trim(${"p_av_text$i"})) == 0 or
00073 isNumber(${"p_av_text$i"}) == 0 )
00074 {
00075 break;
00076 }
00077
00078 if (CountSql($p_cn,"select pcm_val from tmp_pcmn where pcm_val=".${"p_av_text$i"}) == 0 )
00079 {
00080 $len=strlen(${"p_av_text$i"})-1;
00081
00082 $p_parent=substr(${"p_av_text$i"},0,$len);
00083 while (CountSql($p_cn,"select pcm_val from tmp_pcmn where pcm_val=$p_parent") == 0 and
00084 $len > 0 ) {
00085 $len--;
00086 $p_parent=substr(${"p_av_text$i"},0,$len);
00087 }
00088
00089 if ( $len <= 0 ) {
00090 echo_error ("No parent found");
00091 exit("No parent found for ".${"p_av_text$i"});
00092
00093 }
00094 $lib=FormatString($p_av_text0);
00095 $sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
00096 values (%s,'%s',%d)",
00097 ${"p_av_text$i"},
00098 $lib,
00099 $p_parent);
00100
00101
00102 $Res=ExecSql($p_cn,$Sql);
00103 }
00104
00105
00106 $Sql=sprintf("insert into jnt_fic_att_value (f_id,ad_id) values (%d,%d)",
00107 $l_f_id,ATTR_DEF_ACCOUNT);
00108 $Res=ExecSql($p_cn,$Sql);
00109
00110
00111 $l_jft_id=GetSequence($p_cn,'s_jnt_fic_att_value');
00112
00113
00114
00115 $Sql=sprintf("insert into attr_value(jft_id,av_text) values (%d,'%s')",
00116 $l_jft_id,${"p_av_text$i"});
00117 $Res=ExecSql($p_cn,$Sql);
00118
00119 $create=0;
00120 }
00121
00122 }
00123
00124 echo_debug ( " create = $create ");
00125 if ( $create == 1 ) {
00126
00127
00128 $base=GetBaseFiche($p_cn,$p_type);
00129
00130
00131
00132 if ( $base !=null ) {
00133
00134 $num=GetNextFiche($p_cn,$base);
00135
00136 $lib=FormatString($p_av_text0);
00137 $sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
00138 values (%s,'%s',%d)",
00139 $num,
00140 $lib,
00141 $base);
00142 echo_debug($sql);
00143 $Res=ExecSql($p_cn,$sql);
00144
00145
00146 $Sql=sprintf("insert into jnt_fic_att_value (f_id,ad_id) values (%d,%d)",
00147 $l_f_id,ATTR_DEF_ACCOUNT);
00148 $Res=ExecSql($p_cn,$Sql);
00149
00150
00151 $l_jft_id=GetSequence($p_cn,'s_jnt_fic_att_value');
00152
00153
00154
00155 $Sql=sprintf("insert into attr_value(jft_id,av_text) values (%d,'%s')",
00156 $l_jft_id,$num);
00157 $Res=ExecSql($p_cn,$Sql);
00158 }
00159 }
00160
00161
00162
00163 for ( $i = 0; $i < $p_inc;$i++) {
00164
00165 if ( ${"p_ad_id$i"} == ATTR_DEF_ACCOUNT ) continue;
00166
00167
00168 if ( ${"p_ad_id$i"} == ATTR_DEF_QUICKCODE ) {
00169 $sql=sprintf("select insert_quick_code(%d,'%s')",
00170 $l_f_id,FormatString(${"p_av_text$i"}));
00171 $Res=ExecSql($p_cn,$sql);
00172 continue;
00173 }
00174
00175 $Sql=sprintf("insert into jnt_fic_att_value (f_id,ad_id) values (%d,%d)",
00176 $l_f_id,${"p_ad_id$i"});
00177 $Res=ExecSql($p_cn,$Sql);
00178
00179
00180 $l_jft_id=GetSequence($p_cn,'s_jnt_fic_att_value');
00181
00182
00183 if ( ${"p_ad_id$i"} == ATTR_DEF_TVA ) {
00184
00185 if ( strlen(trim(${"p_av_text$i"})) != 0 and
00186 isNumber(${"p_av_text$i"}) == 1) {
00187
00188 if ( CountSql($p_cn,"select * from tva_rate where tva_id='".${"p_av_text$i"}."'") == 0 ) {
00189
00190 ${"p_av_text$i"}=1;
00191
00192 echo_error('invalid rate') ;
00193 echo '<script>
00194 alert("Attention tva invalid, valeur par défaut =1 ");
00195 </script>';
00196
00197 }
00198 }
00199 }
00200 $text=FormatString(${"p_av_text$i"});
00201
00202 $Sql=sprintf("insert into attr_value(jft_id,av_text) values (%d,'%s')",
00203 $l_jft_id,$text);
00204 $Res=ExecSql($p_cn,$Sql);
00205
00206 }
00207
00208 }
00225 function EncodeFiche($p_cn,$p_type,$p_array=null) {
00226 echo_debug('fiche_inc.php',__LINE__,"function EncodeFiche($p_cn,$p_type) ");
00227
00228 $ch_col="</TD><TD>";
00229 $ch_li='</TR><TR>';
00230 $url="";
00231
00232
00233
00234 if ($p_array == null) {
00235 $url="?action=vue&fiche=$p_type";
00236 } else {
00237
00238 $a=GetArray($p_cn,'select fd_id from fiche where f_id='.$p_type);
00239 if ( $a == null ) {
00240 echo_error(__FILE__.":".__LINE__." Aucune fiche trouvée");
00241 return;
00242 }
00243 $url="?action=vue&fiche=".$a[0]['fd_id'];
00244 }
00245
00246
00247 echo '<FORM action="fiche.php'.$url.'" method="post" name="fiche">';
00248 echo '<INPUT TYPE="HIDDEN" name="fiche" value="'.$p_type.'">';
00249 $l_sessid=$_REQUEST['PHPSESSID'];
00250 $url="";
00251 echo JS_SHOW_TVA;
00252 echo JS_SEARCH_POSTE;
00253 echo "<TABLE>";
00254 if ($p_array == null) {
00255
00256
00257
00258 echo '<H2 class="info">New </H2>';
00259 $p_f_id="";
00260 echo_debug('fiche_inc.php',__LINE__,"Array is null");
00261
00262
00263 $sql="select frd_id,ad_id,ad_text from fiche_def join jnt_fic_attr using (fd_id)
00264 join attr_def using (ad_id) where fd_id=".$p_type." order by ad_id";
00265
00266 $Res=ExecSql($p_cn,$sql);
00267 $Max=pg_NumRows($Res);
00268
00269 echo '<INPUT TYPE="HIDDEN" name="fd_id" value="'.$p_type.'">';
00270 for ($i=0;$i < $Max;$i++) {
00271 $l_line=pg_fetch_array($Res,$i);
00272
00273
00274 $Hid=sprintf('<INPUT TYPE="HIDDEN" name="ad_id%d" value="%s">',
00275 $i,$l_line['ad_id']);
00276
00277 $but_search_poste="";
00278
00279 if ( $l_line ['ad_id'] == ATTR_DEF_ACCOUNT ) {
00280 $ctl_name="av_text$i";
00281 $but_search_poste='<INPUT TYPE="BUTTON" VALUE="Cherche" OnClick="SearchPoste(\''.$l_sessid.'\',\''.$ctl_name.'\')">';
00282 }
00283
00284 if ( $l_line ['ad_id'] == ATTR_DEF_TVA ) {
00285 $but_search_poste='<INPUT TYPE="BUTTON" VALUE="Montre" OnClick="ShowTva(\''.$l_sessid.'\', \'av_text'.$i.'\')">';
00286 }
00287
00288 printf ('<TR><TD> %s </TD><TD><INPUT TYPE="TEXT" NAME="av_text%d">%s %s</TD></TR>',
00289 $l_line['ad_text'], $i,$Hid,$but_search_poste);
00290 }
00291 echo '</TR>';
00292 echo '</TABLE>';
00293 echo '<INPUT TYPE="HIDDEN" name="inc" value="'.$Max.'">';
00294 echo '<INPUT TYPE="SUBMIT" name="add_fiche" value="ajoute">';
00295 echo '</FORM>';
00296 }else {
00297
00298
00299
00300
00301 $label=getFicheNameById($p_cn,$p_type);
00302 echo '<H2 class="info">'.$label.'</H2>';
00303
00304
00305 $sql="select av_text,ad_id,ad_text,jft_id from attr_value
00306 natural join attr_def
00307 natural join jnt_fic_att_value
00308 natural join fiche where f_id=$p_type order by ad_id";
00309
00310 $Res=ExecSql($p_cn,$sql);
00311 $Max=pg_NumRows($Res);
00312 echo_debug('fiche_inc.php',__LINE__,"Max ==== $Max");
00313
00314 echo '<INPUT TYPE="HIDDEN" name="f_id" value="'.$p_type.'">';
00315 echo '<INPUT TYPE="HIDDEN" name="f_label" value="'.$label.'">';
00316 echo '<INPUT TYPE="HIDDEN" name="max" value="'.$Max.'">';
00317
00318 for ($i=0;$i < $Max;$i++) {
00319
00320 $l_line=pg_fetch_array($Res,$i);
00321
00322
00323
00324
00325 $but_search_poste="";
00326 if ( $l_line['ad_id'] == ATTR_DEF_ACCOUNT ) {
00327 printf('<INPUT TYPE="HIDDEN" name="class" value="%s">',
00328 $l_line['av_text']);
00329
00330 $ctl_name="av_text$i";
00331 $but_search_poste='<INPUT TYPE="BUTTON" VALUE="Cherche" OnClick="SearchPoste(\''.$l_sessid.'\',\''.$ctl_name.'\')">';
00332 }
00333
00334
00335 if ( $l_line ['ad_id'] == ATTR_DEF_TVA ) {
00336 $but_search_poste='<INPUT TYPE="BUTTON" VALUE="Montre" OnClick="ShowTva(\''.$l_sessid.'\',\'av_text'.$i.'\')">';
00337 }
00338
00339
00340 $ad=sprintf('<input type="hidden" name="ad_id%d" value="%s">',
00341 $l_line['ad_id'],$l_line['av_text']);
00342
00343
00344 $Hid=sprintf('<INPUT TYPE="HIDDEN" name="jft_id%d" value="%s">',
00345 $i,$l_line['jft_id']);
00346 printf ('<TR><TD> %s </TD><TD><INPUT TYPE="TEXT" NAME="av_text%d" VALUE="%s">%s %s %s</TD></TR>',
00347 $l_line['ad_text'], $i, $l_line['av_text'],$Hid,$but_search_poste,$ad);
00348
00349 }
00350 echo '</TR>';
00351 echo '</TABLE>';
00352 echo '<INPUT TYPE="SUBMIT" name="update_fiche" value="Mis à jour">';
00353 echo '</FORM>';
00354 }
00355 }
00356
00370 function GetBaseFiche($p_cn,$p_type) {
00371 $base=null;
00372 $Res=ExecSql($p_cn,"select fd_class_base from fiche_def where fd_id=".$p_type);
00373 if ( pg_NumRows($Res) == 0 ) return null;
00374 $base=pg_fetch_array($Res,0);
00375 return $base['fd_class_base'];
00376 }
00377
00392 function GetBaseFicheDefault($p_cn,$p_type) {
00393 $base=null;
00394 $Res=ExecSql($p_cn,"select frd_class_base from fiche_def_ref where frd_id=".$p_type);
00395 if ( pg_NumRows($Res) == 0 ) return null;
00396 $base=pg_fetch_array($Res,0);
00397 return $base['frd_class_base'];
00398 }
00412 function ViewFiche($p_cn,$p_type) {
00413 require_once("user_common.php");
00414 echo '<H2 class="info">'.getFicheDefName($p_cn,$p_type).'</H2>';
00415
00416 $step=$_SESSION['g_pagesize'];
00417 $sql_limit="";
00418 $sql_offset="";
00419 if ( $step != -1 ) {
00420 $page=(isset($_GET['page']))?$_GET['page']:1;
00421 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00422 $max_line=CountSql($p_cn,"select f_id,av_text from
00423 fiche join jnt_fic_att_value using (f_id)
00424 join attr_value using (jft_id)
00425 where fd_id='".$p_type."' and ad_id=".ATTR_DEF_NAME." order by f_id");
00426 $sql_limit=" limit ".$step;
00427 $sql_offset=" offset ".$offset;
00428 $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00429 }
00430
00431
00432
00433 $Res=ExecSql($p_cn,"select f_id,av_text,j_qcode from
00434 fiche join jnt_fic_att_value using (f_id)
00435 join attr_value using (jft_id)
00436 left outer join vw_poste_qcode using(f_id)
00437 where fd_id='".$p_type.
00438 "' and ad_id=".ATTR_DEF_NAME." order by f_id $sql_offset $sql_limit ");
00439 $Max=pg_NumRows($Res);
00440 echo $bar;
00441
00442 echo '<table>';
00443 for ( $i = 0; $i < $Max; $i++) {
00444 $l_line=pg_fetch_array($Res,$i);
00445 if ( $i%2 == 0)
00446 echo '<TR class="odd">';
00447 else
00448 echo '<TR class="even">';
00449
00450 $span_mod='<TD><A href="fiche.php?action=detail&fiche_id='.$l_line['f_id'].'">'.$l_line['j_qcode'].'</A></TD>';
00451 $span_del='<TD>'.
00452 '<A href="fiche.php?f_fd_id='.$p_type.'&action=delete&fiche_id='.$l_line['f_id'].
00453 '"> delete</A></td>';
00454
00455 echo $span_del.$span_mod.'<TD>'.$l_line['av_text']."</TD>";
00456 echo '</tr>';
00457 }
00458 echo '</table>';
00459 echo '<FORM METHOD="POST" action="fiche.php">';
00460 echo '<INPUT TYPE="HIDDEN" name="fiche" value="'.$p_type.'">';
00461 echo '<INPUT TYPE="SUBMIT" name="add" Value="Ajout fiche">';
00462 echo '</FORM>';
00463 echo $bar;
00464
00465 }
00480 function GetNextFiche($p_cn,$p_base) {
00481 $Res=ExecSql($p_cn,"select max(pcm_val) as maxcode from tmp_pcmn where pcm_val_parent = $p_base");
00482 $Max=pg_NumRows($Res);
00483 echo_debug('fiche_inc.php',__LINE__,"$Max=pg_NumRows");
00484 $l_line=pg_fetch_array($Res,0);
00485 $ret=$l_line['maxcode'];
00486 if ( $ret == "" ) {
00487 $ret=sprintf("%d%04d",$p_base,0);
00488 return $ret+1;
00489
00490 }
00491
00492 echo_debug('fiche_inc.php',__LINE__,"ret $ret");
00493 return $ret+1;
00494 }
00510 function ViewFicheDetail($p_cn,$p_id) {
00511
00512
00513 $fd_id=GetFicheDef($p_cn,$p_id);
00514
00515
00516 $sql="insert into jnt_fic_att_value (f_id,ad_id)
00517 select $p_id, ad_id
00518 from jnt_fic_attr
00519 where fd_id=$fd_id and
00520 ad_id not in (select ad_id from jnt_fic_att_value where
00521 f_id=$p_id)";
00522
00523 $Res=ExecSql($p_cn,$sql);
00524
00525
00526 $sql="insert into attr_value select jft_id,'' from jnt_fic_att_value
00527 where f_id=$p_id and jft_id not in (select jft_id from attr_value natural join jnt_fic_att_value where
00528 f_id = $p_id)";
00529 $Res=ExecSql($p_cn,$sql);
00530
00531 EncodeFiche ($p_cn,$p_id,1);
00532 }
00548 function UpdateFiche($p_cn,$p_array) {
00549
00550 echo_debug ('fiche_inc.php',__LINE__,"UpdateFiche");
00551 $tva_error=false;
00552 foreach ( $p_array as $key=> $element) {
00553 echo_debug('fiche_inc.php',__LINE__,"UF $key => $element");
00554 ${"$key"}=$element;
00555
00556 if ( $key == "ad_id".ATTR_DEF_NAME ) {
00557 $label=$element;
00558 if (strlen(trim($label))== 0 )
00559 return;
00560 }
00561
00562 if ( $key=="ad_id".ATTR_DEF_ACCOUNT) {
00563 $class=$element;
00564 }
00565
00566
00567 if ( $key == 'ad_id'.ATTR_DEF_TVA ) {
00568
00569 if ( strlen(trim($element)) == 0 ) continue;
00570 if ( CountSql($p_cn,"select * from tva_rate where tva_id='".$element."'") == 0 ) {
00571
00572 echo_error('invalid rate') ;
00573 echo '<script>
00574 alert("Attention tva invalid remis à sa valeur par défaut ");
00575 </script>';
00576 $tva_error=true;
00577 }
00578 }
00579 }
00580
00581
00582 $fd_ref=GetFicheDefRef($p_cn,$fiche);
00583
00584 for ( $i =0 ; $i < $max ; $i++) {
00585
00586 $text=FormatString( ${"av_text$i"});
00587
00588 $Res=ExecSql($p_cn,"select ad_id from jnt_fic_att_value where jft_id=".${"jft_id$i"});
00589 $a=pg_fetch_array($Res,0);
00590 if ( $a['ad_id'] != ATTR_DEF_QUICKCODE)
00591 {
00592 $sql=sprintf("update attr_value set av_text='%s' where jft_id=%d",
00593 $text,
00594 ${"jft_id$i"});
00595 }
00596 else
00597 {
00598 $sql=sprintf("select update_quick_code(%d,'%s')",
00599 ${"jft_id$i"},
00600 $text);
00601 }
00602
00603 $Res=ExecSql($p_cn,$sql);
00604 }
00605
00606 if ( $tva_error == true ) {
00607 $sql="update attr_value set av_text=1 where jft_id = ( select jft_id from jnt_fic_att_value
00608 natural join fiche natural join attr_def
00609 where ad_id=".ATTR_DEF_TVA." and f_id=$fiche)";
00610 $Res=ExecSql($p_cn,$sql);
00611 }
00612
00613
00614 $sql="select av_text from attr_value natural join jnt_fic_att_value
00615 where f_id=$fiche and ad_id=".ATTR_DEF_ACCOUNT;
00616 $Res=ExecSql($p_cn,$sql);
00617
00618 if ( pg_NumRows($Res) != 0 ) {
00619
00620
00621 $f=pg_fetch_array($Res,0);
00622 $class_old=$f['av_text'];
00623
00624
00625 if ( $class != $class_old and $class != "" ) {
00626 if ( CountSql($p_cn,"select * from jrnx where j_poste=$class") or
00627 CountSql($p_cn,"select * from jrnx where j_poste=$class_old" ))
00628 {
00629
00630 echo_error("Not possible to change the account, already used");
00631 } else {
00632 if ( CountSql($p_cn,"select * from tmp_pcmn where pcm_val=".$class) ==0)
00633
00634 {
00635
00636 $parent=GetParent($p_cn,$class);
00637 $Res=ExecSql($p_cn,
00638 "insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
00639 values ($class,'$f_label',$parent)");
00640 }
00641 }
00642 $class=$class_old;
00643 } else
00644 {
00645
00646 echo_debug('fiche_inc.php',__LINE__,"new account ");
00647 $class=$class_old;
00648 if ( CountSql($p_cn,"select * from tmp_pcmn where pcm_val=".$class) == 0 ) {
00649
00650 $parent=GetParent($p_cn,$class);
00651 $Res=ExecSql($p_cn,
00652 "insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
00653 values ($class,'$f_label',$parent)");
00654 }
00655 }
00656
00657
00658
00659
00660 $f_label=FormatString($f_label);
00661 ExecSql($p_cn,"update tmp_pcmn set pcm_lib='".$f_label."' where pcm_val=".$class);
00662
00663
00664 }
00665
00666
00667
00668
00669 }
00682 function EncodeModele($p_js)
00683 {
00684 echo '<H2 CLASS="info"> Ajout d\'un modèle</H2>';
00685 echo '<FORM ACTION="fiche.php" METHOD="post">';
00686 echo '<BR>Libellé <INPUT TYPE="TEXT" NAME="nom_mod">';
00687 echo '<BR>Classe de base <INPUT TYPE="TEXT" NAME="class_base">';
00688 echo $p_js;
00689 echo '<INPUT TYPE="HIDDEN" NAME="inc" VALUE="1">';
00690 echo '<BR><INPUT TYPE="SUBMIT" name="record_model" VALUE="Ajoute modèle">';
00691 echo '</FORM>';
00692 }
00707 function DefModele ($p_cn,$p_js,$p_array=null,$p_ligne=1)
00708 {
00709 echo_debug('fiche_inc.php',__LINE__,"DefModele ($p_array,$p_ligne=1) ");
00710
00711
00712 $display='<FORM ACTION="fiche.php" METHOD="POST">';
00713
00714
00715 $display.='<INPUT TYPE="HIDDEN" NAME="INC" VALUE="'.$p_ligne.'">';
00716
00717
00718 $display.='<TABLE BORDER="0" CELLSPACING="0">';
00719
00720
00721
00722 $display.='<TR><TD> Catégorie de fiche </TD>';
00723 $display.='<TD><INPUT TYPE="INPUT" NAME="nom_mod">';
00724 $display.='</TD></TR>';
00725
00726
00727 $display.='<TR><TD> Classe de base </TD>';
00728 $display.='<TD><INPUT TYPE="INPUT" NAME="class_base"> '.$p_js;
00729 $display.='</TD></TR>';
00730
00731 $display.='<TR><TD> <INPUT TYPE="CHECKBOX" NAME="create" CHECKED>Création automatique du poste comptable</TD></TR>';
00732
00733
00734 $ref=Get_fiche_def_ref($p_cn);
00735
00736
00737
00738
00739
00740 $check="CHECKED";
00741 if ( sizeof($ref) ) {
00742 foreach ($ref as $i=>$v) {
00743 $display.='<TR><TD COLSPAN="2">';
00744
00745 $display.='<INPUT TYPE="RADIO" NAME="FICHE_REF" VALUE="'.$v['id'].'"'.$check.'>';
00746 $display.=$v['text'];
00747
00748 if ( sizeof ($v['class']) != 0 )
00749 $display.="  <I>Class base = ".$v['class']."</I>";
00750 $display.="</TD></TR>";
00751 $check="";
00752 }
00753
00754 }
00755
00756 $display.='</TABLE>';
00757 $display.='<INPUT TYPE="SUBMIT" NAME="add_modele" VALUE="Sauve">';
00758 $display.='</FORM>';
00759
00760
00761 echo $display;
00762
00763 }
00779 function AddModele($p_cn,$p_array) {
00780 echo_debug('fiche_inc.php',__LINE__,"AddModele");
00781
00782
00783 foreach ( $p_array as $key=>$element ) {
00784 echo_debug('fiche_inc.php',__LINE__,"p_$key $element");
00785 ${"p_$key"}=$element;
00786 }
00787
00788 $p_nom_mod=FormatString($p_nom_mod);
00789 echo_debug('fiche_inc.php',__LINE__,"Adding $p_nom_mod");
00790
00791
00792 if ( isNumber($p_class_base) == 0 && FormatString($p_class_base) != null ) {
00793 echo_error ('p_class_base is NOT a number');
00794 }
00795 if ( strlen(trim($p_nom_mod)) == 0 )
00796 return;
00797
00798
00799 if (! isset ($p_FICHE_REF) or strlen($p_FICHE_REF) == 0 ) {
00800 echo_error ("AddModele : fiche_ref MUST NOT be null or empty");
00801 return;
00802 }
00803
00804
00805
00806
00807 if ( FormatString($p_class_base) == null )
00808 {
00809
00810 $p_class_base=GetBaseFicheDefault($p_cn,$p_FICHE_REF);
00811 }
00812
00813 if ( isset($p_create))
00814 $p_create='true';
00815 else
00816 $p_create='false';
00817
00818
00819 if ( FormatString($p_class_base) != null) {
00820
00821
00822 $sql=sprintf("insert into fiche_def(fd_label,fd_class_base,frd_id,fd_create_account)
00823 values ('%s',%s,%d,'%s')",
00824 $p_nom_mod,$p_class_base,$p_FICHE_REF,$p_create);
00825 $Res=ExecSql($p_cn,$sql);
00826
00827
00828 $sql=sprintf("select account_add(%d,'%s')",
00829 $p_class_base,$p_nom_mod);
00830
00831 $Res=ExecSql($p_cn,$sql);
00832
00833
00834 $fd_id=GetSequence($p_cn,'s_fdef');
00835
00836
00837
00838 if ( $p_create=='true' ) {
00839 $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id)
00840 values (%d,%d)",$fd_id,ATTR_DEF_ACCOUNT);
00841 $Res=ExecSql($p_cn,$sql);
00842 }
00843 } else {
00844
00845 $sql=sprintf("insert into fiche_def(fd_label,frd_id,fd_create_account) values ('%s',%d,'%s')",
00846 $p_nom_mod,$p_FICHE_REF,$p_create);
00847
00848 $Res=ExecSql($p_cn,$sql);
00849
00850
00851 $fd_id=GetSequence($p_cn,'s_fdef');
00852
00853 }
00854
00855
00856 $def_attr=Get_attr_min($p_cn,$p_FICHE_REF);
00857
00858
00859
00860 if (sizeof($def_attr) != 0 ) {
00861
00862 foreach ( $def_attr as $i=>$v) {
00863 $sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id)
00864 values (%d,%s)",
00865 $fd_id,$v['ad_id']);
00866 ExecSql($p_cn,$sql);
00867 }
00868 }
00869
00870
00871 }
00887 function UpdateModele($p_cn,$p_fiche) {
00888
00889 $array=GetDataModele($p_cn,$p_fiche);
00890 if ($array==null) {
00891 echo_error ("fiche_inc:UpdateModele Fiche non trouvée");
00892 return;
00893 }
00894 echo '<H2 class="info">'.getFicheDefName($p_cn,$p_fiche).'</H2>';
00895 foreach ( $array as $key=>$element) echo_debug('fiche_inc.php',__LINE__,"$key => $element");
00896 DisplayDetailModele($p_cn,$array,$array['ligne']);
00897
00898 }
00913 function GetDataModele($p_cn,$p_fiche) {
00914 $Res=ExecSql($p_cn,"select fd_class_base,ad_id,ad_text from
00915 fiche_def
00916 natural join jnt_fic_attr
00917 natural join attr_def
00918 where
00919 fd_id=$p_fiche");
00920 $Max=pg_NumRows($Res) ;
00921 if ($Max==0) return null;
00922
00923
00924 for ($i=0; $i < $Max;$i++) {
00925 $line=pg_fetch_array($Res,$i);
00926 if ($i == 0 ) {
00927 $array['label']=GetFicheDefName($p_cn,$p_fiche);
00928 $array['class_base']=$line['fd_class_base'];
00929 $array['fd_id']=$p_fiche;
00930 }
00931
00932
00933 $text=sprintf("ad_id%d",$i);
00934 $array[$text]=$line['ad_id'];
00935
00936 $text=sprintf("ad_text%d",$i);
00937 $array[$text]=$line['ad_text'];
00938
00939 }
00940 $array['ligne']=$Max;
00941 return $array;
00942 }
00956 function Remove ($p_cn, $p_fid) {
00957 if ( ! isset ($p_cn) ||
00958 ! isset ($p_fid) ) {
00959 echo_error ("Remove Missing Parameter p_cn = $p_cn p_fid=$p_fid");
00960 return;
00961 }
00962
00963
00964 $fd_id=GetFicheDef($p_cn,$p_fid);
00965 if ( GetCreateAccount($p_cn,$fd_id) == 1 ) {
00966
00967 $class=GetClass($p_cn,$p_fid);
00968
00969
00970 if (FormatString($class) != null &&
00971 CountSql($p_cn,"select * from jrnx where j_poste=$class") != 0 ) {
00972 echo "<SCRIPT> alert('Impossible ce poste est utilisé dans un journal'); </SCRIPT>";
00973 return;
00974 } else {
00975
00976 if ( trim(strlen($class)) != 0 and isNumber($class) == 1)
00977 ExecSql($p_cn,"delete from tmp_pcmn where pcm_val=".$class);
00978 }
00979
00980 }
00981
00982 $Res=ExecSql($p_cn,"delete from attr_value
00983 where jft_id in (select jft_id
00984 from jnt_fic_att_value
00985 natural join fiche where f_id=$p_fid)");
00986
00987 $Res=ExecSql($p_cn,"delete from jnt_fic_att_value where f_id=$p_fid");
00988
00989
00990 $Res=ExecSql($p_cn,"delete from fiche where f_id=$p_fid");
00991
00992 }
01006 function getFicheName($p_cn,$p_id) {
01007
01008
01009
01010 $Res=ExecSql($p_cn,"select vw_name from
01011 vw_fiche_attr where quick_code='$p_id'");
01012 if ( pg_NumRows($Res) == 0 ) return "Unknown";
01013 $st=pg_fetch_array($Res,0);
01014 return $st['vw_name'];
01015 }
01028 function getFicheNameById($p_cn,$p_id) {
01029
01030
01031 $Res=ExecSql($p_cn,"select av_text from
01032 attr_value
01033 natural join jnt_fic_att_value
01034 natural join fiche
01035 where
01036 f_id=$p_id and
01037 ad_id=".ATTR_DEF_NAME);
01038
01039 if ( pg_NumRows($Res) == 0 ) return "Unknown";
01040 $st=pg_fetch_array($Res,0);
01041 return $st['av_text'];
01042 }
01043
01056 function getFicheDefName($p_cn,$p_id) {
01057 $Res=ExecSql($p_cn,"select fd_label from fiche_def where fd_id=$p_id");
01058 if ( pg_NumRows($Res) == 0 ) return "Unknown";
01059 $st=pg_fetch_array($Res,0);
01060 return $st['fd_label'];
01061 }
01062
01075 function GetFicheJrn($p_cn,$p_jrn,$p_type)
01076 {
01077 $get="";
01078 if ( $p_type == 'deb' ) {
01079 $get='jrn_def_fiche_deb';
01080 }
01081 if ( $p_type == 'cred' ) {
01082 $get='jrn_def_fiche_cred';
01083 }
01084 if ( $get == "" ) {
01085 echo_error("Invalid p_type function GetFicheJrn($p_cn,$p_jrn,$p_type)");
01086 exit -1;
01087 }
01088 $Res=ExecSql($p_cn,"select $get as fiche from jrn_def where jrn_def_id=$p_jrn");
01089 $Max=pg_NumRows($Res);
01090 if ( $Max==0) {
01091 echo_warning("No rows");
01092 return null;
01093 }
01094
01095 $list=pg_fetch_array($Res,0);
01096 if ( $list['fiche']=="") {
01097 echo_warning("No fiche");
01098 return null;
01099 }
01100
01101 $sql="select f_id,av_text as f_label
01102 from fiche natural join jnt_fic_att_value
01103 natural join attr_def
01104 natural join attr_value
01105 natural join fiche_def
01106 where ad_id=1 and
01107 fd_id in (".$list['fiche'].") order by f_label";
01108
01109 $Res=ExecSql($p_cn,$sql);
01110 $Max=pg_NumRows($Res);
01111 if ($Max==0 ) return null;
01112
01113 for ($i=0;$i<$Max;$i++) {
01114 $line=pg_fetch_array($Res,$i);
01115 $f_id=$line['f_id'];
01116 $f_label=$line['f_label'];
01117 $a[$i]=array($f_id,$f_label);
01118 }
01119 return $a;
01120 }
01133 function Get_fiche_def_ref($p_cn)
01134 {
01135
01136 $Res=ExecSql($p_cn, "select frd_id,frd_text,frd_class_base
01137 from fiche_def_ref
01138 order by frd_text");
01139
01140
01141 $Max=pg_NumRows($Res);
01142 if ( $Max == 0) return null;
01143
01144
01145 for ($i=0;$i<$Max;$i++) {
01146 $f=pg_fetch_array($Res,$i);
01147 $array[$i]['id']=$f['frd_id'];
01148 $array[$i]['text']=$f['frd_text'];
01149 $array[$i]['class']=$f['frd_class_base'];
01150 }
01151
01152
01153 return $array;
01154 }
01167 function Get_attr_min($p_cn,$p_fiche_def_ref) {
01168
01169 $Sql="select ad_id,ad_text from attr_min natural join attr_def
01170 natural join fiche_def_ref
01171 where
01172 frd_id= $p_fiche_def_ref";
01173 $Res=ExecSql($p_cn,$Sql);
01174 $Num=pg_NumRows($Res);
01175
01176
01177 if ($Num == 0 ) return null;
01178
01179
01180 for ($i=0;$i<$Num;$i++) {
01181 $f=pg_fetch_array($Res,$i);
01182 $array[$i]['ad_id']=$f['ad_id'];
01183 $array[$i]['ad_text']=$f['ad_text'];
01184 }
01185 return $array;
01186 }
01199 function Get_attr_def($p_cn,$p_fiche_def) {
01200
01201 $Sql="select ad_id,ad_text from attr_def
01202 natural join jnt_fic_attr
01203 natural join fiche_def
01204 where
01205 fd_id= $p_fiche_def order by ad_id";
01206 $Res=ExecSql($p_cn,$Sql);
01207 $Num=pg_NumRows($Res);
01208
01209
01210 if ($Num == 0 ) return null;
01211
01212
01213 for ($i=0;$i<$Num;$i++) {
01214 $f=pg_fetch_array($Res,$i);
01215 $array[$i]['ad_id']=$f['ad_id'];
01216 $array[$i]['ad_text']=$f['ad_text'];
01217 }
01218 return $array;
01219 }
01232 function GetCreateAccount($p_cn,$p_fiche_def) {
01233
01234 $Sql="select fd_create_account
01235 from fiche_def
01236 where
01237 fd_id= $p_fiche_def";
01238 $Res=ExecSql($p_cn,$Sql);
01239 $Num=pg_NumRows($Res);
01240
01241
01242 if ($Num == 0 ) return 0;
01243
01244
01245 for ($i=0;$i<$Num;$i++) {
01246 $f=pg_fetch_array($Res,$i);
01247 echo_debug ("fd_create_account == ".$f['fd_create_account']);
01248 if ( $f['fd_create_account']=='t') {
01249 echo_debug('fiche_inc.php',__LINE__,"fd_create_account return 1");
01250 return 1;
01251 }
01252 }
01253 echo_debug('fiche_inc.php',__LINE__,"fd_create_account return 0");
01254 return 0;
01255 }
01269 function GetFicheDefRef($p_cn,$p_f_id)
01270 {
01271
01272 $sql="select frd_id from fiche_def join fiche using (fd_id)
01273 where f_id=$p_f_id";
01274
01275 $Res=ExecSql($p_cn,$sql);
01276
01277
01278 if ( pg_NumRows($Res) == 0 ) return null;
01279
01280
01281 $f=pg_fetch_array($Res,0);
01282
01283
01284 return $f['frd_id'];
01285
01286 }
01300 function GetFicheDef($p_cn,$p_f_id)
01301 {
01302
01303 $sql="select fd_id from fiche_def join fiche using (fd_id)
01304 where f_id=$p_f_id";
01305
01306 $Res=ExecSql($p_cn,$sql);
01307
01308
01309 if ( pg_NumRows($Res) == 0 ) return null;
01310
01311
01312 $f=pg_fetch_array($Res,0);
01313
01314
01315 return $f['fd_id'];
01316
01317 }
01318
01331 function GetClass($p_cn,$p_fid) {
01332 echo_debug('fiche_inc.php',__LINE__,"GetClass($p_fid)");
01333
01334
01335
01336 $sql="select av_text from attr_value
01337 natural join jnt_fic_att_value
01338 natural join attr_def
01339 where
01340 ad_id=".ATTR_DEF_ACCOUNT." and f_id=$p_fid";
01341
01342 $Res=ExecSql($p_cn,$sql);
01343 if (pg_NumRows($Res) == 0 ) return null;
01344
01345
01346 $f=pg_fetch_array($Res,0);
01347 return $f['av_text'];
01348 }
01361 function InsertModeleLine($p_cn,$p_fid,$p_adid)
01362 {
01363
01364
01365 $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id) values (%d,%d)",
01366 $p_fid,$p_adid);
01367 $Res=ExecSql($p_cn,$sql);
01368
01369 }
01382 function SaveModeleName($p_cn,$p_fid,$p_label)
01383 {
01384
01385
01386 $sql=sprintf("update fiche_def set fd_label='%s' where
01387 fd_id=%d",
01388 $p_label,$p_fid);
01389 $Res=ExecSql($p_cn,$sql);
01390
01391 }
01392
01408 function DisplayDetailModele($p_cn,$p_array,$MaxLine)
01409 {
01410 echo_debug('fiche_inc.php',__LINE__,"DisplayDetailModele");
01411
01412 foreach ($p_array as $v=>$i) {
01413 echo_debug('fiche_inc.php',__LINE__,"v == $v i==$i");
01414 ${"$v"}=$i;
01415 }
01416 echo '<FORM action="fiche.php" method="get">';
01417 echo '<INPUT TYPE="HIDDEN" NAME="fd_id" VALUE="'.$fd_id.'">';
01418
01419 printf("<TABLE>");
01420
01421 for ($i=0;$i<$MaxLine;$i++) {
01422 echo '<TR><td>';
01423
01424 if ( ${"ad_id$i"} == ATTR_DEF_NAME ) {
01425 printf('Label</TD><TD><INPUT TYPE="TEXT" NAME="label" VALUE="%s">',
01426 $label);
01427 printf('</td><TD><input type="submit" NAME="change_name" value="Change Nom">');
01428 } else {
01429
01430 printf('%s ',
01431 ${"ad_text$i"});
01432 }
01433 echo '</td></tr>';
01434 }
01435
01436
01437
01438 $Res=ExecSql($p_cn,"select ad_id,ad_text from attr_def
01439 where ad_id not in (select ad_id from fiche_def natural join jnt_fic_attr
01440 where fd_id=$fd_id)");
01441 $M=pg_NumRows($Res);
01442
01443
01444 echo '<TR> <TD>';
01445 echo '<SELECT NAME="ad_id">';
01446 for ($i=0;$i<$M;$i++) {
01447 $l=pg_fetch_array($Res,$i);
01448 printf('<OPTION VALUE="%s"> %s',
01449 $l['ad_id'],$l['ad_text']);
01450 }
01451 echo '</SELECT>';
01452 echo '</TD><TD> <INPUT TYPE="SUBMIT" Value="Add that line" NAME="add_ligne"></TD></TR>';
01453 printf("</TABLE>");
01454 echo '</FORM>';
01455 }
01468 function GetParent($p_cn,$p_val)
01469 {
01470 $len=strlen($p_val)-1;
01471 for ($i=$len-1;$i>0;$i--) {
01472 $a=substr($p_val,0,$i);
01473 echo_debug ("parent == $a len =1");
01474 if (CountSql($p_cn,"select pcm_val from tmp_pcmn where pcm_val=$a") == 1)
01475 return $a;
01476 }
01477 }
01492 function getFicheAttribut($p_cn,$p_id,$p_attr="") {
01493
01494
01495
01496 if ( $p_attr != "") {
01497 $Res=ExecSql($p_cn,"select av_text from
01498 attr_value
01499 natural join jnt_fic_att_value
01500 natural join fiche
01501 where
01502 ad_id=$p_attr
01503 and f_id=(select f_id from vw_poste_qcode where j_qcode='$p_id') ");
01504 if ( pg_NumRows($Res) == 0 ) return NULL;
01505 $st=pg_fetch_array($Res,0);
01506 return $st['av_text'];
01507 } else {
01508
01509 $Res=ExecSql($p_cn,"select * from vw_fiche_attr where quick_code='$p_id'");
01510 if ( pg_NumRows($Res) == 0 ) return null;
01511 $st=pg_fetch_array($Res,0);
01512 return $st;
01513 }
01514 }
01515
01532 function IsFicheOfJrn($p_cn,$p_jrn,$p_fiche,$p_type="")
01533 {
01534 $get="";
01535 if ( $p_type == 'deb' ) {
01536 $get='jrn_def_fiche_deb';
01537 }
01538 if ( $p_type == 'cred' ) {
01539 $get='jrn_def_fiche_cred';
01540 }
01541 if ( $get != "" ) {
01542 $Res=ExecSql($p_cn,"select $get as fiche from jrn_def where jrn_def_id=$p_jrn");
01543 } else {
01544
01545 $Res=ExecSql($p_cn," select jrn_def_fiche_cred as fiche
01546 from jrn_def where jrn_def_id=$p_jrn
01547 union
01548 select jrn_def_fiche_deb
01549 from jrn_def where jrn_def_id=$p_jrn"
01550 );
01551 }
01552 $Max=pg_NumRows($Res);
01553 if ( $Max==0) {
01554 echo_warning("No rows");
01555 return null;
01556 }
01557
01558 $list=pg_fetch_array($Res,0);
01559 if ( $list['fiche']=="") {
01560 echo_warning("No fiche");
01561 return null;
01562 }
01563
01564 $sql="select *
01565 from vw_fiche_attr
01566 where
01567 fd_id in (".$list['fiche'].") and quick_code='$p_fiche'";
01568
01569 $Res=ExecSql($p_cn,$sql);
01570 $Max=pg_NumRows($Res);
01571 if ($Max==0 )
01572 return 0;
01573 else
01574 return 1;
01575 }
01576 ?>