--- loncom/interface/londocs.pm 2015/03/24 10:05:45 1.484.2.60 +++ loncom/interface/londocs.pm 2023/09/06 13:35:14 1.484.2.93.2.15 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.60 2015/03/24 10:05:45 raeburn Exp $ +# $Id: londocs.pm,v 1.484.2.93.2.15 2023/09/06 13:35:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,12 +43,14 @@ use Apache::lonnavdisplay(); use Apache::lonextresedit(); use Apache::lontemplate(); use Apache::lonsimplepage(); +use Apache::loncourserespicker(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; use File::MMagic; use Apache::lonlocal; use Cwd; +use UUID::Tiny ':std'; use LONCAPA qw(:DEFAULT :match); my $iconpath; @@ -85,7 +87,7 @@ sub storemap { if ($map =~ /^default/) { $hadchanges=1; - } else { + } elsif ($contentchg) { $suppchanges=1; } return ($errtext,0); @@ -139,7 +141,101 @@ sub clean { return $title; } +sub default_folderpath { + my ($coursenum,$coursedom,$navmapref) = @_; + return unless ($coursenum && $coursedom && ref($navmapref)); +# Check if entire course is hidden and/or encrypted + my ($hiddenmap,$encryptmap,$folderpath,$hiddentop); + my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence"; + unless (ref($$navmapref)) { + $$navmapref = Apache::lonnavmaps::navmap->new(); + } + if (ref($$navmapref)) { + if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') { + my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) }; + my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1); + unless (@resources) { + $hiddenmap = 1; + unless ($env{'request.role.adv'}) { + $hiddentop = 1; + if ($env{'form.folder'}) { + undef($env{'form.folder'}); + } + } + } + } + if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') { + $encryptmap = 1; + } + } + unless ($hiddentop) { + $folderpath='default&'.&escape(&mt('Main Content')). + '::'.$hiddenmap.':'.$encryptmap.'::'; + } + if (wantarray) { + return ($folderpath,$hiddentop); + } else { + return $folderpath; + } +} +sub validate_supppath { + my ($coursenum,$coursedom) = @_; + my $backto; + if ($env{'form.supppath'} ne '') { + my @items = split(/\&/,$env{'form.supppath'}); + my ($badpath,$got_supp,$supppath,%supphidden,%suppids); + for (my $i=0; $i<@items; $i++) { + my $odd = $i%2; + if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { + $badpath = 1; + last; + } elsif ($odd) { + my $suffix; + my $idx = $i-1; + if ($items[$i] =~ /^([^:]*)::(|1):::$/) { + $backto .= '&'.$1; + } elsif ($items[$idx] eq 'supplemental') { + $backto .= '&'.$items[$i]; + } else { + $backto .= '&'.$items[$i]; + my $is_hidden; + unless ($got_supp) { + my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); + if (ref($supplemental) eq 'HASH') { + if (ref($supplemental->{'hidden'}) eq 'HASH') { + %supphidden = %{$supplemental->{'hidden'}}; + } + if (ref($supplemental->{'ids'}) eq 'HASH') { + %suppids = %{$supplemental->{'ids'}}; + } + } + $got_supp = 1; + } + if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') { + my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0]; + if ($supphidden{$mapid}) { + $is_hidden = 1; + } + } + $suffix = '::'.$is_hidden.':::'; + } + $supppath .= '&'.$items[$i].$suffix; + } else { + $supppath .= '&'.$items[$i]; + $backto .= '&'.$items[$i]; + } + } + if ($badpath) { + delete($env{'form.supppath'}); + } else { + $supppath =~ s/^\&//; + $backto =~ s/^\&//; + $env{'form.supppath'} = $supppath; + } + } + return $backto; +} sub dumpcourse { my ($r) = @_; @@ -586,7 +682,7 @@ sub recurse_html { } sub group_import { - my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_; + my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_; my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap, %removeparam,$importuploaded,$fixuperrors); $allmaps = {}; @@ -615,6 +711,166 @@ sub group_import { } } if ($url) { + if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) { + $url = $1; + my $marker = $2; + my $info = $3; + my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings); + my @extras = ('linktext','explanation','crslabel','crstitle','crsappend'); + my @toolinfo = split(/:/,$info); + if ($residx) { + %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); + $toolid = $toolsettings{'id'}; + } else { + $toolid = shift(@toolinfo); + } + if ($toolid =~ /^c/) { + $tooltype = 'crs'; + $toolprefix = 'c'; + } else { + $tooltype = 'dom'; + } + $toolid =~ s/\D//g; + ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}, + $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'}, + $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo; + foreach my $item (@extras) { + $toolhash{$item} = &unescape($toolhash{$item}); + } + if ($folder =~ /^supplemental/) { + delete($toolhash{'gradable'}); + } else { + $toolhash{'gradable'} =~ s/\D+//g; + } + if (ref($ltitoolsref) eq 'HASH') { + if (ref($ltitoolsref->{$tooltype}) eq 'HASH') { + if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') { + my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}}; + my @deleted; + $toolhash{'id'} = $toolprefix.$toolid; + if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') || + ($toolhash{'target'} eq 'window')) { + if ($toolhash{'target'} eq 'window') { + foreach my $item ('width','height') { + $toolhash{$item} =~ s/^\s+//; + $toolhash{$item} =~ s/\s+$//; + if ($toolhash{$item} =~ /\D/) { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } + } + } + } elsif ($residx) { + $toolhash{'target'} = $toolsettings{'target'}; + if ($toolhash{'target'} eq 'window') { + foreach my $item ('width','height') { + $toolhash{$item} = $toolsettings{$item}; + } + } + } elsif (ref($tools{'display'}) eq 'HASH') { + $toolhash{'target'} = $tools{'display'}{'target'}; + if ($toolhash{'target'} eq 'window') { + $toolhash{'width'} = $tools{'display'}{'width'}; + $toolhash{'height'} = $tools{'display'}{'height'}; + } + } + if ($toolhash{'target'} eq 'iframe') { + foreach my $item ('width','height','linktext','explanation') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } + } elsif ($toolhash{'target'} eq 'tab') { + foreach my $item ('width','height') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } + } + if (ref($tools{'crsconf'}) eq 'HASH') { + foreach my $item ('label','title','linktext','explanation') { + my $crsitem; + if (($item eq 'label') || ($item eq 'title')) { + $crsitem = 'crs'.$item; + } else { + $crsitem = $item; + } + if ($tools{'crsconf'}{$item}) { + $toolhash{$crsitem} =~ s/^\s+//; + $toolhash{$crsitem} =~ s/\s+$//; + if ($toolhash{$crsitem} eq '') { + delete($toolhash{$crsitem}); + } + } else { + delete($toolhash{$crsitem}); + } + if (($residx) && (exists($toolsettings{$crsitem}))) { + unless (exists($toolhash{$crsitem})) { + push(@deleted,$crsitem); + } + } + } + } + if ($toolhash{'passback'}) { + my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4); + $toolhash{'gradesecret'} = $gradesecret; + $toolhash{'gradesecretdate'} = time; + } + if ($toolhash{'roster'}) { + my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4); + $toolhash{'rostersecret'} = $rostersecret; + $toolhash{'rostersecretdate'} = time; + } + my $changegradable; + if (($residx) && ($folder =~ /^default/)) { + if ($toolsettings{'gradable'}) { + unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) { + push(@deleted,'gradable'); + $changegradable = 1; + } + } elsif ($toolhash{'gradable'}) { + $changegradable = 1; + } + if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) { + $changegradable = 1; + if ($toolsettings{'gradable'}) { + $toolhash{'gradable'} = 1; + } + } + } + my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum); + if ($putres eq 'ok') { + if (@deleted) { + &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum); + } + if (($changegradable) && ($folder =~ /^default/)) { + my $val; + if ($toolhash{'gradable'}) { + $val = 'yes'; + } else { + $val = 'no'; + } + &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val, + 'string_yesno'); + &remember_parms($residx,'gradable','set',$val); + } + } else { + return (&mt('Failed to save update to external tool.'),1); + } + } + } + } + } if (($caller eq 'londocs') && ($folder =~ /^default/)) { if (($url =~ /\.(page|sequence)$/) && (!$donechk)) { @@ -626,8 +882,8 @@ sub group_import { $donechk = 1; } if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) { - &contained_map_check($url,$folder,\%removefrommap,\%removeparam, - \%addedmaps,\%hierarchy,\%titles,$allmaps); + &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap, + \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps); $importuploaded = 1; } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) { next if ($allmaps->{$url}); @@ -640,26 +896,27 @@ sub group_import { } my $ext = 'false'; if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } - $name = &LONCAPA::map::qtunescape($name); - if ($name eq '') { - $name = &LONCAPA::map::qtunescape(&mt('Web Page')); - } if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) { my $filepath = $1; - my $fname = $name; - if ($fname =~ /^\W+$/) { + my $fname; + if ($name eq '') { + $name = &mt('Web Page'); $fname = 'web'; } else { - $fname =~ s/\W/_/g; - } - if (length($fname > 15)) { - $fname = substr($fname,0,14); + $fname = $name; + $fname=&Apache::lonnet::clean_filename($fname); + if ($fname eq '') { + $fname = 'web'; + } elsif (length($fname) > 15) { + $fname = substr($fname,0,14); + } } + my $title = &Apache::loncommon::cleanup_html($name); my $initialtext = &mt('Replace with your own content.'); my $newhtml = < -$name +$title $initialtext @@ -681,6 +938,7 @@ END return (&mt('Failed to save new web page.'),1); } } + $name = &LONCAPA::map::qtunescape($name); $url = &LONCAPA::map::qtunescape($url); $LONCAPA::map::resources[$residx] = join(':', ($name, $url, $ext, 'normal', 'res')); @@ -721,7 +979,6 @@ END &storemap($coursenum, $coursedom, $folder.'.'.$container,1); unless ($fatal) { if ($folder =~ /^supplemental/) { - &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); my ($errtext,$fatal) = &mapread($coursenum,$coursedom, $folder.'.'.$container); } @@ -791,12 +1048,14 @@ sub log_docs { } sub docs_change_log { - my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_; + my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_; my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/); + my $navmap; my $js = ''."\n". -'
'. +''. '

