--- loncom/interface/londocs.pm 2010/12/25 04:40:15 1.434.2.3
+++ loncom/interface/londocs.pm 2012/03/28 12:58:42 1.479
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.434.2.3 2010/12/25 04:40:15 raeburn Exp $
+# $Id: londocs.pm,v 1.479 2012/03/28 12:58:42 goltermann Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,8 +26,6 @@
# http://www.lon-capa.org/
#
-
-
package Apache::londocs;
use strict;
@@ -41,6 +39,7 @@ use Apache::lonratedt();
use Apache::lonxml;
use Apache::lonclonecourse;
use Apache::lonnavmaps;
+use Apache::lonnavdisplay();
use HTML::Entities;
use GDBM_File;
use Apache::lonlocal;
@@ -176,7 +175,7 @@ sub dumpcourse {
$newfilename=&clean($newfilename);
$newfilename.='.'.$ext;
my @dirs=split(/\//,$newfilename);
- my $path='/home/'.$ca.'/public_html';
+ my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
my $makepath=$path;
my $fail=0;
for (my $i=0;$i<$#dirs;$i++) {
@@ -264,704 +263,12 @@ sub dumpcourse {
}
}
-
-
sub exportbutton {
my $crstype = &Apache::loncommon::course_type();
return "".&mt('IMS Export')."".
&Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').' ';
}
-
-
-sub exportcourse {
- my $r=shift;
- 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 $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;
-
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['finishexport']);
- if ($env{'form.finishexport'}) {
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['archive','discussion']);
-
- my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
- my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
- if (@exportitems == 0 && @discussions == 0) {
- $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;
- my $manifestok = 0;
- my $imsresources;
- my $tempexport;
- my $copyresult;
- my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
- if ($manifestok) {
- &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
- close($ims_manifest);
-
-#Create zip file in prtspool
- my $imszipfile = '/prtspool/'.
- $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
- time.'_'.rand(1000000000).'.zip';
- my $cwd = &Cwd::getcwd();
- my $imszip = '/home/httpd/'.$imszipfile;
- chdir $tempexport;
- open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
- close(OUTPUT);
- chdir $cwd;
- $outcome .= '
'
- .&mt('[_1]Your IMS package[_2] is ready for download.'
- ,'','')
- .'
';
- if ($copyresult) {
- $outcome .= '
'
- .&mt('The following errors occurred during export - [_1]'
- ,$copyresult)
- .'
';
- }
- } else {
- $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.')
- .'
');
}
@@ -2300,6 +1677,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='';
@@ -2351,9 +1730,11 @@ 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('
'.&mt('Your Version Settings have been Saved').'
');
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
} else {
- $r->print('
'.&mt('An Error Occured while Attempting to Save your Version Settings').'
');
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
}
&mark_hash_old();
}
@@ -2419,12 +1800,19 @@ sub checkversions {
'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
- 'di' => 'Differences');
+ 'di' => 'Differences',
+ 'save' => 'Save',
+ 'act' => 'Actions');
$r->print(<
-
-
+
+
+
-
$header
-
+
$header
+
ENDHEADERS
+ #number of columns for version history
+ my $num_ver_col = 1;
+ $r->print(
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('Resources').'
'.
+ "
$lt{'mr'}
".
+ "
$lt{'ve'}
".
+ "
$lt{'vu'}
".
+ '
'.&mt('History').'
'.
+ '');
foreach my $key (sort(keys(%changes))) {
if ($changes{$key}>$starttime) {
my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
my $currentversion=&Apache::lonnet::getversion($key);
if ($currentversion<0) {
- $currentversion=&mt('Could not be determined.');
+ $currentversion=''.&mt('Could not be determined.').'';
}
my $linkurl=&Apache::lonnet::clutter($key);
- $r->print(
- '
');
+}
+
+#
+# End tabs
+#
+
+sub endContentScreen {
+ my ($r)=@_;
+ $r->print('
');
+}
+
+sub supplemental_base {
+ return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
+}
sub handler {
my $r = shift;
@@ -2620,7 +2062,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',
@@ -2644,8 +2086,14 @@ sub handler {
$help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
$help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
-# does this user have privileges to modify docs
- my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+
+ my $allowed;
+# URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
+ unless ($r->uri eq '/adm/supplemental') {
+ # does this user have privileges to modify content.
+ $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+ }
+
if ($allowed && $env{'form.verify'}) {
&init_breadcrumbs('verify','Verify Content');
&verifycontent($r);
@@ -2663,56 +2111,173 @@ sub handler {
&dumpcourse($r);
} elsif ($allowed && $env{'form.exportcourse'}) {
&init_breadcrumbs('exportcourse','IMS Export');
- &exportcourse($r);
+ &Apache::imsexport::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',
+ 'symb','command']);
+
+# 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 $addentries = {};
+ my $container;
my $containertag;
my $uploadtag;
+# Do we directly jump somewhere?
+
+ if ($env{'form.command'} eq 'direct') {
+ my ($mapurl,$id,$resurl);
+ if ($env{'form.symb'} ne '') {
+ ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
+ if ($resurl=~/\.(sequence|page)$/) {
+ $mapurl=$resurl;
+ } elsif ($resurl eq 'adm/navmaps') {
+ $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
+ }
+ my $mapresobj;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ $mapresobj = $navmap->getResourceByUrl($mapurl);
+ }
+ $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
+ my $type=$2;
+ my $path;
+ if (ref($mapresobj)) {
+ my $pcslist = $mapresobj->map_hierarchy();
+ if ($pcslist ne '') {
+ foreach my $pc (split(/,/,$pcslist)) {
+ next if ($pc <= 1);
+ my $res = $navmap->getByMapPc($pc);
+ if (ref($res)) {
+ my $thisurl = $res->src();
+ $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
+ my $thistitle = $res->title();
+ $path .= '&'.
+ &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
+ &Apache::lonhtmlcommon::entity_encode($thistitle).
+ ':'.$res->randompick().
+ ':'.$res->randomout().
+ ':'.$res->encrypted().
+ ':'.$res->randomorder();
+ }
+ }
+ }
+ $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
+ &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
+ ':'.$mapresobj->randompick().
+ ':'.$mapresobj->randomout().
+ ':'.$mapresobj->encrypted().
+ ':'.$mapresobj->randomorder();
+ } else {
+ my $maptitle = &Apache::lonnet::gettitle($mapurl);
+ $path = '&default&...::::'.
+ '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
+ &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
+ }
+ $path = 'default&'.
+ &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
+ $path;
+ if ($type eq 'sequence') {
+ $env{'form.folderpath'}=$path;
+ $env{'form.pagepath'}='';
+ } else {
+ $env{'form.pagepath'}=$path;
+ $env{'form.folderpath'}='';
+ }
+ } elsif ($env{'form.supppath'} ne '') {
+ $env{'form.folderpath'}=$env{'form.supppath'};
+ }
+ } elsif ($env{'form.command'} eq 'editdocs') {
+ $env{'form.folderpath'} = 'default&'.
+ &Apache::lonhtmlcommon::entity_encode('Main Course Content');
+ $env{'form.pagepath'}='';
+ } elsif ($env{'form.command'} eq 'editsupp') {
+ $env{'form.folderpath'} = 'default&'.
+ &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
+ $env{'form.pagepath'}='';
+ }
+
+# Where do we store these for when we come back?
+ my $stored_folderpath='docs_folderpath';
+ if ($supplementalflag) {
+ $stored_folderpath='docs_sup_folderpath';
+ }
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['folderpath','pagepath',
- 'pagesymb']);
# 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));
$env{'form.folder'}=pop(@folderpath);
+ $container='sequence';
}
if ($env{'form.pagepath'}) {
my (@pagepath)=split('&',$env{'form.pagepath'});
$env{'form.pagename'}=&unescape(pop(@pagepath));
$env{'form.folder'}=pop(@pagepath);
+ $container='page';
$containertag = ''.
'';
$uploadtag =
@@ -2737,38 +2302,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'};
@@ -2783,7 +2322,22 @@ sub create_form_ul {
$iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
if ($allowed) {
- $script .= &editing_js($udom,$uname);
+ my @tabids;
+ if ($supplementalflag) {
+ @tabids = ('002','ee2','ff2');
+ } else {
+ @tabids = ('aa1','bb1','cc1','ff1');
+ unless ($env{'form.pagepath'}) {
+ unshift(@tabids,'001');
+ push(@tabids,('dd1','ee1'));
+ }
+ }
+ my $tabidstr = join("','",@tabids);
+ $script .= &editing_js($udom,$uname,$supplementalflag).
+ &resize_contentdiv_js($tabidstr);
+ $addentries = {
+ onload => "javascript:resize_contentdiv('contentscroll','1','1');",
+ };
}
# -------------------------------------------------------------------- Body tag
$script = '