--- loncom/interface/loncreateuser.pm 2009/08/14 16:43:32 1.295.2.7 +++ loncom/interface/loncreateuser.pm 2012/06/01 11:39:24 1.361 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.295.2.7 2009/08/14 16:43:32 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.361 2012/06/01 11:39:24 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 @@ -110,6 +111,7 @@ sub initialize_authen_forms { sub auth_abbrev { my %abv_auth = ( + krb5 => 'krb', krb4 => 'krb', internal => 'int', localuth => 'loc', @@ -217,10 +219,11 @@ 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", + 'webdav' => "WebDAV access to authoring spaces (if SSL and author/co-author)", 'portfolio' => "Personal User Portfolio", 'avai' => "Available", 'cusa' => "availability", @@ -228,21 +231,27 @@ sub build_tools_display { 'usde' => "Use default", 'uscu' => "Use custom", 'official' => 'Can request creation of official courses', - 'unofficial' => 'Can request creation of unofficial courses', + 'unofficial' => 'Can request creation of unofficial courses', + 'community' => 'Can request creation of communities', ); if ($context eq 'requestcourses') { %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, - 'requestcourses.official','requestcourses.unofficial'); - @usertools = ('official','unofficial'); - @options =('norequest','approve','autolimit','validate'); + 'requestcourses.official','requestcourses.unofficial', + 'requestcourses.community'); + @usertools = ('official','unofficial','community'); + @options =('norequest','approval','autolimit','validate'); %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain); %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'); - @usertools = ('aboutme','blog','portfolio'); + 'tools.aboutme','tools.portfolio','tools.blog', + 'tools.webdav'); + @usertools = ('aboutme','blog','webdav','portfolio'); } foreach my $item (@usertools) { my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off, @@ -285,13 +294,24 @@ 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'; } if ($curroption =~ /^autolimit=(\d*)$/) { $currlimit = $1; - $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit); + if ($currlimit eq '') { + $currdisp = &mt('Yes, automatic creation'); + } else { + $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit); + } } else { $currdisp = $reqdisplay{$curroption}; } @@ -325,9 +345,12 @@ sub build_tools_display { if ($option eq 'autolimit') { $custdisp .= ''; + 'value="'.$currlimit.'" />
'. + $reqtitles{'unlimited'}; + } else { + $custdisp .= ''; } - $custdisp .= ''; + $custdisp .= ''; } $custdisp .= ''; $custradio = ''.&mt('Custom setting').'
'.$custdisp; @@ -335,7 +358,7 @@ sub build_tools_display { $currdisp = ($curr_access?&mt('Yes'):&mt('No')); $custdisp = '  '; $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp. @@ -369,7 +392,7 @@ sub coursereq_externaluser { 'reqcrsotherdom.official','reqcrsotherdom.unofficial', 'reqcrsotherdom.community'); @usertools = ('official','unofficial','community'); - @options = ('approve','validate','autolimit'); + @options = ('approval','validate','autolimit'); %validations = &Apache::lonnet::auto_courserequest_checks($cdom); my $optregex = join('|',@options); my %reqtitles = &courserequest_titles(); @@ -377,22 +400,27 @@ sub coursereq_externaluser { my ($curroption,$currlimit,$tooloff); if ($userenv{'reqcrsotherdom.'.$item} ne '') { my @curr = split(',',$userenv{'reqcrsotherdom.'.$item}); - if (grep(/^\Q$cdom\E:($optregex)=?(\d*)$/,@curr)) { - $curroption = $1; - $currlimit = $2; - if (!$curroption) { - $curroption = 'norequest'; + foreach my $req (@curr) { + if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) { + $curroption = $1; + $currlimit = $2; + last; } } + if (!$curroption) { + $curroption = 'norequest'; + $tooloff = ' checked="checked"'; + } } else { $curroption = 'norequest'; $tooloff = ' checked="checked"'; } $output.= &Apache::loncommon::start_data_table_row()."\n". - ' '.$lt{$item}.': '. + ' '.$lt{$item}.': '. + ''; foreach my $option (@options) { if ($option eq 'validate') { my $canvalidate = 0; @@ -407,18 +435,21 @@ sub coursereq_externaluser { if ($option eq $curroption) { $checked = ' checked="checked"'; } - $output .= ''; } - $output .= ''."\n". + $output .= '
'."\n". ' '; + '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}. + ' '; + $reqtitles{$option}.''; if ($option eq 'autolimit') { - $output .= ''; + 'value="'.$currlimit.'" />'. + '
'.$reqtitles{'unlimited'}; + } else { + $output .= ''; } - $output .= ' ' + $output .= '
'."\n". &Apache::loncommon::end_data_table_row()."\n"; } return $output; @@ -430,26 +461,27 @@ sub courserequest_titles { unofficial => 'Unofficial', community => 'Communities', norequest => 'Not allowed', - approve => 'Approval by Dom. Coord.', + approval => 'Approval by Dom. Coord.', validate => 'With validation', autolimit => 'Numerical limit', + unlimited => '(blank for unlimited)', ); - return %titles; -} - + return %titles; +} + sub courserequest_display { my %titles = &Apache::lonlocal::texthash ( - approve => 'Yes, need approval', + approval => 'Yes, need approval', validate => 'Yes, with validation', norequest => 'No', - ); + ); return %titles; } # =================================================================== Phase one sub print_username_entry_form { - my ($r,$context,$response,$srch,$forcenewuser) = @_; + my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_; my $defdom=$env{'request.role.domain'}; my $formtoset = 'crtuser'; if (exists($env{'form.startrolename'})) { @@ -468,22 +500,10 @@ sub print_username_entry_form { '// ]]>'."\n". ''."\n"; - my %loaditems = ( - 'onload' => "javascript:setFormElements(document.$formtoset)", - ); - my %breadcrumb_text = &singleuser_breadcrumb(); - my $start_page = - &Apache::loncommon::start_page('User Management', - $jscript,{'add_entries' => \%loaditems,}); - if ($env{'form.action'} eq 'custom') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.crtuser)", - text=>"Pick custom role",}); - } else { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.crtuser)", - text=>$breadcrumb_text{'search'}, - faq=>282,bug=>'Instructor Interface',}); + 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 $helpitem = 'Course_Change_Privileges'; if ($env{'form.action'} eq 'custom') { @@ -491,51 +511,135 @@ sub print_username_entry_form { } elsif ($env{'form.action'} eq 'singlestudent') { $helpitem = 'Course_Add_Student'; } - 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 %breadcrumb_text = &singleuser_breadcrumb($crstype); + if ($env{'form.action'} eq 'custom') { + push(@{$brcrum}, + {href=>"javascript:backPage(document.crtuser)", + text=>"Pick custom role", + help => $helpitem,} + ); + } else { + push (@{$brcrum}, + {href => "javascript:backPage(document.crtuser)", + text => $breadcrumb_text{'search'}, + help => $helpitem, + faq => 282, + bug => 'Instructor Interface',} + ); + } + my %loaditems = ( + 'onload' => "javascript:setFormElements(document.$formtoset)", + ); + my $args = {bread_crumbs => $brcrum, + bread_crumbs_component => 'User Management', + add_entries => \%loaditems,}; + $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args)); + 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('
'. + ''. + ''. + '

'.$lt{'ecrp'}.'

'. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_row(). + ''); + if (keys(%existingroles) > 0) { + $r->print('
'); + } else { + $r->print('
'.$newroletext.''); + } + $r->print(''.$lt{'nr'}.'
'. + &Apache::loncommon::end_data_table_row()); + if (keys(%existingroles) > 0) { + $r->print(&Apache::loncommon::start_data_table_row().'
'. + ''. + '
'. + ''. + ''. + &Apache::loncommon::end_data_table_row()); + } + $r->print(&Apache::loncommon::end_data_table().'

'. + '

'. + '
'); } } 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 %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); + my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_; my ($usertype,$inexact); if (ref($srch) eq 'HASH') { if (($srch->{'srchin'} eq 'dom') && @@ -543,9 +647,10 @@ sub entry_form { ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} ne '') && ($srch->{'srchterm'} ne '')) { + my (%curr_rules,%got_rules); my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username'); - $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules); + $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules); } else { $inexact = 1; } @@ -574,6 +679,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", @@ -585,8 +691,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'}; @@ -634,19 +744,13 @@ sub user_modification_js { '."\n"; - my %breadcrumb_text = &singleuser_breadcrumb(); - my $args; - if ($env{'form.popup'}) { - $args->{'no_nav_bar'} = 1; - } else { - $args = undef; - } - $r->print(&Apache::loncommon::start_page($title,$jscript,$args)); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.userupdate)", - text=>$breadcrumb_text{'search'}, - faq=>282,bug=>'Instructor Interface',}); + my %breadcrumb_text = &singleuser_breadcrumb($crstype); + push (@{$brcrum}, + {href => "javascript:backPage(document.userupdate)", + text => $breadcrumb_text{'search'}, + faq => 282, + bug => 'Instructor Interface',} + ); if ($env{'form.prevphase'} eq 'userpicked') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')", - text=>$breadcrumb_text{'userpicked'}, - faq=>282,bug=>'Instructor Interface',}); - } - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')", - text=>$breadcrumb_text{'modify'}, - faq=>282,bug=>'Instructor Interface',}, - {href=>"/adm/createuser", - text=>"Result", - faq=>282,bug=>'Instructor Interface',}); + push(@{$brcrum}, + {href => "javascript:backPage(document.userupdate,'get_user_info','select')", + text => $breadcrumb_text{'userpicked'}, + faq => 282, + bug => 'Instructor Interface',}); + } my $helpitem = 'Course_Change_Privileges'; if ($env{'form.action'} eq 'singlestudent') { $helpitem = 'Course_Add_Student'; } - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', - $helpitem)); + push(@{$brcrum}, + {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')", + text => $breadcrumb_text{'modify'}, + faq => 282, + bug => 'Instructor Interface',}, + {href => "/adm/createuser", + text => "Result", + faq => 282, + bug => 'Instructor Interface', + help => $helpitem}); + my $args = {bread_crumbs => $brcrum, + bread_crumbs_component => 'User Management'}; + if ($env{'form.popup'}) { + $args->{'no_nav_bar'} = 1; + } + $r->print(&Apache::loncommon::start_page($title,$jscript,$args)); $r->print(&update_result_form($uhome)); # Check Inputs if (! $env{'form.ccuname'} ) { @@ -2073,11 +2310,17 @@ sub update_user_data { $r->print('

