<?php

#####################################################
#  
#  Copyright © 2004, Stefano Balestrini
#  essebe@essebe.ch - http://www.essebe.ch
#  Licence: GPL 
#
#
#  Merci de laisser ce copyright en place...
#####################################################

include("../mainfile.php");
include(XOOPS_ROOT_PATH."/header.php");
include(XOOPS_ROOT_PATH."/class/xoopsformloader.php");

global $xoopsTheme, $xoopsconfig,$HTTP_POST_VARS,$HTTP_GET_VARS;
$xoopsOption['show_rblock'] =0;



opentable($width='100%');
if ($HTTP_POST_VARS){
#####################################################	
//récupération des données
//recovery of the data
#####################################################

$echo  = !empty($HTTP_POST_VARS['champ']) ? $HTTP_POST_VARS['champ'] : $HTTP_GET_VARS['champ'];
$echo = $myts->makeTareaData4Preview($echo);
$echo2  = $myts->makeTboxData4PreviewInForm($echo);

$hiddena  = !empty($HTTP_POST_VARS['hidden']) ? $HTTP_POST_VARS['hidden'] : $HTTP_GET_VARS['hidden'];
$hiddena1 = $myts->makeTareaData4Preview($hiddena);

$yesnoa  = !empty($HTTP_POST_VARS['yesno']) ? $HTTP_POST_VARS['yesno'] : $HTTP_GET_VARS['yesno'];
if ($yesnoa == 1){$yesnoa1 = "J'ai dit oui";	
}elseif ($yesnoa == 0){$yesnoa1 = "J'ai dit non";}

$radioa  = !empty($HTTP_POST_VARS['radio']) ? $HTTP_POST_VARS['radio'] : $HTTP_GET_VARS['radio'];
if ($radioa == 1){$radioa1 = "Option 2";	
}elseif ($radioa == 0){$radioa1 = "Option1";}
elseif ($radioa == 2){$radioa1 = "Option3";}

$cochera  = !empty($HTTP_POST_VARS['cocher']) ?$HTTP_POST_VARS['cocher'] : $HTTP_GET_VARS['cocher'];
if ($cochera !=""){
$tableau  =  array_values($cochera);
}


$selecta  = !empty($HTTP_POST_VARS['select']) ? $HTTP_POST_VARS['select'] : $HTTP_GET_VARS['select'];
if ($selecta == 1){$selecta1 = "Option 2";	
}elseif ($selecta == 0){$selecta1 = "Option1";}
elseif ($selecta == 2){$selecta1 = "Option3";}

$filea  = !empty($HTTP_POST_VARS['file']) ? $HTTP_POST_VARS['file'] : $HTTP_GET_VARS['file'];
$filea1 = $myts->makeTareaData4Preview($filea);

$datea  = !empty($HTTP_POST_VARS['calendar']) ? $HTTP_POST_VARS['calendar'] : $HTTP_GET_VARS['calendar'];
$datea1 = $myts->makeTareaData4Preview($datea);
$datea2  = $myts->makeTboxData4PreviewInForm($datea);

$datetimeA  = !empty($HTTP_POST_VARS['datetime']) ?$HTTP_POST_VARS['datetime'] : $HTTP_GET_VARS['datetime'];

if ($datetimeA !=""){
$tableau2  =  array_values($datetimeA);
}


function calcul_hours($temps)
{
  #####################################################
  //combien d'heures ?
  // how many hours
  #####################################################
  $hours = floor($temps / 3600);

  #####################################################
  //combien de minutes ?
  // how many minutes
  #####################################################
  $min = floor(($temps - ($hours * 3600)) / 60);
  if ($min < 10)
    $min = "0".$min;
    
  #####################################################
  //combien de secondes
  // how many seconds
  #####################################################
  
  $sec = $temps - ($hours * 3600) - ($min * 60);
  if ($sec < 10)
    $sec = "0".$sec;
        
  echo $hours.":".$min;
}


$labela  = !empty($HTTP_POST_VARS['label']) ? $HTTP_POST_VARS['label'] : $HTTP_GET_VARS['label'];
$labela1 = $myts->makeTareaData4Preview($labela);

$groupa  = !empty($HTTP_POST_VARS['groupe']) ? $HTTP_POST_VARS['groupe'] : $HTTP_GET_VARS['groupe'];

if ($groupa == 1){$groupea = "Groupe 1";	
}elseif ($groupa == 2){$groupea = "Groupe 2";}
elseif ($groupa == 5){$groupea = "Groupe 3";}

$selusera  = !empty($HTTP_POST_VARS['utilisateur']) ? $HTTP_POST_VARS['utilisateur'] : $HTTP_GET_VARS['utilisateur'];
$selusera1 = $myts->makeTareaData4Preview($selusera);
if ($selusera1 == 0) $selusera1="0";

$seltheme  = !empty($HTTP_POST_VARS['theme']) ? $HTTP_POST_VARS['theme'] : $HTTP_GET_VARS['theme'];
$seltheme1 = $myts->makeTareaData4Preview($seltheme);


$selmodul  = !empty($HTTP_POST_VARS['module']) ? $HTTP_POST_VARS['module'] : $HTTP_GET_VARS['module'];
$selmodul1 = $myts->makeTareaData4Preview($selmodul);


$zonetexta  = !empty($HTTP_POST_VARS['zonetext']) ? $HTTP_POST_VARS['zonetext'] : $HTTP_GET_VARS['zonetext'];
$zonetexta1 = $myts->makeTareaData4Preview($zonetexta);
$zonetexta2  = $myts->makeTboxData4PreviewInForm($zonetexta);

$textform  = !empty($HTTP_POST_VARS['textenforme']) ? $HTTP_POST_VARS['textenforme'] : $HTTP_GET_VARS['textenforme'];
$textform1 = $myts->makeTareaData4Preview($textform,1,1,1,$myts->allowLibrary = "true",$myts->allowImage = "true");
$textform2  = $myts->makeTboxData4PreviewInForm($textform);

$passw  = !empty($HTTP_POST_VARS['pass']) ? $HTTP_POST_VARS['pass'] : $HTTP_GET_VARS['pass'];
$passw1 = $myts->makeTareaData4Preview($passw);
$passw2  = $myts->makeTboxData4PreviewInForm($passw);

$timezonea  = !empty($HTTP_POST_VARS['timezon']) ? $HTTP_POST_VARS['timezon'] : $HTTP_GET_VARS['timezon'];
$timezonea = $myts->makeTareaData4Preview($timezonea);
$timezonea2  = $myts->makeTboxData4PreviewInForm($timezonea);

#####################################################
//affichage des données
//posting the data for preview
#####################################################

echo "<b><font size ='4'>Preview form</font></b> <br>----------<br><b>CHAMP :</b> $echo
	   <br>----------<br><b>Hidden :</b> $hiddena1
	   <br>----------<br><b>Time zone :</b> $timezonea
	   <br>----------<br><b>Choix Oui/Non :</b> $yesnoa1
	   <br>----------<br><b>Choix radio :</b> $radioa1
	   <br>----------<br><b>Choix cases :</b> ";
	   
	   for ($i=0; $i<count($tableau); $i++){ 
	   if ($tableau[$i] == 0 ){
	   	echo  "Option 1 -";
	   	}else if($tableau[$i] == 1 ){
	   	echo  " Option 2 -";
	   	}else{
	   	echo  " Option 3";}
	}
	   		
	   		

echo 	  "<br>----------<br><b>Choix select :</b> $selecta1
	   <br>----------<br><b>Fichier :</b> $filea1
	   <br>----------<br><b>Date :</b> $datea1
	   <br>----------<br><b>Date et Heure :</b> ";
	   
	   echo $tableau2[0]." - ";
	   calcul_hours($tableau2[1]);
	   
echo	  "<br>----------<br><b>Groupe :</b> $groupa - $groupea
	   <br>----------<br><b>User :</b> $selusera1
	   <br>----------<br><b>Thème :</b> $seltheme1
	   <br>----------<br><b>Module :</b> $selmodul1
	   <br>----------<br> $zonetexta1
	   <br>----------<br> $textform1
	   <br>----------<br> $passw1";
}	

	
#####################################################	
//formulaire
//Form
#####################################################

