X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=cgi%2Fsets.cgi;h=4cb21db4a0a55cbf313210ec9bc48a7fc8779870;hb=13310b57d98ddb47294f5844f1dadb88b2c77cd8;hp=b4ef999a82f7b93a92a65a720e2b40f29e80773c;hpb=582478ebeca009066b0445dca96d56c10d6a2f6e;p=technostate.git diff --git a/cgi/sets.cgi b/cgi/sets.cgi index b4ef999..4cb21db 100755 --- a/cgi/sets.cgi +++ b/cgi/sets.cgi @@ -1,5 +1,5 @@ #!/usr/bin/perl -Tw -# $Id: sets.cgi,v 1.2 1999-04-22 05:54:53 ivan Exp $ +# $Id: sets.cgi,v 1.6 1999-04-23 06:34:07 ivan Exp $ # Copyright (c) 1999 Ivan Kohler. All rights reserved. # This program is free software; you can redistribute it and/or modify it under # the same terms as perl itself @@ -33,8 +33,8 @@ unless ( $cgi->param('magic') ) { #first time through die $sth->errstr unless $rv; print $cgi->header( '-expires' => 'now' ), - $cgi->start_html('Person listing'), - $cgi->h1('Person listing'), + $cgi->start_html('Set listing'), + $cgi->h1('Set listing'), ; unless ( $sth eq '0E0' ) { @@ -43,9 +43,10 @@ unless ( $cgi->param('magic') ) { #first time through print $cgi->start_table, $cgi->tr( - map { - $cgi->th($_) - } @columns + ( map { + $cgi->th($_) + } @columns + ), $cgi->th('People'); ) ; @@ -53,42 +54,71 @@ unless ( $cgi->param('magic') ) { #first time through my $hashref = undef; while ( $hashref = $sth->fetchrow_hashref ) { %hash = %{$hashref}; - print $cgi->tr( map { $cgi->td( $hash{$_} ) } @columns ); + print $cgi->tr( + ( map { $cgi->td( $hash{$_} ) } @columns ) ), + ; } print $cgi->end_table; } $cgi->param('magic', 'new_form'); - print '

Add new person'; + print '

Add new set'; print $cgi->end_html; exit; } elsif ( $cgi->param('magic') eq 'new_form' ) { - $cgi->param('PERSON_ID', 0); + $cgi->param('SET_ID', 0); $cgi->param('magic', 'process_form'); - &print_form( $cgi, "Add person" ); + &print_form( $cgi, "Add set" ); exit; } elsif ( $cgi->param('magic') eq 'process_form' ) { + $cgi->param('FILESIZE', 0); + $cgi->param('DOWNLOADS', 0); + my $field; foreach $field ( @fields ) { if ( $cgi->param( $field ) ) { $cgi->param( $field ) =~ /^(.*)$/; - $cgi->param( $field, $1); + my $param = $1 || 0; + if ( (DBI::looks_like_number($param))[0] ) { + $cgi->param( $field, $param ); + } else { + $cgi->param( $field, $dbh->quote($param) ); + } } } - my $statement = 'INSERT INTO PERSONS ( '. + + my $statement = "INSERT INTO $table ( ". join(', ', @fields ). ' ) VALUES ( '. - join( ', ', map { $dbh->quote($cgi->param($_)) } @fields ). + join( ', ', map { $cgi->param($_) } @fields ). ' )' ; + warn $statement; my $sth = $dbh->prepare($statement) or die $dbh->errstr; my $rv = $sth->execute; die $sth->errstr unless $rv; + my $set_id = $sth->{'insertid'}; + warn $set_id; + + $dbh->do( "DELETE FROM PERSONS_SETS WHERE ( SET_ID = $set_id )" ) + or die $dbh->errstr; + + my $person_id; + foreach $person_id ( $cgi->param('PERSON_ID') ) { + $dbh->do( + "INSERT INTO PERSONS_SETS ( PERSON_ID, SET_ID ) ". + "VALUES ( $person_id, $set_id )" + ) or die $dbh->errstr; + } + + #my $rv = $sth->execute; + #die $sth->errstr unless $rv; + my $url = $cgi->url; $url =~ s/^\/[\/]+$//; print $cgi->redirect($url); @@ -98,17 +128,26 @@ unless ( $cgi->param('magic') ) { #first time through sub print_form { my $cgi = shift; my $action = shift; - print $cgi->header( '-expires' => 'now' ), + + my %persons = map { @{$_}; } + @{$dbh->selectall_arrayref( "SELECT PERSON_ID, NAME FROM PERSONS" )}; + print $cgi->header, $cgi->start_html($action), $cgi->h1($action), $cgi->start_form, - $cgi->hidden( -name => 'ID' ), + $cgi->hidden( -name => 'SET_ID' ), "Start Time: ", $cgi->textfield( -name => 'SETSTART' ), "
", "Length: ", $cgi->textfield( -name => 'DURATION' ), "
", "Filename: ", $cgi->textfield( -name => 'FILENAME' ), "
", "Short Description: ", $cgi->textarea( -name => 'DESCRIPTION', -cols => '45', -rows => '2' ), "
", "Long Description: ", $cgi->textarea( -name => 'INFO', -cols => '45', -rows => '5' ), "
", "Keywords: ", $cgi->textfield( -name => 'KEYWORDS' ), "
", + "People: ", $cgi->scrolling_list( + -name => "PERSON_ID", + '-values' => [ sort { $persons{$a} cmp $persons{$b} } keys(%persons) ], + '-labels' => \%persons, + '-multiple' => 'true', + ), "Show?: ", $cgi->textfield( -name => 'SHOW_ID' ), "
", $cgi->hidden( -name => 'magic'), $cgi->submit('Submit'),