--- loncom/interface/loncreateuser.pm 2003/07/20 00:39:01 1.65
+++ loncom/interface/loncreateuser.pm 2004/12/02 21:32:51 1.90
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.65 2003/07/20 00:39:01 www Exp $
+# $Id: loncreateuser.pm,v 1.90 2004/12/02 21:32:51 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,10 +29,41 @@
package Apache::loncreateuser;
+=pod
+
+=head1 NAME
+
+Apache::loncreateuser - handler to create users and custom roles
+
+=head1 SYNOPSIS
+
+Apache::loncreateuser 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 file of the role
+author.
+
+=cut
+
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
use Apache::loncommon;
+use Apache::lonlocal;
my $loginscript; # piece of javascript used in two separate instances
my $generalrule;
@@ -92,14 +123,24 @@ sub print_username_entry_form {
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');
+ my $bodytag =&Apache::loncommon::bodytag('Create Users, Change User Privileges').&Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
my $selscript=&Apache::loncommon::studentbrowser_javascript();
my $sellink=&Apache::loncommon::selectstudent_link
('crtuser','ccuname','ccdomain');
my %existingroles=&my_custom_roles();
my $choice=&Apache::loncommon::select_form('make new role','rolename',
('make new role' => 'Generate new role ...',%existingroles));
+ my %lt=&Apache::lonlocal::texthash(
+ 'siur' => "Set Individual User Roles",
+ 'usr' => "Username",
+ 'dom' => "Domain",
+ 'usrr' => "User Roles",
+ 'ecrp' => "Edit Custom Role Privileges",
+ 'nr' => "Name of Role",
+ 'cre' => "Custom Role Editor"
+ );
+ my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
+ my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
$r->print(<<"ENDDOCUMENT");
@@ -109,19 +150,19 @@ $selscript
$bodytag
-Home Server: $home_server_list
+$lt{'idsn'}
+$lt{'hs'}: $home_server_list
-Login Data
+$lt{'lg'}
$generalrule
$authformkrb
$authformint
@@ -238,11 +429,20 @@ Home Server: $authformloc
ENDNEWUSER
} else { # user already exists
+ my %lt=&Apache::lonlocal::texthash(
+ 'cup' => "Change User Privileges",
+ 'usr' => "User",
+ 'id' => "in domain",
+ 'fn' => "first name",
+ 'mn' => "middle name",
+ 'ln' => "last name",
+ 'gen' => "generation"
+ );
$r->print(<Change User Privileges
+$lt{'cup'}
$forminfo
-User "$ccuname" in domain "$ccdomain"
+$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"
ENDCHANGEUSER
# Get the users information
my %userenv = &Apache::lonnet::get('environment',
@@ -253,7 +453,7 @@ ENDCHANGEUSER
-first name middle name last name generation
+$lt{'fn'} $lt{'mn'} $lt{'ln'} $lt{'gen'}
END
@@ -266,7 +466,7 @@ END
$r->print(''.$userenv{$_}.' ');
}
}
- $r->print(<print(<
END
@@ -274,14 +474,23 @@ END
my ($tmp) = keys(%rolesdump);
unless ($tmp =~ /^(con_lost|error)/i) {
my $now=time;
- $r->print(<
-Revoke Existing Roles
-
-Revoke Delete Role Extent Start End
-END
- foreach my $area (sort keys(%rolesdump)) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'rer' => "Revoke Existing Roles",
+ 'rev' => "Revoke",
+ 'del' => "Delete",
+ 'ren' => "Re-Enable",
+ 'rol' => "Role",
+ 'ext' => "Extent",
+ 'sta' => "Start",
+ 'end' => "End"
+ );
+ my (%roletext,%sortrole,%roleclass,%rolepriv);
+ foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
+ my $b1=join('_',(split('_',$b))[1,0]);
+ return $a1 cmp $b1;
+ } keys(%rolesdump)) {
next if ($area =~ /^rolesdef/);
+ my $envkey=$area;
my $role = $rolesdump{$area};
my $thisrole=$area;
$area =~ s/\_\w\w$//;
@@ -293,18 +502,24 @@ END
my $bgcol='ffffff';
my $allowed=0;
my $delallowed=0;
+ my $sortkey=$role_code;
+ my $class='Unknown';
if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
+ $class='Course';
my ($coursedom,$coursedir) = ($1,$2);
+ $sortkey.="\0$1";
# $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
my %coursedata=
&Apache::lonnet::coursedescription($1.'_'.$2);
my $carea;
if (defined($coursedata{'description'})) {
- $carea='Course: '.$coursedata{'description'}.
- ' Domain: '.$coursedom.(' 'x8).
+ $carea=$coursedata{'description'}.
+ ' '.&mt('Domain').': '.$coursedom.(' 'x8).
&Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
+ $sortkey.="\0".$coursedata{'description'};
} else {
- $carea='Unavailable course: '.$area;
+ $carea=&mt('Unavailable course').': '.$area;
+ $sortkey.="\0".&mt('Unavailable course').': '.$area;
}
$inccourses{$1.'_'.$2}=1;
if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
@@ -328,9 +543,11 @@ END
$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
$carea.=' Section/Group: '.$3;
+ $sortkey.="\0$3";
}
$area=$carea;
} else {
+ $sortkey.="\0".$area;
# Determine if current user is able to revoke privileges
if ($area=~ /^\/(\w+)\//) {
if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
@@ -347,6 +564,13 @@ END
$allowed=1;
}
}
+ if ($role_code eq 'ca' || $role_code eq 'au') {
+ $class='Construction Space';
+ } elsif ($role_code eq 'su') {
+ $class='System';
+ } else {
+ $class='Domain';
+ }
}
if ($role_code eq 'ca') {
$area=~/\/(\w+)\/(\w+)/;
@@ -356,6 +580,7 @@ END
$allowed=0;
}
}
+ $bgcol='77FF77';
my $row = '';
$row.='';
my $active=1;
@@ -366,10 +591,16 @@ END
if ($active) {
$row.=' ';
} else {
- $row.='expired or revoked';
+ $row.=&mt('expired or revoked');
}
}
$row.=' ';
+ if ($allowed && !$active) {
+ $row.= ' ';
+ } else {
+ $row.=' ';
+ }
+ $row.=' ';
if ($delallowed) {
$row.= ' ';
} else {
@@ -389,9 +620,43 @@ END
' '.($role_end_time ?localtime($role_end_time)
: ' ' )
." \n";
- $r->print($row);
+ $sortrole{$sortkey}=$envkey;
+ $roletext{$envkey}=$row;
+ $roleclass{$envkey}=$class;
+ $rolepriv{$envkey}=$allowed;
+ #$r->print($row);
} # end of foreach (table building loop)
- $r->print('
');
+ my $rolesdisplay = 0;
+ my %output = ();
+ foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
+ $output{$type} = '';
+ foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
+ if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
+ $output{$type}.=$roletext{$sortrole{$which}};
+ }
+ }
+ unless($output{$type} eq '') {
+ $output{$type} = "".
+ "".&mt($type)." ".
+ $output{$type};
+ $rolesdisplay = 1;
+ }
+ }
+ if ($rolesdisplay == 1) {
+ $r->print(<
+$lt{'rer'}
+
+$lt{'rev'} $lt{'ren'} $lt{'del'} $lt{'rol'} $lt{'e
+xt'} $lt{'sta'} $lt{'end'}
+END
+ foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
+ if ($output{$type}) {
+ $r->print($output{$type}."\n");
+ }
+ }
+ $r->print('
');
+ }
} # End of unless
my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
if ($currentauth=~/^krb(4|5):/) {
@@ -409,15 +674,20 @@ END
$currentauth=~/^localauth:/
) { # bad authentication scheme
if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'err' => "ERROR",
+ 'uuas' => "This user has an unrecognized authentication scheme",
+ 'sldb' => "Please specify login data below",
+ 'ld' => "Login Data"
+ );
$r->print(<
-ERROR:
-This user has an unrecognized authentication scheme ($currentauth).
-Please specify login data below.
-Login Data
+$lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'sldb'}.
+$lt{'ld'}
$generalrule
$authformkrb
$authformint
@@ -427,14 +697,18 @@ ENDBADAUTH
} else {
# This user is not allowed to modify the users
# authentication scheme, so just notify them of the problem
+ my %lt=&Apache::lonlocal::texthash(
+ 'err' => "ERROR",
+ 'uuas' => "This user has an unrecognized authentication scheme",
+ 'adcs' => "Please alert a domain coordinator of this situation"
+ );
$r->print(<
- ERROR:
-This user has an unrecognized authentication scheme ($currentauth).
-Please alert a domain coordinator of this situation.
+ $lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'adcs'}.
ENDBADAUTH
}
@@ -464,22 +738,26 @@ ENDBADAUTH
$authformcurrent.=' (will override current values) ';
if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
# Current user has login modification privileges
+ my %lt=&Apache::lonlocal::texthash(
+ 'ccld' => "Change Current Login Data",
+ 'enld' => "Enter New Login Data"
+ );
$r->print(<
-Change Current Login Data
+$lt{'ccld'}
$generalrule
$authformnop
$authformcurrent
-Enter New Login Data
+$lt{'enld'}
$authform_other
ENDOTHERAUTHS
}
} ## End of "check for bad authentication type" logic
} ## End of new user/old user logic
- $r->print('Add Roles ');
+ $r->print(''.&mt('Add Roles').' ');
#
# Co-Author
#
@@ -488,20 +766,31 @@ ENDOTHERAUTHS
# No sense in assigning co-author role to yourself
my $cuname=$ENV{'user.name'};
my $cudom=$ENV{'request.role.domain'};
+ my %lt=&Apache::lonlocal::texthash(
+ 'cs' => "Construction Space",
+ 'act' => "Activate",
+ 'rol' => "Role",
+ 'ext' => "Extent",
+ 'sta' => "Start",
+ 'end' => "End",
+ 'cau' => "Co-Author",
+ 'ssd' => "Set Start Date",
+ 'sed' => "Set End Date"
+ );
$r->print(<Construction Space
-Activate Role Extent
-Start End
+$lt{'cs'}
+$lt{'act'} $lt{'rol'} $lt{'ext'}
+$lt{'sta'} $lt{'end'}
-
-Co-Author
+
+$lt{'cau'}
$cudom\_$cuname
-
+
Set Start Date
-
+"javascript:pjump('date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'ssd'}
+
Set End Date
+"javascript:pjump('date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'sed'}
ENDCOAUTH
@@ -509,36 +798,53 @@ ENDCOAUTH
#
# Domain level
#
- $r->print('Domain Level '.
- 'Activate Role Extent '.
- 'Start End ');
+ my $num_domain_level = 0;
+ my $domaintext =
+ ''.&mt('Domain Level').' '.
+ ''.&mt('Activate').' '.&mt('Role').' '.&mt('Extent').' '.
+ ''.&mt('Start').' '.&mt('End').' ';
foreach ( sort( keys(%incdomains))) {
my $thisdomain=$_;
- foreach ('dc','li','dg','au') {
+ foreach ('dc','li','dg','au','sc') {
if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
my $plrole=&Apache::lonnet::plaintext($_);
- $r->print(< "Set Start Date",
+ 'sed' => "Set End Date"
+ );
+ $num_domain_level ++;
+ $domaintext .= <<"ENDDROW";
$plrole
$thisdomain
Set Start Date
+"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}
Set End Date
+"javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}
ENDDROW
}
}
}
- $r->print('
');
+ $domaintext.='
';
+ if ($num_domain_level > 0) {
+ $r->print($domaintext);
+ }
#
# Course level
#
- $r->print(&course_level_table(%inccourses));
- $r->print(" \n");
+ my $num_sections;
+
+ if ($ENV{'request.role'} =~ m-^dc\./(\w+)/$-) {
+ $r->print(&course_level_dc($1));
+ $r->print(' '."\n");
+ } else {
+ $r->print(&course_level_table(%inccourses));
+ $r->print(' '."\n");
+ }
$r->print("