--- loncom/auth/lonroles.pm 2009/10/26 21:16:38 1.236 +++ loncom/auth/lonroles.pm 2009/12/15 05:04:17 1.240.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.236 2009/10/26 21:16:38 raeburn Exp $ +# $Id: lonroles.pm,v 1.240.2.3 2009/12/15 05:04:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,6 +138,7 @@ use Apache::lonannounce; use Apache::lonlocal; use Apache::lonpageflip(); use Apache::lonnavdisplay(); +use Apache::lonmainmenu(); use GDBM_File; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; @@ -224,6 +225,7 @@ sub handler { my %dcroles = (); my $numdc = &check_fordc(\%dcroles,$then); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + my $custommenu = &Apache::loncommon::needs_gci_custom(); # ================================================================== Roles Init if ($env{'form.selectrole'}) { @@ -255,12 +257,12 @@ sub handler { # Check if user is a DC trying to enter a course or author space and needs privs to be created if ($numdc > 0) { foreach my $envkey (keys %env) { -# Is this an ad-hoc CC-role? - if (my ($domain,$coursenum) = - ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) { +# Is this an ad-hoc Coordinator role? + if (my ($ccrole,$domain,$coursenum) = + ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { &Apache::lonnet::check_adhoc_privs($domain,$coursenum, - $then,$refresh,$now,'cc'); + $then,$refresh,$now,$ccrole); } last; } @@ -318,7 +320,9 @@ sub handler { } } } - + if (($env{'form.cm'}) && ($env{'form.orgurl'})) { + $r->internal_redirect($env{'form.orgurl'}); + } foreach $envkey (keys %env) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); @@ -491,8 +495,8 @@ ENDENTERKEY $courseid = substr($courseid, 1); } $courseid =~ s/\//_/; - if ($role eq 'cc' && $env{'course.' . $courseid . - '.course.helper.not.run'}) { + if (($cdom ne 'gcitest') && (($role eq 'cc') || ($role eq 'co')) + && ($env{'course.' . $courseid .'.course.helper.not.run'})) { $furl = "/adm/helper/course.initialization.helper"; # Send the user to the course they selected } elsif ($env{'request.course.id'}) { @@ -515,7 +519,7 @@ ENDENTERKEY .$env{'request.course.sec'}) ) { my $startpage = &courseloadpage($courseid); - unless ($startpage eq 'firstres') { + unless (($startpage eq 'firstres') || ($cdom eq 'gcitest')) { $msg = &mt('Entering [_1] ...', $env{'course.'.$courseid.'.description'}); &redirect_user($r,&mt('New in course'), @@ -530,6 +534,9 @@ ENDENTERKEY # Guess not ... $furl=&Apache::lonpageflip::first_accessible_resource(); } + if (($cdom eq 'gcitest') && ($custommenu)) { + $furl = '/adm/navmaps'; + } $msg = &mt('Entering [_1] ...', $env{'course.'.$courseid.'.description'}); &redirect_user($r,&mt('Entering [_1]', @@ -572,7 +579,6 @@ ENDENTERKEY } } - # =============================================================== No Roles Init &Apache::loncommon::content_type($r,'text/html'); @@ -580,23 +586,34 @@ ENDENTERKEY $r->send_http_header; return OK if $r->header_only; - my $crumbtext = 'User Roles'; - my $pagetitle = 'My Roles'; - my $recent = &mt('Recent Roles'); - my $show_course=&Apache::loncommon::show_course(); - if ($show_course) { - $crumbtext = 'Courses'; - $pagetitle = 'My Courses'; - $recent = &mt('Recent Courses'); - } - my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}]; - my $swinfo=&Apache::lonmenu::rawconfig(); - my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum}); - my $standby=&mt('Role selected. Please stand by.'); - $standby=~s/\n/\\n/g; + my ($crumbtext,$pagetitle,$recent,$show_course); my $noscript=''.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').''.&mt('As this is not the case, most functionality in the system will be unavailable.').''; - - $r->print(< 1}); + $r->print(<<"ENDCUSTOM"); +$start_page + + +$noscript + +ENDCUSTOM + } else { + $crumbtext = 'User Roles'; + $pagetitle = 'My Roles'; + $recent = &mt('Recent Roles'); + $show_course=&Apache::loncommon::show_course(); + if ($show_course) { + $crumbtext = 'Courses'; + $pagetitle = 'My Courses'; + $recent = &mt('Recent Courses'); + } + my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}]; + my $swinfo=&Apache::lonmenu::rawconfig(); + my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum}); + my $standby=&mt('Role selected. Please stand by.'); + $standby=~s/\n/\\n/g; + $r->print(< @@ -623,6 +640,7 @@ function enterrole (thisform,rolecode,bu // ]]> ENDHEADER + } # ------------------------------------------ Get Error Message from Environment @@ -690,10 +708,12 @@ ENDHEADER if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; } - $r->print(''); - $r->print(''); - $r->print(''); - $r->print(''); + unless ($custommenu) { + $r->print(''); + $r->print(''); + $r->print(''); + $r->print(''); + } } my (%roletext,%sortrole,%roleclass,%futureroles,%timezones); @@ -703,11 +723,38 @@ ENDHEADER $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); + if ($custommenu) { + my %courses = &Apache::loncommon::existing_gcitest_courses(); + $env{'browser.interface'}='faketextual'; + $env{'environment.remote'}='off'; + my $numcourses = keys(%courses); + my $switcher; + if ($numcourses > 0) { + $switcher = &Apache::lonmainmenu::gcitest_switcher(%courses); + my $current; + if ($env{'request.course.id'}) { + $current = 'cc./'.$env{'course.'.$env{'request.course.id'}.'.domain'}. + '/'.$env{'course.'.$env{'request.course.id'}.'.num'}; + } + my $switcher_js = &Apache::lonmainmenu::gcitest_switcher_js($current,$numcourses); + $r->print(<<"ENDSCRIPT"); + +ENDSCRIPT + } + $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher). + &Apache::loncommon::end_page()); + return OK; + } if ($env{'user.adv'}) { - $r->print( - ''.&mt('Show all roles').': print('print(' checked="checked" '); } - $r->print(' />'); + $r->print(' />'.&mt('Show all roles').'' + .' ' + .''); } else { if ($countactive > 0) { &queued_selfenrollment($r); @@ -766,6 +813,27 @@ ENDHEADER } $r->print(&Apache::loncommon::end_page()); return OK; + } elsif ($countactive==1) { # Is there only one choice? + my $needs_switchserver; + if ($env{'user.author'}) { + $needs_switchserver = &check_needs_switchserver($possiblerole); + } + if ((!$needs_switchserver) && ($env{'request.role'} eq 'cm')) { + $r->print(''.&mt('Please stand by.').''. + ''. + ''); + $r->print("\n"); + $r->rflush(); + $r->print(''); + $r->print(&Apache::loncommon::end_page()); + return OK; + } + if ($needs_switchserver) { + $r->print("".&mt('Server Switch Required')."\n". + &mt('Construction Space access is only available from '. + 'the home server of the corresponding Author.').''. + &mt("Click the 'Switch Server' link to go there.").''); + } } # ----------------------------------------------------------------------- Table unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) { @@ -1109,7 +1177,7 @@ sub roletable_headers { } sub roletypes { - my @types = ('Domain','Construction Space','Course','Unavailable','System'); + my @types = ('Domain','Construction Space','Course','Community','Unavailable','System'); return @types; } @@ -1188,14 +1256,20 @@ sub requestcourse_advice { my ($types,$typename) = &Apache::loncommon::course_types(); if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { $r->print(''.&mt('Request creation of a course or community').''. - ''.&mt('You have rights to create courses and/or communities in the following domain(s):').''); + ''.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').''); my (@reqdoms,@reqtypes); foreach my $type (sort(keys(%request_doms))) { push(@reqtypes,$type); if (ref($request_doms{$type}) eq 'ARRAY') { my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}})); - $r->print(&mt('[_1] in domain: [_2]', - ''.$typename->{$type}.'',''.$domstr.'')); + $r->print( + '' + .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]', + '', + '', + ''.$domstr.'') + .'' + ); foreach my $dom (@{$request_doms{$type}}) { unless (grep(/^\Q$dom\E/,@reqdoms)) { push(@reqdoms,$dom); @@ -1447,10 +1521,11 @@ sub check_fordc { sub adhoc_course_role { my ($refresh,$then) = @_; - my ($cdom,$cnum); + my ($cdom,$cnum,$crstype); $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - if (&check_forcc($cdom,$cnum,$refresh,$then)) { + $crstype = &Apache::loncommon::course_type(); + if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) { my $setprivs; if (!defined($env{'user.role.'.$env{'form.switchrole'}})) { $setprivs = 1; @@ -1500,11 +1575,16 @@ sub adhoc_course_role { } sub check_forcc { - my ($cdom,$cnum,$refresh,$then) = @_; - my $is_cc; + my ($cdom,$cnum,$refresh,$then,$crstype) = @_; + my ($is_cc,$ccrole); + if ($crstype eq 'Community') { + $ccrole = 'co'; + } else { + $ccrole = 'cc'; + } if ($cdom ne '' && $cnum ne '') { if (&Apache::lonnet::is_course($cdom,$cnum)) { - my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum; + my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum; if (defined($env{$envkey})) { $is_cc = 1; my ($tstart,$tend)=split(/\./,$env{$envkey}); @@ -1521,7 +1601,7 @@ sub courselink { my $courseform=&Apache::loncommon::selectcourse_link ('rolechoice','dccourse'.$rowtype.'_'.$dcdom, 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'. - $dcdom,$dcdom,undef); + $dcdom,$dcdom,undef,'Course/Community'); my $hiddenitems = ''. ''. ''. @@ -1531,7 +1611,7 @@ sub courselink { sub coursepick_jscript { my %lt = &Apache::lonlocal::texthash( - plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course or community you wish to enter.", + plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.", youc => 'You can only use this screen to select courses and communities in the current domain.', ); my $verify_script = <<"END"; @@ -1584,9 +1664,10 @@ sub display_cc_role { my $advanced = $env{'user.adv'}; my $tryagain = $env{'form.tryagain'}; unless ($rolekey =~/^error\:/) { - if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) { - my $tcourseid = $1.'_'.$2; - my $trolecode = 'cc./'.$1.'/'.$2; + if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) { + my $ccrole = $1; + my $tcourseid = $2.'_'.$3; + my $trolecode = $1.'./'.$2.'/'.$3; my $twhere; my $ttype; my $tbg='LC_roles_is'; @@ -1601,7 +1682,7 @@ sub display_cc_role { $twhere=&mt('Currently not available'); $env{'course.'.$tcourseid.'.description'}=$twhere; } - my $trole = &Apache::lonnet::plaintext('cc',$ttype); + my $trole = &Apache::lonnet::plaintext($ccrole,$ttype); $twhere.="".&mt('Domain').":".$1; ($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,''); } @@ -1617,7 +1698,7 @@ sub adhoc_roles_row { ,'','',$dcdom) .' '; my $selectcclink = &courselink($dcdom,$rowtype); - my $ccrole = &Apache::lonnet::plaintext('cc'); + my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1); my $carole = &Apache::lonnet::plaintext('ca'); my $selectcalink = &coauthorlink($dcdom,$rowtype); $output.=$ccrole.': '.$selectcclink
'.&mt('Show all roles').': print('print(' checked="checked" '); } - $r->print(' />'); + $r->print(' />'.&mt('Show all roles').'' + .' ' + .'
print(' checked="checked" '); } - $r->print(' />
'.&mt('You have rights to create courses and/or communities in the following domain(s):').'
'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'