00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 include_once("impress_inc.php");
00034 function EncodeForm($p_line,$p_sessid,$p_array=null) {
00035
00036 include_once("constant.php");
00037 echo JS_SEARCH_POSTE;
00038 $search='<INPUT TYPE="BUTTON" VALUE="Cherche" OnClick="SearchPoste(\''.$p_sessid."','not')\">";
00039 for ( $i =0 ; $i <= $p_line; $i++) {
00040 ${"text$i"}="";
00041 ${"form$i"}="";
00042 ${"pos$i"}="";
00043 }
00044 if ( $p_array != null ) {
00045 foreach ( $p_array as $key=> $element ) {
00046 ${"$key"}=$element;
00047 echo_debug ("EncodeForm $key = $element");
00048
00049 }
00050
00051 } else {
00052 $form_nom="";
00053 $text0="";
00054 $form0="";
00055 }
00056 echo "<FORM ACTION=\"form.php\" METHOD=\"POST\">";
00057 printf ("Nom du rapport : <INPUT TYPE=\"TEXT\" NAME=\"form_nom\" VALUE=\"%s\">",
00058 $form_nom);
00059 printf ('<INPUT TYPE="HIDDEN" NAME="line" value="%s"',
00060 $p_line);
00061 if ( isset ($fr_id)) printf ('<INPUT TYPE="HIDDEN" NAME="fr_id" value="%s"',
00062 $fr_id);
00063
00064 echo '<TABLE>';
00065 echo "<TR>";
00066 if ( isset($fr_id) ) echo "<TH> Position </TH>";
00067 echo "<TH> Texte </TH>";
00068 echo "<TH> Formule</TH>";
00069
00070 echo '</TR>';
00071 for ( $i =0 ; $i < $p_line;$i++) {
00072 echo "<TR>";
00073
00074
00075
00076 if ( isset($fr_id)) {
00077 echo "<TD>";
00078 printf ('<input TYPE="TEXT" NAME="pos%d" size="3" VALUE="%s">',
00079 $i,${"pos$i"});
00080 echo '</TD>';
00081 }
00082
00083 echo "<TD>";
00084 printf ('<input TYPE="TEXT" NAME="text%d" size="25" VALUE="%s">',
00085 $i,${"text$i"});
00086 echo '</TD>';
00087
00088 echo "<TD>";
00089 printf ('<input TYPE="TEXT" NAME="form%d" SIZE="25" VALUE="%s">',
00090 $i,${"form$i"});
00091 echo $search;
00092 echo '</TD>';
00093
00094 echo "</TR>";
00095 }
00096 echo "</TABLE>";
00097 if ( isset($fr_id)){
00098 echo '<INPUT TYPE="submit" value="Enregistre" name="update">';
00099 }else {
00100 echo '<INPUT TYPE="submit" value="Enregistre" name="record">';
00101 }
00102 echo '<INPUT TYPE="submit" value="Ajoute une ligne" name="add_line">';
00103 echo '<INPUT TYPE="submit" value="Efface ce rapport" name="del_form">';
00104
00105 echo "</FORM>";
00106
00107 }
00117 function ViewForm($p_cn,$p_sessid,$p_id) {
00118 $array=GetDataForm($p_cn,$p_id);
00119 $l_nom=GetFormName($p_cn,$p_id);
00120 $array['form_nom']=$l_nom;
00121
00122 $l_line=GetNumberLine($p_cn,$p_id);
00123 EncodeForm($l_line,$p_sessid,$array);
00124
00125 }
00134 function DeleteForm($p_cn,$p_id) {
00135 ExecSql($p_cn,"delete from form where fo_fr_id=$p_id");
00136 ExecSql($p_cn,"delete from formdef where fr_id=$p_id");
00137 }
00149 function GetDataForm($p_cn,$p_id) {
00150 $Res=ExecSql($p_cn,"select fo_id,fo_fr_id,fo_pos,fo_label,fo_formula from form where fo_fr_id=$p_id
00151 order by fo_pos");
00152 $Max=pg_NumRows($Res);
00153 for ( $i=0;$i<$Max;$i++){
00154 $l_line=pg_fetch_array($Res,$i);
00155
00156
00157 $text=sprintf("fo_id%d",$i);
00158 $array[$text]=$l_line['fo_id'];
00159
00160 $text=sprintf("text%d",$i);
00161 $array[$text]=$l_line['fo_label'];
00162
00163 $text=sprintf("form%d",$i);
00164 $array[$text]=$l_line['fo_formula'];
00165
00166 $text=sprintf("pos%d",$i);
00167 $array[$text]=$l_line['fo_pos'];
00168 }
00169 $array["fr_id"]=$p_id;
00170 return $array;
00171 }
00180 function GetNumberLine($p_cn,$p_id) {
00181 $Res=ExecSql($p_cn,"select * from form where fo_fr_id=".$p_id);
00182 $count=pg_NumRows($Res);
00183 return $count;
00184 }
00195 function GetFormName($p_cn,$p_id) {
00196 $Res=ExecSql($p_cn,"select fr_label from formdef where fr_id=".$p_id);
00197 if ( pg_NumRows($Res) == 0 ) return null;
00198 $name=pg_fetch_array($Res,0);
00199 return $name['fr_label'];
00200 }
00208 function UpdateForm($p_cn,$p_array) {
00209 foreach ($p_array as $key=>$element) {
00210 echo_debug ("UpdateForm $key = $element");
00211 ${"$key"}=$element;
00212 }
00213 $Res=ExecSql($p_cn,"update formdef set fr_label='".FormatString($form_nom)."' where fr_id=".$fr_id);
00214 $Res=ExecSql($p_cn,"delete from form where fo_fr_id=".$fr_id);
00215
00216 for ($i =0; $i <$line;$i++) {
00217 echo_debug ("position =".${"pos$i"});
00218 if ( (string) ${"pos$i"} != (string) (int) ${"pos$i"}) {
00219 ${"pos$i"}=$i+1;
00220 }
00221 if ( ${"pos$i"} > $line || ${"pos$i"} < 0) {
00222 ${"pos$i"}=$i+1;
00223 echo_debug('form_inc.php',__LINE__,"position trop grand max = $line+1 ");
00224 }
00225 }
00226 for ($i =0; $i <$line;$i++) {
00227 for ( $o=$i+1; $o < $line;$o++) {
00228 if ( ${"pos$i"} == ${"pos$o"} ) {
00229 ${"pos$o"}=$o+1;
00230 }
00231 }
00232 }
00233 for ( $i=0;$i<$line;$i++) {
00234 if ( strlen(trim(${"text$i"})) != 0) {
00235 ${"text$i"}=FormatString(${"text$i"});
00236 ${"form$i"}=FormatString(${"form$i"});
00237 if ( ${"text$i"} != null ) {
00238 if ( CheckFormula(${"form$i"}) == false )
00239 ${"form$i"}="!!!!!!! FORMULE INVALIDE ".${"form$i"};
00240
00241 ${"form$i"}=(${"form$i"}==null)?"null":"'".${"form$i"}."'";
00242 $sql=sprintf("insert into form (fo_fr_id,
00243 fo_pos,
00244 fo_label,
00245 fo_formula) values
00246 ( %d,
00247 %d,
00248 '%s',
00249 %s)",
00250 $fr_id,${"pos$i"},
00251 ${"text$i"},
00252 ${"form$i"}
00253 );
00254 $Res=ExecSql($p_cn,$sql);
00255 }
00256 }
00257 }
00258
00259 }
00267 function AddForm($p_cn,$p_array) {
00268 foreach ($p_array as $key=>$element) {
00269 echo_debug ("AddForm $key = $element");
00270 ${"$key"}=$element;
00271 }
00272
00273 if ( !isset ($form_nom) ||
00274 ! isset ($line) ) {
00275 echo_error("Nom ou ligne non défini");
00276 return;
00277 }
00278 $form_nom=(FormatString($form_nom)==null)?"NoName":FormatString($form_nom);
00279 $sql="insert into formdef (fr_label) values ('".$form_nom."')";
00280 $Res=ExecSql($p_cn,$sql);
00281 $n=GetSequence($p_cn,"s_formdef");
00282
00283 for ($i=0;$i < $line;$i++) {
00284 ${"text$i"}=FormatString(${"text$i"});
00285 ${"form$i"}=FormatString(${"form$i"});
00286 if ( ${"text$i"} != null ) {
00287
00288 ${"form$i"}=(${"form$i"}==null)?"null":"'".${"form$i"}."'";
00289 CheckFormula(${"form$i"});
00290 $sql=sprintf("insert into form (fo_fr_id,
00291 fo_pos,
00292 fo_label,
00293 fo_formula) values
00294 ( %d,
00295 %d,
00296 '%s',
00297 %s)",
00298 $n,$i+1,${"text$i"},${"form$i"}
00299 );
00300 $Res=ExecSql($p_cn,$sql);
00301 }
00302 }
00303 }
00304
00305 ?>