--- loncom/interface/londocs.pm 2022/12/31 14:08:59 1.690
+++ loncom/interface/londocs.pm 2023/05/22 21:10:55 1.699
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.690 2022/12/31 14:08:59 raeburn Exp $
+# $Id: londocs.pm,v 1.699 2023/05/22 21:10:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -719,7 +719,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) {
@@ -728,6 +728,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'},
@@ -741,127 +747,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 (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
- $changegradable = 1;
+ 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'}) {
- $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);
+ }
+ 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);
}
- &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);
}
}
}
@@ -1207,7 +1216,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]).':
');
+ my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
+ if ($title eq '') {
+ ($title) = ($url =~ m{/([^/]+)$});
+ } elsif ($is_supp) {
+ $title = &Apache::loncommon::parse_supplemental_title($title);
+ }
+ $r->print(&LONCAPA::map::qtescape($title).':');
foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
# FIXME: internationalization seems wrong here
@@ -3109,7 +3124,7 @@ sub update_parameter {
my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
$name=&LONCAPA::map::qtescape($name);
$url=&LONCAPA::map::qtescape($url);
- next unless ($name && $url);
+ next unless $url;
my $is_map;
if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
$is_map = 1;
@@ -4294,7 +4309,7 @@ END
$nomodal = 1;
}
}
- my ($checkencrypt,$shownurl);
+ my $checkencrypt;
if (!$env{'request.role.adv'}) {
if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
@@ -4314,7 +4329,7 @@ END
my $currenc = $env{'request.enc'};
$env{'request.enc'} = 1;
$shownsymb = &Apache::lonenc::encrypted($symb);
- $shownurl = &Apache::lonenc::encrypted($url);
+ my $shownurl = &Apache::lonenc::encrypted($url);
if (&Apache::lonnet::symbverify($symb,$url)) {
$url = $shownurl;
} else {
@@ -4329,7 +4344,8 @@ END
$url = &Apache::lonnet::clutter($url);
}
}
- $shownurl = $url;
+ } else {
+ $url = '';
}
unless ($env{'request.role.adv'}) {
if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
@@ -4340,8 +4356,8 @@ END
$hiddenres = 1;
}
}
- if ($url ne '') {
- $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
+ if (($url ne '') && ($shownsymb ne '')) {
+ $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
}
}
} elsif ($supplementalflag) {
@@ -4646,7 +4662,7 @@ $form_end;
my ($enctext,$hidtext,$formhidden,$formurlhidden);
if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
$hidtext = ' checked="checked"';
- if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
+ if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
push(@{$filtersref->{'hiddenresource'}},$orderidx);
}
}
@@ -5718,6 +5734,7 @@ 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()) };
@@ -5951,8 +5968,19 @@ sub handler {
}
}
my $tabidstr = join("','",@tabids);
- %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
- my $posslti = keys(%ltitools);
+ 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).
@@ -6156,6 +6184,7 @@ sub handler {
'dire' => 'Directory:',
'cate' => 'Category:',
'tmpl' => 'Template:',
+ 'empd' => 'No resources found',
'comment' => 'Comment',
'parse' => 'Upload embedded images/multimedia files if HTML file',
'bb5' => 'Blackboard 5',
@@ -6304,13 +6333,20 @@ SEDFFORM
CRSFORM
@@ -6532,165 +6568,62 @@ NROSTFORM
NWEBFORM
my @ids=&Apache::lonnet::current_machine_ids();
- my (%select_menus,$rolehomes);
- my $numauthor = 0;
- my $numcrsdirs = 0;
- my ($showstdprob,$showswitch,$switchlink);
- my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
- my $exclude = &Apache::lonnet::priv_exclude();
+ my $machines_str = "'".join("','",@ids)."'";
+ my (%is_home,%toppath,$rolehomes);
if ($env{'user.author'}) {
- $numauthor ++;
- $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
- my $is_home = 1;
- my %subdirs;
- &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
- $select_menus{'author'}->{'default'} = '/';
- my @ordered = ();
- foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
- $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
- push(@ordered,$relpath);
- }
- $select_menus{'author'}->{'order'} = \@ordered;
- $showstdprob = 'block';
- } else {
- $rolehomes = ''."\n";
- $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
- $select_menus{'author'}->{'default'} = 'switch';
- $select_menus{'author'}->{'order'} = ['switch'];
- $showstdprob = 'none';
+ $is_home{'author'} = 1;
}
+ $rolehomes = ''."\n";
}
my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
['active'],['ca','aa']);
- my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
- my (%by_roletype,%at_home);
+ my %by_roletype;
if (keys(%roleshash)) {
foreach my $entry (keys(%roleshash)) {
my ($auname,$audom,$roletype) = split(/:/,$entry);
my $key = $entry;
$key =~ s/:/___/g;
- $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
- $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
+ my $author = $auname.'___'.$audom;
+ $by_roletype{$roletype}{$author} = 1;
my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
- if (grep(/^\Q$rolehome\E$/,@ids)) {
- $at_home{$auname.'___'.$audom} = 1;
- my $is_home = 1;
- my (%subdirs,@ordered);
- my $toppath="/priv/$audom/$auname";
- &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
- $select_menus{$key}->{'default'} = '/';
- foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
- $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
- push(@ordered,$relpath);
- }
- $select_menus{$key}->{'order'} = \@ordered;
- } else {
- $rolehomes .= ''."\n";
- $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
- $select_menus{$key}->{'default'} = 'switch';
- $select_menus{$key}->{'order'} = ['switch'];
- }
- $numauthor ++;
- }
- }
- my ($pickdir,$showtitle);
- if ($numauthor) {
- my @order;
- my $defrole;
- if ($env{'user.author'}) {
- push(@order,'author');
- $defrole = 'author';
- }
- if (keys(%by_roletype)) {
- foreach my $possrole ('ca','aa') {
- if (ref($by_roletype{$possrole}) eq 'HASH') {
- foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
- unless ($defrole) {
- $defrole = $author;
- if ($at_home{$author}) {
- $showstdprob = 'block';
- } else {
- $showstdprob = 'none';
- }
- }
- push(@order,$author.'___'.$possrole);
- }
- }
+ $toppath{$author} = "/priv/$audom/$auname";
+ if (grep(/^\Q$rolehome\E$/,@ids)) {
+ $is_home{$author} = 1;
}
+ $rolehomes .= ''."\n";
}
- $select_menus{'course'}->{'text'} = &mt('Course Resource');
- if (grep(/^\Q$crshome\E$/,@ids)) {
- my $is_home = 1;
- my %subdirs;
- my $toppath="/priv/$coursedom/$coursenum";
- &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
- $numcrsdirs = keys(%subdirs);
- $select_menus{'course'}->{'default'} = '/';
- my @ordered = ();
- foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
- $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
- push(@ordered,$relpath);
- }
- $select_menus{'course'}->{'order'} = \@ordered;
- } else {
- $rolehomes .= ''."\n";
- $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
- $select_menus{'course'}->{'default'} = 'switch';
- $select_menus{'course'}->{'order'} = ['switch'];
- }
- push(@order,'course');
- $pickdir = $lt{'loca'}.
- &Apache::loncommon::linked_select_forms('courseresform','
'.$lt{'dire'},
- $defrole,'authorrole','authorpath',
- \%select_menus,\@order,'toggleCrsResTitle();',
- '','priv').'
';
- $showtitle = 'none';
- } else {
- my $is_home;
- $showtitle = 'inline';
- if (grep(/^\Q$crshome\E$/,@ids)) {
- $is_home = 1;
- $showstdprob = 'block';
- $pickdir .= '';
- my $toppath="/priv/$coursedom/$coursenum'}";
- my %subdirs;
- &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
- $numcrsdirs = keys(%subdirs);
- if ($numcrsdirs) {
- $pickdir .= $lt{'dire'}.'
'."\n".
+ $lt{'dire'}.
+ ''.
+ ''.
+ '
'."\n";
my %seltemplate_menus;
my @files = &Apache::lonhomework::get_template_list('problem');
@@ -6733,7 +6666,7 @@ NWEBFORM
my $templatepreview = ''.
''.&mt('Example').'';
my $crsresform=(<