--- loncom/interface/londocs.pm 2010/10/27 01:00:38 1.439
+++ loncom/interface/londocs.pm 2011/07/04 13:01:53 1.454
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.439 2010/10/27 01:00:38 raeburn Exp $
+# $Id: londocs.pm,v 1.454 2011/07/04 13:01:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -280,6 +280,7 @@ sub exportcourse {
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 $numprobs = 0;
my $navmap = Apache::lonnavmaps::navmap->new();
if (!defined($navmap)) {
$r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').
@@ -310,6 +311,7 @@ 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) {
@@ -331,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
@@ -435,6 +438,8 @@ sub exportcourse {
if (($curRes->is_sequence()) || ($curRes->is_page())) {
$lastcontainer = $currelem;
$display .= 'onclick="javascript:propagateCheck('."'$currelem'".')"';
+ } elsif ($curRes->is_problem()) {
+ $numprobs ++;
}
$display .= ' />'."\n";
for (my $i=0; $i<$depth; $i++) {
@@ -519,6 +524,16 @@ function containerCheck(item) {
$r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package',
$scripttag));
$r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
+ if ($numprobs > 0) {
+ $display .= '
'.
+ &mt('Export format for LON-CAPA problems:').
+ ' '.
+ ' '.&mt('XML').' '.(' ' x3).
+ ' '.
+ ' '.&mt('HTML').' '.(' ' x3).
+ ' '.
+ ' '.&mt('Text').'
';
+ }
$r->print($display.
' '.
' '."\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. '
;
@@ -580,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;
@@ -619,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;
@@ -656,10 +677,27 @@ 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)) {
+ 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";
}
- } elsif ($caller eq 'noedit') {
+ } 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,
+ );
+ 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];
+ } elsif ($line !~ m{ }) {
+ $line =~ s/^(\s+|\s+)$//g;
+ $line =~ s{^\Q\E([^<]+)\Q \E$}{1};
+ push(@tosave,$line);
+ }
+ $content = join("\t",@tosave);
+ if ($mc_answer) {
+ $content .= "\t".$mc_answer."\n";
+ }
+ }
+ if (@tosave) {
+ $content = $currdirpath."\t".$title."\t".join("\t",@tosave);
+ if ($mc_answer) {
+ $content .= "\t".$mc_answer."\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;
@@ -905,7 +1004,6 @@ sub extract_media {
$repstatus = 'ok';
}
} elsif ($caller eq 'uploaded') {
-
$repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
}
if ($repstatus eq 'ok') {
@@ -1150,6 +1248,7 @@ 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',
@@ -1238,6 +1337,7 @@ sub docs_change_log {
$r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':');
foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
+# FIXME: internationalization seems wrong here
$r->print(''.
&mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
$docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
@@ -1521,12 +1621,11 @@ sub editor {
$LONCAPA::map::resources[$idx]='';
}
- my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
- if ($allowed) {
- ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
+ my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
&breadcrumbs($allowed,$crstype);
$r->print($breadcrumbtrail);
- } else {
+
+ unless ($allowed) {
$randompick = -1;
}
@@ -1653,19 +1752,21 @@ sub editor {
&Apache::loncommon::end_data_table_count();
if ($shown) {
- $r->print(&Apache::loncommon::start_data_table());
+ $r->print(&Apache::loncommon::start_scrollbox('900px','880px','400px')
+ .&Apache::loncommon::start_data_table());
if ($allowed) {
$r->print(&Apache::loncommon::start_data_table_header_row()
.''.&mt('Move').' '
.''.&mt('Actions').' '
.''.&mt('Document').' ');
if ($folder !~ /^supplemental/) {
- $->print(''.&mt('Settings').' ');
+ $r->print(''.&mt('Settings').' ');
}
$r->print(&Apache::loncommon::end_data_table_header_row());
}
$r->print($output
.&Apache::loncommon::end_data_table()
+ .&Apache::loncommon::end_scrollbox()
);
} else {
$r->print(''
@@ -1682,11 +1783,10 @@ sub editor {
sub process_file_upload {
my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
# upload a file, if present
- my $parseaction;
- if ($env{'form.parserflag'}) {
+ my ($parseaction,$showupload,$nextphase,$mimetype);
+ if ($env{'form.parserflag'}) {
$parseaction = 'parse';
}
- my $phase_status;
my $folder=$env{'form.folder'};
if ($folder eq '') {
$folder='default';
@@ -1705,7 +1805,8 @@ sub process_file_upload {
$LONCAPA::map::resources[1]='';
}
if ($fatal) {
- return 'failed';
+ $$upload_output = '
'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'
';
+ return;
}
my $destination = 'docs/';
if ($folder =~ /^supplemental/) {
@@ -1716,13 +1817,23 @@ sub process_file_upload {
} elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
$destination .= $2.'/';
}
-# this is for a course, not a user, so set coursedoc flag
-# probably the only place in the system where this should be "1"
+# this is for a course, not a user, so set context to coursedoc.
my $newidx=&LONCAPA::map::getresidx();
$destination .= $newidx;
my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
$parseaction,$allfiles,
- $codebase);
+ $codebase,undef,undef,undef,undef,
+ undef,undef,\$mimetype);
+ if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
+ my $stored = $1;
+ $showupload = ''.&mt('Uploaded [_1]',''.
+ $stored.' ').'
';
+ } else {
+ my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
+
+ $$upload_output = ''.&mt('Unable to save file [_1].',''.$filename.' ').'
';
+ return;
+ }
my $ext='false';
if ($url=~m{^http://}) { $ext='true'; }
$url = &LONCAPA::map::qtunescape($url);
@@ -1739,51 +1850,37 @@ sub process_file_upload {
($errtext,$fatal)=&storemap($coursenum,$coursedom,
$folder.'.'.$container);
if ($fatal) {
- $$upload_output .= ''.$errtext.'
';
- return 'failed';
+ $$upload_output = ''.$errtext.'
';
+ return;
} else {
- if ($parseaction eq 'parse') {
+ if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
+ $$upload_output = $showupload;
my $total_embedded = scalar(keys(%{$allfiles}));
if ($total_embedded > 0) {
- my $num = 0;
- my $state = '
-
-
-
-
- ';
- $phase_status = 'phasetwo';
-
- $$upload_output .=
- 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA. '.
- &Apache::loncommon::ask_for_embedded_content(
- '/adm/coursedocs',$state,$allfiles,$codebase);
+ my $uploadphase = 'upload_embedded';
+ my $primaryurl = &HTML::Entities::encode($url,'<>&"');
+ my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
+ my ($embedded,$num) =
+ &Apache::loncommon::ask_for_embedded_content(
+ '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
+ if ($embedded) {
+ if ($num) {
+ $$upload_output .=
+ ''.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'
'.$embedded;
+ $nextphase = $uploadphase;
+ } else {
+ $$upload_output .= $embedded;
+ }
+ } else {
+ $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').' ';
+ }
} else {
- $$upload_output .= 'No embedded items identified ';
+ $$upload_output .= &mt('No embedded items identified').' ';
}
}
}
}
- return $phase_status;
-}
-
-sub process_secondary_uploads {
- my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
- 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 .= $newidx;
- my ($url,$filename);
- $url=&Apache::lonnet::userfileupload($formname.$num,'coursedoc',$destination);
- ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
- return $filename;
+ return $nextphase;
}
sub is_supplemental_title {
@@ -1848,7 +1945,7 @@ sub entryline {
}
if ($env{'form.pagepath'}) {
$type = $container = 'page';
- $esc_path=&escape($path = $env{'form.pagepath'});
+ $esc_path=&escape($env{'form.pagepath'});
$path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
$symb=&escape($env{'form.pagesymb'});
}
@@ -2242,6 +2339,7 @@ sub list_symbs {
my $crstype = &Apache::loncommon::course_type();
$r->print(&Apache::loncommon::start_page('Symb List'));
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
+ &startContentScreen($r,'tools');
my $navmap = Apache::lonnavmaps::navmap->new();
if (!defined($navmap)) {
$r->print(''.&mt('Retrieval of List Failed').' '.
@@ -2256,7 +2354,6 @@ sub list_symbs {
}
$r->print("\n\n");
}
- $r->print(''.&mt('Back to Course Editor').' ');
}
@@ -2265,6 +2362,7 @@ sub verifycontent {
my $crstype = &Apache::loncommon::course_type();
$r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
+ &startContentScreen($r,'tools');
$hashtied=0;
undef %alreadyseen;
%alreadyseen=();
@@ -2283,13 +2381,7 @@ sub verifycontent {
}
}
&untiehash();
- $r->print(
- ''.&mt('Done').'
'
- .' '
- .''
- .&mt('Back to Course Editor')
- .'
'
- );
+ $r->print(''.&mt('Done').'
');
}
@@ -2304,6 +2396,8 @@ sub checkversions {
my $crstype = &Apache::loncommon::course_type();
$r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
$r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
+ &startContentScreen($r,'tools');
+
my $header='';
my $startsel='';
my $monthsel='';
@@ -2614,8 +2708,67 @@ sub init_breadcrumbs {
bug=>'Instructor Interface'});
}
+# subroutine to list form elements
+sub create_list_elements {
+ my @formarr = @_;
+ my $list = '';
+ for my $button (@formarr){
+ for my $picture(keys %$button) {
+ $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
+ }
+ }
+ return $list;
+}
+
+# subroutine to create ul from list elements
+sub create_form_ul {
+ my $list = shift;
+ my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
+ return $ul;
+}
+
+#
+# Start tabs
+#
+
+sub startContentScreen {
+ my ($r,$mode)=@_;
+ $r->print('');
+ $r->print(' '.&mt('Content Overview').' ');
+
+ my $active = '';
+# does this user have privileges to modify docs?
+ my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+
+ my $onclick;
+ my $href;
+
+ if ($allowed) {
+ $r->print(' '.&mt('Content Editor').' ');
+ }
+ $r->print(' '.&mt('Content Search').' ');
+ $r->print(' '.&mt('Content Index').' ');
+ $r->print(''.&mt('Supplemental Documents').' ');
+ $r->print(' ');
+ $r->print(''
+ .'
');
+ $r->print('
');
+}
+
+#
+# End tabs
+#
+sub endContentScreen {
+ my ($r)=@_;
+ $r->print('
');
+}
+sub supplemental_base {
+ return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Documents'));
+}
sub handler {
my $r = shift;
@@ -2624,7 +2777,7 @@ sub handler {
return OK if $r->header_only;
my $crstype = &Apache::loncommon::course_type();
-
+#
# --------------------------------------------- Initialize help topics for this
foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
'Adding_External_Resource','Navigate_Content',
@@ -2669,45 +2822,83 @@ sub handler {
&init_breadcrumbs('exportcourse','IMS Export');
&exportcourse($r);
} else {
-# is this a standard course?
+#
+# Done catching special calls
+# The whole rest is for course and supplemental documents
+# Get the parameters that may be needed
+#
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['folderpath','pagepath',
+ 'pagesymb','forcesupplement','forcestandard']);
+
+# standard=1: this is a "new-style" course with an uploaded map as top level
+# standard=2: this is a "old-style" course, and there is nothing we can do
my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
- my $forcestandard = 0;
- my $forcesupplement;
+
+# Decide whether this should display supplemental or main content
+# supplementalflag=1: show supplemental documents
+# supplementalflag=0: show standard documents
+
+
+ my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
+ if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
+ $supplementalflag=0;
+ }
+ if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
+ if ($env{'form.forcestandard'}) { $supplementalflag=0; }
+ unless ($allowed) { $supplementalflag=1; }
+ unless ($standard) { $supplementalflag=1; }
+
my $script='';
my $showdoc=0;
my $containertag;
my $uploadtag;
-
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['folderpath','pagepath',
- 'pagesymb']);
+# Where do we store these for when we come back?
+ my $stored_folderpath='docs_folderpath';
+ if ($supplementalflag) {
+ $stored_folderpath='docs_sup_folderpath';
+ }
+
# No folderpath, no pagepath, see if we have something stored
if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
- &Apache::loncommon::restore_course_settings('docs_folderpath',
+ &Apache::loncommon::restore_course_settings($stored_folderpath,
{'folderpath' => 'scalar'});
}
+
+# If we are not allowed to make changes, all we can see are supplemental docs
if (!$allowed) {
- unless($env{'form.folderpath'} =~ /^supplemental/) {
- $env{'form.folderpath'} = '';
+ $env{'form.pagepath'}='';
+ unless ($env{'form.folderpath'} =~ /^supplemental/) {
+ $env{'form.folderpath'} = &supplemental_base();
}
}
+# If we still not have a folderpath, see if we can resurrect at pagepath
if (!$env{'form.folderpath'} && $allowed) {
- &Apache::loncommon::restore_course_settings('docs_folderpath',
+ &Apache::loncommon::restore_course_settings($stored_folderpath,
{'pagepath' => 'scalar'});
}
- if ($env{'form.pagepath'}) {
- $env{'form.folderpath'}='';
- }
+# Make the zeroth entry in supplemental docs page paths, so we can get to top level
if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
- $env{'form.folderpath'} = 'supplemental&'.
- &escape(&mt('Supplemental '.$crstype.' Documents')).'&'.
+ $env{'form.folderpath'} = &supplemental_base()
+ .'&'.
$env{'form.folderpath'};
}
- &Apache::loncommon::store_course_settings('docs_folderpath',
+# If after all of this, we still don't have any paths, make them
+ unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
+ if ($supplementalflag) {
+ $env{'form.folderpath'}=&supplemental_base();
+ } else {
+ $env{'form.folderpath'}='default';
+ }
+ }
+
+# Store this
+ &Apache::loncommon::store_course_settings($stored_folderpath,
{'pagepath' => 'scalar',
'folderpath' => 'scalar'});
+
if ($env{'form.folderpath'}) {
my (@folderpath)=split('&',$env{'form.folderpath'});
$env{'form.foldername'}=&unescape(pop(@folderpath));
@@ -2741,38 +2932,12 @@ sub handler {
if ($showdoc) { # got called in sequence from course
$allowed=0;
} else {
- if (($env{'form.folder'}=~/^(?:group|default)_/) ||
- ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
- $forcestandard = 1;
- }
- $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
-
if ($allowed) {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
$script=&Apache::lonratedt::editscript('simple');
}
}
-# subroutine to list form elements
-sub create_list_elements {
- my @formarr = @_;
- my $list = '';
- for my $button (@formarr){
- for my $picture(keys %$button) {
- #my $link = Apache::lonhtmlcommon::htmltag('a' ,$button->{$picture}, {href => "test"});
- $list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
- }
- }
- return $list;
-}
-
-# subroutine to create ul from list elements
-sub create_form_ul {
- my $list = shift;
- my $ul = Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
- return $ul;
-}
-
# get course data
my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -2798,119 +2963,67 @@ sub create_form_ul {
# Breadcrumbs
&Apache::lonhtmlcommon::clear_breadcrumbs();
- if ($allowed) {
+ unless ($showdoc) {
&Apache::lonhtmlcommon::add_breadcrumb({
- href=>"/adm/coursedocs",text=>"$crstype Editor"});
+ href=>"/adm/coursedocs",text=>"$crstype Contents"});
- $r->print(&Apache::loncommon::start_page("$crstype Editor", $script,
+ $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
{'force_register' => $showdoc,})
.&Apache::loncommon::help_open_menu('','',273,'RAT')
.&Apache::lonhtmlcommon::breadcrumbs(
'Editing the Table of Contents for your '.$crstype,
'Docs_Adding_Course_Doc')
);
- } elsif ($showdoc) {
+ } else {
$r->print(&Apache::loncommon::start_page("$crstype documents",undef,
{'force_register' => $showdoc,}));
- } else {
- my $folder=$env{'form.folder'};
- if ($folder eq '' || $folder eq 'supplemental') {
- $env{'form.folderpath'} = 'supplemental&'.
- &escape(&mt('Supplemental '.$crstype.' Documents'));
- }
- my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
- $r->print(&Apache::loncommon::start_page("Supplemental documents").
- $breadcrumbtrail);
}
my %allfiles = ();
my %codebase = ();
- my ($upload_result,$upload_output);
+ my ($upload_result,$upload_output,$uploadphase);
if ($allowed) {
if (($env{'form.uploaddoc.filename'}) &&
($env{'form.cmd'}=~/^upload_(\w+)/)) {
-# Process file upload - phase one - upload and parse primary file.
+ my $context = $1;
+ # Process file upload - phase one - upload and parse primary file.
undef($hadchanges);
- $upload_result = &process_file_upload(\$upload_output,$coursenum,
- $coursedom,\%allfiles,
- \%codebase,$1);
+ $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
+ \%allfiles,\%codebase,$context);
if ($hadchanges) {
&mark_hash_old();
}
- if ($upload_result eq 'phasetwo') {
- $r->print($upload_output);
- }
- } elsif ($env{'form.phasetwo'}) {
- my %newname = ();
- my %origname = ();
- my %attribs = ();
- my $updateflag = 0;
- my $residx = $env{'form.newidx'};
- my $primary_url = &unescape($env{'form.primaryurl'});
-# Process file upload - phase two - gather secondary files.
- for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
- if ($env{'form.embedded_item_'.$i.'.filename'}) {
- my $javacodebase;
- $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
- $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
- if (exists($env{'form.embedded_codebase_'.$i})) {
- $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
- $origname{$i} =~ s#^\Q$javacodebase\E/##;
- }
- my @attributes = ();
- if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
- @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
- } else {
- @attributes = ($env{'form.embedded_attrib_'.$i});
- }
- foreach my $attr (@attributes) {
- push(@{$attribs{$i}},&unescape($attr));
- }
- if ($javacodebase) {
- $codebase{$i} = $javacodebase;
- $codebase{$i} =~ s#/$##;
- $updateflag = 1;
- }
- }
- unless ($newname{$i} eq $origname{$i}) {
- $updateflag = 1;
- }
- }
-# Process file upload - phase three - modify primary file
- if ($updateflag) {
- my ($content,$rtncode);
- my $updateflag = 0;
- my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
- if ($getstatus eq 'ok') {
- foreach my $item (keys(%newname)) {
- if ($newname{$item} ne $origname{$item}) {
- my $attrib_regexp = '';
- if (@{$attribs{$item}} > 1) {
- $attrib_regexp = join('|',@{$attribs{$item}});
- } else {
- $attrib_regexp = $attribs{$item}[0];
- }
- if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
- }
- $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
- }
- if (exists($codebase{$item})) {
- $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
- }
- }
-# Save edited file.
- my $saveresult;
- my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
- my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
- my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
- } else {
- &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
- }
- }
+ $r->print($upload_output);
+ } elsif ($env{'form.phase'} eq 'upload_embedded') {
+ # Process file upload - phase two - upload embedded objects
+ $uploadphase = 'check_embedded';
+ my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
+ my $state = &embedded_form_elems($uploadphase,$primaryurl,
+ $env{'form.newidx'});
+ my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my ($destination,$dir_root) = &embedded_destination();
+ my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
+ my $actionurl = '/adm/coursedocs';
+ my ($result,$flag) =
+ &Apache::loncommon::upload_embedded('coursedoc',$destination,
+ $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
+ $actionurl);
+ $r->print($result.&return_to_editor());
+ } elsif ($env{'form.phase'} eq 'check_embedded') {
+ # Process file upload - phase three - modify references in HTML file
+ $uploadphase = 'modified_orightml';
+ my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my ($destination,$dir_root) = &embedded_destination();
+ $r->print(&Apache::loncommon::modify_html_refs('coursedoc',$destination,
+ $docuname,$docudom,undef,
+ $dir_root).
+ &return_to_editor());
}
}
- unless ($showdoc || $upload_result eq 'phasetwo') {
+ unless ($showdoc || $uploadphase) {
# -----------------------------------------------------------------------------
my %lt=&Apache::lonlocal::texthash(
'uplm' => 'Upload a new main '.lc($crstype).' document',
@@ -2932,7 +3045,7 @@ sub create_form_ul {
'sipa' => 'Simple Course Page',
'sipr' => 'Simple Problem',
'drbx' => 'Drop Box',
- 'scuf' => 'Score Upload Form',
+ 'scuf' => 'External Scores (handgrade, upload, clicker)',
'bull' => 'Discussion Board',
'mypi' => 'My Personal Information Page',
'grpo' => 'Group Portfolio',
@@ -2979,12 +3092,7 @@ CHBO
$checkbox
FUFORM
- #$list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
- #$fileuploadform .= create_form_ul(create_list_elements(@fileuploada));
- $fileuploadform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$fileuploada,{class => 'LC_menubuttons_inline_text'}));
- $fileuploadform .= (<
-FUFORM
+ $fileuploadform .= &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$fileuploada,{class => 'LC_menubuttons_inline_text'})).'';
my $simpleeditdefaultform=(<
@@ -2995,7 +3103,7 @@ SEDFFORM
{ ' ' => "$help{'Importing_LON-CAPA_Resource'}" },
{ ' ' => "" },
);
- $simpleeditdefaultform .= create_form_ul(create_list_elements(@simpleeditdefaultforma));
+ $simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
$simpleeditdefaultform .=(<
@@ -3009,14 +3117,15 @@ SEDFFORM
SEDFFORM
- my $extresourcesform=(<
- $uploadtag
-
- $help{'Adding_External_Resource'}
-
+ my $extresourcesform=(<
+ $uploadtag
+
+ $help{'Adding_External_Resource'}
+
ERFORM
+
if ($allowed) {
&update_paste_buffer($coursenum,$coursedom);
my %lt=&Apache::lonlocal::texthash(
@@ -3040,57 +3149,21 @@ ERFORM
HIDDENFORM
}
-# --------------------------------------------------------- Main tab structure
-
- my $activeClass = 1;
- my $active = '';
- my %tabtitles = (
- main => {
- Course => &mt('Main Course Documents'),
- Community => &mt('Main Community Documents'),
- },
- supplemental => {
- Course => &mt('Supplemental Course Documents'),
- Community => &mt('Supplemental Community Documents'),
- },
- );
+
+# Generate the tabs
+ &startContentScreen($r,($supplementalflag?'supdocs':'docs'));
+
+
+#
+
+ my $savefolderpath;
+
if ($allowed) {
- $r->print('');
- if (($standard) && ($allowed) && (!$forcesupplement) && (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'}eq"" || ($env{'form.pagepath'}))) {
- if($activeClass == 1){
- $active = 'class="active"';
- $activeClass = 0;
- }
- }
- $r->print(''.$tabtitles{'main'}{$crstype}.' ');
- $active = '';
- if (!$forcestandard || ($env{'form.folderpath'}=~/^supplemental/)) {
- if($activeClass == 1){
- $active = 'class="active"';
- }
- }
- $r->print(''.$tabtitles{'supplemental'}{$crstype}.' ');
- $r->print(' ');
- } else {
- $r->print(' ');
- }
- $r->print(''
- .'
');
-# --------------------------------------------------------- Standard documents
- my $savefolderpath;
- $active = 'style="display: none;"';
- if($activeClass == 0){
- $active = 'style="display: block;"';
- }
- if ($allowed) {
- $r->print('
');
my $folder=$env{'form.folder'};
- if ($folder eq '' || $folder=~/^supplemental/) {
+ if ($folder eq '' || $supplementalflag) {
$folder='default';
$savefolderpath = $env{'form.folderpath'};
- $env{'form.folderpath'}='default&'.&escape($tabtitles{'main'}{$crstype});
+ $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
$uploadtag = '
';
}
@@ -3224,11 +3297,14 @@ NROSTFORM
my $specialdocumentsform;
my @specialdocumentsforma;
+my $gradingform;
+my @gradingforma;
+my $communityform;
+my @communityforma;
my $newfolderform;
my $newfolderb;
- unless ($env{'form.pagepath'}) {
- my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+ my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
my $newpageform=(<
@@ -3275,35 +3351,35 @@ NGFFORM
@specialdocumentsforma=(
{' '=>$newpageform},
{' '=>$newsylform},
- {' '=>$newgroupfileform},
- );
+ {' '=>$newnavform},
+ {' '=>$newsmppageform},
+ );
+ $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
+
my @importdoc = (
{' '=>$extresourcesform},
{' '=>$imspform},);
- $fileuploadform = create_form_ul(create_list_elements(@importdoc)) . ' ' . $fileuploadform;
+ $fileuploadform = &create_form_ul(&create_list_elements(@importdoc)) . ' ' . $fileuploadform;
- push @specialdocumentsforma, ({' '=>$newnavform},
- {' '=>$newsmppageform},
- {' '=>$newsmpproblemform},
- {' '=>$newdropboxform},
- {' '=>$newexuploadform},
- {' '=>$newbulform},
- {' '=>$newaboutmeform},
- {' '=>$newaboutsomeoneform},
- {' '=>$newrosterform},);
+ @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));
- $specialdocumentsform = create_form_ul(create_list_elements(@specialdocumentsforma));
- }
-if($env{'form.pagepath'}) {
-
- @specialdocumentsforma=(
- {' '=>$newsmpproblemform},
- {' '=>$newexuploadform}
- );
- $specialdocumentsform= create_form_ul(create_list_elements(@specialdocumentsforma));
-}
my @tools = (
# {' '=>$extresourcesform},
@@ -3314,42 +3390,40 @@ my @tools = (
my %orderhash = (
'aa' => ['Import Documents',$fileuploadform],
'bb' => ['Published Resources',$simpleeditdefaultform],
- 'cc' => ['Special Documents',$specialdocumentsform],
- 'dd' => ['Tools', create_form_ul(create_list_elements(@tools)).&generate_admin_options(\%help,\%env)],
+ 'cc' => ['Grading Resources',$gradingform],
+ 'ff' => ['Tools', &create_form_ul(&create_list_elements(@tools)).&generate_admin_options(\%help,\%env)],
);
-unless($env{'form.pagepath'}) {
+unless ($env{'form.pagepath'}) {
$orderhash{'00'} = ['Newfolder',$newfolderform];
+ $orderhash{'dd'} = ['Community Resources',$communityform];
+ $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
}
-my $tid='1';
$hadchanges=0;
- my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
- if ($error) {
- $r->print(''.$error.'
');
- }
- if ($hadchanges) {
- &mark_hash_old();
- }
+ 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($tid,\%orderhash));
+ &changewarning($r,'');
+ $r->print(&generate_edit_table('1',\%orderhash));
+ }
-$r->print(' ');
}
-# ----------------------------------------------------- Supplemental documents
- $active = 'style="display: none;"';
- if($activeClass == 1){
- $active = 'style="display: block;"';
- }
- $r->print('
');
+
+# 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'} eq ''))) {
- $env{'form.folderpath'} = 'supplemental&'.
- &escape(&mt('Supplemental '.$crstype.' Documents'));
+ $env{'form.folderpath'} = &supplemental_base();
} elsif ($allowed) {
$env{'form.folderpath'} = $savefolderpath;
}
@@ -3378,7 +3452,7 @@ $r->print('
');
SUPDOCFORM
- $supupdocform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."";
+ $supupdocform .= &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."";
my $supnewfolderform=(<
@@ -3433,30 +3507,27 @@ my @supimportdoc = (
{' '
=>$supnewextform},
);
-$supupdocform = create_form_ul(create_list_elements(@supimportdoc)) . ' ' . $supupdocform;
+$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))]
+ 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
);
-
- my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
- if ($error) {
- $r->print(''.$error.'
');
+ if ($supplementalflag) {
+ my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
+ if ($error) {
+ $r->print(''.$error.'
');
+ }
+ $r->print(&generate_edit_table('2',\%suporderhash));
}
- my $tid='2';
- $r->print(&generate_edit_table($tid,\%suporderhash));
- } else {
+ } elsif ($supplementalflag) {
my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
if ($error) {
$r->print(''.$error.'
');
}
}
-
-$r->print(' ');
-$r->print('
');
-
+ &endContentScreen($r);
if ($allowed) {
$r->print('
@@ -3468,7 +3539,7 @@ $r->print('');
');
}
} else {
- unless ($upload_result eq 'phasetwo') {
+ unless ($uploadphase) {
# -------------------------------------------------------- This is showdoc mode
$r->print("".&mt('Uploaded Document').' - '.
&Apache::lonnet::gettitle($r->uri).' '.
@@ -3481,6 +3552,42 @@ $r->print('');
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(
@@ -3511,7 +3618,7 @@ sub generate_admin_options {
{' '
=>""},
);
- return '';
+ return '';
}
@@ -3570,7 +3677,7 @@ sub editing_js {
t_mnf => 'New Folder',
p_mnp => 'Name of New Page',
t_mnp => 'New Page',
- p_mxu => 'Title for the Uploaded Score',
+ 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',
@@ -3599,7 +3706,7 @@ sub editing_js {
}
}
my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
- my $toplevelsupp = 'supplemental&Supplemental%20'.$crstype.'%20Documents';
+ my $toplevelsupp = &supplemental_base();
return <