'.&mt('User [_1] in domain [_2]', $env{'form.ccuname'}, $env{'form.ccdomain'}).'

'); + $r->print('

'.&mt('Please be patient').'

'); + my (%alerts,%rulematch,%inst_results,%curr_rules); - my @usertools = ('aboutme','blog','portfolio'); - my @requestcourses = ('official','unofficial'); + my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id'); + my @usertools = ('aboutme','blog','webdav','portfolio'); + my @requestcourses = ('official','unofficial','community'); my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'}); + my %canmodify_status = + &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'}, + ['inststatus']); if ($env{'form.makeuser'}) { $r->print('

'.&mt('Creating new account.').'

'); # Check for the authentication mode and password @@ -2137,49 +2380,52 @@ sub update_user_data { $r->print(&mt('Generating user').': '.$result); $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); - my (%changeHash,%newcustom,%changed); + my (%changeHash,%newcustom,%changed,%changedinfo); if ($uhome ne 'no_host') { - if ($env{'form.customquota'} == 1) { - if ($env{'form.portfolioquota'} eq '') { - $newcustom{'quota'} = 0; - } else { - $newcustom{'quota'} = $env{'form.portfolioquota'}; - $newcustom{'quota'} =~ s/[^\d\.]//g; + if ($context eq 'domain') { + if ($env{'form.customquota'} == 1) { + if ($env{'form.portfolioquota'} eq '') { + $newcustom{'quota'} = 0; + } else { + $newcustom{'quota'} = $env{'form.portfolioquota'}; + $newcustom{'quota'} =~ s/[^\d\.]//g; + } + $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash); } - $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash); - } - foreach my $item (@usertools) { - if ($env{'form.custom'.$item} == 1) { - $newcustom{$item} = $env{'form.tools_'.$item}; - $changed{$item} = &tool_admin($item,$newcustom{$item}, - \%changeHash,'tools'); + foreach my $item (@usertools) { + if ($env{'form.custom'.$item} == 1) { + $newcustom{$item} = $env{'form.tools_'.$item}; + $changed{$item} = &tool_admin($item,$newcustom{$item}, + \%changeHash,'tools'); + } } - } - foreach my $item (@requestcourses) { - $newcustom{$item} = $env{'form.crsreq_'.$item}; - if ($env{'form.crsreq_'.$item} eq 'autolimit') { - $newcustom{$item} .= '='; - unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) { - $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'}; + foreach my $item (@requestcourses) { + if ($env{'form.custom'.$item} == 1) { + $newcustom{$item} = $env{'form.crsreq_'.$item}; + if ($env{'form.crsreq_'.$item} eq 'autolimit') { + $newcustom{$item} .= '='; + unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) { + $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'}; + } + } + $changed{$item} = &tool_admin($item,$newcustom{$item}, + \%changeHash,'requestcourses'); } } - $changed{$item} = &tool_admin($item,$newcustom{$item}, - \%changeHash,'requestcourses'); } - if (exists($env{'form.inststatus'})) { - my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus'); - if (@inststatuses > 0) { - $changeHash{'inststatus'} = join(',',@inststatuses); - $changed{'inststatus'} = $changeHash{'inststatus'}; + if ($canmodify_status{'inststatus'}) { + if (exists($env{'form.inststatus'})) { + my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus'); + if (@inststatuses > 0) { + $changeHash{'inststatus'} = join(',',@inststatuses); + $changed{'inststatus'} = $changeHash{'inststatus'}; + } } } if (keys(%changed)) { - $changeHash{'firstname'} = $env{'form.cfirstname'}; - $changeHash{'middlename'} = $env{'form.cmiddlename'}; - $changeHash{'lastname'} = $env{'form.clastname'}; - $changeHash{'generation'} = $env{'form.cgeneration'}; - $changeHash{'id'} = $env{'form.cid'}; - $changeHash{'permanentemail'} = $env{'form.cpermanentemail'}; + foreach my $item (@userinfo) { + $changeHash{$item} = $env{'form.c'.$item}; + } my $chgresult = &Apache::lonnet::put('environment',\%changeHash, $env{'form.ccdomain'},$env{'form.ccuname'}); @@ -2207,20 +2453,24 @@ sub update_user_data { $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end); } } + + $r->rflush(); # Finish display of header before time consuming actions start + ## - my (@userroles,%userupdate,$cnum,$cdom,$namechanged); + my (@userroles,%userupdate,$cnum,$cdom,%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 my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation', 'id','permanentemail','portfolioquota','inststatus','tools.aboutme', - 'tools.blog','tools.portfolio','requestcourses.official', - 'requestcourses.unofficial','requestcourses.community', - 'reqcrsotherdom.official','reqcrsotherdom.unofficial', - 'reqcrsotherdom.community'], + 'tools.blog','tools.webdav','tools.portfolio', + 'requestcourses.official','requestcourses.unofficial', + 'requestcourses.community','reqcrsotherdom.official', + 'reqcrsotherdom.unofficial','reqcrsotherdom.community'], $env{'form.ccdomain'},$env{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { @@ -2294,10 +2544,9 @@ 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'); my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles); foreach my $item (@userinfo) { # Strip leading and trailing whitespace @@ -2344,40 +2593,48 @@ sub update_user_data { } } my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus, - $inststatus,$newinststatus,$oldisdefault,$newisdefault,$olddefquotatext, - $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext, - $oldinststatuses,$newinststatuses); - my ($defquota,$settingstatus) = - &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus); - my ($showquota,$showtools,$showrequestcourses,$showinststatus,$showreqotherdom); + $newinststatus,$oldisdefault,$newisdefault,%oldsettings, + %oldsettingstext,%newsettings,%newsettingstext,@disporder, + $olddefquota,$oldsettingstatus,$newdefquota,$newsettingstatus); + @disporder = ('inststatus'); + if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) { + push(@disporder,'requestcourses'); + } else { + push(@disporder,'reqcrsotherdom'); + } + push(@disporder,('quota','tools')); + $oldinststatus = $userenv{'inststatus'}; + ($olddefquota,$oldsettingstatus) = + &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus); + ($newdefquota,$newsettingstatus) = ($olddefquota,$oldsettingstatus); + my %canshow; if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { - $showquota = 1; + $canshow{'quota'} = 1; } if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) { - $showtools = 1; + $canshow{'tools'} = 1; } if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) { - $showrequestcourses = 1; + $canshow{'requestcourses'} = 1; } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { - $showreqotherdom = 1; + $canshow{'reqcrsotherdom'} = 1; } if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) { - $showinststatus = 1; + $canshow{'inststatus'} = 1; } my (%changeHash,%changed); - $oldinststatus = $userenv{'inststatus'}; if ($oldinststatus eq '') { - $oldinststatuses = $othertitle; + $oldsettings{'inststatus'} = $othertitle; } else { if (ref($usertypes) eq 'HASH') { - $oldinststatuses = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'}))); + $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'}))); } else { - $oldinststatuses = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'}))); + $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'}))); } } $changeHash{'inststatus'} = $userenv{'inststatus'}; - my %canmodify_inststatus = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},['inststatus'],\@userroles); - if ($canmodify_inststatus{'inststatus'}) { + if ($canmodify_status{'inststatus'}) { + $canshow{'inststatus'} = 1; if (exists($env{'form.inststatus'})) { my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus'); if (@inststatuses > 0) { @@ -2385,87 +2642,88 @@ sub update_user_data { $changeHash{'inststatus'} = $newinststatus; if ($newinststatus ne $oldinststatus) { $changed{'inststatus'} = $newinststatus; + ($newdefquota,$newsettingstatus) = + &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus); } if (ref($usertypes) eq 'HASH') { - $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses)); + $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses)); } else { - $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses)); - } - } else { - $newinststatus = ''; - $changeHash{'inststatus'} = $newinststatus; - $newinststatuses = $othertitle; - if ($newinststatus ne $oldinststatus) { - $changed{'inststatus'} = $changeHash{'inststatus'}; + $newsettings{'inststatus'} = join(', ',@inststatuses); } } + } else { + $newinststatus = ''; + $changeHash{'inststatus'} = $newinststatus; + $newsettings{'inststatus'} = $othertitle; + if ($newinststatus ne $oldinststatus) { + $changed{'inststatus'} = $changeHash{'inststatus'}; + ($newdefquota,$newsettingstatus) = + &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus); + } } + } elsif ($context ne 'selfcreate') { + $canshow{'inststatus'} = 1; + $newsettings{'inststatus'} = $oldsettings{'inststatus'}; } $changeHash{'portfolioquota'} = $userenv{'portfolioquota'}; - if ($userenv{'portfolioquota'} ne '') { - $oldportfolioquota = $userenv{'portfolioquota'}; - if ($env{'form.customquota'} == 1) { - if ($env{'form.portfolioquota'} eq '') { - $newportfolioquota = 0; + if ($context eq 'domain') { + if ($userenv{'portfolioquota'} ne '') { + $oldportfolioquota = $userenv{'portfolioquota'}; + if ($env{'form.customquota'} == 1) { + if ($env{'form.portfolioquota'} eq '') { + $newportfolioquota = 0; + } else { + $newportfolioquota = $env{'form.portfolioquota'}; + $newportfolioquota =~ s/[^\d\.]//g; + } + if ($newportfolioquota != $oldportfolioquota) { + $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash); + } } else { - $newportfolioquota = $env{'form.portfolioquota'}; - $newportfolioquota =~ s/[^\d\.]//g; - } - if ($newportfolioquota != $oldportfolioquota) { - $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash); + $changed{'quota'} = "a_admin('',\%changeHash); + $newportfolioquota = $newdefquota; + $newisdefault = 1; } } else { - $changed{'quota'} = "a_admin('',\%changeHash); - $newportfolioquota = $defquota; - $newisdefault = 1; - } - } else { - $oldisdefault = 1; - $oldportfolioquota = $defquota; - if ($env{'form.customquota'} == 1) { - if ($env{'form.portfolioquota'} eq '') { - $newportfolioquota = 0; + $oldisdefault = 1; + $oldportfolioquota = $olddefquota; + if ($env{'form.customquota'} == 1) { + if ($env{'form.portfolioquota'} eq '') { + $newportfolioquota = 0; + } else { + $newportfolioquota = $env{'form.portfolioquota'}; + $newportfolioquota =~ s/[^\d\.]//g; + } + $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash); } else { - $newportfolioquota = $env{'form.portfolioquota'}; - $newportfolioquota =~ s/[^\d\.]//g; + $newportfolioquota = $newdefquota; + $newisdefault = 1; } - $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash); + } + if ($oldisdefault) { + $oldsettingstext{'quota'} = &get_defaultquota_text($oldsettingstatus); + } + if ($newisdefault) { + $newsettingstext{'quota'} = &get_defaultquota_text($newsettingstatus); + } + &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv, + \%changeHash,\%changed,\%newsettings,\%newsettingstext); + if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) { + &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext, + \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext); } else { - $newportfolioquota = $defquota; - $newisdefault = 1; + &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext, + \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext); + } + } + foreach my $item (@userinfo) { + if ($env{'form.c'.$item} ne $userenv{$item}) { + $namechanged{$item} = 1; } } - if ($oldisdefault) { - $olddefquotatext = &get_defaultquota_text($settingstatus); - } - if ($newisdefault) { - $newdefquotatext = &get_defaultquota_text($settingstatus); - } - &tool_changes('tools',\@usertools,\%oldaccess,\%oldaccesstext,\%userenv, - \%changeHash,\%changed,\%newaccess,\%newaccesstext); - - if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) { - &tool_changes('requestcourses',\@requestcourses,\%oldaccess,\%oldaccesstext, - \%userenv,\%changeHash,\%changed,\%newaccess,\%newaccesstext); - } else { - &tool_changes('reqcrsotherdom',\@requestcourses,\%oldaccess,\%oldaccesstext, - \%userenv,\%changeHash,\%changed,\%newaccess,\%newaccesstext); - } - if ($env{'form.cfirstname'} ne $userenv{'firstname'} || - $env{'form.cmiddlename'} ne $userenv{'middlename'} || - $env{'form.clastname'} ne $userenv{'lastname'} || - $env{'form.cgeneration'} ne $userenv{'generation'} || - $env{'form.cid'} ne $userenv{'id'} || - $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) { - $namechanged = 1; - } - if (($namechanged) || (keys(%changed) > 0)) { - $changeHash{'firstname'} = $env{'form.cfirstname'}; - $changeHash{'middlename'} = $env{'form.cmiddlename'}; - $changeHash{'lastname'} = $env{'form.clastname'}; - $changeHash{'generation'} = $env{'form.cgeneration'}; - $changeHash{'id'} = $env{'form.cid'}; - $changeHash{'permanentemail'} = $env{'form.cpermanentemail'}; + $oldsettings{'quota'} = $oldportfolioquota.' Mb'; + $newsettings{'quota'} = $newportfolioquota.' Mb'; + if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) { my ($chgresult,$namechgresult); if (keys(%changed) > 0) { $chgresult = @@ -2476,12 +2734,12 @@ sub update_user_data { ($env{'user.domain'} eq $env{'form.ccdomain'})) { my %newenvhash; foreach my $key (keys(%changed)) { - if (($key eq 'official') || ($key eq 'unofficial')) { + if (($key eq 'official') || ($key eq 'unofficial') + || ($key eq 'community')) { $newenvhash{'environment.requestcourses.'.$key} = $changeHash{'requestcourses.'.$key}; if ($changeHash{'requestcourses.'.$key} ne '') { - $newenvhash{'environment.canrequest.'.$key} = - $changeHash{'requestcourses.'.$key}; + $newenvhash{'environment.canrequest.'.$key} = 1; } else { $newenvhash{'environment.canrequest.'.$key} = &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, @@ -2505,14 +2763,17 @@ sub update_user_data { } } } - if ($namechanged) { - # Make the change + if (keys(%namechanged) > 0) { + foreach my $field (@userinfo) { + $changeHash{$field} = $env{'form.c'.$field}; + } +# Make the change $namechgresult = &Apache::lonnet::modifyuser($env{'form.ccdomain'}, $env{'form.ccuname'},$changeHash{'id'},undef,undef, $changeHash{'firstname'},$changeHash{'middlename'}, $changeHash{'lastname'},$changeHash{'generation'}, - $changeHash{'id'},undef,$changeHash{'permanentemail'}); + $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo); %userupdate = ( lastname => $env{'form.clastname'}, middlename => $env{'form.cmiddlename'}, @@ -2521,138 +2782,13 @@ sub update_user_data { id => $env{'form.cid'}, ); } - if (($namechanged && $namechgresult eq 'ok') || + if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') || ((keys(%changed) > 0) && $chgresult eq 'ok')) { # Tell the user we changed the name - my %lt=&Apache::lonlocal::texthash( - 'uic' => 'User Information Changed', - 'frst' => 'First Name', - 'mddl' => 'Middle Name', - 'lst' => 'Last Name', - 'gen' => 'Generation', - 'id' => 'Student/Employee ID', - 'mail' => 'Permanent e-mail address', - 'disk' => 'Disk space allocated to portfolio files', - 'blog' => 'Blog Availability', - 'aboutme' => 'Personal Information Page Availability', - 'portfolio' => 'Portfolio Availability', - 'official' => 'Can Request Official Courses', - 'unofficial' => 'Can Request Unofficial Courses', - 'inststatus' => "Affiliation", - 'prvs' => 'Previous Value:', - 'chto' => 'Changed To:' - ); - $r->print('

'.$lt{'uic'}.'

'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row()); - $r->print(<<"END"); -   - $lt{'frst'} - $lt{'mddl'} - $lt{'lst'} - $lt{'gen'} - $lt{'id'} - $lt{'mail'} -END - if ($showinststatus) { - $r->print(" - $lt{'inststatus'}\n"); - } - if ($showrequestcourses) { - foreach my $item (@requestcourses) { - $r->print(" - $lt{$item}\n"); - } - } elsif ($showreqotherdom) { - foreach my $item (@requestcourses) { - $r->print(" - $lt{$item}\n"); - } - } - if ($showquota) { - $r->print(" - $lt{'disk'}\n"); - } - if ($showtools) { - foreach my $item (@usertools) { - $r->print(" - $lt{$item}\n"); - } - } - $r->print(&Apache::loncommon::end_data_table_header_row(). - &Apache::loncommon::start_data_table_row()); - $r->print(<<"END"); - $lt{'prvs'} - $userenv{'firstname'} - $userenv{'middlename'} - $userenv{'lastname'} - $userenv{'generation'} - $userenv{'id'} - $userenv{'permanentemail'} -END - if ($showinststatus) { - $r->print(" - $oldinststatuses\n"); - } - if ($showrequestcourses) { - foreach my $item (@requestcourses) { - $r->print(" - $oldaccess{$item} $oldaccesstext{$item}\n"); - } - } elsif ($showreqotherdom) { - foreach my $item (@requestcourses) { - $r->print(" - $oldaccess{$item} $oldaccesstext{$item}\n"); - } - } - if ($showquota) { - $r->print(" - $oldportfolioquota Mb $olddefquotatext \n"); - } - if ($showtools) { - foreach my $item (@usertools) { - $r->print(" - $oldaccess{$item} $oldaccesstext{$item} \n"); - } - } - $r->print(&Apache::loncommon::end_data_table_row(). - &Apache::loncommon::start_data_table_row()); - $r->print(<<"END"); - $lt{'chto'} - $env{'form.cfirstname'} - $env{'form.cmiddlename'} - $env{'form.clastname'} - $env{'form.cgeneration'} - $env{'form.cid'} - $env{'form.cpermanentemail'} -END - if ($showinststatus) { - $r->print(" - $newinststatuses\n"); - } - if ($showrequestcourses) { - foreach my $item (@requestcourses) { - $r->print(" - $newaccess{$item} $newaccesstext{$item} \n"); - } - } elsif ($showreqotherdom) { - foreach my $item (@requestcourses) { - $r->print(" - $newaccess{$item} $newaccesstext{$item} \n"); - } - } - if ($showquota) { - $r->print(" - $newportfolioquota Mb $newdefquotatext \n"); - } - if ($showtools) { - foreach my $item (@usertools) { - $r->print(" - $newaccess{$item} $newaccesstext{$item} \n"); - } - } - $r->print(&Apache::loncommon::end_data_table_row(). - &Apache::loncommon::end_data_table().'
'); + &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses, + \@usertools,\%userenv,\%changed,\%namechanged, + \%oldsettings, \%oldsettingstext,\%newsettings, + \%newsettingstext); if ($env{'form.cid'} ne $userenv{'id'}) { &Apache::lonnet::idput($env{'form.ccdomain'}, ($env{'form.ccuname'} => $env{'form.cid'})); @@ -2678,53 +2814,13 @@ END $env{'form.ccuname'}.' '.&mt('in domain').' '. $env{'form.ccdomain'}.'

'); } - } else { # End of if ($env ... ) logic + } else { # End of if ($env ... ) logic # They did not want to change the users name, quota, tool availability, # or ability to request creation of courses, # but we can still tell them what the name and quota and availabilities are - my %lt=&Apache::lonlocal::texthash( - 'id' => "Student/Employee ID", - 'mail' => "Permanent e-mail address", - 'disk' => "Disk space allocated to user's portfolio files", - 'blog' => "Blog Availability", - 'aboutme' => "Personal Information Page Availability", - 'portfolio' => "Portfolio Availability", - 'official' => "Can Request Official Courses", - 'unofficial' => "Can Request Unofficial Course", - 'inststatus' => "Affiliation", - ); - $r->print(<<"END"); -

$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'} -END - if ($userenv{'permanentemail'} ne '') { - $r->print('
['.$lt{'mail'}.': '. - $userenv{'permanentemail'}.']'); - } - if ($showinststatus) { - $r->print('
['.$lt{'inststatus'}.': '.$oldinststatuses.']'); - } - if ($showrequestcourses) { - foreach my $item (@requestcourses) { - $r->print('
['.$lt{$item}.': '.$newaccess{$item}.' '. - $newaccesstext{$item}.']'."\n"); - } - } elsif ($showreqotherdom) { - foreach my $item (@requestcourses) { - $r->print('
['.$lt{$item}.': '.$newaccess{$item}.' '. - $newaccesstext{$item}.']'."\n"); - } - } - if ($showtools) { - foreach my $item (@usertools) { - $r->print('
['.$lt{$item}.': '.$newaccess{$item}.' '. - $newaccesstext{$item}.']'."\n"); - } - } - if ($showquota) { - $r->print('
['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. - $olddefquotatext.']'); - } - $r->print('

'); + &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses, + \@usertools,\%userenv,\%changed,\%namechanged,\%oldsettings, + \%oldsettingstext,\%newsettings,\%newsettingstext); } if (@mod_disallowed) { my ($rolestr,$contextname); @@ -2761,12 +2857,17 @@ 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) { + if (keys(%namechanged) > 0) { if ($context eq 'course') { if (@userroles > 0) { if ((@rolechanges == 0) || @@ -2792,7 +2893,137 @@ END .&mt('Create/Modify Another User').'

'); } } - $r->print(&Apache::loncommon::end_page()); +} + +sub display_userinfo { + my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$userenv, + $changedhash,$namechangedhash,$oldsetting,$oldsettingtext, + $newsetting,$newsettingtext) = @_; + return unless (ref($order) eq 'ARRAY' && + ref($canshow) eq 'HASH' && + ref($requestcourses) eq 'ARRAY' && + ref($usertools) eq 'ARRAY' && + ref($userenv) eq 'HASH' && + ref($changedhash) eq 'HASH' && + ref($oldsetting) eq 'HASH' && + ref($oldsettingtext) eq 'HASH' && + ref($newsetting) eq 'HASH' && + ref($newsettingtext) eq 'HASH'); + my %lt=&Apache::lonlocal::texthash( + 'ui' => 'User Information (unchanged)', + 'uic' => 'User Information Changed', + 'firstname' => 'First Name', + 'middlename' => 'Middle Name', + 'lastname' => 'Last Name', + 'generation' => 'Generation', + 'id' => 'Student/Employee ID', + 'permanentemail' => 'Permanent e-mail address', + 'quota' => 'Disk space allocated to portfolio files', + 'blog' => 'Blog Availability', + 'webdav' => 'WebDAV Availability', + 'aboutme' => 'Personal Information Page Availability', + 'portfolio' => 'Portfolio Availability', + 'official' => 'Can Request Official Courses', + 'unofficial' => 'Can Request Unofficial Courses', + 'community' => 'Can Request Communities', + 'inststatus' => "Affiliation", + 'prvs' => 'Previous Value:', + 'chto' => 'Changed To:' + ); + my $title = $lt{'ui'}; + if ($changed) { + $title = $lt{'uic'}; + } + $r->print('

'.$title.'

'. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row()); + if ($changed) { + $r->print(" \n"); + } + my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id'); + foreach my $item (@userinfo) { + $r->print("$lt{$item}\n"); + } + foreach my $entry (@{$order}) { + if ($canshow->{$entry}) { + if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) { + foreach my $item (@{$requestcourses}) { + $r->print("$lt{$item}\n"); + } + } elsif ($entry eq 'tools') { + foreach my $item (@{$usertools}) { + $r->print("$lt{$item}\n"); + } + } else { + $r->print("$lt{$entry}\n"); + } + } + } + $r->print(&Apache::loncommon::end_data_table_header_row(). + &Apache::loncommon::start_data_table_row()); + if ($changed) { + $r->print(''.$lt{'prvs'}.''."\n"); + } + foreach my $item (@userinfo) { + $r->print(''.$userenv->{$item}.' '."\n"); + } + foreach my $entry (@{$order}) { + if ($canshow->{$entry}) { + if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) { + foreach my $item (@{$requestcourses}) { + $r->print("$oldsetting->{$item} $oldsettingtext->{$item}\n"); + } + } elsif ($entry eq 'tools') { + foreach my $item (@{$usertools}) { + $r->print("$oldsetting->{$item} $oldsettingtext->{$item}\n"); + } + } else { + $r->print("$oldsetting->{$entry} $oldsettingtext->{$entry} \n"); + } + } + } + $r->print(&Apache::loncommon::end_data_table_row()); + if ($changed) { + $r->print(&Apache::loncommon::start_data_table_row(). + ''.$lt{'chto'}.''."\n"); + foreach my $item (@userinfo) { + my $value = $env{'form.c'.$item}; + if ($namechangedhash->{$item}) { + $value = ''.$value.''; + } + $r->print("$value \n"); + } + foreach my $entry (@{$order}) { + if ($canshow->{$entry}) { + if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) { + foreach my $item (@{$requestcourses}) { + my $value = $newsetting->{$item}.' '.$newsettingtext->{$item}; + if ($changedhash->{$item}) { + $value = ''.$value.''; + } + $r->print("$value \n"); + } + } elsif ($entry eq 'tools') { + foreach my $item (@{$usertools}) { + my $value = $newsetting->{$item}.' '.$newsettingtext->{$item}; + if ($changedhash->{$item}) { + $value = ''.$value.''; + } + $r->print("$value \n"); + } + } else { + my $value = $newsetting->{$entry}.' '.$newsettingtext->{$entry}; + if ($changedhash->{$entry}) { + $value = ''.$value.''; + } + $r->print("$value \n"); + } + } + } + $r->print(&Apache::loncommon::end_data_table_row()); + } + $r->print(&Apache::loncommon::end_data_table().'
'); + return; } sub tool_changes { @@ -2805,53 +3036,61 @@ sub tool_changes { return; } if ($context eq 'reqcrsotherdom') { - my @options = ('approve','validate','autolimit'); + my @options = ('approval','validate','autolimit'); my $optregex = join('|',@options); my %reqdisplay = &courserequest_display(); my $cdom = $env{'request.role.domain'}; foreach my $tool (@{$usertools}) { - $oldaccesstext->{$tool} = &mt('no'); + $oldaccesstext->{$tool} = &mt('No'); + $newaccesstext->{$tool} = $oldaccesstext->{$tool}; $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool}; + my $newop; + if ($env{'form.'.$context.'_'.$tool}) { + $newop = $env{'form.'.$context.'_'.$tool}; + if ($newop eq 'autolimit') { + my $limit = $env{'form.'.$context.'_'.$tool.'_limit'}; + $limit =~ s/\D+//g; + $newop .= '='.$limit; + } + } if ($userenv->{$context.'.'.$tool} eq '') { - if ($env{'form.'.$context.'_'.$tool}) { - $changed->{$tool}=&tool_admin($tool,$cdom, + if ($newop) { + $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop, $changeHash,$context); if ($changed->{$tool}) { - $newaccesstext->{$tool} = &mt('yes'); + $newaccesstext->{$tool} = &mt('Yes'); } else { - $newaccesstext->{$tool} = $oldaccesstext->{$tool}; } + $newaccesstext->{$tool} = $oldaccesstext->{$tool}; + } } } else { my @curr = split(',',$userenv->{$context.'.'.$tool}); my @new; my $changedoms; - my $newop = $env{'form.'.$context.'_'.$tool}; - if ($newop eq 'autolimit') { - $newop .= '='; - unless ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) { - $newop .= $env{'form.'.$context.'_'.$tool.'_limit'}; - } - } - if (grep(/^\Q$cdom:($optregex\=?\d*)\E$/,@curr)) { - $oldaccesstext->{$tool} = &mt('yes'); - my $oldop = $1; - if ($oldop ne $newop) { - $changedoms = 1; - foreach my $dom (@curr) { - unless ($dom eq $cdom) { - push(@new,$dom); + foreach my $req (@curr) { + if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) { + $oldaccesstext->{$tool} = &mt('Yes'); + my $oldop = $1; + if ($oldop ne $newop) { + $changedoms = 1; + foreach my $item (@curr) { + my ($reqdom,$option) = split(':',$item); + unless ($reqdom eq $cdom) { + push(@new,$item); + } } + if ($newop) { + push(@new,$cdom.':'.$newop); + } + @new = sort(@new); } - if ($newop) { - push(@new,$cdom.':'.$newop); - } - @new = sort(@new); + last; } - } elsif ($env{'form.'.$context.'_'.$tool}) { + } + if ((!$changedoms) && ($newop)) { $changedoms = 1; @new = sort(@curr,$cdom.':'.$newop); } - $newaccesstext->{$tool} = $oldaccesstext->{$tool}; if ($changedoms) { my $newdomstr; if (@new) { @@ -2862,10 +3101,12 @@ sub tool_changes { if ($changed->{$tool}) { if ($env{'form.'.$context.'_'.$tool}) { if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') { - if ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) { - $newaccesstext->{$tool} = &mt('Yes, processed automatically'); + my $limit = $env{'form.'.$context.'_'.$tool.'_limit'}; + $limit =~ s/\D+//g; + if ($limit) { + $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit); } else { - $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user).',$env{'form.'.$context.'_'.$tool.'_limit'}); + $newaccesstext->{$tool} = &mt('Yes, processed automatically'); } } else { $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}}; @@ -3214,7 +3455,7 @@ sub update_roles { } } # End of foreach (keys(%env)) # Flush the course logs so reverse user roles immediately updated - &Apache::lonnet::flushcourselogs(); + $r->register_cleanup(\&Apache::lonnet::flushcourselogs); if (@rolechanges == 0) { $r->print(&mt('No roles to modify')); } @@ -3222,8 +3463,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; @@ -3256,7 +3503,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); @@ -3380,19 +3633,30 @@ sub build_roles { # ========================================================== Custom Role Editor sub custom_role_editor { - my ($r) = @_; - my $rolename=$env{'form.rolename'}; + my ($r,$brcrum) = @_; + my $action = $env{'form.customroleaction'}; + my $rolename; + if ($action eq 'new') { + $rolename=$env{'form.newrolename'}; + } else { + $rolename=$env{'form.rolename'}; + } - if ($rolename eq 'make new role') { - $rolename=$env{'form.newrolename'}; + my ($crstype,$context); + if ($env{'request.course.id'}) { + $crstype = &Apache::loncommon::course_type(); + $context = 'course'; + } else { + $context = 'domain'; + $crstype = $env{'form.templatecrstype'}; } $rolename=~s/[^A-Za-z0-9]//gs; - if (!$rolename || $env{'form.phase'} eq 'pickrole') { - &print_username_entry_form($r); + &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum); return; } + # ------------------------------------------------------- What can be assigned? my %full=(); my %courselevel=(); @@ -3401,7 +3665,6 @@ sub custom_role_editor { my $dompriv=''; my $coursepriv=''; my $body_top; - my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]); my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); # ------------------------------------------------------- Does this role exist? @@ -3410,6 +3673,9 @@ sub custom_role_editor { $body_top .= &mt('Existing Role').' "'; # ------------------------------------------------- Get current role privileges ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef); + if ($crstype eq 'Community') { + $syspriv =~ s/bre\&S//; + } } else { $body_top .= &mt('New Role').' "'; $roledef=''; @@ -3449,41 +3715,92 @@ sub custom_role_editor { my ($jsback,$elements) = &crumb_utilities(); my $button_code = "\n"; my $head_script = "\n"; - $head_script .= ''."\n"; - $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script)); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.form1,'pickrole','')", - text=>"Pick custom role", - faq=>282,bug=>'Instructor Interface',}, - {href=>"javascript:backPage(document.form1,'','')", - text=>"Edit custom role", - faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', - 'Course_Editing_Custom_Roles')); - - $r->print($body_top); + my $context_code; + if ($context eq 'domain') { + my $checkedCommunity = ''; + my $checkedCourse = ' checked="checked"'; + if ($env{'form.templatecrstype'} eq 'Community') { + $checkedCommunity = $checkedCourse; + $checkedCourse = ''; + } + $context_code = ''.(' ' x2). + ''. + ''. + ''; + if ($env{'form.customroleaction'} eq 'new') { + $context_code .= ''; + } else { + $context_code .= ''; + } + $context_code .= ''. + ''; + } + + $head_script .= "\n".$jsback."\n" + .'// ]]>'."\n" + .''."\n"; + push (@{$brcrum}, + {href => "javascript:backPage(document.form1,'pickrole','')", + text => "Pick custom role", + faq => 282,bug=>'Instructor Interface',}, + {href => "javascript:backPage(document.form1,'','')", + text => "Edit custom role", + faq => 282, + bug => 'Instructor Interface', + help => 'Course_Editing_Custom_Roles'} + ); + my $args = { bread_crumbs => $brcrum, + bread_crumbs_component => 'User Management'}; + + $r->print(&Apache::loncommon::start_page('Custom Role Editor', + $head_script,$args). + $body_top); my %lt=&Apache::lonlocal::texthash( 'prv' => "Privilege", 'crl' => "Course Level", 'dml' => "Domain Level", 'ssl' => "System Level"); - $r->print('
' + $r->print('
' .'
' .''.&mt('Select a Template').'' .$button_code - .'
' - .'
' - ); + .'
'); + if ($context_code) { + $r->print('
' + .'
' + .''.&mt('Context').'' + .$context_code + .'' + .'
' + ); + } + $r->print('
'); $r->print(< @@ -3495,8 +3812,8 @@ ENDCCF ''.$lt{'prv'}.''.$lt{'crl'}.''.$lt{'dml'}. ''.$lt{'ssl'}.''. &Apache::loncommon::end_data_table_header_row()); - foreach my $priv (sort keys %full) { - my $privtext = &Apache::lonnet::plaintext($priv); + foreach my $priv (sort(keys(%full))) { + my $privtext = &Apache::lonnet::plaintext($priv,$crstype); $r->print(&Apache::loncommon::start_data_table_row(). ''.$privtext.''. ($courselevel{$priv}?''. ($domainlevel{$priv}?'':' '). - ''. - ($systemlevel{$priv}?'':' '). - ''. - &Apache::loncommon::end_data_table_row()); + ''); + if ($priv eq 'bre' && $crstype eq 'Community') { + $r->print(' '); + } else { + $r->print($systemlevel{$priv}?'':' '); + } + $r->print(''. + &Apache::loncommon::end_data_table_row()); } $r->print(&Apache::loncommon::end_data_table(). ''. ''."\n".''."\n". ''."\n". - ''. - &Apache::loncommon::end_page()); + ''); } # -------------------------------------------------------- sub make_script_template { - my ($role) = @_; + my ($role,$crstype) = @_; my %full_c=(); my %full_d=(); my %full_s=(); @@ -3534,6 +3854,7 @@ sub make_script_template { $full_d{$priv}=1; } foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { + next if (($crstype eq 'Community') && ($item eq 'bre&S')); my ($priv,$restrict)=split(/\&/,$item); $full_s{$priv}=1; } @@ -3586,40 +3907,44 @@ sub make_script_template { } # ---------------------------------------------------------- sub make_button_code { - my ($role) = @_; - my $label = &Apache::lonnet::plaintext($role); + my ($role,$crstype) = @_; + my $label = &Apache::lonnet::plaintext($role,$crstype); my $button_code = ''; return ($button_code); } # ---------------------------------------------------------- Call to definerole sub set_custom_role { - my ($r,$context) = @_; + my ($r,$context,$brcrum) = @_; my $rolename=$env{'form.rolename'}; $rolename=~s/[^A-Za-z0-9]//gs; if (!$rolename) { - &custom_role_editor($r); + &custom_role_editor($r,$brcrum); return; } my ($jsback,$elements) = &crumb_utilities(); - my $jscript = ''; - - $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.customresult,'pickrole','')", - text=>"Pick custom role", - faq=>282,bug=>'Instructor Interface',}, - {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')", - text=>"Edit custom role", - faq=>282,bug=>'Instructor Interface',}, - {href=>"javascript:backPage(document.customresult,'set_custom_roles','')", - text=>"Result", - faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', - 'Course_Editing_Custom_Roles')); + my $jscript = ''."\n"; + push(@{$brcrum}, + {href => "javascript:backPage(document.customresult,'pickrole','')", + text => "Pick custom role", + faq => 282, + bug => 'Instructor Interface',}, + {href => "javascript:backPage(document.customresult,'selected_custom_edit','')", + text => "Edit custom role", + faq => 282, + bug => 'Instructor Interface',}, + {href => "javascript:backPage(document.customresult,'set_custom_roles','')", + text => "Result", + faq => 282, + bug => 'Instructor Interface', + help => 'Course_Editing_Custom_Roles'}, + ); + my $args = { bread_crumbs => $brcrum, + bread_crumbs_component => 'User Management'}; + $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args)); my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); @@ -3676,7 +4001,6 @@ sub set_custom_role { } $r->print('

'.&mt('Create or edit another custom role').'

'); $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'
'); - $r->print(&Apache::loncommon::end_page()); } # ================================================================ Main Handler @@ -3687,9 +4011,10 @@ sub handler { $r->send_http_header; return OK; } - my $context; + my ($context,$crstype); if ($env{'request.course.id'}) { $context = 'course'; + $crstype = &Apache::loncommon::course_type(); } elsif ($env{'request.role'} =~ /^au\./) { $context = 'author'; } else { @@ -3699,17 +4024,24 @@ sub handler { ['action','state','callingform','roletype','showrole','bulkaction','popup','phase', 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']); &Apache::lonhtmlcommon::clear_breadcrumbs(); + my $args; + my $brcrum = []; + my $bread_crumbs_component = 'User Management'; if ($env{'form.action'} ne 'dateselect') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/createuser", - text=>"User Management", - help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}); + $brcrum = [{href=>"/adm/createuser", + text=>"User Management", + help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'} + ]; } #SD Following files not added to help, because the corresponding .tex-files seem to #be missing: Course_Approve_Selfenroll,Course_User_Logs, my ($permission,$allowed) = - &Apache::lonuserutils::get_permission($context); + &Apache::lonuserutils::get_permission($context,$crstype); if (!$allowed) { + if ($context eq 'course') { + $r->internal_redirect('/adm/viewclasslist'); + return OK; + } $env{'user.error.msg'}= "/adm/createuser:cst:0:0:Cannot create/modify user data ". "or view user status."; @@ -3721,17 +4053,20 @@ sub handler { # Main switch on form.action and form.state, as appropriate if (! exists($env{'form.action'})) { - $r->print(&header()); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); - $r->print(&print_main_menu($permission,$context)); - $r->print(&Apache::loncommon::end_page()); + $args = {bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + $r->print(&header(undef,$args)); + $r->print(&print_main_menu($permission,$context,$crstype)); } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) { - $r->print(&header()); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=upload&state=', - text=>"Upload Users List"}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List', - 'Course_Create_Class_List')); + push(@{$brcrum}, + { href => '/adm/createuser?action=upload&state=', + text => 'Upload Users List', + help => 'Course_Create_Class_List', + }); + $bread_crumbs_component = 'Upload Users List'; + $args = {bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + $r->print(&header(undef,$args)); $r->print('
'."\n"); @@ -3739,7 +4074,7 @@ sub handler { &Apache::lonuserutils::print_first_users_upload_form($r,$context); } elsif ($env{'form.state'} eq 'got_file') { &Apache::lonuserutils::print_upload_manager_form($r,$context, - $permission); + $permission,$crstype); } elsif ($env{'form.state'} eq 'enrolling') { if ($env{'form.datatoken'}) { &Apache::lonuserutils::upfile_drop_add($r,$context,$permission); @@ -3747,7 +4082,6 @@ sub handler { } else { &Apache::lonuserutils::print_first_users_upload_form($r,$context); } - $r->print('
'.&Apache::loncommon::end_page()); } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'} eq 'singlestudent')) && ($permission->{'cusr'})) { my $phase = $env{'form.phase'}; @@ -3764,13 +4098,13 @@ sub handler { if ($env{'form.srchterm'} !~ /^$match_username$/) { my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @'); $env{'form.phase'} = ''; - &print_username_entry_form($r,$context,$response,$srch); + &print_username_entry_form($r,$context,$response,$srch,undef,$crstype,$brcrum); } else { my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'}); my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'}); &print_user_modification_page($r,$ccuname,$ccdomain, $srch,$response,$context, - $permission); + $permission,$crstype,$brcrum); } } elsif ($env{'form.phase'} eq 'get_user_info') { my ($currstate,$response,$forcenewuser,$results) = @@ -3780,7 +4114,8 @@ sub handler { } if ($currstate eq 'select') { &print_user_selection_page($r,$response,$srch,$results, - \@search,$context); + \@search,$context,undef,$crstype, + $brcrum); } elsif ($currstate eq 'modify') { my ($ccuname,$ccdomain); if (($srch->{'srchby'} eq 'uname') && @@ -3798,194 +4133,218 @@ sub handler { } &print_user_modification_page($r,$ccuname,$ccdomain, $srch,$response,$context, - $permission); + $permission,$crstype,$brcrum); } elsif ($currstate eq 'query') { - &print_user_query_page($r,'createuser'); + &print_user_query_page($r,'createuser',$brcrum); } else { $env{'form.phase'} = ''; &print_username_entry_form($r,$context,$response,$srch, - $forcenewuser); + $forcenewuser,$crstype,$brcrum); } } elsif ($env{'form.phase'} eq 'userpicked') { my $ccuname = &LONCAPA::clean_username($env{'form.seluname'}); my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'}); &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'', - $context,$permission); + $context,$permission,$crstype, + $brcrum); } } elsif ($env{'form.phase'} eq 'update_user_data') { - &update_user_data($r,$context); + &update_user_data($r,$context,$crstype,$brcrum); } else { - &print_username_entry_form($r,$context,undef,$srch); + &print_username_entry_form($r,$context,undef,$srch,undef,$crstype, + $brcrum); } } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) { if ($env{'form.phase'} eq 'set_custom_roles') { - &set_custom_role($r,$context); + &set_custom_role($r,$context,$brcrum); } else { - &custom_role_editor($r); + &custom_role_editor($r,$brcrum); } } elsif (($env{'form.action'} eq 'listusers') && ($permission->{'view'} || $permission->{'cusr'})) { if ($env{'form.phase'} eq 'bulkchange') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=listusers', - text=>"List Users"}, - {href=>"/adm/createuser", - text=>"Result"}); + push(@{$brcrum}, + {href => '/adm/createuser?action=listusers', + text => "List Users"}, + {href => "/adm/createuser", + text => "Result", + help => 'Course_View_Class_List'}); + $bread_crumbs_component = 'Update Users'; + $args = {bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + $r->print(&header(undef,$args)); my $setting = $env{'form.roletype'}; my $choice = $env{'form.bulkaction'}; - $r->print(&header()); - $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users", - 'Course_View_Class_List')); if ($permission->{'cusr'}) { - &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice); - $r->print(&Apache::loncommon::end_page()); + &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype); } else { $r->print(&mt('You are not authorized to make bulk changes to user roles')); $r->print('

'.&mt('Display User Lists').''); - $r->print(&Apache::loncommon::end_page()); } } else { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=listusers', - text=>"List Users"}); + push(@{$brcrum}, + {href => '/adm/createuser?action=listusers', + text => "List Users", + help => 'Course_View_Class_List'}); + $bread_crumbs_component = 'List Users'; + $args = {bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles); my $formname = 'studentform'; - if ($context eq 'domain' && $env{'form.roletype'} eq 'course') { - ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) = - &Apache::lonuserutils::courses_selector($env{'request.role.domain'}, - $formname); + if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community'))) { + if ($env{'form.roletype'} eq 'course') { + ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) = + &Apache::lonuserutils::courses_selector($env{'request.role.domain'}, + $formname); + } elsif ($env{'form.roletype'} eq 'community') { + $cb_jscript = + &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); + my %elements = ( + coursepick => 'radio', + coursetotal => 'text', + courselist => 'text', + ); + $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements); + } $jscript .= &verify_user_display(); my $js = &add_script($jscript).$cb_jscript; my $loadcode = &Apache::lonuserutils::course_selector_loadcode($formname); if ($loadcode ne '') { - $r->print(&header($js,{'onload' => $loadcode,})); - } else { - $r->print(&header($js)); + $args->{add_entries} = {onload => $loadcode}; } + $r->print(&header($js,$args)); } else { - $r->print(&header(&add_script(&verify_user_display()))); + $r->print(&header(&add_script(&verify_user_display()),$args)); } - $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users", - 'Course_View_Class_List')); &Apache::lonuserutils::print_userlist($r,undef,$permission,$context, $formname,$totcodes,$codetitles,$idlist,$idlist_titles); - $r->print(&Apache::loncommon::end_page()); } } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) { - $r->print(&header()); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=drop', - text=>"Drop Students"}); + my $brtext; + if ($crstype eq 'Community') { + $brtext = 'Drop Members'; + } else { + $brtext = 'Drop Students'; + } + push(@{$brcrum}, + {href => '/adm/createuser?action=drop', + text => $brtext, + help => 'Course_Drop_Student'}); + if ($env{'form.state'} eq 'done') { + push(@{$brcrum}, + {href=>'/adm/createuser?action=drop', + text=>"Result"}); + } + $bread_crumbs_component = $brtext; + $args = {bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + $r->print(&header(undef,$args)); if (!exists($env{'form.state'})) { - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students', - 'Course_Drop_Student')); - - &Apache::lonuserutils::print_drop_menu($r,$context,$permission); + &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype); } elsif ($env{'form.state'} eq 'done') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=drop', - text=>"Result"}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students', - 'Course_Drop_Student')); &Apache::lonuserutils::update_user_list($r,$context,undef, $env{'form.action'}); } - $r->print(&Apache::loncommon::end_page()); } elsif ($env{'form.action'} eq 'dateselect') { if ($permission->{'cusr'}) { - $r->print(&header(undef,undef,{'no_nav_bar' => 1}). + $r->print(&header(undef,{'no_nav_bar' => 1}). &Apache::lonuserutils::date_section_selector($context, - $permission). - &Apache::loncommon::end_page()); + $permission,$crstype)); } else { - $r->print(&header(). - ''.&mt('You do not have permission to modify dates or sections for users').''. - &Apache::loncommon::end_page()); + $r->print(&header(undef,{'no_nav_bar' => 1}). + ''.&mt('You do not have permission to modify dates or sections for users').''); } } elsif ($env{'form.action'} eq 'selfenroll') { - $r->print(&header()); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=selfenroll', - text=>"Configure Self-enrollment"}); + push(@{$brcrum}, + {href => '/adm/createuser?action=selfenroll', + text => "Configure Self-enrollment", + help => 'Course_Self_Enrollment'}); if (!exists($env{'form.state'})) { - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment', - 'Course_Self_Enrollment')); + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => 'Configure Self-enrollment'}; + $r->print(&header(undef,$args)); $r->print('

'.&mt('Self-enrollment with a student role').'

'."\n"); &print_selfenroll_menu($r,$context,$permission); } elsif ($env{'form.state'} eq 'done') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=selfenroll', - text=>"Result"}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result', - 'Course_Self_Enrollment')); + push (@{$brcrum}, + {href=>'/adm/createuser?action=selfenroll', + text=>"Result"}); + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => 'Self-enrollment result'}; + $r->print(&header(undef,$args)); $r->print('

