--- loncom/interface/lonmenu.pm	2019/08/06 23:18:43	1.369.2.77
+++ loncom/interface/lonmenu.pm	2021/01/04 17:27:54	1.369.2.79.2.4
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.369.2.77 2019/08/06 23:18:43 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.79.2.4 2021/01/04 17:27:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -735,7 +735,7 @@ sub innerregister {
         $newmail= 'swmenu.setstatus("you have","messages");';
     }
 
-    my ($mapurl,$resurl,$crstype);
+    my ($mapurl,$resurl,$crstype,$navmap);
 
     if ($env{'request.course.id'}) {
 #
@@ -743,13 +743,25 @@ sub innerregister {
 #
         $crstype = &Apache::loncommon::course_type();
         if ($env{'request.symb'}) {
-            ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
+            my $ignorenull;
+            unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
+                $ignorenull = 1;
+            }
+            my $symb = &Apache::lonnet::symbread('','',$ignorenull);
+            ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
 
             my $maptitle = &Apache::lonnet::gettitle($mapurl);
-            my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
+            my $restitle = &Apache::lonnet::gettitle($symb);
 
-            my @crumbs;
+            my (@crumbs,@mapcrumbs);
+            if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
+                ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'})) {
+                $navmap = Apache::lonnavmaps::navmap->new();
+                if (ref($navmap)) {
+                    @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
+                }
+            }
             unless (($forcereg) && 
                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
@@ -757,15 +769,22 @@ sub innerregister {
                             href  => "Javascript:gopost('/adm/navmaps','')"});
             }
             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
-                push(@crumbs, {text  => '...',
-                               no_mt => 1});
+                if (@mapcrumbs) {
+                    push(@crumbs,@mapcrumbs);
+                } else {
+                    push(@crumbs, {text  => '...',
+                                   no_mt => 1});
+                }
             }
 
-            push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
-                                                       && $maptitle ne 'default.sequence' 
-                                                       && $maptitle ne $coursetitle);
-
-            push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
+            unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') ||
+                    ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
+                push @crumbs, {text => $maptitle, no_mt => 1,
+                               href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
+            }
+            if ($restitle && !@mapcrumbs) {
+                push(@crumbs,{text => $restitle, no_mt => 1});
+            }
             my @tools;
             if ($env{'request.filename'} =~ /\.page$/) {
                 my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
@@ -999,13 +1018,14 @@ if ($env{'browser.mobile'}) {
     $is_mobile = 1;
 }
 
-            unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
-		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
+            unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio|ext\.tool)(\?|$)/) {
+		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) &&
+                       ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)})) {
 		    $menuitems.=(<<ENDREALRES);
 s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info('$is_mobile')&Show Metadata
 ENDREALRES
                 }
-                unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
+                unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) ||
                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) { 
 	            $menuitems.=(<<ENDREALRES);
 s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
@@ -1508,11 +1528,12 @@ sub prepare_functions {
 # Determine whether or not to display 'Edit' or 'View Source' icon/button
 #
     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
+        my $blocked = &Apache::loncommon::blocking_status('about',$2,$1);
         my $file=&Apache::lonnet::declutter($env{'request.filename'});
         ($cfile,$home,$switchserver,$forceedit,$forceview) =
             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
-        if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
+        if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                                           $forceedit,$forceview,$forcereg);
         }
