--- loncom/interface/loncreateuser.pm 2009/10/26 15:54:34 1.317
+++ loncom/interface/loncreateuser.pm 2010/03/21 21:05:42 1.337
@@ -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.337 2010/03/21 21:05:42 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -51,13 +51,14 @@ In LON-CAPA, roles are actually collecti
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 roles can be defined by a Domain Coordinator, Course Coordinator
+or Community Coordinator via the Manage User functionality.
+The custom role editor screen will show all privileges which 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.
+Custom role definitions are stored in the C file of the creator
+of the role.
=cut
@@ -218,7 +219,7 @@ END_SCRIPT
sub build_tools_display {
my ($ccuname,$ccdomain,$context) = @_;
my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
- $colspan);
+ $colspan,$isadv,%domconfig);
my %lt = &Apache::lonlocal::texthash (
'blog' => "Personal User Blog",
'aboutme' => "Personal Information Page",
@@ -242,6 +243,9 @@ sub build_tools_display {
%reqtitles = &courserequest_titles();
%reqdisplay = &courserequest_display();
$colspan = ' colspan="2"';
+ %domconfig =
+ &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
+ $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
} else {
%userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
'tools.aboutme','tools.portfolio','tools.blog');
@@ -288,7 +292,14 @@ sub build_tools_display {
&Apache::loncommon::start_data_table_row()."\n";
if ($context eq 'requestcourses') {
my ($curroption,$currlimit);
- $curroption = $userenv{$context.'.'.$item};
+ if ($userenv{$context.'.'.$item} ne '') {
+ $curroption = $userenv{$context.'.'.$item};
+ } else {
+ my (@inststatuses);
+ $curroption =
+ &Apache::loncoursequeueadmin::get_processtype($ccuname,$ccdomain,$isadv,$ccdomain,
+ $item,\@inststatuses,\%domconfig);
+ }
if (!$curroption) {
$curroption = 'norequest';
}
@@ -468,7 +479,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'})) {
@@ -487,10 +498,15 @@ sub print_username_entry_form {
'// ]]>'."\n".
''."\n";
+ my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
+ if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
+ && (&Apache::lonnet::allowed('mcr','/'))) {
+ $jscript .= &customrole_javascript();
+ }
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,});
@@ -512,48 +528,112 @@ sub print_username_entry_form {
}
my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
$helpitem);
- my %existingroles=&Apache::lonuserutils::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(
'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",
- 'ecrp' => "Edit Custom Role Privileges",
- 'nr' => "Name of Role",
+ 'ecrp' => "Define or Edit Custom Role",
+ 'nr' => "role name",
'cre' => "Next",
);
$r->print($start_page."\n".$crumbs);
if ($env{'form.action'} eq 'custom') {
if (&Apache::lonnet::allowed('mcr','/')) {
- $r->print(<
-
-
-$lt{'ecrp'}
-$choice $lt{'nr'}:
-
-
-ENDCUSTOM
+ my $newroletext = &mt('Define new custom role:');
+ $r->print('');
}
} 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 ");
+ $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 customrole_javascript {
+ my $js = <<"END";
+
+END
+ return $js;
+}
+
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 +673,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 +685,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 +761,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 +789,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 +804,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 +816,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('');
+ return;
+}
- # Create Navigation:
- # Navigation Script
- my $nav_script = <<"ENDSCRIPT";
+sub userlogdisplay_nav {
+ my ($formname,$curr,$more_records) = @_;
+ my ($nav_script,$nav_links);
+ if (ref($curr) eq 'HASH') {
+ # Create Navigation:
+ # Navigation Script
+ $nav_script = <<"ENDSCRIPT";
ENDSCRIPT
- # Navigation Buttons
- my $nav_links;
- $nav_links = '';
- if (($curr{'page'} > 1) || ($more_records)) {
- if ($curr{'page'} > 1) {
- $nav_links .= ' ';
- }
- if ($more_records) {
- $nav_links .= ' ';
+ # Navigation Buttons
+ $nav_links = '
';
+ if (($curr->{'page'} > 1) || ($more_records)) {
+ if ($curr->{'page'} > 1) {
+ $nav_links .= ' ';
+ }
+ if ($more_records) {
+ $nav_links .= ' ';
+ }
}
+ $nav_links .= '
';
}
- $nav_links .= '
';
-
- # Table Header
- my $tableheader =
- &Apache::loncommon::start_data_table_header_row()
- .' '
- .''.&mt('When').' '
- .''.&mt('Who made the change').' '
- .''.&mt('Changed User').' '
- .''.&mt('Role').' '
- .''.&mt('Section').' '
- .''.&mt('Context').' '
- .''.&mt('Start').' '
- .''.&mt('End').' '
- .&Apache::loncommon::end_data_table_header_row();
-
- # Print Content
- $r->print(
- $nav_script
- .$nav_links
- .&Apache::loncommon::start_data_table()
- .$tableheader
- .$content
- .&Apache::loncommon::end_data_table()
- .$nav_links
- .$form_footer
- );
- return;
+ return ($nav_script,$nav_links);
}
sub role_display_filter {
- my ($formname,$cdom,$cnum,$curr,$version) = @_;
+ my ($formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
my $context = 'course';
+ my $lctype = lc($crstype);
my $nolink = 1;
my $output = ''.
''.&mt('Changes/page:').' '.
@@ -5108,7 +5453,7 @@ sub role_display_filter {
&Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
$curr->{'rolelog_end_date'},undef,
undef,undef,undef,undef,undef,undef,$nolink);
- my %lt = &rolechg_contexts();
+ my %lt = &rolechg_contexts($crstype);
$output .= ' '.&mt('Window during which changes occurred:').' '.
''.&mt('After:').
' '.$startform.' '.
@@ -5122,13 +5467,13 @@ sub role_display_filter {
$output .= ' selected="selected"';
}
$output .= '>'.&mt('Any').''."\n";
- my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
+ my @roles = &Apache::lonuserutils::course_roles($context,undef,1,$lctype);
foreach my $role (@roles) {
my $plrole;
if ($role eq 'cr') {
$plrole = &mt('Custom Role');
} else {
- $plrole=&Apache::lonnet::plaintext($role);
+ $plrole=&Apache::lonnet::plaintext($role,$crstype);
}
my $selstr = '';
if ($role eq $curr->{'role'}) {
@@ -5140,7 +5485,7 @@ sub role_display_filter {
' '.
''.
&mt('Context:').' ';
- foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
+ foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses') {
my $selstr = '';
if ($curr->{'chgcontext'} eq $chgtype) {
$selstr = ' selected="selected"';
@@ -5170,6 +5515,7 @@ sub role_display_filter {
}
sub rolechg_contexts {
+ my ($crstype) = @_;
my %lt = &Apache::lonlocal::texthash (
any => 'Any',
auto => 'Automated enrollment',
@@ -5178,8 +5524,13 @@ sub rolechg_contexts {
course => 'User Management in course',
domain => 'User Management in domain',
selfenroll => 'Self-enrolled',
- requestcourses => 'Course Request',
+ requestcourses => 'Course Request',
);
+ if ($crstype eq 'Community') {
+ $lt{'createcourse'} = &mt('Community Creation');
+ $lt{'course'} = &mt('User Management in community');
+ $lt{'requestcourses'} = &mt('Community Request');
+ }
return %lt;
}
@@ -5508,12 +5859,12 @@ sub build_search_response {
my ($context,$srch,%srch_results) = @_;
my ($currstate,$response,$forcenewuser);
my %names = (
- 'uname' => 'username',
- 'lastname' => 'last name',
+ 'uname' => 'username',
+ 'lastname' => 'last name',
'lastfirst' => 'last name, first name',
- 'crs' => 'this course',
- 'dom' => 'LON-CAPA domain: ',
- 'instd' => 'the institutional directory for domain: ',
+ 'crs' => 'this course',
+ 'dom' => 'LON-CAPA domain',
+ 'instd' => 'the institutional directory for domain',
);
my %single = (
@@ -5533,14 +5884,20 @@ sub build_search_response {
$currstate = 'modify';
$response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
- $response .= &display_domain_info($srch->{'srchdomain'});
+ $response .= ': '.&display_domain_info($srch->{'srchdomain'});
}
- } else {
- $response = ''.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
+ } else { # Search has nothing found. Prepare message to user.
+ $response = '';
if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
- $response .= &display_domain_info($srch->{'srchdomain'});
+ $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
+ ''.$srch->{'srchterm'}.' ',
+ &display_domain_info($srch->{'srchdomain'}));
+ } else {
+ $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
+ ''.$srch->{'srchterm'}.' ');
}
$response .= ' ';
+
if ($srch->{'srchin'} ne 'alc') {
$forcenewuser = 1;
my $cansrchinst = 0;
@@ -5690,12 +6047,13 @@ sub course_level_table {
'end' => "End"
);
- foreach my $protectedcourse (sort( keys(%inccourses))) {
+ foreach my $protectedcourse (sort(keys(%inccourses))) {
my $thiscourse=$protectedcourse;
$thiscourse=~s:_:/:g;
my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
+ my $isowner = &is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
my $area=$coursedata{'description'};
- my $type=$coursedata{'type'};
+ my $crstype=$coursedata{'type'};
if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
my ($domain,$cnum)=split(/\//,$thiscourse);
my %sections_count;
@@ -5705,12 +6063,13 @@ sub course_level_table {
&Apache::loncommon::get_sections($domain,$cnum);
}
}
- my @roles = &Apache::lonuserutils::roles_by_context('course');
+ my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
foreach my $role (@roles) {
- my $plrole=&Apache::lonnet::plaintext($role);
- if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
+ my $plrole=&Apache::lonnet::plaintext($role,$crstype);
+ if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
+ ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
$table .= &course_level_row($protectedcourse,$role,$area,$domain,
- $plrole,\%sections_count,\%lt);
+ $plrole,\%sections_count,\%lt);
} elsif ($env{'request.course.sec'} ne '') {
if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
$env{'request.course.sec'})) {
@@ -5720,7 +6079,8 @@ sub course_level_table {
}
}
if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
- foreach my $cust (sort keys %customroles) {
+ foreach my $cust (sort(keys(%customroles))) {
+ next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
$table .= &course_level_row($protectedcourse,$role,$area,$domain,
$cust,\%sections_count,\%lt);
@@ -5751,7 +6111,7 @@ sub course_level_row {
$protectedcourse.'_'.$role.'" /> '."\n".
' '.$plrole.' '."\n".
' '.$area.' Domain: '.$domain.' '."\n";
- if ($role eq 'cc') {
+ if (($role eq 'cc') || ($role eq 'co')) {
$row .= ' ';
} elsif ($env{'request.course.sec'} ne '') {
$row .= ' '.
' ';
my $courseform=''.&Apache::loncommon::selectcourse_link
- ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').' ';
- my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
+ ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course/Community','crstype').'';
+ my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser');
my %lt=&Apache::lonlocal::texthash(
'rol' => "Role",
'grs' => "Section",
@@ -5811,14 +6171,14 @@ sub course_level_dc {
'ssd' => "Set Start Date",
'sed' => "Set End Date"
);
- my $header = ''.&mt('Course Level').' '.
+ my $header = ''.&mt('Course/Community Level').' '.
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
''.$courseform.' '.$lt{'rol'}.' '.$lt{'grs'}.' '.$lt{'sta'}.' '.$lt{'end'}.' '.
&Apache::loncommon::end_data_table_header_row();
my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
- ' '."\n".
- ''."\n";
+ ' '."\n".
+ ''."\n";
foreach my $role (@roles) {
my $plrole=&Apache::lonnet::plaintext($role);
$otheritems .= ' '.$plrole;
@@ -5838,13 +6198,14 @@ sub course_level_dc {
' '.$lt{'new'}.' '.
' '.
' '.
- ' '.
+ ' '.
+ ' '.
'
';
$otheritems .= <
+
$lt{'ssd'}
-
+
$lt{'sed'}
ENDTIMEENTRY
@@ -6211,6 +6572,21 @@ sub get_selfenroll_titles {
return (\@row,\%lt);
}
+sub is_courseowner {
+ my ($thiscourse,$courseowner) = @_;
+ if ($courseowner eq '') {
+ if ($env{'request.course.id'} eq $thiscourse) {
+ $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
+ }
+ }
+ if ($courseowner ne '') {
+ if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
+ return 1;
+ }
+ }
+ return;
+}
+
#---------------------------------------------- end functions for &phase_two
#--------------------------------- functions for &phase_two and &phase_three