#!/usr/bin/perl ########################################################################### # Reviews Iterface # # This program will be used to generate the top level reviews page. # # (c) 2002 The Stigmata Organization ############################################################################ # Uses and Requires use lib qw( . ); use CGI; use CGI::Carp qw( fatalsToBrowser ); use DBI; use DTO::Site; use strict; # Run Main main(); # Sub It sub main { # Create CGI Object my $q = CGI->new(); # Create DTO Site Object my $dtos = DTO::Site->new($q); # Generate Page print $dtos->generate_top(); print $dtos->revnavbar(); print main_page($q,$dtos); print $dtos->generate_bottom(); } sub main_page { # Passed Q my $q = shift; my $dtos = shift; # HTML Variable my $html; # What do I do? if ($q->param('done')) { $html .= process_form($q, $dtos); } else { $html .= create_form($q, $dtos); } # Return Page return $html; } sub create_form { # Passed Q my $q = shift; my $dtos = shift; # HTML Var my $html; # Title $html .= $q->h2("Create a New Review"); # Get All Shows my $shows = $dtos->get_shows(); if (!defined $shows) { $html .= $q->b("An Error Has Occurred:") . $q->p; $html .= $dtos->get_error . $q->p; return $html; } # Get Show List in to good form my %lshows; $lshows{0} = ' -- Select a Show/CD -- '; foreach my $show (@$shows) { $lshows{$show->{'snc_id'}} = $show->{'snc_title'}; } my @vshows = keys %lshows; # Start My Form $html .= $q->startform(); $html .= $q->hidden(-name=>'done', -value=>1); # Set up Form $html .= $q->b("Select a CD or Show to Review:") . $q->br; $html .= $q->popup_menu(-name=>'show', -value=>\@vshows, -labels=>\%lshows, -default=>0) . $q->p; $html .= $q->textarea(-name=>'reviewtext', -cols=>60, -rows=>20, -wrap=>'hard') . $q->p; # Submission $html .= $q->submit(-name=>' Submit Review '); $html .= "         "; $html .= $q->reset(-name=>' Clear All Fields '); # End Form $html .= $q->endform(); # Return HTML return $html; } sub process_form { # My Passed Q my $q = shift; my $dtos = shift; # Get User ID - FIX ME FIX ME FIX ME my $userid = 1; # HTML Variable my $html; # HTML Header $html .= $q->h2("Create a New Review"); # Check Errors my @errors = checkerrors($q); if (@errors) { $html = $q->b("The following errors have occurred:") . $q->br; $html .= ""; $html .= create_form($q,$dtos); return $html; } # Insert Review my $revid = $dtos->create_review($userid, $q->param('show'), $q->param('reviewtext')); if (!defined $revid) { $html .= $q->b("An Error Has Occurred:") . $q->p; $html .= $dtos->get_error() . $q->p; return $html; } # Things Woked $html .= $q->b("Review Created") . $q->p; # Return return $html; } sub checkerrors { # Passed Q my $q = shift; # Errors Var my @errors; # Checking! if ($q->param('show') == 0 || $q->param('show') =~ /^\s*$/) { push @errors, "Show or CD not selected"; } if ($q->param('reviewtext') =~ /^\s*$/) { push @errors, "Review Text is empty"; } # Return Errors return @errors; }