Diff for /loncom/interface/loncommon.pm between versions 1.454 and 1.524

version 1.454, 2006/09/13 19:42:06 version 1.524, 2007/04/16 23:15:42
Line 59  use Apache::lonnet; Line 59  use Apache::lonnet;
 use GDBM_File;  use GDBM_File;
 use POSIX qw(strftime mktime);  use POSIX qw(strftime mktime);
 use Apache::lonmenu();  use Apache::lonmenu();
   use Apache::lonenc();
 use Apache::lonlocal;  use Apache::lonlocal;
 use HTML::Entities;  use HTML::Entities;
 use Apache::lonhtmlcommon();  use Apache::lonhtmlcommon();
 use Apache::loncoursedata();  use Apache::loncoursedata();
 use Apache::lontexconvert();  use Apache::lontexconvert();
 use Apache::lonclonecourse();  use Apache::lonclonecourse();
 use LONCAPA;  use LONCAPA qw(:DEFAULT :match);
   
   # ---------------------------------------------- Designs
   use vars qw(%defaultdesign);
   
 my $readit;  my $readit;
   
   
 ##  ##
 ## Global Variables  ## Global Variables
 ##  ##
Line 81  my %scprtag; Line 86  my %scprtag;
 my %fe; my %fd; my %fm;  my %fe; my %fd; my %fm;
 my %category_extensions;  my %category_extensions;
   
 # ---------------------------------------------- Designs  
   
 my %designhash;  
   
 # ---------------------------------------------- Thesaurus variables  # ---------------------------------------------- Thesaurus variables
 #  #
 # %Keywords:  # %Keywords:
