--- loncom/interface/loncreateuser.pm 2002/11/18 20:06:53 1.44
+++ loncom/interface/loncreateuser.pm 2008/12/08 22:46:28 1.267
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.44 2002/11/18 20:06:53 matthew Exp $
+# $Id: loncreateuser.pm,v 1.267 2008/12/08 22:46:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,127 +25,427 @@
#
# http://www.lon-capa.org/
#
-# (Create a course
-# (My Desk
-#
-# (Internal Server Error Handler
-#
-# (Login Screen
-# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
-# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
-#
-# YEAR=2001
-# 3/1/1 Gerd Kortemeyer)
-#
-# 3/1 Gerd Kortemeyer)
-#
-# 2/14 Gerd Kortemeyer)
-#
-# 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17,3/24,04/12 Gerd Kortemeyer
-# April Guy Albertelli
-# 05/10,10/16 Gerd Kortemeyer
-# 11/12,11/13,11/15 Scott Harrison
-# 02/11/02 Matthew Hall
-#
-# $Id: loncreateuser.pm,v 1.44 2002/11/18 20:06:53 matthew Exp $
###
package Apache::loncreateuser;
+=pod
+
+=head1 NAME
+
+Apache::loncreateuser.pm
+
+=head1 SYNOPSIS
+
+ Handler to create users and custom roles
+
+ Provides an Apache handler for creating users,
+ editing their login parameters, roles, and removing roles, and
+ also creating and assigning custom roles.
+
+=head1 OVERVIEW
+
+=head2 Custom Roles
+
+In LON-CAPA, roles are actually collections of privileges. "Teaching
+Assistant", "Course Coordinator", and other such roles are really just
+collection of privileges that are useful in many circumstances.
+
+Creating custom roles can be done by the Domain Coordinator through
+the Create User functionality. That screen will show all privileges
+that can be assigned to users. For a complete list of privileges,
+please see C.
+
+Custom role definitions are stored in the C'.$lt{'usrt'}.'
'."\n".
+ &Apache::loncommon::start_data_table();
+
+ if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'tools.aboutme','tools.portfolio','tools.blog');
+ my @usertools = ('aboutme','blog','portfolio');
+ foreach my $item (@usertools) {
+ my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off);
+ $cust_off = 'checked="checked" ';
+ $tool_on = 'checked="checked" ';
+ $curr_access = &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item);
+ if ($userenv{'tools.'.$item} eq '') {
+ $custom_access = 'default';
+ if (!$curr_access) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ } else {
+ $custom_access = 'custom';
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ if ($userenv{'tools.'.$item} == 0) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ }
+ $curr_access = &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item);
+ $output .= ' '."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{$item}.' '."\n".
+ ' '.&mt('Availability determined currently from [_1] setting.',$custom_access).
+ ' '.$lt{'avai'}.': '.
+ ($curr_access?&mt('Yes'):&mt('No')).' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'chse'}.': '.
+ ' -- '.
+ $lt{'cusa'}.': '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ }
+ if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ $output .= ''."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'disk'}.' '."\n".
+ ' '.$lt{'cuqu'}.': '.
+ $currquota.' Mb. '.
+ $defaultinfo.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' Mb '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ return $output;
}
# =================================================================== Phase one
sub print_username_entry_form {
- my $r=shift;
- my $defdom=$ENV{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $bodytag =&Apache::loncommon::bodytag(
- 'Create Users, Change User Privileges');
- $r->print(<<"ENDDOCUMENT");
-
-
-$actiontext
");
+ if ($env{'form.origform'} ne 'crtusername') {
+ $r->print("\n".$response);
+ }
+ $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
+ }
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub entry_form {
+ my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my ($usertype,$inexact);
+ if (ref($srch) eq 'HASH') {
+ if (($srch->{'srchin'} eq 'dom') &&
+ ($srch->{'srchby'} eq 'uname') &&
+ ($srch->{'srchtype'} eq 'exact') &&
+ ($srch->{'srchdomain'} ne '') &&
+ ($srch->{'srchterm'} ne '')) {
+ my ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
+ $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
+ } else {
+ $inexact = 1;
+ }
+ }
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
+ my $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser',$cancreate,$usertype);
+ my $srchbutton = &mt('Search');
+ if ($env{'form.action'} eq 'singlestudent') {
+ $srchbutton = &mt('Search and Enroll');
+ } elsif ($cancreate && $responsemsg ne '' && $inexact) {
+ $srchbutton = &mt('Search or Add New User');
+ }
+ my $output = <<"ENDBLOCK";
+
+ENDBLOCK
+ if ($env{'form.phase'} eq '') {
+ my $defdom=$env{'request.role.domain'};
+ my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+ my %lt=&Apache::lonlocal::texthash(
+ 'enro' => 'Enroll one student',
+ 'admo' => 'Add/modify a single user',
+ 'crea' => 'create new user if required',
+ 'uskn' => "username is known",
+ 'crnu' => 'Create a new user',
+ 'usr' => 'Username',
+ 'dom' => 'in domain',
+ 'enrl' => 'Enroll',
+ 'cram' => 'Create/Modify user',
+ );
+ my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
+ my ($title,$buttontext,$showresponse);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $title = $lt{'enro'};
+ $buttontext = $lt{'enrl'};
+ } else {
+ $title = $lt{'admo'};
+ $buttontext = $lt{'cram'};
+ }
+ if ($cancreate) {
+ $title .= ' ('.$lt{'crea'}.')';
+ } else {
+ $title .= ' ('.$lt{'uskn'}.')';
+ }
+ if ($env{'form.origform'} eq 'crtusername') {
+ $showresponse = $responsemsg;
+ }
+ $output .= <<"ENDDOCUMENT";
+
+