'.&mt('Self-enrollment with a student role').'

'."\n"); &update_selfenroll_config($r,$context,$permission); } - $r->print(&Apache::loncommon::end_page()); } elsif ($env{'form.action'} eq 'selfenrollqueue') { - $r->print(&header()); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=selfenrollqueue', - text=>"Enrollment requests"}); + push(@{$brcrum}, + {href => '/adm/createuser?action=selfenrollqueue', + text => 'Enrollment requests', + help => 'Course_Self_Enrollment'}); + $bread_crumbs_component = 'Enrollment requests'; + if ($env{'form.state'} eq 'done') { + push(@{$brcrum}, + {href => '/adm/createuser?action=selfenrollqueue', + text => 'Result', + help => 'Course_Self_Enrollment'}); + $bread_crumbs_component = 'Enrollment result'; + } + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + $r->print(&header(undef,$args)); my $cid = $env{'request.course.id'}; my $cdom = $env{'course.'.$cid.'.domain'}; my $cnum = $env{'course.'.$cid.'.num'}; my $coursedesc = $env{'course.'.$cid.'.description'}; if (!exists($env{'form.state'})) { - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment requests', - 'Course_SelfEnrollment_Approval')); $r->print('

'.&mt('Pending enrollment requests').'

'."\n"); $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context, $cdom,$cnum)); - } elsif ($env{'form.state'} eq 'done') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=selfenrollqueue', - text=>"Result"}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment result', - 'Course_Self_Enrollment')); $r->print('

