--- loncom/interface/londocs.pm 2021/04/23 01:37:14 1.677 +++ 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.677 2021/04/23 01:37:14 raeburn Exp $ +# $Id: londocs.pm,v 1.700 2023/07/11 12:44:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,7 +45,6 @@ use Apache::lontemplate(); use Apache::lonsimplepage(); use Apache::lonhomework(); use Apache::lonpublisher(); -use Apache::lonparmset(); use Apache::loncourserespicker(); use HTML::Entities; use HTML::TokeParser; @@ -91,7 +90,7 @@ sub storemap { if ($map =~ /^default/) { $hadchanges=1; - } else { + } elsif ($contentchg) { $suppchanges=1; } return ($errtext,0); @@ -183,43 +182,62 @@ sub default_folderpath { } } -sub validate_folderpath { - my ($supplementalflag) = @_; - 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'}); - } - } - return; -} - -sub validate_suppath { +sub validate_supppath { + my ($coursenum,$coursedom) = @_; + my $backto; if ($env{'form.supppath'} ne '') { my @items = split(/\&/,$env{'form.supppath'}); - my $badpath; + 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]; } - last if ($badpath); } if ($badpath) { delete($env{'form.supppath'}); + } else { + $supppath =~ s/^\&//; + $backto =~ s/^\&//; + $env{'form.supppath'} = $supppath; } } - return; + return $backto; } sub dumpcourse { @@ -700,7 +718,7 @@ sub group_import { $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) { @@ -709,6 +727,12 @@ 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{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'}, @@ -722,127 +746,130 @@ sub group_import { $toolhash{'gradable'} =~ s/\D+//g; } if (ref($ltitoolsref) eq 'HASH') { - if (ref($ltitoolsref->{$toolid}) eq 'HASH') { - my @deleted; - $toolhash{'id'} = $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); + 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 ($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 (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') { - foreach my $item ('width','height','linktext','explanation') { - delete($toolhash{$item}); - if ($residx) { - if ($toolsettings{$item}) { - push(@deleted,$item); + 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); + } 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','linktext','explanation') { - my $crsitem; - if (($item eq 'label') || ($item eq 'title')) { - $crsitem = 'crs'.$item; - } else { - $crsitem = $item; - } - if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) { - $toolhash{$crsitem} =~ s/^\s+//; - $toolhash{$crsitem} =~ s/\s+$//; - if ($toolhash{$crsitem} eq '') { + 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}); } - } else { - delete($toolhash{$crsitem}); - } - if (($residx) && (exists($toolsettings{$crsitem}))) { - unless (exists($toolhash{$crsitem})) { - push(@deleted,$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 ($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; } - if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) { - $changegradable = 1; + my $changegradable; + if (($residx) && ($folder =~ /^default/)) { if ($toolsettings{'gradable'}) { - $toolhash{'gradable'} = 1; + 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'; + my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum); + if ($putres eq 'ok') { + if (@deleted) { + &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum); } - &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val, - 'string_yesno'); - &remember_parms($residx,'gradable','set',$val); + 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); } - } else { - return (&mt('Failed to save update to external tool.'),1); } } } @@ -955,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); } @@ -1189,7 +1215,13 @@ sub docs_change_log { } $r->print(''); if ($docslog{$id}{'logentry'}{'parameter_res'}) { - $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':