// PHPMyLinks version 0.1.4, Copyright (C) 2000, Rémi Henriot
// http://rhenriot.free.fr/phpmylinks/ - rhenriot@mail.com
//
// This is free software ; you can redistribute it and/or modify it
// under the terms of the PHPMyLinks License Version 1.0
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY ; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// For more details, see the license.txt file that you should have
// received with this program.
require 'connexion.inc.php';
function main_sub_sca($cat_id)
{
$query = "select sca_id ".
"from sous_categorie ".
"where cat_id = ".$cat_id." ".
"and sca_nom is null";
$result = mysql_query($query);
if($result && $row=mysql_fetch_object($result))
$sca_id = $row->sca_id;
else
$sca_id = -1;
return $sca_id;
}
function options_categories($cat_id)
{
$result = mysql_query("select cat_id, cat_nom from categorie ".
"order by cat_nom");
$first_cat_id = -1;
while($row=mysql_fetch_object($result))
{
if($first_cat_id == -1) $first_cat_id = $row->cat_id;
echo "\n";
}
return $cat_id == -1 ? $first_cat_id : $cat_id;
}
function options_sub_categories($cat_id, $sca_id)
{
$ret_val = $sca_id;
$req = "select sca_id, sca_nom ".
"from sous_categorie ".
"where cat_id = ".$cat_id." ".
"order by sca_nom";
$result = mysql_query($req);
while($row=mysql_fetch_object($result))
{
if($sca_id == -1 && $row->sca_nom == '') $ret_val = $row->sca_id;
echo "\n";
}
return $ret_val; // (should never be -1, but either $sca_id if $sca_id != -1
// or the id of the main sub-category (i.e. with a null name)
}
function js_update_options_sca()
{
echo
"function update_options_sca(sca, ind_selection) {\n".
" tab = new Array();\n";
$req = "select sca.cat_id, sca.sca_id, sca.sca_nom ".
"from categorie cat, sous_categorie sca ".
"where cat.cat_id = sca.cat_id ".
"order by cat.cat_nom, sca.sca_nom";
$result = mysql_query($req);
$cat_id_courant = -1;
$no_ligne = -1;
while($row=mysql_fetch_object($result))
{
$non_vide = 1;
if($row->cat_id != $cat_id_courant)
{
$cat_id_courant = $row->cat_id;
if($no_ligne != -1)
echo "\"\n";
$no_ligne++;
echo "\ttab[$no_ligne] =\"";
}
echo "$row->sca_id;$row->sca_nom;";
}
if(isset($non_vide)) echo "\";\n";
echo
" tab2 = tab[ind_selection].split(';');\n".
" sca.length = 0;\n".
" for(i=0; i+1 < tab2.length; i = i+2)\n".
" if(i==0)\n".
" sca.options[i/2] = new Option(tab2[i+1], tab2[i], true, true);\n".
" else\n".
" sca.options[i/2] = new Option(tab2[i+1], tab2[i]);\n".
" if(navigator.appName == 'Netscape') history.go(0);\n".
"}\n";
}
?>