--- loncom/interface/londocs.pm 2017/02/20 18:29:22 1.622 +++ loncom/interface/londocs.pm 2020/03/06 18:53:27 1.669 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.622 2017/02/20 18:29:22 raeburn Exp $ +# $Id: londocs.pm,v 1.669 2020/03/06 18:53:27 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,6 +45,8 @@ use Apache::lontemplate(); use Apache::lonsimplepage(); use Apache::lonhomework(); use Apache::lonpublisher(); +use Apache::lonparmset(); +use Apache::loncourserespicker(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; @@ -52,6 +54,7 @@ use File::MMagic; use File::Copy; use Apache::lonlocal; use Cwd; +use UUID::Tiny ':std'; use LONCAPA qw(:DEFAULT :match); my $iconpath; @@ -603,9 +606,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}; @@ -654,11 +657,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 @extras = ('linktext','explanation','crslabel','crstitle','crsappend'); my @toolinfo = split(/:/,$info); if ($residx) { %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); @@ -668,28 +672,42 @@ sub group_import { } $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/; - } + my @deleted; $toolhash{'id'} = $toolid; - if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) { + 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') { - $toolhash{'width'} = $toolsettings{'width'}; - $toolhash{'height'} = $toolsettings{'height'}; + foreach my $item ('width','height') { + $toolhash{$item} = $toolsettings{$item}; + } } } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') { $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'}; @@ -699,40 +717,93 @@ sub group_import { } } if ($toolhash{'target'} eq 'iframe') { - delete($toolhash{'width'}); - delete($toolhash{'height'}); - if ($residx) { - if ($toolsettings{'width'}) { - push(@deleted,'width'); + 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') { + 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{'crs'.$item} =~ s/^\s+//; - $toolhash{'crs'.$item} =~ s/\s+$//; - if ($toolhash{'crs'.$item} eq '') { - delete($toolhash{'crs'.$item}); + $toolhash{$crsitem} =~ s/^\s+//; + $toolhash{$crsitem} =~ s/\s+$//; + if ($toolhash{$crsitem} eq '') { + delete($toolhash{$crsitem}); } } else { - delete($toolhash{'crs'.$item}); + delete($toolhash{$crsitem}); } - if (($residx) && (exists($toolsettings{'crs'.$item}))) { - unless (exists($toolhash{'crs'.$item})) { - push(@deleted,'crs'.$item); + 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); } } } @@ -748,8 +819,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}); @@ -789,7 +860,7 @@ $initialtext END $env{'form.output'}=$newhtml; - my $result = + my $result = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output', "$filepath/$residx/$fname.html"); @@ -948,7 +1019,7 @@ sub docs_change_log { if ($supplementalflag) { $tid = 2; } - my ($breadcrumbtrail) = + my ($breadcrumbtrail) = &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1); $r->print($breadcrumbtrail. &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto, @@ -970,6 +1041,7 @@ sub docs_change_log { 'encrypturl' => 'URL hidden', 'randompick' => 'Randomly pick', 'randomorder' => 'Randomly ordered', + 'gradable' => 'Grade can be assigned to External Tool', 'set' => 'set to', 'del' => 'deleted'); my $filter = &Apache::loncommon::display_filter('docslog')."\n". @@ -1077,7 +1149,7 @@ sub docs_change_log { $r->print(''); if ($docslog{$id}{'logentry'}{'parameter_res'}) { $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':