[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /auth lonroles.pm

raeburn raeburn at source.lon-capa.org
Mon Aug 27 07:48:24 EDT 2012


raeburn		Mon Aug 27 11:48:24 2012 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/auth	lonroles.pm 
  Log:
  - For 2.11.
    - Backport 1.270, 1.271, 1.272, 1.273, 1.274, 1.275.
  
  
-------------- next part --------------
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.269.2.1 loncom/auth/lonroles.pm:1.269.2.2
--- loncom/auth/lonroles.pm:1.269.2.1	Fri Aug  3 17:35:39 2012
+++ loncom/auth/lonroles.pm	Mon Aug 27 11:48:24 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.269.2.1 2012/08/03 17:35:39 raeburn Exp $
+# $Id: lonroles.pm,v 1.269.2.2 2012/08/27 11:48:24 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -217,9 +217,17 @@
         $update = $then;
     }
 
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+
+# -------------------------------------------------- Check if setting hot list
+    my $hotlist;
+    if ($env{'form.action'} eq 'verify_and_change_rolespref') {
+        $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
+    }
+
 # -------------------------------------------------------- Check for new roles
     my $updateresult;
-    if ($env{'form.doupdate'}) {
+    if ($env{'form.state'} eq 'doupdate') {
         my $show_course=&Apache::loncommon::show_course();
         my $checkingtxt;
         if ($show_course) {
@@ -227,16 +235,22 @@
         } else {
             $checkingtxt = &mt('Checking for new roles ...');
         }
-        $updateresult = '<span class="LC_info">'.$checkingtxt.'</span>';
+        $updateresult = $checkingtxt;
         $updateresult .= &update_session_roles();
         &Apache::lonnet::appenv({'user.update.time'  => $now});
         $update = $now;
+        &Apache::loncoursequeueadmin::reqauthor_check();
+    }
+
+# -------------------------------------------------- Check for author requests
+    my $reqauthor;
+    if ($env{'form.state'} eq 'requestauthor') {
+       $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
     }
 
     my $envkey;
     my %dcroles = ();
     my $numdc = &check_fordc(\%dcroles,$update,$then);
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
     my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
 
 # ================================================================== Roles Init
@@ -283,8 +297,10 @@
                 if (my ($ccrole,$domain,$coursenum) =
 		    ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
                     if ($dcroles{$domain}) {
-                        &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
-                                                           $update,$refresh,$now,$ccrole);
+                        if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+                                                           $update,$refresh,$now,$ccrole)) {
+                            &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
+                        }
                     }
                     last;
                 }
@@ -507,6 +523,12 @@
                         my $msg;
 			my ($furl,$ferr)=
 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+                        unless (($ferr) || ($env{'form.switchrole'}) ||
+                                ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
+                            &Apache::lonnet::put('nohist_crslastlogin',
+                                {$env{'user.name'}.':'.$env{'user.domain'}.
+                                ':'.$csec.':'.$role => $now},$cdom,$cnum);
+                        }
 			if (($env{'form.orgurl'}) && 
 			    ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
 			    my $dest=$env{'form.orgurl'};
@@ -653,15 +675,20 @@
         $recent = &mt('Recent Courses');
     }
     my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
+
+    my %roles_in_env;
+    my $showcount = &roles_from_env(\%roles_in_env,$update); 
+
     my $swinfo=&Apache::lonmenu::rawconfig();
     my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
+    my $funcs = &get_roles_functions($showcount);
     my $standby=&mt('Role selected. Please stand by.');
     $standby=~s/\n/\\n/g;
-    my $noscript='<span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
+    my $noscript='<br /><span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
 
     $r->print(<<ENDHEADER);
 $start_page
-<br />
+$funcs
 <noscript>
 $noscript
 </noscript>
@@ -684,10 +711,17 @@
     }
 }
 
