Audio-DB

 view release on metacpan or  search on metacpan

DB/Util/SystemConfig.pm  view on Meta::CPAN

}

sub print_edit_form {
  my $self = shift;
  my @cols = qw/First Last Email Username Password Priviledges/;
  my $dbh = $self->{dbh};
  my $sth = $dbh->prepare(qq{select * from users});
  print div({-class=>'actionbyline'},
	    "Use this form to edit the information of all users simultaneously.");
  print start_div({-class=>'actioncontent'});
  print startform(),
    start_table();
  print TR(td(\@cols));
  $sth->execute();
  while (my $h = $sth->fetchrow_hashref) {
    print 
      hidden(-name=>'user_id',-value=>$h->{user_id});
    print
      TR(td(textfield({-name=>'first_name',-value=>$h->{first_name},-size=>15})),
	 td(textfield({-name=>'last_name',-value=>$h->{last_name},-size=>15})),
	 td(textfield({-name=>'email',-value=>$h->{email},-size=>20})),
	 td(textfield({-name=>'username',-value=>$h->{username},-size=>10})),
	 td(textfield({-name=>'password',-value=>$h->{password},-size=>10})),
	 td(popup_menu({-name=>'privs',-values=>[qw/user admin overlord/],
			-default=>$h->{privs}})));
  }
  print end_table;
  print submit(-name=>'submit',-label=>'Update Users');
  print end_div;
}


sub process_edit_form {
  my $self = shift;
  my $dbh = $self->{dbh};
  # iterate over each param...
  my @fields = qw/first_name last_name email username password privs/; 
  my @params = param();
  my $params = { id         => [ param('user_id') ],
		 first_name => [ param('first_name') ],
		 last_name  => [ param('last_name') ],
		 email      => [ param('email') ],
		 username   => [ param('username') ],
		 password   => [ param('password') ],
		 privs      => [ param('privs') ]  };
  
  # Yuck, there has to be a better way
  my $count = 0;
  my $result;
  foreach my $id (@{$params->{id}}) {
    my @vals;
    foreach (@fields) {
      push (@vals,$_ . "=" . $dbh->quote($params->{$_}[$count]));
    }

    $result = $dbh->do("update users set "
			  . join(",",@vals)
			  . " where user_id=$id");
    $count++;
  } 
  # This is kind of bogus - only looks at the last record updated.
  if ($result) {
    print div({-class=>'success'},"The users have been succesfully updated.");
  } else {
    $self->print_sql_error($dbh->errstr);
  }
}


sub user_summary {
  my $self = shift;
  $self->print_navigation($self->build_nav_link(-class=>'admin',-action=>'display_user_options',
						-text=>'User Configuration'),
			  $self->build_nav_link(-class=>'admin',-action=>'user_summary',
						-text=>'View All Users'));
  my $dbh = $self->{dbh};
  my $sth = $dbh->prepare(qq{select * from users ORDER BY last_name});
  $sth->execute();
  
  my @cols = ('First','Last','Email','Username','Status','Joined','Last Login','Songs Played');
  my @keys = ('first_name','last_name','email','username','privs','joined','last_access','songs_played');
  
  my $rows = [];
  while (my $h = $sth->fetchrow_hashref) {
    my @row;
    foreach (@keys) {
      push (@row,$h->{$_});
    }
    push (@$rows,[ @row ]);
  }
  if (@$rows) {
    print div({-class=>'actionbyline'},"Summary Information For All Users");
    print start_div({-class=>'actioncontent'});
    print start_table();
    print TR(td(\@cols));
    foreach (@$rows) {
      print TR(td(\@$_));
    }
    print end_table;
    print end_div;
  } else {
    print div({-class=>'warning'},"There are no users currently in the database");
  }
}


# First parameter is for establishing the navigation
sub delete_all_users {
  my $self = shift;
  $self->delete_all('User Configuration','users');
}

# Generalized delete all

# THIS IS KIND OF SILLY, AND MOSTLY JUST USED FOR DEBUGGING.
# Since ALL PLAYLISTS ARE ATACHED TO USERS
# I MUST NECESSARILY EMPTY OUT THE PLAYLISTS AND PLAYLIST_SONGS TABLES AS WELL
sub delete_all {
  my ($self,$text,$table) = @_;
  my $param = url_param('admin');
  my $action = $links{$param};



( run in 1.199 second using v1.01-cache-2.11-cpan-39bf76dae61 )