--- loncom/interface/londocs.pm 2007/01/05 19:40:43 1.268
+++ loncom/interface/londocs.pm 2011/08/15 16:31:55 1.457
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.268 2007/01/05 19:40:43 www Exp $
+# $Id: londocs.pm,v 1.457 2011/08/15 16:31:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,6 +26,8 @@
# http://www.lon-capa.org/
#
+
+
package Apache::londocs;
use strict;
@@ -33,6 +35,7 @@ use Apache::Constants qw(:common :http);
use Apache::imsexport;
use Apache::lonnet;
use Apache::loncommon;
+use Apache::lonhtmlcommon;
use LONCAPA::map();
use Apache::lonratedt();
use Apache::lonxml;
@@ -53,15 +56,9 @@ my %alreadyseen=();
my $hadchanges;
-# Available help topics
my %help=();
-# Mapread read maps into LONCAPA::map:: global arrays
-# @order and @resources, determines status
-# sets @order - pointer to resources in right order
-# sets @resources - array with the resources with correct idx
-#
sub mapread {
my ($coursenum,$coursedom,$map)=@_;
@@ -76,25 +73,25 @@ sub storemap {
&LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
$map,1);
if ($errtext) { return ($errtext,2); }
-
+
$hadchanges=1;
return ($errtext,0);
}
-# ----------------------------------------- Return hash with valid author names
+
sub authorhosts {
my %outhash=();
my $home=0;
my $other=0;
- foreach (keys %env) {
- if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
my $role=$1;
my $realm=$2;
- my ($start,$end)=split(/\./,$env{$_});
+ my ($start,$end)=split(/\./,$env{$key});
if (($start) && ($start>time)) { next; }
if (($end) && (time>$end)) { next; }
- my $ca; my $cd;
+ my ($ca,$cd);
if ($1 eq 'au') {
$ca=$env{'user.name'};
$cd=$env{'user.domain'};
@@ -116,38 +113,43 @@ sub authorhosts {
}
return ($home,$other,%outhash);
}
-# ------------------------------------------------------ Generate "dump" button
+
sub dumpbutton {
my ($home,$other,%outhash)=&authorhosts();
- my $type = &Apache::loncommon::course_type();
+ my $crstype = &Apache::loncommon::course_type();
if ($home+$other==0) { return ''; }
- my $output='
';
if ($home) {
- return ' '.
- ' '.
- &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
- } else {
- return' '.
- &mt('Dump '.$type.
- ' DOCS to Construction Space: available on other servers');
+ my $link =
+ "';
+ return
+ $link.' '
+ .&Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs')
+ .' ';
+ } else {
+ return
+ &mt('Dump '.$crstype.' Documents to Construction Space: available on other servers');
}
}
sub clean {
my ($title)=@_;
$title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
- return $title;
+ return $title;
}
-# -------------------------------------------------------- Actually dump course
+
+
sub dumpcourse {
my ($r) = @_;
- my $type = &Apache::loncommon::course_type();
- $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
- '');
+ '
');
}
}
-# ------------------------------------------------------ Generate "export" button
+
sub exportbutton {
- my $type = &Apache::loncommon::course_type();
- return ' '.
- ' '.
- &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
+ my $crstype = &Apache::loncommon::course_type();
+ return "".
+ &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').' ';
}
+
+
sub exportcourse {
my $r=shift;
- my $type = &Apache::loncommon::course_type();
+ my $crstype = &Apache::loncommon::course_type();
my %discussiontime = &Apache::lonnet::dump('discussiontimes',
$env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
- my $numdisc = keys %discussiontime;
+ my $numdisc = keys(%discussiontime);
+ my $numprobs = 0;
my $navmap = Apache::lonnavmaps::navmap->new();
+ if (!defined($navmap)) {
+ $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').
+ ''.&mt('IMS Export Failed').' '.
+ '');
+ if ($crstype eq 'Community') {
+ $r->print(&mt('Unable to retrieve information about community contents'));
+ } else {
+ $r->print(&mt('Unable to retrieve information about course contents'));
+ }
+ $r->print('
');
+ if ($crstype eq 'Community') {
+ $r->print(&mt('Return to Community Editor'));
+ } else {
+ $r->print(&mt('Return to Course Editor'));
+ }
+ $r->print(' ');
+ &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+ return;
+ }
my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
my $curRes;
my $outcome;
@@ -281,10 +311,21 @@ sub exportcourse {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['archive','discussion']);
+ my $format = $env{'form.format'};
my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
if (@exportitems == 0 && @discussions == 0) {
- $outcome = ' As you did not select any content items or discussions for export, an IMS package has not been created. Please go back to select either content items or discussions for export';
+ $outcome =
+ ''
+ .&mt('As you did not select any content items or discussions'
+ .' for export, an IMS package has not been created.')
+ .'
'
+ .''
+ .&mt('Please [_1]go back[_2] to select either content items'
+ .' or discussions for export.'
+ ,''
+ ,' ')
+ .'
';
} else {
my $now = time;
my %symbs;
@@ -292,9 +333,10 @@ sub exportcourse {
my $imsresources;
my $tempexport;
my $copyresult;
- my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
+ my $testbank;
+ my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport,$format,\$testbank);
if ($manifestok) {
- &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
+ &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest,$format,$testbank);
close($ims_manifest);
#Create zip file in prtspool
@@ -307,35 +349,53 @@ sub exportcourse {
open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
close(OUTPUT);
chdir $cwd;
- $outcome .= &mt('Download the zip file from IMS '.lc($type).' archive ',$imszipfile,);
+ $outcome .= ''
+ .&mt('[_1]Your IMS package[_2] is ready for download.'
+ ,'',' ')
+ .'
';
if ($copyresult) {
- $outcome .= 'The following errors occurred during export - '.$copyresult;
+ $outcome .= ''
+ .&mt('The following errors occurred during export - [_1]'
+ ,$copyresult)
+ .'
';
}
} else {
- $outcome = ' Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file. ';
+ $outcome = ''
+ .&mt('Unfortunately you will not be able to retrieve'
+ .' an IMS archive of your course at this time,'
+ .' because there was a problem creating a'
+ .' manifest file.')
+ .'
'
+ .''
+ .&mt('Go Back')
+ .'
';
}
}
- $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
+ $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
$r->print($outcome);
$r->print(&Apache::loncommon::end_page());
} else {
- my $display;
- $display = ''.
- &Apache::loncommon::end_page());
+ &mt('Export').'" />');
}
}
sub create_ims_store {
- my ($now,$manifestok,$outcome,$tempexport) = @_;
+ my ($now,$manifestok,$outcome,$tempexport,$format,$testbank) = @_;
$$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
my $ims_manifest;
if (!-e $$tempexport) {
@@ -512,7 +586,11 @@ sub create_ims_store {
' '."\n".
' '."\n".
-' '.$env{'course.'.$env{'request.course.id'}.'.description'}.' '
+' '.$env{'course.'.$env{'request.course.id'}.'.description'}.' ';
+ if ($format eq 'plaintext') {
+ my $testbankfilename = $$tempexport.'/testbank.txt';
+ $$testbank = Apache::File->new('>'.$testbankfilename);
+ }
} else {
$$outcome .= 'An error occurred opening the IMS manifest file. '
;
@@ -521,7 +599,8 @@ sub create_ims_store {
}
sub build_package {
- my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
+ my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,
+ $ims_manifest,$format,$testbank) = @_;
# first iterator to look for dependencies
my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
my $curRes;
@@ -548,7 +627,7 @@ sub build_package {
if ($curRes->is_sequence() || $curRes->is_page()) {
$lastcontainer = $count;
}
- if (grep/^$count$/,@$exportitems) {
+ if (grep(/^$count$/,@$exportitems)) {
&get_dependencies($exportitems,\%parent,$depth,\@dependencies);
}
}
@@ -560,6 +639,7 @@ sub build_package {
$count = 0;
my $imsresources;
my $pkgdepth;
+ my $currdirpath = 'Top';
while ($curRes = $it->next()) {
if ($curRes == $it->BEGIN_MAP()) {
$prevdepth = $depth;
@@ -572,7 +652,7 @@ sub build_package {
if (ref($curRes)) {
$count ++;
- if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
+ if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {
my $symb = $curRes->symb();
my $isvisible = 'true';
my $resourceref;
@@ -597,20 +677,38 @@ sub build_package {
''.$curRes->title().' ';
print $ims_manifest "\n".$itementry;
- unless ($curRes->is_sequence()) {
+ if ($curRes->is_sequence()) {
+ $currdirpath = 'Top';
+ my $pcslist = $curRes->map_hierarchy();
+ if ($pcslist ne '') {
+ foreach my $pc (split(/,/,$pcslist),$curRes->map_pc()) {
+ next if ($pc <= 1);
+ my $res = $navmap->getByMapPc($pc);
+ if (ref($res)) {
+ my $encloser = $res->title();
+ if ($encloser) {
+ if ($currdirpath) {
+ $currdirpath .= ' -> ';
+ }
+ $currdirpath .= $encloser;
+ }
+ }
+ }
+ }
+ } else {
my $content_file;
my @hrefs = ();
- &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
+ &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport,$format,$currdirpath,$testbank);
if ($content_file) {
$imsresources .= "\n".
' '."\n".
' '."\n";
- foreach (@hrefs) {
+ foreach my $item (@hrefs) {
$imsresources .=
- ' '."\n";
+ ' '."\n";
}
- if (grep/^$count$/,@$discussions) {
+ if (grep(/^$count$/,@$discussions)) {
my $ressymb = $symb;
my $mode;
if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
@@ -651,8 +749,8 @@ sub build_package {
sub get_dependencies {
my ($exportitems,$parent,$depth,$dependencies) = @_;
if ($depth > 1) {
- if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
- push @$dependencies, $$parent{$depth};
+ if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {
+ push(@{$dependencies},$$parent{$depth});
if ($depth > 2) {
&get_dependencies($exportitems,$parent,$depth-1,$dependencies);
}
@@ -661,7 +759,7 @@ sub get_dependencies {
}
sub process_content {
- my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
+ my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport,$format,$currdirpath,$testbank) = @_;
my $content_type;
my $message;
my @uploads = ();
@@ -718,10 +816,15 @@ sub process_content {
$canedit= 1;
}
# only include problem code where current user is author
- if ($canedit) {
- $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
- } else {
- $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
+ if (($format eq 'html') || ($format eq 'plaintext')) {
+ my $title = $curRes->title;
+ $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,$format,$currdirpath,$title,$testbank);
+ } elsif ($format eq 'xml') {
+ if ($canedit) {
+ $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
+ } else {
+ $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
+ }
}
} elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
$$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
@@ -741,12 +844,13 @@ sub process_content {
}
sub replicate_content {
- my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
+ my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller,$currdirpath,
+ $title,$testbank) = @_;
my ($map,$ind,$url);
if ($caller eq 'templateupload') {
$url = $symb;
$url =~ s#//#/#g;
- } else {
+ } else {
($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
}
my $content;
@@ -785,10 +889,71 @@ sub replicate_content {
} else {
$$message = 'Could not render '.$url.' server message - '.$rtncode." \n";
}
- } elsif ($caller eq 'noedit') {
-# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
+ } elsif (($caller eq 'noedit') || ($caller eq 'html') ||
+ ($caller eq 'plaintext')) {
+# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
+ my %form = (
+ grade_symb => $symb,
+ grade_courseid => $cdom.'_'.$cnum,
+ grade_domain => $env{'user.domain'},
+ grade_username => $env{'user.name'},
+ grade_imsexport => 1,
+ instructor_comments => 'hide',
+ );
+ my $feedurl=&Apache::lonnet::clutter($url);
+ my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
+ if (ref($response)) {
+ if ($response->is_success) {
+ $content = $userview;
+ $content =~ s/\Qonchange="javascript:setSubmittedPart('\E[^\']+\Q');"\E//g;
+ $content =~ s/^\s*[\n\r]+$//;
+ if ($caller eq 'plaintext') {
+ my @lines = split(/[\n\r]+/,$content);
+ my @tosave;
+ my $foilcounter = 0;
+ my @alphabet = ('a'..'z');
+ my $mc_answer;
+ foreach my $line (@lines) {
+ next if ($line =~ /^\s*$/);
+ if ($line =~ m{(|\Q<\label>\E)\Q Incorrect:\E}) {
+ $foilcounter ++;
+ } elsif ($line =~ m{(|\Q \E)\Q Correct:\E}) {
+ $foilcounter ++;
+ $mc_answer = $alphabet[$foilcounter-1];
+ } elsif ($line !~ m{\Q \E(|\Q \E)\Q \E}) {
+ $line =~ s/^(\s+|\s+)$//g;
+ $line =~ s{^\Q\E([^<]+)\Q \E$}{1};
+ $tosave[$foilcounter] .= $line.' ';
+ }
+ $content = join("\t",@tosave);
+ if ($mc_answer) {
+ $content .= "\t".$mc_answer."\n";
+ }
+ }
+ if (@tosave) {
+ my $qtype;
+ if ($mc_answer) {
+ $qtype = 'MC';
+ }
+ $content = $currdirpath."\t".$title."\t$qtype\t".join("\t",@tosave);
+ if ($mc_answer) {
+ $content .= "\t".$mc_answer;
+ }
+ $content .= "\n";
+ }
+ } else {
+ $content = ''.$content.'';
+ }
+ if (($caller eq 'plaintext') && ($testbank)) {
+ print $testbank $content;
+ }
+ } else {
+ $content = 'Not the owner of this resource';
+ }
+ } else {
+ $content = 'Not the owner of this resource';
+ }
$repstatus = 'ok';
- $content = 'Not the owner of this resource';
}
if ($repstatus eq 'ok') {
print $copiedfile $content;
@@ -818,7 +983,7 @@ sub extract_media {
$dirpath = $url;
$container = '';
}
- &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
+ &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);
foreach my $embed_file (keys(%allfiles)) {
my $filename;
if ($embed_file =~ m#([^/]+)$#) {
@@ -839,14 +1004,13 @@ sub extract_media {
}
}
if ($caller eq 'resource') {
- my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
- my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
+ my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
+ my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
$embed_content = &Apache::lonnet::getfile($embed_path);
unless ($embed_content eq -1) {
$repstatus = 'ok';
}
} elsif ($caller eq 'uploaded') {
-
$repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
}
if ($repstatus eq 'ok') {
@@ -858,7 +1022,7 @@ sub extract_media {
my $copiedfile;
if ($copiedfile = Apache::File->new('>'.$destination)) {
print $copiedfile $embed_content;
- push @{$href}, 'resources/'.$count.'/res/'.$filename;
+ push(@{$href},'resources/'.$count.'/res/'.$filename);
my $attrib_regexp = '';
if (@{$allfiles{$embed_file}} > 1) {
$attrib_regexp = join('|',@{$allfiles{$embed_file}});
@@ -902,18 +1066,16 @@ sub store_template {
}
}
-# Imports the given (name, url) resources into the course
-# coursenum, coursedom, and folder must precede the list
+
sub group_import {
- my $coursenum = shift;
- my $coursedom = shift;
- my $folder = shift;
- my $container = shift;
- my $caller = shift;
- while (@_) {
- my $name = shift;
- my $url = shift;
- if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) && ($caller eq 'londocs')) {
+ my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
+
+ while (@files) {
+ my ($name, $url, $residx) = @{ shift(@files) };
+ if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
+ && ($caller eq 'londocs')
+ && (!&Apache::lonnet::stat_file($url))) {
+
my $errtext = '';
my $fatal = 0;
my $newmapstr = ''."\n".
@@ -925,7 +1087,7 @@ sub group_import {
my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
'output',$1.$2);
if ($result != m|^/uploaded/|) {
- $errtext.='Map not saved: A network error occured when trying to save the new map. ';
+ $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
$fatal = 2;
}
if ($fatal) {
@@ -933,21 +1095,24 @@ sub group_import {
}
}
if ($url) {
- my $idx = &LONCAPA::map::getresidx($url);
- $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
+ if (!$residx
+ || defined($LONCAPA::map::zombies[$residx])) {
+ $residx = &LONCAPA::map::getresidx($url,$residx);
+ push(@LONCAPA::map::order, $residx);
+ }
my $ext = 'false';
if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
- $url =~ s/:/\:/g;
- $name =~ s/:/\:/g;
- $LONCAPA::map::resources[$idx] =
- join ':', ($name, $url, $ext, 'normal', 'res');
+ $url = &LONCAPA::map::qtunescape($url);
+ $name = &LONCAPA::map::qtunescape($name);
+ $LONCAPA::map::resources[$residx] =
+ join(':', ($name, $url, $ext, 'normal', 'res'));
}
}
return &storemap($coursenum, $coursedom, $folder.'.'.$container);
}
sub breadcrumbs {
- my ($where)=@_;
+ my ($allowed,$crstype)=@_;
&Apache::lonhtmlcommon::clear_breadcrumbs();
my (@folders);
if ($env{'form.pagepath'}) {
@@ -958,44 +1123,51 @@ sub breadcrumbs {
my $folderpath;
my $cpinfo='';
my $plain='';
- if ($env{'form.markedcopy_url'}) {
- $cpinfo='&markedcopy_url='.
- &escape($env{'form.markedcopy_url'}).
- '&markedcopy_title='.
- &escape($env{'form.markedcopy_title'});
- }
my $randompick=-1;
my $isencrypted=0;
my $ishidden=0;
+ my $is_random_order=0;
+ if (!$allowed) {
+ my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ {'href' => '/adm/menu',
+ 'title'=> 'Go to main menu',
+ 'text' => $description,
+ });
+ $plain .= $description.' >';
+ }
while (@folders) {
my $folder=shift(@folders);
- my $foldername=shift(@folders);
+ my $foldername=shift(@folders);
if ($folderpath) {$folderpath.='&';}
$folderpath.=$folder.'&'.$foldername;
my $url='/adm/coursedocs?folderpath='.
&escape($folderpath);
- my $name=&unescape($foldername);
-# randompick number, hidden, encrypted is appended with ":"s to the foldername
- $name=~s/\:(\d*)\:(\w*)\:(\w*)$//;
- if ($1 ne '') {
+ my $name=&unescape($foldername);
+# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
+ $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
+ if ($1 ne '') {
$randompick=$1;
} else {
$randompick=-1;
}
if ($2) { $ishidden=1; }
if ($3) { $isencrypted=1; }
+ if ($4 ne '') { $is_random_order = 1; }
+ if ($folder eq 'supplemental') {
+ $name = &mt('Supplemental '.$crstype.' Documents');
+ }
&Apache::lonhtmlcommon::add_breadcrumb(
{'href'=>$url.$cpinfo,
'title'=>$name,
- 'text'=>''.
- $name.' ',
+ 'text'=>$name,
'no_mt'=>1,
});
$plain.=$name.' > ';
}
$plain=~s/\>\;\s*$//;
return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
- 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain);
+ undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
}
sub log_docs {
@@ -1033,7 +1205,7 @@ sub log_docs {
'currentfolder' => $env{'form.folder'});
if ($parmidx) {
$storehash{'parameter_res'}=$oldresources[$parmidx];
- foreach my $parm (keys %parmaction) {
+ foreach my $parm (keys(%parmaction)) {
$storehash{'parameter_action_'.$parm}=$parmaction{$parm};
$storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
}
@@ -1060,9 +1232,9 @@ sub log_docs {
}
-#
-# Docs Change Log
-#
+
+
+
sub docs_change_log {
my ($r)=@_;
my $folder=$env{'form.folder'};
@@ -1083,9 +1255,11 @@ sub docs_change_log {
&Apache::loncommon::restore_course_settings('docs_log',
\%saveable_parameters);
if (!$env{'form.show'}) { $env{'form.show'}=10; }
+# FIXME: internationalization seems wrong here
my %lt=('hiddenresource' => 'Resources hidden',
'encrypturl' => 'URL hidden',
'randompick' => 'Randomly pick',
+ 'randomorder' => 'Randomly ordered',
'set' => 'set to',
'del' => 'deleted');
$r->print(&Apache::loncommon::display_filter().
@@ -1107,7 +1281,7 @@ sub docs_change_log {
foreach my $key (@changes) {
$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
}
- if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
+ if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
}
my $count = 0;
my $time =
@@ -1155,10 +1329,10 @@ sub docs_change_log {
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
- if ($oldname ne $newname) {
+ if ($oldname ne '' && $oldname ne $newname) {
$r->print(&LONCAPA::map::qtescape($newname));
}
- }
+ }
$r->print('');
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
@@ -1168,8 +1342,9 @@ sub docs_change_log {
$r->print(' ');
if ($docslog{$id}{'logentry'}{'parameter_res'}) {
$r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).': ');
- }
-# ----------------------------------------------------- Supplemental documents
- if (!$forcestandard) {
- $r->print('');
-# ''.&mt('Supplemental Course Documents').
-# ($allowed?' '.$help{'Supplemental'}:'').' ');
+
+
+
+ my $recoverform=(<
+
+
+RFORM
+
+ my $imspform=(<
+
+
+
+IMSPFORM
+
+ my $newnavform=(<
+
+ $uploadtag
+
+
+ $help{'Navigate_Content'}
+
+NNFORM
+ my $newsmppageform=(<
+
+ $uploadtag
+
+
+ $help{'Simple Page'}
+
+NSPFORM
+
+ my $newsmpproblemform=(<
+
+ $uploadtag
+
+
+ $help{'Simple Problem'}
+
+
+NSPROBFORM
+
+ my $newdropboxform=(<
+
+ $uploadtag
+
+
+
+NDBFORM
+
+ my $newexuploadform=(<
+
+ $uploadtag
+
+
+ $help{'Score_Upload_Form'}
+
+NEXUFORM
+
+ my $newbulform=(<
+
+ $uploadtag
+
+
+ $help{'Bulletin Board'}
+
+NBFORM
+
+ my $newaboutmeform=(<
+
+ $uploadtag
+
+
+ $help{'My Personal Information Page'}
+
+NAMFORM
+
+ my $newaboutsomeoneform=(<
+
+ $uploadtag
+
+
+
+NASOFORM
+
+
+ my $newrosterform=(<
+
+ $uploadtag
+
+
+ $help{'Course Roster'}
+
+NROSTFORM
+
+my $specialdocumentsform;
+my @specialdocumentsforma;
+my $gradingform;
+my @gradingforma;
+my $communityform;
+my @communityforma;
+my $newfolderform;
+my $newfolderb;
+
+ my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+
+ my $newpageform=(<
+
+
+
+
+ $help{'Adding_Pages'}
+
+NPFORM
+
+
+ $newfolderform=(<
+
+
+
+ $lt{'newf'} $help{'Adding_Folders'}
+
+NFFORM
+
+ my $newsylform=(<
+
+ $uploadtag
+
+
+ $help{'Syllabus'}
+
+
+NSYLFORM
+
+ my $newgroupfileform=(<
+
+ $uploadtag
+
+
+ $help{'Group Portfolio'}
+
+NGFFORM
+ @specialdocumentsforma=(
+ {' '=>$newpageform},
+ {' '=>$newsylform},
+ {' '=>$newnavform},
+ {' '=>$newsmppageform},
+ );
+ $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
+
+
+ my @importdoc = (
+ {' '=>$extresourcesform},
+ {' '=>$imspform},);
+ $fileuploadform = &create_form_ul(&create_list_elements(@importdoc)) . ' ' . $fileuploadform;
+
+ @gradingforma=(
+ {' '=>$newsmpproblemform},
+ {' '=>$newdropboxform},
+ {' '=>$newexuploadform},
+
+ );
+ $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
+
+ @communityforma=(
+ {' '=>$newbulform},
+ {' '=>$newaboutmeform},
+ {' '=>$newaboutsomeoneform},
+ {' '=>$newrosterform},
+ {' '=>$newgroupfileform},
+ );
+ $communityform = &create_form_ul(&create_list_elements(@communityforma));
+
+
+
+my @tools = (
+# {' '=>$extresourcesform},
+# {' '=>$imspform},
+ {' '=>$recoverform},
+ );
+
+my %orderhash = (
+ 'aa' => ['Import Documents',$fileuploadform],
+ 'bb' => ['Published Resources',$simpleeditdefaultform],
+ 'cc' => ['Grading Resources',$gradingform],
+ 'ff' => ['Tools', &create_form_ul(&create_list_elements(@tools)).&generate_admin_options(\%help,\%env)],
+ );
+unless ($env{'form.pagepath'}) {
+ $orderhash{'00'} = ['Newfolder',$newfolderform];
+ $orderhash{'dd'} = ['Community Resources',$communityform];
+ $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
+}
+
+ $hadchanges=0;
+ unless ($supplementalflag) {
+ my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
+ if ($error) {
+ $r->print(''.$error.'
');
+ }
+ if ($hadchanges) {
+ &mark_hash_old();
+ }
+
+ &changewarning($r,'');
+ $r->print(&generate_edit_table('1',\%orderhash));
+ }
+
+ }
+
+# Supplemental documents start here
+
my $folder=$env{'form.folder'};
- unless ($folder=~/^supplemental/) {
+ unless ($supplementalflag) {
$folder='supplemental';
}
if ($folder =~ /^supplemental$/ &&
- $env{'form.folderpath'} =~ /^default\&/) {
- $env{'form.folderpath'}='supplemental&'.
- &escape(&mt('Supplemental '.$type.' Documents'));
+ (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
+ $env{'form.folderpath'} = &supplemental_base();
+ } elsif ($allowed) {
+ $env{'form.folderpath'} = $savefolderpath;
}
- &editor($r,$coursenum,$coursedom,$folder,$allowed);
+ $env{'form.pagepath'} = '';
if ($allowed) {
- my $folderseq=
- '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
- '.sequence';
-
- $r->print(<
-$lt{'upls'}
-$lt{'spec'}
-
-
-
-
-
-
-
-
-
- $help{'Adding_Folders'}
-
-
-
-
-
-
- $help{'Adding_External_Resource'}
-
-
-
-
-
-
-
-$help{'Syllabus'}
-
-
-
-
-
-
-
-$help{'My Personal Info'}
-
-
-
-
-ENDSUPFORM
- }
+ my $folderseq=
+ '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
+ '.sequence';
+
+ my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+
+ my $supupdocformbtn = " $help{'Uploading_From_Harddrive'}";
+ my $supupdocform=(<
+
+ $fileupload
+
+
+
+ $checkbox
+
+
+ $lt{'comment'}:
+
+
+
+
+SUPDOCFORM
+ $supupdocform .= &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."";
+
+ my $supnewfolderform=(<
+
+
+
+
+ $help{'Adding_Folders'}
+
+SNFFORM
+
+
+ my $supnewextform=(<
+
+
+
+ $help{'Adding_External_Resource'}
+
+SNEFORM
+
+ my $supnewsylform=(<
+
+
+
+
+ $help{'Syllabus'}
+
+SNSFORM
+
+ my $supnewaboutmeform=(<
+
+
+
+
+ $help{'My Personal Information Page'}
+
+SNAMFORM
+
+
+my @specialdocs = (
+ {' '
+ =>$supnewsylform},
+ {' '
+ =>$supnewaboutmeform},
+ );
+my @supimportdoc = (
+ {' '
+ =>$supnewextform},
+ );
+$supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)) . ' ' . $supupdocform;
+my %suporderhash = (
+ '00' => ['Supnewfolder', $supnewfolderform],
+ 'ee' => ['Import Documents',$supupdocform],
+ 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
+ );
+ if ($supplementalflag) {
+ my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
+ if ($error) {
+ $r->print(''.$error.'
');
+ }
+ $r->print(&generate_edit_table('2',\%suporderhash));
+ }
+ } elsif ($supplementalflag) {
+ my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
+ if ($error) {
+ $r->print(''.$error.'
');
+ }
}
+
+ &endContentScreen($r);
+
if ($allowed) {
- $r->print(' ');
+ $r->print('
+
+
+
+
+
+ ');
}
- $r->print('');
} else {
- unless ($upload_result eq 'phasetwo') {
+ unless ($uploadphase) {
# -------------------------------------------------------- This is showdoc mode
$r->print("".&mt('Uploaded Document').' - '.
&Apache::lonnet::gettitle($r->uri).' '.
-&mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."
".
- &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'
');
+&mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."".
+ &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'
');
}
}
}
$r->print(&Apache::loncommon::end_page());
return OK;
-}
+}
+
+sub embedded_form_elems {
+ my ($phase,$primaryurl,$newidx) = @_;
+ my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+ return <
+
+
+
+
+STATE
+}
+
+sub embedded_destination {
+ my $folder=$env{'form.folder'};
+ my $destination = 'docs/';
+ if ($folder =~ /^supplemental/) {
+ $destination = 'supplemental/';
+ }
+ if (($folder eq 'default') || ($folder eq 'supplemental')) {
+ $destination .= 'default/';
+ } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
+ $destination .= $2.'/';
+ }
+ $destination .= $env{'form.newidx'};
+ my $dir_root = '/userfiles';
+ return ($destination,$dir_root);
+}
+
+sub return_to_editor {
+ my $actionurl = '/adm/coursedocs';
+ return '
'."\n".
+ ' '."\n".
+ ''.&mt('Return to Editor').
+ ' ';
+}
+
+sub generate_admin_options {
+ my ($help_ref,$env_ref) = @_;
+ my %lt=&Apache::lonlocal::texthash(
+ 'vc' => 'Verify Content',
+ 'cv' => 'Check/Set Resource Versions',
+ 'ls' => 'List Symbs',
+ 'sl' => 'Show Log',
+ 'imse' => 'IMS Export',
+ 'dcd' => 'Dump Course Documents to Construction Space: available on other servers'
+ );
+ my %help = %{$help_ref};
+ my %env = %{$env_ref};
+ my $dumpbut=&dumpbutton();
+ my $exportbut=&exportbutton();
+ my @list = (
+ {' '
+ => "$help{'Verify_Content'}"},
+ {' '
+ =>"$help{'Check_Resource_Versions'}"},
+ );
+ if($dumpbut ne ''){
+ push @list, {' '=>$dumpbut};
+ }
+ push @list, ({' '
+ =>$exportbut},
+ {' '
+ =>" "},
+ {' '
+ =>""},
+ );
+ return ' '.&create_form_ul(&create_list_elements(@list)).' ';
+
+}
+
+
+sub generate_edit_table {
+ my ($tid,$orderhash_ref) = @_;
+ return unless(ref($orderhash_ref) eq 'HASH');
+ my %orderhash = %{$orderhash_ref};
+ my $form;
+ my $activetab;
+ my $active;
+ if($env{'form.active'} ne ''){
+ $activetab = $env{'form.active'};
+ }
+ $form = '';
+ $form .= '
';
+ foreach my $name (sort(keys(%orderhash))){
+ if($name ne '00'){
+ if($activetab eq '' || $activetab ne $name){
+ $active = '';
+ }elsif($activetab eq $name){
+ $active = 'class="active"';
+ }
+ $form .= ''.&mt(${$orderhash{$name}}[0]).' ';
+ } else {
+ $form .= ''.${$orderhash{$name}}[1].' ';
+
+ }
+ }
+ $form .= ' ';
+ $form .= '
';
+ foreach my $field (keys(%orderhash)){
+ if($field ne '00'){
+ if($activetab eq '' || $activetab ne $field){
+ $active = 'style="display: none;"';
+ }elsif($activetab eq $field){
+ $active = 'style="display:block;"';
+ }
+ $form .= '
'.${$orderhash{$field}}[1]
+ .'
';
+ }
+ }
+ $form .= '
';
+ return $form;
+}
sub editing_js {
my ($udom,$uname) = @_;
my $now = time();
+ my %lt = &Apache::lonlocal::texthash(
+ p_mnf => 'Name of New Folder',
+ t_mnf => 'New Folder',
+ p_mnp => 'Name of New Page',
+ t_mnp => 'New Page',
+ p_mxu => 'Title for the External Score',
+ p_msp => 'Name of Simple Course Page',
+ p_msb => 'Title for the Problem',
+ p_mdb => 'Title for the Drop Box',
+ p_mbb => 'Title for the Discussion Board',
+ p_mab => "Enter user:domain for User's Personal Information Page",
+ p_mab2 => 'Personal Information Page of ',
+ p_mab_alrt1 => 'Not a valid user:domain',
+ p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
+ p_chn => 'New Title',
+ p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
+ p_rmr2a => 'Remove[_99]',
+ p_rmr2b => '?[_99]',
+ p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
+ p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
+ p_ctr2a => 'Cut[_98]',
+ p_ctr2b => '?[_98]'
+ );
+
+ my $crstype = &Apache::loncommon::course_type();
+ my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
+ my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
+ my $main_container_page;
+ if ($docs_folderpath eq '') {
+ if ($docs_pagepath ne '') {
+ $main_container_page = 1;
+ }
+ }
+ my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
+ my $toplevelsupp = &supplemental_base();
return < 2 ){
+ currentNav = document.getElementById(tabnav[1].id);
+ currentLis = currentNav.getElementsByTagName('LI');
+ for(i = 0; i< currentLis.length; i++){
+ if(currentLis[i].className == 'active') {
+ funcString = currentLis[i].onclick.toString();
+ tab = funcString.split('"');
+ if(tab.length < 2) {
+ tab = funcString.split("'");
+ }
+ currentData = document.getElementById(tab[1]);
+ currentData.style.display = 'block';
+ }
+ }
+ }
+}
+
+function showPage(current, pageId, nav, data) {
+ hideAll(current, nav, data);
+ openTabs(pageId);
+ unselectInactive(nav);
+ current.className = 'active';
+ currentData = document.getElementById(pageId);
+ currentData.style.display = 'block';
+ resize_contentdiv('contentscroll');
+ if (nav == 'mainnav') {
+ var storedpath = "$docs_folderpath";
+ if (storedpath == '') {
+ storedpath = "$docs_pagepath";
+ }
+ var storedpage = "$main_container_page";
+ var reg = new RegExp("^supplemental");
+ if (pageId == 'mainCourseDocuments') {
+ if (storedpage == 1) {
+ document.simpleedit.folderpath.value = '';
+ document.uploaddocument.folderpath.value = '';
+ } else {
+ if (reg.test(storedpath)) {
+ document.simpleedit.folderpath.value = '$toplevelmain';
+ document.uploaddocument.folderpath.value = '$toplevelmain';
+ document.newext.folderpath.value = '$toplevelmain';
+ } else {
+ document.simpleedit.folderpath.value = storedpath;
+ document.uploaddocument.folderpath.value = storedpath;
+ document.newext.folderpath.value = storedpath;
+ }
+ }
+ } else {
+ if (reg.test(storedpath)) {
+ document.simpleedit.folderpath.value = storedpath;
+ document.supuploaddocument.folderpath.value = storedpath;
+ document.supnewext.folderpath.value = storedpath;
+ } else {
+ document.simpleedit.folderpath.value = '$toplevelsupp';
+ document.supuploaddocument.folderpath.value = '$toplevelsupp';
+ document.supnewext.folderpath.value = '$toplevelsupp';
+ }
+ }
}
- this.document.forms.renameform.submit();
- }
+ return false;
}
-function cutres(folderpath,index,oldtitle,container,pagesymb) {
- if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) {
- this.document.forms.renameform.cmd.value='cut_'+index;
- this.document.forms.renameform.markcopy.value=index;
- if (container == 'sequence') {
- this.document.forms.renameform.folderpath.value=folderpath;
+function injectData(current, hiddenField, name, value) {
+ currentElement = document.getElementById(hiddenField);
+ currentElement.name = name;
+ currentElement.value = value;
+ current.submit();
+}
+
+ENDNEWSCRIPT
+}
+
+sub resize_contentdiv_js {
+ my $viewport_js = &Apache::loncommon::viewport_geometry_js();
+ return < scrollboxheight) {
+ if (freespace > offset) {
+ newscrollboxheight = scrollboxheight+freespace-offset;
+ if (newscrollboxheight < minscrollbox) {
+ newscrollboxheight = minscrollbox;
+ }
+ scrollbox.style.height = newscrollboxheight+"px";
+ }
+ }
}
- if (container == 'page') {
- this.document.forms.renameform.pagepath.value=folderpath;
- this.document.forms.renameform.pagesymb.value=pagesymb;
+ scrollboxheight = scrollbox.offsetHeight;
+
+ if (scrollboxscrollheight <= scrollboxheight) {
+ var contentlistheight = document.getElementById("contentlist").offsetHeight;
+ if ((contentlistheight+offset)