From 13310b57d98ddb47294f5844f1dadb88b2c77cd8 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 23 Apr 1999 06:34:07 +0000 Subject: [PATCH] new stuff --- cgi/sets.cgi | 39 +++++++++++++++--- cgi/shows.cgi | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cgi/studios.cgi | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 272 insertions(+), 5 deletions(-) create mode 100755 cgi/shows.cgi create mode 100755 cgi/studios.cgi diff --git a/cgi/sets.cgi b/cgi/sets.cgi index e5c64b1..4cb21db 100755 --- a/cgi/sets.cgi +++ b/cgi/sets.cgi @@ -1,5 +1,5 @@ #!/usr/bin/perl -Tw -# $Id: sets.cgi,v 1.5 1999-04-22 06:21:06 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 @@ -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,7 +54,9 @@ 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; } @@ -99,6 +102,23 @@ unless ( $cgi->param('magic') ) { #first time through 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); @@ -108,6 +128,9 @@ unless ( $cgi->param('magic') ) { #first time through sub print_form { my $cgi = shift; my $action = shift; + + my %persons = map { @{$_}; } + @{$dbh->selectall_arrayref( "SELECT PERSON_ID, NAME FROM PERSONS" )}; print $cgi->header, $cgi->start_html($action), $cgi->h1($action), @@ -119,6 +142,12 @@ sub print_form { "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'), diff --git a/cgi/shows.cgi b/cgi/shows.cgi new file mode 100755 index 0000000..461adfc --- /dev/null +++ b/cgi/shows.cgi @@ -0,0 +1,120 @@ +#!/usr/bin/perl -Tw +# $Id: shows.cgi,v 1.1 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 + +use strict; +use vars qw ( $data_source $user $password $table @fields + $cgi $dbh + ); +use subs qw( print_form ); +use CGI qw(tr th td); +use CGI::Carp qw(fatalsToBrowser); +use DBI; + +$data_source = "DBI:mysql:technostate"; +$user = "agent"; +$password = "t3chno"; + +$table = "SHOWS"; +@fields = qw( SHOW_ID PERSON_ID SHOWSTART DURATION STUDIO_ID ); + +$cgi = new CGI; + +$dbh = DBI->connect( $data_source, $user, $password ) + or die "Cannot connect: ". $DBI::errstr; + +unless ( $cgi->param('magic') ) { #first time through + + my $sth = $dbh->prepare( "SELECT * FROM $table" ) + or die $dbh->errstr; + my $rv = $sth->execute; + die $sth->errstr unless $rv; + + print $cgi->header( '-expires' => 'now' ), + $cgi->start_html('Show listing'), + $cgi->h1('Show listing'), + ; + + unless ( $sth eq '0E0' ) { + + my @columns = @{ $sth->{'NAME'} }; + + print $cgi->start_table, + $cgi->tr( + map { + $cgi->th($_) + } @columns + ) + ; + + my %hash = (); + my $hashref = undef; + while ( $hashref = $sth->fetchrow_hashref ) { + %hash = %{$hashref}; + print $cgi->tr( map { $cgi->td( $hash{$_} ) } @columns ); + } + print $cgi->end_table; + + } + + $cgi->param('magic', 'new_form'); + print '