'.&mt('Enrollment request processing').'

'."\n"); $r->print(&Apache::loncoursequeueadmin::update_request_queue($context, $cdom,$cnum,$coursedesc)); } - $r->print(&Apache::loncommon::end_page()); } elsif ($env{'form.action'} eq 'changelogs') { - $r->print(&header()); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/createuser?action=changelogs', - text=>"User Management Logs"}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes', - 'Course_User_Logs')); - &print_userchangelogs_display($r,$context,$permission); - $r->print(&Apache::loncommon::end_page()); + push (@{$brcrum}, + {href => '/adm/createuser?action=changelogs', + text => 'User Management Logs', + help => 'Course_User_Logs'}); + $bread_crumbs_component = 'User Changes'; + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + $r->print(&header(undef,$args)); + &print_userchangelogs_display($r,$context,$permission); } else { - $r->print(&header()); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); - $r->print(&print_main_menu($permission,$context)); - $r->print(&Apache::loncommon::end_page()); + $bread_crumbs_component = 'User Management'; + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + $r->print(&header(undef,$args)); + $r->print(&print_main_menu($permission,$context,$crstype)); } + $r->print(&Apache::loncommon::end_page()); return OK; } sub header { - my ($jscript,$loaditems,$args) = @_; + my ($jscript,$args) = @_; my $start_page; - if (ref($loaditems) eq 'HASH') { - $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems}); - } else { + if (ref($args) eq 'HASH') { $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args); + } else { + $start_page=&Apache::loncommon::start_page('User Management',$jscript); } return $start_page; } sub add_script { my ($js) = @_; - return ''."\n"; + return ''."\n"; } sub verify_user_display { @@ -4006,123 +4365,226 @@ END ############################################################### # Menu Phase One sub print_main_menu { - my ($permission,$context) = @_; + my ($permission,$context,$crstype) = @_; + my $linkcontext = $context; + my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype)); + if (($context eq 'course') && ($crstype eq 'Community')) { + $linkcontext = lc($crstype); + $stuterm = 'Members'; + } my %links = ( - domain => { - upload => 'Upload a File of Users', - singleuser => 'Add/Modify a Single User', - listusers => 'Manage Multiple Users', - }, - author => { - upload => 'Upload a File of Co-authors', - singleuser => 'Add/Modify a Single Co-author', - listusers => 'Display Co-authors and Manage Multiple Users', - }, - course => { - upload => 'Upload a File of Course Users', - singleuser => 'Add/Modify a Single Course User', - listusers => 'Display Class Lists and Manage Multiple Users', - }, + domain => { + upload => 'Upload a File of Users', + singleuser => 'Add/Modify a User', + listusers => 'Manage Users', + }, + author => { + upload => 'Upload a File of Co-authors', + singleuser => 'Add/Modify a Co-author', + listusers => 'Manage Co-authors', + }, + course => { + upload => 'Upload a File of Course Users', + singleuser => 'Add/Modify a Course User', + listusers => 'List and Modify Multiple Course Users', + }, + community => { + upload => 'Upload a File of Community Users', + singleuser => 'Add/Modify a Community User', + listusers => 'List and Modify Multiple Community Users', + }, + ); + my %linktitles = ( + domain => { + singleuser => 'Add a user to the domain, and/or a course or community in the domain.', + listusers => 'Show and manage users in this domain.', + }, + author => { + singleuser => 'Add a user with a co- or assistant author role.', + listusers => 'Show and manage co- or assistant authors.', + }, + course => { + singleuser => 'Add a user with a certain role to this course.', + listusers => 'Show and manage users in this course.', + }, + community => { + singleuser => 'Add a user with a certain role to this community.', + listusers => 'Show and manage users in this community.', + }, ); + my @menu = ( {categorytitle => 'Single Users', + items => + [ + { + linktext => $links{$linkcontext}{'singleuser'}, + icon => 'edit-redo.png', + #help => 'Course_Change_Privileges', + url => '/adm/createuser?action=singleuser', + permission => $permission->{'cusr'}, + linktitle => $linktitles{$linkcontext}{'singleuser'}, + }, + ]}, - my @menu = - ( - { text => $links{$context}{'upload'}, - help => 'Course_Create_Class_List', - action => 'upload', - permission => $permission->{'cusr'}, + {categorytitle => 'Multiple Users', + items => + [ + { + linktext => $links{$linkcontext}{'upload'}, + icon => 'uplusr.png', + #help => 'Course_Create_Class_List', + url => '/adm/createuser?action=upload', + permission => $permission->{'cusr'}, + linktitle => 'Upload a CSV or a text file containing users.', + }, + { + linktext => $links{$linkcontext}{'listusers'}, + icon => 'mngcu.png', + #help => 'Course_View_Class_List', + url => '/adm/createuser?action=listusers', + permission => ($permission->{'view'} || $permission->{'cusr'}), + linktitle => $linktitles{$linkcontext}{'listusers'}, }, - { text => $links{$context}{'singleuser'}, - help => 'Course_Change_Privileges', - action => 'singleuser', - permission => $permission->{'cusr'}, + + ]}, + + {categorytitle => 'Administration', + items => [ ]}, + ); + + if ($context eq 'domain'){ + + push(@{ $menu[2]->{items} }, #Category: Administration + { + linktext => 'Custom Roles', + icon => 'emblem-photos.png', + #help => 'Course_Editing_Custom_Roles', + url => '/adm/createuser?action=custom', + permission => $permission->{'custom'}, + linktitle => 'Configure a custom role.', }, - { text => $links{$context}{'listusers'}, - help => 'Course_View_Class_List', - action => 'listusers', - permission => ($permission->{'view'} || $permission->{'cusr'}), - }, ); - if ($context eq 'domain' || $context eq 'course') { - my $customlink = { text => 'Edit Custom Roles', - help => 'Course_Editing_Custom_Roles', - action => 'custom', - permission => $permission->{'custom'}, - }; - push(@menu,$customlink); - } - if ($context eq 'course') { + + }elsif ($context eq 'course'){ my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity(); - my @courselinks = - ( - { text => 'Enroll a Single Student', - help => 'Course_Add_Student', - action => 'singlestudent', - permission => $permission->{'cusr'}, - }, - { text => 'Drop Students', - help => 'Course_Drop_Student', - action => 'drop', - permission => $permission->{'cusr'}, - }); - if (!exists($permission->{'cusr_section'})) { - push(@courselinks, - { text => 'Automated Enrollment Manager', - help => 'Course_Automated_Enrollment', - permission => (&Apache::lonnet::auto_run($cnum,$cdom) - && $permission->{'cusr'}), - url => '/adm/populate', - }, - { text => 'Configure User Self-enrollment', - help => 'Course_Self_Enrollment', - action => 'selfenroll', - permission => $permission->{'cusr'}, - }); - } + + my %linktext = ( + 'Course' => { + single => 'Add/Modify a Student', + drop => 'Drop Students', + groups => 'Course Groups', + }, + 'Community' => { + single => 'Add/Modify a Member', + drop => 'Drop Members', + groups => 'Community Groups', + }, + ); + + my %linktitle = ( + 'Course' => { + single => 'Add a user with the role of student to this course', + drop => 'Remove a student from this course.', + groups => 'Manage course groups', + }, + 'Community' => { + single => 'Add a user with the role of member to this community', + drop => 'Remove a member from this community.', + groups => 'Manage community groups', + }, + ); + + push(@{ $menu[0]->{items} }, #Category: Single Users + { + linktext => $linktext{$crstype}{'single'}, + #help => 'Course_Add_Student', + icon => 'list-add.png', + url => '/adm/createuser?action=singlestudent', + permission => $permission->{'cusr'}, + linktitle => $linktitle{$crstype}{'single'}, + }, + ); + + push(@{ $menu[1]->{items} }, #Category: Multiple Users + { + linktext => $linktext{$crstype}{'drop'}, + icon => 'edit-undo.png', + #help => 'Course_Drop_Student', + url => '/adm/createuser?action=drop', + permission => $permission->{'cusr'}, + linktitle => $linktitle{$crstype}{'drop'}, + }, + ); + push(@{ $menu[2]->{items} }, #Category: Administration + { + linktext => 'Custom Roles', + icon => 'emblem-photos.png', + #help => 'Course_Editing_Custom_Roles', + url => '/adm/createuser?action=custom', + permission => $permission->{'custom'}, + linktitle => 'Configure a custom role.', + }, + { + linktext => $linktext{$crstype}{'groups'}, + icon => 'grps.png', + #help => 'Course_Manage_Group', + url => '/adm/coursegroups?refpage=cusr', + permission => $permission->{'grp_manage'}, + linktitle => $linktitle{$crstype}{'groups'}, + }, + { + linktext => 'Change Log', + icon => 'document-properties.png', + #help => 'Course_User_Logs', + url => '/adm/createuser?action=changelogs', + permission => $permission->{'cusr'}, + linktitle => 'View change log.', + }, + ); if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) { - push(@courselinks, - { text => 'Enrollment Requests', - help => 'Course_Approve_Selfenroll', - action => 'selfenrollqueue', - permission => $permission->{'cusr'}, - }); - } - push(@courselinks, - { text => 'Manage Course Groups', - help => 'Course_Manage_Group', - permission => $permission->{'grp_manage'}, - url => '/adm/coursegroups?refpage=cusr', - }, - { text => 'View Change Logs', - help => 'Course_User_Logs', - action => 'changelogs', + push(@{ $menu[2]->{items} }, + { + linktext => 'Enrollment Requests', + icon => 'selfenrl-queue.png', + #help => 'Course_Approve_Selfenroll', + url => '/adm/createuser?action=selfenrollqueue', + permission => $permission->{'cusr'}, + linktitle =>'Approve or reject enrollment requests.', + }, + ); + } + + if (!exists($permission->{'cusr_section'})){ + if ($crstype ne 'Community') { + push(@{ $menu[2]->{items} }, + { + linktext => 'Automated Enrollment', + icon => 'roles.png', + #help => 'Course_Automated_Enrollment', + permission => (&Apache::lonnet::auto_run($cnum,$cdom) + && $permission->{'cusr'}), + url => '/adm/populate', + linktitle => 'Automated enrollment manager.', + } + ); + } + push(@{ $menu[2]->{items} }, + { + linktext => 'User Self-Enrollment', + icon => 'self_enroll.png', + #help => 'Course_Self_Enrollment', + url => '/adm/createuser?action=selfenroll', permission => $permission->{'cusr'}, - },); + linktitle => 'Configure user self-enrollment.', + }, + ); + } + }; +return Apache::lonhtmlcommon::generate_menu(@menu); # { text => 'View Log-in History', # help => 'Course_User_Logins', # action => 'logins', # permission => $permission->{'cusr'}, # }); - push(@menu,@courselinks); - } - my $menu_html = ''; - foreach my $menu_item (@menu) { - next if (! $menu_item->{'permission'}); - $menu_html.='

