--- loncom/interface/londocs.pm 2020/03/05 22:35:58 1.484.2.87 +++ loncom/interface/londocs.pm 2023/07/11 12:44:18 1.700 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.87 2020/03/05 22:35:58 raeburn Exp $ +# $Id: londocs.pm,v 1.700 2023/07/11 12:44:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,12 +43,17 @@ use Apache::lonnavdisplay(); use Apache::lonextresedit(); use Apache::lontemplate(); use Apache::lonsimplepage(); +use Apache::lonhomework(); +use Apache::lonpublisher(); +use Apache::loncourserespicker(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; use File::MMagic; +use File::Copy; use Apache::lonlocal; use Cwd; +use UUID::Tiny ':std'; use LONCAPA qw(:DEFAULT :match); my $iconpath; @@ -85,7 +90,7 @@ sub storemap { if ($map =~ /^default/) { $hadchanges=1; - } else { + } elsif ($contentchg) { $suppchanges=1; } return ($errtext,0); @@ -177,6 +182,64 @@ sub default_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) = @_; my $crstype = &Apache::loncommon::course_type(); @@ -232,7 +295,7 @@ ENDJS } else { &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles, 'dumpdocs',$cdom,$cnum); - } + } my @todump = &Apache::loncommon::get_env_multiple('form.archive'); my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages, %newcontent,%has_simpleprobs); @@ -243,7 +306,7 @@ ENDJS if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) { $tocopy{$1} = $name; $display{$item} = $1; - $lookup{$1} = $item; + $lookup{$1} = $item; } elsif ($res eq 'lib/templates/simpleproblem.problem') { $simpleproblems{$item} = { symb => $resources{$item}, @@ -343,7 +406,7 @@ $contents{content}.' '; } if ($contents{webreferences}) { - $content .= ' + $content .= '

'.&mt('Web References').'

