--- loncom/interface/loncreateuser.pm 2003/03/23 09:06:08 1.51
+++ loncom/interface/loncreateuser.pm 2007/08/31 12:33:32 1.181
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.51 2003/03/23 09:06:08 albertel Exp $
+# $Id: loncreateuser.pm,v 1.181 2007/08/31 12:33:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,35 +25,47 @@
#
# 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
-# 02/11/02 Matthew Hall
-#
-# $Id: loncreateuser.pm,v 1.51 2003/03/23 09:06:08 albertel Exp $
###
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;
+use Apache::longroup;
+use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
my $generalrule;
@@ -63,10 +75,9 @@ my $authformint;
my $authformfsys;
my $authformloc;
-BEGIN {
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
+sub initialize_authen_forms {
+ my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
+ $krbdefdom= uc($krbdefdom);
my %param = ( formname => 'document.cu',
kerb_def_dom => $krbdefdom
);
@@ -82,60 +93,341 @@ BEGIN {
}
+# ======================================================= Existing Custom Roles
+
+sub my_custom_roles {
+ my %returnhash=();
+ my %rolehash=&Apache::lonnet::dump('roles');
+ foreach my $key (keys %rolehash) {
+ if ($key=~/^rolesdef\_(\w+)$/) {
+ $returnhash{$1}=$1;
+ }
+ }
+ return %returnhash;
+}
# ==================================================== Figure out author access
sub authorpriv {
my ($auname,$audom)=@_;
- if (($auname ne $ENV{'user.name'}) ||
- (($audom ne $ENV{'user.domain'}) &&
- ($audom ne $ENV{'request.role.domain'}))) { return ''; }
- unless (&Apache::lonnet::allowed('cca',$audom)) { return ''; }
+ unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
+ || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
return 1;
}
+# ====================================================
+
+sub portfolio_quota {
+ my ($ccuname,$ccdomain) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ 'disk' => "Disk space allocated to user's portfolio files",
+ 'cuqu' => "Current quota",
+ 'cust' => "Custom quota",
+ 'defa' => "Default",
+ 'chqu' => "Change quota",
+ );
+ my ($currquota,$quotatype,$inststatus,$defquota) =
+ &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
+ my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
+ my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
+ if ($inststatus ne '') {
+ if ($usertypes->{$inststatus} ne '') {
+ $longinsttype = $usertypes->{$inststatus};
+ }
+ }
+ $custom_on = ' ';
+ $custom_off = ' checked="checked" ';
+ my $quota_javascript = <<"END_SCRIPT";
+
+END_SCRIPT
+ if ($quotatype eq 'custom') {
+ $custom_on = $custom_off;
+ $custom_off = ' ';
+ $showquota = $currquota;
+ if ($longinsttype eq '') {
+ $defaultinfo = &mt('For this user, the default quota would be [_1]
+ Mb.',$defquota);
+ } else {
+ $defaultinfo = &mt("For this user, the default quota would be [_1]
+ Mb, as determined by the user's institutional
+ affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ } else {
+ if ($longinsttype eq '') {
+ $defaultinfo = &mt('For this user, the default quota is [_1]
+ Mb.',$defquota);
+ } else {
+ $defaultinfo = &mt("For this user, the default quota of [_1]
+ Mb, is determined by the user's institutional
+ affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ }
+ my $output = $quota_javascript.
+ ''.$lt{'disk'}.'
'.
+ $lt{'cuqu'}.': '.$currquota.' Mb. '.
+ $defaultinfo.'
'.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' Mb';
+ 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');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
- my $sellink=&Apache::loncommon::selectstudent_link
- ('crtuser','ccuname','ccdomain');
- $r->print(<<"ENDDOCUMENT");
-
-
-The LearningOnline Network with CAPA
-$selscript
-
-$bodytag
+ my ($r,$response,$srch,$forcenewuser) = @_;
+ my $defdom=$env{'request.role.domain'};
+ my $formtoset = 'crtuser';
+ if (exists($env{'form.startrolename'})) {
+ $formtoset = 'docustom';
+ $env{'form.rolename'} = $env{'form.startrolename'};
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
+
+ my %loaditems = (
+ 'onload' => "javascript:setFormElements(document.$formtoset)",
+ );
+ my $start_page =
+ &Apache::loncommon::start_page('Create Users, Change User Privileges',
+ $jscript,{'add_entries' => \%loaditems,});
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"User modify/custom role edit",
+ faq=>282,bug=>'Instructor Interface',});
+
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
+ 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(
+ 'srch' => "User Search",
+ or => "or",
+ 'siur' => "Set Individual User Roles",
+ 'usr' => "Username",
+ 'dom' => "Domain",
+ 'ecrp' => "Edit Custom Role Privileges",
+ 'nr' => "Name of Role",
+ 'cre' => "Custom Role Editor",
+ 'mod' => "to add/modify roles",
+ );
+ my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
+ my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
+ my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
+ my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain');
+ if ($sellink) {
+ $sellink = "$lt{'or'} ".$sellink;
+ }
+ $r->print("
+$start_page
+$crumbs
+$lt{siur}$helpsiur
+$lt{'srch'} $sellink $lt{'mod'}
+$response");
+ $r->print(&entry_form($defdom,$srch,$forcenewuser));
+ if (&Apache::lonnet::allowed('mcr','/')) {
+ $r->print(<
+
+$lt{'ecrp'}$helpecpr
+$lt{'nr'}: $choice
+
+
+ENDCUSTOM
+ }
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub entry_form {
+ my ($dom,$srch,$forcenewuser) = @_;
+ my $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser');
+ my $srchbutton = &mt('Search');
+ my $output = <<"ENDDOCUMENT";
-
+
+$userpicker
+
-
-