2 # $Id: sets.cgi,v 1.1 1999-04-22 05:04:56 trose 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->do( "SELECT * FROM PERSONS" ) or die $dbh->errstr;
33 $cgi->start_html('Person listing'),
34 $cgi->h1('Person listing'),
37 unless ( $sth eq '0E0' ) {
39 print $cgi->start_table,
51 } @{ $sth->fetchall_arrayref },
56 $cgi->param('magic', 'new_form');
57 print '<P><A HREF="', $cgi->self_url, '">Add new person</A>';
62 } elsif ( $cgi->param('magic') eq 'new_form' ) {
63 $cgi->param('PERSON_ID', 0);
64 $cgi->param('magic', 'process_form');
65 &print_form( $cgi, "Add person" );
67 } elsif ( $cgi->param('magic') eq 'process_form' ) {
70 foreach $field ( @fields ) {
71 if ( $cgi->param( $field ) ) {
72 $cgi->param( $field ) =~ /^(.*)$/;
73 $cgi->param( $field, $1);
76 my $statement = 'INSERT INTO PERSONS ( '.
79 join( ', ', map { $cgi->param($_) } @fields ).
82 my $sth = $dbh->prepare($statement)
84 my $rv = $sth->execute;
85 die $sth->errstr unless $rv;
96 $cgi->start_html($action),
99 $cgi->hidden( -name => 'ID' ),
100 "Start Time: ", $cgi->textfield( -name => 'SETSTART' ), "<BR>",
101 "Length: ", $cgi->textfield( -name => 'DURATION' ), "<BR>",
102 "Filename: ", $cgi->textfield( -name => 'FILENAME' ), "<BR>",
103 "Short Description: ", $cgi->textarea( -name => 'DESCRIPTION', -cols => '45', -rows => '2' ), "<BR>",
104 "Long Description: ", $cgi->textarea( -name => 'INFO', -cols => '45', -rows => '5' ), "<BR>",
105 "Keywords: ", $cgi->textfield( -name => 'KEYWORDS' ), "<BR>",
106 "Show?: ", $cgi->textfield( -name => 'SHOW_ID' ), "<BR>",
107 $cgi->hidden( -name => 'magic'),
108 $cgi->submit('Submit'),