@@ -1537,7 +1558,8 @@ sub prepare_functions {
 #
         if (($perms{'mdc'}) &&
             (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
-            ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
+            ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) || 
+            (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
             if ($resurl =~ m{^/}) {
                 $cfile = $resurl;
             } else {
@@ -1549,9 +1571,17 @@ sub prepare_functions {
             } else {
                 $forceedit = 1;
             }
-            $editbutton = &get_editbutton($cfile,$home,$switchserver,
-                                          $forceedit,$forceview,$forcereg,
-                                          $hostname);
+            if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
+                my $text = 'Edit Folder';
+                &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
+                        "gocmd('/adm/coursedocs','direct')",
+                        'Folder/Page Content');
+                $editbutton = 1;
+            } else {
+                $editbutton = &get_editbutton($cfile,$home,$switchserver,
+                                              $forceedit,$forceview,$forcereg,
+                                              $hostname);
+            }
         } elsif (($resurl eq '/adm/extresedit') &&
                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
             ($cfile,$home,$switchserver,$forceedit,$forceview) =
@@ -1583,17 +1613,20 @@ sub prepare_functions {
                 if ((($cfile eq '') || (!$editbutton)) &&
                     ($resurl =~ /$LONCAPA::assess_re/)) {
                     my $showurl = &Apache::lonnet::clutter($resurl);
+                    my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
+                                                              ? "/$env{'request.course.sec'}"
+                                                              : '');
                     if ((&Apache::lonnet::allowed('cre','/')) &&
                         (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
                         $viewsrcbutton = 1;
-                    } elsif (&Apache::lonnet::allowed('vxc',$env{'request.course.id'})) {
+                    } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
                         if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
                             my $auname = $1;
                             if (($env{'request.course.adhocsrcaccess'} ne '') &&
                                 (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
                                 $viewsrcbutton = 1;
                             } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
-                                     (&Apache::lonnet::allowed('bre','/'))) {
+                                     (&Apache::lonnet::allowed('bre',$crs_sec))) {
                                 $viewsrcbutton = 1;
                             }
                         }
@@ -1613,10 +1646,13 @@ sub prepare_functions {
         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
             my ($sdom,$sname) = ($1,$2);
             unless (&Apache::lonnet::is_course($sdom,$sname)) {
-                &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
-                        '',
-                        "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
-                            'Send message to specific user','','',1);
+                my $blocked = &Apache::loncommon::blocking_status('about',$sname,$sdom);
+                unless ($blocked) {
+                    &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
+                            '',
+                            "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
+                                'Send message to specific user','','',1);
+                }
             }
             my $hideprivileged = 1;
             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
@@ -1651,6 +1687,7 @@ sub prepare_functions {
         if (($env{'form.folderpath'} =~ /^supplemental/) &&
             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
             (($resurl =~ m{^/adm/wrapper/ext/}) ||
+             ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
              ($resurl eq '/adm/supplemental') ||
              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
@@ -1679,7 +1716,7 @@ sub prepare_functions {
         &advtools_crumbs(@inlineremote);
         return $editbutton;
     } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
-        return $editbutton;
+        return $editbutton || $viewsrcbutton;
     } else {
         if (ref($bread_crumbs) eq 'ARRAY') {
             if (@inlineremote > 0) {
@@ -2161,6 +2198,220 @@ function toggleCountdown() {
 END
 }
 
+# This creates a "done button" for timed events.  The confirmation box is a jQuery
+# dialog widget. If the interval parameter requires a proctor key for the timed
+# event to be marked done, there will also be a textbox where that can be entered.
+# Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
+# set the value of LC_interval_done_proctorpass to the text entered in that box,
+# and submit the corresponding form.
+#
+# The &zero_time() routine in lonhomework.pm is called when a page is rendered if
+# LC_interval_done is true.
+#
+sub done_button_js {
+    my ($type,$width,$height,$proctor,$donebuttontext) = @_;
+    return unless (($type eq 'map') || ($type eq 'resource'));
+    my %lt = &Apache::lonlocal::texthash(
+                 title    => 'WARNING!',
+                 preamble => 'You are trying to end this timed event early.',
+                 map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
+                 resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
+                 okdone   => 'Click "OK" if you are completely finished.',
+                 cancel   => 'Click "Cancel" to continue working.',
+                 proctor  => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
+                 ok       => 'OK',
+                 exit     => 'Cancel',
+                 key      => 'Key:',
+                 nokey    => 'A proctor key is required',
+    );
+    my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    my ($missing,$tried) = (0,0);
+    if (ref($navmap)) {
+        my @resources=();
+        if ($type eq 'map') {
+            my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
+            if ($env{'request.symb'} =~ /\.page$/) {
+                @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
+            } else {
+                @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
+            }
+        } else {
+            my $res = $navmap->getBySymb($env{'request.symb'});
+            if (ref($res)) {
+                if ($res->is_problem()) {
+                    push(@resources,$res);
+                }
+            }
+        }
+        foreach my $res (@resources) {
+            if (ref($res->parts()) eq 'ARRAY') {
+                foreach my $part (@{$res->parts()}) {
+                    if (!$res->tries($part)) {
+                        $missing++;
+                    } else {
+                        $tried++;
+                    }
+                }
+            }
+        }
+    }
+    if ($missing) {
+        $lt{'miss'} .= '<p class="LC_error">';
+        if ($type eq 'map') {
+            $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
+        } else {
+            $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
+        }
+        if ($missing > 1) {
+            $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
+        } else {
+            $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
+        }
+    }
+    $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
+    if ($proctor) {
+        if ($height !~ /^\d+$/) {
+            $height = 400;
+            if ($missing) {
+                $height += 60;
+            }
+        }
+        if ($width !~ /^\d+$/) {
+            $width = 400;
+            if ($missing) {
+                $width += 60;
+            }
+        }
+        return <<END;
+<form method="post" name="LCdoneButton" action="">
+    <input type="hidden" name="LC_interval_done" value="" />
+    <input type="hidden" name="LC_interval_done_proctorpass" value="" />
+    <input type="hidden" name="symb" value="$shownsymb" />
+    <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
+</form>
+
+<div id="LC_done-confirm" title="$lt{'title'}">
+  <p>$lt{'preamble'} $lt{$type}</p>
+  $lt{'miss'}
+  <p>$lt{'proctor'}</p>
+  <form name="LCdoneButtonProctor" action="">
+    <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
+    <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
+  </form>
+  <p>$lt{'cancel'}</p>
+</div>
+
+<script type="text/javascript">
+// <![CDATA[
+    \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
+    \$( "#LC_done-confirm-opener" ).on("click", function() {
+        \$( "#LC_done-confirm" ).dialog("open");
+        \$( "#LC_done-confirm" ).dialog({
+            height: $height,
+            width: $width,
+            modal: true,
+            resizable: false,
+            buttons: [
+                {
+                    text: "$lt{'ok'}",
+                    click: function() {
+                        var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
+                        if ((proctorkey == '') || (proctorkey == null)) {
+                            alert("$lt{'nokey'}");
+                        } else {
+                            \$( '[name="LC_interval_done"]' )[0].value = 'true';
+                            \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
+                            \$( '[name="LCdoneButton"]' )[0].submit();
+                        }
+                    },
+                },
+                {
+                    text: "$lt{'exit'}",
+                    click: function() {
+                        \$("#LC_done-confirm").dialog( "close" );
+                    }
+                }
+            ],
+            close: function() {
+                \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
+            }
+        });
+        \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
+            event.preventDefault();
+            \$( '[name="LC_interval_done"]' )[0].value = 'true';
+            \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
+            \$( '[name="LCdoneButton"]' )[0].submit();
+        });
+});
+
+// ]]>
+</script>
+
+END
+    } else {
+        if ($height !~ /^\d+$/) {
+            $height = 320;
+            if ($missing) {
+                $height += 60;
+            }
+        }
+        if ($width !~ /^\d+$/) {
+            $width = 320;
+            if ($missing) {
+                $width += 60;
+            }
+        }
+        if ($missing) {
+            $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
+        }
+        return <<END;
+
+<form method="post" name="LCdoneButton" action="">
+    <input type="hidden" name="LC_interval_done" value="" />
+    <input type="hidden" name="symb" value="$shownsymb" />
+    <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
+</form>
+
+<div id="LC_done-confirm" title="$lt{'title'}">
+    <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
+</div>
+
+<script type="text/javascript">
+// <![CDATA[
+\$( "#LC_done-confirm" ).dialog({ autoOpen: false });
+\$( "#LC_done-confirm-opener" ).click(function() {
+    \$( "#LC_done-confirm" ).dialog( "open" );
+    \$( "#LC_done-confirm" ).dialog({
+      resizable: false,
+      height: $height,
+      width: $width,
+      modal: true,
+      buttons: [
+                 {
+                    text: "$lt{'ok'}",
+                    click: function() {
+                        \$( this ).dialog( "close" );
+                        \$( '[name="LC_interval_done"]' )[0].value = 'true';
+                        \$( '[name="LCdoneButton"]' )[0].submit();
+                    },
+                 },
+                 {
+                     text: "$lt{'exit'}",
+                     click: function() {
+                         \$( this ).dialog( "close" );
+                     },
+                  },
+               ],
+       });
+});
+// ]]>
+</script>
+
+END
+    }
+}
+
 sub utilityfunctions {
     my ($httphost) = @_;
     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
@@ -2354,6 +2605,11 @@ function open_StoredLinks_Import(rat) {
    newWin.focus();
 }
 
+function open_source() {
+   sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
+                         'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
+}
+
 (function (\$) {
   \$(document).ready(function () {
     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
@@ -2947,10 +3203,20 @@ sub countdown_timer {
         }
         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
         my @interval=&Apache::lonnet::EXT("resource.0.interval");
+        my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
         if (@interval > 1) {
+            ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
+            if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
+                $usesdone = 'done';
+                $donebuttontext = $1;
+                (undef,$proctor,$secret) = split(/_/,$2);
+            } elsif ($donesuffix =~ /^done(|_.+)$/) {
+                $donebuttontext = &mt('Done');
+                ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
+            }
             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
             if ($first_access > 0) {
-                if ($first_access+$interval[0] > time) {
+                if ($first_access+$timelimit > time) {
                     $hastimeleft = 1;
                 }
             }
@@ -2958,11 +3224,16 @@ sub countdown_timer {
         if (($duedate && $duedate > time) ||
             (!$duedate && $hastimeleft) ||
             ($slot_name ne '' && $slothastime)) {
-            my ($collapse,$expand,$alttxt,$title,$currdisp);
+            my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
             if ((@interval > 1 && $hastimeleft) ||
                 ($type eq 'Task' && $slothastime)) {
                 $currdisp = 'inline';
                 $collapse = '&#9658;&nbsp;';
+                if ((@interval > 1) && ($hastimeleft)) {
+                    if ($usesdone eq 'done') {
+                        $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
+                    }
+                }
             } else {
                 $currdisp = 'none';
                 $expand = '&#9668;&nbsp;';
@@ -2973,7 +3244,7 @@ sub countdown_timer {
             }
             my $desc = &mt('Countdown to due date/time');
             return <<END;
-
+$donebutton
 <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 $collapse