[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom loncapa_apache.conf loncom/homework edit.pm imageresponse.pm randomlabel.pm loncom/interface filecategories.tab loncommon.pm londocs.pm loncom/lonnet/perl lonnet.pm loncom/publisher loncoursepub.pm loncom/xml londefdef.pm scripttag.pm
raeburn
raeburn at source.lon-capa.org
Fri Jul 1 16:00:16 EDT 2016
raeburn Fri Jul 1 20:00:16 2016 EDT
Added files:
/loncom/publisher loncoursepub.pm
Modified files:
/loncom/homework imageresponse.pm randomlabel.pm edit.pm
/loncom/xml scripttag.pm londefdef.pm
/loncom/interface loncommon.pm londocs.pm filecategories.tab
/loncom/lonnet/perl lonnet.pm
/loncom loncapa_apache.conf
/doc/loncapafiles loncapafiles.lpml
Log:
- Course "Authoring" Space
"Import a File" and "Image" blocks in Colorful Editor include a "Choose File"
link which allows selection of published files from "Course Authoring" Space,
or upload of a new file (with auto-publication).
-------------- next part --------------
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.105 loncom/homework/imageresponse.pm:1.106
--- loncom/homework/imageresponse.pm:1.105 Tue Apr 30 03:03:34 2013
+++ loncom/homework/imageresponse.pm Fri Jul 1 19:59:15 2016
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# image click response style
#
-# $Id: imageresponse.pm,v 1.105 2013/04/30 03:03:34 raeburn Exp $
+# $Id: imageresponse.pm,v 1.106 2016/07/01 19:59:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -752,9 +752,8 @@
$Apache::edit::bgimgsrcdepth=$Apache::lonxml::curdepth;
$result=&Apache::edit::tag_start($target,$token,'Clickable Image').
- &Apache::edit::editline($token->[1],$bgimg,'Image Source File',40);
- $result.=&Apache::edit::browse(undef,'textnode',undef,$only).' ';
- $result.=&Apache::edit::search(undef,'textnode').
+ &Apache::edit::editline($token->[1],$bgimg,'Image Source File',40).
+ &Apache::edit::browse_or_search(undef,'textnode',undef,$only,undef,1).
&Apache::edit::end_row();
} elsif ($target eq "modified") {
$result=$token->[4].&Apache::edit::modifiedfield('/image',$parser);
Index: loncom/homework/randomlabel.pm
diff -u loncom/homework/randomlabel.pm:1.96 loncom/homework/randomlabel.pm:1.97
--- loncom/homework/randomlabel.pm:1.96 Mon Nov 14 02:17:47 2011
+++ loncom/homework/randomlabel.pm Fri Jul 1 19:59:15 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# random labelling tool
#
-# $Id: randomlabel.pm,v 1.96 2011/11/14 02:17:47 raeburn Exp $
+# $Id: randomlabel.pm,v 1.97 2016/07/01 19:59:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -193,9 +193,9 @@
$Apache::edit::bgimgsrc=
&Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
$Apache::edit::bgimgsrccurdepth=$Apache::lonxml::curdepth;
- $result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' ';
- $result.=&Apache::edit::browse('bgimg',undef,undef,$only).' ';
- $result.=&Apache::edit::search('bgimg').'<br />'.
+ $result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' '.
+ &Apache::edit::browse_or_search('bgimg',undef,undef,$only,undef,1).
+ '<br />'.
&Apache::edit::text_arg('Width(pixel):' ,'width' ,$token,6).
&Apache::edit::text_arg('Height(pixel):','height' ,$token,6).
&Apache::edit::text_arg('TeXWidth(mm):' ,'texwidth',$token,6).
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.153 loncom/homework/edit.pm:1.154
--- loncom/homework/edit.pm:1.153 Mon Jan 19 15:35:53 2015
+++ loncom/homework/edit.pm Fri Jul 1 19:59:15 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# edit mode helpers
#
-# $Id: edit.pm,v 1.153 2015/01/19 15:35:53 goltermann Exp $
+# $Id: edit.pm,v 1.154 2016/07/01 19:59:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -134,10 +134,11 @@
use strict;
use Apache::lonnet;
+use Apache::loncommon;
use HTML::Entities();
use Apache::lonlocal;
use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
# Global Vars
@@ -1195,52 +1196,162 @@
&Apache::lonnet::delenv('imagechoice.');
}
+#----------------------------------------------------- browse and search links
+sub browse_or_search {
+ my ($id,$mode,$titleid,$only,$crsonly,$usesearch) = @_;
+ my $output;
+ my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url();
+ if ($cnum) {
+ my $form = 'lonhomework';
+ my ($element,$bretitleelement,$srchtitleelement);
+ $element = &get_element($id,$mode);
+ my %lt = &Apache::lonlocal::texthash (
+ uacf => 'Use a course file',
+ uanf => 'Use a new file',
+ impo => 'Import',
+ sear => 'Search',
+ sefi => 'Select File',
+ upfi => 'Upload File',
+ dire => 'Directory',
+ news => 'New sub-directory',
+ );
+ my ($importcrsres,$uploadfile,$allonly);
+ if ($only) {
+ $allonly = $only;
+ if ($crsonly) {
+ $allonly .= ','.$crsonly;
+ }
+ } elsif ($crsonly) {
+ $allonly = $crsonly;
+ }
+ my ($numdirs,$pickfile) =
+ &Apache::loncommon::import_crsauthor_form($form,'coursepath_'.$element,'coursefile_'.$element,undef,$allonly,$element);
+ if ($pickfile) {
+ $importcrsres=(<<CRSRES);
+ <fieldset id="importcrsresform_$element" style="display:inline;">
+ <legend>$lt{'uacf'}</legend>
+ $pickfile
+ <input type="button" name="crsres" value="$lt{'sefi'}" onclick="updateCrsFile(this.form,'$element');" />
+ </fieldset>
+CRSRES
+ }
+ my %subdirs;
+ my $toppath="/priv/$cdom/$cnum";
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ &Apache::lonnet::recursedirs(1,'priv',$londocroot,$toppath,'',\%subdirs);
+ my $numcrsdirs = keys(%subdirs);
+ my $pickdir;
+ if ($numcrsdirs) {
+ $pickdir = $lt{'dire'}.'<select name="crsauthorpath_'.$element.'">'."\n".
+ '<option value="/">/</option>'."\n";
+ foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
+ $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
+ }
+ $pickdir .= '</select><br />';
+ } else {
+ $pickdir = '<input type="hidden" name="crsauthorpath_'.$element.'" value="/" />'."\n";
+ }
+ my $uploadfile =(<<CRSUPL);
+ <fieldset id="uploadcrsresform_$element" style="display:inline;">
+ <legend>$lt{'uanf'}</legend>
+ <p>
+ $pickdir
+ <span class="LC_nobreak">$lt{'news'}?
+ <label><input type="radio" name="newsubdir_$element" value="0" onclick="toggleNewsubdir(this.form,'$element');" checked="checked" />No</label>
+
+ <label><input type="radio" name="newsubdir_$element" value="1" onclick="toggleNewsubdir(this.form,'$element');" />Yes</label>
+ </span><span id="newsubdir_$element"></span>
+ <input type="hidden" name="newsubdirname_$element" id="newsubdirname_$element" value="" autocomplete="off" />
+ </p>
+ <input type="file" id="uploadcrsres_$element" name="uploadcrsres_$element" size="40" />
+ <input type="hidden" id="crsuploadto_$element" name="filename_$element" value="$ENV{'REQUEST_URI'}" />
+ <input type="submit" id="crsupload_$element" class="LC_uploadcrsres" value="$lt{'upfi'}" />
+ <iframe id="crsupload_target_$element" name="crsupload_target_$element" src="" style="width:0px;height:0px;border:0px"></iframe>
+ </fieldset>
+CRSUPL
+ if ($titleid) {
+ $bretitleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
+ $srchtitleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
+ } else {
+ $bretitleelement=",'$only'";
+ }
+ $output = '<a href="javascript:toggleChooser(document.'.$form.",'$element'".');">'.
+ &mt('Choose File').'</a>'.
+ '<div id="chooser_'.$element.'" style="display:none" class="LC_left_float">'.
+ '<fieldset><legend>'.&mt('Choose File').'</legend>';
+ if ($numdirs) {
+ $output .= '<label><input type="radio" name="chooser_'.$element.'" value="crsres" onclick="toggleCrsFile(this.form,'."'$element','$numdirs'".')" />'.$lt{'uacf'}.'</label> ';
+ }
+ $output .= '<label><input type="radio" name="chooser_'.$element.'" value="upload" onclick="toggleCrsUpload(this.form,'."'$element','$numcrsdirs'".')" />'.$lt{'uanf'}.'</label> '.
+ '<label><input type="radio" name="chooser_'.$element.'" value="import" onclick="toggleResImport(this.form,'."'$element'".');openbrowser('."'$form','$element'$bretitleelement)".'" />'.$lt{'impo'}.'</label>';
+ if ($usesearch) {
+ $output .= ' <label><input type="radio" name="chooser_'.$element.'" value="search" onclick="opensearcher('."'$form','$element'$srchtitleelement".')" />'.$lt{'sear'}.'</label>';
+ }
+ $output .= '<div id="chooser_'.$element.'_crsres" style="display:none">'.
+ $importcrsres.
+ '</div>'.
+ '<div id="chooser_'.$element.'_upload" style="display:none">'.
+ $uploadfile.
+ '</div>'.
+ '</fieldset></div>';
+
+ } else {
+ $output = &browse($id, $mode, $titleid, $only);
+ if ($usesearch) {
+ $output .= ' '.&search($id, $mode, $titleid);
+ }
+ }
+ return $output;
+}
+
#----------------------------------------------------- browse
sub browse {
# insert a link to call up the filesystem browser (lonindexer)
my ($id, $mode, $titleid, $only) = @_;
+ my %lt = &Apache::lonlocal::texthash (
+ se => 'Select',
+ );
my $form = 'lonhomework';
- my $element;
- if (! defined($mode) || $mode eq 'attribute') {
- $element = &escape("$id\_$Apache::lonxml::curdepth");
- } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
- $element = &escape('homework_edit_'.
- $Apache::lonxml::curdepth);
- }
+ my $element = &get_element($id,$mode);
my $titleelement;
if ($titleid) {
$titleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
} else {
$titleelement=",'$only'";
}
- my $result = <<"ENDBUTTON";
-<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>Select</a>
+ return <<"ENDBUTTON";
+<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>$lt{'se'}</a>
ENDBUTTON
- return $result;
}
-#----------------------------------------------------- browse
+#----------------------------------------------------- search
sub search {
# insert a link to call up the filesystem browser (lonindexer)
my ($id, $mode, $titleid) = @_;
my $form = 'lonhomework';
- my $element;
- if (! defined($mode) || $mode eq 'attribute') {
- $element = &escape("$id\_$Apache::lonxml::curdepth");
- } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
- $element = &escape('homework_edit_'.
- $Apache::lonxml::curdepth);
- }
+ my $element = &get_element($id,$mode);
my $titleelement;
if ($titleid) {
$titleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
}
+ my $linktext = &mt('Search');
my $result = <<"ENDBUTTON";
-<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>Search</a>
+<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>$linktext</a>
ENDBUTTON
return $result;
}
+sub get_element {
+ my ($id,$mode) = @_;
+ my $element;
+ if (! defined($mode) || $mode eq 'attribute') {
+ $element = &escape("$id\_$Apache::lonxml::curdepth");
+ } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
+ $element = &escape('homework_edit_'.
+ $Apache::lonxml::curdepth);
+ }
+ return $element;
+}
1;
__END__
Index: loncom/xml/scripttag.pm
diff -u loncom/xml/scripttag.pm:1.174 loncom/xml/scripttag.pm:1.175
--- loncom/xml/scripttag.pm:1.174 Mon Apr 6 16:27:12 2015
+++ loncom/xml/scripttag.pm Fri Jul 1 19:59:25 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# <script> definiton
#
-# $Id: scripttag.pm,v 1.174 2015/04/06 16:27:12 raeburn Exp $
+# $Id: scripttag.pm,v 1.175 2016/07/01 19:59:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -364,7 +364,7 @@
$result=
&Apache::edit::tag_start($target,$token,'New Script Functions').
&Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
- &Apache::edit::browse(undef,'textnode').
+ &Apache::edit::browse_or_search(undef,'textnode').
$error.'</td></tr>'.
&Apache::edit::end_table();
}
@@ -616,9 +616,11 @@
my $location=$token->[1];
$location=~s/^\s*//s;
$location=~s/\s*$//s;
+ my $crsonly = join(',',(&Apache::loncommon::filecategorytypes('Problem'),
+ &Apache::loncommon::filecategorytypes('Library')));
$result.=&Apache::edit::editline($location,$bodytext,'',40);
- $result.=&Apache::edit::browse(undef,'textnode');
- $result.= ' <label>'.&mt('Import as:').
+ $result.=&Apache::edit::browse_or_search(undef,'textnode',undef,undef,$crsonly);
+ $result.= ' <span class="LC_nobreak"><label>'.&mt('Import as:').
'<select name="importmode_'.$Apache::lonxml::curdepth.'">';
my %options=&Apache::lonlocal::texthash('' => 'as standard library',
'problem' => 'as problem',
@@ -630,7 +632,7 @@
}
$result.='>'.$options{$option}.'</option>';
}
- $result.='</select></label>';
+ $result.='</select></label></span>';
#FIXME this need to convert $bodytext to be a contruction space reference
#my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
#$result.="Click<a href=\"$location\">here</a> to edit<br />"
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.458 loncom/xml/londefdef.pm:1.459
--- loncom/xml/londefdef.pm:1.458 Thu Jan 14 19:40:26 2016
+++ loncom/xml/londefdef.pm Fri Jul 1 19:59:25 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.458 2016/01/14 19:40:26 damieng Exp $
+# $Id: londefdef.pm,v 1.459 2016/07/01 19:59:25 raeburn Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -2872,8 +2872,8 @@
my $only = join(',',&Apache::loncommon::filecategorytypes('Pictures'));
$currentstring .=&Apache::edit::tag_start($target,$token);
$currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
- &Apache::edit::browse('src',undef,'alt',$only).' '.
- &Apache::edit::search('src',undef,'alt').'<br />';
+ &Apache::edit::browse_or_search('src',undef,'alt',$only,undef,1).
+ '<br />';
$currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
$currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
$currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
@@ -2895,17 +2895,19 @@
my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
-
+ my $element = &Apache::edit::get_element('src');
+ my $text;
if ($token->[2]{'src'}=~/\$/) {
- $currentstring.=&mt('Variable image source');
+ $text = &mt('Variable image source');
} elsif ($token->[2]{'src'}=~/\S/) {
$currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
if ($width) { $currentstring.=' width="'.$width.'" '; }
if ($height) { $currentstring.=' height="'.$height.'" '; }
- $currentstring .= ' />';
+ $currentstring .= ' id="previewimg_'.$element.'" />';
} else {
- $currentstring.=&mt("No image source specified");
+ $text = &mt("No image source specified");
}
+ $currentstring .= ' <span id="showimg_'.$element.'">'.$text.'</span>';
} elsif ($target eq 'modified') {
my ($osrc,$owidth,$oheight)=
($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1247 loncom/interface/loncommon.pm:1.1248
--- loncom/interface/loncommon.pm:1.1247 Mon Jun 20 15:35:42 2016
+++ loncom/interface/loncommon.pm Fri Jul 1 19:59:35 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1247 2016/06/20 15:35:42 raeburn Exp $
+# $Id: loncommon.pm,v 1.1248 2016/07/01 19:59:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1775,6 +1775,162 @@
}
sub colorfuleditor_js {
+ my $browse_or_search;
+ my $respath;
+ my ($cnum,$cdom) = &crsauthor_url();
+ if ($cnum) {
+ $respath = "/res/$cdom/$cnum/";
+ my %js_lt = &Apache::lonlocal::texthash(
+ sunm => 'Sub-directory name',
+ save => 'Save page to make this permanent',
+ );
+ &js_escape(\%js_lt);
+ $browse_or_search = <<"END";
+
+ function toggleChooser(form,element,titleid,only,search) {
+ var disp = 'none';
+ if (document.getElementById('chooser_'+element)) {
+ var curr = document.getElementById('chooser_'+element).style.display;
+ if (curr == 'none') {
+ disp='inline';
+ if (form.elements['chooser_'+element].length) {
+ for (var i=0; i<form.elements['chooser_'+element].length; i++) {
+ form.elements['chooser_'+element][i].checked = false;
+ }
+ }
+ toggleResImport(form,element);
+ }
+ document.getElementById('chooser_'+element).style.display = disp;
+ }
+ }
+
+ function toggleCrsFile(form,element,numdirs) {
+ if (document.getElementById('chooser_'+element+'_crsres')) {
+ var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
+ if (curr == 'none') {
+ if (numdirs) {
+ form.elements['coursepath_'+element].selectedIndex = 0;
+ if (numdirs > 1) {
+ window['select1'+element+'_changed']();
+ }
+ }
+ }
+ document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
+
+ }
+ if (document.getElementById('chooser_'+element+'_upload')) {
+ document.getElementById('chooser_'+element+'_upload').style.display = 'none';
+ if (document.getElementById('uploadcrsres_'+element)) {
+ document.getElementById('uploadcrsres_'+element).value = '';
+ }
+ }
+ return;
+ }
+
+ function toggleCrsUpload(form,element,numcrsdirs) {
+ if (document.getElementById('chooser_'+element+'_crsres')) {
+ document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
+ }
+ if (document.getElementById('chooser_'+element+'_upload')) {
+ var curr = document.getElementById('chooser_'+element+'_upload').style.display;
+ if (curr == 'none') {
+ if (numcrsdirs) {
+ form.elements['crsauthorpath_'+element].selectedIndex = 0;
+ form.elements['newsubdir_'+element][0].checked = true;
+ toggleNewsubdir(form,element);
+ }
+ }
+ document.getElementById('chooser_'+element+'_upload').style.display = 'block';
+ }
+ return;
+ }
+
+ function toggleResImport(form,element) {
+ var choices = new Array('crsres','upload');
+ for (var i=0; i<choices.length; i++) {
+ if (document.getElementById('chooser_'+element+'_'+choices[i])) {
+ document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
+ }
+ }
+ }
+
+ function toggleNewsubdir(form,element) {
+ var newsub = form.elements['newsubdir_'+element];
+ if (newsub) {
+ if (newsub.length) {
+ for (var j=0; j<newsub.length; j++) {
+ if (newsub[j].checked) {
+ if (document.getElementById('newsubdirname_'+element)) {
+ if (newsub[j].value == '1') {
+ document.getElementById('newsubdirname_'+element).type = "text";
+ if (document.getElementById('newsubdir_'+element)) {
+ document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
+ }
+ } else {
+ document.getElementById('newsubdirname_'+element).type = "hidden";
+ document.getElementById('newsubdirname_'+element).value = "";
+ document.getElementById('newsubdir_'+element).innerHTML = "";
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ function updateCrsFile(form,element) {
+ var directory = form.elements['coursepath_'+element];
+ var filename = form.elements['coursefile_'+element];
+ var path = directory.options[directory.selectedIndex].value;
+ var file = filename.options[filename.selectedIndex].value;
+ form.elements[element].value = '$respath';
+ if (path == '/') {
+ form.elements[element].value += file;
+ } else {
+ form.elements[element].value += path+'/'+file;
+ }
+ unClean();
+ if (document.getElementById('previewimg_'+element)) {
+ document.getElementById('previewimg_'+element).src = form.elements[element].value;
+ var newsrc = document.getElementById('previewimg_'+element).src;
+ }
+ if (document.getElementById('showimg_'+element)) {
+ document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
+ }
+ toggleChooser(form,element);
+ return;
+ }
+
+ function uploadDone(suffix,name) {
+ if (name) {
+ document.forms["lonhomework"].elements[suffix].value = name;
+ unClean();
+ toggleChooser(document.forms["lonhomework"],suffix);
+ }
+ }
+
+\$(document).ready(function(){
+
+ \$(document).delegate('form :submit', 'click', function( event ) {
+ if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
+ var buttonId = this.id;
+ var suffix = buttonId.toString();
+ suffix = suffix.replace(/^crsupload_/,'');
+ event.preventDefault();
+ document.lonhomework.target = 'crsupload_target_'+suffix;
+ document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
+ \$(this.form).submit();
+ document.lonhomework.target = '';
+ if (document.getElementById('crsuploadto_'+suffix)) {
+ document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
+ }
+ return false;
+ }
+ });
+});
+END
+ }
return <<"COLORFULEDIT"
<script type="text/javascript">
// <![CDATA[>
@@ -1957,7 +2113,7 @@
}
}
-
+$browse_or_search
// ]]>
</script>
@@ -2009,6 +2165,130 @@
value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
}
+sub crsauthor_url {
+ my ($url) = @_;
+ if ($url eq '') {
+ $url = $ENV{'REQUEST_URI'};
+ }
+ my ($cnum,$cdom);
+ if ($env{'request.course.id'}) {
+ my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
+ if ($audom ne '' && $auname ne '') {
+ if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
+ ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
+ $cnum = $auname;
+ $cdom = $audom;
+ }
+ }
+ }
+ return ($cnum,$cdom);
+}
+
+sub import_crsauthor_form {
+ my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix) = @_;
+ return (0) unless ($env{'request.course.id'});
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
+ return (0) unless (($cnum ne '') && ($cdom ne ''));
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my @ids=&Apache::lonnet::current_machine_ids();
+ my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
+
+ if (grep(/^\Q$crshome\E$/, at ids)) {
+ $is_home = 1;
+ }
+ $relpath = "/priv/$cdom/$cnum";
+ &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
+ my %lt = &Apache::lonlocal::texthash (
+ fnam => 'Filename',
+ dire => 'Directory',
+ );
+ my $numdirs = scalar(keys(%files));
+ my (%possexts,$singledir, at singledirfiles);
+ if ($only) {
+ map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
+ }
+ my (%nonemptydirs,$possdirs);
+ if ($numdirs > 1) {
+ my @order;
+ foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
+ if (ref($files{$key}) eq 'HASH') {
+ my $shown = $key;
+ if ($key eq '') {
+ $shown = '/';
+ }
+ my @ordered = ();
+ foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
+ if ($only) {
+ my ($ext) = ($file =~ /\.([^.]+)$/);
+ unless ($possexts{lc($ext)}) {
+ next;
+ }
+ }
+ $selimport_menus{$key}->{'select2'}->{$file} = $file;
+ push(@ordered,$file);
+ }
+ if (@ordered) {
+ push(@order,$key);
+ $nonemptydirs{$key} = 1;
+ $selimport_menus{$key}->{'text'} = $shown;
+ $selimport_menus{$key}->{'default'} = '';
+ $selimport_menus{$key}->{'select2'}->{''} = '';
+ $selimport_menus{$key}->{'order'} = \@ordered;
+ }
+ }
+ }
+ $possdirs = scalar(keys(%nonemptydirs));
+ if ($possdirs > 1) {
+ my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
+ $output = $lt{'dire'}.
+ &linked_select_forms($form,'<br />'.
+ $lt{'fnam'},'',
+ $firstselectname,$secondselectname,
+ \%selimport_menus,\@order,
+ $onchangefirst,'',$suffix).'<br />';
+ } elsif ($possdirs == 1) {
+ $singledir = (keys(%nonemptydirs))[0];
+ if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
+ @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
+ }
+ delete($selimport_menus{$singledir});
+ }
+ } elsif ($numdirs == 1) {
+ $singledir = (keys(%files))[0];
+ foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
+ if ($only) {
+ my ($ext) = ($file =~ /\.([^.]+)$/);
+ unless ($possexts{lc($ext)}) {
+ next;
+ }
+ }
+ push(@singledirfiles,$file);
+ }
+ if (@singledirfiles) {
+ $possdirs == 1;
+ }
+ }
+ if (($possdirs == 1) && (@singledirfiles)) {
+ my $showdir = $singledir;
+ if ($singledir eq '') {
+ $showdir = '/';
+ }
+ $output = $lt{'dire'}.
+ '<select name="'.$firstselectname.'">'.
+ '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
+ '</select><br />'.
+ $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
+ '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
+ foreach my $file (@singledirfiles) {
+ $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
+ }
+ $output .= '</select><br />'."\n";
+ }
+ return ($possdirs,$output);
+}
+
=pod
=head1 Excel and CSV file utility routines
@@ -3874,7 +4154,11 @@
sub filecategorytypes {
my ($cat) = @_;
- return @{$category_extensions{lc($cat)}};
+ if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
+ return @{$category_extensions{lc($cat)}};
+ } else {
+ return ();
+ }
}
=pod
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.607 loncom/interface/londocs.pm:1.608
--- loncom/interface/londocs.pm:1.607 Mon Jun 20 14:26:58 2016
+++ loncom/interface/londocs.pm Fri Jul 1 19:59:36 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.607 2016/06/20 14:26:58 raeburn Exp $
+# $Id: londocs.pm,v 1.608 2016/07/01 19:59:36 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4908,8 +4908,6 @@
my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
$env{'form.folder'} = $folder;
&snapshotbefore();
- my $url = $redirect;
- $url =~ s{^/priv/}{/res/};
my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
my $ext = 'false';
my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
@@ -5394,61 +5392,11 @@
</form>
SEDFFORM
- my $is_home;
- my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
- my @ids=&Apache::lonnet::current_machine_ids();
- if (grep(/^\Q$crshome\E$/, at ids)) {
- $is_home = 1;
- }
- my (%subdirs,%files,%selimport_menus);
- my $pickfile;
- my $relpath = "/res/$coursedom/$coursenum";
- &recursedirs($is_home,'res',$londocroot,$relpath,'',\%subdirs,\%files);
- my $numdirs = scalar(keys(%files));
- if ($numdirs > 1) {
- my @order = sort { lc($a) cmp lc($b) } (keys(%files));
- foreach my $key (@order) {
- if (ref($files{$key}) eq 'HASH') {
- my $shown = $key;
- if ($key eq '') {
- $shown = '/';
- }
- $selimport_menus{$key}->{'text'} = $shown;
- $selimport_menus{$key}->{'default'} = '';
- my @ordered = ('');
- $selimport_menus{$key}->{'select2'}->{''} = '';
- foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
- $selimport_menus{$key}->{'select2'}->{$file} = $file;
- push(@ordered,$file);
- }
- $selimport_menus{$key}->{'order'} = \@ordered;
- }
- }
- $pickfile = $lt{'dire'}.
- &Apache::loncommon::linked_select_forms('crsresimportform','<br />'.
- &mt('Filename: '),'',
- 'coursepath','coursefile',
- \%selimport_menus,\@order,
- "resize_scrollbox('contentscroll','1','0');",'','res').
- '<br />';
- } elsif ($numdirs == 1) {
- my $singledir = (keys(%files))[0];
- my $showdir = $singledir;
- if ($singledir eq '') {
- $showdir = '/';
- }
- $pickfile = $lt{'dire'}.
- '<select name="coursepath">'.
- '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
- '</select><br />'.
- &mt('Filename: ').'<select name="coursefile">'."\n".
- '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
- foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
- $pickfile .= '<option value="'.$file.'">'.$file.'</option>'."\n";
- }
- $pickfile .= '</select><br />'."\n";
- }
my $importcrsresform;
+ my ($numdirs,$pickfile) =
+ &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
+ "resize_scrollbox('contentscroll','1','0');",
+ undef,'res');
if ($pickfile) {
$importcrsresform=(<<CRSFORM);
<a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
@@ -5675,7 +5623,7 @@
if (grep(/^\Q$env{'user.home'}\E$/, at ids)) {
my $is_home = 1;
my %subdirs;
- &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
+ &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
$select_menus{'author'}->{'default'} = '/';
$select_menus{'author'}->{'select2'}->{'/'} = '/';
my @ordered = ('/');
@@ -5706,7 +5654,7 @@
my $is_home = 1;
my (%subdirs, at ordered);
my $toppath="/priv/$audom/$auname";
- &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
+ &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
$select_menus{$key}->{'default'} = '/';
$select_menus{$key}->{'select2'}->{'/'} = '/';
my @ordered = ('/');
@@ -5748,7 +5696,7 @@
my $is_home = 1;
my %subdirs;
my $toppath="/priv/$coursedom/$coursenum";
- &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
+ &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
$numcrsdirs = keys(%subdirs);
$select_menus{'course'}->{'default'} = '/';
$select_menus{'course'}->{'select2'}->{'/'} = '/';
@@ -5778,13 +5726,13 @@
$pickdir .= '<input type="hidden" name="authorrole" value="course" />';
my $toppath="/priv/$coursedom/$coursenum'}";
my %subdirs;
- &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
+ &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
$numcrsdirs = keys(%subdirs);
if ($numcrsdirs) {
$pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
'<option value="/">/</option>'."\n";
foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
- $pickdir .= '<option value="'.$relpath.'</option>'."\n";
+ $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
}
$pickdir .= '</select>';
} else {
@@ -7838,87 +7786,6 @@
SIMPFORM
}
-sub recursedirs {
- my ($is_home,$context,$docroot,$toppath,$relpath,$dirhashref,$filehashref) = @_;
- return unless (ref($dirhashref) eq 'HASH');
- my $currpath = $docroot.$toppath;
- if ($relpath) {
- $currpath .= "/$relpath";
- }
- my $savefile;
- if (ref($filehashref)) {
- $savefile = 1;
- }
- if ($is_home) {
- if (opendir(my $dirh,$currpath)) {
- foreach my $item (sort { lc($a) cmp lc($b) } grep(!/^\.+$/,readdir($dirh))) {
- next if ($item eq '');
- if (-d "$currpath/$item") {
- my $newpath;
- if ($relpath) {
- $newpath = "$relpath/$item";
- } else {
- $newpath = $item;
- }
- $dirhashref->{&js_escape($newpath)} = 1;
- &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref);
- } elsif ($savefile) {
- if ($context eq 'priv') {
- unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) {
- $filehashref->{&js_escape($relpath)}{$item} = 1;
- }
- } else {
- unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/) || ($item =~ /\.rights$/)) {
- $filehashref->{&js_escape($relpath)}{$item} = 1;
- }
- }
- }
- }
- closedir($dirh);
- }
- } else {
- my ($dirlistref,$listerror) =
- &Apache::lonnet::dirlist($toppath.$relpath);
- my @dir_lines;
- my $dirptr=16384;
- if (ref($dirlistref) eq 'ARRAY') {
- foreach my $dir_line (sort
- {
- my ($afile)=split('&',$a,2);
- my ($bfile)=split('&',$b,2);
- return (lc($afile) cmp lc($bfile));
- } (@{$dirlistref})) {
- my ($item,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef) =
- split(/\&/,$dir_line,16);
- $item =~ s/\s+$//;
- next if (($item =~ /^\.\.?$/) || ($obs));
- if ($dirptr&$testdir) {
- my $newpath;
- if ($relpath) {
- $newpath = "$relpath/$item";
- } else {
- $relpath = '/';
- $newpath = $item;
- }
- $dirhashref->{&js_escape($newpath)} = 1;
- &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref);
- } elsif ($savefile) {
- if ($context eq 'priv') {
- unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) {
- $filehashref->{$relpath}{$item} = 1;
- }
- } else {
- unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/)) {
- $filehashref->{$relpath}{$item} = 1;
- }
- }
- }
- }
- }
- }
- return;
-}
-
sub makenewproblem {
my ($r,$coursedom,$coursenum) = @_;
# Creating a new problem
Index: loncom/interface/filecategories.tab
diff -u loncom/interface/filecategories.tab:1.3 loncom/interface/filecategories.tab:1.4
--- loncom/interface/filecategories.tab:1.3 Fri Jul 1 19:27:25 2016
+++ loncom/interface/filecategories.tab Fri Jul 1 19:59:36 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network
# file categories useful for searching against
#
-# $Id: filecategories.tab,v 1.3 2016/07/01 19:27:25 raeburn Exp $
+# $Id: filecategories.tab,v 1.4 2016/07/01 19:59:36 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -59,4 +59,5 @@
problem Problem
quiz Problem
exam Problem
+library Library
sequence Sequence
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1312 loncom/lonnet/perl/lonnet.pm:1.1313
--- loncom/lonnet/perl/lonnet.pm:1.1312 Sun Jun 19 04:28:19 2016
+++ loncom/lonnet/perl/lonnet.pm Fri Jul 1 19:59:46 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1312 2016/06/19 04:28:19 raeburn Exp $
+# $Id: lonnet.pm,v 1.1313 2016/07/01 19:59:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -10216,6 +10216,115 @@
return ();
}
+# --------------------------------------------------------- recursedirs
+# Recursive function to traverse either a specific user's Authoring Space
+# or corresponding Published Resource Space, and populate the hash ref:
+# $dirhashref with URLs of all directories, and if $filehashref hash
+# ref arg is provided, the URLs of any files, excluding versioned, .meta,
+# or .rights files in resource space, and .meta, .save, .log, and .bak
+# files in Authoring Space.
+#
+# Inputs:
+#
+# $is_home - true if current server is home server for user's space
+# $context - either: priv, or res respectively for Authoring or Resource Space.
+# $docroot - Document root (i.e., /home/httpd/html
+# $toppath - Top level directory (i.e., /res/$dom/$uname or /priv/$dom/$uname
+# $relpath - Current path (relative to top level).
+# $dirhashref - reference to hash to populate with URLs of directories (Required)
+# $filehashref - reference to hash to populate with URLs of files (Optional)
+#
+# Returns: nothing
+#
+# Side Effects: populates $dirhashref, and $filehashref (if provided).
+#
+# Currently used by interface/londocs.pm to create linked select boxes for
+# directory and filename to import a Course "Author" resource into a course, and
+# also to create linked select boxes for Authoring Space and Directory to choose
+# save location for creation of a new "standard" problem from the Course Editor.
+#
+
+sub recursedirs {
+ my ($is_home,$context,$docroot,$toppath,$relpath,$dirhashref,$filehashref) = @_;
+ return unless (ref($dirhashref) eq 'HASH');
+ my $currpath = $docroot.$toppath;
+ if ($relpath) {
+ $currpath .= "/$relpath";
+ }
+ my $savefile;
+ if (ref($filehashref)) {
+ $savefile = 1;
+ }
+ if ($is_home) {
+ if (opendir(my $dirh,$currpath)) {
+ foreach my $item (sort { lc($a) cmp lc($b) } grep(!/^\.+$/,readdir($dirh))) {
+ next if ($item eq '');
+ if (-d "$currpath/$item") {
+ my $newpath;
+ if ($relpath) {
+ $newpath = "$relpath/$item";
+ } else {
+ $newpath = $item;
+ }
+ $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;
+ &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref);
+ } elsif ($savefile) {
+ if ($context eq 'priv') {
+ unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) {
+ $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1;
+ }
+ } else {
+ unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/) || ($item =~ /\.rights$/)) {
+ $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1;
+ }
+ }
+ }
+ }
+ closedir($dirh);
+ }
+ } else {
+ my ($dirlistref,$listerror) =
+ &dirlist($toppath.$relpath);
+ my @dir_lines;
+ my $dirptr=16384;
+ if (ref($dirlistref) eq 'ARRAY') {
+ foreach my $dir_line (sort
+ {
+ my ($afile)=split('&',$a,2);
+ my ($bfile)=split('&',$b,2);
+ return (lc($afile) cmp lc($bfile));
+ } (@{$dirlistref})) {
+ my ($item,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef) =
+ split(/\&/,$dir_line,16);
+ $item =~ s/\s+$//;
+ next if (($item =~ /^\.\.?$/) || ($obs));
+ if ($dirptr&$testdir) {
+ my $newpath;
+ if ($relpath) {
+ $newpath = "$relpath/$item";
+ } else {
+ $relpath = '/';
+ $newpath = $item;
+ }
+ $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;
+ &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref);
+ } elsif ($savefile) {
+ if ($context eq 'priv') {
+ unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) {
+ $filehashref->{$relpath}{$item} = 1;
+ }
+ } else {
+ unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/)) {
+ $filehashref->{$relpath}{$item} = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+ return;
+}
+
# -------------------------------------------------------- Value of a Condition
# gets the value of a specific preevaluated condition
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.246 loncom/loncapa_apache.conf:1.247
--- loncom/loncapa_apache.conf:1.246 Fri Jun 24 20:54:03 2016
+++ loncom/loncapa_apache.conf Fri Jul 1 20:00:07 2016
@@ -2,7 +2,7 @@
## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
##
-# $Id: loncapa_apache.conf,v 1.246 2016/06/24 20:54:03 raeburn Exp $
+# $Id: loncapa_apache.conf,v 1.247 2016/07/01 20:00:07 raeburn Exp $
#
# LON-CAPA Section (extensions to httpd.conf daemon configuration)
@@ -529,6 +529,16 @@
PerlHandler Apache::daxesave
</LocationMatch>
+<Location /adm/coursepub>
+AuthType LONCAPA
+Require valid-user
+PerlAuthzHandler Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::loncoursepub
+ErrorDocument 404 /adm/notfound.html
+ErrorDocument 500 /adm/errorhandler
+</Location>
+
<LocationMatch "^/adm/wrapper/">
AuthType LONCAPA
Require valid-user
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.931 doc/loncapafiles/loncapafiles.lpml:1.932
--- doc/loncapafiles/loncapafiles.lpml:1.931 Sat Apr 9 21:20:38 2016
+++ doc/loncapafiles/loncapafiles.lpml Fri Jul 1 20:00:16 2016
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
<!-- loncapafiles.lpml -->
-<!-- $Id: loncapafiles.lpml,v 1.931 2016/04/09 21:20:38 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.932 2016/07/01 20:00:16 raeburn Exp $ -->
<!--
@@ -4339,6 +4339,14 @@
</dependencies>
</file>
<file>
+<source>loncom/publisher/loncoursepub.pm</source>
+<target dist='default'>home/httpd/lib/perl/Apache/loncoursepub.pm</target>
+<categoryname>handler</categoryname>
+<description>
+Handler for asynchronous file upload via colorful editor ("Course Authoring" space).
+</description>
+</file>
+<file>
<source>loncom/interface/lonmeta.pm</source>
<target dist='default'>home/httpd/lib/perl/Apache/lonmeta.pm</target>
<categoryname>handler</categoryname>
Index: loncom/publisher/loncoursepub.pm
+++ loncom/publisher/loncoursepub.pm
# The LearningOnline Network with CAPA
# Handler to store uploaded files etc. in Course's Authoring
# Space,
#
# $Id: loncoursepub.pm,v 1.1 2016/07/01 19:59:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::loncoursepub;
use strict;
use Apache::Constants qw(:common :http :methods);
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonpublisher;
use Apache::londocs;
use Apache::lonlocal;
use LONCAPA qw(:DEFAULT :match);
sub handler {
my $r = shift;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
if ($env{'request.course.id'}) {
my $newurl;
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['LC_uploadcrsres']);
my $suffix = $env{'form.LC_uploadcrsres'};
my $containerfile = $env{'form.filename_'.$suffix};
if ($containerfile =~ m{^(/priv/\Q$cdom/$cnum\E)}) {
my $toppath = $1;
if ($suffix) {
my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
my $newfilename = $env{'form.uploadcrsres_'.$suffix.'.filename'};
$newfilename =~ s/(\s+$|^\s+)//g;
$newfilename =~ s/[\#\?&%\":]//g;
$newfilename =~ s/\.(\d+)(\.\w+)$/$2/;
my $relpath = $env{'form.crsauthorpath_'.$suffix};
my $newsubdir;
if ($env{'form.newsubdir_'.$suffix}) {
$newsubdir = $env{'form.newsubdirname_'.$suffix};
}
if ($newfilename ne '') {
my $path = $londocroot.$toppath;
my $redirect = &Apache::londocs::finishnewprob($toppath,$path,$relpath,$newsubdir,$newfilename);
if ($redirect) {
my $url = $redirect;
my $srcfile = $londocroot.$url;
$url =~ s{^/priv/}{/res/};
my $targetfile = $londocroot.$url;
if (open(my $fh,'>'.$srcfile)) {
print $fh $env{'form.uploadcrsres_'.$suffix};
close($fh);
$url =~ s{^/priv/}{/res/};
my $targetfile = $londocroot.$url;
my $nokeyref = &Apache::lonpublisher::getnokey($Apache::lonnet::perlvar{'lonIncludes'});
my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
$newurl = $url;
}
}
}
}
}
$r->print(<<"END");
<html>
<head>
<script type="text/javascript">
window.onload=top.uploadDone('$suffix','$newurl');
</script>
<body></body>
</html>
END
}
}
return OK;
}
1;
__END__
More information about the LON-CAPA-cvs
mailing list