Diff for /loncom/interface/loncommon.pm between versions 1.1075.2.17 and 1.1093

version 1.1075.2.17, 2012/12/12 23:03:07 version 1.1093, 2012/08/21 01:50:33
Line 70  use Apache::lonclonecourse(); Line 70  use Apache::lonclonecourse();
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use DateTime::TimeZone;  use DateTime::TimeZone;
 use DateTime::Locale::Catalog;  use DateTime::Locale::Catalog;
 use Authen::Captcha;  use Text::Aspell;
 use Captcha::reCAPTCHA;  
   
 # ---------------------------------------------- Designs  # ---------------------------------------------- Designs
 use vars qw(%defaultdesign);  use vars qw(%defaultdesign);
Line 156  sub ssi_with_retries { Line 155  sub ssi_with_retries {
 # ----------------------------------------------- Filetypes/Languages/Copyright  # ----------------------------------------------- Filetypes/Languages/Copyright
 my %language;  my %language;
 my %supported_language;  my %supported_language;
   my %supported_codes;
 my %latex_language; # For choosing hyphenation in <transl..>  my %latex_language; # For choosing hyphenation in <transl..>
 my %latex_language_bykey; # for choosing hyphenation from metadata  my %latex_language_bykey; # for choosing hyphenation from metadata
 my %cprtag;  my %cprtag;
Line 190  BEGIN { Line 190  BEGIN {
             while (my $line = <$fh>) {              while (my $line = <$fh>) {
                 next if ($line=~/^\#/);                  next if ($line=~/^\#/);
                 chomp($line);                  chomp($line);
                 my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));                  my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
                 $language{$key}=$val.' - '.$enc;                  $language{$key}=$val.' - '.$enc;
                 if ($sup) {                  if ($sup) {
                     $supported_language{$key}=$sup;                      $supported_language{$key}=$sup;
       $supported_codes{$key}   = $code;
                 }                  }
  if ($latex) {   if ($latex) {
     $latex_language_bykey{$key} = $latex;      $latex_language_bykey{$key} = $latex;
     $latex_language{$two} = $latex;      $latex_language{$code} = $latex;
  }   }
             }              }
             close($fh);              close($fh);
Line 659  if (!Array.prototype.indexOf) { Line 660  if (!Array.prototype.indexOf) {
         var n = 0;          var n = 0;
         if (arguments.length > 0) {          if (arguments.length > 0) {
             n = Number(arguments[1]);              n = Number(arguments[1]);
             if (n !== n) { // shortcut for verifying if it's NaN              if (n !== n) { // shortcut for verifying if it is NaN
                 n = 0;                  n = 0;
             } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {              } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
                 n = (n > 0 || -1) * Math.floor(Math.abs(n));                  n = (n > 0 || -1) * Math.floor(Math.abs(n));
Line 887  sub check_uncheck_jscript { Line 888  sub check_uncheck_jscript {
 function checkAll(field) {  function checkAll(field) {
     if (field.length > 0) {      if (field.length > 0) {
         for (i = 0; i < field.length; i++) {          for (i = 0; i < field.length; i++) {
             if (!field[i].disabled) {              if (!field[i].disabled) { 
                 field[i].checked = true;                  field[i].checked = true;
             }              }
         }          }
     } else {      } else {
         if (!field.disabled) {          if (!field.disabled) { 
             field.checked = true;              field.checked = true;
         }          }
     }      }
Line 1001  sub select_language { Line 1002  sub select_language {
   
 =pod  =pod
   
   
   =item * &list_languages()
   
   Returns an array reference that is suitable for use in language prompters.
   Each array element is itself a two element array.  The first element
   is the language code.  The second element a descsriptiuon of the 
   language itself.  This is suitable for use in e.g.
   &Apache::edit::select_arg (once dereferenced that is).
   
   =cut 
   
   sub list_languages {
       my @lang_choices;
   
       foreach my $id (&languageids()) {
    my $code = &supportedlanguagecode($id);
    if ($code) {
       my $selector    = $supported_codes{$id};
       my $description = &plainlanguagedescription($id);
       push (@lang_choices, [$selector, $description]);
    }
       }
       return \@lang_choices;
   }
   
   =pod
   
 =item * &linked_select_forms(...)  =item * &linked_select_forms(...)
   
 linked_select_forms returns a string containing a <script></script> block  linked_select_forms returns a string containing a <script></script> block
Line 2992  sub get_related_words { Line 3020  sub get_related_words {
     untie %thesaurus_db;      untie %thesaurus_db;
     return @Words;      return @Words;
 }  }
   ###############################################################
   #
   #  Spell checking
   #
   
   =pod
   
   =head1 Spell checking
   
   =over 4
   
   =item * &check_spelling($wordlist $language)
   
   Takes a string containing words and feeds it to an external
   spellcheck program via a pipeline. Returns a string containing
   them mis-spelled words.
   
   Parameters:
   
   =over 4
   
   =item - $wordlist
   
   String that will be fed into the spellcheck program.
   
   =item - $language
   
   Language string that specifies the language for which the spell
   check will be performed.
   
   =back
   
   =back
   
   Note: This sub assumes that aspell is installed.
   
   
   =cut
   
   
 =pod  =pod
   
Line 2999  sub get_related_words { Line 3066  sub get_related_words {
   
 =cut  =cut
   
   sub check_spelling {
       my ($wordlist, $language) = @_;
       my @misspellings;
       
       # Generate the speller and set the langauge.
       # if explicitly selected:
   
       my $speller = Text::Aspell->new;
       if ($language) {
    $speller->set_option('lang', $language);
       }
   
       # Turn the word list into an array of words by splittingon whitespace
   
       my @words = split(/\s+/, $wordlist);
   
       foreach my $word (@words) {
    if(! $speller->check($word)) {
       push(@misspellings, $word);
    }
       }
       return join(' ', @misspellings);
       
   }
   
 # -------------------------------------------------------------- Plaintext name  # -------------------------------------------------------------- Plaintext name
 =pod  =pod
   
Line 3232  sub aboutmewrapper { Line 3324  sub aboutmewrapper {
     if (!defined($username)  && !defined($domain)) {      if (!defined($username)  && !defined($domain)) {
         return;          return;
     }      }
     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.      return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
  ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';   ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
 }  }
   
Line 4960  Inputs: Line 5052  Inputs:
   
 =item * $bgcolor, used to override the bgcolor on a webpage to a specific value  =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
   
 =item * $no_inline_link, if true and in remote mode, don't show the  
          'Switch To Inline Menu' link  
   
 =item * $args, optional argument valid values are  =item * $args, optional argument valid values are
             no_auto_mt_title -> prevents &mt()ing the title arg              no_auto_mt_title -> prevents &mt()ing the title arg
             inherit_jsmath -> when creating popup window in a page,              inherit_jsmath -> when creating popup window in a page,
                               should it have jsmath forced on by the                                should it have jsmath forced on by the
                               current page                                current page
   
 =item * $advtoolsref, optional argument, ref to an array containing  
             inlineremote items to be added in "Functions" menu below  
             breadcrumbs.  
   
 =back  =back
   
 Returns: A uniform header for LON-CAPA web pages.    Returns: A uniform header for LON-CAPA web pages.  
Line 4984  other decorations will be returned. Line 5069  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,$args)=@_;
   
     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 5026  sub bodytag { Line 5111  sub bodytag {
     }      }
   
     if (!$realm) { $realm='&nbsp;'; }      if (!$realm) { $realm='&nbsp;'; }
 # Set messages  
     my $messages=&domainlogo($domain);  
   
     my $extra_body_attr = &make_attr_string($forcereg,\%design);      my $extra_body_attr = &make_attr_string($forcereg,\%design);
   
Line 5062  sub bodytag { Line 5145  sub bodytag {
     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;      $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);      &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
   
     if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {           if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
         return $bodytag;               return $bodytag; 
     }          } 
   
     if ($env{'request.state'} eq 'construct') { $forcereg=1; }  
   
     unless ($env{'environment.remote'} eq 'on') {          if ($env{'request.state'} eq 'construct') { $forcereg=1; }
   
         #    if ($env{'request.state'} eq 'construct') {          #    if ($env{'request.state'} eq 'construct') {
         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls          #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
Line 5077  sub bodytag { Line 5158  sub bodytag {
   
   
         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {          if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
             unless ($env{'request.noversionuri'} =~ m{/res/adm/pages/bookmarkmenu/}) {               if ($dc_info) {
                 if ($dc_info) {                   $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                      $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;               }
                 }               $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                 $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />                  <em>$realm</em> $dc_info</div>|;
                                <em>$realm</em> $dc_info</div>|;  
             }  
             return $bodytag;              return $bodytag;
         }          }
   
Line 5111  sub bodytag { Line 5190  sub bodytag {
                                 $args->{'bread_crumbs'});                                  $args->{'bread_crumbs'});
             } elsif ($forcereg) {               } elsif ($forcereg) { 
                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);                  $bodytag .= &Apache::lonmenu::innerregister($forcereg);
             } else {  
                 $bodytag .=  
                     &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},  
                                                         $forcereg,$args->{'group'},  
                                                         $args->{'bread_crumbs'},  
                                                         $advtoolsref);  
             }              }
         }else{          }else{
             # this is to seperate menu from content when there's no secondary              # this is to seperate menu from content when there's no secondary
Line 5126  sub bodytag { Line 5199  sub bodytag {
         }          }
   
         return $bodytag;          return $bodytag;
     }  
   
 #  
 # Top frame rendering, Remote is up  
 #  
   
     my $imgsrc = $img;  
     if ($img =~ /^\/adm/) {  
         $imgsrc = &lonhttpdurl($img);  
     }  
     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';  
   
     # Explicit link to get inline menu  
     my $menu= ($no_inline_link?''  
                :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');  
   
     if ($dc_info) {  
         $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;  
     }  
   
     unless ($env{'form.inhibitmenu'}) {  
         $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>  
                        <ol class="LC_primary_menu LC_right">  
                        <li>$menu</li>  
                        </ol><div id="LC_realm"> $realm $dc_info</div>|;  
     }  
     my $funclist;  
     if ($env{'request.state'} eq 'construct') {  
         if (!$public){  
             if ($env{'request.state'} eq 'construct') {  
                 $funclist = &Apache::lonhtmlcommon::scripttag(  
                                 &Apache::lonmenu::utilityfunctions(), 'start').  
                             &Apache::lonhtmlcommon::scripttag('','end').  
                             &Apache::lonmenu::innerregister($forcereg,  
                                                             $args->{'bread_crumbs'});  
             }  
         }  
     }  
     return(<<ENDBODY);  
 $bodytag  
 <table id="LC_title_bar" class="LC_with_remote">  
 <tr><td>$upperleft</td>  
     <td>$messages&nbsp;</td>  
 </tr>  
 <tr><td>$titleinfo $dc_info $menu</td>  
 </tr>  
 </table>  
 $funclist  
 ENDBODY  
 }  }
   
 sub dc_courseid_toggle {  sub dc_courseid_toggle {
Line 5206  sub make_attr_string { Line 5230  sub make_attr_string {
  delete($attr_ref->{$key});   delete($attr_ref->{$key});
     }      }
  }   }
         if ($env{'environment.remote'} eq 'on') {   $attr_ref->{'onload'}  = $on_load;
             $attr_ref->{'onload'}  =   $attr_ref->{'onunload'}= $on_unload;
                 &Apache::lonmenu::loadevents().  $on_load;  
             $attr_ref->{'onunload'}=  
                 &Apache::lonmenu::unloadevents().$on_unload;  
         } else {    
     $attr_ref->{'onload'}  = $on_load;  
     $attr_ref->{'onunload'}= $on_unload;  
         }  
     }      }
   
     my $attr_string;      my $attr_string;
Line 5387  form, .inline { Line 5404  form, .inline {
   
 .LC_error {  .LC_error {
   color: red;    color: red;
     font-size: larger;
 }  }
   
 .LC_warning {  .LC_warning,
   color: darkorange;  
 }  
   
 .LC_diff_removed {  .LC_diff_removed {
   color: red;    color: red;
 }  }
Line 5555  td.LC_table_cell_checkbox { Line 5570  td.LC_table_cell_checkbox {
   text-align: left;    text-align: left;
 }  }
   
 .LC_head_subbox, .LC_actionbox {  .LC_head_subbox {
   clear:both;    clear:both;
   background: #F8F8F8; /* $sidebg; */    background: #F8F8F8; /* $sidebg; */
   border: 1px solid $sidebg;    border: 1px solid $sidebg;
   margin: 0 0 10px 0;    margin: 0 0 10px 0;      
   padding: 3px;    padding: 3px;
   text-align: left;    text-align: left;
 }  }
Line 6254  div.LC_docs_entry_move { Line 6269  div.LC_docs_entry_move {
   
 table.LC_data_table tr > td.LC_docs_entry_commands,  table.LC_data_table tr > td.LC_docs_entry_commands,
 table.LC_data_table tr > td.LC_docs_entry_parameter {  table.LC_data_table tr > td.LC_docs_entry_parameter {
     background: #DDDDDD;
   font-size: x-small;    font-size: x-small;
 }  }
   
Line 6634  ul#LC_secondary_menu { Line 6650  ul#LC_secondary_menu {
   margin: 0;    margin: 0;
   width: 100%;    width: 100%;
   text-align: left;    text-align: left;
   float: left;  
 }  }
   
 ul#LC_secondary_menu li {  ul#LC_secondary_menu li {
   font-weight: bold;    font-weight: bold;
   line-height: 1.8em;    line-height: 1.8em;
   border-right: 1px solid black;  
   vertical-align: middle;  
   float: left;  
 }  
   
 ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {  
   background-color: $data_table_light;  
 }  
   
 ul#LC_secondary_menu li a {  
   padding: 0 0.8em;    padding: 0 0.8em;
 }  
   
 ul#LC_secondary_menu li ul {  
   display: none;  
 }  
   
 ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {  
   display: block;  
   position: absolute;  
   margin: 0;  
   padding: 0;  
   list-style:none;  
   float: none;  
   background-color: $data_table_light;  
   z-index: 2;  
   margin-left: -1px;  
 }  
   
 ul#LC_secondary_menu li ul li {  
   font-size: 90%;  
   vertical-align: top;  
   border-left: 1px solid black;  
   border-right: 1px solid black;    border-right: 1px solid black;
   background-color: $data_table_light    display: inline;
   list-style:none;    vertical-align: middle;
   float: none;  
 }  
   
 ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {  
   background-color: $data_table_dark;  
 }  }
   
 ul.LC_TabContent {  ul.LC_TabContent {
Line 7127  ul.LC_funclist li { Line 7105  ul.LC_funclist li {
  cursor:pointer;   cursor:pointer;
 }  }
   
 /*  
   styles used by TTH when "Default set of options to pass to tth/m  
   when converting TeX" in course settings has been set  
   
   option passed: -t  
   
 */  
   
 td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}  
 td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}  
 td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}  
 td div.norm {line-height:normal;}  
   
 /*  
   option passed -y3  
 */  
   
 span.roman {font-family: serif; font-style: normal; font-weight: normal;}  
 span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}  
 span.overacc1 {position: relative;  left: .6em; top: -1.2ex;}  
   
 END  END
 }  }
   
