#!/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 .= ""; $html .= $q->p; $html .= create_form($q); return $html; } # 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( UPDATE users SET user_passwd = ?, user_fname = ?, user_lname = ?, user_email = ?, user_aim = ?, user_yahoo = ?, user_icq = ?, user_msn = ?, user_privacy = ? WHERE user_id = ? )); $sth->bind_param(1, $q->param('passwd1')); $sth->bind_param(2, $q->param('fname')); $sth->bind_param(3, $q->param('lname')); $sth->bind_param(4, $q->param('email')); $sth->bind_param(5, $q->param('aim')); $sth->bind_param(6, $q->param('yahoo')); $sth->bind_param(7, $q->param('icq')); $sth->bind_param(8, $q->param('msn')); $sth->bind_param(9, $q->param('privacy')); $sth->bind_param(10, $q->param('userid')); $sth->execute || die "Unable to execute: " . $dbh->errstr; $dbh->disconnect; $sth->finish; $html .= $q->b("Profile Updated."); $html .= $q->p; $html .= viewprofile($q); # Return Page return $html; } sub checkerrors { # Passed Q my $q = shift; # Error List my @errors = (); # Check all my Data if ($q->param('fname') =~ /^\s*$/) { push @errors, "First Name is Missing"; } if ($q->param('lname') =~ /^\s*$/) { push @errors, "Last Name is Missing"; } if ($q->param('email') =~ /^\s*$/) { push @errors, "E-Mail Address is Missing"; } if ($q->param('passwd1') =~ /^\s*$/) { push @errors, "Password is Missing"; } if ($q->param('passwd2') =~ /^\s*$/) { push @errors, "Re-Type of Password is Missing"; } if ($q->param('passwd1') != $q->param('passwd2')) { push @errors, "Passwords Do Not Match"; } return @errors; }