-function setToUpdate(thisform) {
-    thisform.doupdate.value='1';
-    thisform.selectrole.value='';
-    thisform.submit();
+function rolesView (caller) {
+    if ((caller == 'showall') || (caller == 'noshowall')) {
+        document.rolechoice.display.value = caller;
+    } else {
+        if ((caller == 'doupdate') || (caller == 'requestauthor') ||
+            (caller == 'queued')) {
+            document.rolechoice.state.value = caller;
+        }
+    }
+    document.rolechoice.selectrole.value='';
+    document.rolechoice.submit();
 }
 
 // ]]>
@@ -756,55 +790,43 @@
 		  &Apache::loncommon::end_page());
 	return OK;
     } else {
-        $r->print($updateresult); 
+        if ($updateresult || $reqauthor || $hotlist) {
+            my $showresult = '<div>';
+            if ($updateresult) {
+                $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
+            }
+            if ($reqauthor) {
+                $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
+            }
+            if ($hotlist) {
+                $showresult .= $hotlist;
+            }
+            $showresult .= '</div>';
+            $r->print($showresult);
+        } elsif ($env{'form.state'} eq 'queued') {
+            $r->print(&get_queued());
+        }
         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
         }
+        my $display = ($env{'form.display'} =~ /^(showall)$/);
         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
         $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
         $r->print('<input type="hidden" name="selectrole" value="1" />');
         $r->print('<input type="hidden" name="newrole" value="" />');
+        $r->print('<input type="hidden" name="display" value="'.$display.'" />');
+        $r->print('<input type="hidden" name="state" value="" />');
     }
     $r->rflush();
 
     my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
     my ($countactive,$countfuture,$inrole,$possiblerole) = 
-        &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
-                      \%futureroles,\%timezones,$loncaparev);
+        &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
+                      \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
     $refresh = $now;
     &Apache::lonnet::appenv({'user.refresh.time'  => $refresh});
