--- loncom/interface/loncreateuser.pm 2009/10/26 15:54:34 1.317 +++ loncom/interface/loncreateuser.pm 2009/10/30 03:51:15 1.318 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.317 2009/10/26 15:54:34 bisitz Exp $ +# $Id: loncreateuser.pm,v 1.318 2009/10/30 03:51:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -468,7 +468,7 @@ sub courserequest_display { # =================================================================== Phase one sub print_username_entry_form { - my ($r,$context,$response,$srch,$forcenewuser) = @_; + my ($r,$context,$response,$srch,$forcenewuser,$crstype) = @_; my $defdom=$env{'request.role.domain'}; my $formtoset = 'crtuser'; if (exists($env{'form.startrolename'})) { @@ -490,7 +490,7 @@ sub print_username_entry_form { my %loaditems = ( 'onload' => "javascript:setFormElements(document.$formtoset)", ); - my %breadcrumb_text = &singleuser_breadcrumb(); + my %breadcrumb_text = &singleuser_breadcrumb($crstype); my $start_page = &Apache::loncommon::start_page('User Management', $jscript,{'add_entries' => \%loaditems,}); @@ -517,6 +517,7 @@ sub print_username_entry_form { ('make new role' => 'Generate new role ...',%existingroles)); my %lt=&Apache::lonlocal::texthash( 'srst' => 'Search for a user and enroll as a student', + 'srme' => 'Search for a user and enroll as a member', 'srad' => 'Search for a user and modify/add user information or roles', 'usr' => "Username", 'dom' => "Domain", @@ -540,20 +541,24 @@ ENDCUSTOM } else { my $actiontext = $lt{'srad'}; if ($env{'form.action'} eq 'singlestudent') { - $actiontext = $lt{'srst'}; + if ($crstype eq 'Community') { + $actiontext = $lt{'srme'}; + } else { + $actiontext = $lt{'srst'}; + } } $r->print("

$actiontext

"); if ($env{'form.origform'} ne 'crtusername') { $r->print("\n".$response); } - $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response)); + $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype)); } $r->print(&Apache::loncommon::end_page()); } sub entry_form { - my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_; + my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_; my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); my ($usertype,$inexact); if (ref($srch) eq 'HASH') { @@ -593,6 +598,7 @@ ENDBLOCK my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain'); my %lt=&Apache::lonlocal::texthash( 'enro' => 'Enroll one student', + 'enrm' => 'Enroll one member', 'admo' => 'Add/modify a single user', 'crea' => 'create new user if required', 'uskn' => "username is known", @@ -604,8 +610,12 @@ ENDBLOCK ); my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain'); my ($title,$buttontext,$showresponse); - if ($env{'form.action'} eq 'singlestudent') { - $title = $lt{'enro'}; + if ($env{'form.action'} eq 'singlestudent') { + if ($crstype eq 'Community') { + $title = $lt{'enrm'}; + } else { + $title = $lt{'enro'}; + } $buttontext = $lt{'enrl'}; } else { $title = $lt{'admo'}; @@ -676,7 +686,7 @@ END # =================================================================== Phase two sub print_user_selection_page { - my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements) = @_; + my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype) = @_; my @fields = ('username','domain','lastname','firstname','permanentemail'); my $sortby = $env{'form.sortby'}; @@ -704,8 +714,10 @@ ENDSCRIPT my %lt=&Apache::lonlocal::texthash( 'usrch' => "User Search to add/modify roles", 'stusrch' => "User Search to enroll student", + 'memsrch' => "User Search to enroll member", 'usel' => "Select a user to add/modify roles", - 'stusel' => "Select a user to enroll as a student", + 'stusel' => "Select a user to enroll as a student", + 'memsel' => "Select a user to enroll as a member", 'username' => "username", 'domain' => "domain", 'lastname' => "last name", @@ -717,7 +729,7 @@ ENDSCRIPT } else { $r->print(&Apache::loncommon::start_page('User Management',$jscript)); - my %breadcrumb_text = &singleuser_breadcrumb(); + my %breadcrumb_text = &singleuser_breadcrumb($crstype); &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:backPage(document.usersrchform,'','')", text=>$breadcrumb_text{'search'}, @@ -729,14 +741,26 @@ ENDSCRIPT $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', 'Course_Change_Privileges')); $r->print("$lt{'usrch'}
"); - $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context)); + $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype)); $r->print('

'.$lt{'usel'}.'

