#!/usr/bin/perl

use DBI;
use CGI;

$param=new CGI;
$tabulka11 = $param ->param('table11');
$radka11 = $param ->param('radka11');
$id11 = $param ->param('id11');

#print "Content-type:text/html\n\n";
&init;
$dbh = DBI->connect("$INIT","$LOGIN","$PASS");
$sth=$dbh->prepare("select * from $tabulka11 LIMIT 1");
$sth->execute;
@sloupce = @{$sth->{NAME}};
while(@rr=$sth->fetchrow_array){};

$sqld="";
foreach $r(@sloupce)
{
 $e=$param->param($r);
  $e=~s/'/\\'/g;
  $e=~s/"/\\"/g;
 $sqld.=qq($r='$e',);
}
chop $sqld;

$vysl =$radka11/1;
if(!$vysl)
{
 $sth=$dbh->do("update $tabulka11 set  $sqld where $id11 like '$radka11';");
}else
{
 $sth=$dbh->do("update $tabulka11 set $sqld where $id11=$radka11;");
}

#$sth->execute;
#while(@rr=$sth->fetchrow_array){}
$dbh->disconnect;
#print " - $sqld , $id11=$radka11";

print "Location:view.cgi?table=$tabulka11\n\n";



# -------------------------------------------------
sub init
{
 open(F,"dat.conf");
 @o =<F>;
 close(F);
 %COLS=();
 foreach $radek (@o)
 {
  next if $radek=~/^#/; next unless $radek=~/\S/;
  if ($radek=~/^init/i)   {($INIT)=($radek=~/^init\s*=\s*(\S*)/i);};
  if ($radek=~/^login/i)   {($LOGIN)=($radek=~/^login\s*=\s*(\S*)/i);};
  if ($radek=~/^pass/i)   {($PASS)=($radek=~/^pass\s*=\s*(\S*)/i);};
  #if ($radek=~/^tables/i) {($tmp)=($radek=~/^tables\s*=\s*(.*)/i);$tmp=~s/\s*//g;@TABL=split(",",$tmp);};
  #if ($radek=~/^cols/i) {($tmp1,$tmp2)=($radek=~/^cols\s*(.*?)\s*=\s*(.*)/i);$tmp2=~s/\s*//g;$tmp2=~s/,/,/g;$COLS{"$tmp1"}="$tmp2";};
 }
 if(!$INIT) {&err("100","No init string");exit(0);}
}

sub err
{
 print "<br> Error :<b>$_[0]</b> : $_[1]\n";
}