Initial revision
[mir.git] / dbscripts / table2html.pl
1 #!/usr/bin/perl
2
3 ### extract
4
5 use DBI;
6
7 $db_user="root";
8 $dbi_string="DBI:mysql:nadiraktuell";
9
10 die "parameter [-form] tableName" if ($#ARGV>1 | $#ARGV==-1);
11 die unless ($dbh=DBI->connect($dbi_string,$db_user));
12
13 $form=0;
14
15 if ($#ARGV == 1){
16     $form=1;
17     $tableName=$ARGV[1];
18 }
19 else {
20     $tableName=$ARGV[0];
21 }
22
23 $sth=$dbh->prepare(<<EO_QUERY);
24 show fields from $tableName
25 EO_QUERY
26
27 $sth->execute;
28
29 if (defined $sth) {
30     
31     print(<<HEAD);
32 <html>
33 <head>
34 <title>
35 nadiraktuell.$tableName
36 </title>
37 <head>
38
39 <body>
40 <B>nadiraktuell.$tableName</B><P>
41 HEAD
42
43
44     if ($form==1) { 
45       print "<form action=\"/scripts/NadirAktuell\">
46 \t<input type=hidden name=module value=$tableName>
47         <input type=\"hidden\" name=\"id\" value=\"\${id}\">
48         <if new>
49                 <input type=\"hidden\" name=\"do\" value=\"insert\">
50         <else>
51                 <input type=\"hidden\" name=\"do\" value=\"update\">
52         </if>
53
54 <table border=\"0\">\n"; 
55     }
56 #
57 # Schleife
58
59     while (@data=$sth->fetchrow_array) {
60
61       print "\n<tr>\n<td align=\"right\"><B>$data[0]:</B></td>\n";
62       if ($form==1) {
63         print "<td><input type=\"text\" size=\"40\" name=\"$data[0]\" value=\"\$\{$data[0]\}\"></td>\n";
64       }
65       else {
66         print "<td><\$\{$data[0]\}></td>\n";
67       }
68       print "</tr>\n\n";
69     
70     }
71     
72     if ($form==1) {
73       print "<td colspan=\"2\" align=\"right\">
74 <if new>
75 <input type=\"submit\" name=\"save\" value=\"einfügen\">
76 <else>
77 <input type=\"submit\" name=\"save\" value=\"speichern\">
78 </if>
79 </td>
80 </form>
81 </table>";
82     }
83
84 print(<<BODY);
85
86 </body>
87 </html>
88 BODY
89 }
90
91 $sth->finish;
92 $dbh->disconnect;
93