-    my $updatebutton = &mt('Check for role changes');
-    my $show_course=&Apache::loncommon::show_course();
-    if ($show_course) {
-        $updatebutton = &mt('Check for new courses');
-    }
-    my $do_update;
-    unless (($env{'form.source'} eq 'login') || ($env{'form.doupdate'})) {
-        $do_update = '<input type="hidden" name="doupdate" value="" />'.
-                     '<input type="button" name="update" value="'.
-                     $updatebutton.'" onclick="javascript:setToUpdate(this.form)" />';
-    }
-    if ($env{'user.adv'}) {
-        my $showall = '<label><input type="checkbox" name="showall"';
-        if ($env{'form.showall'}) { 
-            $showall .= ' checked="checked" ';
-        }
-        $showall .= ' />'.&mt('Show all roles').'</label> '.
-                    '<input type="submit" value="'.&mt('Update display').'" />';
-        if ($do_update) {
-            $r->print('<div class="LC_left_float"><fieldset>'.
-                      '<legend>'. &mt('Display').'</legend>'.
-                      $showall.'</fieldset></div>'.
-                      '<div class="LC_left_float"><fieldset><legend>'.
-                      &mt('Changes?').'</legend>'.
-                      $do_update.'</fieldset></div><br clear="all" />');
-        } else {
-            $r->print($showall);
-        }
-    } else {
-        $r->print('<p>'.$do_update.'</p>');
+    unless ($env{'user.adv'}) {
         if ($countactive > 0) {
-            $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
             my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
             my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); 
             $r->print(
@@ -982,19 +1004,38 @@
     return OK;
 }
 
+sub roles_from_env {
+    my ($roleshash,$update) = @_;
+    my $count = 0;
+    if (ref($roleshash) eq 'HASH') {
+        foreach my $envkey (keys(%env)) {
+            if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
+                next if ($1 eq 'gr');
+                $roleshash->{$envkey} = $env{$envkey};
+                my ($start,$end) = split(/\./,$env{$envkey});
+                unless ($end && $end<$update) {
+                    $count ++;
+                }
+            }
+        }
+    }
+    return $count;
+}
+
 sub gather_roles {
-    my ($update,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
+    my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
+        $timezones,$loncaparev) = @_;
     my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
     my $advanced = $env{'user.adv'};
     my $tryagain = $env{'form.tryagain'};
     my @ids = &Apache::lonnet::current_machine_ids();
-    foreach my $envkey (sort(keys(%env))) {
-        my $button = 1;
-        my $switchserver='';
-        my $switchwarning;
-        my ($role_text,$role_text_end,$sortkey);
-        if ($envkey=~/^user\.role\./) {
-            my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
+    if (ref($roles_in_env) eq 'HASH') {
+        foreach my $envkey (sort(keys(%{$roles_in_env}))) {
+            my $button = 1;
+            my $switchserver='';
+            my $switchwarning;
+            my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
+                $tend,$tremark,$tstatus,$tpstart,$tpend);
             &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
                                          \$trolecode,\$tstatus,\$tstart,\$tend);
             next if (!defined($role) || $role eq '' || $role =~ /^gr/);
@@ -1008,7 +1049,7 @@
             if (($tstatus eq 'is')
                 || ($tstatus eq 'selected')
                 || ($tstatus eq 'future')
-                || ($env{'form.showall'})) {
+                || ($env{'form.display'} eq 'showall')) {
                 my $timezone = &role_timezone($where,$timezones);
                 if ($tstart) {
                     $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
@@ -1895,7 +1936,7 @@
         }
         if ($env{$envkey} eq '') {
             my $status_in_db =
-                &curr_role_status($tstart,$tend,$refresh,$now);
+                &curr_role_status($tstart,$tend,$now,$now);
                 &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
             if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
                 if ($status_in_db eq 'active') {
@@ -1939,7 +1980,7 @@
                 my $status_in_env =
                     &curr_role_status($currstart,$currend,$refresh,$update);
                 my $status_in_db =
-                    &curr_role_status($tstart,$tend,$refresh,$now);
+                    &curr_role_status($tstart,$tend,$now,$now);
                 if ($status_in_env ne $status_in_db) {
                     if ($status_in_env eq 'active') {
                         if ($role eq 'st') {
@@ -2141,7 +2182,7 @@
     }
     if (($oldsec) && (@newsec > 0)) {
         if (@newsec > 1) {
-            $msg = '<div class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</div>';
+            $msg = '<p class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</p>';
         } else {
             my $newrole = $env{'request.role'};
             if ($newsec[0] eq 'none') {
@@ -2179,13 +2220,13 @@
             $msg .= '</form></p>';
         }
     } elsif ($currrole_expired) {
-        $msg .= '<div class="LC_warning">';
+        $msg .= '<p class="LC_warning">';
         if (&Apache::loncommon::show_course()) {
             $msg .= &mt('Your role in the current course has expired.');
         } else {
             $msg .= &mt('Your current role has expired.');
         }
-        $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</div>';
+        $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</p>';
     }
     if (!@changed_roles || !(keys(%changed_groups))) {
         my ($rolesmsg,$groupsmsg);
@@ -2210,7 +2251,7 @@
                 }
                 $msg .= '</ul>';
             } else {
-                $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br /><br />';
+                $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
             }
             return $msg;
         }
@@ -2467,6 +2508,131 @@
     return $is_active;
 }
 
+sub get_roles_functions {
+    my ($rolescount) = @_;
+    my @links;
+    if ($env{'user.adv'}) {
+        if ($env{'form.display'} eq 'showall') {
+            push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired roles')]);
+        } else {
+            push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired roles')]);
+        }
+    }
+    push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
+    if ($env{'environment.canrequest.author'}) {
+        unless (&Apache::loncoursequeueadmin::is_active_author()) {
+            push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
+        }
+    }
+    if (&Apache::lonmenu::check_for_rcrs()) {
+        push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
+    }
+    if ($env{'form.state'} eq 'queued') {
+        push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
+    } else {
+        push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
+    }
+    if (($rolescount > 3) || ($env{'environment.recentroles'})) {
+        push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
+    }
+
+    my $funcs = &Apache::lonhtmlcommon::start_funclist();
+    foreach my $link (@links) {
+        $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
+                      '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
+                      '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
+                      $link->[2].'</a>');
+    }
+    $funcs .= &Apache::lonhtmlcommon::end_funclist();
+    return &Apache::loncommon::head_subbox($funcs);
+}
+
+sub get_queued {
+    my ($output,%reqcrs);
+    my ($types,$typenames) = &Apache::loncommon::course_types();
+    my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
+                                           $env{'user.name'},'^status:');
+    foreach my $key (keys(%statusinfo)) {
+        next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
+        (undef,my($cdom,$cnum)) = split(':',$key);
+        my $requestkey = $cdom.'_'.$cnum;
+        if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+            my %history = &Apache::lonnet::restore($requestkey,'courserequests',
+                                                   $env{'user.domain'},$env{'user.name'});
+            next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
+            my $reqtime = $history{'reqtime'};
+            my $lastupdate = $history{'timestamp'};
+            my $showtype = $history{'crstype'};
+            if (defined($typenames->{$history{'crstype'}})) {
+                $showtype = $typenames->{$history{'crstype'}};
+            }
+            my $description;
+            if (ref($history{'details'}) eq 'HASH') {
+                $description = $history{details}{'cdescr'};
+            }
+            @{$reqcrs{$reqtime}} = ($description,$showtype);
+        }
+    }
+    my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
+    if (@sortedtimes > 0) {
+        $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
+                   &Apache::loncommon::start_data_table().
+                   &Apache::loncommon::start_data_table_header_row().
+                   '<th>'.&mt('Date requested').'</th>'.
+                   '<th>'.&mt('Course title').'</th>'.
+                   '<th>'.&mt('Course type').'</th>';
+                   &Apache::loncommon::end_data_table_header_row();
+        foreach my $reqtime (@sortedtimes) {
+            next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
+            $output .= &Apache::loncommon::start_data_table_row().
+                       '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
+                       '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
+                       &Apache::loncommon::end_data_table_row();
+        }
+        $output .= &Apache::loncommon::end_data_table().
+                   '<br /></p>';
+    }
+    my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
+    if ($queuedselfenroll) {
+        $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
+                   $queuedselfenroll.'<br /></p>';
+    }
+    if ($env{'environment.canrequest.author'}) {
+        unless (&Apache::loncoursequeueadmin::is_active_author()) {
+            my $requestauthor;
+            my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
+            if (($status eq 'approval') || ($status eq 'approved')) {
+                $output .= '<p><b>'.&mt('Author role request').'</b><br />';
+                if ($status eq 'approval') {
+                    $output .= &mt('A request for authoring space submitted on [_1] is awaiting approval',
+                                  &Apache::lonlocal::locallocaltime($timestamp));
+                } elsif ($status eq 'approved') {
+                    my %roleshash =
+                        &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+                                                      ['active'],['au'],[$env{'user.domain'}]);
+                    if (keys(%roleshash)) {
+                        $output .= '<span class="LC_info">'.
+                                   &mt('Your request for an author role has been approved.').'<br />'.
+                                   &mt('Use the "Check for changes" link to update your list of roles.').
+                                   '</span>';
+                    }
+                }
+                $output .= '</p>';
+            }
+        }
+    }
+    unless ($output) {
+        if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
+            $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
+            $output = &mt('No requests for courses, communities or authoring currently queued');
+        } else {
+            $output = &mt('No enrollment requests currently queued awaiting approval');
+        }
+    }
+    return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
+           $output.'</fieldset></div><br clear="all" />';
+}
+
 1;
 __END__
 


More information about the LON-CAPA-cvs mailing list