2 # $Id: sets.cgi,v 1.4 1999-04-22 06:06:16 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('Set listing'),
37 $cgi->h1('Set 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 set</A>';
67 } elsif ( $cgi->param('magic') eq 'new_form' ) {
68 $cgi->param('SET_ID', 0);
69 $cgi->param('magic', 'process_form');
70 &print_form( $cgi, "Add set" );
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 $cgi->param('FILESIZE', 0);
82 $cgi->param('DOWNLOADS', 0);
84 my $statement = "INSERT INTO $table ( ".
87 join( ', ', map { $dbh->quote($cgi->param($_)) } @fields ).
90 my $sth = $dbh->prepare($statement)
92 my $rv = $sth->execute;
93 die $sth->errstr unless $rv;
96 $url =~ s/^\/[\/]+$//;
97 print $cgi->redirect($url);
105 $cgi->start_html($action),
108 $cgi->hidden( -name => 'ID' ),
109 "Start Time: ", $cgi->textfield( -name => 'SETSTART' ), "<BR>",
110 "Length: ", $cgi->textfield( -name => 'DURATION' ), "<BR>",
111 "Filename: ", $cgi->textfield( -name => 'FILENAME' ), "<BR>",
112 "Short Description: ", $cgi->textarea( -name => 'DESCRIPTION', -cols => '45', -rows => '2' ), "<BR>",
113 "Long Description: ", $cgi->textarea( -name => 'INFO', -cols => '45', -rows => '5' ), "<BR>",
114 "Keywords: ", $cgi->textfield( -name => 'KEYWORDS' ), "<BR>",
115 "Show?: ", $cgi->textfield( -name => 'SHOW_ID' ), "<BR>",
116 $cgi->hidden( -name => 'magic'),
117 $cgi->submit('Submit'),