Diff for /loncom/interface/loncommon.pm between versions 1.1075.2.161.2.24 and 1.1075.2.162

version 1.1075.2.161.2.24, 2024/03/29 00:45:24 version 1.1075.2.162, 2022/01/16 19:11:03
Line 61  use POSIX qw(strftime mktime); Line 61  use POSIX qw(strftime mktime);
 use Apache::lonmenu();  use Apache::lonmenu();
 use Apache::lonenc();  use Apache::lonenc();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonnavmaps();  use Apache::lonnet();
 use HTML::Entities;  use HTML::Entities;
 use Apache::lonhtmlcommon();  use Apache::lonhtmlcommon();
 use Apache::loncoursedata();  use Apache::loncoursedata();
Line 71  use Apache::lonuserutils(); Line 71  use Apache::lonuserutils();
 use Apache::lonuserstate();  use Apache::lonuserstate();
 use Apache::courseclassifier();  use Apache::courseclassifier();
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use LONCAPA::map();  
 use HTTP::Request;  use HTTP::Request;
 use DateTime::TimeZone;  use DateTime::TimeZone;
 use DateTime::Locale;  use DateTime::Locale;
Line 84  use Crypt::DES; Line 83  use Crypt::DES;
 use DynaLoader; # for Crypt::DES version  use DynaLoader; # for Crypt::DES version
 use File::Copy();  use File::Copy();
 use File::Path();  use File::Path();
 use String::CRC32();  
 use Short::URL();  
   
 # ---------------------------------------------- Designs  # ---------------------------------------------- Designs
 use vars qw(%defaultdesign);  use vars qw(%defaultdesign);
