#!/usr/bin/perl ########################################################################### # User Creation. # # This program will be used to create users. # # (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); print $dtos->generate_bottom(); } sub main_page { # Passed Q my $q = shift; # HTML Variable my $html; # Where do you want to go today? if ($q->param('done') == 1) { $html .= process_form($q); } elsif ($q->param('edit') == 1) { $html .= create_form($q); } else { $html .= viewprofile($q); } return $html; } sub viewprofile { # Passed Q my $q = shift; # HTML Variable my $html; # Header $html .= $q->h2("View Your Profile"); # Database Information my $database = "dtorg"; my $host = "wicked.stigmata.org"; my $data_source = "DBI:mysql:$database;host=$host"; my $username = "skadz"; my $password = "egenera"; my $dbh = DBI->connect( $data_source, $username, $password); if (!$dbh) { die "Can't connect to $data_source:" . $dbh->errstr. "\n"; } my $sth = $dbh->prepare(qq( SELECT user_id, user_name, user_passwd, user_fname, user_lname, user_email, user_aim, user_yahoo, user_icq, user_msn, user_privacy FROM users WHERE user_name = ? )); $sth->bind_param(1, 'Skadz'); $sth->execute || die "Unable to execute: " . $dbh->errstr; # Get Information Out my $ref = $sth->fetchrow_hashref(); # Close it up $dbh->disconnect; $sth->finish; # Check Privacy my $privacy = "Your Information is Not Kept Private"; if ($ref->{'user_privacy'} == 1) { $privacy = "Your Information is Kept Private"; } # Print Table $html .= $q->table({-width=>"100%"}, $q->TR( $q->td($q->b("First Name")), $q->td($q->b("Last Name")) ), $q->TR( $q->td($ref->{'user_fname'}), $q->td($ref->{'user_lname'}) ), $q->TR( $q->td($q->b("User Name")), $q->td($q->b("E-Mail Address")) ), $q->TR( $q->td($ref->{'user_name'}), $q->td($ref->{'user_email'}) ), $q->TR( $q->td($q->b("AIM")), $q->td($q->b("Yahoo IM")) ), $q->TR( $q->td($ref->{'user_aim'}), $q->td($ref->{'user_yahoo'}) ), $q->TR( $q->td($q->b("ICQ")), $q->td($q->b("MSN")) ), $q->TR( $q->td($ref->{'user_icq'}), $q->td($ref->{'user_msn'}) ), $q->TR( $q->td({-colspan=>2}, $q->b($privacy)) ), ); $html .= $q->p; $html .= $q->startform(); my $userid = $ref->{'user_id'}; $html .= $q->hidden(-name=>'edit', -value=>1); $html .= $q->hidden(-name=>'userid', -value=>$userid); $html .= $q->submit(-name=>' Edit Your Profile '); $html .= $q->endform(); $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; $html .= $q->br . $q->br; # Return Variable return $html; } sub create_form { # Passed Q my $q = shift; # HTML Variable my $html; # Header $html .= $q->h2("Edit Your Profile"); # Database Information my $database = "dtorg"; my $host = "wicked.stigmata.org"; my $data_source = "DBI:mysql:$database;host=$host"; my $username = "skadz"; my $password = "egenera"; my $dbh = DBI->connect( $data_source, $username, $password); if (!$dbh) { die "Can't connect to $data_source:" . $dbh->errstr. "\n"; } my $sth = $dbh->prepare(qq( SELECT user_id, user_name, user_passwd, user_fname, user_lname, user_email, user_aim, user_yahoo, user_icq, user_msn, user_privacy FROM users WHERE user_name = ? )); $sth->bind_param(1, 'Skadz'); $sth->execute || die "Unable to execute: " . $dbh->errstr; # Get Information Out my $ref = $sth->fetchrow_hashref(); my $privacy = 0; if ($ref->{'user_privacy'}) { $privacy = 1; } # Close it up $dbh->disconnect; $sth->finish; # Make My Form $html .= $q->startform(); $html .= $q->hidden(-name=>'userid'); $html .= $q->hidden(-name=>'done', -value=>1); $html .= $q->table( $q->TR( $q->td($q->b("First Name")), $q->td($q->b("Last Name")) ), $q->TR( $q->td($q->textfield(-name=>'fname', -size=>25, -default=>$ref->{'user_fname'})), $q->td($q->textfield(-name=>'lname', -size=>25, -default=>$ref->{'user_lname'})) ), $q->TR( $q->td($q->b("E-Mail Address")), $q->td(" ") ), $q->TR( $q->td($q->textfield(-name=>'email', -size=>25, -maxlength=>25, -default=>$ref->{'user_email'})), $q->td(" ") ), $q->TR( $q->td($q->b("Password")), $q->td($q->b("Re-Type Password")) ), $q->TR( $q->td($q->password_field(-name=>'passwd1', -size=>25, -maxlength=>25, -default=>$ref->{'user_passwd'})), $q->td($q->password_field(-name=>'passwd2', -size=>25, -maxlength=>25, -default=>$ref->{'user_passwd'})) ), $q->TR( $q->td($q->b("AIM")), $q->td($q->b("Yahoo IM")) ), $q->TR( $q->td($q->textfield(-name=>'aim', -size=>25, -maxlength=>50, -default=>$ref->{'user_aim'})), $q->td($q->textfield(-name=>'yahoo', -size=>25, -maxlength=>50, -default=>$ref->{'user_yahoo'})) ), $q->TR( $q->td($q->b("ICQ")), $q->td($q->b("MSN")) ), $q->TR( $q->td($q->textfield(-name=>'icq', -size=>25, -maxlength=>50, -default=>$ref->{'user_icq'})), $q->td($q->textfield(-name=>'msn', -size=>25, -maxlength=>50, -default=>$ref->{'user_msn'})) ), $q->TR( $q->td({-colspan=>2}, $q->checkbox(-name=>'privacy', -value=>1, -checked=>$privacy, -label=>"Click here to have your information kept private")) ), $q->TR( $q->td($q->submit(-name=>' Update Your Profile ')), $q->td($q->reset(-name=>' Reset All Fields ')), ) ); $html .= $q->endform(); $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; # Return Info return $html; } sub process_form { # Passed Q my $q = shift; # HTML Var my $html; # Dump #$html .= $q->Dump(); # Error Checking my @errors = checkerrors($q); if (@errors) { $html = $q->b("Please correct the following errors and resubmit:") . $q->p; $html .= "