📄 addgroupform.pm
字号:
# $Id: AddGroupForm.pm,v 1.6 2006/01/19 22:30:54 martin Exp $## Copyright 2005 Nature Publishing Group# This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## The Bibliotech::Component::AddGroupForm class provides a group add form.package Bibliotech::Component::AddGroupForm;use strict;use base 'Bibliotech::Component';sub last_updated_basis { ('DBI', 'LOGIN')}sub html_content { my ($self, $class, $verbose, $main, $action) = @_; my $bibliotech = $self->bibliotech; my $cgi = $bibliotech->cgi; my ($add, $edit) = (0, 0); if (!$action or $action eq 'add') { $action = 'add'; $add = 1; } elsif ($action eq 'edit') { $edit = 1; } my $user = $self->getlogin; unless ($user) { my $msg; if ($action eq 'add') { $msg = 'to add a group'; } elsif ($action eq 'edit') { $msg = 'to edit a group'; } return $self->saylogin($msg); } my $username = $user->username; # parameter cleaning foreach (qw/name description members/) { my $value = $self->cleanparam($cgi->param($_)); $cgi->param($_ => $value) if $value; } my $validationmsg; my $button = $cgi->param('button'); if ($button =~ /^Add/ or $button =~ /^Save/) { my $name = $cgi->param('name'); my $gang; eval { my $func = $action.'group'; $gang = $bibliotech->$func(user => $user, (map {$_ => $cgi->param($_) || undef} qw/name description private/), members => [grep { $_ && /\S/ } split(/\W+/, $cgi->param('members'))]); }; if ($@) { $validationmsg = $@; } else { die 'Location: '.$bibliotech->location.(defined($gang) && $name ? "group/$name" : 'library')."\n"; } } my $name; my $gang; eval { if ($add) { $cgi->param(members => $username) unless $cgi->param('members'); } else { if ($name = $cgi->param('name')) { if ($gang = new Bibliotech::Gang ($name)) { die "You are not the owner of this group.\n" unless $gang->owner->user_id == $user->user_id; foreach (qw/description private/) { $cgi->param($_ => $gang->$_); } $cgi->param(members => join(', ', sort map($_->username, $gang->users))); } } die "No group.\n" unless $gang; } }; return Bibliotech::Page::HTML_Content->simple($cgi->div({class => 'errormsg'}, $@)) if $@; my $formaction = $bibliotech->location.$action.'group'; my $o = $cgi->start_form(-method => 'POST', -action => $formaction, -name => $action); $o .= $cgi->div({class => 'errormsg'}, $validationmsg) if $validationmsg; $o .= $cgi->start_table; $o .= $cgi->Tr($cgi->td({id => 'namelabelcell', class => 'addfgroupormlabelcell'}, 'Group name:'), $cgi->td({id => 'namedatacell', class => 'addgroupdatacell'}, $add ? $cgi->textfield(-id => 'namebox', -class => 'textctl', -name => 'name', -size => 40) : $name . $cgi->hidden('name'))); $o .= $cgi->Tr($cgi->td({id => 'descriptionlabelcell', class => 'addgroupformlabelcell'}, 'Description:', $cgi->span({class => 'optional'}, '(optional)')), $cgi->td({id => 'descriptiondatacell', class => 'addgroupformdatacell'}, $cgi->textfield(-id => 'descriptionbox', -class => 'textctl', -name => 'description', -size => 70)) ); $o .= $cgi->Tr($cgi->td({id => 'privatelabelcell', class => 'addgroupformlabelcell'}, 'Private:'), $cgi->td({id => 'privatedatacell', class => 'addgroupformdatacell'}, $cgi->checkbox(-id => 'privatebox', -class => 'checkboxctl', -name => 'private', -label => 'Keep this group private; do not display in group list.', -value => 1)) ); $o .= $cgi->Tr($cgi->td({id => 'memberslabelcell', class => 'addgroupformlabelcell'}, 'Member roster:'), $cgi->td({id => 'membersdatacell', class => 'addgroupformdatacell'}, $cgi->textarea(-id => 'membersbox', -class => 'textareactl', -name => 'members', -rows => 4, -columns => 60). $cgi->div({id => 'membershelpbox', class => 'ctlhelp'}, 'Enter the usernames of the members of this group, separated by commas, spaces, or line breaks. Erase all the names to remove the group entirely.')) ); $o .= $cgi->Tr($cgi->td(['', $cgi->submit(-id => 'addbutton', -class => 'buttonctl', -name => 'button', -value => $add ? 'Add' : 'Save')])); $o .= $cgi->end_table; $o .= $cgi->end_form; my $javascript_first_empty = $self->firstempty($cgi, $action, qw/name members/); return new Bibliotech::Page::HTML_Content ({html_parts => {main => $o}, javascript_onload => ($main ? $javascript_first_empty : undef)});}1;__END__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -