--- loncom/interface/loncreateuser.pm 2003/04/30 15:49:45 1.52 +++ loncom/interface/loncreateuser.pm 2003/07/18 13:45:14 1.60 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.52 2003/04/30 15:49:45 matthew Exp $ +# $Id: loncreateuser.pm,v 1.60 2003/07/18 13:45:14 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,7 +46,7 @@ # 05/10,10/16 Gerd Kortemeyer # 02/11/02 Matthew Hall # -# $Id: loncreateuser.pm,v 1.52 2003/04/30 15:49:45 matthew Exp $ +# $Id: loncreateuser.pm,v 1.60 2003/07/18 13:45:14 www Exp $ ### package Apache::loncreateuser; @@ -54,6 +54,7 @@ package Apache::loncreateuser; use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; +use Apache::loncommon; my $loginscript; # piece of javascript used in two separate instances my $generalrule; @@ -82,6 +83,18 @@ BEGIN { } +# ======================================================= Existing Custom Roles + +sub my_custom_roles { + my %returnhash=(); + my %rolehash=&Apache::lonnet::dump('roles'); + foreach (keys %rolehash) { + if ($_=~/^rolesdef\_(\w+)$/) { + $returnhash{$_}=$_; + } + } + return %returnhash; +} # ==================================================== Figure out author access @@ -106,6 +119,9 @@ sub print_username_entry_form { 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)); $r->print(<<"ENDDOCUMENT"); @@ -115,15 +131,19 @@ $selscript $bodytag
-

+

Set Individual User Roles

-
Username: $sellink
Domain:$domform
-

- + +
+
+ +

Edit Custom Role Privileges