Line 431  sub studentbrowser_javascript { Line 428  sub studentbrowser_javascript {
 <script type="text/javascript" language="Javascript">  <script type="text/javascript" language="Javascript">
 // <![CDATA[  // <![CDATA[
     var stdeditbrowser;      var stdeditbrowser;
     function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv,uident) {      function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
         var url = '/adm/pickstudent?';          var url = '/adm/pickstudent?';
         var filter;          var filter;
  if (!ignorefilter) {   if (!ignorefilter) {
Line 452  sub studentbrowser_javascript { Line 449  sub studentbrowser_javascript {
             }              }
         }          }
         if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }          if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
         if (uident !== '') { url+="&identelement="+uident; }  
         var title = 'Student_Browser';          var title = 'Student_Browser';
         var options = 'scrollbars=1,resizable=1,menubar=0';          var options = 'scrollbars=1,resizable=1,menubar=0';
         options += ',width=700,height=600';          options += ',width=700,height=600';
Line 484  ENDRESBRW Line 480  ENDRESBRW
 }  }
   
 sub selectstudent_link {  sub selectstudent_link {
    my ($form,$unameele,$udomele,$courseadv,$clickerid,$identelem)=@_;     my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".     my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                       &Apache::lonhtmlcommon::entity_encode($unameele)."','".                        &Apache::lonhtmlcommon::entity_encode($unameele)."','".
                       &Apache::lonhtmlcommon::entity_encode($udomele)."'";                        &Apache::lonhtmlcommon::entity_encode($udomele)."'";
Line 501  sub selectstudent_link { Line 497  sub selectstudent_link {
            $callargs .= ",'','','$courseadv'";             $callargs .= ",'','','$courseadv'";
        } elsif ($courseadv eq 'condition') {         } elsif ($courseadv eq 'condition') {
            $callargs .= ",'','','$courseadv'";             $callargs .= ",'','','$courseadv'";
        } elsif ($identelem ne '') {  
            $callargs .= ",'','',''";  
        }  
        if ($identelem ne '') {  
            $callargs .= ",'".&Apache::lonhtmlcommon::entity_encode($identelem)."'";  
        }         }
        return '<span class="LC_nobreak">'.         return '<span class="LC_nobreak">'.
               '<a href="javascript:openstdbrowser('.$callargs.');">'.                '<a href="javascript:openstdbrowser('.$callargs.');">'.
Line 957  ENDSCRT Line 948  ENDSCRT
 }  }
   
 sub select_timezone {  sub select_timezone {
    my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;     my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
    my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.'>'."\n";     my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
    if ($includeempty) {     if ($includeempty) {
        $output .= '<option value=""';         $output .= '<option value=""';
        if (($selected eq '') || ($selected eq 'local')) {         if (($selected eq '') || ($selected eq 'local')) {
Line 1228  END Line 1219  END
   
 =pod  =pod
   
 =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)  =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
   
 Returns a string corresponding to an HTML link to the given help  Returns a string corresponding to an HTML link to the given help
 $topic, where $topic corresponds to the name of a .tex file in  $topic, where $topic corresponds to the name of a .tex file in
Line 1252  $imgid is the id of the img tag used for Line 1243  $imgid is the id of the img tag used for
 used in a javascript call to switch the image src.  See   used in a javascript call to switch the image src.  See 
 lonhtmlcommon::htmlareaselectactive() for an example.  lonhtmlcommon::htmlareaselectactive() for an example.
   
 $links_target will optionally be set to a target (_top, _parent or _self).  
   
 =cut  =cut
   
 sub help_open_topic {  sub help_open_topic {
     my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;      my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
     $text = "" if (not defined $text);      $text = "" if (not defined $text);
     $stayOnPage = 0 if (not defined $stayOnPage);      $stayOnPage = 0 if (not defined $stayOnPage);
     $width = 500 if (not defined $width);      $width = 500 if (not defined $width);
Line 1283  sub help_open_topic { Line 1272  sub help_open_topic {
     }      }
   
     # Add the text      # Add the text
     my $target = ' target="_top"';  
     if ($links_target) {  
         $target = ' target="'.$links_target.'"';  
     } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||  
              (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {  
         $target = '';  
     }  
     if ($text ne "") {      if ($text ne "") {
  $template.='<span class="LC_help_open_topic">'   $template.='<span class="LC_help_open_topic">'
                   .'<a'.$target.' href="'.$link.'">'                    .'<a target="_top" href="'.$link.'">'
                   .$text.'</a>';                    .$text.'</a>';
     }      }
   
Line 1302  sub help_open_topic { Line 1284  sub help_open_topic {
     if ($imgid ne '') {      if ($imgid ne '') {
         $imgid = ' id="'.$imgid.'"';          $imgid = ' id="'.$imgid.'"';
     }      }
     $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'      $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
               .'<img src="'.$helpicon.'" border="0"'                .'<img src="'.$helpicon.'" border="0"'
               .' alt="'.&mt('Help: [_1]',$topic).'"'                .' alt="'.&mt('Help: [_1]',$topic).'"'
               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid                 .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
Line 1375  ENDOUTPUT Line 1357  ENDOUTPUT
   
 # now just updates the help link and generates a blue icon  # now just updates the help link and generates a blue icon
 sub help_open_menu {  sub help_open_menu {
     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)       my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
  = @_;       = @_;    
     $stayOnPage = 1;      $stayOnPage = 1;
     my $output;      my $output;
     if ($component_help) {      if ($component_help) {
  if (!$text) {   if (!$text) {
     $output=&help_open_topic($component_help,undef,$stayOnPage,      $output=&help_open_topic($component_help,undef,$stayOnPage,
        $width,$height,'',$links_target);         $width,$height);
  } else {   } else {
     my $help_text;      my $help_text;
     $help_text=&unescape($topic);      $help_text=&unescape($topic);
     $output='<table><tr><td>'.      $output='<table><tr><td>'.
  &help_open_topic($component_help,$help_text,$stayOnPage,   &help_open_topic($component_help,$help_text,$stayOnPage,
  $width,$height,'',$links_target).'</td></tr></table>';   $width,$height).'</td></tr></table>';
  }   }
     }      }
     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);      my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
Line 1497  sub help_open_bug { Line 1479  sub help_open_bug {
     {      {
  $link = $url;   $link = $url;
     }      }
   
     my $target = '_top';  
     if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||  
         (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {  
         $target = '_blank';  
     }  
   
     # Add the text      # Add the text
     if ($text ne "")      if ($text ne "")
     {      {
  $template .=    $template .= 
   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".    "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
   "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";    "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
     }      }
   
     # Add the graphic      # Add the graphic
     my $title = &mt('Report a Bug');      my $title = &mt('Report a Bug');
     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");      my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
     $template .= <<"ENDTEMPLATE";      $template .= <<"ENDTEMPLATE";
  <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>   <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
 ENDTEMPLATE  ENDTEMPLATE
     if ($text ne '') { $template.='</td></tr></table>' };      if ($text ne '') { $template.='</td></tr></table>' };
     return $template;      return $template;
Line 1728  the id of the element to resize, second Line 1703  the id of the element to resize, second
 surrounds everything that comes after the textarea, this routine needs  surrounds everything that comes after the textarea, this routine needs
 to be attached to the <body> for the onload and onresize events.  to be attached to the <body> for the onload and onresize events.
   
   =back
   
 =cut  =cut
   
 sub resize_textarea_js {  sub resize_textarea_js {
Line 2014  sub insert_folding_button { Line 1991  sub insert_folding_button {
             value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";              value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
 }  }
   
 =pod  
   
 =item * &iframe_wrapper_headjs()  
   
 emits javascript containing two global vars to facilitate handling of resizing  
 by code in iframe_wrapper_resizejs() used when an iframe is present in a page  
 with standard LON-CAPA menus.  
   
 =cut  
   
 #  
 # Where iframe is in use, if window.onload() executes before the custom resize function  
 # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)  
 # are used to ensure document.ready() triggers a call to resize, so the iframe contents  
 # do not obscure the Functions menu.  
 #  
   
 sub iframe_wrapper_headjs {  
     return <<"ENDJS";  
 <script type="text/javascript">  
 // <![CDATA[  
 var LCnotready = 0;  
 var LCresizedef = 0;  
 // ]]>  
 </script>  
   
 ENDJS  
   
 }  
   
 =pod  
   
 =item * &iframe_wrapper_resizejs()  
   
 emits javascript used to handle resizing for a page containing  
 an iframe, to ensure that the iframe does not obscure any  
 standard LON-CAPA menu items.  
   
 =back  
   
 =cut  
   
 #  
 # jQuery to use when iframe is in use and a page resize occurs.  
 # This script will ensure that the iframe does not obscure any  
 # standard LON-CAPA inline menus (primary, secondary, and/or  
 # breadcrumbs and Functions menus. Expects javascript from  
 # &iframe_wrapper_headjs() to be in head portion of the web page,  
 # e.g., by inclusion in second arg passed to &start_page().  
 #  
   
 sub iframe_wrapper_resizejs {  
     my $offset = 5;  
     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);  
     if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {  
         $offset = 0;  
     }  
     return &Apache::lonhtmlcommon::scripttag(<<SCRIPT);  
     \$(document).ready( function() {  
         \$(window).unbind('resize').resize(function(){  
             var header = null;  
             var offset = $offset;  
             var height = 0;  
             var hdrtop = 0;  
             if (\$('div.LC_menus_content:first').length) {  
                 if (\$('div.LC_menus_content:first').hasClass ("shown")) {  
                     header = \$('div.LC_menus_content:first');  
                     offset = 12;  
                 }  
             } else if (\$('div.LC_head_subbox:first').length) {  
                 header = \$('div.LC_head_subbox:first');  
                 offset = 9;  
             } else {  
                 if (\$('#LC_breadcrumbs').length) {  
                     header = \$('#LC_breadcrumbs');  
                 }  
             }  
             if (header != null && header.length) {  
                 height = header.height();  
                 hdrtop = header.position().top;  
             }  
             var pos = height + hdrtop + offset;  
             \$('.LC_iframecontainer').css('top', pos);  
         });  
         LCresizedef = 1;  
         if (LCnotready == 1) {  
             LCnotready = 0;  
             \$(window).trigger('resize');  
         }  
     });  
     window.onload = function(){  
          if (LCresizedef) {  
              LCnotready = 0;  
              \$(window).trigger('resize');  
          } else {  
              LCnotready = 1;  
          }  
     };  
 SCRIPT  
   
 }  
   
 =pod  =pod
   
Line 2835  This is not an optimal method, but it wo Line 2711  This is not an optimal method, but it wo
   
 =item * authform_filesystem  =item * authform_filesystem
   
 =item * authform_lti  
   
 =back  =back
   
 See loncreateuser.pm for invocation and use examples.  See loncreateuser.pm for invocation and use examples.
Line 3261  sub authform_filesystem { Line 3135  sub authform_filesystem {
     return $result;      return $result;
 }  }
   
 sub authform_lti {  
     my %in = (  
               formname => 'document.cu',  
               kerb_def_dom => 'MSU.EDU',  
               @_,  
               );  
     my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);  
     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});  
     if ($in{'readonly'}) {  
         $disabled = ' disabled="disabled"';  
     }  
     if (defined($in{'curr_authtype'})) {  
         if ($in{'curr_authtype'} eq 'lti') {  
             if ($can_assign{'lti'}) {  
                 $lticheck = 'checked="checked" ';  
                 if (defined($in{'mode'})) {  
                     if ($in{'mode'} eq 'modifyuser') {  
                         $lticheck = '';  
                     }  
                 }  
             } else {  
                 $result = &mt('Currently LTI Authenticated.');  
                 return $result;  
             }  
         }  
     } else {  
         if ($authnum == 1) {  
             $authtype = '<input type="hidden" name="login" value="lti" />';  
         }  
     }  
     if (!$can_assign{'lti'}) {  
         return;  
     } elsif ($authtype eq '') {  
         if (defined($in{'mode'})) {  
             if ($in{'mode'} eq 'modifycourse') {  
                 if ($authnum == 1) {  
                     $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';  
                 }  
             }  
         }  
     }  
     $jscall = "javascript:changed_radio('lti',$in{'formname'});";  
     if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {  
         $authtype = '<input type="radio" name="login" value="lti" '.  
                     $lticheck.' onchange="'.$jscall.'" onclick="'.  
                     $jscall.'"'.$disabled.' />';  
     }  
     $autharg = '<input type="hidden" name="ltiarg" value="" />';  
     if ($authtype) {  
         $result = &mt('[_1] LTI Authenticated',  
                       '<label>'.$authtype.'</label>'.$autharg);  
     } else {  
         $result = '<b>'.&mt('LTI Authenticated').'</b>'.  
                   $autharg;  
     }  
     return $result;  
 }  
   
 sub get_assignable_auth {  sub get_assignable_auth {
     my ($dom) = @_;      my ($dom) = @_;
     if ($dom eq '') {      if ($dom eq '') {
Line 3434  sub check_passwd_rules { Line 3250  sub check_passwd_rules {
     return $warning;      return $warning;
 }  }
   
 sub passwd_validation_js {  
     my ($currpasswdval,$domain,$context,$id) = @_;  
     my (%passwdconf,$alertmsg);  
     if ($context eq 'linkprot') {  
         my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);  
         if (ref($domconfig{'ltisec'}) eq 'HASH') {  
             if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {  
                 %passwdconf = %{$domconfig{'ltisec'}{'rules'}};  
             }  
         }  
         if ($id eq 'add') {  
             $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';  
         } elsif ($id =~ /^\d+$/) {  
             my $pos = $id+1;  
             $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';  
         } else {  
             $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';  
         }  
     } else {  
         %passwdconf = &Apache::lonnet::get_passwdconf($domain);  
         $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';  
     }  
     my ($min,$max,@chars,$numrules,$intargjs,%alert);  
     $numrules = 0;  
     $min = $Apache::lonnet::passwdmin;  
     if (ref($passwdconf{'chars'}) eq 'ARRAY') {  
         if ($passwdconf{'min'} =~ /^\d+$/) {  
             if ($passwdconf{'min'} > $min) {  
                 $min = $passwdconf{'min'};  
             }  
         }  
         if ($passwdconf{'max'} =~ /^\d+$/) {  
             $max = $passwdconf{'max'};  
             $numrules ++;  
         }  
         @chars = @{$passwdconf{'chars'}};  
         if (@chars) {  
             $numrules ++;  
         }  
     }  
     if ($min > 0) {  
         $numrules ++;  
     }  
     if (($min > 0) || ($max ne '') || (@chars > 0)) {  
         if ($min) {  
             $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';  
         }  
         if ($max) {  
             $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';  
         }  
         my (@charalerts,@charrules);  
         if (@chars) {  
             if (grep(/^uc$/,@chars)) {  
                 push(@charalerts,&mt('contain at least one upper case letter'));  
                 push(@charrules,'uc');  
             }  
             if (grep(/^lc$/,@chars)) {  
                 push(@charalerts,&mt('contain at least one lower case letter'));  
                 push(@charrules,'lc');  
             }  
             if (grep(/^num$/,@chars)) {  
                 push(@charalerts,&mt('contain at least one number'));  
                 push(@charrules,'num');  
             }  
             if (grep(/^spec$/,@chars)) {  
                 push(@charalerts,&mt('contain at least one non-alphanumeric'));  
                 push(@charrules,'spec');  
             }  
         }  
         $intargjs = qq|            var rulesmsg = '';\n|.  
                     qq|            var currpwval = $currpasswdval;\n|;  
             if ($min) {  
                 $intargjs .= qq|  
             if (currpwval.length < $min) {  
                 rulesmsg += ' - $alert{min}';  
             }  
 |;  
             }  
             if ($max) {  
                 $intargjs .= qq|  
             if (currpwval.length > $max) {  
                 rulesmsg += ' - $alert{max}';  
             }  
 |;  
             }  
             if (@chars > 0) {  
                 my $charrulestr = '"'.join('","',@charrules).'"';  
                 my $charalertstr = '"'.join('","',@charalerts).'"';  
                 $intargjs .= qq|            var brokerules = new Array();\n|.  
                              qq|            var charrules = new Array($charrulestr);\n|.  
                              qq|            var charalerts = new Array($charalertstr);\n|;  
                 my %rules;  
                 map { $rules{$_} = 1; } @chars;  
                 if ($rules{'uc'}) {  
                     $intargjs .= qq|  
             var ucRegExp = /[A-Z]/;  
             if (!ucRegExp.test(currpwval)) {  
                 brokerules.push('uc');  
             }  
 |;  
                 }  
                 if ($rules{'lc'}) {  
                     $intargjs .= qq|  
             var lcRegExp = /[a-z]/;  
             if (!lcRegExp.test(currpwval)) {  
                 brokerules.push('lc');  
             }  
 |;  
                 }  
                 if ($rules{'num'}) {  
                      $intargjs .= qq|  
             var numRegExp = /[0-9]/;  
             if (!numRegExp.test(currpwval)) {  
                 brokerules.push('num');  
             }  
 |;  
                 }  
                 if ($rules{'spec'}) {  
                      $intargjs .= q|  
             var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;  
             if (!specRegExp.test(currpwval)) {  
                 brokerules.push('spec');  
             }  
 |;  
                 }  
                 $intargjs .= qq|  
             if (brokerules.length > 0) {  
                 for (var i=0; i<brokerules.length; i++) {  
                     for (var j=0; j<charrules.length; j++) {  
                         if (brokerules[i] == charrules[j]) {  
                             rulesmsg += ' - '+charalerts[j]+'\\n';  
                             break;  
                         }  
                     }  
                 }  
             }  
 |;  
             }  
             $intargjs .= qq|  
             if (rulesmsg != '') {  
                 rulesmsg = '$alertmsg'+rulesmsg;  
                 alert(rulesmsg);  
                 return false;  
             }  
 |;  
     }  
     return ($numrules,$intargjs);  
 }  
   
 ###############################################################  ###############################################################
 ##    Get Kerberos Defaults for Domain                 ##  ##    Get Kerberos Defaults for Domain                 ##
 ###############################################################  ###############################################################
Line 4001  sub syllabuswrapper { Line 3668  sub syllabuswrapper {
     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};      return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
 }  }
   
 sub aboutme_on {  
     my ($uname,$udom)=@_;  
     unless ($uname) { $uname=$env{'user.name'}; }  
     unless ($udom)  { $udom=$env{'user.domain'}; }  
     return if ($udom eq 'public' && $uname eq 'public');  
     my $hashkey=$uname.':'.$udom;  
     my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);  
     if ($cached) {  
         return $aboutme;  
     }  
     $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');  
     &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);  
     return $aboutme;  
 }  
   
 sub devalidate_aboutme_cache {  
     my ($uname,$udom)=@_;  
     if (!$udom)  { $udom =$env{'user.domain'}; }  
     if (!$uname) { $uname=$env{'user.name'};   }  
     return if ($udom eq 'public' && $uname eq 'public');  
     my $id=$uname.':'.$udom;  
     &Apache::lonnet::devalidate_cache_new('aboutme',$id);  
 }  
   
 # -----------------------------------------------------------------------------  # -----------------------------------------------------------------------------
   
 sub track_student_link {  sub track_student_link {
Line 4628  sub get_previous_attempt { Line 4271  sub get_previous_attempt {
       }        }
       $prevattempts.= &end_data_table_row().&end_data_table();        $prevattempts.= &end_data_table_row().&end_data_table();
     } else {      } else {
       my $msg;  
       if ($symb =~ /ext\.tool$/) {  
           $msg = &mt('No grade passed back.');  
       } else {  
           $msg = &mt('Nothing submitted - no attempts.');  
       }  
       $prevattempts=        $prevattempts=
   &start_data_table().&start_data_table_row().    &start_data_table().&start_data_table_row().
   '<td>'.$msg.'</td>'.    '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
   &end_data_table_row().&end_data_table();    &end_data_table_row().&end_data_table();
     }      }
   } else {    } else {
Line 5093  sub findallcourses { Line 4730  sub findallcourses {
 sub blockcheck {  sub blockcheck {
     my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;      my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
   
     unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {      unless ($activity eq 'docs') {
         my ($has_evb,$check_ipaccess);          my ($has_evb,$check_ipaccess);
         my $dom = $env{'user.domain'};          my $dom = $env{'user.domain'};
         if ($env{'request.course.id'}) {          if ($env{'request.course.id'}) {
Line 5116  sub blockcheck { Line 4753  sub blockcheck {
                     }                      }
                 }                  }
             }              }
         } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||  
                 ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {  
             my $checkrole;  
             if ($env{'request.role.domain'} eq '') {  
                 $checkrole = "cm./$env{'user.domain'}/";  
             } else {  
                 $checkrole = "cm./$env{'request.role.domain'}/";  
             }  
             if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {  
                 $has_evb = 1;  
             }  
         }          }
         unless ($has_evb || $check_ipaccess) {          unless ($has_evb || $check_ipaccess) {
             my @machinedoms = &Apache::lonnet::current_machine_domains();              my @machinedoms = &Apache::lonnet::current_machine_domains();
Line 5172  sub blockcheck { Line 4798  sub blockcheck {
                 }                  }
             }              }
         }          }
         if (($activity eq 'wishlist') || ($activity eq 'annotate')) {  
             return ();  
         }  
     }      }
     if (defined($udom) && defined($uname)) {      if (defined($udom) && defined($uname)) {
         # If uname and udom are for a course, check for blocks in the course.          # If uname and udom are for a course, check for blocks in the course.
Line 5200  sub blockcheck { Line 4823  sub blockcheck {
     # boards, chat or groups, check for blocking in current course only.      # boards, chat or groups, check for blocking in current course only.
   
     if (($activity eq 'boards' || $activity eq 'chat' ||      if (($activity eq 'boards' || $activity eq 'chat' ||
          $activity eq 'groups' || $activity eq 'printout' ||           $activity eq 'groups' || $activity eq 'printout') &&
          $activity eq 'search' || $activity eq 'reinit' ||          ($env{'request.course.id'})) {
          $activity eq 'alert') && ($env{'request.course.id'})) {  
         foreach my $key (keys(%live_courses)) {          foreach my $key (keys(%live_courses)) {
             if ($key ne $env{'request.course.id'}) {              if ($key ne $env{'request.course.id'}) {
                 delete($live_courses{$key});                  delete($live_courses{$key});
Line 5536  END_MYBLOCK Line 5158  END_MYBLOCK
         $text = &mt('Gradebook Blocked');          $text = &mt('Gradebook Blocked');
     } elsif ($activity eq 'search') {      } elsif ($activity eq 'search') {
         $text = &mt('Search Blocked');          $text = &mt('Search Blocked');
     } elsif ($activity eq 'alert') {  
         $text = &mt('Checking Critical Messages Blocked');  
     } elsif ($activity eq 'reinit') {  
         $text = &mt('Checking Course Update Blocked');  
     } elsif ($activity eq 'about') {      } elsif ($activity eq 'about') {
         $text = &mt('Access to User Information Pages Blocked');          $text = &mt('Access to User Information Pages Blocked');
     } elsif ($activity eq 'wishlist') {      } elsif ($activity eq 'wishlist') {
Line 5580  sub check_ip_acc { Line 5198  sub check_ip_acc {
     }      }
   
     my $name;      my $name;
     my %access = (      foreach my $pattern (split(',',$acc)) {
                      allowfrom => 1,          $pattern =~ s/^\s*//;
                      denyfrom  => 0,          $pattern =~ s/\s*$//;
                  );  
     my @allows;  
     my @denies;  
     foreach my $item (split(',',$acc)) {  
         $item =~ s/^\s*//;  
         $item =~ s/\s*$//;  
         if ($item =~ /^\!(.+)$/) {  
             push(@denies,$1);  
         } else {  
             push(@allows,$item);  
         }  
     }  
     my $numdenies = scalar(@denies);  
     my $numallows = scalar(@allows);  
     my $count = 0;  
     foreach my $pattern (@denies,@allows) {  
         $count ++;  
         my $acctype = 'allowfrom';  
         if ($count <= $numdenies) {  
             $acctype = 'denyfrom';  
         }  
         if ($pattern =~ /\*$/) {          if ($pattern =~ /\*$/) {
             #35.8.*              #35.8.*
             $pattern=~s/\*//;              $pattern=~s/\*//;
             if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }              if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {          } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
             #35.8.3.[34-56]              #35.8.3.[34-56]
             my $low=$2;              my $low=$2;
Line 5615  sub check_ip_acc { Line 5212  sub check_ip_acc {
             $pattern=$1;              $pattern=$1;
             if ($ip =~ /^\Q$pattern\E/) {              if ($ip =~ /^\Q$pattern\E/) {
                 my $last=(split(/\./,$ip))[3];                  my $last=(split(/\./,$ip))[3];
                 if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }                  if ($last <=$high && $last >=$low) { $allowed=1; }
             }              }
         } elsif ($pattern =~ /^\*/) {          } elsif ($pattern =~ /^\*/) {
             #*.msu.edu              #*.msu.edu
Line 5625  sub check_ip_acc { Line 5222  sub check_ip_acc {
                 my $netaddr=inet_aton($ip);                  my $netaddr=inet_aton($ip);
                 ($name)=gethostbyaddr($netaddr,AF_INET);                  ($name)=gethostbyaddr($netaddr,AF_INET);
             }              }
             if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }              if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {          } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
             #127.0.0.1              #127.0.0.1
             if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }              if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
         } else {          } else {
             #some.name.com              #some.name.com
             if (!defined($name)) {              if (!defined($name)) {
Line 5636  sub check_ip_acc { Line 5233  sub check_ip_acc {
                 my $netaddr=inet_aton($ip);                  my $netaddr=inet_aton($ip);
                 ($name)=gethostbyaddr($netaddr,AF_INET);                  ($name)=gethostbyaddr($netaddr,AF_INET);
             }              }
             if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }              if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
         }  
         if ($allowed =~ /^(0|1)$/) { last; }  
     }  
     if ($allowed eq '') {  
         if ($numdenies && !$numallows) {  
             $allowed = 1;  
         } else {  
             $allowed = 0;  
         }          }
           if ($allowed) { last; }
     }      }
     return $allowed;      return $allowed;
 }  }
Line 5731  sub get_domainconf { Line 5321  sub get_domainconf {
                                 foreach my $host (keys(%{$domconfig{'login'}{$key}})) {                                  foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
                                     if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {                                      if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
                                         $designhash{$udom.'.login.'.$key.'_'.$host} = 1;                                          $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
                                         foreach my $item ('text','img','alt','url','title','window','notsso') {                                          foreach my $item ('text','img','alt','url','title','notsso') {
                                             $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};                                              $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
                                         }                                          }
                                     }                                      }
Line 5964  sub head_subbox { Line 5554  sub head_subbox {
 Input: (optional) filename from which breadcrumb trail is built.  Input: (optional) filename from which breadcrumb trail is built.
        In most cases no input as needed, as $env{'request.filename'}         In most cases no input as needed, as $env{'request.filename'}
        is appropriate for use in building the breadcrumb trail.         is appropriate for use in building the breadcrumb trail.
        frameset flag  
        If page header is being requested for use in a frameset, then  
        the second (option) argument -- frameset will be true, and  
        the target attribute set for links should be target="_parent".  
   
 Returns: HTML div with CSTR path and recent box  Returns: HTML div with CSTR path and recent box
          To be included on Authoring Space pages           To be included on Authoring Space pages
Line 5975  Returns: HTML div with CSTR path and rec Line 5561  Returns: HTML div with CSTR path and rec
 =cut  =cut
   
 sub CSTR_pageheader {  sub CSTR_pageheader {
     my ($trailfile,$frameset) = @_;      my ($trailfile) = @_;
     if ($trailfile eq '') {      if ($trailfile eq '') {
         $trailfile = $env{'request.filename'};          $trailfile = $env{'request.filename'};
     }      }
Line 5998  sub CSTR_pageheader { Line 5584  sub CSTR_pageheader {
         $lastitem = $thisdisfn;          $lastitem = $thisdisfn;
     }      }
   
     my ($target,$crumbtarget) = (' target="_top"','_top');  
     if ($frameset) {  
         $target = ' target="_parent"';  
         $crumbtarget = '_parent';  
     } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {  
         $target = '';  
         $crumbtarget = '';  
     } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {  
         $target = ' target="'.$env{'request.deeplink.target'}.'"';  
         $crumbtarget = $env{'request.deeplink.target'};  
     }  
   
     my $output =      my $output =
          '<div>'           '<div>'
         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?          .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
         .'<b>'.&mt('Authoring Space:').'</b> '          .'<b>'.&mt('Authoring Space:').'</b> '
         .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'          .'<form name="dirs" method="post" action="'.$formaction
         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);          .'" target="_top">' #FIXME lonpubdir: target="_parent"
           .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
   
     if ($lastitem) {      if ($lastitem) {
         $output .=          $output .=
Line 6025  sub CSTR_pageheader { Line 5600  sub CSTR_pageheader {
     }      }
     $output .=      $output .=
          '<br />'           '<br />'
         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"          #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')          .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
         .'</form>'          .'</form>'
         .&Apache::lonmenu::constspaceform($frameset)          .&Apache::lonmenu::constspaceform()
         .'</div>';          .'</div>';
   
     return $output;      return $output;
 }  }
   
 ##############################################  
 =pod  
   
 =item * &nocodemirror()  
   
 Input: None  
   
 Returns: 1 if CodeMirror is deactivated based on  
          user's preference, or domain default,  
          if user indicated use of default.  
   
 =cut  
   
 sub nocodemirror {  
     my $nocodem = $env{'environment.nocodemirror'};  
     unless ($nocodem) {  
         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});  
         if ($domdefs{'nocodemirror'}) {  
             $nocodem = 'yes';  
         }  
     }  
     if ($nocodem eq 'yes') {  
         return 1;  
     }  
     return;  
 }  
   
 ##############################################  
 =pod  
   
 =item * &permitted_editors()  
   
 Input: $uri (optional)  
   
 Returns: %editors hash in which keys are editors  
          permitted in current Authoring Space.  
          Value for each key is 1. Possible keys  
          are: edit, xml, and daxe. If no specific  
          set of editors has been set for the Author  
          who owns the Authoring Space, then the  
          domain default will be used.  If no domain  
          default has been set, then the keys will be  
          edit and xml.  
   
 =cut  
   
 sub permitted_editors {  
     my ($uri) = @_;  
     my ($is_author,$is_coauthor,$auname,$audom,%editors);  
     if ($env{'request.role'} =~ m{^au\./}) {  
         $is_author = 1;  
     } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {  
         ($audom,$auname) = ($1,$2);  
         if (($audom ne '') && ($auname ne '')) {  
             if (($env{'user.domain'} eq $audom) &&  
                 ($env{'user.name'} eq $auname)) {  
                 $is_author = 1;  
             } else {  
                 $is_coauthor = 1;  
             }  
         }  
     } elsif ($env{'request.course.id'}) {  
         if ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {  
             ($audom,$auname) = ($1,$2);  
         } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {  
             ($audom,$auname) = ($1,$2);  
         } elsif (($uri eq '/daxesave') &&  
                  ($env{'form.path'} =~ m{^/daxeopen/priv/($match_domain)/($match_username)/})) {  
             ($audom,$auname) = ($1,$2);  
         }  
         if (($audom ne '') && ($auname ne '')) {  
             if (($env{'user.domain'} eq $audom) &&  
                 ($env{'user.name'} eq $auname)) {  
                 $is_author = 1;  
             } else {  
                 $is_coauthor = 1;  
             }  
         }  
     }  
     if ($is_author) {  
         if (exists($env{'environment.editors'})) {  
             map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});  
         } else {  
             %editors = ( edit => 1,  
                          xml => 1,  
                        );  
         }  
     } elsif ($is_coauthor) {  
         if (exists($env{"environment.internal.editors./$audom/$auname"})) {  
             map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});  
         } else {  
             %editors = ( edit => 1,  
                          xml => 1,  
                        );  
         }  
     } else {  
         %editors = ( edit => 1,  
                      xml => 1,  
                    );  
     }  
     return %editors;  
 }  
   
 ###############################################  ###############################################
 ###############################################  ###############################################
   
Line 6188  Inputs: Line 5660  Inputs:
             inlineremote items to be added in "Functions" menu below              inlineremote items to be added in "Functions" menu below
             breadcrumbs.              breadcrumbs.
   
 =item * $ltiscope, optional argument, will be one of: resource, map or  
             course, if LON-CAPA is in LTI Provider context. Value is  
             the scope of use, i.e., launch was for access to a single, a map  
             or the entire course.  
   
 =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider  
             context, this will contain the URL for the landing item in  
             the course, after launch from an LTI Consumer  
   
 =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider  
             context, this will contain a reference to hash of items  
             to be included in the page header and/or inline menu.  
   
 =item * $menucoll, optional argument, if specific menu collection is in  
             effect, either set as the default for the course, or set for  
             the deeplink paramater for $env{'request.deeplink.login'}  
             then $menucoll will be the number of that collection.  
   
 =item * $menuref, optional argument, reference to a hash, containing the  
             menu options included for the menu in effect, based on the  
             configuration for the numbered menu collection in use.  
   
 =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister  
             within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),  
             if so, $showncrumbsref is set there to 1, and will propagate back  
             via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()  
             being called a second time.  
   
 =back  =back
   
 Returns: A uniform header for LON-CAPA web pages.    Returns: A uniform header for LON-CAPA web pages.  
Line 6227  other decorations will be returned. Line 5671  other decorations will be returned.
   
 sub bodytag {  sub bodytag {
     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,      my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
         $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref,          $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
         $ltiscope,$ltiuri,$ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;  
   
     my $public;      my $public;
     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))      if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
Line 6312  sub bodytag { Line 5755  sub bodytag {
  undef($role);   undef($role);
     }      }
   
     my $showcrstitle = 1;  
     if (($cid) && ($env{'request.lti.login'})) {  
         if (ref($ltimenu) eq 'HASH') {  
             unless ($ltimenu->{'role'}) {  
                 undef($role);  
             }  
             unless ($ltimenu->{'coursetitle'}) {  
                 $realm='&nbsp;';  
                 $showcrstitle = 0;  
             }  
         }  
     } elsif (($cid) && ($menucoll)) {  
         if (ref($menuref) eq 'HASH') {  
             unless ($menuref->{'role'}) {  
                 undef($role);  
             }  
             unless ($menuref->{'crs'}) {  
                 $realm='&nbsp;';  
                 $showcrstitle = 0;  
             }  
         }  
     }  
   
     my $titleinfo = '<h1>'.$title.'</h1>';      my $titleinfo = '<h1>'.$title.'</h1>';
     #      #
     # Extra info if you are the DC      # Extra info if you are the DC
     my $dc_info = '';      my $dc_info = '';
     if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&      if (($env{'user.adv'}) && ($env{'request.course.id'}) &&
         (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {          (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};          $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
         $dc_info =~ s/\s+$//;          $dc_info =~ s/\s+$//;
     }      }
   
     my $crstype;  
     if ($cid) {  
         $crstype = $env{'course.'.$cid.'.type'};  
     } elsif ($args->{'crstype'}) {  
         $crstype = $args->{'crstype'};  
     }  
   
     $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});      $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
   
     if ($env{'request.state'} eq 'construct') { $forcereg=1; }      if ($env{'request.state'} eq 'construct') { $forcereg=1; }
Line 6379  sub bodytag { Line 5792  sub bodytag {
         $bodytag .= Apache::lonhtmlcommon::scripttag(          $bodytag .= Apache::lonhtmlcommon::scripttag(
             Apache::lonmenu::utilityfunctions($httphost), 'start');              Apache::lonmenu::utilityfunctions($httphost), 'start');
   
         my $collapsible;          my ($left,$right) = Apache::lonmenu::primary_menu($args->{'links_disabled'});
         if ($args->{'collapsible_header'} ne '') {  
             $collapsible = 1;  
             my ($menustate,$tiptext,$divclass);  
             if ($args->{'start_collapsed'}) {  
                 $menustate = 'collapsed';  
                 $tiptext = 'display';  
                 $divclass = 'hidden';  
             } else {  
                 $menustate = 'expanded';  
                 $tiptext = 'hide';  
                 $divclass = 'shown';  
             }  
             my $alttext = &mt('menu state: '.$menustate);  
             my $tooltip = &mt($tiptext.' standard menus');  
             $bodytag .= <<"END";  
 <div id="LC_expandingContainer" style="display:inline;">  
 <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">  
 <a href="#" style="text-decoration:none;"><img class="LC_collapsible_indicator" alt="$alttext" title="$tooltip" src="/res/adm/pages/$menustate.png" style="border:0;margin:0;padding:0;max-width:100%;height:auto" /></a></div>  
 <div class="LC_menus_content $divclass">  
 END  
         }  
         unless ($args->{'no_primary_menu'}) {  
             my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,  
                                                               $args->{'links_disabled'},  
                                                               $args->{'links_target'},  
                                                               $collapsible);  
             if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {  
                 if ($dc_info) {  
                     $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;  
                 }  
                 $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />  
                                <em>$realm</em> $dc_info</div>|;  
                 return $bodytag;  
             }  
   
             unless ($env{'request.symb'} =~ m/\.page___\d+___/) {          if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
                 $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;              if ($dc_info) {
                   $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
             }              }
               $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
                              <em>$realm</em> $dc_info</div>|;
               return $bodytag;
           }
   
             $bodytag .= $right;          unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
               $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
           }
   
             if ($dc_info) {          $bodytag .= $right;
                 $dc_info = &dc_courseid_toggle($dc_info);  
             }          if ($dc_info) {
             $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;              $dc_info = &dc_courseid_toggle($dc_info);
         }          }
           $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
   
         #if directed to not display the secondary menu, don't.          #if directed to not display the secondary menu, don't.
         if ($args->{'no_secondary_menu'}) {          if ($args->{'no_secondary_menu'}) {
Line 6433  END Line 5820  END
         }          }
         #don't show menus for public users          #don't show menus for public users
         if (!$public){          if (!$public){
             unless ($args->{'no_inline_menu'}) {              $bodytag .= Apache::lonmenu::secondary_menu($httphost,$args->{'links_disabled'});
                 $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,  
                                                             $args->{'no_primary_menu'},  
                                                             $menucoll,$menuref,  
                                                             $args->{'links_disabled'},  
                                                             $args->{'links_target'});  
             }  
             $bodytag .= Apache::lonmenu::serverform();              $bodytag .= Apache::lonmenu::serverform();
             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');              $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
             if ($env{'request.state'} eq 'construct') {              if ($env{'request.state'} eq 'construct') {
                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,                  $bodytag .= &Apache::lonmenu::innerregister($forcereg,
                                 $args->{'bread_crumbs'},'','',$hostname,                                  $args->{'bread_crumbs'},'','',$hostname);
                                 $ltiscope,$ltiuri,$showncrumbsref);  
             } elsif ($forcereg) {              } elsif ($forcereg) {
                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,                  $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
                                 $args->{'group'},$args->{'hide_buttons'},                                                              $args->{'group'},
                                 $hostname,$ltiscope,$ltiuri,$showncrumbsref);                                                              $args->{'hide_buttons'},
                                                               $hostname);
             } else {              } else {
                 my $forbodytag;                  my $forbodytag;
                 &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},                  &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
Line 6467  END Line 5848  END
             $bodytag .= '<hr style="clear:both" />';              $bodytag .= '<hr style="clear:both" />';
             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');               $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
         }          }
         if ($args->{'collapsible_header'} ne '') {  
             $bodytag .= $args->{'collapsible_header'}.  
                         '<div id="LC_collapsible_separator"></div>'.  
                         '</div></div>';  
         }  
         return $bodytag;          return $bodytag;
     }      }
   
Line 6596  sub endbodytag { Line 5973  sub endbodytag {
     }      }
     if ( exists( $env{'internal.head.redirect'} ) ) {      if ( exists( $env{'internal.head.redirect'} ) ) {
         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {          if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
             my ($endbodyjs,$idattr);  
             if ($env{'internal.head.to_opener'}) {  
                 my $linkid = 'LC_continue_link';  
                 $idattr = ' id="'.$linkid.'"';  
                 my $redirect_for_js = &js_escape($env{'internal.head.redirect'});  
                 $endbodyjs=<<ENDJS;  
 <script type="text/javascript">  
 // <![CDATA[  
 function ebFunction(evt) {  
     evt.preventDefault();  
     var dest = '$redirect_for_js';  
     if (window.opener != null && !window.opener.closed) {  
         window.opener.location.href=dest;  
         window.close();  
     } else {  
         window.location.href=dest;  
     }  
     return false;  
 }  
   
 \$(document).ready(function () {  
   if (document.getElementById('$linkid')) {  
     var clickelem = document.getElementById('$linkid');  
     clickelem.addEventListener('click',ebFunction,false);  
   }  
 });  
 // ]]>  
 </script>  
 ENDJS  
             }  
     $endbodytag=      $endbodytag=
         "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".          "<br /><a href=\"$env{'internal.head.redirect'}\">".
         &mt('Continue').'</a>'.          &mt('Continue').'</a>'.
         $endbodytag;          $endbodytag;
         }          }
     }      }
     if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {  
         $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;  
     }  
     return $endbodytag;      return $endbodytag;
 }  }
   
Line 6719  form, .inline { Line 6063  form, .inline {
   display: inline;    display: inline;
 }  }
   
 .LC_menus_content.shown{  
   display: block;  
 }  
   
 .LC_menus_content.hidden {  
   display: none;  
 }  
   
 .LC_right {  .LC_right {
   text-align:right;    text-align:right;
 }  }
Line 6747  form, .inline { Line 6083  form, .inline {
   width:400px;    width:400px;
 }  }
   
 #LC_collapsible_separator {  
     border: 1px solid black;  
     width: 99.9%;  
     height: 0px;  
 }  
   
 .LC_iframecontainer {  .LC_iframecontainer {
     width: 98%;      width: 98%;
     margin: 0;      margin: 0;
Line 7948  fieldset { Line 7278  fieldset {
   /* overflow: hidden; */    /* overflow: hidden; */
 }  }
   
 fieldset#LC_selectuser {  
     margin: 0;  
     padding: 0;  
 }  
   
 article.geogebraweb div {  article.geogebraweb div {
     margin: 0;      margin: 0;
 }  }
Line 8496  a#LC_content_toolbar_edittoplevel { Line 7821  a#LC_content_toolbar_edittoplevel {
   background-image:url(/res/adm/pages/edittoplevel.gif);    background-image:url(/res/adm/pages/edittoplevel.gif);
 }  }
   
 a#LC_content_toolbar_printout {  
   background-image:url(/res/adm/pages/printout.gif);  
 }  
   
 ul#LC_toolbar li a:hover {  ul#LC_toolbar li a:hover {
   background-position: bottom center;    background-position: bottom center;
 }  }
