<?php
// $Id: dynselectinstances.php,v 1.2 2008-07-09 12:03:13 fgiva Exp $
header('Content-type: text/html; charset=iso-8859-1');  
include ("../dyn/session.inc");
require_once "DB.php";
include_once ("../dyn/connexion.php");
$db=& DB :: connect($dsn, $db_option);
if (DB :: isError($db)) 
    die($db->getMessage());
$theme=$_POST["theme"];
switch ($theme) {
case "direction":
case "service":
case "batiment":
case "fournisseur":
  $sql  = "select id$theme,lib$theme from $theme order by lib$theme";   
  break;
default: //enlever modele de modele...
  $theme=substr($theme,6);
  $sql  = "select idmodele,libmodele from modeleelement where nature = '$theme'";
  if (strstr($theme,"logiciel")) $sql.=" and integre = 'v'";   
  $sql.=" order by libmodele";
}
$res = $db->query($sql);
if (DB :: isError($res))
    die($res->getMessage().$sql);
echo 'var o = null;';   
echo 'var s = document.forms["'.$_POST["form"].'"].elements["'.$_POST["select"].'"];';   
echo 's.options.length = 0;';   
//echo 's.options[s.options.length] = new Option("Choisir un type","");';
while ($row=& $res->fetchRow()){
  $row[1]=str_replace("\"","\\\"",$row[1]); //pour " dans lib ecran
  echo 's.options[s.options.length] = new Option("'.$row[1].'","'.$row[0].'");';   
}
$res->free();
$db->disconnect();
?>