--- loncom/interface/londocs.pm 2016/06/10 22:31:27 1.605 +++ loncom/interface/londocs.pm 2024/01/10 20:07:37 1.709 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.605 2016/06/10 22:31:27 raeburn Exp $ +# $Id: londocs.pm,v 1.709 2024/01/10 20:07:37 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); @@ -97,6 +102,7 @@ sub authorhosts { my %outhash=(); my $home=0; my $other=0; + my @ids=&Apache::lonnet::current_machine_ids(); foreach my $key (keys(%env)) { if ($key=~/^user\.role\.(au|ca)\.(.+)$/) { my $role=$1; @@ -113,7 +119,6 @@ sub authorhosts { } my $allowed=0; my $myhome=&Apache::lonnet::homeserver($ca,$cd); - my @ids=&Apache::lonnet::current_machine_ids(); foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; @@ -139,7 +144,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) = @_; @@ -164,8 +263,8 @@ ENDJS add_entries => {'onload' => "hide_searching();"}, }; } - $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n". - &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n"); + $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n". + &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n"); $r->print(&startContentScreen('tools')); my ($home,$other,%outhash)=&authorhosts(); unless ($home) { @@ -564,9 +663,9 @@ sub recurse_html { } else { $relfile = $dependency; $depurl = $currurlpath; - $depurl =~ s{[^/]+$}{}; + $depurl =~ s{[^/]+$}{}; $depurl .= $dependency; - ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); + ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); } next if ($relfile eq ''); my $newname = $replacehash->{$container}; @@ -615,11 +714,12 @@ sub group_import { } } if ($url) { - if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) { + if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) { $url = $1; my $marker = $2; my $info = $3; - my ($toolid,%toolhash,%toolsettings); + 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); @@ -627,73 +727,149 @@ sub group_import { } 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{'crslabel'},$toolhash{'crstitle'}) = @toolinfo; - $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'}); - $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'}); + $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') { - my @deleted; - if (ref($ltitoolsref->{$toolid}) eq 'HASH') { - if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) { - $url =~ s/exttool$/exttools/; - } - $toolhash{'id'} = $toolid; - if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) { - if ($toolhash{'target'} eq 'window') { - foreach my $item ('width','height') { - $toolhash{$item} =~ s/^\s+//; - $toolhash{$item} =~ s/\s+$//; + 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'}; } } - } elsif ($residx) { - $toolhash{'target'} = $toolsettings{'target'}; - if ($toolhash{'target'} eq 'window') { - $toolhash{'width'} = $toolsettings{'width'}; - $toolhash{'height'} = $toolsettings{'height'}; - } - } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') { - $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'}; - if ($toolhash{'target'} eq 'window') { - $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'}; - $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'}; - } - } - if ($toolhash{'target'} eq 'iframe') { - delete($toolhash{'width'}); - delete($toolhash{'height'}); - if ($residx) { - if ($toolsettings{'width'}) { - push(@deleted,'width'); + if ($toolhash{'target'} eq 'iframe') { + foreach my $item ('width','height','linktext','explanation') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } } - if ($toolsettings{'height'}) { - push(@deleted,'height'); + } elsif ($toolhash{'target'} eq 'tab') { + foreach my $item ('width','height') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } } } - } - if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') { - foreach my $item ('label','title') { - if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) { - $toolhash{'crs'.$item} =~ s/^\s+//; - $toolhash{'crs'.$item} =~ s/\s+$//; - if ($toolhash{'crs'.$item} eq '') { - delete($toolhash{'crs'.$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); + } } - } else { - delete($toolhash{'crs'.$item}); } - if (($residx) && (exists($toolsettings{'crs'.$item}))) { - unless (exists($toolhash{'crs'.$item})) { - push(@deleted,'crs'.$item); + } + 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); - } + 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); + } } } } @@ -709,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}); @@ -723,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 @@ -750,7 +927,7 @@ $initialtext END $env{'form.output'}=$newhtml; - my $result = + my $result = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output', "$filepath/$residx/$fname.html"); @@ -764,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')); @@ -804,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); } @@ -874,12 +1051,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'}) { - &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space'); + &checkversions($r,$canedit); + } elsif ($canedit && $env{'form.dumpcourse'}) { + &init_breadcrumbs('dumpcourse','Copy uploaded 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']); + 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 @@ -4898,11 +6069,25 @@ sub handler { } if ($env{'form.forcesupplement'}) { $supplementalflag=1; } if ($env{'form.forcestandard'}) { $supplementalflag=0; } - unless ($allowed) { $supplementalflag=1; } - unless ($standard) { $supplementalflag=1; } + unless (($supplementalflag) || + ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) { + unless ($allowed) { $supplementalflag=1; } + unless ($standard) { $supplementalflag=1; } + } 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 = {}; @@ -4910,27 +6095,28 @@ sub handler { 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'}); @@ -4949,13 +6135,23 @@ 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 - if (!$allowed) { + +# Set folderpath if we are not allowed to make changes and this is supplemental content + if ((!$allowed) && ($supplementalflag)) { unless ($env{'form.folderpath'} =~ /^supplemental/) { $env{'form.folderpath'} = &supplemental_base(); } @@ -4966,19 +6162,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'}); } @@ -4996,8 +6274,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 = ''; @@ -5008,7 +6290,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'); } @@ -5037,7 +6319,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'); @@ -5047,15 +6329,34 @@ sub handler { } } my $tabidstr = join("','",@tabids); - %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom); - my $posslti = keys(%ltitools); - $script .= &editing_js($udom,$uname,$supplementalflag,$posslti). + 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, + $londocroot,$canedit,$hostname,\$navmap). &history_tab_js(). &inject_data_js(). &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid). &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(); @@ -5077,37 +6378,75 @@ sub handler { &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, + 'bread_crumbs_nomenu' => 1}; + } 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); + my $args = {'bread_crumbs' => $brcrum}; + unless (($env{'form.folderpath'} eq '') || + ($env{'form.folder'} eq 'supplemental')) { + $args->{'bread_crumbs_nomenu'} = 1; + } $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef, - {'bread_crumbs' => $brcrum,})); + $args)); } 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; @@ -5115,9 +6454,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 @@ -5130,7 +6474,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); @@ -5141,11 +6485,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(). @@ -5159,7 +6503,7 @@ sub handler { if ($allowed && $toolsflag) { $r->print(&startContentScreen('tools')); - $r->print(&generate_admin_menu($crstype)); + $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom)); $r->print(&endContentScreen()); } elsif ((!$showdoc) && (!$uploadphase)) { # ----------------------------------------------------------------------------- @@ -5167,10 +6511,11 @@ sub handler { 'copm' => 'All documents out of a published map into this folder', 'upfi' => 'Upload File', 'upld' => 'Upload Content', - 'srch' => 'Search', - 'impo' => 'Import', + 'srch' => 'Search Repository', + 'impo' => 'Import from Repository', 'lnks' => 'Import from Stored Links', 'impm' => 'Import from Assembled Map', + 'imcr' => 'Import from Course Resources', 'extr' => 'External Resource', 'extt' => 'External Tool', 'selm' => 'Select Map', @@ -5181,7 +6526,11 @@ sub handler { 'navc' => 'Table of Contents', 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', - 'webp' => 'Blank Web Page (editable)', + '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', @@ -5195,12 +6544,23 @@ 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.', ); # ----------------------------------------------------------------------------- @@ -5230,7 +6590,7 @@ sub handler { if ($disk_quota == 0) { $percent = 100.0; } else { - $percent = 100*($current_disk_usage/$disk_quota); + $percent = 100*($usage/$disk_quota); } $usage = sprintf("%.2f",$usage); $quota = sprintf("%.2f",$quota); @@ -5241,16 +6601,13 @@ sub handler { my $fileupload=(< - - FIUP - my $checkbox=(<$lt{'parse'}? --> CHBO my $imsfolder = $env{'form.folder'}; @@ -5264,10 +6621,12 @@ CHBO

