xhtml = ''; $this->pageId = 'Page#'.$pageId; $this->flush = false; $this->currentPage = ''; $this->bodyJs = ''; } /** * Affichage global * */ function show() { $this->xhtml .= "\n"; return $this->xhtml; } /** * Javascript du BODY * */ function getBodyJs() { $js = "var myValidator = new fValidator(\"".$this->formId."\");\n".$this->bodyJs; return $js; } /** * Entete de formulaire * */ function visitFormosite(Formosite $comp, $level) { $this->action = $comp->action; $this->formId = $comp->id; return true; } /** * Enregistrement du HTML si la page est concernée * */ function visitPage(Page $comp, $level) { if ($this->flush == true) { if ($comp->id != $this->currentPage) { $this->xhtml .= ""; $this->flush = false; } } elseif ($comp->id == $this->pageId) { //$this->xhtml .= "
Le fomulaire de la page ".$this->pageId."
\n"; $this->xhtml .= "
\n"; $this->xhtml .= "
\n"; $this->xhtml .= "
\n"; $this->flush = true; } $this->currentPage = $comp->id; } /** * Ajout d'un champ * */ function visitField(Field $comp, $level) { if ($this->flush == true) { $this->xhtml .= $this->toXHTML(&$comp); } } /** * génération du html en fonction du type de champ * */ function toXHTML($field) { $xhtml = ''; $divType = ($field->required == 'true') ? "uRow" : "opt-uRow"; $xhtmlLabel = ($field->required == 'true') ? "".$field->label." *" : $field->label; if (sizeof($field->fieldErrors) == 0){$info = ($field->info != '') ? $field->info : " ";} else{$info = $field->fieldErrors[0];} switch($field->type) { case 'Text': $value = ($valueControl == "post") ? "name."']) ? \$_POST['".$field->name."'] : '".$field->value."'; ?>" : $field->value; $js = " ".$this->jsEvents($field->validIf, $field->name, $field->required); $maxlength = ($this->maxLength($field->validIf) !== false) ? " maxlength='".$this->maxLength($field->validIf)."'" : ""; $disabled = ($field->disabled) ? " disabled='disabled' " : ''; $xhtml = "
"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "
\n"; break; case 'Select': $values = explode("|",$field->okValues); $selected = (in_array(trim(strtolower($field->value)), $values)) ? $field->value : ""; $xhtml = "
\n".$this->fieldSelection( $field->name, $field->name, $field->class, $values, $field->value, $field->required)."\n"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "
\n"; break; case 'Checkbox': $checked = ($field->status == 'on') ? true : false; $field->value = ($field->value == '') ? "true" : $field->value; $xhtml = "
\n".$this->fieldCheckbox( $field->name, $field->name, $field->class, $checked ,$field->value )."\n\n"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "
\n"; break; case 'Radio': $values = explode("|",$field->okValues); $selected = (in_array(trim(strtolower($field->value)), $values)) ? $field->value : ""; $xhtml = "
".$xhtmlLabel."\n\n"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= $this->fieldRadio( $field->name, $field->name, $field->class, $values, $field->value )."
\n"; break; case 'Textarea': $value = ($valueControl == "post") ? "name."']) ? \$_POST['".$field->name."'] : '".$field->value."'; ?>" : $field->value; $xhtml = "

\n"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "
\n";; break; case 'Hidden': $xhtml = "
\n"; break; case 'File': $xhtml = "
"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "
\n"; break; case 'Password': $maxlength = ($this->maxLength($field->validIf) !== false) ? " maxlength='".$this->maxLength($field->validIf)."'" : ""; $disabled = ($field->disabled) ? " disabled='disabled' " : ''; $xhtml = "
"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "
\n"; break; case 'Submit': $xhtml = "

\n"; break; case 'Fieldset': $xhtml = "
".$field->label."\n"; break; case 'Fieldset_end': $xhtml = "
\n"; break; case 'Comment': $xhtml = "

".$field->label; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "

\n"; break; case 'Linked_1-n': $this->bodyJs .= $this->jsSuggest($field->name); $xhtml = "
"; $xhtml .= ($field->infobulle != '') ? " ? ".$field->infobulle."" : ''; $xhtml .= "
\n"; break; default : $xhtml = ''; break; } return $xhtml; } // Type de champs function fieldTypesSelection($field, $selectedValue) { $s = "" ; return $s ; } // Formatte un champ Select function fieldSelection($id, $name, $class, $values, $selected, $required) { $s = "" ; return $s ; } // Formatte une Checkbox function fieldCheckbox($id, $name, $class, $checked, $value) { $ischecked = ($checked == true) ? "checked='checked'" : ""; $s = ""; return $s ; } // Formatte des boutons radio function fieldRadio( $id, $name, $class, $values, $selected ) { $s = "" ; return $s ; } // Retourne les évènements JS associés function jsEvents($validIf, $fieldName, $req) { if ($req) { $this->bodyJs .= "myValidator.register($(\"$fieldName\"), requiredValidate);\n"; } $tests = explode("|",$validIf); foreach ( $tests as $test ) { switch($test) { case 'email': $this->bodyJs .= "myValidator.register($(\"$fieldName\"), emailValidate);\n"; break; case 'url': $this->bodyJs .= "myValidator.register($(\"$fieldName\"), urlValidate);\n"; break; case 'int': $this->bodyJs .= "myValidator.register($(\"$fieldName\"), integerValidate);\n"; break; case 'date': $this->bodyJs .= "myValidator.register($(\"$fieldName\"), dateValidate);\n"; break; case 'date-a2': $this->bodyJs .= "myValidator.register($(\"$fieldName\"), datea2Validate);\n"; break; } } if (trim($events) != '') $events = "onchange=\"".$events."\" "; return $events; } // Retourne le JS "Autosuggest" pour un champ lié function jsSuggest($fieldName) { $js = " var options = { script: \"[::ROOT_URL::]/saisie/form/searchLinkedField?fieldName=".$fieldName."&\", varname: \"strSuggest\", json: true, noresults: \"pas de résultats\", timeout: 2500, callback: function (obj) { document.getElementById('".$fieldName."').value = obj.id; document.getElementById('".$fieldName."_id').value = '#' + obj.id; } }; var as = new bsn.AutoSuggest('".$fieldName."_search', options); $('".$fieldName."_search').addEvent('change', resetLinkedFields); function resetLinkedFields() { if ($('".$fieldName."_search').value == '') { $('".$fieldName."_id').value = ''; $('".$fieldName."').value = ''; } } "; return $js; } // Retourne la longueur max du champ si existante function maxLength($validIf) { $max = false; $tests = explode("|", $validIf); foreach ( $tests as $test ) { if (substr($test,0,3) == 'max' && is_numeric(substr($test, 3)) && substr($test, 3) >= 0 && substr($test, 3) <= 9999){$max = substr($test, 3);} } return $max; } // Retourne la longueur min du champ si existante function minLength($validIf) { $min = false; $tests = explode("|",$validIf); foreach ( $tests as $test ) { if (substr($test,0,3) == 'min' && is_numeric(substr($test, 3)) && substr($test, 3) >= 0 && substr($test, 3) <= 9999){$min = substr($test, 3);} } return $min; } //Pas d'action sur ces composites function visitBlock(Block $comp, $level) { return true; } } ?>