'); } elsif ($env{'form.action'} eq 'singlestudent') { $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', 'Course_Add_Student')); - $r->print($jscript."$lt{'stusrch'}
"); - $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context)); - $r->print('

'.$lt{'stusel'}.'

'); + $r->print($jscript.""); + if ($crstype eq 'Community') { + $r->print($lt{'memsrch'}); + } else { + $r->print($lt{'stusrch'}); + } + $r->print("
"); + $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype)); + $r->print('

'); + if ($crstype eq 'Community') { + $r->print($lt{'memsel'}); + } else { + $r->print($lt{'stusel'}); + } + $r->print('

'); } } $r->print('
'. @@ -811,11 +835,11 @@ sub print_user_query_page { } sub print_user_modification_page { - my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission) = @_; + my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype) = @_; if (($ccuname eq '') || ($ccdomain eq '')) { my $usermsg = &mt('No username and/or domain provided.'); $env{'form.phase'} = ''; - &print_username_entry_form($r,$context,$usermsg); + &print_username_entry_form($r,$context,$usermsg,'','',$crstype); return; } my ($form,$formname); @@ -856,7 +880,7 @@ sub print_user_modification_page { ,'','') .'


'; $env{'form.phase'} = ''; - &print_username_entry_form($r,$context,$response); + &print_username_entry_form($r,$context,$response,undef,undef,$crstype); return; } $newuser = 1; @@ -880,7 +904,7 @@ sub print_user_modification_page { 'username'); } $env{'form.phase'} = ''; - &print_username_entry_form($r,$context,$userchkmsg); + &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype); return; } } @@ -907,7 +931,7 @@ sub print_user_modification_page { } my $start_page = &Apache::loncommon::start_page('User Management',$js,$args); - my %breadcrumb_text = &singleuser_breadcrumb(); + my %breadcrumb_text = &singleuser_breadcrumb($crstype); &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:backPage($form)", text=>$breadcrumb_text{'search'}, @@ -956,6 +980,7 @@ ENDFORMINFO my %lt=&Apache::lonlocal::texthash( 'cnu' => 'Create New User', 'ast' => 'as a student', + 'ame' => 'as a member', 'ind' => 'in domain', 'lg' => 'Login Data', 'hs' => "Home Server", @@ -974,7 +999,11 @@ $loginscript

$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain ENDTITLE if ($env{'form.action'} eq 'singlestudent') { - $r->print(' ('.$lt{'ast'}.')'); + if ($crstype eq 'Community') { + $r->print(' ('.$lt{'ame'}.')'); + } else { + $r->print(' ('.$lt{'ast'}.')'); + } } $r->print('

'."\n".'
'); my $personal_table = @@ -993,7 +1022,7 @@ $lt{'hs'}: $home_server_pick $r->print($home_server_pick); } if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { - $r->print('

'.&mt('User Can Request Creation of Courses in this Domain?').'

'. + $r->print('

'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'

'. &Apache::loncommon::start_data_table(). &build_tools_display($ccuname,$ccdomain, 'requestcourses'). @@ -1067,6 +1096,7 @@ ENDAUTH my %lt=&Apache::lonlocal::texthash( 'cup' => "Modify existing user: ", 'ens' => "Enroll one student: ", + 'enm' => "Enroll one member: ", 'id' => "in domain", ); $r->print(< ENDCHANGEUSER if ($env{'form.action'} eq 'singlestudent') { - $r->print($lt{'ens'}); + if ($crstype eq 'Community') { + $r->print($lt{'enm'}); + } else { + $r->print($lt{'ens'}); + } } else { $r->print($lt{'cup'}); } @@ -1090,7 +1124,7 @@ ENDCHANGEUSER $r->print(&Apache::lonuserutils::forceid_change($context)); } if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { - $r->print('

'.&mt('User Can Request Creation of Courses in this Domain?').'

'. + $r->print('

'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'

'. &Apache::loncommon::start_data_table()); if ($env{'request.role.domain'} eq $ccdomain) { $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses')); @@ -1174,7 +1208,13 @@ ENDNOTOOLSPRIV } ## End of new user/old user logic if ($env{'form.action'} eq 'singlestudent') { - $r->print('
'."\n"); + my $btntxt; + if ($crstype eq 'Community') { + $btntxt = &mt('Enroll Member'); + } else { + $btntxt = &mt('Enroll Student'); + } + $r->print('
'."\n"); } else { $r->print('