IMSFORM @@ -5290,9 +6649,11 @@ IMSFORM $lt{'upfi'} $fileupload + +
$lt{'title'}:
- + $pathitem
@@ -5300,11 +6661,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'} @@ -5315,36 +6682,90 @@ FUFORM $lt{'copm'}
-  $lt{'selm'}
- + onfocus="this.blur();$mapimportjs" $disabled /> +  $lt{'selm'}
+ SEDFFORM + my ($importcrsresform,$checkcrsres); + if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) { + $checkcrsres = 1; + } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') { + my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom); + if ($domdefs{'crsauthor'}) { + $checkcrsres = 1; + } + } + if ($checkcrsres) { + my ($numdirs,$pickfile) = + &Apache::loncommon::import_crsauthor_form('coursepath','coursefile', + "resize_scrollbox('contentscroll','1','0');", + undef,'res'); + if ($pickfile) { + $importcrsresform=(< + $lt{'imcr'}$help{'Course_Resources'} +
+ +
+CRSFORM + } + } + + my $fromstoredjs; + if ($canedit) { + $fromstoredjs = 'open_StoredLinks_Import()'; + } else { + $fromstoredjs = "alert('".&js_escape($lt{'er'})."')"; + } + my @importpubforma = ( - { ''.$lt{srch}.'' => $pathitem."$lt{'srch'}" }, + { ''.$lt{srch}.'' => $pathitem."$lt{'srch'}$help{'Search_LON-CAPA_Resource'}" }, { ''.$lt{impo}.'' => "$lt{'impo'}$help{'Importing_LON-CAPA_Resource'}" }, - { ''.$lt{lnks}.'' => "$lt{'lnks'}" }, - { ''.$lt{impm}.'' => $importpubform } - ); + { ''.$lt{lnks}.'' => ''.$lt{'lnks'}.''.$help{'Import_Stored_Links'} }, + { ''.$lt{impm}.'' => $importpubform }, + ); + if ($importcrsresform) { + push(@importpubforma,{ ''.$lt{imcr}.'' => $importcrsresform}); + } $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); + \%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(< @@ -5354,6 +6775,11 @@ SEDFFORM $containertag +
+ + + $containertag +
HIDDENFORM $r->print(&makesimpleeditform($pathitem)."\n". @@ -5376,12 +6802,12 @@ HIDDENFORM } # - + my $hostname = $r->hostname(); my $savefolderpath; 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')); @@ -5390,9 +6816,13 @@ HIDDENFORM } my $postexec=''; if ($folder eq 'default') { + my $windowname = 'loncapaclient'; + if ($env{'request.lti.login'}) { + $windowname .= 'lti'; + } $r->print(''."\n" ); @@ -5405,17 +6835,17 @@ HIDDENFORM my $newnavform=(< - + $pathitem - $lt{'navc'} + $lt{'navc'} $help{'Navigate_Content'} NNFORM my $newsmppageform=(< - + $pathitem $lt{'sipa'} @@ -5425,7 +6855,7 @@ NSPFORM my $newsmpproblemform=(< - + $pathitem $lt{'sipr'} @@ -5436,7 +6866,7 @@ NSPROBFORM my $newdropboxform=(< - + $pathitem $lt{'drbx'} @@ -5446,7 +6876,7 @@ NDBFORM my $newexuploadform=(< - + $pathitem $lt{'scuf'} @@ -5456,7 +6886,7 @@ NEXUFORM my $newbulform=(< - + $pathitem $lt{'bull'} @@ -5466,18 +6896,18 @@ NBFORM my $newaboutmeform=(< - + $pathitem - $lt{'mypi'} + $lt{'mypi'} $help{'My Personal Information Page'} NAMFORM my $newaboutsomeoneform=(< - + $pathitem $lt{'abou'} @@ -5486,11 +6916,11 @@ NASOFORM my $newrosterform=(< - + $pathitem - $lt{'rost'} + $lt{'rost'} $help{'Course_Roster'} NROSTFORM @@ -5507,14 +6937,172 @@ NROSTFORM } my $newwebpageform =(< - + $pathitem $lt{'webp'} $help{'Web_Page'} NWEBFORM + my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); + my @ids=&Apache::lonnet::current_machine_ids(); + my $machines_str = "'".join("','",@ids)."'"; + my (%is_home,%toppath,$rolehomes); + if ($env{'user.author'}) { + if (grep(/^\Q$env{'user.home'}\E$/,@ids)) { + $is_home{'author'} = 1; + } + $rolehomes = ''."\n"; + } + my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles', + ['active'],['ca','aa']); + my %by_roletype; + if (keys(%roleshash)) { + foreach my $entry (keys(%roleshash)) { + my ($auname,$audom,$roletype) = split(/:/,$entry); + my $key = $entry; + $key =~ s/:/___/g; + my $author = $auname.'___'.$audom; + $by_roletype{$roletype}{$author} = 1; + my $rolehome = &Apache::lonnet::homeserver($auname,$audom); + $toppath{$author} = "/priv/$audom/$auname"; + if (grep(/^\Q$rolehome\E$/,@ids)) { + $is_home{$author} = 1; + } + $rolehomes .= ''."\n"; + } + } + my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'}; + if (grep(/^\Q$crshome\E$/,@ids)) { + $is_home{'course'} = 1; + } + $rolehomes .= ''."\n"; + my $pickdir = $lt{'loca'}. + '
'."\n". + $lt{'dire'}. + '
'."\n"; + my %seltemplate_menus; + my @files = &Apache::lonhomework::get_template_list('problem'); + my @noexamplelink = ('blank.problem','blank.library','script.library'); + my $currentcategory = ''; + my @ordered = (''); + my %templatehelp; + my $defcategory = ''; + my @catorder = ($defcategory); + $seltemplate_menus{$defcategory}->{'order'} = ['']; + $seltemplate_menus{$defcategory}->{'text'} = ''; + foreach my $file (@files) { + if (ref($file) eq 'ARRAY') { + my ($path,$title,$category,$help) = @{$file}; + next if ($title !~ /\S/); + if (&js_escape($category) ne $currentcategory) { + $currentcategory = &js_escape($category); + push(@catorder,&js_escape($currentcategory)); + $seltemplate_menus{$currentcategory}->{'text'} = $category; + $seltemplate_menus{$currentcategory}->{'default'} = ''; + $seltemplate_menus{$currentcategory}->{'select2'}->{''} = ''; + push(@{$seltemplate_menus{$currentcategory}->{'order'}},''); + } + if ($path) { + $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title; + push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path)); + if ($help) { + $templatehelp{$path} = $help; + } + } + } + } + my $templates = $lt{'cate'}.' '. + &Apache::loncommon::linked_select_forms('courseresform','
'.$lt{'tmpl'}.' ', + $defcategory,'tempcategory','template', + \%seltemplate_menus,\@catorder, + "resize_scrollbox('contentscroll','1','0');", + "toggleExampleText();",'template').'
'; + my $templatepreview = ''. + ''.&mt('Example').''; + my $crsresform; + if (($env{'user.author'}) || ($checkcrsres)) { + $crsresform=(< + $lt{'stpr'}$help{'Standard_Problem'} +
+ +
+ +RESFORM + } my $specialdocumentsform; my @specialdocumentsforma; @@ -5553,7 +7141,7 @@ NFFORM $pathitem - $lt{'syll'} + $lt{'syll'} $help{'Syllabus'} @@ -5561,32 +7149,40 @@ NSYLFORM my $newgroupfileform=(< - + $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 (keys(%ltitools)) { - push(@importdoc, - {''.$lt{extt}.''=>$exttoolform}, + 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} @@ -5600,41 +7196,50 @@ NGFFORM @gradingforma=( {''.$lt{sipr}.''=>$newsmpproblemform}, {''.$lt{drbx}.''=>$newdropboxform}, - {''.$lt{scuf}.''=>$newexuploadform}, - + {''.$lt{scuf}.''=>$newexuploadform} ); + if ($crsresform) { + push(@gradingforma, + {''.$lt{stpr}.''=>$crsresform} + ); + } $gradingform = &create_form_ul(&create_list_elements(@gradingforma)); @communityforma=( {''.$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)); my %orderhash = ( 'aa' => ['Upload',$fileuploadform], - 'bb' => ['Import',$importpubform], - 'cc' => ['Grading',$gradingform], + 'bb' => ['External',$externalform], + 'cc' => ['Import',$importpubform], + 'dd' => ['Assessment',$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,\%ltitools); + $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,''); } @@ -5646,7 +7251,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) { @@ -5664,8 +7269,10 @@ unless ($container eq 'page') {
SUPDOCFORM @@ -5693,13 +7301,15 @@ SNFFORM my $supextform = &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, - $help{'Adding_External_Resource'}); + $help{'Adding_External_Resource'}, + 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); + $coursenum,\%ltitools,$disabled); my $supnewsylform=(< @@ -5707,7 +7317,7 @@ SNFFORM $pathitem - $lt{'syll'} + $lt{'syll'} $help{'Syllabus'} SNSFORM @@ -5718,7 +7328,7 @@ SNSFORM $pathitem - $lt{'mypi'} + $lt{'mypi'} $help{'My Personal Information Page'} SNAMFORM @@ -5745,22 +7355,22 @@ SWEBFORM my @specialdocs = ( - {''.$lt{syll}.'' + {''.$lt{syll}.'' =>$supnewsylform}, - {''.$lt{mypi}.'' + {''.$lt{mypi}.'' =>$supnewaboutmeform}, {''.$lt{webp}.''=>$supwebpageform}, ); -my @supimportdoc = ( - {''.$lt{extr}.'' - =>$supextform}); - if (keys(%ltitools)) { - push(@supimportdoc, - {''.$lt{extt}.'' + my @supexternal = ( + {''.$lt{extr}.'' + =>$supextform}); + if ($posslti) { + push(@supexternal, + {''.$lt{extt}.'' =>$supexttoolform}); } - push(@supimportdoc, + my @supimportdoc = ( {''.$lt{upl}.'' =>$supupdocform}, ); @@ -5768,32 +7378,27 @@ my @supimportdoc = ( $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,\%ltitools); - 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.'

'); } @@ -5820,13 +7425,16 @@ 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; } sub embedded_form_elems { my ($phase,$primaryurl,$newidx) = @_; my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); + $newidx =~s /\D+//g; return < @@ -5847,7 +7455,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); } @@ -5873,6 +7485,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"; @@ -5890,7 +7505,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); @@ -5947,6 +7562,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.'); @@ -5978,13 +7597,15 @@ sub remove_archive { } sub generate_admin_menu { - my ($crstype) = @_; + my ($crstype,$canedit,$coursenum,$coursedom) = @_; 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', + 'ca' => "Enter $crstype Authoring Space", 'imse' => 'Export contents to IMS Archive', 'dcd' => "Copy $crstype Content to Authoring Space", ); @@ -6035,8 +7656,42 @@ 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) { + my ($crsauname,$crsaudom,$crshome); + if (($coursenum ne '') && ($coursedom ne '')) { + my $crsauthorurl = "/priv/$coursedom/$coursenum/"; + ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl); + if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) { + my @ids=&Apache::lonnet::current_machine_ids(); + my $linkurl; + if (grep(/^\Q$crshome\E$/,@ids)) { + $linkurl = $crsauthorurl; + } else { + $linkurl = + &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1); + } + if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) { + push(@{$menu[0]->{items}}, + { linktext => $lt{'ca'}, + url => $linkurl, + permission => 'F', + help => 'Docs_Course_Authorspace', + icon => 'impcrsau.png', + linktitle => $lt{'ca'}, + }); + } + } + } + push(@menu, { categorytitle=>'Export', items =>[ { linktext => $lt{'imse'}, @@ -6055,6 +7710,7 @@ sub generate_admin_menu { }, ] }); + } return '
'."\n". ''."\n". &Apache::lonhtmlcommon::generate_menu(@menu)."\n". @@ -6063,15 +7719,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 = '
'. @@ -6135,7 +7792,7 @@ sub generate_edit_table { - +
END @@ -6161,7 +7818,8 @@ END } sub editing_js { - my ($udom,$uname,$supplementalflag,$posslti) = @_; + 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', @@ -6173,6 +7831,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', @@ -6191,6 +7850,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', @@ -6201,6 +7862,12 @@ 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(); @@ -6209,11 +7876,12 @@ sub editing_js { 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 $toplevelsupp = &supplemental_base(); - 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/) { @@ -6222,8 +7890,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'; @@ -6232,30 +7938,39 @@ 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'"; - } + 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) { - $fieldsets .= ",'supptool'"; + $extfieldsets .= ",'supptool'"; } } - return <=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; + } + } + } + } + var templateradio = document.courseresform.elements['newresusetemp']; + if (athome) { + if (document.getElementById('stdprobswitch')) { + document.getElementById('stdprobswitch').style.display = 'none'; + } + if (document.getElementById('newstdproblem')) { + document.getElementById('newstdproblem').style.display = 'none'; + } + var canedit = '$canedit'; + if (canedit) { + if (templateradio.length > 1) { + for (var i=0; i 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'; + } + if (templateradio.length > 1) { + for (var i=0; i 'Switch server?', - duco => 'Copying Content to Authoring Space', + duco => 'Copying uploaded 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', ); @@ -7255,6 +9502,212 @@ sub makesimpleeditform { SIMPFORM } +sub makenewproblem { + my ($r,$coursedom,$coursenum) = @_; +# Creating a new problem + my ($redirect,$error); + if ($env{'form.authorrole'}) { + my ($newsubdir,$filename); + if ($env{'form.newsubdir'}) { + if ($env{'form.newsubdirname'} ne '') { + $newsubdir = $env{'form.newsubdirname'}; + } + } + if ($env{'form.newresourcename'}) { + $filename = $env{'form.newresourcename'}; + $filename =~ s/\.(\d+)(\.\w+)$/$2/; + $filename =~ s/`//g; + $filename =~ s{/\.\./}{_}g; + $filename =~ s/\.+/./g; + $filename =~ s{/+}{_}g; + if ($filename ne '') { + my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/); + if (($ext) && ($ext ne '.problem')) { + $filename = $name.'.problem'; + } elsif ($ext eq '') { + $filename .= '.problem'; + } + my $docroot = $r->dir_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"; + &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom); + my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile"; + 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__ @@ -7354,7 +9807,9 @@ check on this Verify Content -=item devalidateversioncache() & checkversions() +=item devalidateversioncache() + +=item checkversions() Check Versions