#!/usr/bin/perl # Rodilla use HTML::Template; use DBI; use CGI::FormBuilder; # Declarando Variables my ($template_not_install, @campos, $comentario, $tipocampo, $validacion, $nombre_en_db, $db, $dbtype, $dbname, $host, $dbuser, $dbpass, @datos_db, $query); unless(-e "config/formulario.txt"){ $template_not_install = HTML::Template->new(filename => 'templates/not_install.tmpl'); print "Content-type: text/html\n\n"; print $template_not_install->output; } print "Content-type: text/html\n\n"; open(FORM, 'config/formulario.txt') || die "No pude abrir el archivo formulario.txt: $!"; while(
){ chomp; ($comentario, $tipocampo, $validacion, $nombre_en_db) = split(/:/, $_); push @campos, $comentario; } my $formulario = CGI::FormBuilder->new( method => 'post', name => 'Rodilla', title => 'RODILLA!!', fields => \@campos, font => 'Arial', submit => 'Enviar', stylesheet => 'templates/styles/style.css', ); if ($formulario->submitted && $formulario->validate){ open(DB, 'config/datos_db.txt') || die "No pude abrir el archivo formulario.txt: $!"; while(){ chomp; @datos_db = split(/\s/, $_); } $db = DBI->connect("DBI:$datos_db[0]:database=$datos_db[1];host=$datos_db[2]", $datos_db[3], $datos_db[4], {RaiseError => 1}); my @copia = @campos; foreach (@campos) { $_ = "\$$_,"; } foreach (@copia) { $_ = "\$$_ \= \$formulario->field('$_')"; } my @definitivo = @copia; foreach (@definitivo) { eval($_); } my $numero = @campos; $numero = $numero -1; chop($campos[$numero]); $query = $db->prepare("INSERT INTO formulario VALUES(\"\", @campos);"); $query->execute(); print $formulario->confirm(template => 'templates/funciona.tmpl'); } else{ print $formulario->render(header => 1); }