#!/usr/bin/perl -w # # index.cgi # # aout 2000 - mad # deverminage et ménage # ajout 'Nouveautes' # juillet 2000 - thomas # création # use CGI; use CGI::Carp qw(fatalsToBrowser); use DBI; use Data::Dumper; use lib ("$ENV{'DOCUMENT_ROOT'}/support/lib/perl"); use HTMLT::Interpreter; require 'klib.pl'; require 'dka_drivers.pl'; use strict ; local $| = 1 ; my $debug = 0 ; my $interp = HTMLT::Interpreter->new('.'); my $ns={}; $ns->{'TEMPLATE'} = 'driversliste.htmlt'; $ns->{'DEBUGLEVEL'} = 0 ; require 'kextlangage.pl' ; setExtendedLangage( $ns ) ; my $q = new CGI ; print STDERR Dumper( $q )."\n" if($debug); # 2001-10-25 mad@ktaland.com # détection des cookies déactivés chez le client. my $from_login_page = $q->param( 'LOGIN' ); my $checking_cookie = $q->param( 'CHECKCOOKIE' ); #$cookie_name = 'DKA_LOGINKTA' ; my $cookie_name = GetConfig('login_cookiename'); my $cookie = $q->cookie( $cookie_name ); print STDERR "cookie $cookie_name\n" if($debug); print STDERR "cookie value : [ ",($cookie?$cookie:'null')," ]\n" if($debug); if( $from_login_page ){ # on redirige sur ce script avec le parametre CHECKCOOKIE pour détection cookie my $location = $ENV{'SCRIPT_NAME'} . '?CHECKCOOKIE=1'; print $q->header( '-location'=>$location ); exit(); } my $dbh = ConnectDB(); my $login_groupes_libelle = ''; my ($login_groupes_id, $user_id ) = split( ';', $cookie) if($cookie); # pas encore logger, par défaut on log en 'public' if( ! $cookie ){ if( $checking_cookie ){ $ns->{'MESSAGE'} = 'Vous devez activer les cookies pour pouvoir être identifié.'; } # Mon Nov 05 13:55:16 CET 2001 mad@ktaland.com # il n'y a plus de groupe 'public' #require "$ENV{'DOCUMENT_ROOT'}/drivers/perl/login.pl"; #my $grplistes = CheckLogin( 'public', 'public' ) ; #if( $grplistes ){ # $cookie = $q->cookie( -name => $cookie_name , # -value => $grplistes ); # #$q->header( -'cookie' => $cookie ); #} }else{ $login_groupes_libelle = join( ',', @{getGroupesLibelle( $dbh, $login_groupes_id )} ); } my( $fonction, $marque ); $fonction = $q->param('fonction') || '0'; $marque = $q->param('marque') || '0'; popup( 'MRQ', 'DKA_MARQUES', $marque ); popup( 'FCT', 'DKA_FUNCTIONS', $fonction ); # # Listes les produits correspondants à la sélection du visiteur # print STDERR "marque=$marque, fonction=$fonction\n"; if( $marque or $fonction ){ $ns->{'RECHERCHE'}= '1' ; recherche_produit( $fonction, $marque ); }else{ $ns->{'RECHERCHE'}= '' ; $ns->{'DKA_PRODUITS'}= '' ; #$ns->{'MESSAGE'} = 'il faut sélectionner un produit ET une marque' ; } # 23/08/0 10:06 mad - TODO : # !!! Pourquoi 2 fois la meme chose ???? # popup( 'MRQ', 'DKA_MARQUES', $marque ); popup( 'FCT', 'DKA_FUNCTIONS', $fonction ); nouveautes( $dbh, $ns ); $ns->{'LOGIN_GROUPES'} = $login_groupes_libelle ; print $q->header(); print $interp->make_page( $ns ); if( $debug>0 ){ print '
' ;
	print dump_namespace( $ns );
	print '