Line 8638  pre.LC_wordwrap { Line 7959  pre.LC_wordwrap {
 }  }
   
 /*  /*
   styles used for response display  
 */  
 div.LC_radiofoil, div.LC_rankfoil {  
   margin: .5em 0em .5em 0em;  
 }  
 table.LC_itemgroup {  
   margin-top: 1em;  
 }  
   
 /*  
   styles used by TTH when "Default set of options to pass to tth/m    styles used by TTH when "Default set of options to pass to tth/m
   when converting TeX" in course settings has been set    when converting TeX" in course settings has been set
   
Line 8668  span.roman {font-family: serif; font-sty Line 7979  span.roman {font-family: serif; font-sty
 span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}  span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}
 span.overacc1 {position: relative;  left: .6em; top: -1.2ex;}  span.overacc1 {position: relative;  left: .6em; top: -1.2ex;}
   
 /*  
   sections with roles, for content only  
 */  
 section[class^="role-"] {  
   padding-left: 10px;  
   padding-right: 5px;  
   margin-top: 8px;  
   margin-bottom: 8px;  
   border: 1px solid #2A4;  
   border-radius: 5px;  
   box-shadow: 0px 1px 1px #BBB;  
 }  
 section[class^="role-"]>h1 {  
   position: relative;  
   margin: 0px;  
   padding-top: 10px;  
   padding-left: 40px;  
 }  
 section[class^="role-"]>h1:before {  
   position: absolute;  
   left: -5px;  
   top: 5px;  
 }  
 section.role-activity>h1:before {  
   content:url('/adm/daxe/images/section_icons/activity.png');  
 }  
 section.role-advice>h1:before {  
   content:url('/adm/daxe/images/section_icons/advice.png');  
 }  
 section.role-bibliography>h1:before {  
   content:url('/adm/daxe/images/section_icons/bibliography.png');  
 }  
 section.role-citation>h1:before {  
   content:url('/adm/daxe/images/section_icons/citation.png');  
 }  
 section.role-conclusion>h1:before {  
   content:url('/adm/daxe/images/section_icons/conclusion.png');  
 }  
 section.role-definition>h1:before {  
   content:url('/adm/daxe/images/section_icons/definition.png');  
 }  
 section.role-demonstration>h1:before {  
   content:url('/adm/daxe/images/section_icons/demonstration.png');  
 }  
 section.role-example>h1:before {  
   content:url('/adm/daxe/images/section_icons/example.png');  
 }  
 section.role-explanation>h1:before {  
   content:url('/adm/daxe/images/section_icons/explanation.png');  
 }  
 section.role-introduction>h1:before {  
   content:url('/adm/daxe/images/section_icons/introduction.png');  
 }  
 section.role-method>h1:before {  
   content:url('/adm/daxe/images/section_icons/method.png');  
 }  
 section.role-more_information>h1:before {  
   content:url('/adm/daxe/images/section_icons/more_information.png');  
 }  
 section.role-objectives>h1:before {  
   content:url('/adm/daxe/images/section_icons/objectives.png');  
 }  
 section.role-prerequisites>h1:before {  
   content:url('/adm/daxe/images/section_icons/prerequisites.png');  
 }  
 section.role-remark>h1:before {  
   content:url('/adm/daxe/images/section_icons/remark.png');  
 }  
 section.role-reminder>h1:before {  
   content:url('/adm/daxe/images/section_icons/reminder.png');  
 }  
 section.role-summary>h1:before {  
   content:url('/adm/daxe/images/section_icons/summary.png');  
 }  
 section.role-syntax>h1:before {  
   content:url('/adm/daxe/images/section_icons/syntax.png');  
 }  
 section.role-warning>h1:before {  
   content:url('/adm/daxe/images/section_icons/warning.png');  
 }  
   
 #LC_minitab_header {  #LC_minitab_header {
   float:left;    float:left;
   width:100%;    width:100%;
