2 # $Id: sets.cgi,v 1.2 1999-04-22 05:54:53 ivan Exp $
3 # Copyright (c) 1999 Ivan Kohler. All rights reserved.
4 # This program is free software; you can redistribute it and/or modify it under
5 # the same terms as perl itself
8 use vars qw ( $data_source $user $password $table @fields
11 use subs qw( print_form );
13 use CGI::Carp qw(fatalsToBrowser);
16 $data_source = "DBI:mysql:technostate";
21 @fields = qw( SET_ID SETSTART DURATION FILENAME FILESIZE DESCRIPTION INFO KEYWORDS DOWNLOADS SHOW_ID );
25 $dbh = DBI->connect( $data_source, $user, $password )
26 or die "Cannot connect: ". $DBI::errstr;
28 unless ( $cgi->param('magic') ) { #first time through
30 my $sth = $dbh->prepare( "SELECT * FROM $table" )
32 my $rv = $sth->execute;
33 die $sth->errstr unless $rv;
35 print $cgi->header( '-expires' => 'now' ),
36 $cgi->start_html('Person listing'),
37 $cgi->h1('Person listing'),
40 unless ( $sth eq '0E0' ) {
42 my @columns = @{ $sth->{'NAME'} };
44 print $cgi->start_table,
54 while ( $hashref = $sth->fetchrow_hashref ) {
56 print $cgi->tr( map { $cgi->td( $hash{$_} ) } @columns );
58 print $cgi->end_table;
61 $cgi->param('magic', 'new_form');
62 print '<P><A HREF="', $cgi->self_url, '">Add new person</A>';
67 } elsif ( $cgi->param('magic') eq 'new_form' ) {
68 $cgi->param('PERSON_ID', 0);
69 $cgi->param('magic', 'process_form');
70 &print_form( $cgi, "Add person" );
72 } elsif ( $cgi->param('magic') eq 'process_form' ) {
75 foreach $field ( @fields ) {
76 if ( $cgi->param( $field ) ) {
77 $cgi->param( $field ) =~ /^(.*)$/;
78 $cgi->param( $field, $1);
81 my $statement = 'INSERT INTO PERSONS ( '.
84 join( ', ', map { $dbh->quote($cgi->param($_)) } @fields ).
87 my $sth = $dbh->prepare($statement)
89 my $rv = $sth->execute;
90 die $sth->errstr unless $rv;
93 $url =~ s/^\/[\/]+$//;
94 print $cgi->redirect($url);
101 print $cgi->header( '-expires' => 'now' ),
102 $cgi->start_html($action),
105 $cgi->hidden( -name => 'ID' ),
106 "Start Time: ", $cgi->textfield( -name => 'SETSTART' ), "<BR>",
107 "Length: ", $cgi->textfield( -name => 'DURATION' ), "<BR>",
108 "Filename: ", $cgi->textfield( -name => 'FILENAME' ), "<BR>",
109 "Short Description: ", $cgi->textarea( -name => 'DESCRIPTION', -cols => '45', -rows => '2' ), "<BR>",
110 "Long Description: ", $cgi->textarea( -name => 'INFO', -cols => '45', -rows => '5' ), "<BR>",
111 "Keywords: ", $cgi->textfield( -name => 'KEYWORDS' ), "<BR>",
112 "Show?: ", $cgi->textfield( -name => 'SHOW_ID' ), "<BR>",
113 $cgi->hidden( -name => 'magic'),
114 $cgi->submit('Submit'),