--- loncom/interface/londocs.pm 2015/09/12 15:47:57 1.597
+++ loncom/interface/londocs.pm 2016/03/18 21:59:42 1.599
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.597 2015/09/12 15:47:57 raeburn Exp $
+# $Id: londocs.pm,v 1.599 2016/03/18 21:59:42 damieng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -586,7 +586,7 @@ sub recurse_html {
}
sub group_import {
- my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
+ my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
%removeparam,$importuploaded,$fixuperrors);
$allmaps = {};
@@ -615,6 +615,39 @@ sub group_import {
}
}
if ($url) {
+ if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
+ $url = $1;
+ my $marker = $2;
+ my $info = $3;
+ my ($toolid,%toolhash);
+ my @toolinfo = split(/:/,$info);
+ if ($residx) {
+ my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
+ $toolid = $toolsettings{'id'};
+ } else {
+ $toolid = shift(@toolinfo);
+ }
+ $toolid =~ s/\D//g;
+ ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}) = @toolinfo;
+ if (ref($ltitoolsref) eq 'HASH') {
+ if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
+ if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
+ $url =~ s/exttool$/exttools/;
+ }
+ $toolhash{'id'} = $toolid;
+ if ($toolhash{'target'} eq 'iframe') {
+ delete($toolhash{'width'});
+ delete($toolhash{'height'});
+ } elsif ($toolhash{'target'} eq 'window') {
+ foreach my $item ('width','height') {
+ $toolhash{$item} =~ s/^\s+//;
+ $toolhash{$item} =~ s/\s+$//;
+ }
+ }
+ my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
+ }
+ }
+ }
if (($caller eq 'londocs') &&
($folder =~ /^default/)) {
if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
@@ -652,7 +685,7 @@ sub group_import {
} else {
$fname =~ s/\W/_/g;
}
- if (length($fname > 15)) {
+ if (length($fname) > 15) {
$fname = substr($fname,0,14);
}
my $initialtext = &mt('Replace with your own content.');
@@ -1150,10 +1183,12 @@ sub print_paste_buffer {
($url ne '')) {
$clipboardcount ++;
my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
- $canpaste,$nopaste,$othercrs,$areachange);
+ $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
$is_external = 1;
+ } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
+ $is_exttool = 1;
}
if ($folder =~ /^supplemental/) {
$canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
@@ -1202,7 +1237,7 @@ sub print_paste_buffer {
}
}
my $buffer;
- if ($is_external) {
+ if (($is_external) || ($is_exttool)) {
$buffer = &mt('External Resource').': '.
&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
&LONCAPA::map::qtescape($url).')';
@@ -1362,7 +1397,8 @@ sub supp_pasteable {
(($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
- ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
+ ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
+ ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
return 1;
}
return;
@@ -2880,7 +2916,7 @@ sub handle_edit_cmd {
sub editor {
my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
- $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
+ $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref)=@_;
my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
if ($allowed) {
(my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
@@ -3079,6 +3115,17 @@ sub editor {
} else {
return $errortxt;
}
+ } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
+ my ($suffix,$errortxt,$locknotfreed) =
+ &new_timebased_suffix($coursedom,$coursenum,'exttool');
+ if ($locknotfreed) {
+ $r->print($locknotfreed);
+ }
+ if ($suffix) {
+ $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
+ } else {
+ return $errortxt;
+ }
} elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
if ($supplementalflag) {
next unless ($1 eq 'supplemental');
@@ -3101,7 +3148,7 @@ sub editor {
}
($errtext,$fatal,my $fixuperrors) =
&group_import($coursenum, $coursedom, $folder,$container,
- 'londocs',@imports);
+ 'londocs',$ltitoolsref,@imports);
return $errtext if ($fatal);
if ($fixuperrors) {
$r->print($fixuperrors);
@@ -3186,7 +3233,7 @@ sub editor {
$output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
$coursenum,$coursedom,$crstype,
$pathitem,$supplementalflag,$container,
- \%filters,\%curr_groups);
+ \%filters,\%curr_groups,$ltitoolsref);
$idx++;
$shown++;
}
@@ -3552,7 +3599,8 @@ sub is_supplemental_title {
sub entryline {
my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
- $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups)=@_;
+ $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
+ $ltitoolsref)=@_;
my ($foldertitle,$renametitle,$oldtitle);
if (&is_supplemental_title($title)) {
($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
@@ -3643,6 +3691,7 @@ END
'rn' => 'Rename',
'cp' => 'Copy',
'ex' => 'External Resource',
+ 'et' => 'External Tool',
'ed' => 'Edit',
'pr' => 'Preview',
'sv' => 'Save',
@@ -3660,6 +3709,7 @@ END
|/aboutme$
|/navmaps$
|/bulletinboard$
+ |/exttools?$
|\.html$)}x)
|| $isexternal) {
$skip_confirm = 1;
@@ -3796,7 +3846,9 @@ END
}
} elsif ($url=~m|^/ext/|) {
$url='/adm/wrapper'.$url;
- }
+ } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
+ $url='/adm/wrapper'.$url;
+ }
if (&Apache::lonnet::symbverify($symb,$url)) {
$url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
} else {
@@ -3862,12 +3914,17 @@ $form_common."\n".
$form_end;
}
} elsif ($supplementalflag && !$allowed) {
+ my $isexttool;
+ if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
+ $url='/adm/wrapper'.$url;
+ $isexttool = 1;
+ }
$url .= ($url =~ /\?/) ? '&':'?';
$url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
if ($title) {
$url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
}
- if ($isexternal && $orderidx) {
+ if ((($isexternal) || ($isexttool)) && $orderidx) {
$url .= '&idx='.$orderidx;
}
}
@@ -3878,6 +3935,11 @@ $form_end;
if ($isexternal) {
($editlink,$extresform) =
&Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
+ } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
+ ($editlink,$extresform) =
+ &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
+ undef,undef,undef,'tool',$coursedom,
+ $coursenum,$ltitoolsref);
} elsif (!$isfolder && !$ispage) {
my ($cfile,$home,$switchserver,$forceedit,$forceview) =
&Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
@@ -4789,6 +4851,7 @@ sub handler {
my $container;
my $containertag;
my $pathitem;
+ my %ltitools;
# Do we directly jump somewhere?
@@ -4926,11 +4989,13 @@ sub handler {
}
}
my $tabidstr = join("','",@tabids);
+ %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
+ my $exttoolurl = "/adm/$coursedom/$coursenum/new/exttool";
$script .= &editing_js($udom,$uname,$supplementalflag).
&history_tab_js().
&inject_data_js().
&Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
- &Apache::lonextresedit::extedit_javascript();
+ &Apache::lonextresedit::extedit_javascript(\%ltitools);
$addentries = {
onload => "javascript:resize_scrollbox('contentscroll','1','1');",
};
@@ -5048,6 +5113,8 @@ sub handler {
'impo' => 'Import',
'lnks' => 'Import from Stored Links',
'impm' => 'Import from Assembled Map',
+ 'extr' => 'External Resource',
+ 'extt' => 'External Tool',
'selm' => 'Select Map',
'load' => 'Load Map',
'newf' => 'New Folder',
@@ -5191,6 +5258,11 @@ SEDFFORM
my $extresourcesform =
&Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
$help{'Adding_External_Resource'});
+ my $exttoolform =
+ &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
+ $help{'Adding_External_Tool'},undef,
+ undef,'tool',$coursedom,$coursenum,
+ \%ltitools);
if ($allowed) {
my $folder = $env{'form.folder'};
if ($folder eq '') {
@@ -5436,6 +5508,11 @@ NGFFORM
my @importdoc = (
{''=>$extresourcesform}
);
+ if (keys(%ltitools)) {
+ push(@importdoc,
+ {'
'=>$exttoolform},
+ );
+ }
unless ($container eq 'page') {
push(@importdoc,
{'
'=>$imspform}
@@ -5477,7 +5554,7 @@ unless ($container eq 'page') {
$hadchanges=0;
unless (($supplementalflag || $toolsflag)) {
my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
- $supplementalflag,\%orderhash,$iconpath,$pathitem);
+ $supplementalflag,\%orderhash,$iconpath,$pathitem,\%ltitools);
if ($error) {
$r->print('
'.$error.'
'); } @@ -5544,6 +5621,12 @@ SNFFORM &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, $help{'Adding_External_Resource'}); + my $supexttoolform = + &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, + $help{'Adding_External_Tool'}, + undef,undef,'tool',$coursedom, + $coursenum,\%ltitools); + my $supnewsylform=(<'.$error.'
'); } else { @@ -6072,12 +6161,12 @@ sub editing_js { $backtourl = '/adm/navmaps'; } - my $fieldsets = "'ext','doc'"; + my $fieldsets = "'ext','tool','doc'"; unless ($main_container_page) { $fieldsets .=",'ims'"; } if ($supplementalflag) { - $fieldsets = "'suppext','suppdoc'"; + $fieldsets = "'suppext','supptool','suppdoc'"; } return <