+Name of Role: $choice
+ ENDDOCUMENT @@ -135,6 +155,14 @@ sub print_user_modification_page { my $ccuname=$ENV{'form.ccuname'}; my $ccdomain=$ENV{'form.ccdomain'}; + $ccuname=~s/\W//gs; + $ccdomain=~s/\W//gs; + + unless (($ccuname) && ($ccdomain)) { + &print_username_entry_form($r); + return; + } + my $defdom=$ENV{'request.role.domain'}; my ($krbdef,$krbdefdom) = @@ -236,7 +264,7 @@ ENDNEWUSER $dochead

Change User Privileges

$forminfo -

User "$ccuname" in domain $ccdomain

+

User "$ccuname" in domain "$ccdomain"

ENDCHANGEUSER # Get the users information my %userenv = &Apache::lonnet::get('environment', @@ -254,7 +282,7 @@ END foreach ('firstname','middlename','lastname','generation') { if (&Apache::lonnet::allowed('mau',$ccdomain)) { $r->print(<<"END"); - + END } else { $r->print(''.$userenv{$_}.''); @@ -272,7 +300,7 @@ END

Revoke Existing Roles

- + END foreach my $area (keys(%rolesdump)) { next if ($area =~ /^rolesdef/); @@ -283,19 +311,29 @@ END split(/_/,$role); my $bgcol='ffffff'; my $allowed=0; + my $delallowed=0; if ($area =~ /^\/(\w+)\/(\d\w+)/ ) { + my ($coursedom,$coursedir) = ($1,$2); + # $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'}; + $carea='Course: '.$coursedata{'description'}. + '
Domain: '.$coursedom.(' 'x8). + &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom); } else { $carea='Unavailable course: '.$area; } $inccourses{$1.'_'.$2}=1; - if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) { + if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) || + (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) { $allowed=1; } + if ((&Apache::lonnet::allowed('dro',$1)) || + (&Apache::lonnet::allowed('dro',$ccdomain))) { + $delallowed=1; + } # Compute the background color based on $area $bgcol=$1.'_'.$2; $bgcol=~s/[^8-9b-e]//g; @@ -307,9 +345,15 @@ END } else { # Determine if current user is able to revoke privileges if ($area=~ /^\/(\w+)\//) { - if (&Apache::lonnet::allowed('c'.$role_code,$1)) { + if ((&Apache::lonnet::allowed('c'.$role_code,$1)) || + (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) { $allowed=1; } + if (((&Apache::lonnet::allowed('dro',$1)) || + (&Apache::lonnet::allowed('dro',$ccdomain))) && + ($role_code ne 'dc')) { + $delallowed=1; + } } else { if (&Apache::lonnet::allowed('c'.$role_code,'/')) { $allowed=1; @@ -331,6 +375,16 @@ END if (($active) && ($allowed)) { $row.= ''; } else { + if ($active) { + $row.=' '; + } else { + $row.='expired or revoked'; + } + } + $row.=' - - - - - -
RevokeRoleExtentStartEnd
RevokeDeleteRoleExtentStartEnd'; + if ($delallowed) { + $row.= ''; + } else { $row.=' '; } $row.= ''.&Apache::lonnet::plaintext($role_code). @@ -412,16 +466,7 @@ ENDBADAUTH $authform_other="

$authformkrb

". "

$authformint

$authformfsys

"; } - $authformcurrent=< -
* * * WARNING * * ** * * WARNING * * *
$authformcurrentChanging this value will overwrite existing authentication for the user; you should notify the user of this change.
-ENDCURRENTAUTH + $authformcurrent.=' (will override current values)
'; if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) { # Current user has login modification privileges $r->print(<print('Revoking '.$2.' in '.$1.': '. + $r->print('Revoking '.$2.' in '.$1.': '. + &Apache::lonnet::assignrole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2,$now).'
'); + if ($2 eq 'st') { + $1=~/^\/(\w+)\/(\w+)/; + my $cid=$1.'_'.$2; + $r->print('Drop from classlist: '. + &Apache::lonnet::critical('put:'. + $ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}.':classlist:'. + &Apache::lonnet::escape($ENV{'form.ccuname'}.':'. + $ENV{'form.ccdomain'}).'='. + &Apache::lonnet::escape($now.':'), + $ENV{'course.'.$cid.'.home'}).'
'); + } + } + } elsif ($_=~/^form\.del/) { + if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) { + $r->print('Deleting '.$2.' in '.$1.': '. &Apache::lonnet::assignrole($ENV{'form.ccdomain'}, - $ENV{'form.ccuname'},$1,$2,$now).'
'); + $ENV{'form.ccuname'},$1,$2,$now,0,1).'
'); if ($2 eq 'st') { $1=~/^\/(\w+)\/(\w+)/; my $cid=$1.'_'.$2; - $r->print('Drop from classlist: '. + $r->print('Drop from classlist: '. &Apache::lonnet::critical('put:'. $ENV{'course.'.$cid.'.domain'}.':'. $ENV{'course.'.$cid.'.num'}.':classlist:'. &Apache::lonnet::escape($ENV{'form.ccuname'}.':'. $ENV{'form.ccdomain'}).'='. &Apache::lonnet::escape($now.':'), - $ENV{'course.'.$cid.'.home'}).'
'); + $ENV{'course.'.$cid.'.home'}).'

'); } } } elsif ($_=~/^form\.act/) { if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with 3 id numbers # set start, end times, and the url for the class - my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? - $ENV{'form.start_'.$1.'_'.$2} : + + my $start = ( $ENV{'form.start_'.$1.'_'.$2.'_'.$3} ? + $ENV{'form.start_'.$1.'_'.$2.'_'.$3} : $now ); - my $end = ( $ENV{'form.end_'.$1.'_'.$2} ? - $ENV{'form.end_'.$1.'_'.$2} : + my $end = ( $ENV{'form.end_'.$1.'_'.$2.'_'.$3} ? + $ENV{'form.end_'.$1.'_'.$2.'_'.$3} : 0 ); my $url='/'.$1.'/'.$2; if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) { $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( $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $url,$3,$end,$start). - '
'); + '

'); # Handle students differently if ($3 eq 'st') { $url=~/^\/(\w+)\/(\w+)/; my $cid=$1.'_'.$2; - $r->print('Add to classlist: '. + $r->print('Add to classlist: '. &Apache::lonnet::critical( 'put:'.$ENV{'course.'.$cid.'.domain'}.':'. $ENV{'course.'.$cid.'.num'}.':classlist:'. @@ -762,7 +828,7 @@ END $ENV{'form.ccdomain'} ).'='. &Apache::lonnet::escape($end.':'.$start), $ENV{'course.'.$cid.'.home'}) - .'
'); + .'

'); } } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with two id numbers @@ -776,16 +842,72 @@ END my $url='/'.$1.'/'; # Assign the role and report it. $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) - .'
'); + .'

'); } } } # End of foreach (keys(%ENV)) $r->print(''); } +# ========================================================== Custom Role Editor + +sub custom_role_editor { + my $r=shift; + my $rolename=$ENV{'form.rolename'}; + + if ($rolename eq 'make new role') { + $rolename=$ENV{'form.newrolename'}; + } + + $rolename=~s/\W//gs; + + unless ($rolename) { + &print_username_entry_form($r); + return; + } + + $r->print(&Apache::loncommon::bodytag( + 'Create Users, Change User Privileges').'

'); + my ($rdummy,$roledef)= + &Apache::lonnet::get('roles',["rolesdef_$rolename"]); +# ------------------------------------------------------- Does this role exist? + if (($rdummy ne 'con_lost') && ($roledef ne '')) { + $r->print('Existing Role "'); + } else { + $r->print('New Role "'); + $roledef=''; + } + $r->print($rolename.'"

'); +# ------------------------------------------------------- What can be assigned? + my %full=(); + my %courselevel=(); + foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { + my ($priv,$restrict)=split(/\&/,$_); + unless ($restrict) { $restrict='F'; } + $courselevel{$priv}=$restrict; + $full{$priv}=1; + } + my %domainlevel=(); + foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { + my ($priv,$restrict)=split(/\&/,$_); + unless ($restrict) { $restrict='F'; } + $domainlevel{$priv}=$restrict; + $full{$priv}=1; + } + $r->print(''); + foreach (sort keys %full) { + $r->print(''); + } + $r->print('
PrivilegeCourse LevelDomain Level
'.&Apache::lonnet::plaintext($_).''. + $courselevel{$_}.''.$domainlevel{$_}.'
'); + $r->print('Not yet implemented.'); +} + # ================================================================ Main Handler sub handler { my $r = shift; @@ -811,6 +933,8 @@ sub handler { &print_user_modification_page($r); } elsif ($ENV{'form.phase'} eq 'update_user_data') { &update_user_data($r); + } elsif ($ENV{'form.phase'} eq 'selected_custom_edit') { + &custom_role_editor($r); } } else { $ENV{'user.error.msg'}=