Line 8802  Inputs: $title - optional title for the Line 8032  Inputs: $title - optional title for the
                                    3- whether the side effect should occur                                     3- whether the side effect should occur
                            (side effect of setting                              (side effect of setting 
                                $env{'internal.head.redirect'} to the url                                  $env{'internal.head.redirect'} to the url 
                                redirected to)                                 redirected too)
                                    4- whether the redirect target should be  
                                       the opener of the current (pop-up)  
                                       window (side effect of setting  
                                       $env{'internal.head.to_opener'} to  
                                       1, if true.  
                                    5- whether encrypt check should be skipped  
             domain         -> force to color decorate a page for a specific              domain         -> force to color decorate a page for a specific
                                domain                                 domain
             function       -> force usage of a specific rolish color scheme              function       -> force usage of a specific rolish color scheme
Line 8871  sub headtag { Line 8095  sub headtag {
         }          }
     }      }
     if (ref($args->{'redirect'})) {      if (ref($args->{'redirect'})) {
  my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};   my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
         if (!$skip_enc_check) {   $url = &Apache::lonenc::check_encrypt($url);
     $url = &Apache::lonenc::check_encrypt($url);  
         }  
  if (!$inhibit_continue) {   if (!$inhibit_continue) {
     $env{'internal.head.redirect'} = $url;      $env{'internal.head.redirect'} = $url;
  }   }
         $result.=<<"ADDMETA";   $result.=<<ADDMETA
 <meta http-equiv="pragma" content="no-cache" />  <meta http-equiv="pragma" content="no-cache" />
 ADDMETA  
         if ($to_opener) {  
             $env{'internal.head.to_opener'} = 1;  
             my $dest = &js_escape($url);  
             my $timeout = int($time * 1000);  
             $result .=<<"ENDJS";  
 <script type="text/javascript">  
 // <![CDATA[  
 function LC_To_Opener() {  
     var dest = '$dest';  
     if (dest != '') {  
         if (window.opener != null && !window.opener.closed) {  
             window.opener.location.href=dest;  
             window.close();  
         } else {  
             window.location.href=dest;  
         }  
     }  
 }  
 \$(document).ready(function () {  
     setTimeout('LC_To_Opener()',$timeout);  
 });  
 // ]]>  
 </script>  
 ENDJS  
         } else {  
             $result.=<<"ADDMETA";  
 <meta http-equiv="Refresh" content="$time; url=$url" />  <meta http-equiv="Refresh" content="$time; url=$url" />
 ADDMETA  ADDMETA
         }  
     } else {      } else {
         unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {          unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
             my $requrl = $env{'request.uri'};              my $requrl = $env{'request.uri'};
Line 8955  ADDMETA Line 8149  ADDMETA
                         my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);                          my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
                         if (($newserver eq '') && ($offloadoth)) {                          if (($newserver eq '') && ($offloadoth)) {
                             my @domains = &Apache::lonnet::current_machine_domains();                              my @domains = &Apache::lonnet::current_machine_domains();
                             if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {                              if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) { 
                                 ($newserver) = &Apache::lonnet::choose_server($dom_in_use);                                  ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
                             }                              }
                         }                          }