$action = "form.php";
$title = "Formulaire de test";
$name = "nom";
$my_form = new XoopsThemeForm($title,$name,$action,$method="POST");

#####################################################
//definition and configuration of the fields from your form
#####################################################

#####################################################
//hidden field
// XoopsFormHidden($name,$value="");
$hidden = new XoopsFormHidden("hidden","Valeur du champ caché");

#####################################################
//Label
//The Label field does not turn over any value
// XoopsFormLabel($caption,$value="");
$label = new XoopsFormLabel("Label","<hr>");

#####################################################
//Text field
//XoopsFormText($caption,$name,$size,$maxlenght,$value="");
$champ = new XoopsFormText("Champ","champ",50,49,"$echo2");

#####################################################
//Text zone
//XoopsFormTextArea($caption,$name,$value="",$rows,$cols);
$zonetext = new XoopsFormTextArea("Zône texte","zonetext","$zonetexta2",5,50);

#####################################################
//Text zone with working (icons,url,mail,quote, etc..)
//XoopsFormDhtmlTextArea($caption,$name,$value="",$rows,$cols,$hiddentext="");
$textenforme = new XoopsFormDhtmlTextArea("Zône texte mis en forme","textenforme","$textform2",5,50,$hiddentext="xoopsHiddenText");

#####################################################
//Password
//XoopsFormPassword($caption,$name,$size,$maxlenght,$value="");
$pass = new XoopsFormPassword("Mot de passe","pass",10,6,"$passw2");

#####################################################
//Timezone
//XoopsFormSelectTimezone($caption,$name,$value ="(-12 to +12)",$size=a number of posted lines);
$timezon  = new XoopsFormSelectTimezone("Timezone","timezon",$value ="0",$size=1);

#####################################################
//choix oui ou non
//yes - no field
//XoopsFormRadioYN($caption,$name,$value= "1 for yes 0 for no",$yes,$no);

