From: trose Date: Thu, 22 Apr 1999 05:04:56 +0000 (+0000) Subject: copied persons.cgi and made a few changes X-Git-Url: http://git.freeside.biz/gitweb/?p=technostate.git;a=commitdiff_plain;h=a6888a97f2573cf8c5ca89670dd33bd849080faf copied persons.cgi and made a few changes --- diff --git a/cgi/sets.cgi b/cgi/sets.cgi new file mode 100755 index 0000000..e94a25b --- /dev/null +++ b/cgi/sets.cgi @@ -0,0 +1,112 @@ +#!/usr/bin/perl -Tw +# $Id: sets.cgi,v 1.1 1999-04-22 05:04:56 trose 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; +use CGI::Carp qw(fatalsToBrowser); +use DBI; + +$data_source = "DBI:mysql:technostate"; +$user = "agent"; +$password = "t3chno"; + +$table = "SETS"; +@fields = qw( SET_ID SETSTART DURATION FILENAME FILESIZE DESCRIPTION INFO KEYWORDS DOWNLOADS SHOW_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->do( "SELECT * FROM PERSONS" ) or die $dbh->errstr; + + print $cgi->header, + $cgi->start_html('Person listing'), + $cgi->h1('Person listing'), + ; + + unless ( $sth eq '0E0' ) { + + print $cgi->start_table, + $cgi->tr( + map { + $cgi->th($_) + } @{$sth->{NAME}} + ), + map { + $cgi->tr( + map { + $cgi->td( $_ ) + } @{ $_ } + ) + } @{ $sth->fetchall_arrayref }, + $cgi->end_table, + ; + } + + $cgi->param('magic', 'new_form'); + print '

Add new person'; + print $cgi->end_html; + + exit; + +} elsif ( $cgi->param('magic') eq 'new_form' ) { + $cgi->param('PERSON_ID', 0); + $cgi->param('magic', 'process_form'); + &print_form( $cgi, "Add person" ); + exit; +} elsif ( $cgi->param('magic') eq 'process_form' ) { + + my $field; + foreach $field ( @fields ) { + if ( $cgi->param( $field ) ) { + $cgi->param( $field ) =~ /^(.*)$/; + $cgi->param( $field, $1); + } + } + my $statement = 'INSERT INTO PERSONS ( '. + 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; + + print $cgi->header, + "person added?" + ; +} + +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 => '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' ), "
", + "Show?: ", $cgi->textfield( -name => 'SHOW_ID' ), "
", + $cgi->hidden( -name => 'magic'), + $cgi->submit('Submit'), + $cgi->end_form, + $cgi->end_html; + ; +}