'; - if (exists($menu_item->{'help'})) { - $menu_html.= - &Apache::loncommon::help_open_topic($menu_item->{'help'}); - } - $menu_html.=''; - if (exists($menu_item->{'url'})) { - $menu_html.=qq{}; - } else { - $menu_html.= - qq{}; } - $menu_html.= &mt($menu_item->{'text'}).''; - $menu_html.='

'; - } - return $menu_html; } sub restore_prev_selections { @@ -4138,6 +4600,7 @@ sub restore_prev_selections { sub print_selfenroll_menu { my ($r,$context,$permission) = @_; + my $crstype = &Apache::loncommon::course_type(); my $formname = 'enrollstudent'; my $nolink = 1; my ($row,$lt) = &get_selfenroll_titles(); @@ -4350,9 +4813,7 @@ ENDSCRIPT if (ref($lt) eq 'HASH') { $title = $lt->{$item}; } - $output .= - &Apache::lonhtmlcommon::row_title($title, - 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n"; + $output .= &Apache::lonhtmlcommon::row_title($title); if ($item eq 'types') { my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'}; my $showdomdesc = 1; @@ -4501,8 +4962,12 @@ ENDSCRIPT &mt('No').''; my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1); my (@ccs,%notified); - if ($advhash{'cc'}) { - @ccs = split(/,/,$advhash{'cc'}); + my $ccrole = 'cc'; + if ($crstype eq 'Community') { + $ccrole = 'co'; + } + if ($advhash{$ccrole}) { + @ccs = split(/,/,$advhash{$ccrole}); } if ($currnotified) { foreach my $current (split(/,/,$currnotified)) { @@ -4531,7 +4996,7 @@ ENDSCRIPT ''. &Apache::loncommon::plainname($ccuname,$ccudom). ''; - $count; + $count ++; } my $rem = $count%$numcols; if ($rem) { @@ -4548,7 +5013,7 @@ ENDSCRIPT my $cid = $env{'request.course.id'}; my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'}; my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'}; - my $nolimit = ' checked="checked" '; + $nolimit = ' checked="checked" '; if ($currlim eq 'allstudents') { $crslimit = ' checked="checked" '; $selflimit = ' '; @@ -4589,9 +5054,9 @@ sub visible_in_cat { my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom); my ($cathash,%settable,@vismsgs,$cansetvis); my %visactions = &Apache::lonlocal::texthash( - vis => 'Your course currently appears in the Course Catalog for this domain.', + vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.', gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.', - miss => 'Your course does not currently appear in the Course Catalog for this domain.', + miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.', yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.', coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.', make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:', @@ -4604,9 +5069,9 @@ sub visible_in_cat { dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain', dc_addcat => 'Ask a domain coordinator to assign a category to the course.', ); - $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"','"'); - $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"','"'); - $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','"','"'); + $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','','"'); + $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"','"'); + $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"','"'); if (ref($domconf{'coursecategories'}) eq 'HASH') { if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') { $settable{'togglecats'} = 1; @@ -4807,10 +5272,10 @@ sub print_userchangelogs_display { my $formname = 'roleslog'; my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $crstype = &Apache::loncommon::course_type(); my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum); if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); } - $r->print('
'); my %saveable_parameters = ('show' => 'scalar',); &Apache::loncommon::store_course_settings('roles_log', \%saveable_parameters); @@ -4845,14 +5310,6 @@ sub print_userchangelogs_display { } my (%whodunit,%changed,$version); ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/); - $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version)); - my $showntablehdr = 0; - my $tablehdr = &Apache::loncommon::start_data_table(). - &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(); my ($minshown,$maxshown); $minshown = 1; my $count = 0; @@ -4862,6 +5319,30 @@ sub print_userchangelogs_display { $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'}; } } + + # Form Header + $r->print(''. + &role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype)); + + # Create navigation + my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records); + my $showntableheader = 0; + + # 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(); + + # Display user change log data foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) { next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) || ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'})); @@ -4883,9 +5364,13 @@ sub print_userchangelogs_display { } $count ++; next if ($count < $minshown); - if (!$showntablehdr) { - $r->print($tablehdr); - $showntablehdr = 1; + unless ($showntableheader) { + $r->print($nav_script + .$nav_links + .&Apache::loncommon::start_data_table() + .$tableheader); + $r->rflush(); + $showntableheader = 1; } if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') { $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} = @@ -4921,24 +5406,49 @@ sub print_userchangelogs_display { if ($roleslog{$id}{'logentry'}{'selfenroll'}) { $chgcontext = 'selfenroll'; } - my %lt = &rolechg_contexts(); + my %lt = &rolechg_contexts($crstype); if ($chgcontext ne '' && $lt{$chgcontext} ne '') { $chgcontext = $lt{$chgcontext}; } - $r->print(&Apache::loncommon::start_data_table_row().''.$count.''.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).''.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.''.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.''.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'}).''.$sec.''.$chgcontext.''.$rolestart.''.$roleend.''.&Apache::loncommon::end_data_table_row()."\n"); + $r->print( + &Apache::loncommon::start_data_table_row() + .''.$count.'' + .''.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'' + .''.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'' + .''.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'' + .''.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'' + .''.$sec.'' + .''.$chgcontext.'' + .''.$rolestart.'' + .''.$roleend.'' + .&Apache::loncommon::end_data_table_row()."\n"); + } + + if ($showntableheader) { # Table footer, if content displayed above + $r->print(&Apache::loncommon::end_data_table() + .$nav_links); + } else { # No content displayed above + $r->print('