'. $contents{webreferences}.' @@ -353,10 +416,10 @@ $contents{webreferences}.' '; - $newcontent{'/'.$simplepages{$item}{res}} = $content; + $newcontent{'/'.$simplepages{$item}{res}} = $content; } } - foreach my $item (keys(%tocopy)) { + foreach my $item (keys(%tocopy)) { unless ($item=~/\.(sequence|page)$/) { my $currurlpath = $prefix.$item; my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath); @@ -387,39 +450,39 @@ $contents{webreferences}.' if ($simpleproblems{$num}) { $newfilename=$title.'/'.$simpleproblems{$num}{'name'}; } else { - $newfilename=$title.'/'.$replacehash{$item}; + $newfilename=$title.'/'.$replacehash{$item}; } - $newfilename=~s/\.(\w+)$//; - my $ext=$1; - $newfilename=&clean($newfilename); - $newfilename.='.'.$ext; - my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); + $newfilename=~s/\.(\w+)$//; + my $ext=$1; + $newfilename=&clean($newfilename); + $newfilename.='.'.$ext; + my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); if ($newrelpath ne $replacehash{$item}) { $replacehash{$item} = $newrelpath; } - my @dirs=split(/\//,$newfilename); - my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca"; - my $makepath=$path; - my $fail; + my @dirs=split(/\//,$newfilename); + my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca"; + my $makepath=$path; + my $fail; my $origin; - for (my $i=0;$i<$#dirs;$i++) { - $makepath.='/'.$dirs[$i]; - unless (-e $makepath) { - unless(mkdir($makepath,0755)) { + for (my $i=0;$i<$#dirs;$i++) { + $makepath.='/'.$dirs[$i]; + unless (-e $makepath) { + unless(mkdir($makepath,0755)) { $fail = &mt('Directory creation failed.'); } - } - } + } + } if ($i == 0) { - $result = '
'.$item.' => '.$newfilename.': '; + $result = '
'.$item.' => '.$newfilename.': '; } else { $depresult .= '
  • '.$item.' => '.$newfilename.' '. ''. &mt('(dependency)').': '; } if (-e $path.'/'.$newfilename) { - $fail = &mt('Destination already exists -- not overwriting.'); - } else { + $fail = &mt('Destination already exists -- not overwriting.'); + } else { if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) { if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) || ($item =~ /^simpleproblem_/)) { @@ -441,18 +504,18 @@ $contents{webreferences}.' while (my $token = $parser->get_token) { if ($token->[0] eq 'S') { if (($token->[1] eq 'resource') && - ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && + ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && ($changes{$token->[2]->{'id'}})) { my $id = $token->[2]->{'id'}; $updatedcontent .= '<'.$token->[1]; foreach my $attrib (@{$token->[3]}) { - next unless ($attrib =~ /^(src|type|title|id)$/); + next unless ($attrib =~ /^(src|type|title|id)$/); if ($attrib eq 'src') { - my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); + my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); if ($file) { $updatedcontent .= ' '.$attrib.'="'.$file.'"'; } else { - $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; + $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; } } else { $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; @@ -467,36 +530,36 @@ $contents{webreferences}.' } } print $fh $updatedcontent; - } else { - print $fh &Apache::lonclonecourse::rewritefile( + } else { + print $fh &Apache::lonclonecourse::rewritefile( &Apache::lonclonecourse::readfile($env{'request.course.id'},$item), - (%replacehash,$crs => '') - ); + (%replacehash,$crs => '') + ); } } else { - print $fh + print $fh &Apache::lonclonecourse::readfile($env{'request.course.id'},$item); - } + } } else { - $fail = &mt('Source does not exist.'); + $fail = &mt('Source does not exist.'); } } $fh->close(); - } else { - $fail = &mt('Could not write to destination.'); + } else { + $fail = &mt('Could not write to destination.'); } - } + } my $text; - if ($fail) { + if ($fail) { $text = ''.&mt('fail').(' 'x3).$fail.''; - } else { + } else { $text = ''.&mt('ok').''; } if ($i == 0) { $result .= $text; } else { $depresult .= $text.'
  • '; - } + } } $r->print($result); if ($depresult) { @@ -513,63 +576,63 @@ $contents{webreferences}.' $r->rflush(); my ($preamble,$formname); $formname = 'dumpdoc'; - unless ($home==1) { - $preamble = '
    '. - '
    '. + unless ($home==1) { + $preamble = '
    '. + '
    '. &mt('Select the Authoring Space'). ''; - } else { - $preamble .= ''; - } - } - unless ($home==1) { - $preamble .= '
    '."\n"; - } - my $title=$origcrsdata{'description'}; - $title=~s/[\/\s]+/\_/gs; - $title=&clean($title); - $preamble .= '
    '. + if ($home==1) { + $preamble .= ''; + } else { + $preamble .= ''; + } + } + unless ($home==1) { + $preamble .= '
    '."\n"; + } + my $title=$origcrsdata{'description'}; + $title=~s/[\/\s]+/\_/gs; + $title=&clean($title); + $preamble .= '
    '. '
    '.&mt('Folder in Authoring Space').''. ''. '
    '."\n"; my %uploadedfiles; - &tiehash(); - foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { - my ($ext)=($file=~/\.(\w+)$/); + &tiehash(); + foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { + my ($ext)=($file=~/\.(\w+)$/); # FIXME Check supplemental here - my $title=$hash{'title_'.$hash{ - 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}}; - if (!$title) { - $title=$file; - } else { - $title=~s|/|_|g; - } - $title=~s/\.(\w+)$//; - $title=&clean($title); - $title.='.'.$ext; -# $r->print("\n" + my $title=$hash{'title_'.$hash{ + 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}}; + if (!$title) { + $title=$file; + } else { + $title=~s|/|_|g; + } + $title=~s/\.(\w+)$//; + $title=&clean($title); + $title.='.'.$ext; +# $r->print("\n" $uploadedfiles{$file} = $title; - } - &untiehash(); + } + &untiehash(); $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef, undef,undef,$preamble,$home,\%uploadedfiles)); } @@ -600,7 +663,7 @@ sub recurse_html { } else { $relfile = $dependency; $depurl = $currurlpath; - $depurl =~ s{[^/]+$}{}; + $depurl =~ s{[^/]+$}{}; $depurl .= $dependency; ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); } @@ -609,7 +672,7 @@ sub recurse_html { $newname =~ s{[^/]+$}{}; $replacehash->{$newcontainer} = $newname.$relfile; $deps->{$item}{$newcontainer} = 1; - my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$}); + my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$}); my $depfile = &Apache::lonnet::filelocation('',$depurl); my $type = $mm->checktype_filename($depfile); if ($type eq 'text/html') { @@ -622,7 +685,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 = {}; @@ -651,6 +714,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)) { @@ -662,8 +885,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}); @@ -676,26 +899,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 @@ -717,6 +941,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')); @@ -728,7 +953,7 @@ END removefrommap => \%removefrommap, removeparam => \%removeparam, ); - my ($result,$msgsarray,$lockerror) = + my ($result,$msgsarray,$lockerror) = &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated); if (keys(%import_errors) > 0) { $fixuperrors = @@ -757,7 +982,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); } @@ -829,12 +1053,12 @@ sub log_docs { sub docs_change_log { my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_; my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/); - my $navmap; + my $navmap; my $js = ''."\n". -'
    '. +''. '

    '. &mt($message,'     '.&mt('Content Overview').'    '."\n"; $output .= '     '.&mt('Content Search').'     '."\n"; + $output .= '      '.&mt('Content Index').'      '."\n"; $output .= '

  • '.&mt('Supplemental Content').'
  • '; } else { $output .= '
  •       '.&mt('Main Content Editor').'      
  • '."\n"; @@ -5007,18 +5521,21 @@ sub handler { my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'}; my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'}; +# get docroot + my $londocroot = $r->dir_config('lonDocRoot'); + # graphics settings $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/'); # # --------------------------------------------- Initialize help topics for this foreach my $topic ('Adding_Course_Doc','Main_Course_Documents', - 'Adding_External_Resource','Navigate_Content', - 'Adding_Folders','Docs_Overview', 'Load_Map', - 'Supplemental','Score_Upload_Form','Adding_Pages', - 'Importing_LON-CAPA_Resource','Importing_IMS_Course', - 'Uploading_From_Harddrive','Course_Roster','Web_Page', - 'Dropbox','Simple_Problem') { + 'Adding_External_Resource','Adding_External_Tool', + 'Navigate_Content','Adding_Folders','Docs_Overview', + 'Load_Map','Supplemental','Score_Upload_Form', + 'Adding_Pages','Importing_LON-CAPA_Resource', + 'Importing_IMS_Course','Uploading_From_Harddrive', + 'Course_Roster','Web_Page','Dropbox','Simple_Problem') { $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic); } # Composite help files @@ -5033,18 +5550,21 @@ sub handler { $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files'); $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching'); - my ($allowed,$canedit,$canview,$disabled); + my ($allowed,$canedit,$canview,$noendpage,$disabled); +# does this user have privileges to modify content. + if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { # URI is /adm/supplemental when viewing supplemental docs in non-edit mode. - unless ($r->uri eq '/adm/supplemental') { - # does this user have privileges to modify content. - if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { + unless ($r->uri eq '/adm/supplemental') { $allowed = 1; - $canedit = 1; - $canview = 1; - } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) { + } + $canedit = 1; + $canview = 1; + } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) { +# URI is /adm/supplemental when viewing supplemental docs in non-edit mode. + unless ($r->uri eq '/adm/supplemental') { $allowed = 1; - $canview = 1; } + $canview = 1; } unless ($canedit) { $disabled = ' disabled="disabled"'; @@ -5072,6 +5592,9 @@ sub handler { } 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'}; @@ -5085,17 +5608,68 @@ sub handler { } elsif ($canedit && $env{'form.dumpcourse'}) { &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space'); &dumpcourse($r); - } elsif ($allowed && $env{'form.exportcourse'}) { + } elsif ($canedit && $env{'form.exportcourse'}) { &init_breadcrumbs('exportcourse','IMS Export'); &Apache::imsexport::exportcourse($r); } else { + if ($canedit && $env{'form.authorrole'}) { + $noendpage = 1; + my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum); + if ($redirect) { + if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) { + my $container = 'sequence'; + my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain, + $is_random_order,$container) = + &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1); + my (@folders)=split('&',$env{'form.folderpath'}); + $env{'form.foldername'}=&unescape(pop(@folders)); + my $folder=pop(@folders); + my ($errtext,$fatal) = &mapread($coursenum,$coursedom, + $folder.'.'.$container); + my $warning; + if ($fatal) { + if ($container eq 'page') { + $warning = &mt('An error occurred retrieving the contents of the current page.'); + } else { + $warning = &mt('An error occurred retrieving the contents of the current folder.'); + } + } else { + my $url = $redirect; + my $srcfile = $londocroot.$url; + $url =~ s{^/priv/}{/res/}; + my $targetfile = $londocroot.$url; + my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes')); + my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1); + $env{'form.folder'} = $folder; + &snapshotbefore(); + my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'}); + my $ext = 'false'; + my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url)); + $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url). + ':'.$ext.':normal:res'; + push(@LONCAPA::map::order,$newidx); + &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes', + 'string_yesno'); + &remember_parms($newidx,'hiddenresource','set','yes'); + ($errtext,$fatal) = + &storemap($coursenum, $coursedom, $folder.'.'.$container,1); + &log_differences($plain); + &mark_hash_old(); + $r->internal_redirect($redirect); + return OK; + } + } else { + $r->internal_redirect($redirect); + } + } + } # # Done catching special calls # The whole rest is for course and supplemental documents and utilities menu # Get the parameters that may be needed # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['folderpath', + ['folderpath','title', 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); @@ -5114,7 +5688,7 @@ sub handler { if ($env{'form.symb'}) { my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'}); - unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { + unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { delete($env{'form.symb'}); } } @@ -5142,34 +5716,13 @@ sub handler { if ($env{'form.tools'}) { $toolsflag=1; } if ($env{'form.folderpath'} ne '') { - my @items = split(/\&/,$env{'form.folderpath'}); - my $badpath; - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) { - $badpath = 1; - } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) { - $badpath = 1; - } - last if ($badpath); - } - if ($badpath) { - delete($env{'form.folderpath'}); - } + &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom); } + my $backto_supppath; if ($env{'form.supppath'} ne '') { - my @items = split(/\&/,$env{'form.supppath'}); - my $badpath; - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { - $badpath = 1; - } - last if ($badpath); - } - if ($badpath) { - delete($env{'form.supppath'}); + if ($supplementalflag && $allowed) { + $backto_supppath = &validate_supppath($coursenum,$coursedom); } } @@ -5179,6 +5732,8 @@ sub handler { 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()) }; @@ -5190,10 +5745,10 @@ sub handler { &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_folderpath($coursenum,$coursedom,\$navmap); @@ -5221,13 +5776,16 @@ sub handler { if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) { if ($supplementalflag) { - undef($env{'form.folderpath'}) if ($1 eq 'default'); + 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 @@ -5243,9 +5801,9 @@ sub handler { $env{'form.folderpath'}; } # If allowed and user's role is not advanced check folderpath is not hidden - if (($allowed) && (!$env{'request.role.adv'}) && - ($env{'form.folderpath'} ne '') && (!$supplementalflag)) { - my $folderurl; + 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 '') { @@ -5257,21 +5815,74 @@ sub handler { } else { $folderurl .= '.sequence'; } - unless (ref($navmap)) { - $navmap = Apache::lonnavmaps::navmap->new(); - } - if (ref($navmap)) { - if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') { - my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1); - unless (@resources) { - undef($env{'form.folderpath'}); + 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) { @@ -5346,7 +5957,7 @@ sub handler { my $tid = 1; my @tabids; if ($supplementalflag) { - @tabids = ('002','ee2','ff2'); + @tabids = ('002','dd2','ee2','ff2'); $tid = 2; } else { @tabids = ('aa1','bb1','cc1','ff1'); @@ -5356,15 +5967,34 @@ sub handler { } } my $tabidstr = join("','",@tabids); + 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, - $canedit,$hostname,\$navmap). + $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, + $londocroot,$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(); @@ -5379,14 +6009,22 @@ sub handler { .$script."\n" .'// ]]>'."\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"; @@ -5404,6 +6042,12 @@ sub handler { $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,})); @@ -5434,6 +6078,7 @@ sub handler { my %codebase = (); my ($upload_result,$upload_output,$uploadphase); if ($canedit) { + undef($suppchanges); if (($env{'form.uploaddoc.filename'}) && ($env{'form.cmd'}=~/^upload_(\w+)/)) { my $context = $1; @@ -5445,6 +6090,10 @@ sub handler { 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 @@ -5457,7 +6106,7 @@ sub handler { my ($destination,$dir_root) = &embedded_destination(); my $url_root = '/uploaded/'.$docudom.'/'.$docuname; my $actionurl = '/adm/coursedocs'; - my ($result,$flag) = + my ($result,$flag) = &Apache::loncommon::upload_embedded('coursedoc',$destination, $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state, $actionurl); @@ -5468,11 +6117,11 @@ sub handler { my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; my ($destination,$dir_root) = &embedded_destination(); - my $result = + my $result = &Apache::loncommon::modify_html_refs('coursedoc',$destination, $docuname,$docudom,undef, $dir_root); - $r->print($result.&return_to_editor()); + $r->print($result.&return_to_editor()); } elsif ($env{'form.phase'} eq 'decompress_uploaded') { $uploadphase = 'decompress_phase_one'; $r->print(&decompression_phase_one(). @@ -5498,6 +6147,9 @@ sub handler { 'impo' => 'Import', 'lnks' => 'Import from Stored Links', 'impm' => 'Import from Assembled Map', + 'imcr' => 'Import from Course Resources', + 'extr' => 'External Resource', + 'extt' => 'External Tool', 'selm' => 'Select Map', 'load' => 'Load Map', 'newf' => 'New Folder', @@ -5507,6 +6159,10 @@ sub handler { 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', 'webp' => 'Blank Web Page (editable)', + 'stpr' => 'Standard Problem', + 'news' => 'New sub-directory', + 'crpr' => 'Create Problem', + 'swit' => 'Switch Server', 'drbx' => 'Drop Box', 'scuf' => 'External Scores (handgrade, upload, clicker)', 'bull' => 'Discussion Board', @@ -5520,20 +6176,33 @@ sub handler { 'se' => 'Select', 'file' => 'File', 'title' => 'Title', + 'addp' => 'Add Placeholder to course?', + 'uste' => 'Use Template?', + 'fnam' => 'File Name:', + 'loca' => 'Location:', + 'dire' => 'Directory:', + 'cate' => 'Category:', + 'tmpl' => 'Template:', + 'empd' => 'No resources found', 'comment' => 'Comment', 'parse' => 'Upload embedded images/multimedia files if HTML file', 'bb5' => 'Blackboard 5', 'bb6' => 'Blackboard 6', 'angel5' => 'ANGEL 5.5', 'webctce4' => 'WebCT 4 Campus Edition', + 'yes' => 'Yes', + 'no' => 'No', '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 ($crstype eq 'Placement') { + $quotatype = 'placement'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) { $quotatype = 'official'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) { @@ -5612,7 +6281,7 @@ IMSFORM
    + + + + +RESFORM my $specialdocumentsform; my @specialdocumentsforma; @@ -5897,7 +6765,7 @@ NSYLFORM my $newgroupfileform=(< - + $pathitem @@ -5905,19 +6773,32 @@ NSYLFORM $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{sipa}.''=>$newsmppageform}, {''.$lt{webp}.''=>$newwebpageform}, - ); + ); + } $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma)); - - my @importdoc = ( - {''.$lt{extr}.''=>$extresourcesform} + my @external = ( + {''.$lt{extr}.''=>$extresourcesform} ); + if ($posslti) { + push(@external, + {''.$lt{extt}.''=>$exttoolform}, + ); + } + my $externalform = &create_form_ul(&create_list_elements(@external)); + + my @importdoc = (); unless ($container eq 'page') { push(@importdoc, {''.$lt{imsf}.''=>$imspform} @@ -5932,7 +6813,7 @@ NGFFORM {''.$lt{sipr}.''=>$newsmpproblemform}, {''.$lt{drbx}.''=>$newdropboxform}, {''.$lt{scuf}.''=>$newexuploadform}, - + {''.$lt{stpr}.''=>$crsresform}, ); $gradingform = &create_form_ul(&create_list_elements(@gradingforma)); @@ -5948,28 +6829,29 @@ NGFFORM my %orderhash = ( 'aa' => ['Upload',$fileuploadform], 'bb' => ['Import',$importpubform], - 'cc' => ['Grading',$gradingform], + 'cc' => ['External',$externalform], + 'dd' => ['Grading',$gradingform], + 'ff' => ['Other',$specialdocumentsform], ); unless ($container eq 'page') { $orderhash{'00'} = ['Newfolder',$newfolderform]; - $orderhash{'dd'} = ['Collaboration',$communityform]; - $orderhash{'ee'} = ['Other',$specialdocumentsform]; + $orderhash{'ee'} = ['Collaboration',$communityform]; } $hadchanges=0; unless (($supplementalflag || $toolsflag)) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, $supplementalflag,\%orderhash,$iconpath,$pathitem, - $canedit,$hostname,\$navmap,$hiddentop); + \%ltitools,$canedit,$hostname,\$navmap,$hiddentop); undef($navmap); if ($error) { $r->print('

    '.$error.'

    '); } if ($hadchanges) { - unless (&is_hash_old()) { - &mark_hash_old(); - } - } + unless (&is_hash_old()) { + &mark_hash_old(); + } + } &changewarning($r,''); } @@ -5981,7 +6863,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) { @@ -5999,7 +6881,7 @@ unless ($container eq 'page') {
    SUPDOCFORM @@ -6029,7 +6912,14 @@ SNFFORM my $supextform = &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, $help{'Adding_External_Resource'}, - undef,undef,$disabled); + undef,undef,undef,undef,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=(< @@ -6082,43 +6972,43 @@ my @specialdocs = ( {''.$lt{webp}.''=>$supwebpageform}, ); -my @supimportdoc = ( - {''.$lt{extr}.'' - =>$supextform}, - {''.$lt{upl}.'' + my @supexternal = ( + {''.$lt{extr}.'' + =>$supextform}); + if ($posslti) { + push(@supexternal, + {''.$lt{extt}.'' + =>$supexttoolform}); + } + my @supimportdoc = ( + {''.$lt{upl}.'' =>$supupdocform}, - ); + ); $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)); my %suporderhash = ( '00' => ['Supnewfolder', $supnewfolderform], - 'ee' => ['Upload',$supupdocform], + 'dd' => ['Upload',$supupdocform], + 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))], 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))] ); if ($supplementalflag) { - my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,\%suporderhash,$iconpath,$pathitem, - $canedit,$hostname); - 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,'',$hostname); + $supplementalflag,'',$iconpath,$pathitem,'',$canedit, + $hostname); if ($error) { $r->print('

    '.$error.'

    '); } @@ -6145,7 +7035,9 @@ my %suporderhash = ( &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).''); } } - $r->print(&Apache::loncommon::end_page()); + unless ($noendpage) { + $r->print(&Apache::loncommon::end_page()); + } return OK; } @@ -6223,7 +7115,7 @@ sub decompression_phase_one { $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'}); } else { my $file = $1; - $output = + $output = &Apache::loncommon::process_decompression($docudom,$docuname,$file, $destination,$dir_root, $hiddenelem); @@ -6280,6 +7172,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.'); @@ -6318,6 +7214,7 @@ sub generate_admin_menu { '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", ); @@ -6368,6 +7265,13 @@ 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) { @@ -6498,8 +7402,8 @@ END } sub editing_js { - my ($udom,$uname,$supplementalflag,$coursedom,$coursenum, - $canedit,$hostname,$navmapref) = @_; + my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, + $londocroot,$canedit,$hostname,$navmapref) = @_; my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', @@ -6511,6 +7415,7 @@ sub editing_js { p_mdb => 'Title for the Drop Box', p_mbb => 'Title for the Discussion Board', p_mwp => 'Title for Web Page', + p_mnr => 'Title for the Resource', p_mab => "Enter user:domain for User's Personal Information Page", p_mab2 => 'Personal Information Page of ', p_mab_alrt1 => 'Not a valid user:domain', @@ -6529,6 +7434,8 @@ sub editing_js { p_ctr2b => '?', p_ctr3a => 'Cut those', p_ctr3b => 'items?', + setal => 'Enter a (unique) alias', + delal => 'Are you sure you want to eliminate the alias?', 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', @@ -6539,9 +7446,13 @@ sub editing_js { noor => 'No actions selected or changes to settings specified.', noch => 'No changes to settings specified.', noac => 'No actions selected.', + nofi => 'No file selected', + tinc => 'Title in course', + sunm => 'Sub-directory name', edri => 'Editing rights unavailable for your current role.', + sele => 'Select', + swit => 'Switch server required', ); - &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'},'<>&"'); @@ -6552,7 +7463,9 @@ sub editing_js { my $backtourl; my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref)); my $toplevelsupp = &supplemental_base(); - + my $showfile_js = &Apache::loncommon::show_crsfiles_js(); + my @ids=&Apache::lonnet::current_machine_ids(); + my $machines_str = "'".join("','",@ids)."'"; if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) { my $caller = $1; if ($caller =~ /^supplemental/) { @@ -6581,7 +7494,7 @@ sub editing_js { 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()) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { if ($hostname ne '') { $backtourl = 'http://'.$hostname.$backtourl; } @@ -6590,7 +7503,7 @@ sub editing_js { } } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { - unless (&Apache::lonnet::uses_sts()) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { if ($hostname ne '') { $backtourl = 'http://'.$hostname.$backtourl; } @@ -6601,7 +7514,7 @@ sub editing_js { if ($anchor ne '') { $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); } - $backtourl = &Apache::loncommon::escape_single($backtourl); + $backtourl = &Apache::loncommon::escape_single($backtourl); } else { $backtourl = '/adm/navmaps'; } @@ -6609,17 +7522,30 @@ 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'"; + my $fieldsets = "'doc'"; unless ($main_container_page) { $fieldsets .=",'ims'"; } + my $extfieldsets = "'ext'"; + if ($posslti) { + $extfieldsets .= ",'tool'"; + } if ($supplementalflag) { - $fieldsets = "'suppext','suppdoc'"; + $fieldsets = "'suppdoc'"; + $extfieldsets = "'suppext'"; + if ($posslti) { + $extfieldsets .= ",'supptool'"; + } } my $jsmakefunctions; @@ -6628,7 +7554,7 @@ sub editing_js { function makenewfolder(targetform,folderseq) { var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}'); if (foldername) { - targetform.importdetail.value=escape(foldername)+"="+folderseq; + targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq; targetform.submit(); } } @@ -6636,7 +7562,7 @@ function makenewfolder(targetform,folder function makenewpage(targetform,folderseq) { var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}'); if (pagename) { - targetform.importdetail.value=escape(pagename)+"="+folderseq; + targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq; targetform.submit(); } } @@ -6645,7 +7571,7 @@ function makeexamupload() { var title=prompt('$js_lt{"p_mxu"}'); if (title) { this.document.forms.newexamupload.importdetail.value= - escape(title)+'=/res/lib/templates/examupload.problem'; + encodeURIComponent(title)+'=/res/lib/templates/examupload.problem'; this.document.forms.newexamupload.submit(); } } @@ -6654,7 +7580,7 @@ function makesmppage() { var title=prompt('$js_lt{"p_msp"}'); if (title) { this.document.forms.newsmppg.importdetail.value= - escape(title)+'=/adm/$udom/$uname/new/smppg'; + encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg'; this.document.forms.newsmppg.submit(); } } @@ -6668,8 +7594,8 @@ function makewebpage(type) { formname = this.document.forms.newwebpage; } if (title) { - var webpage = formname.importdetail.value; - formname.importdetail.value = escape(title)+'='+webpage; + var webpage = formname.importdetail.value; + formname.importdetail.value = encodeURIComponent(title)+'='+webpage; formname.submit(); } } @@ -6678,7 +7604,7 @@ function makesmpproblem() { var title=prompt('$js_lt{"p_msb"}'); if (title) { this.document.forms.newsmpproblem.importdetail.value= - escape(title)+'=/res/lib/templates/simpleproblem.problem'; + encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem'; this.document.forms.newsmpproblem.submit(); } } @@ -6687,7 +7613,7 @@ function makedropbox() { var title=prompt('$js_lt{"p_mdb"}'); if (title) { this.document.forms.newdropbox.importdetail.value= - escape(title)+'=/res/lib/templates/DropBox.problem'; + encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem'; this.document.forms.newdropbox.submit(); } } @@ -6696,7 +7622,7 @@ function makebulboard() { var title=prompt('$js_lt{"p_mbb"}'); if (title) { this.document.forms.newbul.importdetail.value= - escape(title)+'=/adm/$udom/$uname/new/bulletinboard'; + encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard'; this.document.forms.newbul.submit(); } } @@ -6735,6 +7661,24 @@ function changename(folderpath,index,old } } +function setalias(folderpath,index) { + var alias = prompt('$js_lt{"setal"}'); + if ((alias != null) && (alias != '')) { + this.document.forms.aliasform.alias.value=alias; + this.document.forms.aliasform.cmd.value='setalias_'+index; + this.document.forms.aliasform.folderpath.value=folderpath; + this.document.forms.aliasform.submit(); + } +} + +function delalias(folderpath,index) { + if (confirm('$js_lt{"delal"}')) { + this.document.forms.aliasform.cmd.value='delalias_'+index; + this.document.forms.aliasform.folderpath.value=folderpath; + this.document.forms.aliasform.submit(); + } +} + ENDNEWSCRIPT } else { $jsmakefunctions = <=0) { + for (i = numfiles; i >= 0; i--) { + selelem.remove(i); + } + } + if ((location == '') || (location == null) || (location == 'undefined')) { + if (selelem.options.length == 0) { + selelem.options[selelem.options.length] = new Option('',''); + selelem.selectedIndex = 0; + } + if (document.getElementById('newstdproblem')) { + document.getElementById('newstdproblem').style.display = 'none'; + } + return; + } + var machineIds = new Array($machines_str); + var athome = 0; + var role = location; + if ((location == 'author') || (location == 'course')) { + if (document.getElementById('rolehome_'+location)) { + var currhome = document.getElementById('rolehome_'+location).value; + if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) { + if (machineIds.includes(currhome)) { + athome = 1; + } + } + } + } else { + const roleinfo = location.split('___'); + role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]); + if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) { + var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value; + if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) { + if (machineIds.includes(currhome)) { + athome = 1; + } + } + } + } + if (athome) { + if (document.getElementById('stdprobswitch')) { + document.getElementById('stdprobswitch').style.display = 'none'; + } + if (document.getElementById('newstdproblem')) { + document.getElementById('newstdproblem').style.display = 'none'; + } + var http = new XMLHttpRequest(); + var url = "/adm/courseauthor"; + var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1"; + http.open("POST", url, true); + http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + http.onreadystatechange = function() { + if (http.readyState == 4 && http.status == 200) { + var data = JSON.parse(http.responseText); + if (Array.isArray(data.dirs)) { + var len = data.dirs.length; + if (len) { + if (len > 1) { + selelem.options[selelem.options.length] = new Option('$js_lt{sele}',''); + } + } + if (len) { + var j; + for (j = 0; j < len; j++) { + selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]); + } + selelem.selectedIndex = 0; + if (len == 1) { + toggleCrsResTitle(); + } + } + } + } + } + http.send(params); + } else { + selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch'); + selelem.selectedIndex = 0; + if (document.getElementById('stdprobswitch')) { + document.getElementById('stdprobswitch').style.display = 'block'; + } + if (document.getElementById('newstdproblem')) { + document.getElementById('newstdproblem').style.display = 'none'; + } + } + } + return; +} + +function switchForProb() { + if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') { + var url = '/adm/switchserver?otherserver='; + var newhostid = ''; + var role = ''; + var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; + if (selloc == 'author') { + newhostid = document.courseresform.rolehome_author.value; + role = "au./&js_escape($env{'user.domain'})/"; + } else if (selloc == 'course') { + newhostid = document.courseresform.rolehome_course.value; + role = "&js_escape($env{'request.role'})"; + } else { + var items = new Array(); + items = selloc.split('___'); + var len = document.courseresform.rolehome_coauthor.length; + if (null == len) { + var currval = document.courseresform.rolehome_coauthor.value; + if (null != currval) { + var info = new Array(); + info = currval.split('='); + newhostid = info[2]; + role = info[0]+'./'+info[1]; + } + } else { + for (var i=0; idir_config('lonDocRoot'); + my @ids=&Apache::lonnet::current_machine_ids(); + if ($env{'form.authorrole'} eq 'author') { + if ($env{'user.author'}) { + if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) { + my $url = "/priv/$env{'user.domain'}/$env{'user.name'}"; + my $path = $docroot.$url; + my $subdir = $env{'form.authorpath'}; + $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename); + } + } + } elsif ($env{'form.authorrole'} eq 'course') { + my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; + if ($chome && grep(/^\Q$chome\E$/,@ids)) { + my $url = "/priv/$coursedom/$coursenum"; + my $path=$docroot.$url; + my $subdir = $env{'form.authorpath'}; + $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename); + if ($redirect) { + my $rightsfile = 'default.rights'; + my $sourcerights = "$path/$rightsfile"; + my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile"; + my $now = time; + if (!-e $sourcerights) { + my $cid = $coursedom.'_'.$coursenum; + if (open(my $fh,">$sourcerights")) { + print $fh < + +END + close($fh); + } + } + if (!-e "$sourcerights.meta") { + if (open(my $fh,">$sourcerights.meta")) { + my $author=$env{'environment.firstname'}.' '. + $env{'environment.middlename'}.' '. + $env{'environment.lastname'}.' '. + $env{'environment.generation'}; + $author =~ s/\s+$//; + print $fh <<"END"; + + +$author +$coursenum:$coursedom +private +$now + + +$coursedom +0 + +notset +$now +0 +rights +$env{'user.name'}:$env{'user.domain'} + + + +$coursenum:$coursedom +deny:::course,allow:$cid::course + + + + +END + close($fh); + } + } + if ((-e $sourcerights) && (-e "$sourcerights.meta")) { + if (!-e "$docroot/res/$coursedom") { + mkdir("$docroot/res/$coursedom",0755); + } + if (!-e "$docroot/res/$coursedom/$coursenum") { + mkdir("$docroot/res/$coursedom/$coursenum",0755); + } + if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) { + my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes')); + my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1); + } + } + my $source = $docroot.$redirect; + if (!-e "$source.meta") { + my $cid = $coursedom.'_'.$coursenum; + my $now = time; + if (open(my $fh,">$source.meta")) { + my $author=$env{'environment.firstname'}.' '. + $env{'environment.middlename'}.' '. + $env{'environment.lastname'}.' '. + $env{'environment.generation'}; + $author =~ s/\s+$//; + my $title = $env{'form.newresourcetitle'}; + $title =~ s/^\s+|\s+$//g; + print $fh < +$author +$coursenum:$coursedom +custom +$now +/res/$coursedom/$coursenum/default.rights + +$coursedom +0 + +notset +$now +0 +problem +$coursenum:$coursedom + + + +$coursenum:$coursedom + + + +$title +END + close($fh); + } + } + } + } + } else { + my ($auname,$audom,$role) = split('___',$env{'form.authorrole'}); + my $rolehome = &Apache::lonnet::homeserver($auname,$audom); + if (grep(/^\Q$rolehome\E$/,@ids)) { + my $now = time; + if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) { + my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname}); + if (($start <= $now) && (($end == 0) || ($end >= $now))) { + my $url = "/priv/$audom/$auname"; + my $path = $r->dir_config('lonDocRoot').$url; + my $subdir = $env{'form.authorpath'}; + $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename); + } + } + } + } + } + } + } + return ($redirect,$error); +} + +sub finishnewprob { + my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_; + unless (-d $path) { + unless (mkdir($path,02770)) { + return; + } + } + my $redirect; + if ($subdir ne '/') { + $subdir = &cleandir($subdir); + if (($subdir ne '') && (-d "$path/$subdir")) { + $path .= "/$subdir"; + $url .= "/$subdir"; + } + } + my $dest; + if ($newsubdir ne '') { + $newsubdir = &cleandir($newsubdir); + } + if ($newsubdir ne '') { + if (-d "$path/$newsubdir") { + $dest = "$path/$newsubdir/$filename"; + } else { + my $dirok; + unless (-e "$path/$newsubdir") { + if (mkdir("$path/$newsubdir",02770)) { + if (chmod(02770,"$path/$newsubdir")) { + $dirok = 1; + } + } + } + if ($dirok) { + $dest = "$path/$newsubdir/$filename"; + } + } + if (($dest ne '') && (!-e $dest)) { + $redirect = "$url/$newsubdir/$filename"; + } + } else { + $dest = "$path/$filename"; + if (($dest ne '') && (!-e $dest)) { + $redirect = "$url/$filename"; + } + } + if ((!-e $dest) && ($context ne 'upload')) { + my $template = $env{'form.template'}; + my $copyfrom; + if ($template ne '') { + my %templates; + my @files = &Apache::lonhomework::get_template_list('problem'); + foreach my $poss (@files) { + if (ref($poss) eq 'ARRAY') { + if ($template eq $poss->[0]) { + $templates{$template} = 1; + last; + } + } + } + if ($templates{$template}) { + $copyfrom = $template; + } + } + if ($filename =~ /\.problem$/) { + unless ($copyfrom) { + $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem'; + } + &File::Copy::copy($copyfrom,$dest); + } + } + return $redirect; +} + +sub cleandir { + my ($dir) = @_; + $dir =~ s/^\s+//; + $dir =~ s/\s+$//; + $dir =~ s/\.+//g; + $dir =~ s/[\#\?&%\":]//g; + return $dir; +} + 1; __END__ @@ -7793,7 +9406,7 @@ check on this Verify Content -=item devalidateversioncache() +=item devalidateversioncache() =item checkversions()