'. &mt($message,' "/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}", + text=>'Results', + faq=>273, + bug=>'Instructor Interface'}); + &verifycontent($r,$env{'form.checkstale'}); + } else { + &contentverifyform($r); + } } elsif ($allowed && $env{'form.listsymbs'}) { &init_breadcrumbs('listsymbs','List Content IDs'); &list_symbs($r); + } elsif ($allowed && $env{'form.shorturls'}) { + &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs'); + &short_urls($r,$canedit); } elsif ($allowed && $env{'form.docslog'}) { &init_breadcrumbs('docslog','Show Log'); my $folder = $env{'form.folder'}; if ($folder eq '') { $folder='default'; } - &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath); + &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit); } elsif ($allowed && $env{'form.versions'}) { &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions'); - &checkversions($r); - } elsif ($allowed && $env{'form.dumpcourse'}) { + &checkversions($r,$canedit); + } elsif ($canedit && $env{'form.dumpcourse'}) { &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space'); &dumpcourse($r); } elsif ($allowed && $env{'form.exportcourse'}) { @@ -4575,10 +5895,30 @@ sub handler { # Get the parameters that may be needed # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['folderpath', + ['folderpath','title', 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); + foreach my $item ('forcesupplement','forcestandard','tools') { + next if ($env{'form.'.$item} eq ''); + unless ($env{'form.'.$item} eq '1') { + delete($env{'form.'.$item}); + } + } + + if ($env{'form.command'}) { + unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) { + delete($env{'form.command'}); + } + } + + if ($env{'form.symb'}) { + my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'}); + unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { + delete($env{'form.symb'}); + } + } + # standard=1: this is a "new-style" course with an uploaded map as top level # standard=2: this is a "old-style" course, and there is nothing we can do @@ -4601,33 +5941,46 @@ sub handler { my $toolsflag=0; if ($env{'form.tools'}) { $toolsflag=1; } + if ($env{'form.folderpath'} ne '') { + &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom); + } + + my $backto_supppath; + if ($env{'form.supppath'} ne '') { + if ($supplementalflag && $allowed) { + $backto_supppath = &validate_supppath($coursenum,$coursedom); + } + } + my $script=''; my $showdoc=0; my $addentries = {}; my $container; my $containertag; my $pathitem; + my %ltitools; + my $posslti; + my $hiddentop; + my $navmap; + my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) }; # Do we directly jump somewhere? - if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) { if ($env{'form.symb'} ne '') { $env{'form.folderpath'}= - &Apache::loncommon::symb_to_docspath($env{'form.symb'}); + &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap); &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}.'_'.$env{'form.symb'}}); - } elsif ($env{'form.supppath'} ne '') { + } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) { $env{'form.folderpath'}=$env{'form.supppath'}; &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => - $env{'form.command'}.'_'.$env{'form.supppath'}}); + $env{'form.command'}.'_'.$backto_supppath}); } } elsif ($env{'form.command'} eq 'editdocs') { - $env{'form.folderpath'} = 'default&'. - &escape(&mt('Main Content').':::::'); + $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap); &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}}); } elsif ($env{'form.command'} eq 'editsupp') { - $env{'form.folderpath'} = 'supplemental&'. - &escape('Supplemental Content'); + $env{'form.folderpath'} = &supplemental_base(); &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'}); } elsif ($env{'form.command'} eq 'contents') { &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'}); @@ -4646,9 +5999,19 @@ sub handler { if ((!$env{'form.folderpath'}) && $allowed) { &Apache::loncommon::restore_course_settings($stored_folderpath, {'folderpath' => 'scalar'}); - unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) { + + if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) { + if ($supplementalflag) { + undef($env{'form.folderpath'}) if ($1 eq 'default'); + } else { + undef($env{'form.folderpath'}) if ($1 eq 'supplemental'); + } + } else { undef($env{'form.folderpath'}); } + if ($env{'form.folderpath'} ne '') { + &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom); + } } # If we are not allowed to make changes, all we can see are supplemental docs @@ -4663,19 +6026,101 @@ sub handler { .'&'. $env{'form.folderpath'}; } +# If allowed and user's role is not advanced check folderpath is not hidden + my $hidden_and_empty; + if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) { + my ($folderurl,$foldername,$hiddenfolder); + my @pathitems = split(/\&/,$env{'form.folderpath'}); + my $folder = $pathitems[-2]; + if ($folder eq '') { + undef($env{'form.folderpath'}); + } else { + $folderurl = "uploaded/$coursedom/$coursenum/$folder"; + if ((split(/\:/,$pathitems[-1]))[5]) { + $folderurl .= '.page'; + } else { + $folderurl .= '.sequence'; + } + if ($supplementalflag) { + ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/); + $foldername = &HTML::Entities::decode(&unescape($foldername)); + my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); + if (ref($supplemental) eq 'HASH') { + my ($suppmap,$suppmapnum); + if ($folder eq 'supplemental') { + $suppmap = 'default'; + $suppmapnum = 0; + } elsif ($folder =~ /^supplemental_(\d+)$/) { + $suppmap = $1; + $suppmapnum = $suppmap; + } + if ($hiddenfolder) { + my $hascontent; + foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) { + if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) { + $hascontent = 1; + } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') { + foreach my $id (@{$supplemental->{'ids'}->{$key}}) { + if ($id =~ /^$suppmapnum\:/) { + $hascontent = 1; + last; + } + } + } + last if ($hascontent); + } + unless ($hascontent) { + if ($foldername ne '') { + $hidden_and_empty = $foldername; + } else { + $hidden_and_empty = $folder; + } + } + } + } + } else { + unless (ref($navmap)) { + $navmap = Apache::lonnavmaps::navmap->new(); + } + ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/); + $foldername = &HTML::Entities::decode(&unescape($foldername)); + if (ref($navmap)) { + if ($hiddenfolder || + (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) { + my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1); + unless (@resources) { + if ($foldername ne '') { + $hidden_and_empty = $foldername; + } else { + $hidden_and_empty = $folder; + } + } + } + } + } + if ($hidden_and_empty ne '') { + splice(@pathitems,-2); + if (@pathitems) { + $env{'form.folderpath'} = join('&',@pathitems); + } else { + undef($env{'form.folderpath'}); + } + } + } + } + # If after all of this, we still don't have any paths, make them unless ($env{'form.folderpath'}) { if ($supplementalflag) { $env{'form.folderpath'}=&supplemental_base(); - } else { - $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'). - ':::::'); + } elsif ($allowed) { + ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap); } } # Store this unless ($toolsflag) { - if ($allowed) { + if (($allowed) && ($env{'form.folderpath'} ne '')) { &Apache::loncommon::store_course_settings($stored_folderpath, {'folderpath' => 'scalar'}); } @@ -4693,8 +6138,12 @@ sub handler { } else { if ($env{'form.folder'} eq '' || $env{'form.folder'} eq 'supplemental') { - $folderpath='default&'. - &escape(&mt('Main Content').':::::'); + if ($env{'form.folder'} eq 'supplemental') { + $folderpath=&supplemental_base(); + } elsif (!$hiddentop) { + $folderpath='default&'. + &escape(&mt('Main Content').':::::'); + } } } $containertag = ''; @@ -4705,7 +6154,7 @@ sub handler { if ($showdoc) { # got called in sequence from course $allowed=0; } else { - if ($allowed) { + if ($canedit) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']); $script=&Apache::lonratedt::editscript('simple'); } @@ -4744,13 +6193,34 @@ sub handler { } } my $tabidstr = join("','",@tabids); - $script .= &editing_js($udom,$uname,$supplementalflag). + my (%domtools,%crstools); + my %tooltypes = &Apache::loncommon::usable_exttools(); + if ($tooltypes{'dom'}) { + %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer'); + } + if ($tooltypes{'crs'}) { + %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer'); + } + %ltitools = ( + dom => \%domtools, + crs => \%crstools, + ); + $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools)); + my $hostname = $r->hostname(); + $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, + $canedit,$hostname,\$navmap). &history_tab_js(). &inject_data_js(). &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid). - &Apache::lonextresedit::extedit_javascript(); + &Apache::lonextresedit::extedit_javascript(\%ltitools); + my $onload = "javascript:resize_scrollbox('contentscroll','1','1');"; + if ($hidden_and_empty ne '') { + my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'", + $hidden_and_empty); + $onload .= "javascript:alert('".&js_escape($alert)."');"; + } $addentries = { - onload => "javascript:resize_scrollbox('contentscroll','1','1');", + onload => $onload, }; } $script .= &paste_popup_js(); @@ -4764,43 +6234,76 @@ sub handler { .'// '."\n" - .''."\n"; + .''."\n" + .''."\n"; # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); if ($showdoc) { - $r->print(&Apache::loncommon::start_page("$crstype documents",undef, - {'force_register' => $showdoc,})); + my $args; + if ($supplementalflag) { + my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&'); + my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); + $args = {'bread_crumbs' => $brcrum}; + } else { + $args = {'force_register' => $showdoc}; + } + $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args)); } elsif ($toolsflag) { + my ($breadtext,$breadtitle); + $breadtext = "$crstype Editor"; + if ($canedit) { + $breadtitle = 'Editing '.$crstype.' Contents'; + } else { + $breadtext .= ' (View-only mode)'; + $breadtitle = 'Viewing '.$crstype.' Contents'; + } &Apache::lonhtmlcommon::add_breadcrumb({ - href=>"/adm/coursedocs",text=>"$crstype Contents"}); + href=>"/adm/coursedocs",text=>$breadtext}); $r->print(&Apache::loncommon::start_page("$crstype Contents", $script) .&Apache::loncommon::help_open_menu('','',273,'RAT') .&Apache::lonhtmlcommon::breadcrumbs( - 'Editing Course Contents') + $breadtitle) ); } elsif ($r->uri eq '/adm/supplemental') { + unless ($env{'request.role.adv'}) { + unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) { + $r->internal_redirect('/adm/navmaps'); + return OK; + } + } my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype); $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef, {'bread_crumbs' => $brcrum,})); } else { + my ($breadtext,$breadtitle,$helpitem); + $breadtext = "$crstype Editor"; + if ($canedit) { + $breadtitle = 'Editing '.$crstype.' Contents'; + $helpitem = 'Docs_Adding_Course_Doc'; + } else { + $breadtext .= ' (View-only mode)'; + $breadtitle = 'Viewing '.$crstype.' Contents'; + $helpitem = 'Docs_Viewing_Course_Doc'; + } &Apache::lonhtmlcommon::add_breadcrumb({ - href=>"/adm/coursedocs",text=>"$crstype Contents"}); + href=>"/adm/coursedocs",text=>$breadtext}); $r->print(&Apache::loncommon::start_page("$crstype Contents", $script, {'add_entries' => $addentries} ) .&Apache::loncommon::help_open_menu('','',273,'RAT') .&Apache::lonhtmlcommon::breadcrumbs( - 'Editing '.$crstype.' Contents', - 'Docs_Adding_Course_Doc') + $breadtitle, + $helpitem) ); } my %allfiles = (); my %codebase = (); my ($upload_result,$upload_output,$uploadphase); - if ($allowed) { + if ($canedit) { + undef($suppchanges); if (($env{'form.uploaddoc.filename'}) && ($env{'form.cmd'}=~/^upload_(\w+)/)) { my $context = $1; @@ -4808,9 +6311,14 @@ sub handler { undef($hadchanges); $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom, \%allfiles,\%codebase,$context,$crstype); + undef($navmap); if ($hadchanges) { &mark_hash_old(); } + if ($suppchanges) { + &Apache::lonnet::update_supp_caches($coursedom,$coursenum); + undef($suppchanges); + } $r->print($upload_output); } elsif ($env{'form.phase'} eq 'upload_embedded') { # Process file upload - phase two - upload embedded objects @@ -4852,7 +6360,7 @@ sub handler { if ($allowed && $toolsflag) { $r->print(&startContentScreen('tools')); - $r->print(&generate_admin_menu($crstype)); + $r->print(&generate_admin_menu($crstype,$canedit)); $r->print(&endContentScreen()); } elsif ((!$showdoc) && (!$uploadphase)) { # ----------------------------------------------------------------------------- @@ -4864,6 +6372,8 @@ sub handler { 'impo' => 'Import', 'lnks' => 'Import from Stored Links', 'impm' => 'Import from Assembled Map', + 'extr' => 'External Resource', + 'extt' => 'External Tool', 'selm' => 'Select Map', 'load' => 'Load Map', 'newf' => 'New Folder', @@ -4892,19 +6402,51 @@ sub handler { 'bb6' => 'Blackboard 6', 'angel5' => 'ANGEL 5.5', 'webctce4' => 'WebCT 4 Campus Edition', + 'er' => 'Editing rights unavailable for your current role.', ); # ----------------------------------------------------------------------------- + # Calculate free quota space for a user or course. A javascript function checks + # file size to determine if upload should be allowed. + my $quotatype = 'unofficial'; + if ($crstype eq 'Community') { + $quotatype = 'community'; + } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) { + $quotatype = 'official'; + } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) { + $quotatype = 'textbook'; + } + my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom, + 'course',$quotatype); # expressed in MB + my $current_disk_usage = 0; + foreach my $subdir ('docs','supplemental') { + $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum, + "userfiles/$subdir",1); # expressed in kB + } + my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage); + my $usage = $current_disk_usage/1024; # in MB + my $quota = $disk_quota; + my $percent; + if ($disk_quota == 0) { + $percent = 100.0; + } else { + $percent = 100*($usage/$disk_quota); + } + $usage = sprintf("%.2f",$usage); + $quota = sprintf("%.2f",$quota); + $percent = sprintf("%.0f",$percent); + my $quotainfo = '