' + .&mt('There are no records to display.') + .'

' + ); } - if ($showntablehdr) { - $r->print(&Apache::loncommon::end_data_table().'
'); - if (($curr{'page'} > 1) || ($more_records)) { - $r->print(''); - if ($curr{'page'} > 1) { - $r->print(''); - } - if ($more_records) { - $r->print(''); - } - $r->print('
'.&mt('Previous [_1] changes',$curr{'show'}).''.&mt('Next [_1] changes',$curr{'show'}).'
'); - $r->print(<<"ENDSCRIPT"); + + # Form Footer + $r->print( + '' + .'' + .'
'); + return; +} + +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 + $nav_links = '

'; + if (($curr->{'page'} > 1) || ($more_records)) { + if ($curr->{'page'} > 1) { + $nav_links .= ' '; + } + if ($more_records) { + $nav_links .= ''; + } } - } else { - $r->print('

'. - &mt('There are no records to display'). - '

'); + $nav_links .= '

'; } - $r->print(''. - ''); - 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 = ''. + my %lt = &rolechg_contexts($crstype); + $output .= ''. + ''. ''. + ''. + ''."\n". ' '."\n". ' '."\n"; - if ($role eq 'cc') { + if (($role eq 'cc') || ($role eq 'co')) { $row .= ''; } elsif ($env{'request.course.sec'} ne '') { $row .= ' '. + ''. &Apache::loncommon::end_data_table_header_row(); my $otheritems = &Apache::loncommon::start_data_table_row()."\n". - ''."\n". - ''."\n". + ''. + ''. + ''. '
'. ''.&mt('Changes/page:').'
'. @@ -4982,23 +5503,27 @@ 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(); - $output .= '
'.&mt('Window during which changes occurred:').'
'.&mt('After:'). - ''.$startform.'
'.&mt('Before:').''. - $endform.'
  '.&mt('Window during which changes occurred:').'