Line 150  BEGIN { Line 151  BEGIN {
         }          }
     }      }
   
 # -------------------------------------------------------------- domain designs  # -------------------------------------------------------------- default domain designs
   
     my $filename;  
     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';      my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
     opendir(DIR,$designdir);      my $designfile = $designdir.'/default.tab';
     while ($filename=readdir(DIR)) {      if ( open (my $fh,"<$designfile") ) {
  if ($filename!~/\.tab$/) { next; }          while (my $line = <$fh>) {
  my ($domain)=($filename=~/^(\w+)\./);              next if ($line =~ /^\#/);
  {              chomp($line);
     my $designfile = $designdir.'/'.$filename;              my ($key,$val)=(split(/\=/,$line));
     if ( open (my $fh,"<$designfile") ) {              if ($val) { $defaultdesign{$key}=$val; }
  while (my $line = <$fh>) {          }
     next if ($line =~ /^\#/);          close($fh);
     chomp($line);  
     my ($key,$val)=(split(/\=/,$line));  
     if ($val) { $designhash{$domain.'.'.$key}=$val; }  
  }  
  close($fh);  
     }  
  }  
   
     }      }
     closedir(DIR);  
   
   
 # ------------------------------------------------------------- file categories  # ------------------------------------------------------------- file categories
     {      {
Line 386  sub selectstudent_link { Line 375  sub selectstudent_link {
 }  }
   
 sub coursebrowser_javascript {  sub coursebrowser_javascript {
     my ($domainfilter)=@_;      my ($domainfilter,$sec_element,$formname)=@_;
     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');      my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
    return (<<ENDSTDBRW);     my $output = '
 <script type="text/javascript" language="Javascript" >  <script type="text/javascript" language="Javascript" >
     var stdeditbrowser;      var stdeditbrowser;'."\n";
      $output .= <<"ENDSTDBRW";
     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {      function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
         var url = '/adm/pickcourse?';          var url = '/adm/pickcourse?';
         var filter;          var domainfilter = '';
         if (filter != null) {          var formid = getFormIdByName(formname);
            if (filter != '') {          if (formid > -1) {
                url += 'filter='+filter+'&';              var domid = getIndexByName(formid,udom);
    }              if (domid > -1) {
                   if (document.forms[formid].elements[domid].type == 'select-one') {
                       domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                   }
                   if (document.forms[formid].elements[domid].type == 'hidden') {
                       domainfilter=document.forms[formid].elements[domid].value;
                   }
               }
         }          }
         var domainfilter='$domainfilter';  
         if (domainfilter != null) {          if (domainfilter != null) {
            if (domainfilter != '') {             if (domainfilter != '') {
                url += 'domainfilter='+domainfilter+'&';                 url += 'domainfilter='+domainfilter+'&';
Line 408  sub coursebrowser_javascript { Line 404  sub coursebrowser_javascript {
         url += 'form=' + formname + '&cnumelement='+uname+          url += 'form=' + formname + '&cnumelement='+uname+
                             '&cdomelement='+udom+                              '&cdomelement='+udom+
                                     '&cnameelement='+desc;                                      '&cnameelement='+desc;
         if (extra_element !=null && extra_element != '' && formname == 'rolechoice') {          if (extra_element !=null && extra_element != '') {
             url += '&roleelement='+extra_element;              if (formname == 'rolechoice') {
             if (domainfilter == null || domainfilter == '') {                  url += '&roleelement='+extra_element;
                 url += '&domainfilter='+extra_element;                  if (domainfilter == null || domainfilter == '') {
                       url += '&domainfilter='+extra_element;
                   }
             }              }
               else {
                   if (formname == 'portform') {
                       url += '&setroles='+extra_element;
                   }
               }     
         }          }
         if (multflag !=null && multflag != '') {          if (multflag !=null && multflag != '') {
             url += '&multiple='+multflag;              url += '&multiple='+multflag;
Line 435  sub coursebrowser_javascript { Line 438  sub coursebrowser_javascript {
         stdeditbrowser = open(url,title,options,'1');          stdeditbrowser = open(url,title,options,'1');
         stdeditbrowser.focus();          stdeditbrowser.focus();
     }      }
 </script>  
       function getFormIdByName(formname) {
           for (var i=0;i<document.forms.length;i++) {
               if (document.forms[i].name == formname) {
                   return i;
               }
           }
           return -1; 
       }
   
       function getIndexByName(formid,item) {
           for (var i=0;i<document.forms[formid].elements.length;i++) {
               if (document.forms[formid].elements[i].name == item) {
                   return i;
               }
           }
           return -1;
       }
 ENDSTDBRW  ENDSTDBRW
       if ($sec_element ne '') {
           $output .= &setsec_javascript($sec_element,$formname);
       }
       $output .= '
   </script>';
       return $output;
 }  }
   
   sub setsec_javascript {
       my ($sec_element,$formname) = @_;
       my $setsections = qq|
   function setSect(sectionlist) {
       var sectionsArray = sectionlist.split(",");
       var numSections = sectionsArray.length;
       document.$formname.$sec_element.length = 0;
       if (numSections == 0) {
           document.$formname.$sec_element.multiple=false;
           document.$formname.$sec_element.size=1;
           document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
       } else {
           if (numSections == 1) {
               document.$formname.$sec_element.multiple=false;
               document.$formname.$sec_element.size=1;
               document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
               document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
               document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
           } else {
               for (var i=0; i<numSections; i++) {
                   document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
               }
               document.$formname.$sec_element.multiple=true
               if (numSections < 3) {
                   document.$formname.$sec_element.size=numSections;
               } else {
                   document.$formname.$sec_element.size=3;
               }
               document.$formname.$sec_element.options[0].selected = false
           }
       }
   }
   |;
       return $setsections;
   }
   
   
 sub selectcourse_link {  sub selectcourse_link {
    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;     my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
     return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.     return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
         '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select [_1]',$selecttype)."</a>";          '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
 }  }
   
 sub check_uncheck_jscript {  sub check_uncheck_jscript {
Line 1190  sub create_text_file { Line 1253  sub create_text_file {
 ##        Home server <option> list generating code          ##  ##        Home server <option> list generating code          ##
 ###############################################################  ###############################################################
   
 =pod  
   
 =head1 Home Server option list generating code  
   
 =over 4  
   
 =item * get_domains()  
   
 Returns an array containing each of the domains listed in the hosts.tab  
 file.  
   
 =cut  
   
 #-------------------------------------------  
 sub get_domains {  
     # The code below was stolen from "The Perl Cookbook", p 102, 1st ed.  
     my @domains;  
     my %seen;  
     foreach my $dom (sort(values(%Apache::lonnet::hostdom))) {  
  push(@domains,$dom) unless $seen{$dom}++;  
     }  
     return @domains;  
 }  
   
 # ------------------------------------------  # ------------------------------------------
   
 sub domain_select {  sub domain_select {
     my ($name,$value,$multiple)=@_;      my ($name,$value,$multiple)=@_;
     my %domains=map {       my %domains=map { 
  $_ => $_.' '.$Apache::lonnet::domaindescription{$_}    $_ => $_.' '. &Apache::lonnet::domain($_,'description') 
     } &get_domains;      } &Apache::lonnet::all_domains();
     if ($multiple) {      if ($multiple) {
  $domains{''}=&mt('Any domain');   $domains{''}=&mt('Any domain');
  return &multiple_select_form($name,$value,4,\%domains);   return &multiple_select_form($name,$value,4,\%domains);
Line 1233  sub domain_select { Line 1272  sub domain_select {
   
 =pod  =pod
   
   =head1 Routines for form select boxes
   
   =over 4
   
   =cut
   
 =item * multiple_select_form($name,$value,$size,$hash,$order)  =item * multiple_select_form($name,$value,$size,$hash,$order)
   
 Returns a string containing a <select> element int multiple mode  Returns a string containing a <select> element int multiple mode
Line 1240  Returns a string containing a <select> e Line 1285  Returns a string containing a <select> e
   
 Args:  Args:
   $name - name of the <select> element    $name - name of the <select> element
   $value - sclara or array ref of values that should already be selected    $value - scalar or array ref of values that should already be selected
   $size - number of rows long the select element is    $size - number of rows long the select element is
   $hash - the elements should be 'option' => 'shown text'    $hash - the elements should be 'option' => 'shown text'
           (shown text should already have been &mt())            (shown text should already have been &mt())
   $order - (optional) array ref of the order to show the elments in    $order - (optional) array ref of the order to show the elements in
   
 =cut  =cut
   
Line 1260  sub multiple_select_form { Line 1305  sub multiple_select_form {
         }          }
     }      }
     $output.="\n<select name='$name' size='$size' multiple='1'>";      $output.="\n<select name='$name' size='$size' multiple='1'>";
     my @order = ref($order) ? @$order      my @order;
                             : sort(keys(%$hash));      if (ref($order) eq 'ARRAY')  {
           @order = @{$order};
       } else {
           @order = sort(keys(%$hash));
       }
       if (exists($$hash{'select_form_order'})) {
           @order = @{$$hash{'select_form_order'}};
       }
           
     foreach my $key (@order) {      foreach my $key (@order) {
         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';          $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
         $output.='selected="selected" ' if ($selected{$key});          $output.='selected="selected" ' if ($selected{$key});
Line 1303  sub select_form { Line 1356  sub select_form {
     return $selectform;      return $selectform;
 }  }
   
   # For display filters
   
   sub display_filter {
       if (!$env{'form.show'}) { $env{'form.show'}=10; }
       if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
       return '<nobr><label>'.&mt('Records [_1]',
          &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
      (&mt('all'),10,20,50,100,1000,10000))).
      '</label></nobr> <nobr>'.
              &mt('Filter [_1]',
      &select_form($env{'form.displayfilter'},
    'displayfilter',
    ('currentfolder' => 'Current folder/page',
    'containing' => 'Containing phrase',
    'none' => 'None'))).
    '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
   }
   
 sub gradeleveldescription {  sub gradeleveldescription {
     my $gradelevel=shift;      my $gradelevel=shift;
     my %gradelevels=(0 => 'Not specified',      my %gradelevels=(0 => 'Not specified',
Line 1358  selected"); Line 1429  selected");
 #-------------------------------------------  #-------------------------------------------
 sub select_dom_form {  sub select_dom_form {
     my ($defdom,$name,$includeempty) = @_;      my ($defdom,$name,$includeempty) = @_;
     my @domains = get_domains();      my @domains = sort(&Apache::lonnet::all_domains());
     if ($includeempty) { @domains=('',@domains); }      if ($includeempty) { @domains=('',@domains); }
     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";      my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
     foreach my $dom (@domains) {      foreach my $dom (@domains) {
Line 1374  sub select_dom_form { Line 1445  sub select_dom_form {
   
 =pod  =pod
   
 =item * get_library_servers($domain)  
   
 Returns a hash which contains keys like '103l3' and values like   
 'kirk.lite.msu.edu'.  All of the keys will be for machines in the  
 given $domain.  
   
 =cut  
   
 #-------------------------------------------  
 sub get_library_servers {  
     my $domain = shift;  
     my %library_servers;  
     foreach my $hostid (keys(%Apache::lonnet::libserv)) {  
         if ($Apache::lonnet::hostdom{$hostid} eq $domain) {  
             $library_servers{$hostid} = $Apache::lonnet::hostname{$hostid};  
         }  
     }  
     return %library_servers;  
 }  
   
 #-------------------------------------------  
   
 =pod  
   
 =item * home_server_option_list($domain)  =item * home_server_option_list($domain)
   
 returns a string which contains an <option> list to be used in a   returns a string which contains an <option> list to be used in a 
Line 1408  returns a string which contains an <opti Line 1455  returns a string which contains an <opti
 #-------------------------------------------  #-------------------------------------------
 sub home_server_option_list {  sub home_server_option_list {
     my $domain = shift;      my $domain = shift;
     my %servers = &get_library_servers($domain);      my %servers = &Apache::lonnet::get_servers($domain,'library');
     my $result = '';      my $result = '';
     foreach my $hostid (sort(keys(%servers))) {      foreach my $hostid (sort(keys(%servers))) {
         $result.=          $result.=
Line 1420  sub home_server_option_list { Line 1467  sub home_server_option_list {
   
 =pod  =pod
   
 =back  
   
 =cut  =cut
   
 ###############################################################  ###############################################################
Line 1810  If target_domain is not found in domain. Line 1855  If target_domain is not found in domain.
 #-------------------------------------------  #-------------------------------------------
 sub get_auth_defaults {  sub get_auth_defaults {
     my $domain=shift;      my $domain=shift;
     return ($Apache::lonnet::domain_auth_def{$domain},$Apache::lonnet::domain_auth_arg_def{$domain});      return (&Apache::lonnet::domain($domain,'auth_def'),
       &Apache::lonnet::domain($domain,'auth_arg_def'));
       
 }  }
 ###############################################################  ###############################################################
 ##   End Get Authentication Defaults for Domain              ##  ##   End Get Authentication Defaults for Domain              ##
Line 2067  sub getnames { Line 2114  sub getnames {
     }      }
 }  }
   
   sub getemails {
       my ($uname,$udom)=@_;
       if ($udom eq 'public' && $uname eq 'public') {
    return;
       }
       if (!$udom) { $udom=$env{'user.domain'}; }
       if (!$uname) { $uname=$env{'user.name'}; }
       my $id=$uname.':'.$udom;
       my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
       if ($cached) {
    return %{$names};
       } else {
    my %loadnames=&Apache::lonnet::get('environment',
                         ['notification','critnotification',
       'permanentemail'],
      $udom,$uname);
    &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
    return %loadnames;
       }
   }
   
 # ------------------------------------------------------------------ Screenname  # ------------------------------------------------------------------ Screenname
   
 =pod  =pod
Line 2145  sub track_student_link { Line 2213  sub track_student_link {
  &help_open_topic('View_recent_activity');   &help_open_topic('View_recent_activity');
 }  }
   
   # ===================================================== Display a student photo
   
   
   sub student_image_tag {
       my ($domain,$user)=@_;
       my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
       if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
    return '<img src="'.$imgsrc.'" align="right" />';
       } else {
    return '';
       }
   }
   
 =pod  =pod
   
 =back  =back
Line 2353  sub preferred_languages { Line 2434  sub preferred_languages {
          $env{'course.'.$env{'request.course.id'}.'.languages'}));           $env{'course.'.$env{'request.course.id'}.'.languages'}));
     }      }
     if ($env{'environment.languages'}) {      if ($env{'environment.languages'}) {
  @languages=split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'});   @languages=(@languages,
       split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
     }      }
     my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0];      my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0];
     if ($browser) {      if ($browser) {
  @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser));   @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser));
     }      }
     if ($Apache::lonnet::domain_lang_def{$env{'user.domain'}}) {      if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) {
  @languages=(@languages,   @languages=(@languages,
  $Apache::lonnet::domain_lang_def{$env{'user.domain'}});      &Apache::lonnet::domain($env{'user.domain'},
       'lang_def'));
     }      }
     if ($Apache::lonnet::domain_lang_def{$env{'request.role.domain'}}) {      if (&Apache::lonnet::domain($env{'request.role.domain'},'lang_def')) {
  @languages=(@languages,   @languages=(@languages,
  $Apache::lonnet::domain_lang_def{$env{'request.role.domain'}});      &Apache::lonnet::domain($env{'request.role.domain'},
       'lang_def'));
     }      }
     if ($Apache::lonnet::domain_lang_def{      if (&Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
                           $Apache::lonnet::perlvar{'lonDefDomain'}}) {   'lang_def')) {
  @languages=(@languages,   @languages=(@languages,
  $Apache::lonnet::domain_lang_def{      &Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
                                   $Apache::lonnet::perlvar{'lonDefDomain'}});      'lang_def'));
     }      }
 # turn "en-ca" into "en-ca,en"  # turn "en-ca" into "en-ca,en"
     my @genlanguages;      my @genlanguages;
Line 2576  sub get_student_answers { Line 2660  sub get_student_answers {
   }    }
   $moreenv{'grade_target'}='answer';    $moreenv{'grade_target'}='answer';
   %moreenv=(%form,%moreenv);    %moreenv=(%form,%moreenv);
   my $userview=&Apache::lonnet::ssi('/res/'.$feedurl,%moreenv);    $feedurl = &Apache::lonnet::clutter($feedurl);
     &Apache::lonenc::check_encrypt(\$feedurl);
     my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
   return $userview;    return $userview;
 }  }
   
Line 2595  sub submlink { Line 2681  sub submlink {
     my ($text,$uname,$udom,$symb,$target)=@_;      my ($text,$uname,$udom,$symb,$target)=@_;
     if (!($uname && $udom)) {      if (!($uname && $udom)) {
  (my $cursymb, my $courseid,$udom,$uname)=   (my $cursymb, my $courseid,$udom,$uname)=
     &Apache::lonxml::whichuser($symb);      &Apache::lonnet::whichuser($symb);
  if (!$symb) { $symb=$cursymb; }   if (!$symb) { $symb=$cursymb; }
     }      }
     if (!$symb) { $symb=&Apache::lonnet::symbread(); }      if (!$symb) { $symb=&Apache::lonnet::symbread(); }
Line 2641  sub pprmlink { Line 2727  sub pprmlink {
     my ($text,$uname,$udom,$symb,$target)=@_;      my ($text,$uname,$udom,$symb,$target)=@_;
     if (!($uname && $udom)) {      if (!($uname && $udom)) {
  (my $cursymb, my $courseid,$udom,$uname)=   (my $cursymb, my $courseid,$udom,$uname)=
     &Apache::lonxml::whichuser($symb);      &Apache::lonnet::whichuser($symb);
  if (!$symb) { $symb=$cursymb; }   if (!$symb) { $symb=$cursymb; }
     }      }
     if (!$symb) { $symb=&Apache::lonnet::symbread(); }      if (!$symb) { $symb=&Apache::lonnet::symbread(); }
Line 2690  sub maketime { Line 2776  sub maketime {
 #########################################  #########################################
   
 sub findallcourses {  sub findallcourses {
     my ($roles) = @_;      my ($roles,$uname,$udom) = @_;
     my %roles;      my %roles;
     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }      if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
     my %courses;      my %courses;
     my $now=time;      my $now=time;
     foreach my $key (keys(%env)) {      if (!defined($uname)) {
  if ( $key=~m{^user\.role\.(\w+)\./(\w+)/(\w+)} ) {          $uname = $env{'user.name'};
     my ($role,$domain,$id) = ($1,$2,$3);      }
     next if ($role eq 'ca' || $role eq 'aa');      if (!defined($udom)) {
     next if (%roles && !exists($roles{$role}));          $udom = $env{'user.domain'};
     my ($starttime,$endtime)=split(/\./,$env{$key});      }
             my $active=1;      if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
             if ($starttime) {          my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
  if ($now<$starttime) { $active=0; }          if (!%roles) {
               %roles = (
                          cc => 1,
                          in => 1,
                          ep => 1,
                          ta => 1,
                          cr => 1,
                          st => 1,
                );
           }
           foreach my $entry (keys(%roleshash)) {
               my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
               if ($trole =~ /^cr/) { 
                   next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
               } else {
                   next if (!exists($roles{$trole}));
             }              }
             if ($endtime) {              if ($tend) {
                 if ($now>$endtime) { $active=0; }                  next if ($tend < $now);
               }
               if ($tstart) {
                   next if ($tstart > $now);
               }
               my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
               (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
               if ($secpart eq '') {
                   ($cnum,$role) = split(/_/,$cnumpart); 
                   $sec = 'none';
                   $realsec = '';
               } else {
                   $cnum = $cnumpart;
                   ($sec,$role) = split(/_/,$secpart);
                   $realsec = $sec;
               }
               $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
           }
       } else {
           foreach my $key (keys(%env)) {
       if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                    $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
           my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
           next if ($role eq 'ca' || $role eq 'aa');
           next if (%roles && !exists($roles{$role}));
           my ($starttime,$endtime)=split(/\./,$env{$key});
                   my $active=1;
                   if ($starttime) {
       if ($now<$starttime) { $active=0; }
                   }
                   if ($endtime) {
                       if ($now>$endtime) { $active=0; }
                   }
                   if ($active) {
                       if ($sec eq '') {
                           $sec = 'none';
                       }
                       $courses{$cdom.'_'.$cnum}{$sec} = 
                                        $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
                   }
             }              }
             if ($active) { $courses{$domain.'_'.$id}=1; }  
         }          }
     }      }
     return keys(%courses);      return %courses;
 }  }
   
 ###############################################  ###############################################
   
   sub blockcheck {
       my ($setters,$activity,$uname,$udom) = @_;
   
       if (!defined($udom)) {
           $udom = $env{'user.domain'};
       }
       if (!defined($uname)) {
           $uname = $env{'user.name'};
       }
   
       # If uname and udom are for a course, check for blocks in the course.
   
       if (&Apache::lonnet::is_course($udom,$uname)) {
           my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
           my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
           return ($startblock,$endblock);
       }
   
       my $startblock = 0;
       my $endblock = 0;
       my %live_courses = &findallcourses(undef,$uname,$udom);
   
       # If uname is for a user, and activity is course-specific, i.e.,
       # boards, chat or groups, check for blocking in current course only.
   
       if (($activity eq 'boards' || $activity eq 'chat' ||
            $activity eq 'groups') && ($env{'request.course.id'})) {
           foreach my $key (keys(%live_courses)) {
               if ($key ne $env{'request.course.id'}) {
                   delete($live_courses{$key});
               }
           }
       }
   
       my $otheruser = 0;
       my %own_courses;
       if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
           # Resource belongs to user other than current user.
           $otheruser = 1;
           # Gather courses for current user
           %own_courses = 
               &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
       }
   
       # Gather active course roles - course coordinator, instructor, 
       # exam proctor, ta, student, or custom role.
   
       foreach my $course (keys(%live_courses)) {
           my ($cdom,$cnum);
           if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
               $cdom = $env{'course.'.$course.'.domain'};
               $cnum = $env{'course.'.$course.'.num'};
           } else {
               ($cdom,$cnum) = split(/_/,$course); 
           }
           my $no_ownblock = 0;
           my $no_userblock = 0;
           if ($otheruser) {
               # Check if current user has 'evb' priv for this
               if (defined($own_courses{$course})) {
                   foreach my $sec (keys(%{$own_courses{$course}})) {
                       my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                       if ($sec ne 'none') {
                           $checkrole .= '/'.$sec;
                       }
                       if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                           $no_ownblock = 1;
                           last;
                       }
                   }
               }
               # if they have 'evb' priv and are currently not playing student
               next if (($no_ownblock) &&
                    ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
           }
           foreach my $sec (keys(%{$live_courses{$course}})) {
               my $checkrole = 'cm./'.$cdom.'/'.$cnum;
               if ($sec ne 'none') {
                   $checkrole .= '/'.$sec;
               }
               if ($otheruser) {
                   # Resource belongs to user other than current user.
                   # Assemble privs for that user, and check for 'evb' priv.
                   my ($trole,$tdom,$tnum,$tsec);
                   my $entry = $live_courses{$course}{$sec};
                   if ($entry =~ /^cr/) {
                       ($trole,$tdom,$tnum,$tsec) = 
                         ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   } else {
                       ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   }
                   my ($spec,$area,$trest,%allroles,%userroles);
                   $area = '/'.$tdom.'/'.$tnum;
                   $trest = $tnum;
                   if ($tsec ne '') {
                       $area .= '/'.$tsec;
                       $trest .= '/'.$tsec;
                   }
                   $spec = $trole.'.'.$area;
                   if ($trole =~ /^cr/) {
                       &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                                                         $tdom,$spec,$trest,$area);
                   } else {
                       &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                                                          $tdom,$spec,$trest,$area);
                   }
                   my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
                   if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                       if ($1) {
                           $no_userblock = 1;
                           last;
                       }
                   }
               } else {
                   # Resource belongs to current user
                   # Check for 'evb' priv via lonnet::allowed().
                   if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                       $no_ownblock = 1;
                       last;
                   }
               }
           }
           # if they have the evb priv and are currently not playing student
           next if (($no_ownblock) &&
                    ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
           next if ($no_userblock);
   
           # Retrieve blocking times and identity of blocker for course
           # of specified user, unless user has 'evb' privilege.
           
           my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
           if (($start != 0) && 
               (($startblock == 0) || ($startblock > $start))) {
               $startblock = $start;
           }
           if (($end != 0)  &&
               (($endblock == 0) || ($endblock < $end))) {
               $endblock = $end;
           }
       }
       return ($startblock,$endblock);
   }
   
   sub get_blocks {
       my ($setters,$activity,$cdom,$cnum) = @_;
       my $startblock = 0;
       my $endblock = 0;
       my $course = $cdom.'_'.$cnum;
       $setters->{$course} = {};
       $setters->{$course}{'staff'} = [];
       $setters->{$course}{'times'} = [];
       my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
       foreach my $record (keys(%records)) {
           my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
           if ($start <= time && $end >= time) {
               my ($staff_name,$staff_dom,$title,$blocks) =
                   &parse_block_record($records{$record});
               if ($blocks->{$activity} eq 'on') {
                   push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   push(@{$$setters{$course}{'times'}}, [$start,$end]);
                   if ( ($startblock == 0) || ($startblock > $start) ) {
                       $startblock = $start;
                   }
                   if ( ($endblock == 0) || ($endblock < $end) ) {
                       $endblock = $end;
                   }
               }
           }
       }
       return ($startblock,$endblock);
   }
   
   sub parse_block_record {
       my ($record) = @_;
       my ($setuname,$setudom,$title,$blocks);
       if (ref($record) eq 'HASH') {
           ($setuname,$setudom) = split(/:/,$record->{'setter'});
           $title = &unescape($record->{'event'});
           $blocks = $record->{'blocks'};
       } else {
           my @data = split(/:/,$record,3);
           if (scalar(@data) eq 2) {
               $title = $data[1];
               ($setuname,$setudom) = split(/@/,$data[0]);
           } else {
               ($setuname,$setudom,$title) = @data;
           }
           $blocks = { 'com' => 'on' };
       }
       return ($setuname,$setudom,$title,$blocks);
   }
   
   sub build_block_table {
       my ($startblock,$endblock,$setters) = @_;
       my %lt = &Apache::lonlocal::texthash(
           'cacb' => 'Currently active communication blocks',
           'cour' => 'Course',
           'dura' => 'Duration',
           'blse' => 'Block set by'
       );
       my $output;
       $output = '<br />'.$lt{'cacb'}.':<br />';
       $output .= &start_data_table();
       $output .= '
   <tr>
    <th>'.$lt{'cour'}.'</th>
    <th>'.$lt{'dura'}.'</th>
    <th>'.$lt{'blse'}.'</th>
   </tr>
   ';
       foreach my $course (keys(%{$setters})) {
           my %courseinfo=&Apache::lonnet::coursedescription($course);
           for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
               my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
               my $fullname = &plainname($uname,$udom);
               if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   && $env{'user.name'} ne 'public' 
                   && $env{'user.domain'} ne 'public') {
                   $fullname = &aboutmewrapper($fullname,$uname,$udom);
               }
               my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
               $openblock = &Apache::lonlocal::locallocaltime($openblock);
               $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
               $output .= &Apache::loncommon::start_data_table_row().
                          '<td>'.$courseinfo{'description'}.'</td>'.
                          '<td>'.$openblock.' to '.$closeblock.'</td>'.
                          '<td>'.$fullname.'</td>'.
                           &Apache::loncommon::end_data_table_row();
           }
       }
       $output .= &end_data_table();
   }
   
   sub blocking_status {
       my ($activity,$uname,$udom) = @_;
       my %setters;
       my ($blocked,$output,$ownitem,$is_course);
       my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
       if ($startblock && $endblock) {
           $blocked = 1;
           if (wantarray) {
               my $category;
               if ($activity eq 'boards') {
                   $category = 'Discussion posts in this course';
               } elsif ($activity eq 'blogs') {
                   $category = 'Blogs';
               } elsif ($activity eq 'port') {
                   if (defined($uname) && defined($udom)) {
                       if ($uname eq $env{'user.name'} &&
                           $udom eq $env{'user.domain'}) {
                           $ownitem = 1;
                       }
                   }
                   $is_course = &Apache::lonnet::is_course($udom,$uname);
                   if ($ownitem) { 
                       $category = 'Your portfolio files';  
                   } elsif ($is_course) {
                       my $coursedesc;
                       foreach my $course (keys(%setters)) {
                           my %courseinfo =
                                &Apache::lonnet::coursedescription($course);
                           $coursedesc = $courseinfo{'description'};
                       }
                       $category = "Group files in the course '$coursedesc'";
                   } else {
                       $category = 'Portfolio files belonging to ';
                       if ($env{'user.name'} eq 'public' && 
                           $env{'user.domain'} eq 'public') {
                           $category .= &plainname($uname,$udom);
                       } else {
                           $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                       }
                   }
               } elsif ($activity eq 'groups') {
                   $category = 'Groups in this course';
               }
               my $showstart = &Apache::lonlocal::locallocaltime($startblock);
               my $showend = &Apache::lonlocal::locallocaltime($endblock);
               $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
               if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   $output .= &build_block_table($startblock,$endblock,\%setters);
               }
           }
       }
       if (wantarray) {
           return ($blocked,$output);
       } else {
           return $blocked;
       }
   }
   
 ###############################################  ###############################################
   
 =pod  =pod
Line 2745  sub determinedomain { Line 3176  sub determinedomain {
     return $domain;      return $domain;
 }  }
 ###############################################  ###############################################
   
   sub devalidate_domconfig_cache {
       my ($udom)=@_;
       &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
   }
   
   # ---------------------- Get domain configuration for a domain
   sub get_domainconf {
       my ($udom) = @_;
       my $cachetime=1800;
       my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
       if (defined($cached)) { return %{$result}; }
   
       my %domconfig = &Apache::lonnet::get_dom('configuration',
        ['login','rolecolors'],$udom);
       my %designhash;
       if (keys(%domconfig) > 0) {
           if (ref($domconfig{'login'}) eq 'HASH') {
               foreach my $key (keys(%{$domconfig{'login'}})) {
                   $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
               }
           }
           if (ref($domconfig{'rolecolors'}) eq 'HASH') {
               foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                       foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                           $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                       }
                   }
               }
           }
       } else {
           my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
           my $designfile =  $designdir.'/'.$udom.'.tab';
           if (-e $designfile) {
               if ( open (my $fh,"<$designfile") ) {
                   while (my $line = <$fh>) {
                       next if ($line =~ /^\#/);
                       chomp($line);
                       my ($key,$val)=(split(/\=/,$line));
                       if ($val) { $designhash{$udom.'.'.$key}=$val; }
                   }
                   close($fh);
               }
           }
           if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
               $designhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
           }
       }
       &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
     $cachetime);
       return %designhash;
   }
   
 =pod  =pod
   
 =item * &domainlogo()  =item * &domainlogo()
Line 2758  If the domain logo does not exist, a des Line 3243  If the domain logo does not exist, a des
   
 ###############################################  ###############################################
 sub domainlogo {  sub domainlogo {
     my $domain = &determinedomain(shift);          my $domain = &determinedomain(shift);
      # See if there is a logo      my %designhash = &get_domainconf($domain);    
     if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') {      # See if there is a logo
  my $logo=&lonhttpdurl("/adm/lonDomLogos/$domain.gif");      if ($designhash{$domain.'.login.domlogo'} ne '') {
         return '<img src="'.$logo.'" alt="'.$domain.'" />';          my $imgsrc = $designhash{$domain.'.login.domlogo'};
     } elsif(exists($Apache::lonnet::domaindescription{$domain})) {          if ($imgsrc =~ /^\/(adm|res)/) {
         return $Apache::lonnet::domaindescription{$domain};              $imgsrc = &lonhttpdurl($imgsrc);
           } 
           return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
       } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
           return &Apache::lonnet::domain($domain,'description');
     } else {      } else {
         return '';          return '';
     }      }
Line 2800  sub designparm { Line 3289  sub designparm {
  return $env{'environment.color.'.$which};   return $env{'environment.color.'.$which};
     }      }
     $domain=&determinedomain($domain);      $domain=&determinedomain($domain);
     if (exists($designhash{$domain.'.'.$which})) {      my %domdesign = &get_domainconf($domain);
  return $designhash{$domain.'.'.$which};      my $output;
       if ($domdesign{$domain.'.'.$which} ne '') {
    $output = $domdesign{$domain.'.'.$which};
     } else {      } else {
         return $designhash{'default.'.$which};          $output = $defaultdesign{$which};
       }
       if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
           ($which =~ /login\.(img|logo|domlogo)/)) {
           if ($output =~ /^\/(adm|res)\//) {
               $output = &lonhttpdurl($output);
           }
     }      }
       return $output;
 }  }
   
 ###############################################  ###############################################
Line 2853  Inputs: Line 3351  Inputs:
 =item * $no_inline_link, if true and in remote mode, don't show the   =item * $no_inline_link, if true and in remote mode, don't show the 
          'Switch To Inline Menu' link           'Switch To Inline Menu' link
   
   =item * $args, optional argument valid values are
               no_auto_mt_title -> prevents &mt()ing the title arg
   
 =back  =back
   
 Returns: A uniform header for LON-CAPA web pages.    Returns: A uniform header for LON-CAPA web pages.  
Line 2864  other decorations will be returned. Line 3365  other decorations will be returned.
   
 sub bodytag {  sub bodytag {
     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,      my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
  $notopbar,$bgcolor,$notitle,$no_inline_link)=@_;   $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
   
     $title=&mt($title);      if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
   
     $function = &get_users_function() if (!$function);      $function = &get_users_function() if (!$function);
     my $img =    &designparm($function.'.img',$domain);      my $img =    &designparm($function.'.img',$domain);
Line 2884  sub bodytag { Line 3385  sub bodytag {
  # role and realm   # role and realm
     my ($role,$realm) = split(/\./,$env{'request.role'},2);      my ($role,$realm) = split(/\./,$env{'request.role'},2);
     if ($role  eq 'ca') {      if ($role  eq 'ca') {
         my ($rdom,$rname) = ($realm =~ m-^/(\w+)/(\w+)$-);          my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
         $realm = &plainname($rname,$rdom).':'.$rdom;          $realm = &plainname($rname,$rdom);
     }       } 
 # realm  # realm
     if ($env{'request.course.id'}) {      if ($env{'request.course.id'}) {
Line 3020  ENDROLE Line 3521  ENDROLE
 # Top frame rendering, Remote is up  # Top frame rendering, Remote is up
 #  #
   
     my $upperleft='<img src="http://'.$ENV{'HTTP_HOST'}.':'.      my $imgsrc = $img;
         $lonhttpdPort.$img.'" alt="'.$function.'" />';      if ($img =~ /^\/adm/) {
           $imgsrc = 'http://'.$ENV{'HTTP_HOST'}.':'.$lonhttpdPort.$img;
       }
       my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
   
     # Explicit link to get inline menu      # Explicit link to get inline menu
     my $menu= ($no_inline_link?''      my $menu= ($no_inline_link?''
Line 3169  sub standard_css { Line 3673  sub standard_css {
     my $mono                 = 'monospace';      my $mono                 = 'monospace';
     my $data_table_head      = $tabbg;      my $data_table_head      = $tabbg;
     my $data_table_light     = '#EEEEEE';      my $data_table_light     = '#EEEEEE';
     my $data_table_dark      = '#DDD';      my $data_table_dark      = '#DDDDDD';
     my $data_table_darker    = '#CCC';      my $data_table_darker    = '#CCCCCC';
     my $data_table_highlight = '#FFFF00';      my $data_table_highlight = '#FFFF00';
     my $mail_new             = '#FFBB77';      my $mail_new             = '#FFBB77';
     my $mail_new_hover       = '#DD9955';      my $mail_new_hover       = '#DD9955';
Line 3181  sub standard_css { Line 3685  sub standard_css {
     my $mail_other           = '#99BBBB';      my $mail_other           = '#99BBBB';
     my $mail_other_hover     = '#669999';      my $mail_other_hover     = '#669999';
     my $table_header         = '#DDDDDD';      my $table_header         = '#DDDDDD';
       my $feedback_link_bg     = '#BBBBBB';
   
     my $border = ($env{'browser.type'} eq 'explorer') ? '0px 2px 0px 2px'      my $border = ($env{'browser.type'} eq 'explorer') ? '0px 2px 0px 2px'
                                               : '0px 3px 0px 4px';                                                : '0px 3px 0px 4px';
   
   
     return <<END;      return <<END;
 h1, h2, h3, th { font-family: $sans }  h1, h2, h3, th { font-family: $sans }
 a:focus { color: red; background: yellow }   a:focus { color: red; background: yellow } 
 table.thinborder { border-collapse: collapse; }  table.thinborder,
 table.thinborder tr th {  border-style: solid; border-width: 1px; background: $tabbg;}  
 table.thinborder tr td { border-style: solid; border-width: 1px}  table.thinborder tr th {
     border-style: solid;
     border-width: 1px;
     background: $tabbg;
   }
   table.thinborder tr td {
     border-style: solid;
     border-width: 1px
   }
   
 form, .inline { display: inline; }  form, .inline { display: inline; }
 .center { text-align: center; }  .center { text-align: center; }
Line 3199  form, .inline { display: inline; } Line 3713  form, .inline { display: inline; }
   color: red;    color: red;
   font-size: larger;    font-size: larger;
 }  }
 .LC_warning {  .LC_warning,
   .LC_diff_removed {
   color: red;    color: red;
 }  }
 .LC_success {  .LC_success,
   .LC_diff_added {
   color: green;    color: green;
 }  }
 .LC_icon {  .LC_icon {
   border: 0px;    border: 0px;
 }  }
   
   table.LC_pastsubmission {
     border: 1px solid black;
     margin: 2px;
   }
   
 table#LC_top_nav, table#LC_menubuttons {  table#LC_top_nav, table#LC_menubuttons {
   width: 100%;    width: 100%;
   background: $pgbg;    background: $pgbg;
Line 3248  table#LC_title_bar td.LC_title_bar_who { Line 3769  table#LC_title_bar td.LC_title_bar_who {
   font: small $sans;    font: small $sans;
   text-align: right;    text-align: right;
 }  }
   span.LC_metadata {
       font-family: $sans;
   }
 span.LC_title_bar_title {  span.LC_title_bar_title {
   font: bold x-large $sans;    font: bold x-large $sans;
 }  }
Line 3317  td.LC_table_cell_checkbox { Line 3841  td.LC_table_cell_checkbox {
   text-align: center;    text-align: center;
 }  }
   
   table#LC_mainmenu td.LC_mainmenu_column {
       vertical-align: top;
   }
   
 .LC_menubuttons_inline_text {  .LC_menubuttons_inline_text {
   color: $font;    color: $font;
   font-family: $sans;    font-family: $sans;
   font-size: smaller;    font-size: smaller;
 }  }
   
   .LC_menubuttons_category {
     color: $font;
     font-family: $sans;
     font-size: larger;
     font-weight: bold;
   }
   
 td.LC_menubuttons_text {  td.LC_menubuttons_text {
   color: $font;    color: $font;
   font-family: $sans;    font-family: $sans;
Line 3352  table.LC_data_table, table.LC_mail_list Line 3887  table.LC_data_table, table.LC_mail_list
 .LC_data_table_dense {  .LC_data_table_dense {
   font-size: small;    font-size: small;
 }  }
 table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th {  table.LC_nested_outer {
     border: 1px solid #000000;
     border-collapse: separate;
     border-spacing: 0px;
     width: 100%;
   }
   table.LC_nested {
     border: 0px;
     border-collapse: separate;
     border-spacing: 0px;
     width: 100%;
   }
   table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
   table.LC_prior_tries tr th {
   font-weight: bold;    font-weight: bold;
   background-color: $data_table_head;    background-color: $data_table_head;
   font-size: smaller;    font-size: smaller;
Line 3370  table.LC_data_table tr.LC_data_table_hig Line 3918  table.LC_data_table tr.LC_data_table_hig
   background-color: $data_table_darker;    background-color: $data_table_darker;
 }  }
 table.LC_data_table tr.LC_empty_row td,  table.LC_data_table tr.LC_empty_row td,
 table.LC_whatsnew tr.LC_empty_row td {  table.LC_nested tr.LC_empty_row td {
   background-color: #FFFFFF;    background-color: #FFFFFF;
   font-weight: bold;    font-weight: bold;
   font-style: italic;    font-style: italic;
   text-align: center;    text-align: center;
   padding: 8px;    padding: 8px;
 }  }
   table.LC_nested tr.LC_empty_row td {
 table.LC_whatsnew {    padding: 4ex
 }  }
   table.LC_nested_outer tr th {
 table.LC_whatsnew tr th,    font-weight: bold;
 table.LC_whatsnew tr.LC_info_row td {    background-color: $data_table_head;
   background-color: #CCC;    font-size: smaller;
     border-bottom: 1px solid #000000;
   }
   table.LC_nested_outer tr td.LC_subheader {
     background-color: $data_table_head;
   font-weight: bold;    font-weight: bold;
   font-size: small;    font-size: small;
     border-bottom: 1px solid #000000;
   text-align: right;    text-align: right;
 }  }
 table.LC_whatsnew tr td {  table.LC_nested tr.LC_info_row td {
   background-color: #FFF;    background-color: #CCC;
     font-weight: bold;
   font-size: small;    font-size: small;
   text-align: right;    text-align: center;
 }  }
 table.LC_whatsnew tr td.LC_first_item {  table.LC_nested tr.LC_info_row td.LC_left_item {
   text-align: left;    text-align: left;
 }  }
   table.LC_nested td {
     background-color: #FFF;
     font-size: small;
   }
   table.LC_nested_outer tr th.LC_right_item,
   table.LC_nested tr.LC_info_row td.LC_right_item,
   table.LC_nested tr.LC_odd_row td.LC_right_item,
   table.LC_nested tr td.LC_right_item {
     text-align: right;
   }
   
 table.LC_whatsnew tr.LC_odd_row td {  table.LC_nested tr.LC_odd_row td {
   background-color: #EEE;    background-color: #EEE;
 }  }
   
   table.LC_createuser {
   }
   
   table.LC_createuser tr.LC_section_row td {
     font-size: smaller;
   }
   
   table.LC_createuser tr.LC_info_row td  {
     background-color: #CCC;
     font-weight: bold;
     text-align: center;
   }
   
 table.LC_calendar {  table.LC_calendar {
   border: 1px solid #000000;    border: 1px solid #000000;
   border-collapse: collapse;    border-collapse: collapse;
Line 3443  table.LC_mail_list tr.LC_mail_other { Line 4020  table.LC_mail_list tr.LC_mail_other {
 table.LC_mail_list tr.LC_mail_other:hover {  table.LC_mail_list tr.LC_mail_other:hover {
   background-color: $mail_other_hover;    background-color: $mail_other_hover;
 }  }
   table.LC_mail_list tr.LC_mail_even {
   }
   table.LC_mail_list tr.LC_mail_odd {
   }
   
   
 table#LC_portfolio_actions {  table#LC_portfolio_actions {
   width: auto;    width: auto;
Line 3499  table#LC_browser tr.LC_browser_file_unpu Line 4081  table#LC_browser tr.LC_browser_file_unpu
 table#LC_browser tr.LC_browser_file_obsolete {  table#LC_browser tr.LC_browser_file_obsolete {
   background: #AAAAAA;    background: #AAAAAA;
 }  }
 table#LC_browser tr.LC_browser_file_modified {  table#LC_browser tr.LC_browser_file_modified,
   table#LC_browser tr.LC_browser_file_metamodified {
   background: #FFFF77;    background: #FFFF77;
 }  }
 table#LC_browser tr.LC_browser_folder {  table#LC_browser tr.LC_browser_folder {
Line 3686  table.LC_descriptive_input td.LC_descrip Line 4269  table.LC_descriptive_input td.LC_descrip
   text-align: right;    text-align: right;
   font-weight: bold;    font-weight: bold;
 }  }
   table.LC_feedback_link {
       background: $feedback_link_bg;
   }
   span.LC_feedback_link {
       background: $feedback_link_bg;
       font-size: larger;
   }
   
   table.LC_prior_tries {
     border: 1px solid #000000;
     border-collapse: separate;
     border-spacing: 1px;
   }
   
   table.LC_prior_tries td {
     padding: 2px;
   }
   
   .LC_answer_correct {
     background: #AAFFAA;
     color: black;
   }
   .LC_answer_charged_try {
     background: #FFAAAA ! important;
     color: black;
   }
   .LC_answer_not_charged_try, 
   .LC_answer_no_grade,
   .LC_answer_late {
     background: #FFFFAA;
     color: black;
   }
   .LC_answer_previous {
     background: #AAAAFF;
     color: black;
   }
   .LC_answer_no_message {
     background: #FFFFFF;
     color: black;
   }
   .LC_answer_unknown {
     background: orange;
     color: black;
   }
   
   
   span.LC_prior_numerical {
     font-family: monospace;
     white-space: pre;
   }
   
   table.LC_prior_option {
     width: 100%;
     border-collapse: collapse;
   }
   table.LC_prior_option tr td {
     border: 1px solid #000000;
   }
   
   span.LC_nobreak {
       white-space: nowrap;
   }
   
 END  END
 }  }
Line 3714  Inputs: $title - optional title for the Line 4359  Inputs: $title - optional title for the
                                domain                                 domain
             function       -> force usage of a specific rolish color scheme              function       -> force usage of a specific rolish color scheme
             bgcolor        -> override the default page bgcolor              bgcolor        -> override the default page bgcolor
               no_auto_mt_title
                              -> prevent &mt()ing the title arg
   
 =back  =back
   
Line 3726  sub headtag { Line 4373  sub headtag {
     my $domain   = $args->{'domain'}   || &determinedomain();      my $domain   = $args->{'domain'}   || &determinedomain();
     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);      my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
     my $url = join(':',$env{'user.name'},$env{'user.domain'},      my $url = join(':',$env{'user.name'},$env{'user.domain'},
    #time(),  
    $Apache::lonnet::perlvar{'lonVersion'},     $Apache::lonnet::perlvar{'lonVersion'},
      time(),
    $env{'environment.color.timestamp'},     $env{'environment.color.timestamp'},
    $function,$domain,$bgcolor);     $function,$domain,$bgcolor);
   
Line 3735  sub headtag { Line 4382  sub headtag {
   
     my $result =      my $result =
  '<head>'.   '<head>'.
  &font_settings().   &font_settings();
  &Apache::lonhtmlcommon::htmlareaheaders();  
   
       if (!$args->{'frameset'}) {
    $result .= &Apache::lonhtmlcommon::htmlareaheaders();
       }
     if ($args->{'force_register'}) {      if ($args->{'force_register'}) {
  $result .= &Apache::lonmenu::registerurl(1);   $result .= &Apache::lonmenu::registerurl(1);
     }      }
Line 3761  ADDMETA Line 4410  ADDMETA
     if (!defined($title)) {      if (!defined($title)) {
  $title = 'The LearningOnline Network with CAPA';   $title = 'The LearningOnline Network with CAPA';
     }      }
           if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
     $result .= '<title> LON-CAPA '.&mt($title).'</title>'      $result .= '<title> LON-CAPA '.$title.'</title>'
  .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'   .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
  .$head_extra;   .$head_extra;
     return $result;      return $result;
Line 3906  Inputs: $title - optional title for the Line 4555  Inputs: $title - optional title for the
                   no_inline_link -> if true and in remote mode, don't show the                     no_inline_link -> if true and in remote mode, don't show the 
                                     'Switch To Inline Menu' link                                      'Switch To Inline Menu' link
   
                     no_auto_mt_title -> prevent &mt()ing the title arg
   
 =back  =back
   
 =cut  =cut
Line 3915  sub start_page { Line 4566  sub start_page {
     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));      #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
     my %head_args;      my %head_args;
     foreach my $arg ('redirect','force_register','domain','function',      foreach my $arg ('redirect','force_register','domain','function',
      'bgcolor','frameset','no_nav_bar','only_body') {       'bgcolor','frameset','no_nav_bar','only_body',
        'no_auto_mt_title') {
  if (defined($args->{$arg})) {   if (defined($args->{$arg})) {
     $head_args{$arg} = $args->{$arg};      $head_args{$arg} = $args->{$arg};
  }   }
Line 3941  sub start_page { Line 4593  sub start_page {
  $args->{'only_body'},      $args->{'domain'},   $args->{'only_body'},      $args->{'domain'},
  $args->{'force_register'}, $args->{'body_title'},   $args->{'force_register'}, $args->{'body_title'},
  $args->{'no_nav_bar'},     $args->{'bgcolor'},   $args->{'no_nav_bar'},     $args->{'bgcolor'},
  $args->{'no_title'},       $args->{'no_inline_link'});   $args->{'no_title'},       $args->{'no_inline_link'},
    $args);
  }   }
     }      }
   
Line 3970  Inputs:         $args - additional optio Line 4623  Inputs:         $args - additional optio
                                  a html attribute                                   a html attribute
                  frameset     -> if true will start with a <frameset>                   frameset     -> if true will start with a <frameset>
                                  rather than <body>                                   rather than <body>
                    dicsussion   -> if true will get discussion from
                                     lonxml::xmlend
                                    (you can pass the target and parser arguments
                                     through optional 'target' and 'parser' args
                                     to this routine)
   
 =cut  =cut
   
Line 4081  sub simple_error_page { Line 4739  sub simple_error_page {
  $css_class = (join(' ',$css_class,$add_class));   $css_class = (join(' ',$css_class,$add_class));
  return  '<tr class="'.$css_class.'">'."\n";;   return  '<tr class="'.$css_class.'">'."\n";;
     }      }
       
       sub continue_data_table_row {
    my ($add_class) = @_;
    my $css_class = ($row_count % 2)?'':'LC_even_row';
    $css_class = (join(' ',$css_class,$add_class));
    return  '<tr class="'.$css_class.'">'."\n";;
       }
   
     sub end_data_table_row {      sub end_data_table_row {
  return '</tr>'."\n";;   return '</tr>'."\n";;
Line 4421  sub get_course_users { Line 5086  sub get_course_users {
                     $usec = 'none';                      $usec = 'none';
                 }                  }
                 if ($uname ne '' && $udom ne '') {                  if ($uname ne '' && $udom ne '') {
                     if ($end < $now) {                      if ($end > 0 && $end < $now) {
                         $status = 'previous';                          $status = 'previous';
                     } elsif ($start > $now) {                      } elsif ($start > $now) {
                         $status = 'future';                          $status = 'future';
Line 4483  sub get_user_info { Line 5148  sub get_user_info {
     return;      return;
 }  }
   
   ###############################################
   
   =pod
   
   =item * &get_user_quota()
   
   Retrieves quota assigned for storage of portfolio files for a user  
   
   Incoming parameters:
   1. user's username
   2. user's domain
   
   Returns:
   1. Disk quota (in Mb) assigned to student. 
   
   If a value has been stored in the user's environment, 
   it will return that, otherwise it returns the default
   for users in the domain.
   
   =cut
   
   ###############################################
   
   
   sub get_user_quota {
       my ($uname,$udom) = @_;
       my $quota;
       if (!defined($udom)) {
           $udom = $env{'user.domain'};
       }
       if (!defined($uname)) {
           $uname = $env{'user.name'};
       }
       if (($udom eq '' || $uname eq '') ||
           ($udom eq 'public') && ($uname eq 'public')) {
           $quota = 0;
       } else {
           if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
               $quota = $env{'environment.portfolioquota'};
           } else {
               my %userenv = &Apache::lonnet::dump('environment',$udom,$uname);
               my ($tmp) = keys(%userenv);
               if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   $quota = $userenv{'portfolioquota'};
               } else {
                   undef(%userenv);
               }
           }
           if ($quota eq '') {
               $quota = &default_quota($udom);
           }
       }
       return $quota;
   }
   
   ###############################################
   
   =pod
   
   =item * &default_quota()
   
   Retrieves default quota assigned for storage of user portfolio files
   
   Incoming parameters:
   1. domain
   
   Returns:
   1. Default disk quota (in Mb) for user portfolios in the domain.
   
   If a value has been stored in the domain's configuration db,
   it will return that, otherwise it returns 20 (for backwards 
   compatibility with domains which have not set up a configuration
   db file; the original statically defined portfolio quota was 20 Mb). 
   
   =cut
   
   ###############################################
   
   
   sub default_quota {
       my ($udom) = @_;
       my %defaults = &Apache::lonnet::get_dom('configuration',
                                               ['portfolioquota'],$udom);
       if ($defaults{'portfolioquota'} ne '') {
           return $defaults{'portfolioquota'};
       } else {
           return '20';
       }
   }
   
 sub get_secgrprole_info {  sub get_secgrprole_info {
     my ($cdom,$cnum,$needroles,$type)  = @_;      my ($cdom,$cnum,$needroles,$type)  = @_;
     my %sections_count = &get_sections($cdom,$cnum);      my %sections_count = &get_sections($cdom,$cnum);
Line 4657  sub get_env_multiple { Line 5412  sub get_env_multiple {
   
 =pod  =pod
   
 =back   =back
   
 =head1 CSV Upload/Handling functions  =head1 CSV Upload/Handling functions
   
Line 4771  sub record_sep { Line 5526  sub record_sep {
             $i++;              $i++;
         }          }
     } else {      } else {
         my @allfields=split(/\,/,$record);          my @allfields;
           if ($env{'form.upfiletype'} eq 'semisv') {
               @allfields=split(/;/,$record,-1);
           } else {
               @allfields=split(/\,/,$record,-1);
           }
         my $i=0;          my $i=0;
         my $j;          my $j;
         for ($j=0;$j<=$#allfields;$j++) {          for ($j=0;$j<=$#allfields;$j++) {
Line 4809  the file type. Line 5569  the file type.
 sub upfile_select_html {  sub upfile_select_html {
     my %Types = (      my %Types = (
                  csv   => &mt('CSV (comma separated values, spreadsheet)'),                   csv   => &mt('CSV (comma separated values, spreadsheet)'),
                    semisv => &mt('Semicolon separated values'),
                  space => &mt('Space separated'),                   space => &mt('Space separated'),
                  tab   => &mt('Tabulator separated'),                   tab   => &mt('Tabulator separated'),
 #                 xml   => &mt('HTML/XML'),  #                 xml   => &mt('HTML/XML'),
Line 5463  Returns: both routines return nothing Line 6224  Returns: both routines return nothing
 #######################################################  #######################################################
 #######################################################  #######################################################
 sub store_course_settings {  sub store_course_settings {
       return &store_settings($env{'request.course.id'},@_);
   }
   
   sub store_settings {
     # save to the environment      # save to the environment
     # appenv the same items, just to be safe      # appenv the same items, just to be safe
     my $courseid = $env{'request.course.id'};  
     my $udom  = $env{'user.domain'};      my $udom  = $env{'user.domain'};
     my $uname = $env{'user.name'};      my $uname = $env{'user.name'};
     my ($prefix,$Settings) = @_;      my ($context,$prefix,$Settings) = @_;
     my %SaveHash;      my %SaveHash;
     my %AppHash;      my %AppHash;
     while (my ($setting,$type) = each(%$Settings)) {      while (my ($setting,$type) = each(%$Settings)) {
         my $basename = join('.','internal',$courseid,$prefix,$setting);          my $basename = join('.','internal',$context,$prefix,$setting);
         my $envname = 'environment.'.$basename;          my $envname = 'environment.'.$basename;
         if (exists($env{'form.'.$setting})) {          if (exists($env{'form.'.$setting})) {
             # Save this value away              # Save this value away
Line 5512  sub store_course_settings { Line 6276  sub store_course_settings {
 }  }
   
 sub restore_course_settings {  sub restore_course_settings {
     my $courseid = $env{'request.course.id'};      return &restore_settings($env{'request.course.id'},@_);
     my ($prefix,$Settings) = @_;  }
   
   sub restore_settings {
       my ($context,$prefix,$Settings) = @_;
     while (my ($setting,$type) = each(%$Settings)) {      while (my ($setting,$type) = each(%$Settings)) {
         next if (exists($env{'form.'.$setting}));          next if (exists($env{'form.'.$setting}));
         my $envname = 'environment.internal.'.$courseid.'.'.$prefix.          my $envname = 'environment.internal.'.$context.'.'.$prefix.
             '.'.$setting;              '.'.$setting;
         if (exists($env{$envname})) {          if (exists($env{$envname})) {
             if ($type eq 'scalar') {              if ($type eq 'scalar') {
Line 5648  sub construct_course { Line 6415  sub construct_course {
 #  #
 # Check if created correctly  # Check if created correctly
 #  #
     ($$crsudom,$$crsunum)=($$courseid=~/^\/(\w+)\/(\w+)$/);      ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);      my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
     $outcome .= &mt('Created on').': '.$crsuhome.'<br>';      $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
 #  #
Line 5657  sub construct_course { Line 6424  sub construct_course {
     my $cloneid='';      my $cloneid='';
     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {      if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
  $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};   $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);          my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
  my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);   my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
  if ($clonehome eq 'no_host') {   if ($clonehome eq 'no_host') {
     $outcome .=      $outcome .=
Line 5830  sub construct_course { Line 6597  sub construct_course {
 # if specified, key authority is not course, but user  # if specified, key authority is not course, but user
 # only active if keyaccess is yes  # only active if keyaccess is yes
     if ($args->{'keyauth'}) {      if ($args->{'keyauth'}) {
  $args->{'keyauth'}=~s/[^\w\@]//g;   my ($user,$domain) = split(':',$args->{'keyauth'});
  if ($args->{'keyauth'}) {   $user = &LONCAPA::clean_username($user);
     $cenv{'keyauth'}=$args->{'keyauth'};   $domain = &LONCAPA::clean_username($domain);
    if ($user ne '' && $domain ne '') {
       $cenv{'keyauth'}=$user.':'.$domain;
  }   }
     }      }
   
Line 5929  sub group_term { Line 6698  sub group_term {
   
 sub icon {  sub icon {
     my ($file)=@_;      my ($file)=@_;
     my $curfext = (split(/\./,$file))[-1];      my $curfext = lc((split(/\./,$file))[-1]);
     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';      my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
     my $embstyle = &Apache::loncommon::fileembstyle($curfext);      my $embstyle = &Apache::loncommon::fileembstyle($curfext);
     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {      if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
Line 5950  sub lonhttpdurl { Line 6719  sub lonhttpdurl {
     return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;      return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
 }  }
   
 sub absolute_url {  
     my ($host_name) = @_;  
     my $protocol = ($ENV{'SERVER_PORT'} == 443?'https://':'http://');  
     if ($host_name eq '') {  
  $host_name = $ENV{'SERVER_NAME'};  
     }  
     return $protocol.$host_name;  
 }  
   
 sub connection_aborted {  sub connection_aborted {
     my ($r)=@_;      my ($r)=@_;
     $r->print(" ");$r->rflush();      $r->print(" ");$r->rflush();
Line 5991  sub escape_url { Line 6751  sub escape_url {
     my $lastitem = &escape(pop(@urlslices));      my $lastitem = &escape(pop(@urlslices));
     return join('/',@urlslices).'/'.$lastitem;      return join('/',@urlslices).'/'.$lastitem;
 }  }
   
   # -------------------------------------------------------- Initliaze user login
   sub init_user_environment {
       my ($r, $username, $domain, $authhost, $form, $args) = @_;
       my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
   
       my $public=($username eq 'public' && $domain eq 'public');
   
   # See if old ID present, if so, remove
   
       my ($filename,$cookie,$userroles);
       my $now=time;
   
       if ($public) {
    my $max_public=100;
    my $oldest;
    my $oldest_time=0;
    for(my $next=1;$next<=$max_public;$next++) {
       if (-e $lonids."/publicuser_$next.id") {
    my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
    if ($mtime<$oldest_time || !$oldest_time) {
       $oldest_time=$mtime;
       $oldest=$next;
    }
       } else {
    $cookie="publicuser_$next";
    last;
       }
    }
    if (!$cookie) { $cookie="publicuser_$oldest"; }
       } else {
    # if this isn't a robot, kill any existing non-robot sessions
    if (!$args->{'robot'}) {
       opendir(DIR,$lonids);
       while ($filename=readdir(DIR)) {
    if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
       unlink($lonids.'/'.$filename);
    }
       }
       closedir(DIR);
    }
   # Give them a new cookie
    my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
                      : $now);
    $cookie="$username\_$id\_$domain\_$authhost";
       
   # Initialize roles
   
    $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
       }
   # ------------------------------------ Check browser type and MathML capability
   
       my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
           $clientunicode,$clientos) = &decode_user_agent($r);
   
   # -------------------------------------- Any accessibility options to remember?
       if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
    foreach my $option ('imagesuppress','appletsuppress',
       'embedsuppress','fontenhance','blackwhite') {
       if ($form->{$option} eq 'true') {
    &Apache::lonnet::put('environment',{$option => 'on'},
        $domain,$username);
       } else {
    &Apache::lonnet::del('environment',[$option],
        $domain,$username);
       }
    }
       }
   # ------------------------------------------------------------- Get environment
   
       my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
       my ($tmp) = keys(%userenv);
       if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
    # default remote control to off
    if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
       } else {
    undef(%userenv);
       }
       if (($userenv{'interface'}) && (!$form->{'interface'})) {
    $form->{'interface'}=$userenv{'interface'};
       }
       $env{'environment.remote'}=$userenv{'remote'};
       if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
   
   # --------------- Do not trust query string to be put directly into environment
       foreach my $option ('imagesuppress','appletsuppress',
    'embedsuppress','fontenhance','blackwhite',
    'interface','localpath','localres') {
    $form->{$option}=~s/[\n\r\=]//gs;
       }
   # --------------------------------------------------------- Write first profile
   
       {
    my %initial_env = 
       ("user.name"          => $username,
        "user.domain"        => $domain,
        "user.home"          => $authhost,
        "browser.type"       => $clientbrowser,
        "browser.version"    => $clientversion,
        "browser.mathml"     => $clientmathml,
        "browser.unicode"    => $clientunicode,
        "browser.os"         => $clientos,
        "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
        "request.course.fn"  => '',
        "request.course.uri" => '',
        "request.course.sec" => '',
        "request.role"       => 'cm',
        "request.role.adv"   => $env{'user.adv'},
        "request.host"       => $ENV{'REMOTE_ADDR'},);
   
           if ($form->{'localpath'}) {
       $initial_env{"browser.localpath"}  = $form->{'localpath'};
       $initial_env{"browser.localres"}   = $form->{'localres'};
           }
   
    if ($public) {
       $initial_env{"environment.remote"} = "off";
    }
    if ($form->{'interface'}) {
       $form->{'interface'}=~s/\W//gs;
       $initial_env{"browser.interface"} = $form->{'interface'};
       $env{'browser.interface'}=$form->{'interface'};
       foreach my $option ('imagesuppress','appletsuppress',
    'embedsuppress','fontenhance','blackwhite') {
    if (($form->{$option} eq 'true') ||
       ($userenv{$option} eq 'on')) {
       $initial_env{"browser.$option"} = "on";
    }
       }
    }
   
    $env{'user.environment'} = "$lonids/$cookie.id";
   
    if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
    &GDBM_WRCREAT(),0640)) {
       &_add_to_env(\%disk_env,\%initial_env);
       &_add_to_env(\%disk_env,\%userenv,'environment.');
       &_add_to_env(\%disk_env,$userroles);
       if (ref($args->{'extra_env'})) {
    &_add_to_env(\%disk_env,$args->{'extra_env'});
       }
       untie(%disk_env);
    } else {
       &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
      'Could not create environment storage in lonauth: '.$!.'</font>');
       return 'error: '.$!;
    }
       }
       $env{'request.role'}='cm';
       $env{'request.role.adv'}=$env{'user.adv'};
       $env{'browser.type'}=$clientbrowser;
   
       return $cookie;
   
   }
   
   sub _add_to_env {
       my ($idf,$env_data,$prefix) = @_;
       while (my ($key,$value) = each(%$env_data)) {
    $idf->{$prefix.$key} = $value;
    $env{$prefix.$key}   = $value;
       }
   }
   
   
 =pod  =pod
   
 =back  =back

Removed from v.1.454  
changed lines
  Added in v.1.524


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