Line 9259  $args - additional optional args support Line 8453  $args - additional optional args support
              links_disabled -> Links in primary and secondary menus are disabled               links_disabled -> Links in primary and secondary menus are disabled
                                (Can enable them once page has loaded - see lonroles.pm                                 (Can enable them once page has loaded - see lonroles.pm
                                for an example).                                 for an example).
              links_target   -> Target for links, e.g., _parent (optional).  
   
 =back  =back
   
Line 9272  sub start_page { Line 8465  sub start_page {
     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));      #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
   
     $env{'internal.start_page'}++;      $env{'internal.start_page'}++;
     my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);      my ($result,@advtools);
   
     if (! exists($args->{'skip_phases'}{'head'}) ) {      if (! exists($args->{'skip_phases'}{'head'}) ) {
         $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);          $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
     }      }
       
     if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {  
         if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {  
             unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {  
                 $args->{'no_primary_menu'} = 1;  
             }  
             unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {  
                 $args->{'no_inline_menu'} = 1;  
             }  
             if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {  
                 map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});  
             }  
         } else {  
             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};  
             my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');  
             if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {  
                 unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {  
                     $args->{'no_primary_menu'} = 1;  
                 }  
                 unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {  
                     $args->{'no_inline_menu'} = 1;  
                 }  
                 if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {  
                     map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};  
                 }  
             }  
         }  
         ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},  
                                   $env{'course.'.$env{'request.course.id'}.'.domain'},  
                                   $env{'course.'.$env{'request.course.id'}.'.num'});  
     } elsif ($env{'request.course.id'}) {  
         my $expiretime=600;  
         if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {  
             &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});  
         }  
         my ($deeplinkmenu,$menuref);  
         ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();  
         if ($menucoll) {  
             if (ref($menuref) eq 'HASH') {  
                 %menu = %{$menuref};  
             }  
             if ($menu{'top'} eq 'n') {  
                 $args->{'no_primary_menu'} = 1;  
             }  
             if ($menu{'inline'} eq 'n') {  
                 unless (&Apache::lonnet::allowed('opa')) {  
                     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};  
                     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};  
                     my $crstype = &course_type();  
                     my $now = time;  
                     my $ccrole;  
                     if ($crstype eq 'Community') {  
                         $ccrole = 'co';  
                     } else {  
                         $ccrole = 'cc';  
                     }  
                     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {  
                         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});  
                         if ((($start) && ($start<0)) ||  
                             (($end) && ($end<$now))  ||  
                             (($start) && ($now<$start))) {  
                             $args->{'no_inline_menu'} = 1;  
                         }  
                     } else {  
                         $args->{'no_inline_menu'} = 1;  
                     }  
                 }  
             }  
         }  
     }  
   
     my $showncrumbs;  
     if (! exists($args->{'skip_phases'}{'body'}) ) {      if (! exists($args->{'skip_phases'}{'body'}) ) {
  if ($args->{'frameset'}) {   if ($args->{'frameset'}) {
     my $attr_string = &make_attr_string($args->{'force_register'},      my $attr_string = &make_attr_string($args->{'force_register'},
Line 9361  sub start_page { Line 8483  sub start_page {
                          $args->{'only_body'},      $args->{'domain'},                           $args->{'only_body'},      $args->{'domain'},
                          $args->{'force_register'}, $args->{'no_nav_bar'},                           $args->{'force_register'}, $args->{'no_nav_bar'},
                          $args->{'bgcolor'},        $args->{'no_inline_link'},                           $args->{'bgcolor'},        $args->{'no_inline_link'},
                          $args,                     \@advtools,                           $args,                     \@advtools);
                          $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);  
         }          }
     }      }
   
Line 9384  sub start_page { Line 8505  sub start_page {
   
     #Breadcrumbs      #Breadcrumbs
     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {      if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
         unless ($showncrumbs) {  
  &Apache::lonhtmlcommon::clear_breadcrumbs();   &Apache::lonhtmlcommon::clear_breadcrumbs();
  #if any br links exists, add them to the breadcrumbs   #if any br links exists, add them to the breadcrumbs
  if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {            if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
Line 9398  sub start_page { Line 8518  sub start_page {
                 }                  }
                 my $menulink;                  my $menulink;
                 # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.                  # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
                 if ((exists($args->{'bread_crumbs_nomenu'})) ||                  if (exists($args->{'bread_crumbs_nomenu'})) {
                     ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {  
                     $menulink = 0;                      $menulink = 0;
                 } else {                  } else {
                     undef($menulink);                      undef($menulink);
                 }                  }
                 my $linkprotout;  
                 if ($env{'request.deeplink.login'}) {  
                     my $linkprotout = &Apache::lonmenu::linkprot_exit();  
                     if ($linkprotout) {  
                         &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);  
                     }  
                 }  
  #if bread_crumbs_component exists show it as headline else show only the breadcrumbs   #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
  if(exists($args->{'bread_crumbs_component'})){   if(exists($args->{'bread_crumbs_component'})){
  $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);   $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
  } else {   }else{
  $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);   $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
  }   }
         }  
     } elsif (($env{'environment.remote'} eq 'on') &&      } elsif (($env{'environment.remote'} eq 'on') &&
              ($env{'form.inhibitmenu'} ne 'yes') &&               ($env{'form.inhibitmenu'} ne 'yes') &&
              ($env{'request.noversionuri'} =~ m{^/res/}) &&               ($env{'request.noversionuri'} =~ m{^/res/}) &&
Line 9459  sub end_page { Line 8570  sub end_page {
     return $result;      return $result;
 }  }
   
 sub menucoll_in_effect {  
     my ($menucoll,$deeplinkmenu,%menu);  
     if ($env{'request.course.id'}) {  
         $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};  
         if ($env{'request.deeplink.login'}) {  
             my ($deeplink_symb,$deeplink,$check_login_symb);  
             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};  
             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};  
             if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {  
                 if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {  
                     my $navmap = Apache::lonnavmaps::navmap->new();  
                     if (ref($navmap)) {  
                         $deeplink = $navmap->get_mapparam(undef,  
                                                           &Apache::lonnet::declutter($env{'request.noversionuri'}),  
                                                           '0.deeplink');  
                     } else {  
                         $check_login_symb = 1;  
                     }  
                 } else {  
                     my $symb=&Apache::lonnet::symbread();  
                     if ($symb) {  
                         $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);  
                     } else {  
                         $check_login_symb = 1;  
                     }  
                 }  
             } else {  
                 $check_login_symb = 1;  
             }  
             if ($check_login_symb) {  
                 $deeplink_symb = &deeplink_login_symb($cnum,$cdom);  
                 if ($deeplink_symb =~ /\.(page|sequence)$/) {  
                     my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);  
                     my $navmap = Apache::lonnavmaps::navmap->new();  
                     if (ref($navmap)) {  
                         $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');  
                     }  
                 } else {  
                     $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);  
                 }  
             }  
             if ($deeplink ne '') {  
                 my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);  
                 if ($display =~ /^\d+$/) {  
                     $deeplinkmenu = 1;  
                     $menucoll = $display;  
                 }  
             }  
         }  
         if ($menucoll) {  
             %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);  
         }  
     }  
     return ($menucoll,$deeplinkmenu,\%menu);  
 }  
   
 sub deeplink_login_symb {  
     my ($cnum,$cdom) = @_;  
     my $login_symb;  
     if ($env{'request.deeplink.login'}) {  
         $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);  
     }  
     return $login_symb;  
 }  
   
 sub symb_from_tinyurl {  
     my ($url,$cnum,$cdom) = @_;  
     if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {  
         my $key = $1;  
         my ($tinyurl,$login);  
         my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);  
         if (defined($cached)) {  
             $tinyurl = $result;  
         } else {  
             my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);  
             my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);  
             if ($currtiny{$key} ne '') {  
                 $tinyurl = $currtiny{$key};  
                 &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);  
             }  
         }  
         if ($tinyurl ne '') {  
             my ($cnumreq,$symb) = split(/\&/,$tinyurl);  
             if (wantarray) {  
                 return ($cnumreq,$symb);  
             } elsif ($cnumreq eq $cnum) {  
                 return $symb;  
             }  
         }  
     }  
     if (wantarray) {  
         return ();  
     } else {  
         return;  
     }  
 }  
   
 sub usable_exttools {  
     my %tooltypes;  
     if ($env{'request.course.id'}) {  
         if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {  
            if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {  
                %tooltypes = (  
                              crs => 1,  
                              dom => 1,  
                             );  
            } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {  
                $tooltypes{'crs'} = 1;  
            } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {  
                $tooltypes{'dom'} = 1;  
            }  
         } else {  
             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};  
             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};  
             my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});  
             if ($crstype eq '') {  
                 $crstype = 'course';  
             }  
             if ($crstype eq 'course') {  
                 if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {  
                     $crstype = 'official';  
                 } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {  
                     $crstype = 'textbook';  
                 } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {  
                     $crstype = 'lti';  
                 } else {  
                     $crstype = 'unofficial';  
                 }  
             }  
             my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);  
             if ($domdefaults{$crstype.'domexttool'}) {  
                 $tooltypes{'dom'} = 1;  
             }  
             if ($domdefaults{$crstype.'exttool'}) {  
                 $tooltypes{'crs'} = 1;  
             }  
         }  
     }  
     return %tooltypes;  
 }  
   
 sub wishlist_window {  sub wishlist_window {
     return(<<'ENDWISHLIST');      return(<<'ENDWISHLIST');
 <script type="text/javascript">  <script type="text/javascript">
Line 10091  function expand_div(caller) { Line 9061  function expand_div(caller) {
   
 sub simple_error_page {  sub simple_error_page {
     my ($r,$title,$msg,$args) = @_;      my ($r,$title,$msg,$args) = @_;
     my %displayargs;  
     if (ref($args) eq 'HASH') {      if (ref($args) eq 'HASH') {
         if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }          if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
         if ($args->{'only_body'}) {  
             $displayargs{'only_body'} = 1;  
         }  
         if ($args->{'no_nav_bar'}) {  
             $displayargs{'no_nav_bar'} = 1;  
         }  
     } else {      } else {
         $msg = &mt($msg);          $msg = &mt($msg);
     }      }
   
     my $page =      my $page =
  &Apache::loncommon::start_page($title,'',\%displayargs).   &Apache::loncommon::start_page($title).
  '<p class="LC_error">'.$msg.'</p>'.   '<p class="LC_error">'.$msg.'</p>'.
  &Apache::loncommon::end_page();   &Apache::loncommon::end_page();
     if (ref($r)) {      if (ref($r)) {
Line 14173  sub process_extracted_files { Line 13136  sub process_extracted_files {
                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.                              my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                                       $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.                                        $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
                                       $title;                                        $title;
                             if (($outer !~ /\D/) &&                              if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
                                 (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&  
                                 ($newidx !~ /\D/)) {  
                                 if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {                                  if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
                                     mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);                                      mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
                                 }                                  }
Line 15936  sub recurse_categories { Line 14897  sub recurse_categories {
         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {          for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
             my $name = $cats->[$depth]{$category}[$k];              my $name = $cats->[$depth]{$category}[$k];
             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;              my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
             my $trailstr = join(' &raquo; ',(@{$parents},$category));              my $trailstr = join(' -&gt; ',(@{$parents},$category));
             if ($allitems->{$item} eq '') {              if ($allitems->{$item} eq '') {
                 push(@{$trails},$trailstr);                  push(@{$trails},$trailstr);
                 $allitems->{$item} = scalar(@{$trails})-1;                  $allitems->{$item} = scalar(@{$trails})-1;
Line 16214  sub commit_studentrole { Line 15175  sub commit_studentrole {
                 }                  }
                 $oldsecurl = $uurl;                  $oldsecurl = $uurl;
                 $expire_role_result =                   $expire_role_result = 
                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);                      &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
                 if ($env{'request.course.sec'} ne '') {                   if ($env{'request.course.sec'} ne '') { 
                     if ($expire_role_result eq 'refused') {                      if ($expire_role_result eq 'refused') {
                         my @roles = ('st');                          my @roles = ('st');
Line 16326  sub check_clone { Line 15287  sub check_clone {
     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};      my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);      my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);      my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
     my $clonetitle;      my $clonemsg;
     my @clonemsg;  
     my $can_clone = 0;      my $can_clone = 0;
     my $lctype = lc($args->{'crstype'});      my $lctype = lc($args->{'crstype'});
     if ($lctype ne 'community') {      if ($lctype ne 'community') {
Line 16335  sub check_clone { Line 15295  sub check_clone {
     }      }
     if ($clonehome eq 'no_host') {      if ($clonehome eq 'no_host') {
         if ($args->{'crstype'} eq 'Community') {          if ($args->{'crstype'} eq 'Community') {
             push(@clonemsg,({              $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                               mt => 'No new community created.',  
                               args => [],  
                             },  
                             {  
                               mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',  
                               args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],  
                             }));  
         } else {          } else {
             push(@clonemsg,({              $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                               mt => 'No new course created.',          }     
                               args => [],  
                             },  
                             {  
                               mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',  
                               args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],  
                             }));  
         }  
     } else {      } else {
  my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});   my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
         $clonetitle = $clonedesc{'description'};  
         if ($args->{'crstype'} eq 'Community') {          if ($args->{'crstype'} eq 'Community') {
             if ($clonedesc{'type'} ne 'Community') {              if ($clonedesc{'type'} ne 'Community') {
                 push(@clonemsg,({                   $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                                   mt => 'No new community created.',                  return ($can_clone, $clonemsg, $cloneid, $clonehome);
                                   args => [],  
                                 },  
                                 {  
                                   mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',  
                                   args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],  
                                 }));  
                 return ($can_clone,\@clonemsg,$cloneid,$clonehome);  
             }              }
         }          }
  if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&   if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
Line 16455  sub check_clone { Line 15393  sub check_clone {
             }              }
             unless ($can_clone) {              unless ($can_clone) {
                 if ($args->{'crstype'} eq 'Community') {                  if ($args->{'crstype'} eq 'Community') {
                     push(@clonemsg,({                      $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
                                       mt => 'No new community created.',  
                                       args => [],  
                                     },  
                                     {  
                                       mt => 'The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',  
                                       args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],  
                                     }));  
                 } else {                  } else {
                     push(@clonemsg,({                      $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
                                       mt => 'No new course created.',  
                                       args => [],  
                                     },  
                                     {  
                                       mt => 'The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',  
                                       args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],  
                                     }));  
         }          }
     }      }
         }          }
     }      }
     return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);      return ($can_clone, $clonemsg, $cloneid, $clonehome);
 }  }
   
 sub construct_course {  sub construct_course {
     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,      my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
         $cnum,$category,$coderef,$callercontext,$user_lh) = @_;          $cnum,$category,$coderef) = @_;
     my ($outcome,$msgref,$clonemsgref);      my $outcome;
     my $linefeed =  '<br />'."\n";      my $linefeed =  '<br />'."\n";
     if ($context eq 'auto') {      if ($context eq 'auto') {
         $linefeed = "\n";          $linefeed = "\n";
Line 16491  sub construct_course { Line 15415  sub construct_course {
 #  #
 # Are we cloning?  # Are we cloning?
 #  #
     my ($can_clone,$cloneid,$clonehome,$clonetitle);      my ($can_clone, $clonemsg, $cloneid, $clonehome);
     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {      if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
  ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);   ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
    if ($context ne 'auto') {
               if ($clonemsg ne '') {
           $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
               }
    }
    $outcome .= $clonemsg.$linefeed;
   
         if (!$can_clone) {          if (!$can_clone) {
     return (0,$outcome,$clonemsgref);      return (0,$outcome);
  }   }
     }      }
   
Line 16513  sub construct_course { Line 15444  sub construct_course {
                                              $args->{'ccuname'}.':'.                                               $args->{'ccuname'}.':'.
                                              $args->{'ccdomain'},                                               $args->{'ccdomain'},
                                              $args->{'crstype'},                                               $args->{'crstype'},
                                              $cnum,$context,$category,                                               $cnum,$context,$category);
                                              $callercontext);  
   
     # Note: The testing routines depend on this being output; see       # Note: The testing routines depend on this being output; see 
     # Utils::Course. This needs to at least be output as a comment      # Utils::Course. This needs to at least be output as a comment
     # if anyone ever decides to not show this, and Utils::Course::new      # if anyone ever decides to not show this, and Utils::Course::new
     # will need to be suitably modified.      # will need to be suitably modified.
     if (($callercontext eq 'auto') && ($user_lh ne '')) {      $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
         $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;  
     } else {  
         $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;  
     }  
     if ($$courseid =~ /^error:/) {      if ($$courseid =~ /^error:/) {
         return (0,$outcome,$clonemsgref);          return (0,$outcome);
     }      }
   
 #  #
Line 16535  sub construct_course { Line 15461  sub construct_course {
     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);      ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);      my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
     if ($crsuhome eq 'no_host') {      if ($crsuhome eq 'no_host') {
         if (($callercontext eq 'auto') && ($user_lh ne '')) {          $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
             $outcome .= &mt_user($user_lh,          return (0,$outcome);
                             'Course creation failed, unrecognized course home server.');  
         } else {  
             $outcome .= &mt('Course creation failed, unrecognized course home server.');  
         }  
         $outcome .= $linefeed;  
         return (0,$outcome,$clonemsgref);  
     }      }
     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;      $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
   
 #  #
 # Do the cloning  # Do the cloning
 #  #   
     my @clonemsg;  
     if ($can_clone && $cloneid) {      if ($can_clone && $cloneid) {
         push(@clonemsg,   $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                       {   if ($context ne 'auto') {
                           mt => 'Created [_1] by cloning from [_2]',      $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                           args => [$crstype,$clonetitle],   }
                       });   $outcome .= $clonemsg.$linefeed;
  my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);   my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
 # Copy all files  # Copy all files
         my @info =   &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
             &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},  
                                                      $args->{'dateshift'},$args->{'crscode'},  
                                                      $args->{'ccuname'}.':'.$args->{'ccdomain'},  
                                                      $args->{'tinyurls'});  
         if (@info) {  
             push(@clonemsg,@info);  
         }  
 # Restore URL  # Restore URL
  $cenv{'url'}=$oldcenv{'url'};   $cenv{'url'}=$oldcenv{'url'};
 # Restore title  # Restore title
Line 16605  sub construct_course { Line 15517  sub construct_course {
     if ($args->{'crstype'}) {      if ($args->{'crstype'}) {
         $cenv{'type'}=$args->{'crstype'};          $cenv{'type'}=$args->{'crstype'};
     }      }
     if ($args->{'lti'}) {  
         $cenv{'internal.lti'}=$args->{'lti'};  
     }  
     if ($args->{'crsid'}) {      if ($args->{'crsid'}) {
         $cenv{'courseid'}=$args->{'crsid'};          $cenv{'courseid'}=$args->{'crsid'};
     }      }
Line 16629  sub construct_course { Line 15538  sub construct_course {
         $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};          $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
     }      }
     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.      my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
     my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.  
     if ($args->{'crssections'}) {      if ($args->{'crssections'}) {
         $cenv{'internal.sectionnums'} = '';          $cenv{'internal.sectionnums'} = '';
         if ($args->{'crssections'} =~ m/,/) {          if ($args->{'crssections'} =~ m/,/) {
Line 16643  sub construct_course { Line 15551  sub construct_course {
                 my $class = $args->{'crscode'}.$sec;                  my $class = $args->{'crscode'}.$sec;
                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});                  my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                 $cenv{'internal.sectionnums'} .= $item.',';                  $cenv{'internal.sectionnums'} .= $item.',';
                 if ($addcheck eq 'ok') {                  unless ($addcheck eq 'ok') {
                     unless (grep(/^\Q$gp\E$/,@oklcsecs)) {  
                         push(@oklcsecs,$gp);  
                     }  
                 } else {  
                     push(@badclasses,$class);                      push(@badclasses,$class);
                 }                  }
             }              }
Line 16675  sub construct_course { Line 15579  sub construct_course {
                 my ($xl,$gp) = split/:/,$item;                  my ($xl,$gp) = split/:/,$item;
                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});                  my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                 $cenv{'internal.crosslistings'} .= $item.',';                  $cenv{'internal.crosslistings'} .= $item.',';
                 if ($addcheck eq 'ok') {                  unless ($addcheck eq 'ok') {
                     unless (grep(/^\Q$gp\E$/,@oklcsecs)) {  
                         push(@oklcsecs,$gp);  
                     }  
                 } else {  
                     push(@badclasses,$xl);                      push(@badclasses,$xl);
                 }                  }
             }              }
Line 16742  sub construct_course { Line 15642  sub construct_course {
     if ($args->{'no_end_date'}) {      if ($args->{'no_end_date'}) {
         $args->{'endaccess'} = 0;          $args->{'endaccess'} = 0;
     }      }
 #  If an official course with institutional sections is created by cloning  
 #  an existing course, section-specific hiding of course totals in student's  
 #  view of grades as copied from cloned course, will be checked for valid  
 #  sections.  
     if (($can_clone && $cloneid) &&  
         ($cenv{'internal.coursecode'} ne '') &&  
         ($cenv{'grading'} eq 'standard') &&  
         ($cenv{'hidetotals'} ne '') &&  
         ($cenv{'hidetotals'} ne 'all')) {  
         my @hidesecs;  
         my $deletehidetotals;  
         if (@oklcsecs) {  
             foreach my $sec (split(/,/,$cenv{'hidetotals'})) {  
                 if (grep(/^\Q$sec$/,@oklcsecs)) {  
                     push(@hidesecs,$sec);  
                 }  
             }  
             if (@hidesecs) {  
                 $cenv{'hidetotals'} = join(',',@hidesecs);  
             } else {  
                 $deletehidetotals = 1;  
             }  
         } else {  
             $deletehidetotals = 1;  
         }  
         if ($deletehidetotals) {  
             delete($cenv{'hidetotals'});  
             &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);  
         }  
     }  
     $cenv{'internal.autostart'}=$args->{'enrollstart'};      $cenv{'internal.autostart'}=$args->{'enrollstart'};
     $cenv{'internal.autoend'}=$args->{'enrollend'};      $cenv{'internal.autoend'}=$args->{'enrollend'};
     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};      $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
Line 16890  sub construct_course { Line 15760  sub construct_course {
 #  #
     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')      unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
     || ($cloneid)) {      || ($cloneid)) {
    use LONCAPA::map;
  $outcome .= &mt('Setting first resource').': ';   $outcome .= &mt('Setting first resource').': ';
   
  my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';   my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
Line 16912  sub construct_course { Line 15783  sub construct_course {
         $outcome .= ($fatal?$errtext:'write ok').$linefeed;          $outcome .= ($fatal?$errtext:'write ok').$linefeed;
     }      }
   
     return (1,$outcome,\@clonemsg);      return (1,$outcome);
 }  }
   
 sub make_unique_code {  sub make_unique_code {
Line 16996  sub group_term { Line 15867  sub group_term {
 }  }
   
 sub course_types {  sub course_types {
     my @types = ('official','unofficial','community','textbook','lti');      my @types = ('official','unofficial','community','textbook');
     my %typename = (      my %typename = (
                          official   => 'Official course',                           official   => 'Official course',
                          unofficial => 'Unofficial course',                           unofficial => 'Unofficial course',
                          community  => 'Community',                           community  => 'Community',
                          textbook   => 'Textbook course',                           textbook   => 'Textbook course',
                          lti        => 'LTI provider',  
                    );                     );
     return (\@types,\%typename);      return (\@types,\%typename);
 }  }
Line 17109  sub init_user_environment { Line 15979  sub init_user_environment {
   
 # See if old ID present, if so, remove  # See if old ID present, if so, remove
   
     my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,      my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
         $coauthorenv);  
     my $now=time;      my $now=time;
   
     if ($public) {      if ($public) {
Line 17175  sub init_user_environment { Line 16044  sub init_user_environment {
           
 # Initialize roles  # Initialize roles
   
  ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =    ($userroles,$firstaccenv,$timerintenv) = 
             &Apache::lonnet::rolesinit($domain,$username,$authhost);              &Apache::lonnet::rolesinit($domain,$username,$authhost);
     }      }
 # ------------------------------------ Check browser type and MathML capability  # ------------------------------------ Check browser type and MathML capability
Line 17254  sub init_user_environment { Line 16123  sub init_user_environment {
             my %is_adv = ( is_adv => $env{'user.adv'} );              my %is_adv = ( is_adv => $env{'user.adv'} );
             my %domdef = &Apache::lonnet::get_domain_defaults($domain);              my %domdef = &Apache::lonnet::get_domain_defaults($domain);
   
             foreach my $tool ('aboutme','blog','webdav','portfolio','timezone') {              foreach my $tool ('aboutme','blog','webdav','portfolio') {
                 $userenv{'availabletools.'.$tool} =                   $userenv{'availabletools.'.$tool} = 
                     &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',                      &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                                                       undef,\%userenv,\%domdef,\%is_adv);                                                        undef,\%userenv,\%domdef,\%is_adv);
             }              }
   
             foreach my $crstype ('official','unofficial','community','textbook','lti') {              foreach my $crstype ('official','unofficial','community','textbook') {
                 $userenv{'canrequest.'.$crstype} =                  $userenv{'canrequest.'.$crstype} =
                     &Apache::lonnet::usertools_access($username,$domain,$crstype,                      &Apache::lonnet::usertools_access($username,$domain,$crstype,
                                                       'reload','requestcourses',                                                        'reload','requestcourses',
                                                       \%userenv,\%domdef,\%is_adv);                                                        \%userenv,\%domdef,\%is_adv);
             }              }
   
             if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&  
                 (exists($userroles->{"user.role.au./$domain/"}))) {  
                 if ($userenv{'authoreditors'}) {  
                     $userenv{'editors'} = $userenv{'authoreditors'};  
                 } elsif ($domdef{'editors'} ne '') {  
                     $userenv{'editors'} = $domdef{'editors'};  
                 } else {  
                     $userenv{'editors'} = 'edit,xml';  
                 }  
             }  
   
             $userenv{'canrequest.author'} =              $userenv{'canrequest.author'} =
                 &Apache::lonnet::usertools_access($username,$domain,'requestauthor',                  &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
                                                   'reload','requestauthor',                                                    'reload','requestauthor',
Line 17306  sub init_user_environment { Line 16164  sub init_user_environment {
             if (ref($timerintenv) eq 'HASH') {              if (ref($timerintenv) eq 'HASH') {
                 &_add_to_env(\%disk_env,$timerintenv);                  &_add_to_env(\%disk_env,$timerintenv);
             }              }
             if (ref($coauthorenv) eq 'HASH') {  
                 if (keys(%{$coauthorenv})) {  
                     &_add_to_env(\%disk_env,$coauthorenv);  
                 }  
             }  
     if (ref($args->{'extra_env'})) {      if (ref($args->{'extra_env'})) {
  &_add_to_env(\%disk_env,$args->{'extra_env'});   &_add_to_env(\%disk_env,$args->{'extra_env'});
     }      }
Line 18098  sub needs_coursereinit { Line 16951  sub needs_coursereinit {
         $interval = 600;          $interval = 600;
     }      }
     if (($now-$env{'request.course.timechecked'})>$interval) {      if (($now-$env{'request.course.timechecked'})>$interval) {
           my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
         &Apache::lonnet::appenv({'request.course.timechecked'=>$now});          &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
         my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);          if ($lastchange > $env{'request.course.tied'}) {
         if ($blocked) {              my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
             return ();              if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
         }                  my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
         my $update;                  if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
         my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);                      &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
         my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);                                               $curr_reqd_hash{'internal.releaserequired'}});
         if ($lastmainchange > $env{'request.course.tied'}) {                      my ($switchserver,$switchwarning) =
             my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);                          &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
             if ($needswitch) {                                                  $curr_reqd_hash{'internal.releaserequired'});
                 return ('switch',$switchwarning,$switchserver);                      if ($switchwarning ne '' || $switchserver ne '') {
             }                          return ('switch',$switchwarning,$switchserver);
             $update = 'main';                      }
         }  
         if ($lastsuppchange > $env{'request.course.suppupdated'}) {  
             if ($update) {  
                 $update = 'both';  
             } else {  
                 my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);  
                 if ($needswitch) {  
                     return ('switch',$switchwarning,$switchserver);  
                 } else {  
                     $update = 'supp';  
                 }                  }
             }              }
             return ($update);              return ('update');
         }  
     }  
     return ();  
 }  
   
 sub switch_for_update {  
     my ($loncaparev,$cdom,$cnum) = @_;  
     my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');  
     if ($curr_reqd_hash{'internal.releaserequired'} ne '') {  
         my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};  
         if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {  
             &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>  
                                     $curr_reqd_hash{'internal.releaserequired'}});  
             my ($switchserver,$switchwarning) =  
                 &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},  
                                         $curr_reqd_hash{'internal.releaserequired'});  
             if ($switchwarning ne '' || $switchserver ne '') {  
                 return ('switch',$switchwarning,$switchserver);  
             }  
         }          }
     }      }
     return ();      return ();
Line 18226  sub parse_supplemental_title { Line 17051  sub parse_supplemental_title {
         my $name =  &plainname($uname,$udom);          my $name =  &plainname($uname,$udom);
         $name = &HTML::Entities::encode($name,'"<>&\'');          $name = &HTML::Entities::encode($name,'"<>&\'');
         $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');          $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
         $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;          $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
         if ($foldertitle ne '') {              $name.': <br />'.$foldertitle;
             $title .= ': <br />'.$foldertitle;  
         }  
     }      }
     if (wantarray) {      if (wantarray) {
         return ($title,$foldertitle,$renametitle);          return ($title,$foldertitle,$renametitle);
Line 18237  sub parse_supplemental_title { Line 17060  sub parse_supplemental_title {
     return $title;      return $title;
 }  }
   
 sub get_supplemental {  
     my ($cnum,$cdom,$ignorecache,$possdel)=@_;  
     my $hashid=$cnum.':'.$cdom;  
     my ($supplemental,$cached,$set_httprefs);  
     unless ($ignorecache) {  
         ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);  
     }  
     unless (defined($cached)) {  
         my $chome=&Apache::lonnet::homeserver($cnum,$cdom);  
         unless ($chome eq 'no_host') {  
             my @order = @LONCAPA::map::order;  
             my @resources = @LONCAPA::map::resources;  
             my @resparms = @LONCAPA::map::resparms;  
             my @zombies = @LONCAPA::map::zombies;  
             my ($errors,%ids,%hidden);  
             $errors =  
                 &recurse_supplemental($cnum,$cdom,'supplemental.sequence',  
                                       $errors,$possdel,\%ids,\%hidden);  
             @LONCAPA::map::order = @order;  
             @LONCAPA::map::resources = @resources;  
             @LONCAPA::map::resparms = @resparms;  
             @LONCAPA::map::zombies = @zombies;  
             $set_httprefs = 1;  
             if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {  
                 &Apache::lonnet::appenv({'request.course.suppupdated' => time});  
             }  
             $supplemental = {  
                                ids => \%ids,  
                                hidden => \%hidden,  
                             };  
             &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);  
         }  
     }  
     return ($supplemental,$set_httprefs);  
 }  
   
 sub recurse_supplemental {  sub recurse_supplemental {
     my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;      my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
     if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {      if ($suppmap) {
         my $mapnum;  
         if ($suppmap eq 'supplemental.sequence') {  
             $mapnum = 0;  
         } else {  
             ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);  
         }  
         my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);          my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
         if ($fatal) {          if ($fatal) {
             $errors ++;              $errors ++;
         } else {          } else {
             my @order = @LONCAPA::map::order;              if ($#LONCAPA::map::resources > 0) {
             if (@order > 0) {                  foreach my $res (@LONCAPA::map::resources) {
                 my @resources = @LONCAPA::map::resources;                      my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
                 my @resparms = @LONCAPA::map::resparms;  
                 foreach my $idx (@order) {  
                     my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);  
                     if (($src ne '') && ($status eq 'res')) {                      if (($src ne '') && ($status eq 'res')) {
                         my $id = $mapnum.':'.$idx;  
                         push(@{$suppids->{$src}},$id);  
                         if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {  
                             $hiddensupp->{$id} = 1;  
                         }  
                         if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {                          if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
                             $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,                              ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
                                                             $hiddensupp,$hiddensupp->{$id});  
                         } else {                          } else {
                             my $allowed;                              $numfiles ++;
                             if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {  
                                 $allowed = 1;  
                             } elsif ($possdel) {  
                                 foreach my $item (@{$suppids->{$src}}) {  
                                     next if ($item eq $id);  
                                     unless ($hiddensupp->{$item}) {  
                                        $allowed = 1;  
                                        last;  
                                     }  
                                 }  
                                 if ((!$allowed) && (exists($env{'httpref.'.$src}))) {  
                                     &Apache::lonnet::delenv('httpref.'.$src);  
                                 }  
                             }  
                             if ($allowed && (!exists($env{'httpref.'.$src}))) {  
                                 &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);  
                             }  
                         }                          }
                     }                      }
                 }                  }
             }              }
         }          }
     }      }
     return $errors;      return ($numfiles,$errors);
 }  
   
 sub set_supp_httprefs {  
     my ($cnum,$cdom,$supplemental,$possdel) = @_;  
     if (ref($supplemental) eq 'HASH') {  
         if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {  
             foreach my $src (keys(%{$supplemental->{'ids'}})) {  
                 next if ($src =~ /\.sequence$/);  
                 if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {  
                     my $allowed;  
                     if ($env{'request.role.adv'}) {  
                         $allowed = 1;  
                     } else {  
                         foreach my $id (@{$supplemental->{'ids'}->{$src}}) {  
                             unless ($supplemental->{'hidden'}->{$id}) {  
                                 $allowed = 1;  
                                 last;  
                             }  
                         }  
                     }  
                     if (exists($env{'httpref.'.$src})) {  
                         if ($possdel) {  
                             unless ($allowed) {  
                                 &Apache::lonnet::delenv('httpref.'.$src);  
                             }  
                         }  
                     } elsif ($allowed) {  
                         &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);  
                     }  
                 }  
             }  
             if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {  
                 &Apache::lonnet::appenv({'request.course.suppupdated' => time});  
             }  
         }  
     }  
 }  
   
 sub get_supp_parameter {  
     my ($resparm,$name)=@_;  
     return if ($resparm eq '');  
     my $value=undef;  
     my $ptype=undef;  
     foreach (split('&&&',$resparm)) {  
         my ($thistype,$thisname,$thisvalue)=split('___',$_);  
         if ($thisname eq $name) {  
             $value=$thisvalue;  
             $ptype=$thistype;  
         }  
     }  
     return $value;  
 }  }
   
 sub symb_to_docspath {  sub symb_to_docspath {
Line 18450  sub symb_to_docspath { Line 17154  sub symb_to_docspath {
     return $path;      return $path;
 }  }
   
 sub validate_folderpath {  
     my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;  
     if ($env{'form.folderpath'} ne '') {  
         my @items = split(/\&/,$env{'form.folderpath'});  
         my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);  
         for (my $i=0; $i<@items; $i++) {  
             my $odd = $i%2;  
             if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {  
                 $badpath = 1;  
             } elsif ($odd && $supplementalflag) {  
                 my $idx = $i-1;  
                 if ($items[$i] =~ /^([^:]*)::(|1):::$/) {  
                     my $esc_name = $1;  
                     if ((!$allowed) || ($items[$idx] eq 'supplemental')) {  
                         $supppath .= '&'.$esc_name;  
                         $changed = 1;  
                     } else {  
                         $supppath .= '&'.$items[$i];  
                     }  
                 } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {  
                     $changed = 1;  
                     my $is_hidden;  
                     unless ($got_supp) {  
                         my ($supplemental) = &get_supplemental($coursenum,$coursedom);  
                         if (ref($supplemental) eq 'HASH') {  
                             if (ref($supplemental->{'hidden'}) eq 'HASH') {  
                                 %supphidden = %{$supplemental->{'hidden'}};  
                             }  
                             if (ref($supplemental->{'ids'}) eq 'HASH') {  
                                 %suppids = %{$supplemental->{'ids'}};  
                             }  
                         }  
                         $got_supp = 1;  
                     }  
                     if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {  
                         my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];  
                         if ($supphidden{$mapid}) {  
                             $is_hidden = 1;  
                         }  
                     }  
                     $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';  
                 } else {  
                     $supppath .= '&'.$items[$i];  
                 }  
             } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {  
                 $badpath = 1;  
             } elsif ($supplementalflag) {  
                 $supppath .= '&'.$items[$i];  
             }  
             last if ($badpath);  
         }  
         if ($badpath) {  
             delete($env{'form.folderpath'});  
         } elsif ($changed && $supplementalflag) {  
             $supppath =~ s/^\&//;  
             $env{'form.folderpath'} = $supppath;  
         }  
     }  
     return;  
 }  
   
 sub captcha_display {  sub captcha_display {
     my ($context,$lonhost,$defdom) = @_;      my ($context,$lonhost,$defdom) = @_;
     my ($output,$error);      my ($output,$error);
Line 18633  sub create_captcha { Line 17276  sub create_captcha {
             $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".              $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
                       '<span class="LC_nobreak">'.                        '<span class="LC_nobreak">'.
                       &mt('Type in the letters/numbers shown below').'&nbsp;'.                        &mt('Type in the letters/numbers shown below').'&nbsp;'.
                       '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.                        '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
                       '</span><br />'.                        '</span><br />'.
                       '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';                        '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
             last;              last;
Line 18771  sub cleanup_html { Line 17414  sub cleanup_html {
   
 # Checks for critical messages and returns a redirect url if one exists.  # Checks for critical messages and returns a redirect url if one exists.
 # $interval indicates how often to check for messages.  # $interval indicates how often to check for messages.
 # $context is the calling context -- roles, grades, contents, menu or flip.  
 sub critical_redirect {  sub critical_redirect {
     my ($interval,$context) = @_;      my ($interval) = @_;
     unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {      unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
         return ();          return ();
     }      }
     if ((time-$env{'user.criticalcheck.time'})>$interval) {      if ((time-$env{'user.criticalcheck.time'})>$interval) {
         if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {  
             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};  
             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};  
             my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);  
             if ($blocked) {  
                 my $checkrole = "cm./$cdom/$cnum";  
                 if ($env{'request.course.sec'} ne '') {  
                     $checkrole .= "/$env{'request.course.sec'}";  
                 }  
                 unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&  
                         ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {  
                     return;  
                 }  
             }  
         }  
         my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},          my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
                                         $env{'user.name'});                                          $env{'user.name'});
         &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});          &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
Line 18858  sub des_decrypt { Line 17485  sub des_decrypt {
     return $plaintext;      return $plaintext;
 }  }
   
 sub get_requested_shorturls {  
     my ($cdom,$cnum,$navmap) = @_;  
     return unless (ref($navmap));  
     my ($numnew,$errors);  
     my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');  
     if (@toshorten) {  
         my (%maps,%resources,%titles);  
         &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,  
                                                                'shorturls',$cdom,$cnum);  
         if (keys(%resources)) {  
             my %tocreate;  
             foreach my $item (sort {$a <=> $b} (@toshorten)) {  
                 my $symb = $resources{$item};  
                 if ($symb) {  
                     $tocreate{$cnum.'&'.$symb} = 1;  
                 }  
             }  
             if (keys(%tocreate)) {  
                 ($numnew,$errors) = &make_short_symbs($cdom,$cnum,  
                                                       \%tocreate);  
             }  
         }  
     }  
     return ($numnew,$errors);  
 }  
   
 sub make_short_symbs {  
     my ($cdom,$cnum,$tocreateref,$lockuser) = @_;  
     my ($numnew,@errors);  
     if (ref($tocreateref) eq 'HASH') {  
         my %tocreate = %{$tocreateref};  
         if (keys(%tocreate)) {  
             my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);  
             my $su = Short::URL->new(no_vowels => 1);  
             my $init = '';  
             my (%newunique,%addcourse,%courseonly,%failed);  
             # get lock on tiny db  
             my $now = time;  
             if ($lockuser eq '') {  
                 $lockuser = $env{'user.name'}.':'.$env{'user.domain'};  
             }  
             my $lockhash = {  
                                 "lock\0$now" => $lockuser,  
                             };  
             my $tries = 0;  
             my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);  
             my ($code,$error);  
             while (($gotlock ne 'ok') && ($tries<3)) {  
                 $tries ++;  
                 sleep 1;  
                 $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);  
             }  
             if ($gotlock eq 'ok') {  
                 $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,  
                                        \%addcourse,\%courseonly,\%failed);  
                 if (keys(%failed)) {  
                     my $numfailed = scalar(keys(%failed));  
                     push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));  
                 }  
                 if (keys(%newunique)) {  
                     my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);  
                     if ($putres eq 'ok') {  
                         $numnew = scalar(keys(%newunique));  
                         my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);  
                         unless ($newputres eq 'ok') {  
                             push(@errors,&mt('error: could not store course look-up of short URLs'));  
                         }  
                     } else {  
                         push(@errors,&mt('error: could not store unique six character URLs'));  
                     }  
                 }  
                 my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);  
                 unless ($dellockres eq 'ok') {  
                     push(@errors,&mt('error: could not release lockfile'));  
                 }  
             } else {  
                 push(@errors,&mt('error: could not obtain lockfile'));  
             }  
             if (keys(%courseonly)) {  
                 my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);  
                 if ($result ne 'ok') {  
                     push(@errors,&mt('error: could not update course look-up of short URLs'));  
                 }  
             }  
         }  
     }  
     return ($numnew,\@errors);  
 }  
   
 sub shorten_symbs {  
     my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;  
     return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&  
                    (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&  
                    (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));  
     my (%possibles,%collisions);  
     foreach my $key (keys(%{$tocreate})) {  
         my $num = String::CRC32::crc32($key);  
         my $tiny = $su->encode($num,$init);  
         if ($tiny) {  
             $possibles{$tiny} = $key;  
         }  
     }  
     if (!$init) {  
         $init = 1;  
     } else {  
         $init ++;  
     }  
     if (keys(%possibles)) {  
         my @posstiny = keys(%possibles);  
         my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);  
         my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);  
         if (keys(%currtiny)) {  
             foreach my $key (keys(%currtiny)) {  
                 next if ($currtiny{$key} eq '');  
                 if ($currtiny{$key} eq $possibles{$key}) {  
                     my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});  
                     unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {  
                         $courseonly->{$tsymb} = $key;  
                     }  
                 } else {  
                     $collisions{$possibles{$key}} = 1;  
                 }  
                 delete($possibles{$key});  
             }  
         }  
         foreach my $key (keys(%possibles)) {  
             $newunique->{$key} = $possibles{$key};  
             my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});  
             unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {  
                 $addcourse->{$tsymb} = $key;  
             }  
         }  
     }  
     if (keys(%collisions)) {  
         if ($init <5) {  
             if (!$init) {  
                 $init = 1;  
             } else {  
                 $init ++;  
             }  
             $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,  
                                    $newunique,$addcourse,$courseonly,$failed);  
         } else {  
             foreach my $key (keys(%collisions)) {  
                 $failed->{$key} = 1;  
                 $failed->{$key} = 1;  
             }  
         }  
     }  
     return $init;  
 }  
   
 sub is_nonframeable {  sub is_nonframeable {
     my ($url,$absolute,$hostname,$ip,$nocache) = @_;      my ($url,$absolute,$hostname,$ip,$nocache) = @_;
     my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);      my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
Line 19163  sub is_nonframeable { Line 17638  sub is_nonframeable {
     return $uselink;      return $uselink;
 }  }
   
 sub page_menu {  
     my ($menucolls,$menunum) = @_;  
     my %menu;  
     foreach my $item (split(/;/,$menucolls)) {  
         my ($num,$value) = split(/\%/,$item);  
         if ($num eq $menunum) {  
             my @entries = split(/\&/,$value);  
             foreach my $entry (@entries) {  
                 my ($name,$fields) = split(/=/,$entry);  
                 if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {  
                     $menu{$name} = $fields;  
                 } else {  
                     my @shown;  
                     if ($fields =~ /,/) {  
                         @shown = split(/,/,$fields);  
                     } else {  
                         @shown = ($fields);  
                     }  
                     if (@shown) {  
                         foreach my $field (@shown) {  
                             next if ($field eq '');  
                             $menu{$field} = 1;  
                         }  
                     }  
                 }  
             }  
         }  
     }  
     return %menu;  
 }  
   
 1;  1;
 __END__;  __END__;
   

Removed from v.1.1075.2.161.2.24  
changed lines
  Added in v.1.1075.2.162


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>