'.&mt('Currently using [_1] of the [_2] available.', + $percent.'%',$quota.' MB').'

'; + my $fileupload=(< - FIUP - my $checkbox=(<$lt{'parse'}? --> CHBO my $imsfolder = $env{'form.folder'}; @@ -4918,10 +6460,12 @@ CHBO IMSFORM @@ -4944,9 +6488,11 @@ IMSFORM $lt{'upfi'} $fileupload + +
$lt{'title'}:
- + $pathitem
@@ -4954,11 +6500,17 @@ IMSFORM $checkbox
- + FUFORM + my $mapimportjs; + if ($canedit) { + $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; + } else { + $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');"; + } my $importpubform=(< $lt{'impm'}$help{'Load_Map'} @@ -4969,31 +6521,47 @@ FUFORM $lt{'copm'}
-  $lt{'selm'}
- + onfocus="this.blur();$mapimportjs" $disabled /> +  $lt{'selm'}
+ SEDFFORM + + my $fromstoredjs; + if ($canedit) { + $fromstoredjs = 'open_StoredLinks_Import()'; + } else { + $fromstoredjs = "alert('".&js_escape($lt{'er'})."')"; + } + my @importpubforma = ( { ''.$lt{srch}.'' => $pathitem."$lt{'srch'}" }, { ''.$lt{impo}.'' => "$lt{'impo'}$help{'Importing_LON-CAPA_Resource'}" }, - { ''.$lt{lnks}.'' => "$lt{'lnks'}" }, + { ''.$lt{lnks}.'' => ''.$lt{'lnks'}.'' }, { ''.$lt{impm}.'' => $importpubform } ); $importpubform = &create_form_ul(&create_list_elements(@importpubforma)); my $extresourcesform = &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem, - $help{'Adding_External_Resource'}); + $help{'Adding_External_Resource'}, + undef,undef,undef,undef,undef,undef,$disabled); + my $exttoolform = + &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem, + $help{'Adding_External_Tool'},undef, + undef,'tool',$coursedom,$coursenum, + \%ltitools,$disabled); if ($allowed) { my $folder = $env{'form.folder'}; if ($folder eq '') { $folder='default'; } - my $output = &update_paste_buffer($coursenum,$coursedom,$folder); - if ($output) { - $r->print($output); + if ($canedit) { + my $output = &update_paste_buffer($coursenum,$coursedom,$folder); + if ($output) { + $r->print($output); + } } $r->print(< @@ -5027,10 +6595,11 @@ HIDDENFORM # my $savefolderpath; + my $hostname = $r->hostname(); if ($allowed) { my $folder=$env{'form.folder'}; - if ($folder eq '' || $supplementalflag) { + if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) { $folder='default'; $savefolderpath = $env{'form.folderpath'}; $env{'form.folderpath'}='default&'.&escape(&mt('Main Content')); @@ -5039,9 +6608,13 @@ HIDDENFORM } my $postexec=''; if ($folder eq 'default') { + my $windowname = 'loncapaclient'; + if ($env{'request.lti.login'}) { + $windowname .= 'lti'; + } $r->print(''."\n" ); @@ -5058,7 +6631,7 @@ HIDDENFORM $pathitem - $lt{'navc'} + $lt{'navc'} $help{'Navigate_Content'} NNFORM @@ -5119,7 +6692,7 @@ NBFORM $pathitem - $lt{'mypi'} + $lt{'mypi'} $help{'My Personal Information Page'} NAMFORM @@ -5139,7 +6712,7 @@ NASOFORM $pathitem - $lt{'rost'} + $lt{'rost'} $help{'Course_Roster'} NROSTFORM @@ -5202,7 +6775,7 @@ NFFORM $pathitem - $lt{'syll'} + $lt{'syll'} $help{'Syllabus'} @@ -5214,23 +6787,34 @@ NSYLFORM $pathitem - $lt{'grpo'} + $lt{'grpo'} $help{'Group Portfolio'} NGFFORM - @specialdocumentsforma=( + if ($container eq 'page') { + @specialdocumentsforma=( + {''.$lt{webp}.''=>$newwebpageform}, + ); + } else { + @specialdocumentsforma=( {''.$lt{newp}.''=>$newpageform}, - {''.$lt{syll}.''=>$newsylform}, - {''.$lt{navc}.''=>$newnavform}, + {''.$lt{syll}.''=>$newsylform}, + {''.$lt{navc}.''=>$newnavform}, {''.$lt{sipa}.''=>$newsmppageform}, {''.$lt{webp}.''=>$newwebpageform}, - ); + ); + } $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma)); my @importdoc = ( {''.$lt{extr}.''=>$extresourcesform} ); + if ($posslti) { + push(@importdoc, + {''.$lt{extt}.''=>$exttoolform}, + ); + } unless ($container eq 'page') { push(@importdoc, {''.$lt{imsf}.''=>$imspform} @@ -5253,8 +6837,8 @@ NGFFORM {''.$lt{bull}.''=>$newbulform}, {''.$lt{mypi}.''=>$newaboutmeform}, {''.$lt{abou}.''=>$newaboutsomeoneform}, - {''.$lt{rost}.''=>$newrosterform}, - {''.$lt{grpo}.''=>$newgroupfileform}, + {''.$lt{rost}.''=>$newrosterform}, + {''.$lt{grpo}.''=>$newgroupfileform}, ); $communityform = &create_form_ul(&create_list_elements(@communityforma)); @@ -5262,22 +6846,26 @@ my %orderhash = ( 'aa' => ['Upload',$fileuploadform], 'bb' => ['Import',$importpubform], 'cc' => ['Grading',$gradingform], + 'ee' => ['Other',$specialdocumentsform], ); unless ($container eq 'page') { $orderhash{'00'} = ['Newfolder',$newfolderform]; $orderhash{'dd'} = ['Collaboration',$communityform]; - $orderhash{'ee'} = ['Other',$specialdocumentsform]; } $hadchanges=0; unless (($supplementalflag || $toolsflag)) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,\%orderhash,$iconpath,$pathitem); + $supplementalflag,\%orderhash,$iconpath,$pathitem, + \%ltitools,$canedit,$hostname,\$navmap,$hiddentop); + undef($navmap); if ($error) { $r->print('

'.$error.'

'); } if ($hadchanges) { - &mark_hash_old(); + unless (&is_hash_old()) { + &mark_hash_old(); + } } &changewarning($r,''); @@ -5290,7 +6878,7 @@ unless ($container eq 'page') { unless ($supplementalflag) { $folder='supplemental'; } - if ($folder =~ /^supplemental$/ && + if (($folder eq 'supplemental') && (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) { $env{'form.folderpath'} = &supplemental_base(); } elsif ($allowed) { @@ -5310,6 +6898,8 @@ unless ($container eq 'page') { $lt{'upfi'} $fileupload + +

@@ -5322,6 +6912,7 @@ unless ($container eq 'page') { $pathitem + SUPDOCFORM @@ -5337,7 +6928,13 @@ SNFFORM my $supextform = &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, - $help{'Adding_External_Resource'}); + $help{'Adding_External_Resource'}, + undef,undef,$disabled); + my $supexttoolform = + &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, + $help{'Adding_External_Tool'}, + undef,undef,'tool',$coursedom, + $coursenum,\%ltitools,$disabled); my $supnewsylform=(< @@ -5345,7 +6942,7 @@ SNFFORM $pathitem - $lt{'syll'} + $lt{'syll'} $help{'Syllabus'} SNSFORM @@ -5356,7 +6953,7 @@ SNSFORM $pathitem - $lt{'mypi'} + $lt{'mypi'} $help{'My Personal Information Page'} SNAMFORM @@ -5383,19 +6980,25 @@ SWEBFORM my @specialdocs = ( - {''.$lt{syll}.'' + {''.$lt{syll}.'' =>$supnewsylform}, - {''.$lt{mypi}.'' + {''.$lt{mypi}.'' =>$supnewaboutmeform}, {''.$lt{webp}.''=>$supwebpageform}, ); my @supimportdoc = ( {''.$lt{extr}.'' - =>$supextform}, + =>$supextform}); + if (keys(%ltitools)) { + push(@supimportdoc, + {''.$lt{extt}.'' + =>$supexttoolform}); + } + push(@supimportdoc, {''.$lt{upl}.'' =>$supupdocform}, - ); + ); $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)); my %suporderhash = ( @@ -5404,28 +7007,22 @@ my %suporderhash = ( 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))] ); if ($supplementalflag) { - my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,\%suporderhash,$iconpath,$pathitem); - if ($error) { - $r->print('

'.$error.'

'); - } else { - if ($suppchanges) { - my %servers = &Apache::lonnet::internet_dom_servers($coursedom); - my @ids=&Apache::lonnet::current_machine_ids(); - foreach my $server (keys(%servers)) { - next if (grep(/^\Q$server\E$/,@ids)); - my $hashid=$coursenum.':'.$coursedom; - my $cachekey = &escape('suppcount').':'.&escape($hashid); - &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]); - } - &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); - undef($suppchanges); - } - } + $suppchanges = 0; + my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, + $supplementalflag,\%suporderhash,$iconpath,$pathitem, + \%ltitools,$canedit,$hostname); + if ($error) { + $r->print('

'.$error.'

'); + } + if ($suppchanges) { + &Apache::lonnet::update_supp_caches($coursedom,$coursenum); + undef($suppchanges); + } } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem); + $supplementalflag,'',$iconpath,$pathitem,'',$canedit, + $hostname); if ($error) { $r->print('

'.$error.'

'); } @@ -5459,6 +7056,7 @@ my %suporderhash = ( sub embedded_form_elems { my ($phase,$primaryurl,$newidx) = @_; my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); + $newidx =~s /\D+//g; return < @@ -5479,7 +7077,11 @@ sub embedded_destination { } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) { $destination .= $2.'/'; } - $destination .= $env{'form.newidx'}; + my $newidx = $env{'form.newidx'}; + $newidx =~s /\D+//g; + if ($newidx) { + $destination .= $newidx; + } my $dir_root = '/userfiles'; return ($destination,$dir_root); } @@ -5505,6 +7107,9 @@ sub decompression_info { } unshift(@hiddens,$pathitem); foreach my $item (@hiddens) { + if ($item eq 'newidx') { + next if ($env{'form.'.$item} =~ /\D/); + } if ($env{'form.'.$item}) { $hiddenelem .= ''."\n"; @@ -5579,6 +7184,10 @@ sub remove_archive { if ($url eq $env{'form.archiveurl'}) { if (&handle_edit_cmd($docuname,$docudom)) { ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1); + if ($suppchanges) { + &Apache::lonnet::update_supp_caches($docudom,$docuname); + undef($suppchanges); + } if ($fatal) { if ($container eq 'page') { $delwarning = &mt('An error occurred updating the contents of the current page.'); @@ -5610,13 +7219,14 @@ sub remove_archive { } sub generate_admin_menu { - my ($crstype) = @_; + my ($crstype,$canedit) = @_; my $lc_crstype = lc($crstype); my ($home,$other,%outhash)=&authorhosts(); my %lt= ( # do not translate here 'vc' => 'Verify Content', 'cv' => 'Check/Set Resource Versions', 'ls' => 'List Resource Identifiers', + 'ct' => 'Display/Set Shortened URLs for Deep-linking', 'imse' => 'Export contents to IMS Archive', 'dcd' => "Copy $crstype Content to Authoring Space", ); @@ -5667,8 +7277,17 @@ sub generate_admin_menu { icon => 'symbs.png', linktitle => "List the unique identifier used for each resource instance in your $lc_crstype" }, + { linktext => $lt{'ct'}, + url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')", + permission => 'F', + help => 'Docs_Short_URLs', + icon => 'shorturls.png', + linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking" + }, ] - }, + }); + if ($canedit) { + push(@menu, { categorytitle=>'Export', items =>[ { linktext => $lt{'imse'}, @@ -5687,6 +7306,7 @@ sub generate_admin_menu { }, ] }); + } return '
'."\n". ''."\n". &Apache::lonhtmlcommon::generate_menu(@menu)."\n". @@ -5695,15 +7315,16 @@ sub generate_admin_menu { sub generate_edit_table { my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile, - $need_save,$copyfolder) = @_; + $need_save,$copyfolder,$canedit) = @_; return unless(ref($orderhash_ref) eq 'HASH'); my %orderhash = %{$orderhash_ref}; - my $form; - my $activetab; - my $active; + my ($form, $activetab, $active, $disabled); if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) { $activetab = $env{'form.active'}; } + unless ($canedit) { + $disabled = ' disabled="disabled"'; + } my $backicon = $iconpath.'clickhere.gif'; my $backtext = &mt('Exit Editor'); $form = '
'. @@ -5767,7 +7388,7 @@ sub generate_edit_table { - +
END @@ -5793,8 +7414,9 @@ END } sub editing_js { - my ($udom,$uname,$supplementalflag) = @_; - my %lt = &Apache::lonlocal::texthash( + my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, + $canedit,$hostname,$navmapref) = @_; + my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', p_mnp => 'Name of New Page', @@ -5811,16 +7433,18 @@ sub editing_js { p_mab_alrt2 => 'Please enter both user and domain in the format user:domain', p_chn => 'New Title', p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!', - p_rmr2a => 'Remove[_99]', - p_rmr2b => '?[_99]', - p_rmr3a => 'Remove those [_2]', - p_rmr3b => 'items?[_2]', + p_rmr2a => 'Remove', + p_rmr2b => '?', + p_rmr3a => 'Remove those', + p_rmr3b => 'items?', + p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".', + p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.', p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!', p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.', - p_ctr2a => 'Cut[_98]', - p_ctr2b => '?[_98]', - p_ctr3a => 'Cut those[_2]', - p_ctr3b => 'items?[_2]', + p_ctr2a => 'Cut', + p_ctr2b => '?', + p_ctr3a => 'Cut those', + p_ctr3b => 'items?', rpck => 'Enter number to pick (e.g., 3)', imsfile => 'You must choose an IMS package for import', imscms => 'You must select which Course Management System was the source of the IMS package', @@ -5831,19 +7455,20 @@ sub editing_js { noor => 'No actions selected or changes to settings specified.', noch => 'No changes to settings specified.', noac => 'No actions selected.', + edri => 'Editing rights unavailable for your current role.', ); + &js_escape(\%js_lt); my $crstype = &Apache::loncommon::course_type(); my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"'); my $main_container_page; if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) { $main_container_page = 1; } - my $toplevelmain = - &escape(&mt('Main Content').':::::'); + my $backtourl; + my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref)); my $toplevelsupp = &supplemental_base(); - my $backtourl; if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) { my $caller = $1; if ($caller =~ /^supplemental/) { @@ -5852,8 +7477,46 @@ sub editing_js { my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller); $res = &Apache::lonnet::clutter($res); if (&Apache::lonnet::is_on_map($res)) { - $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='. - &HTML::Entities::encode($caller,'<>&"'); + my ($url,$anchor); + if ($res =~ /^([^#]+)#([^#]+)$/) { + $url = $1; + $anchor = $2; + if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) { + $caller = $1.&escape('#').$anchor; + } + } else { + $url = $res; + } + $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"'); + if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) { + $backtourl .= '?navmap=1'; + } else { + $backtourl .= '?symb='. + &HTML::Entities::encode($caller,'<>&"'); + } + if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } + } + } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { + if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } + } + } + if ($anchor ne '') { + $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); + } $backtourl = &Apache::loncommon::escape_single($backtourl); } else { $backtourl = '/adm/navmaps'; @@ -5862,56 +7525,69 @@ sub editing_js { } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') { $backtourl = '/adm/menu'; } elsif ($supplementalflag) { - $backtourl = '/adm/supplemental'; + if (($env{'request.role.adv'}) || + (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) { + $backtourl = '/adm/supplemental'; + } else { + $backtourl = '/adm/navmaps'; + } } else { $backtourl = '/adm/navmaps'; } my $fieldsets = "'ext','doc'"; + if ($posslti) { + $fieldsets .= ",'tool'"; + } unless ($main_container_page) { $fieldsets .=",'ims'"; } if ($supplementalflag) { $fieldsets = "'suppext','suppdoc'"; + if ($posslti) { + $fieldsets .= ",'supptool'"; + } } - return <$lt{'more'}'; + document.getElementById('more'+caller).innerHTML = '  $js_lt{'more'}'; } else { document.getElementById('more'+caller).innerHTML = ''; } @@ -6440,10 +8222,10 @@ function togglePick(caller,value) { function toggleCheckUncheck(caller,more) { if (more == 1) { - document.getElementById('more'+caller).innerHTML = '  $lt{'less'}'; + document.getElementById('more'+caller).innerHTML = '  $js_lt{'less'}'; document.getElementById('allfields'+caller).style.display='block'; } else { - document.getElementById('more'+caller).innerHTML = '  $lt{'more'}'; + document.getElementById('more'+caller).innerHTML = '  $js_lt{'more'}'; document.getElementById('allfields'+caller).style.display='none'; } resize_scrollbox('contentscroll','1','1'); @@ -6485,6 +8267,7 @@ function checkSubmits() { var doactions = multiActions(); var cutwarnings = 0; var remwarnings = 0; + var removalinfo = 0; if (doactions == 1) { var remidxlist = document.cumulativeactions.allremoveidx.value; if ((remidxlist != '') && (remidxlist != null)) { @@ -6499,6 +8282,11 @@ function checkSubmits() { remwarnings ++; } } + if (document.getElementById('confirm_removal_'+remidxs[i])) { + if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) { + removalinfo ++; + } + } } } } @@ -6597,14 +8385,19 @@ function checkSubmits() { } if (doactions == 1) { if (numchanges > 0) { - if ((cutwarnings > 0) || (remwarnings > 0)) { + if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) { if (remwarnings > 0) { - if (!confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr3a"} '+remwarnings+' $lt{"p_rmr3b"}')) { + if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) { + return false; + } + } + if (removalinfo > 0) { + if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) { return false; } } if (cutwarnings > 0) { - if (!confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr3a"} '+cutwarnings+' $lt{"p_ctr3b"}')) { + if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) { return false; } } @@ -6620,12 +8413,12 @@ function checkSubmits() { } } if ((dosettings == 1) && (doactions == 1)) { - alert("$lt{'noor'}"); + alert("$js_lt{'noor'}"); } else { if (dosettings == 1) { - alert("$lt{'noch'}"); + alert("$js_lt{'noch'}"); } else { - alert("$lt{'noac'}"); + alert("$js_lt{'noac'}"); } } return false; @@ -6711,7 +8504,7 @@ function setBoxes(value) { return; } -ENDNEWSCRIPT +ENDSCRIPT } sub history_tab_js { @@ -6740,13 +8533,19 @@ ENDINJECT sub dump_switchserver_js { my @hosts = @_; - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( dump => 'Copying content to Authoring Space requires switching server.', swit => 'Switch server?', + ); + my %html_js_lt = &Apache::lonlocal::texthash( + swit => 'Switch server?', duco => 'Copying Content to Authoring Space', yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.', chos => 'Choose server', ); + &js_escape(\%js_lt); + &html_escape(\%html_js_lt); + &js_escape(\%html_js_lt); my $role = $env{'request.role'}; my $js = <<"ENDSWJS";