--- loncom/interface/londocs.pm 2009/06/09 18:42:42 1.371
+++ loncom/interface/londocs.pm 2012/05/07 02:12:47 1.484
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.371 2009/06/09 18:42:42 tempelho Exp $
+# $Id: londocs.pm,v 1.484 2012/05/07 02:12:47 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,8 +26,6 @@
# http://www.lon-capa.org/
#
-
-
package Apache::londocs;
use strict;
@@ -35,11 +33,13 @@ 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;
use Apache::lonclonecourse;
use Apache::lonnavmaps;
+use Apache::lonnavdisplay();
use HTML::Entities;
use GDBM_File;
use Apache::lonlocal;
@@ -100,12 +100,17 @@ sub authorhosts {
my $allowed=0;
my $myhome=&Apache::lonnet::homeserver($ca,$cd);
my @ids=&Apache::lonnet::current_machine_ids();
- foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
+ foreach my $id (@ids) {
+ if ($id eq $myhome) {
+ $allowed=1;
+ last;
+ }
+ }
if ($allowed) {
$home++;
- $outhash{'home_'.$ca.'@'.$cd}=1;
+ $outhash{'home_'.$ca.':'.$cd}=1;
} else {
- $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
+ $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
$other++;
}
}
@@ -114,22 +119,6 @@ sub authorhosts {
}
-sub dumpbutton {
- my ($home,$other,%outhash)=&authorhosts();
- my $type = &Apache::loncommon::course_type();
- if ($home+$other==0) { return ''; }
- if ($home) {
- return ''.
- &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'
';
- } else {
- return '
' - .&mt('Download the zip file from [_1]IMS '.lc($type).' archive[_2]' - ,'','') - .'
'; - if ($copyresult) { - $outcome .= '' - .&mt('The following errors occurred during export - [_1]' - ,$copyresult) - .'
'; - } - } else { - $outcome = '-ENDPASTE - $r->print(' '); + $r->print('
'); } sub do_paste_from_buffer { @@ -1429,7 +791,6 @@ sub update_parameter { sub handle_edit_cmd { my ($coursenum,$coursedom) =@_; - my ($cmd,$idx)=split('_',$env{'form.cmd'}); my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]; @@ -1437,7 +798,7 @@ sub handle_edit_cmd { if ($cmd eq 'del') { if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) && - ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) { + ($url!~/$LONCAPA::assess_page_seq_re/)) { &Apache::lonnet::removeuploadedurl($url); } else { &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]); @@ -1473,11 +834,21 @@ sub handle_edit_cmd { } sub editor { - my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_; - + my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype, + $supplementalflag,$orderhash,$iconpath)=@_; my $container= ($env{'form.pagepath'}) ? 'page' : 'sequence'; + my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) = + &breadcrumbs($allowed,$crstype); + $r->print($breadcrumbtrail); + + my $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container"; + + unless ($allowed) { + $randompick = -1; + } + my ($errtext,$fatal) = &mapread($coursenum,$coursedom, $folder.'.'.$container); return $errtext if ($fatal); @@ -1489,10 +860,6 @@ sub editor { $LONCAPA::map::resources[$idx]=''; } - my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)= - &breadcrumbs($folder,$allowed,$type); - $r->print($breadcrumbtrail); - # ------------------------------------------------------------ Process commands # ---------------- if they are for this folder and user allowed to make changes @@ -1569,36 +936,100 @@ sub editor { my $idx=0; my $shown=0; if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) { - $r->print(''.&mt('Parameters').':
'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'
'); - } - if ($is_random_order) { - $r->print(''.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').'
'); + ($is_random_order?'' + .&mt('Caution: this folder is set to randomly pick a subset' + .' of resources. Adding or removing resources from this' + .' folder will change the set of resources that the' + .' students see, resulting in spurious or missing credit' + .' for completed problems, not limited to ones you' + .' modify. Do not modify the contents of this folder if' + .' it is in active student use.') + .'
' + ); + } + if ($is_random_order) { + $r->print('' + .&mt('Caution: this folder is set to randomly order its' + .' contents. Adding or removing resources from this folder' + .' will change the order of resources shown.') + .'
' + ); + } + $r->print(''.&mt('Currently no documents.').' | '.&mt('Move').' | ' + .''.&mt('Actions').' | ' + .''.&mt('Document').' | '; + if ($folder !~ /^supplemental/) { + $to_show .= ''.&mt('Settings').' | '; + } + $to_show .= &Apache::loncommon::end_data_table_header_row(); + } + $to_show .= $output.' ' + .&Apache::loncommon::end_data_table() + .'
---|
'.&mt('Uploaded [_1]',''. + $stored.'').'
'; + } else { + my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$}); + + $$upload_output = ''.$errtext.'
'; - return 'failed'; + $$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').'\n"); + $r->print('\n"); + $r->print(&Apache::loncommon::end_data_table()); } - $r->print(''.&mt('Return to DOCS').''); } sub verifycontent { my ($r) = @_; - my $type = &Apache::loncommon::course_type(); - my $loaderror=&Apache::lonnet::overloaderror($r); - if ($loaderror) { return $loaderror; } - $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents')); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents')); + my $crstype = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents')); + $r->print(&startContentScreen('tools')); + $r->print(''.&mt("$crstype Content Identifiers").'
'. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''.&mt('Title').' '.&mt('Identifier').' '. + &Apache::loncommon::end_data_table_header_row()."\n"); + my $count; foreach my $res ($navmap->retrieveResources()) { - $r->print($res->compTitle()."\t".$res->symb()."\n"); + $r->print(&Apache::loncommon::start_data_table_row(). + ''.$res->compTitle().' '. + ''.$res->symb().' '. + &Apache::loncommon::start_data_table_row()); + $count ++; + } + if (!$count) { + $r->print(&Apache::loncommon::start_data_table_row(). + ''.&mt("$crstype is empty").' '. + &Apache::loncommon::end_data_table_row()); } - $r->print("\n
'.&mt('Done').'
'); } @@ -2218,9 +1744,11 @@ sub devalidateversioncache { sub checkversions { my ($r) = @_; - my $type = &Apache::loncommon::course_type(); - $r->print(&Apache::loncommon::start_page("Check $type Document Versions")); - $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions")); + 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")); + $r->print(&startContentScreen('tools')); + my $header=''; my $startsel=''; my $monthsel=''; @@ -2272,16 +1800,18 @@ sub checkversions { if (&Apache::lonnet::put('resourceversions',\%newsetversions, $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { - $r->print('
+SEDFFORM
+ my @simpleeditdefaultforma = (
+ { '' => "$uploadtag$lt{'srch'}" },
+ { '' => "$lt{'impo'}$help{'Importing_LON-CAPA_Resource'}" },
+ { '' => "$lt{'wish'}" },
+ );
+ $simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
+ $simpleeditdefaultform .=(<
-
$help{'Load_Map'}
-
'.$error.'
'); - } - if ($hadchanges) { - &mark_hash_old(); - } + unless (($supplementalflag || $toolsflag)) { + my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, + $supplementalflag,\%orderhash,$iconpath); + if ($error) { + $r->print(''.$error.'
'); + } + if ($hadchanges) { + &mark_hash_old(); + } + + &changewarning($r,''); + } + } + +# Supplemental documents start here - &changewarning($r,''); - $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc', - &mt('Editing the Table of Contents for your '.$type))); -$r->print(''.$error.'
'); + } + } + } elsif ($supplementalflag) { + my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, + $supplementalflag,'',$iconpath); + if ($error) { + $r->print(''.$error.'
'); + } + } -my $tid='2'; -my $varscd = 'Supplemental Course Documents'; + $r->print(&endContentScreen()); -$r->print(&generate_edit_table($tid,$varscd,\%suporderhash)); -my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type); - if ($error) { - $r->print(''.$error.'
'); - } -$r->print(''. &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."
'.&mt('Not extracted.').'
'.
+ $error.'
'.$warning.'
'."\n"; + } + return $output; +} + +sub decompression_phase_two { + my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)= + &decompression_info(); + my $output; + if ($env{'form.archivedelete'}) { + $output = &remove_archive($docudom,$docuname,$container); + } + $output .= + &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname, + $destination,$dir_root,$hiddenelem); + return $output; +} + +sub remove_archive { + my ($docudom,$docuname,$container) = @_; + my $map = $env{'form.folder'}.'.'.$container; + my ($output,$delwarning,$delresult,$url); + my ($errtext,$fatal) = &mapread($docuname,$docudom,$map); + if ($fatal) { + if ($container eq 'page') { + $delwarning = &mt('An error occurred retrieving the contents of the current page.'); + } else { + $delwarning = &mt('An error occurred retrieving the contents of the current folder.'); + } + $delwarning .= &mt('As a result the archive file has not been removed.'); + } else { + my $currcmd = $env{'form.cmd'}; + my $position = $env{'form.position'}; + if ($position > 0) { + $env{'form.cmd'} = 'del_'.$position; + my ($title,$url,@rrest) = + split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]); + if (&handle_edit_cmd($docuname,$docudom)) { + ($errtext,$fatal) = &storemap($docuname,$docudom,$map); + if ($fatal) { + if ($container eq 'page') { + $delwarning = &mt('An error occurred updating the contents of the current page.'); + } else { + $delwarning = &mt('An error occurred updating the contents of the current folder.'); + } + } else { + $delresult = &mt('Archive file removed.'); + } + } + } + $env{'form.cmd'} = $currcmd; + } + if ($delwarning) { + $output = ''. + $delwarning. + '
'; + } + if ($delresult) { + $output .= ''. + $delresult. + '
'; + } + return $output; } +sub generate_admin_menu { + my ($crstype) = @_; + my $lc_crstype = lc($crstype); + my ($home,$other,%outhash)=&authorhosts(); + my %lt=&Apache::lonlocal::texthash ( + 'vc' => 'Verify Content', + 'cv' => 'Check/Set Resource Versions', + 'ls' => 'List Resource Identifiers', + 'imse' => 'Export contents to IMS Archive', + 'dcd' => "Dump $crstype Content to Authoring Space", + ); + my ($candump,$dumpurl); + if ($home + $other > 0) { + $candump = 'F'; + if ($home) { + $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')"; + } else { + my @hosts; + foreach my $aurole (keys(%outhash)) { + unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) { + push(@hosts,$outhash{$aurole}); + } + } + if (@hosts == 1) { + my $switchto = '/adm/switchserver?otherserver='.$hosts[0]. + '&role='. + &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='. + &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&'); + $dumpurl = "javascript:dump_needs_switchserver('$switchto')"; + } else { + $dumpurl = "javascript:choose_switchserver_window()"; + } + } + } + my @menu= + ({ categorytitle=>'Administration', + items =>[ + { linktext => $lt{'vc'}, + url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')", + permission => 'F', + help => 'Verify_Content', + icon => 'verify.png', + linktitle => 'Verify contents can be retrieved/rendered', + }, + { linktext => $lt{'cv'}, + url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')", + permission => 'F', + help => 'Check_Resource_Versions', + icon => 'resversion.png', + linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions", + }, + { linktext => $lt{'ls'}, + url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')", + permission => 'F', + #help => '', + icon => 'symbs.png', + linktitle => "List the unique identifier used for each resource instance in your $lc_crstype" + }, + ] + }, + { categorytitle=>'Export', + items =>[ + { linktext => $lt{'imse'}, + url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')", + permission => 'F', + help => 'Docs_Export_Course_Docs', + icon => 'imsexport.png', + linktitle => $lt{'imse'}, + }, + { linktext => $lt{'dcd'}, + url => $dumpurl, + permission => $candump, + #help => '', + icon => 'dump.png', + linktitle => $lt{'dcd'}, + }, + ] + }); + return ''; +} sub generate_edit_table { - my ($tid,$varcd,$orderhash_ref) = @_; + my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_; + return unless(ref($orderhash_ref) eq 'HASH'); my %orderhash = %{$orderhash_ref}; my $form; my $activetab; @@ -3372,51 +3278,78 @@ sub generate_edit_table { if($env{'form.active'} ne ''){ $activetab = $env{'form.active'}; } - $form = '$lt{'yone'}<\\/p>\\n'+ + '