Line 7201  sub headtag { Line 7158  sub headtag {
     if (!$args->{'frameset'}) {      if (!$args->{'frameset'}) {
  $result .= &Apache::lonhtmlcommon::htmlareaheaders();   $result .= &Apache::lonhtmlcommon::htmlareaheaders();
     }      }
     if ($args->{'force_register'}) {      if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
         $result .= &Apache::lonmenu::registerurl(1);          $result .= Apache::lonxml::display_title();
     }      }
     if (!$args->{'no_nav_bar'}       if (!$args->{'no_nav_bar'} 
  && !$args->{'only_body'}   && !$args->{'only_body'}
Line 7411  $args - additional optional args support Line 7368  $args - additional optional args support
              skip_phases    -> hash ref of                skip_phases    -> hash ref of 
                                     head -> skip the <html><head> generation                                      head -> skip the <html><head> generation
                                     body -> skip all <body> generation                                      body -> skip all <body> generation
              no_inline_link -> if true and in remote mode, don't show the  
                                     'Switch To Inline Menu' link  
              no_auto_mt_title -> prevent &mt()ing the title arg               no_auto_mt_title -> prevent &mt()ing the title arg
              inherit_jsmath -> when creating popup window in a page,               inherit_jsmath -> when creating popup window in a page,
                                     should it have jsmath forced on by the                                      should it have jsmath forced on by the
                                     current page                                      current page
              bread_crumbs ->             Array containing breadcrumbs               bread_crumbs ->             Array containing breadcrumbs
              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs               bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
              group          -> includes the current group, if page is for a  
                                specific group  
   
 =back  =back
   
Line 7433  sub start_page { Line 7386  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);      my $result;
   
     if (! exists($args->{'skip_phases'}{'head'}) ) {      if (! exists($args->{'skip_phases'}{'head'}) ) {
         $result .= &xml_begin() . &headtag($title, $head_extra, $args);          $result .= &xml_begin() . &headtag($title, $head_extra, $args);
Line 7450  sub start_page { Line 7403  sub start_page {
                          $args->{'function'},       $args->{'add_entries'},                           $args->{'function'},       $args->{'add_entries'},
                          $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);
                          $args,                     \@advtools);  
         }          }
     }      }
   
Line 7875  sub simple_error_page { Line 7827  sub simple_error_page {
     my ($r,$title,$msg) = @_;      my ($r,$title,$msg) = @_;
     my $page =      my $page =
  &Apache::loncommon::start_page($title).   &Apache::loncommon::start_page($title).
  '<p class="LC_error">'.&mt($msg).'</p>'.   &mt($msg).
  &Apache::loncommon::end_page();   &Apache::loncommon::end_page();
     if (ref($r)) {      if (ref($r)) {
  $r->print($page);   $r->print($page);
Line 9510  sub ask_for_embedded_content { Line 9462  sub ask_for_embedded_content {
             $toplevel = $url;              $toplevel = $url;
             if ($args->{'context'} eq 'paste') {              if ($args->{'context'} eq 'paste') {
                 ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});                  ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
                 ($path) =                  ($path) = 
                     ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});                      ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);                  $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                 $fileloc =~ s{^/}{};                  $fileloc =~ s{^/}{};
             }              }
         }          }
     } elsif ($actionurl eq '/adm/dependencies') {      } elsif ($actionurl eq '/adm/dependencies')  {
         if ($env{'request.course.id'} ne '') {          if ($env{'request.course.id'} ne '') {
             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};              $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
             $cnum =  $env{'course.'.$env{'request.course.id'}.'.num'};              $cnum =  $env{'course.'.$env{'request.course.id'}.'.num'};
Line 9704  sub ask_for_embedded_content { Line 9656  sub ask_for_embedded_content {
         ($args->{'context'} eq 'paste')) {          ($args->{'context'} eq 'paste')) {
         $counter = scalar(keys(%existing));          $counter = scalar(keys(%existing));
         $numpathchg = scalar(keys(%pathchanges));          $numpathchg = scalar(keys(%pathchanges));
         return ($output,$counter,$numpathchg,\%existing);          return ($output,$counter,$numpathchg,\%existing); 
     }      }
     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {      foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
         if ($actionurl eq '/adm/dependencies') {          if ($actionurl eq '/adm/dependencies') {
Line 11325  sub process_extracted_files { Line 11277  sub process_extracted_files {
     if ($env{'form.folderpath'}) {      if ($env{'form.folderpath'}) {
         my @items = split('&',$env{'form.folderpath'});          my @items = split('&',$env{'form.folderpath'});
         $folders{'0'} = $items[-2];          $folders{'0'} = $items[-2];
         if ($env{'form.folderpath'} =~ /\:1$/) {          $containers{'0'}='sequence';
             $containers{'0'}='page';      } elsif ($env{'form.pagepath'}) {
         } else {          my @items = split('&',$env{'form.pagepath'});
             $containers{'0'}='sequence';          $folders{'0'} = $items[-2];
         }          $containers{'0'}='page';
     }      }
     my @archdirs = &get_env_multiple('form.archive_directory');      my @archdirs = &get_env_multiple('form.archive_directory');
     if ($numitems) {      if ($numitems) {
Line 11447  sub process_extracted_files { Line 11399  sub process_extracted_files {
                     }                      }
                 }                  }
             } else {              } else {
                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';                  $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />'; 
             }              }
         }          }
         for (my $i=1; $i<=$numitems; $i++) {          for (my $i=1; $i<=$numitems; $i++) {
Line 11469  sub process_extracted_files { Line 11421  sub process_extracted_files {
                         }                          }
                         if ($itemidx eq '') {                          if ($itemidx eq '') {
                             $itemidx =  0;                              $itemidx =  0;
                         }                          } 
                         if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {                          if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
                             if ($mapinner{$referrer{$i}}) {                              if ($mapinner{$referrer{$i}}) {
                                 $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";                                  $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
Line 11516  sub process_extracted_files { Line 11468  sub process_extracted_files {
                                     $showpath = "$relpath/$title";                                      $showpath = "$relpath/$title";
                                 } else {                                  } else {
                                     $showpath = "/$title";                                      $showpath = "/$title";
                                 }                                  } 
                                 $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";                                  $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
                             }                              } 
                             unless ($ishome) {                              unless ($ishome) {
                                 my $fetch = "$fullpath/$title";                                  my $fetch = "$fullpath/$title";
                                 $fetch =~ s/^\Q$prefix$dir\E//;                                  $fetch =~ s/^\Q$prefix$dir\E//; 
                                 $prompttofetch{$fetch} = 1;                                  $prompttofetch{$fetch} = 1;
                             }                              }
                         }                          }
Line 11531  sub process_extracted_files { Line 11483  sub process_extracted_files {
                                     $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';                                      $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
                 }                  }
             } else {              } else {
                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';                  $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />'; 
             }              }
         }          }
         if (keys(%todelete)) {          if (keys(%todelete)) {
Line 13931  sub init_user_environment { Line 13883  sub init_user_environment {
         my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],          my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
                                              $domain,$username);                                               $domain,$username);
         my $reqstatus = $reqauthor{'author_status'};          my $reqstatus = $reqauthor{'author_status'};
         if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {          if ($reqstatus eq 'approval' || $reqstatus eq 'approved') { 
             if (ref($reqauthor{'author'}) eq 'HASH') {              if (ref($reqauthor{'author'}) eq 'HASH') {
                 $userenv{'requestauthorqueued'} = $reqstatus.':'.                  $userenv{'requestauthorqueued'} = $reqstatus.':'.
                                                   $reqauthor{'author'}{'timestamp'};                                                    $reqauthor{'author'}{'timestamp'};
Line 14112  sub parse_supplemental_title { Line 14064  sub parse_supplemental_title {
     return $title;      return $title;
 }  }
   
 sub captcha_display {  
     my ($context,$lonhost) = @_;  
     my ($output,$error);  
     my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);  
     if ($captcha eq 'original') {  
         $output = &create_captcha();  
         unless ($output) {  
             $error = 'captcha';  
         }  
     } elsif ($captcha eq 'recaptcha') {  
         $output = &create_recaptcha($pubkey);  
         unless ($output) {  
             $error = 'recaptcha';  
         }  
     }  
     return ($output,$error);  
 }  
   
 sub captcha_response {  
     my ($context,$lonhost) = @_;  
     my ($captcha_chk,$captcha_error);  
     my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);  
     if ($captcha eq 'original') {  
         ($captcha_chk,$captcha_error) = &check_captcha();  
     } elsif ($captcha eq 'recaptcha') {  
         $captcha_chk = &check_recaptcha($privkey);  
     } else {  
         $captcha_chk = 1;  
     }  
     return ($captcha_chk,$captcha_error);  
 }  
   
 sub get_captcha_config {  
     my ($context,$lonhost) = @_;  
     my ($captcha,$pubkey,$privkey,$hashtocheck);  
     my $hostname = &Apache::lonnet::hostname($lonhost);  
     my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);  
     my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);  
     if ($context eq 'usercreation') {  
         my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);  
         if (ref($domconfig{$context}) eq 'HASH') {  
             $hashtocheck = $domconfig{$context}{'cancreate'};  
             if (ref($hashtocheck) eq 'HASH') {  
                 if ($hashtocheck->{'captcha'} eq 'recaptcha') {  
                     if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {  
                         $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};  
                         $privkey = $hashtocheck->{'recaptchakeys'}{'private'};  
                     }  
                     if ($privkey && $pubkey) {  
                         $captcha = 'recaptcha';  
                     } else {  
                         $captcha = 'original';  
                     }  
                 } elsif ($hashtocheck->{'captcha'} ne 'notused') {  
                     $captcha = 'original';  
                 }  
             }  
         } else {  
             $captcha = 'captcha';  
         }  
     } elsif ($context eq 'login') {  
         my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);  
         if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {  
             $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};  
             $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};  
             if ($privkey && $pubkey) {  
                 $captcha = 'recaptcha';  
             } else {  
                 $captcha = 'original';  
             }  
         } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {  
             $captcha = 'original';  
         }  
     }  
     return ($captcha,$pubkey,$privkey);  
 }  
   
 sub create_captcha {  
     my %captcha_params = &captcha_settings();  
     my ($output,$maxtries,$tries) = ('',10,0);  
     while ($tries < $maxtries) {  
         $tries ++;  
         my $captcha = Authen::Captcha->new (  
                                            output_folder => $captcha_params{'output_dir'},  
                                            data_folder   => $captcha_params{'db_dir'},  
                                           );  
         my $md5sum = $captcha->generate_code($captcha_params{'numchars'});  
   
         if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {  
             $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".  
                       &mt('Type in the letters/numbers shown below').'&nbsp;'.  
                      '<input type="text" size="5" name="code" value="" /><br />'.  
                      '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';  
             last;  
         }  
     }  
     return $output;  
 }  
   
 sub captcha_settings {  
     my %captcha_params = (  
                            output_dir     => $Apache::lonnet::perlvar{'lonCaptchaDir'},  
                            www_output_dir => "/captchaspool",  
                            db_dir         => $Apache::lonnet::perlvar{'lonCaptchaDb'},  
                            numchars       => '5',  
                          );  
     return %captcha_params;  
 }  
   
 sub check_captcha {  
     my ($captcha_chk,$captcha_error);  
     my $code = $env{'form.code'};  
     my $md5sum = $env{'form.crypt'};  
     my %captcha_params = &captcha_settings();  
     my $captcha = Authen::Captcha->new(  
                       output_folder => $captcha_params{'output_dir'},  
                       data_folder   => $captcha_params{'db_dir'},  
                   );  
     my $captcha_chk = $captcha->check_code($code,$md5sum);  
     my %captcha_hash = (  
                         0       => 'Code not checked (file error)',  
                        -1      => 'Failed: code expired',  
                        -2      => 'Failed: invalid code (not in database)',  
                        -3      => 'Failed: invalid code (code does not match crypt)',  
     );  
     if ($captcha_chk != 1) {  
         $captcha_error = $captcha_hash{$captcha_chk}  
     }  
     return ($captcha_chk,$captcha_error);  
 }  
   
 sub create_recaptcha {  
     my ($pubkey) = @_;  
     my $captcha = Captcha::reCAPTCHA->new;  
     return $captcha->get_options_setter({theme => 'white'})."\n".  
            $captcha->get_html($pubkey).  
            &mt('If either word is hard to read, [_1] will replace them.',  
                '<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').  
            '<br /><br />';  
 }  
   
 sub check_recaptcha {  
     my ($privkey) = @_;  
     my $captcha_chk;  
     my $captcha = Captcha::reCAPTCHA->new;  
     my $captcha_result =  
         $captcha->check_answer(  
                                 $privkey,  
                                 $ENV{'REMOTE_ADDR'},  
                                 $env{'form.recaptcha_challenge_field'},  
                                 $env{'form.recaptcha_response_field'},  
                               );  
     if ($captcha_result->{is_valid}) {  
         $captcha_chk = 1;  
     }  
     return $captcha_chk;  
 }  
   
 =pod  =pod
   
 =back  =back

Removed from v.1.1075.2.17  
changed lines
  Added in v.1.1093


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