2 # $Id: sets.cgi,v 1.7 1999-07-18 05:08:29 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,
46 ( map { $cgi->th($_) } @columns ),
53 while ( $hashref = $sth->fetchrow_hashref ) {
56 ( map { $cgi->td( $hash{$_} ) } @columns ) ),
59 print $cgi->end_table;
62 $cgi->param('magic', 'new_form');
63 print '<P><A HREF="', $cgi->self_url, '">Add new set</A>';
68 } elsif ( $cgi->param('magic') eq 'new_form' ) {
69 $cgi->param('SET_ID', 0);
70 $cgi->param('magic', 'process_form');
71 &print_form( $cgi, "Add set" );
73 } elsif ( $cgi->param('magic') eq 'process_form' ) {
75 $cgi->param('FILESIZE', 0);
76 $cgi->param('DOWNLOADS', 0);
79 foreach $field ( @fields ) {
80 if ( $cgi->param( $field ) ) {
81 $cgi->param( $field ) =~ /^(.*)$/;
83 if ( (DBI::looks_like_number($param))[0] ) {
84 $cgi->param( $field, $param );
86 $cgi->param( $field, $dbh->quote($param) );
91 my $statement = "INSERT INTO $table ( ".
94 join( ', ', map { $cgi->param($_) } @fields ).
98 my $sth = $dbh->prepare($statement)
100 my $rv = $sth->execute;
101 die $sth->errstr unless $rv;
103 my $set_id = $sth->{'insertid'};
106 $dbh->do( "DELETE FROM PERSONS_SETS WHERE ( SET_ID = $set_id )" )
110 foreach $person_id ( $cgi->param('PERSON_ID') ) {
112 "INSERT INTO PERSONS_SETS ( PERSON_ID, SET_ID ) ".
113 "VALUES ( $person_id, $set_id )"
114 ) or die $dbh->errstr;
117 #my $rv = $sth->execute;
118 #die $sth->errstr unless $rv;
121 $url =~ s/^\/[\/]+$//;
122 print $cgi->redirect($url);
130 my %persons = map { @{$_}; }
131 @{$dbh->selectall_arrayref( "SELECT PERSON_ID, NAME FROM PERSONS" )};
133 $cgi->start_html($action),
136 $cgi->hidden( -name => 'SET_ID' ),
137 "Start Time: ", $cgi->textfield( -name => 'SETSTART' ), "<BR>",
138 "Length: ", $cgi->textfield( -name => 'DURATION' ), "<BR>",
139 "Filename: ", $cgi->textfield( -name => 'FILENAME' ), "<BR>",
140 "Short Description: ", $cgi->textarea( -name => 'DESCRIPTION', -cols => '45', -rows => '2' ), "<BR>",
141 "Long Description: ", $cgi->textarea( -name => 'INFO', -cols => '45', -rows => '5' ), "<BR>",
142 "Keywords: ", $cgi->textfield( -name => 'KEYWORDS' ), "<BR>",
143 "People: ", $cgi->scrolling_list(
144 -name => "PERSON_ID",
145 '-values' => [ sort { $persons{$a} cmp $persons{$b} } keys(%persons) ],
146 '-labels' => \%persons,
147 '-multiple' => 'true',
149 "Show?: ", $cgi->textfield( -name => 'SHOW_ID' ), "<BR>",
150 $cgi->hidden( -name => 'magic'),
151 $cgi->submit('Submit'),