Add new show'; + print $cgi->end_html; + + exit; + +} elsif ( $cgi->param('magic') eq 'new_form' ) { + $cgi->param('SHOW_ID', 0); + $cgi->param('magic', 'process_form'); + &print_form( $cgi, "Add show" ); + exit; +} elsif ( $cgi->param('magic') eq 'process_form' ) { + + my $field; + foreach $field ( @fields ) { + if ( $cgi->param( $field ) ) { + $cgi->param( $field ) =~ /^(.*)$/; + 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 $table ( ". + join(', ', @fields ). + ' ) VALUES ( '. + join( ', ', map { $cgi->param($_) } @fields ). + ' )' + ; + my $sth = $dbh->prepare($statement) + or die $dbh->errstr; + my $rv = $sth->execute; + die $sth->errstr unless $rv; + + my $url = $cgi->url; + $url =~ s/^\/[\/]+$//; + print $cgi->redirect($url); +} + +sub print_form { + my $cgi = shift; + my $action = shift; + print $cgi->header, + $cgi->start_html($action), + $cgi->h1($action), + $cgi->start_form, + $cgi->hidden( -name => 'SHOW_ID' ), + "Person_ID: ", $cgi->textfield( -name => 'PERSON_ID' ), "
", + "Show start: ", $cgi->textfield( -name => 'SHOWSTART' ), "
", + "Duration: ", $cgi->textfield( -name => 'DURATION' ), "
", + "Studio_ID: ", $cgi->textfield( -name => 'STUDIO_ID' ), "
", + $cgi->hidden( -name => 'magic'), + $cgi->submit('Submit'), + $cgi->end_form, + $cgi->end_html; + ; +} diff --git a/cgi/studios.cgi b/cgi/studios.cgi new file mode 100755 index 0000000..5fa0dc5 --- /dev/null +++ b/cgi/studios.cgi @@ -0,0 +1,118 @@ +#!/usr/bin/perl -Tw +# $Id: studios.cgi,v 1.1 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 + +use strict; +use vars qw ( $data_source $user $password $table @fields + $cgi $dbh + ); +use subs qw( print_form ); +use CGI qw(tr th td); +use CGI::Carp qw(fatalsToBrowser); +use DBI; + +$data_source = "DBI:mysql:technostate"; +$user = "agent"; +$password = "t3chno"; + +$table = "STUDIOS"; +@fields = qw( STUDIO_ID NAME ISLIVE ); + +$cgi = new CGI; + +$dbh = DBI->connect( $data_source, $user, $password ) + or die "Cannot connect: ". $DBI::errstr; + +unless ( $cgi->param('magic') ) { #first time through + + my $sth = $dbh->prepare( "SELECT * FROM $table" ) + or die $dbh->errstr; + my $rv = $sth->execute; + die $sth->errstr unless $rv; + + print $cgi->header( '-expires' => 'now' ), + $cgi->start_html('Studio listing'), + $cgi->h1('Studio listing'), + ; + + unless ( $sth eq '0E0' ) { + + my @columns = @{ $sth->{'NAME'} }; + + print $cgi->start_table, + $cgi->tr( + map { + $cgi->th($_) + } @columns + ) + ; + + my %hash = (); + my $hashref = undef; + while ( $hashref = $sth->fetchrow_hashref ) { + %hash = %{$hashref}; + print $cgi->tr( map { $cgi->td( $hash{$_} ) } @columns ); + } + print $cgi->end_table; + + } + + $cgi->param('magic', 'new_form'); + print '

Add new studio'; + print $cgi->end_html; + + exit; + +} elsif ( $cgi->param('magic') eq 'new_form' ) { + $cgi->param('STUDIO_ID', 0); + $cgi->param('magic', 'process_form'); + &print_form( $cgi, "Add studio" ); + exit; +} elsif ( $cgi->param('magic') eq 'process_form' ) { + + my $field; + foreach $field ( @fields ) { + if ( $cgi->param( $field ) ) { + $cgi->param( $field ) =~ /^(.*)$/; + 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 $table ( ". + join(', ', @fields ). + ' ) VALUES ( '. + join( ', ', map { $cgi->param($_) } @fields ). + ' )' + ; + my $sth = $dbh->prepare($statement) + or die $dbh->errstr; + my $rv = $sth->execute; + die $sth->errstr unless $rv; + + my $url = $cgi->url; + $url =~ s/^\/[\/]+$//; + print $cgi->redirect($url); +} + +sub print_form { + my $cgi = shift; + my $action = shift; + print $cgi->header, + $cgi->start_html($action), + $cgi->h1($action), + $cgi->start_form, + $cgi->hidden( -name => 'STUDIO_ID' ), + "NAME: ", $cgi->textfield( -name => 'NAME' ), "
", + "ISLIVE", $cgi->textfield( -name => 'ISLIVE' ), "
", + $cgi->hidden( -name => 'magic'), + $cgi->submit('Submit'), + $cgi->end_form, + $cgi->end_html; + ; +} -- 2.11.0