Diff for /loncom/interface/loncommon.pm between versions 1.1075.2.15 and 1.1080

version 1.1075.2.15, 2012/12/12 22:57:22 version 1.1080, 2012/05/28 20:31:17
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 Captcha::reCAPTCHA;  
   
 # ---------------------------------------------- Designs  # ---------------------------------------------- Designs
 use vars qw(%defaultdesign);  use vars qw(%defaultdesign);
Line 887  sub check_uncheck_jscript { Line 885  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) {              field[i].checked = true ;
                 field[i].checked = true;  
             }  
         }          }
     } else {      } else {
         if (!field.disabled) {          field.checked = true
             field.checked = true;  
         }  
     }      }
 }  }
     
Line 3232  sub aboutmewrapper { Line 3226  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 4954  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 4971  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 5013  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 5047  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 5060  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 5092  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 5101  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 5132  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 5306  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 6635  ul#LC_secondary_menu { Line 6552  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 7021  ul#LC_toolbar { Line 6900  ul#LC_toolbar {
   list-style:none;    list-style:none;
   position:relative;    position:relative;
   background-color:white;    background-color:white;
   overflow: auto;  
 }  }
   
 ul#LC_toolbar li {  ul#LC_toolbar li {
Line 7031  ul#LC_toolbar li { Line 6909  ul#LC_toolbar li {
   float: left;    float: left;
   display:inline;    display:inline;
   vertical-align:middle;    vertical-align:middle;
   white-space: nowrap;  
 }  }
   
   
