2 # $Id: sets.cgi,v 1.6 1999-04-23 06:34:07 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,
49 ), $cgi->th('People');
55 while ( $hashref = $sth->fetchrow_hashref ) {
58 ( map { $cgi->td( $hash{$_} ) } @columns ) ),
61 print $cgi->end_table;
64 $cgi->param('magic', 'new_form');
65 print '<P><A HREF="', $cgi->self_url, '">Add new set</A>';
70 } elsif ( $cgi->param('magic') eq 'new_form' ) {
71 $cgi->param('SET_ID', 0);
72 $cgi->param('magic', 'process_form');
73 &print_form( $cgi, "Add set" );
75 } elsif ( $cgi->param('magic') eq 'process_form' ) {
77 $cgi->param('FILESIZE', 0);
78 $cgi->param('DOWNLOADS', 0);
81 foreach $field ( @fields ) {
82 if ( $cgi->param( $field ) ) {
83 $cgi->param( $field ) =~ /^(.*)$/;
85 if ( (DBI::looks_like_number($param))[0] ) {
86 $cgi->param( $field, $param );
88 $cgi->param( $field, $dbh->quote($param) );
93 my $statement = "INSERT INTO $table ( ".
96 join( ', ', map { $cgi->param($_) } @fields ).
100 my $sth = $dbh->prepare($statement)
102 my $rv = $sth->execute;
103 die $sth->errstr unless $rv;
105 my $set_id = $sth->{'insertid'};
108 $dbh->do( "DELETE FROM PERSONS_SETS WHERE ( SET_ID = $set_id )" )
112 foreach $person_id ( $cgi->param('PERSON_ID') ) {
114 "INSERT INTO PERSONS_SETS ( PERSON_ID, SET_ID ) ".
115 "VALUES ( $person_id, $set_id )"
116 ) or die $dbh->errstr;
119 #my $rv = $sth->execute;
120 #die $sth->errstr unless $rv;
123 $url =~ s/^\/[\/]+$//;
124 print $cgi->redirect($url);
132 my %persons = map { @{$_}; }
133 @{$dbh->selectall_arrayref( "SELECT PERSON_ID, NAME FROM PERSONS" )};
135 $cgi->start_html($action),
138 $cgi->hidden( -name => 'SET_ID' ),
139 "Start Time: ", $cgi->textfield( -name => 'SETSTART' ), "<BR>",
140 "Length: ", $cgi->textfield( -name => 'DURATION' ), "<BR>",
141 "Filename: ", $cgi->textfield( -name => 'FILENAME' ), "<BR>",
142 "Short Description: ", $cgi->textarea( -name => 'DESCRIPTION', -cols => '45', -rows => '2' ), "<BR>",
143 "Long Description: ", $cgi->textarea( -name => 'INFO', -cols => '45', -rows => '5' ), "<BR>",
144 "Keywords: ", $cgi->textfield( -name => 'KEYWORDS' ), "<BR>",
145 "People: ", $cgi->scrolling_list(
146 -name => "PERSON_ID",
147 '-values' => [ sort { $persons{$a} cmp $persons{$b} } keys(%persons) ],
148 '-labels' => \%persons,
149 '-multiple' => 'true',
151 "Show?: ", $cgi->textfield( -name => 'SHOW_ID' ), "<BR>",
152 $cgi->hidden( -name => 'magic'),
153 $cgi->submit('Submit'),