'. + ''. + ''. + '
'.&mt('After:'). + ''.$startform.'
'.&mt('Before:').''.$endform.'
'. + '
  '.&mt('Role:').'
'. '
  '. + $output .= '  '. &mt('Context:').'
'.$plrole.''.$area.'
Domain: '.$domain.'
 '. ''. ''; - my $courseform=''.&Apache::loncommon::selectcourse_link - ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').''; - my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu'); + my $courseform=&Apache::loncommon::selectcourse_link + ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype'); + my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser'); my %lt=&Apache::lonlocal::texthash( 'rol' => "Role", 'grs' => "Section", @@ -5667,16 +6219,18 @@ sub course_level_dc { 'sta' => "Start", 'end' => "End", 'ssd' => "Set Start Date", - 'sed' => "Set End Date" + 'sed' => "Set End Date", + 'scc' => "Course/Community" ); - 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'}.''.$lt{'scc'}.''.$lt{'rol'}.''.$lt{'grs'}.''.$lt{'sta'}.''.$lt{'end'}.'
'. + $courseform.(' ' x4).'

 '.$lt{'new'}.'
'. ''. ''. - '
'; $otheritems .= < +
$lt{'ssd'} - +
$lt{'sed'} ENDTIMEENTRY @@ -5766,7 +6321,8 @@ sub update_selfenroll_config { $newnum ++; } } - for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) { + for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { + if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) { my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j); if (@types > 0) { @types = sort(@types); @@ -5966,7 +6522,7 @@ sub update_selfenroll_config { if ($currlimit eq 'allstudents') { $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap); } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') { - $newval = &mt('New self-enrollment no longer allowed when total umber of self-enrolled students reaches [_1].',$newcap); + $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap); } } $r->print('
  • '.&mt('"[_1]" set to "[_2]".',$title,$newval).'
  • '."\n"); @@ -6069,6 +6625,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