Line 7181  sub headtag { Line 7058  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 7391  $args - additional optional args support Line 7268  $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 7413  sub start_page { Line 7286  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 7430  sub start_page { Line 7303  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 7855  sub simple_error_page { Line 7727  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 9442  sub get_env_multiple { Line 9314  sub get_env_multiple {
 sub ask_for_embedded_content {  sub ask_for_embedded_content {
     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;      my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,      my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
         %currsubfile,%unused,$rem);          %currsubfile,%unused);
     my $counter = 0;      my $counter = 0;
     my $numnew = 0;      my $numnew = 0;
     my $numremref = 0;      my $numremref = 0;
Line 9455  sub ask_for_embedded_content { Line 9327  sub ask_for_embedded_content {
     my $heading = &mt('Upload embedded files');      my $heading = &mt('Upload embedded files');
     my $buttontext = &mt('Upload');      my $buttontext = &mt('Upload');
   
     my $navmap;  
     if ($env{'request.course.id'}) {  
         $navmap = Apache::lonnavmaps::navmap->new();  
     }  
     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {      if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
         my $current_path='/';          my $current_path='/';
         if ($env{'form.currentpath'}) {          if ($env{'form.currentpath'}) {
Line 9488  sub ask_for_embedded_content { Line 9356  sub ask_for_embedded_content {
         if (ref($args) eq 'HASH') {          if (ref($args) eq 'HASH') {
             $url = $args->{'docs_url'};              $url = $args->{'docs_url'};
             $toplevel = $url;              $toplevel = $url;
             if ($args->{'context'} eq 'paste') {  
                 ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});  
                 ($path) =  
                     ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});  
                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);  
                 $fileloc =~ s{^/}{};  
             }  
         }          }
     } elsif ($actionurl eq '/adm/dependencies') {      } elsif ($actionurl eq '/adm/dependencies') {
         if ($env{'request.course.id'} ne '') {          if ($env{'request.course.id'} ne '') {
Line 9504  sub ask_for_embedded_content { Line 9365  sub ask_for_embedded_content {
                 $url = $args->{'docs_url'};                  $url = $args->{'docs_url'};
                 $title = $args->{'docs_title'};                  $title = $args->{'docs_title'};
                 $toplevel = "/$url";                  $toplevel = "/$url";
                 ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});  
                 ($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);
Line 9567  sub ask_for_embedded_content { Line 9427  sub ask_for_embedded_content {
                 my @subdir_list = grep(!/^\./,readdir($dir));                  my @subdir_list = grep(!/^\./,readdir($dir));
                 map {$currsubfile{$path}{$_} = 1;} @subdir_list;                  map {$currsubfile{$path}{$_} = 1;} @subdir_list;
             }              }
         } elsif (($actionurl eq '/adm/dependencies') ||          } elsif ($actionurl eq '/adm/dependencies') {
                  (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&  
                   ($args->{'context'} eq 'paste'))) {  
             if ($env{'request.course.id'} ne '') {              if ($env{'request.course.id'} ne '') {
                 my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});                  my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                 if ($dir ne '') {                  if ($dir ne '') {
Line 9605  sub ask_for_embedded_content { Line 9463  sub ask_for_embedded_content {
                 if (ref($currsubfile{$path}) eq 'HASH') {                  if (ref($currsubfile{$path}) eq 'HASH') {
                     foreach my $file (keys(%{$currsubfile{$path}})) {                      foreach my $file (keys(%{$currsubfile{$path}})) {
                          unless ($subdependencies{$path}{$file}) {                           unless ($subdependencies{$path}{$file}) {
                              next if (($rem ne '') &&  
                                       (($env{"httpref.$rem"."$path/$file"} ne '') ||  
                                        (ref($navmap) &&  
                                        (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||  
                                         (($file =~ /^(.*\.s?html?)\.bak$/i) &&  
                                          ($navmap->getResourceByUrl($rem."$path/$1")))))));  
                              $unused{$path.'/'.$file} = 1;                                $unused{$path.'/'.$file} = 1; 
                          }                           }
                     }                      }
Line 9633  sub ask_for_embedded_content { Line 9485  sub ask_for_embedded_content {
             my @dir_list = grep(!/^\./,readdir($dir));              my @dir_list = grep(!/^\./,readdir($dir));
             map {$currfile{$_} = 1;} @dir_list;              map {$currfile{$_} = 1;} @dir_list;
         }          }
     } elsif (($actionurl eq '/adm/dependencies') ||      } elsif ($actionurl eq '/adm/dependencies') {
              (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&  
               ($args->{'context'} eq 'paste'))) {  
         if ($env{'request.course.id'} ne '') {          if ($env{'request.course.id'} ne '') {
             my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});              my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
             if ($dir ne '') {              if ($dir ne '') {
Line 9669  sub ask_for_embedded_content { Line 9519  sub ask_for_embedded_content {
         unless (($file eq $filename) ||          unless (($file eq $filename) ||
                 ($file eq $filename.'.bak') ||                  ($file eq $filename.'.bak') ||
                 ($dependencies{$file})) {                  ($dependencies{$file})) {
             if ($actionurl eq '/adm/dependencies') {  
                 next if (($rem ne '') &&  
                          (($env{"httpref.$rem".$file} ne '') ||  
                           (ref($navmap) &&  
                           (($navmap->getResourceByUrl($rem.$file) ne '') ||  
                            (($file =~ /^(.*\.s?html?)\.bak$/i) &&  
                             ($navmap->getResourceByUrl($rem.$1)))))));  
             }  
             $unused{$file} = 1;              $unused{$file} = 1;
         }          }
     }      }
     if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&  
         ($args->{'context'} eq 'paste')) {  
         $counter = scalar(keys(%existing));  
         $numpathchg = scalar(keys(%pathchanges));  
         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') {
             next if ($embed_file =~ m{^\w+://});              next if ($embed_file =~ m{^\w+://});
Line 9702  sub ask_for_embedded_content { Line 9538  sub ask_for_embedded_content {
             $numremref++;              $numremref++;
         } elsif ($args->{'error_on_invalid_names'}          } elsif ($args->{'error_on_invalid_names'}
             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {              && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
   
             $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';              $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
             $numinvalid++;              $numinvalid++;
         } else {          } else {
Line 11189  function dependencyCheck(form,count,offs Line 11026  function dependencyCheck(form,count,offs
             document.getElementById('arc_depon_'+count).style.display='block';               document.getElementById('arc_depon_'+count).style.display='block'; 
             form.elements[depitem].options.length = 0;              form.elements[depitem].options.length = 0;
             form.elements[depitem].options[0] = new Option('Select','',true,true);              form.elements[depitem].options[0] = new Option('Select','',true,true);
             for (var i=1; i<=numitems; i++) {              for (var i=1; i<count; i++) {
                 if (i == count) {  
                     continue;  
                 }  
                 var startelement = $startcount + (i-1) * 7;                  var startelement = $startcount + (i-1) * 7;
                 for (var j=1; j<6; j++) {                  for (var j=1; j<6; j++) {
                     if ((j != 2) && (j!= 4)) {                      if ((j != 2) && (j!= 4)) {
Line 11333  sub process_extracted_files { Line 11167  sub process_extracted_files {
     my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);      my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
     if ($numitems) {      if ($numitems) {
         for (my $i=1; $i<=$numitems; $i++) {          for (my $i=1; $i<=$numitems; $i++) {
             next if ($env{'form.archive_'.$i} eq 'dependency');  
             my $path = $env{'form.archive_content_'.$i};              my $path = $env{'form.archive_content_'.$i};
             if ($path =~ /^\Q$pathtocheck\E/) {              if ($path =~ /^\Q$pathtocheck\E/) {
                 if ($env{'form.archive_'.$i} eq 'discard') {                  if ($env{'form.archive_'.$i} eq 'discard') {
Line 11384  sub process_extracted_files { Line 11217  sub process_extracted_files {
                             my ($outtext,$errtext) =                              my ($outtext,$errtext) =
                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.                                  &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                                                         $docuname.'/'.$folders{$outer}.                                                          $docuname.'/'.$folders{$outer}.
                                                         '.'.$containers{$outer},1,1);                                                          '.'.$containers{$outer},1);
                             $newseqid{$i} = $newidx;                              $newseqid{$i} = $newidx;
                             unless ($errtext) {                              unless ($errtext) {
                                 $result .=  '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";                                  $result .=  '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
Line 11417  sub process_extracted_files { Line 11250  sub process_extracted_files {
                             my ($outtext,$errtext)=                              my ($outtext,$errtext)=
                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.                                  &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                                                         $docuname.'/'.$folders{$outer}.                                                          $docuname.'/'.$folders{$outer}.
                                                         '.'.$containers{$outer},1,1);                                                          '.'.$containers{$outer},1);
                             unless ($errtext) {                              unless ($errtext) {
                                 if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {                                  if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
                                     $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";                                      $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
Line 11425  sub process_extracted_files { Line 11258  sub process_extracted_files {
                             }                              }
                         }                          }
                     }                      }
                 }                  } elsif ($env{'form.archive_'.$i} eq 'dependency') {
             } else {                      my ($title) = ($path =~ m{/([^/]+)$});
                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';                      $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
             }                      if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
         }                          if (ref($dirorder{$i}) eq 'ARRAY') {
         for (my $i=1; $i<=$numitems; $i++) {                              my ($itemidx,$fullpath,$relpath);
             next unless ($env{'form.archive_'.$i} eq 'dependency');  
             my $path = $env{'form.archive_content_'.$i};  
             if ($path =~ /^\Q$pathtocheck\E/) {  
                 my ($title) = ($path =~ m{/([^/]+)$});  
                 $referrer{$i} = $env{'form.archive_dependent_on_'.$i};  
                 if ($env{'form.archive_'.$referrer{$i}} eq 'display') {  
                     if (ref($dirorder{$i}) eq 'ARRAY') {  
                         my ($itemidx,$fullpath,$relpath);  
                         if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {  
                             my $container = $dirorder{$referrer{$i}}->[-1];  
                             for (my $j=0; $j<@{$dirorder{$i}}; $j++) {                              for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
                                 if ($dirorder{$i}->[$j] eq $container) {                                  if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
                                     $itemidx = $j;                                      my $container = $dirorder{$referrer{$i}}->[-1];
                                       for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
                                           if ($dirorder{$i}->[$j] eq $container) {
                                               $itemidx = $j;
                                           }
                                       }
                                 }                                  }
                             }                              }
                         }                              if ($itemidx ne '') {
                         if ($itemidx eq '') {                                  if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
                             $itemidx =  0;                                      if ($mapinner{$referrer{$i}}) {
                         }                                          $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
                         if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {                                          for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                             if ($mapinner{$referrer{$i}}) {                                              if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                                 $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";                                                  unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                                 for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {                                                      $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                     if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {                                                      $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                         unless (defined($newseqid{$dirorder{$i}->[$j]})) {                                                      if (!-e $fullpath) {
                                             $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};                                                          mkdir($fullpath,0755);
                                             $relpath .= '/'.$titles{$dirorder{$i}->[$j]};                                                      }
                                             if (!-e $fullpath) {                                                  }
                                                 mkdir($fullpath,0755);                                              } else {
                                                   last;
                                             }                                              }
                                         }                                          }
                                     } else {  
                                         last;  
                                     }                                      }
                                 }                                  } elsif ($newdest{$referrer{$i}}) {
                             }                                      $fullpath = $newdest{$referrer{$i}};
                         } elsif ($newdest{$referrer{$i}}) {                                      for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                             $fullpath = $newdest{$referrer{$i}};                                          if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
                             for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {                                              $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
                                 if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {                                              last;
                                     $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};                                          } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                                     last;                                              unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                                 } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {                                                  $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                     unless (defined($newseqid{$dirorder{$i}->[$j]})) {                                                  $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                         $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};                                                  if (!-e $fullpath) {
                                         $relpath .= '/'.$titles{$dirorder{$i}->[$j]};                                                      mkdir($fullpath,0755);
                                         if (!-e $fullpath) {                                                  }
                                             mkdir($fullpath,0755);                                              }
                                           } else {
                                               last;
                                         }                                          }
                                     }                                      }
                                 } else {  
                                     last;  
                                 }                                  }
                             }                                  if ($fullpath ne '') {
                         }                                      if (-e "$prefix$path") {
                         if ($fullpath ne '') {                                          system("mv $prefix$path $fullpath/$title");
                             if (-e "$prefix$path") {                                      }
                                 system("mv $prefix$path $fullpath/$title");                                      if (-e "$fullpath/$title") {
                             }                                          my $showpath;
                             if (-e "$fullpath/$title") {                                          if ($relpath ne '') {
                                 my $showpath;                                              $showpath = "$relpath/$title";
                                 if ($relpath ne '') {                                          } else {
                                     $showpath = "$relpath/$title";                                              $showpath = "/$title";
                                 } else {                                          } 
                                     $showpath = "/$title";                                          $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
                                       } 
                                       unless ($ishome) {
                                           my $fetch = "$fullpath/$title";
                                           $fetch =~ s/^\Q$prefix$dir\E//; 
                                           $prompttofetch{$fetch} = 1;
                                       }
                                 }                                  }
                                 $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";  
                             }  
                             unless ($ishome) {  
                                 my $fetch = "$fullpath/$title";  
                                 $fetch =~ s/^\Q$prefix$dir\E//;  
                                 $prompttofetch{$fetch} = 1;  
                             }                              }
                         }                          }
                       } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
                           $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
                                           $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
                     }                      }
                 } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {  
                     $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',  
                                     $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 13891  sub init_user_environment { Line 13718  sub init_user_environment {
             %domdef = &Apache::lonnet::get_domain_defaults($domain);              %domdef = &Apache::lonnet::get_domain_defaults($domain);
         }          }
   
         foreach my $tool ('aboutme','blog','webdav','portfolio') {          foreach my $tool ('aboutme','blog','portfolio') {
             $userenv{'availabletools.'.$tool} =               $userenv{'availabletools.'.$tool} = 
                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',                  &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                                                   undef,\%userenv,\%domdef,\%is_adv);                                                    undef,\%userenv,\%domdef,\%is_adv);
Line 13904  sub init_user_environment { Line 13731  sub init_user_environment {
                                                   \%userenv,\%domdef,\%is_adv);                                                    \%userenv,\%domdef,\%is_adv);
         }          }
   
         $userenv{'canrequest.author'} =  
             &Apache::lonnet::usertools_access($username,$domain,'requestauthor',  
                                         'reload','requestauthor',  
                                         \%userenv,\%domdef,\%is_adv);  
         my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],  
                                              $domain,$username);  
         my $reqstatus = $reqauthor{'author_status'};  
         if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {  
             if (ref($reqauthor{'author'}) eq 'HASH') {  
                 $userenv{'requestauthorqueued'} = $reqstatus.':'.  
                                                   $reqauthor{'author'}{'timestamp'};  
             }  
         }  
   
  $env{'user.environment'} = "$lonids/$cookie.id";   $env{'user.environment'} = "$lonids/$cookie.id";
   
  if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",   if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
Line 14032  sub build_release_hashes { Line 13845  sub build_release_hashes {
     return;      return;
 }  }
   
 sub update_content_constraints {  
     my ($cdom,$cnum,$chome,$cid) = @_;  
     my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');  
     my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});  
     my %checkresponsetypes;  
     foreach my $key (keys(%Apache::lonnet::needsrelease)) {  
         my ($item,$name,$value) = split(/:/,$key);  
         if ($item eq 'resourcetag') {  
             if ($name eq 'responsetype') {  
                 $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}  
             }  
         }  
     }  
     my $navmap = Apache::lonnavmaps::navmap->new();  
     if (defined($navmap)) {  
         my %allresponses;  
         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {  
             my %responses = $res->responseTypes();  
             foreach my $key (keys(%responses)) {  
                 next unless(exists($checkresponsetypes{$key}));  
                 $allresponses{$key} += $responses{$key};  
             }  
         }  
         foreach my $key (keys(%allresponses)) {  
             my ($major,$minor) = split(/\./,$checkresponsetypes{$key});  
             if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {  
                 ($reqdmajor,$reqdminor) = ($major,$minor);  
             }  
         }  
         undef($navmap);  
     }  
     unless (($reqdmajor eq '') && ($reqdminor eq '')) {  
         &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);  
     }  
     return;  
 }  
   
 sub parse_supplemental_title {  
     my ($title) = @_;  
   
     my ($foldertitle,$renametitle);  
     if ($title =~ /&amp;&amp;&amp;/) {  
         $title = &HTML::Entites::decode($title);  
     }  
     if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {  
         $renametitle=$4;  
         my ($time,$uname,$udom) = ($1,$2,$3);  
         $foldertitle=&Apache::lontexconvert::msgtexconverted($4);  
         my $name =  &plainname($uname,$udom);  
         $name = &HTML::Entities::encode($name,'"<>&\'');  
         $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');  
         $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.  
             $name.': <br />'.$foldertitle;  
     }  
     if (wantarray) {  
         return ($title,$foldertitle,$renametitle);  
     }  
     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.15  
changed lines
  Added in v.1.1080


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