--- loncom/interface/loncreateuser.pm 2003/06/20 14:37:26 1.56 +++ 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.56 2003/06/20 14:37:26 www 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.56 2003/06/20 14:37:26 www Exp $ +# $Id: loncreateuser.pm,v 1.60 2003/07/18 13:45:14 www Exp $ ### package Apache::loncreateuser; @@ -83,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 @@ -107,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"); @@ -116,15 +131,19 @@ $selscript $bodytag
-

+

Set Individual User Roles

-
Username: $sellink
Domain:$domform
-

- + +
+
+ +

Edit Custom Role Privileges

+Name of Role: $choice
+ ENDDOCUMENT @@ -136,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) = @@ -237,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', @@ -286,12 +313,15 @@ END 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'}. - '
Domain: '.$1; + '
Domain: '.$coursedom.(' 'x8). + &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom); } else { $carea='Unavailable course: '.$area; } @@ -824,6 +854,60 @@ END $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; @@ -849,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'}=