' ; } $dbh->disconnect() if($dbh); exit; ######################## # sub recherche_produit { my( $fonction, $marque )=@_; my( $sql, $sth ); if( !$fonction and !$marque ){ $ns->{'DKA_PRODUITS'}=''; return 0 ; } if( $fonction and $marque ){ $sql = "select T3.MRQ_LIBELLE, T2.FCT_LIBELLE, T1.PRD_LIBELLE, T1.PRD_ID from DKA_PRODUITS T1, DKA_FUNCTIONS T2, DKA_MARQUES T3 where T1.FCT_ID = '$fonction' and T1.MRQ_ID = '$marque' and T2.FCT_ID = '$fonction' and T3.MRQ_ID = '$marque' "; }elsif( $fonction ){ $sql = "select T2.FCT_LIBELLE, T1.PRD_LIBELLE, T1.PRD_ID from DKA_PRODUITS T1, DKA_FUNCTIONS T2 where T1.FCT_ID = '$fonction' and T2.FCT_ID = T1.FCT_ID "; }elsif( $marque ){ $sql = "select T3.MRQ_LIBELLE, T1.PRD_LIBELLE, T1.PRD_ID from DKA_PRODUITS T1, DKA_MARQUES T3 where T1.MRQ_ID = '$marque' and T3.MRQ_ID = T1.MRQ_ID "; } #$sql = "select * from DKA_PRODUITS"; $sth = dbExec( $dbh, $sql ); if( !$sth or $sth->rows==0 ){ $ns->{'DKA_PRODUITS'}=''; return 0 ; } my( $href, $cpt, $item ); $cpt=0; while( $href = $sth->fetchrow_hashref ){ foreach $item (keys %$href){ $ns->{'DKA_PRODUITS'}->{$cpt}->{$item}=$href->{$item}; $ns->{'DKA_PRODUITS'}->{$cpt}->{'IDFCT'}=$fonction; $ns->{'DKA_PRODUITS'}->{$cpt}->{'IDMRQ'}=$marque; } $cpt++; } return $cpt ; }#recherche_produit ####################### sub popup{ my( $prefix, $table, $selected )=@_; my( $sql, $sth, $href, $cpt, $item ); #recuperation des fonctions #$sth=$dbh->prepare( "select distinct ${prefix}_LIBELLE, ${prefix}_ID, if(${prefix}_ID='$selected','selected',' ' ) as SELECTED from $table"); $sql ="select distinct ${prefix}_LIBELLE, ${prefix}_ID, if(${prefix}_ID='$selected','SELECTED',' ' ) as SELECTED from $table"; $sth = dbExec( $dbh, $sql ); return undef if( !$sth ); $cpt=0; while( $href = $sth->fetchrow_hashref){ foreach $item (keys %$href){ # remplissage du NS $ns->{$prefix.'POP'}->{$cpt}->{$item}=$href->{$item}; } if( $href->{'SELECTED'} eq 'SELECTED' ){ $ns->{"${prefix}_LIBELLE"} = $href->{ "${prefix}_LIBELLE" }; } $cpt++; } return $cpt ; }#popup ########################## sub nouveautes { my( $dbh, $ns )=@_; my( $sql, $sth ); $sql="select NVT_DATEMODIF, NVT_TEXTE from DKA_NOUVEAUTES where NVT_PUBLISH=1 order by NVT_DATEMODIF desc"; $sth = dbExec( $dbh, $sql ); return undef if( !$sth ); if( $sth->rows <= 0){ $ns->{'DKA_NOUVEAUTES'}=''; }else{ my( $href, $cpt, $item, $s ); $cpt = 0 ; while( $href = $sth->fetchrow_hashref ){ foreach $item ( keys %$href ){ # format checkbox if( $item eq 'NVT_PUBLISH' && $href->{$item}==1 ){ $href->{$item} = 'checked'; } # format europe date if( $item eq 'NVT_DATEMODIF' ){ $s = $href->{$item} ; $href->{$item} = MysqlTimestampToEuropDate( \$s ); } $ns->{'DKA_NOUVEAUTES'}->{$cpt}->{$item} = $href->{$item}; } $cpt++; } } return 1 ; }#nouveautes ######################## sub getGroupesLibelle { my( $dbh, $grp_liste )=@_; return if( ! ${grp_liste} ); my $sql = "select GRP_LIBELLE from LOG_GROUPES where GRP_ID in(${grp_liste})"; my $sth = dbExec( $dbh, $sql ); return '' if(!$sth); my @grp_libs ; while( my $aref = $sth->fetchrow_arrayref() ){ push @grp_libs, $aref->[0]; } return \@grp_libs ; }#getGroupesLibelle