--- loncom/interface/loncreateuser.pm 2003/07/18 20:53:06 1.62 +++ loncom/interface/loncreateuser.pm 2003/12/10 20:38:09 1.72 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.62 2003/07/18 20:53:06 www Exp $ +# $Id: loncreateuser.pm,v 1.72 2003/12/10 20:38:09 sakharuk 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; @@ -100,6 +131,15 @@ sub print_username_entry_form { 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" + ); $r->print(<<"ENDDOCUMENT"); @@ -109,19 +149,19 @@ $selscript $bodytag
-

Set Individual User Roles

+

$lt{siur}

- +$lt{'dom'}:
Username: +
$lt{usr}: $sellink
-Domain:$domform
$domform
- +
-

Edit Custom Role Privileges

-Name of Role: $choice
- +

$lt{'ecrp'}

+$lt{'nr'}: $choice
+ ENDDOCUMENT @@ -206,31 +246,44 @@ ENDFORMINFO ''."\n". &Apache::loncommon::home_server_option_list($ccdomain); + my %lt=&Apache::lonlocal::texthash( + 'cnu' => "Create New User", + 'nu' => "New User", + 'id' => "in domain", + 'pd' => "Personal Data", + 'fn' => "First Name", + 'mn' => "Middle Name", + 'ln' => "Last Name", + 'gen' => "Generation", + 'idsn' => "ID/Student Number", + 'hs' => "Home Server", + 'lg' => "Login Data" + ); $r->print(<Create New User +

$lt{'cnu'}

$forminfo -

New user "$ccuname" in domain $ccdomain

+

$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain

-

Personal Data

+

$lt{'pd'}

- + - + - + - +
First Name
$lt{'fn'}
Middle Name
$lt{'mn'}
Last Name
$lt{'ln'}
Generation
$lt{'gen'}
-ID/Student Number

-Home Server: +$lt{'idsn'}

+${'hs'}:
-

Login Data

+

$lt{'lg'}

$generalrule

$authformkrb

$authformint

@@ -238,11 +291,20 @@ Home Server: -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 @@ -492,14 +594,18 @@ ENDCOAUTH # # Domain level # - $r->print('

Domain Level

'. + $r->print('

'.&mt('Domain Level').'

'. ''. ''); 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($_); + my %lt=&Apache::lonlocal::texthash( + 'ssd' => "Set Start Date", + 'sed' => "Set End Date" + ); $r->print(< @@ -507,10 +613,10 @@ ENDCOAUTH +"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'} +"javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'} ENDDROW } @@ -521,7 +627,7 @@ ENDDROW # Course level # $r->print(&course_level_table(%inccourses)); - $r->print("
\n"); + $r->print("
\n"); $r->print(""); } @@ -607,7 +713,7 @@ ENDTHREEHEAD if ($ENV{'form.makeuser'}) { # Create a new user $r->print(<Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}" +

Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"