$yesno  = new XoopsFormRadioYN("Oui,Non","yesno",$value=null,"J'ai dit oui","j'ai dit non");

#####################################################
//boutons radio
//radio button
//XoopsFormRadio($caption,$name,$value="preselected value");

$radio  =  new XoopsFormRadio("Radio","radio","$radioa");
$options = array("Option1","Option2","Option3");
$radio->addOptionArray($options);
//We can add the options one to one
//$radio->addOption("value","name");

#####################################################
//Case à cocher
//check box
//XoopsFormCheckBox($caption,$name,$value ="preselected value");
$cocher  =  new XoopsFormCheckBox("Cases","cocher",null);
$options = array("Option1","Option2","Option3");
$cocher->addOptionArray($options);

#####################################################
//Select
//turn over a table if selection multiple
//XoopsFormSelect($caption,$name,$value ="preselected value",$size=a number of posted lines,$multiple=False/true);
$select  = new XoopsFormSelect("Sélection","select",$value = null,1,$multiple=False);
$options = array("Option1","Option2","Option3");
$select->addOptionArray($options);

#####################################################
//File field
//XoopsFormFile($caption,$name, $maxfilesize);
$file = new XoopsFormFile("Fichier","file", 305678);

#####################################################
//Date sous la forme yyyy-mm-dd
//Date field with javascript calender  return yyyy-mm-dd
//XoopsFormTextDateSelect($caption,$name,$size,$value = null);
$date  =  new XoopsFormTextDateSelect("Date","calendar",15,$value = null);

#####################################################
//Date et Heure sous la forme d'un tableau
//Date and Time turn over a table
//XoopsFormDateTime($caption,$name,$size,$value = time());

$dateHeure  =  new XoopsFormDateTime("Date et Heure","datetime",15,$value = time());

#####################################################
//Select User Group
//XoopsFormSelectGroup($caption,$name,$include_anon = false, $value="", $size=a number of posted lines,$multiple=false/true);
//turn over a table if selection multiple
$group  = new XoopsFormSelectGroup("Groupe","groupe",$include_anon = false, $value=$groupa, $size=1,$multiple=false);

#####################################################
//Select User 
// XoopsFormSelectUser($caption,$name,$value="", $size=a number of posted lines,$multiple=false/true);
//turn over a table if selection multiple
$seluser  = new XoopsFormSelectUser("Utilisateur","utilisateur",$include_anon=true, $value=null, $size=1, $multiple=false);

#####################################################
//Select Language
//XoopsFormSelectLang($caption,$name,$value="", $size=a number of posted lines);
//
$lang = new XoopsFormSelectLang("Langue","lang",null,1);

#####################################################
//Select a country
//XoopsFormSelectCountry($caption,$name,$value="code of country", $size=a number of posted lines);
//turn over chains containing the code of the country (FR,GB,ZW,...)
$country = new XoopsFormSelectCountry("Pays","pays","FR",1);

#####################################################
//Select a Match Option for search
//XoopsFormSelectMatchOption($caption,$name,$value=" ", $size=a number of posted lines);
//turn over Xoops_Match Options defined in common.php (1=END,2=EQUAL,3=CONTAIN,0=START)
$match = new XoopsFormSelectMatchOption("Recherche","match","0",1);

#####################################################
//Select a theme
//XoopsFormSelectTheme($caption,$name,$value=" ", $size=a number of posted lines);
//turn over a chain with the name of the theme
$theme = new XoopsFormSelectTheme("Thème","theme","",1);

#####################################################
//Select a module
//XoopsFormSelectModule($caption, $name, $include_system=false, $value=0, $size=1, $multiple=false);
//turn over a id of module
$module = new XoopsFormSelectModule("Module","module",$include_system=false,0,1,false);

#####################################################
//boutton envoyer ou reset
//Button
//XoopsFormButton($caption,$name,$value="",$type (button,submit,reset);
$envoi = new XoopsFormButton("Envoi","send","envoyer",submit);

#####################################################
// XoopsFormElementTray


$element_tray = new XoopsFormElementTray("Name of Element", "<br />");
$element_tray->addElement($champ);
$element_tray->addElement($pass);

#####################################################
//posting of the form

$my_form->addElement($element_tray);


$my_form->addElement($hidden, true);
$my_form->addElement($label, true);
$my_form->addElement($timezon, true);
$my_form->addElement($yesno, true);
$my_form->addElement($radio, true);
$my_form->addElement($cocher, true);
$my_form->addElement($select, true);
$my_form->addElement($file, true);
$my_form->addElement($date, true);
$my_form->addElement($dateHeure, true);
$my_form->addElement($group, true);
$my_form->addElement($seluser, true);
$my_form->addElement($lang, true);
$my_form->addElement($country, true);
$my_form->addElement($match, true);
$my_form->addElement($theme, true);
$my_form->addElement($module, true);
$my_form->addElement($zonetext);
$my_form->addElement($textenforme, true);

$my_form->addElement($envoi, true);
$required = array("champ","zonetext","textenforme");

$my_form->setRequired($required);
$my_form->display();


closetable();

include(XOOPS_ROOT_PATH."/footer.php");
?>