'.&mt('Add Roles').'

'); my $addrolesdisplay = 0; @@ -1213,9 +1253,14 @@ ENDNOTOOLSPRIV } sub singleuser_breadcrumb { + my ($crstype) = @_; my %breadcrumb_text; if ($env{'form.action'} eq 'singlestudent') { - $breadcrumb_text{'search'} = 'Enroll a student'; + if ($crstype eq 'Community') { + $breadcrumb_text{'search'} = 'Enroll a member'; + } else { + $breadcrumb_text{'search'} = 'Enroll a student'; + } $breadcrumb_text{'userpicked'} = 'Select a user', $breadcrumb_text{'modify'} = 'Set section/dates', } else { @@ -1443,7 +1488,7 @@ sub display_existing_roles { } # end of foreach (table building loop) my $rolesdisplay = 0; my %output = (); - foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') { + foreach my $type ('Construction Space','Course','Community','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}}) ) { @@ -1463,7 +1508,8 @@ sub display_existing_roles { if ($rolesdisplay == 1) { my $contextrole=''; if ($env{'request.course.id'}) { - $contextrole = 'Existing Roles in this Course'; + my $crstype = &Apache::loncommon::course_type(); + $contextrole = "Existing Roles in this $crstype"; } elsif ($env{'request.role'} =~ /^au\./) { $contextrole = 'Existing Co-Author Roles in your Construction Space'; } else { @@ -1478,7 +1524,7 @@ sub display_existing_roles { ''.$lt{'rol'}.''.$lt{'ext'}. ''.$lt{'sta'}.''.$lt{'end'}.''. &Apache::loncommon::end_data_table_header_row()); - foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') { + foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') { if ($output{$type}) { $r->print($output{$type}."\n"); } @@ -1973,7 +2019,7 @@ sub get_inststatuses { # ================================================================= Phase Three sub update_user_data { - my ($r,$context) = @_; + my ($r,$context,$crstype) = @_; my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); # Error messages @@ -1997,7 +2043,7 @@ sub update_user_data { $jsback."\n". '// ]]>'."\n". ''."\n"; - my %breadcrumb_text = &singleuser_breadcrumb(); + my %breadcrumb_text = &singleuser_breadcrumb($crstype); my $args; if ($env{'form.popup'}) { $args->{'no_nav_bar'} = 1; @@ -2229,9 +2275,10 @@ sub update_user_data { } } ## - my (@userroles,%userupdate,$cnum,$cdom,$namechanged); + my (@userroles,%userupdate,$cnum,$cdom,$crstype,$namechanged); if ($context eq 'course') { ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity(); + $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum); } if (! $env{'form.makeuser'} ) { # Check for need to change @@ -2315,7 +2362,7 @@ sub update_user_data { if ($role eq 'cr') { push(@longroles,'Custom'); } else { - push(@longroles,&Apache::lonnet::plaintext($role)); + push(@longroles,&Apache::lonnet::plaintext($role,$crstype)); } } my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id'); @@ -2784,9 +2831,14 @@ END .''); } if ($env{'form.action'} eq 'singlestudent') { - &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context); - $r->print('

'. - &mt('Enroll Another Student').'

'); + &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype); + $r->print('

'); + if ($crstype eq 'Community') { + $r->print(&mt('Enroll Another Member')); + } else { + $r->print(&mt('Enroll Another Student')); + } + $r->print('

'); } else { my @rolechanges = &update_roles($r,$context); if ($namechanged) { @@ -3255,8 +3307,14 @@ sub update_roles { } sub enroll_single_student { - my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_; - $r->print('

'.&mt('Enrolling Student').'

'); + my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype) = @_; + $r->print('

'); + if ($crstype eq 'Community') { + $r->print(&mt('Enrolling Member')); + } else { + $r->print(&mt('Enrolling Student')); + } + $r->print('

'); # Remove non alphanumeric values from section $env{'form.sections'}=~s/\W//g; @@ -3289,7 +3347,13 @@ sub enroll_single_student { } $r->print('.
'.$showstart.'; '.$showend); if ($startdate <= $now && !$newuser) { - $r->print("

".&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')."

"); + $r->print('

'); + if ($crstype eq 'Community') { + $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.')); + } else { + $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')); + } + $r->print('

'); } } else { $r->print(&mt('unable to enroll').": ".$enroll_result); @@ -3484,10 +3548,19 @@ sub custom_role_editor { my $head_script = "\n"; $head_script .= '