ENDNEWUSERHEAD # Check for the authentication mode and password if (! $amode || ! $genpwd) { @@ -636,7 +742,7 @@ ENDNEWUSERHEAD $r->print('Generating user: '.$result); my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'}, $ENV{'form.ccdomain'}); - $r->print('
Home server: '.$home.' '. + $r->print('
Home server: '.$home.' '. $Apache::lonnet::libserv{$home}); } elsif (($ENV{'form.login'} ne 'nochange') && ($ENV{'form.login'} ne '' )) { @@ -735,10 +841,11 @@ END next if (! $ENV{$_}); # Revoke roles if ($_=~/^form\.rev/) { - if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) { + if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) { +# Revoke standard role $r->print('Revoking '.$2.' in '.$1.': '. - &Apache::lonnet::assignrole($ENV{'form.ccdomain'}, - $ENV{'form.ccuname'},$1,$2,$now).'
'); + &Apache::lonnet::revokerole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2).'
'); if ($2 eq 'st') { $1=~/^\/(\w+)\/(\w+)/; my $cid=$1.'_'.$2; @@ -752,6 +859,14 @@ END $ENV{'course.'.$cid.'.home'}).'
'); } } + if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) { +# Revoke custom role + $r->print( + 'Revoking custom role '.$4.' by '.$3.'@'.$2.' in '.$1.': '. +&Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2,$3,$4). + '
'); + } } elsif ($_=~/^form\.del/) { if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) { $r->print('Deleting '.$2.' in '.$1.': '. @@ -771,7 +886,29 @@ END } } } elsif ($_=~/^form\.act/) { - if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) { + if +($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) { + # Activate a custom role + my $url='/'.$1.'/'.$2; + my $full=$1.'_'.$2.'_cr_cr_'.$3.'_'.$4.'_'.$5; + if ($ENV{'form.sec_'.$full}) { + $url.='/'.$ENV{'form.sec_'.$full}; + } + + my $start = ( $ENV{'form.start_'.$full} ? + $ENV{'form.start_'.$full} : + $now ); + my $end = ( $ENV{'form.end_'.$full} ? + $ENV{'form.end_'.$full} : + 0 ); + + $r->print('Assigning custom role "'.$5.'" by '.$4.'@'.$3.' in '.$url. + ($start?', starting '.localtime($start):''). + ($end?', ending '.localtime($end):'').': '. + &Apache::lonnet::assigncustomrole( + $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$3,$4,$5,$end,$start). + '
'); + } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with 3 id numbers # set start, end times, and the url for the class @@ -786,7 +923,7 @@ END $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3}; } # Assign the role and report it - $r->print('Assigning: '.$3.' in '.$url. + $r->print('Assigning '.$3.' in '.$url. ($start?', starting '.localtime($start):''). ($end?', ending '.localtime($end):'').': '. &Apache::lonnet::assignrole( @@ -819,14 +956,16 @@ END 0 ); my $url='/'.$1.'/'; # Assign the role and report it. - $r->print('Assigning: '.$2.' in '.$url.': '. + $r->print('Assigning '.$2.' in '.$url.': '. ($start?', starting '.localtime($start):''). ($end?', ending '.localtime($end):'').': '. &Apache::lonnet::assignrole( $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $url,$2,$end,$start) .'
'); - } + } else { + $r->print('

ERROR: Unknown command '.$_.'


'); + } } } # End of foreach (keys(%ENV)) $r->print(''); @@ -842,7 +981,7 @@ sub custom_role_editor { $rolename=$ENV{'form.newrolename'}; } - $rolename=~s/\W//gs; + $rolename=~s/[^A-Za-z0-9]//gs; unless ($rolename) { &print_username_entry_form($r); @@ -901,6 +1040,7 @@ sub custom_role_editor { } $full{$priv}=1; } + $r->print(< @@ -931,7 +1071,7 @@ sub set_custom_role { my $rolename=$ENV{'form.rolename'}; - $rolename=~s/\W//gs; + $rolename=~s/[^A-Za-z0-9]//gs; unless ($rolename) { &print_username_entry_form($r); @@ -978,8 +1118,19 @@ sub set_custom_role { $sysrole.=':'.$_; } } - $r->print('Defining Role: '. + $r->print('
Defining Role: '. &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole)); + if ($ENV{'request.course.id'}) { + my $url='/'.$ENV{'request.course.id'}; + $url=~s/\_/\//g; + $r->print('
Assigning Role to Self: '. + &Apache::lonnet::assigncustomrole($ENV{'user.domain'}, + $ENV{'user.name'}, + $url, + $ENV{'user.domain'}, + $ENV{'user.name'}, + $rolename)); + } $r->print(''); } @@ -988,7 +1139,7 @@ sub handler { my $r = shift; if ($r->header_only) { - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK; } @@ -999,7 +1150,7 @@ sub handler { (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) || (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) || (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) { - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; unless ($ENV{'form.phase'}) { &print_username_entry_form($r); @@ -1035,7 +1186,7 @@ sub course_level_table { $thiscourse=~s:_:/:g; my %coursedata=&Apache::lonnet::coursedescription($thiscourse); my $area=$coursedata{'description'}; - if (!defined($area)) { $area='Unavailable course: '.$_; } + if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; } my $bgcol=$thiscourse; $bgcol=~s/[^7-9a-e]//g; $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6); @@ -1069,20 +1220,24 @@ ENDTIMEENTRY } } foreach (sort keys %customroles) { - my $plrole=$_; - $table .= < -
+ - - + - + +"javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">Set End Date ENDENTRY + } } } return '' if ($table eq ''); # return nothing if there is nothing
ActivateRoleExtentStartEnd
$thisdomain Set Start Date Set End Date
$plrole $area + Set Start Date +"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">Set Start Date Set End Date