--- loncom/interface/londocs.pm 2003/08/05 12:47:21 1.71
+++ loncom/interface/londocs.pm 2013/01/14 20:32:04 1.532
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.71 2003/08/05 12:47:21 www Exp $
+# $Id: londocs.pm,v 1.532 2013/01/14 20:32:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,13 +30,23 @@ package Apache::londocs;
use strict;
use Apache::Constants qw(:common :http);
+use Apache::imsexport;
use Apache::lonnet;
use Apache::loncommon;
-use Apache::lonratedt;
-use Apache::lonratsrv;
+use Apache::lonhtmlcommon;
+use LONCAPA::map();
+use Apache::lonratedt();
use Apache::lonxml;
+use Apache::lonclonecourse;
+use Apache::lonnavmaps;
+use Apache::lonnavdisplay();
+use Apache::lonextresedit();
use HTML::Entities;
+use HTML::TokeParser;
use GDBM_File;
+use Apache::lonlocal;
+use Cwd;
+use LONCAPA qw(:DEFAULT :match);
my $iconpath;
@@ -47,268 +57,2616 @@ my %alreadyseen=();
my $hadchanges;
-# Available help topics
my %help=();
-# Mapread read maps into lonratedt::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)=@_;
return
- &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map);
+ &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
+ $map);
}
sub storemap {
- my ($coursenum,$coursedom,$map)=@_;
+ my ($coursenum,$coursedom,$map,$contentchg)=@_;
+ my $report;
+ if (($contentchg) && ($map =~ /^default/)) {
+ $report = 1;
+ }
+ my ($outtext,$errtext)=
+ &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
+ $map,1,$report);
+ if ($errtext) { return ($errtext,2); }
+
$hadchanges=1;
- return
- &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
+ return ($errtext,0);
}
-sub editor {
- my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
- if ($ENV{'form.foldername'}) {
- $r->print('
Folder: '.$ENV{'form.foldername'}.'
');
- }
- my $errtext='';
- my $fatal=0;
- ($errtext,$fatal)=
- &mapread($coursenum,$coursedom,$folder.'.sequence');
- if ($#Apache::lonratedt::order<1) {
- $Apache::lonratedt::order[0]=1;
- $Apache::lonratedt::resources[1]='';
+
+
+sub authorhosts {
+ my %outhash=();
+ my $home=0;
+ my $other=0;
+ foreach my $key (keys(%env)) {
+ if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
+ my $role=$1;
+ my $realm=$2;
+ my ($start,$end)=split(/\./,$env{$key});
+ if (($start) && ($start>time)) { next; }
+ if (($end) && (time>$end)) { next; }
+ my ($ca,$cd);
+ if ($1 eq 'au') {
+ $ca=$env{'user.name'};
+ $cd=$env{'user.domain'};
+ } else {
+ ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
+ }
+ 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;
+ last;
+ }
+ }
+ if ($allowed) {
+ $home++;
+ $outhash{'home_'.$ca.':'.$cd}=1;
+ } else {
+ $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
+ $other++;
+ }
+ }
}
- if ($fatal) {
- $r->print('
'.$errtext.'
');
+ return ($home,$other,%outhash);
+}
+
+
+sub clean {
+ my ($title)=@_;
+ $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
+ return $title;
+}
+
+
+
+sub dumpcourse {
+ my ($r) = @_;
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
+ &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
+ $r->print(&startContentScreen('tools'));
+ my ($home,$other,%outhash)=&authorhosts();
+ unless ($home) {
+ $r->print(&endContentScreen());
+ return '';
+ }
+ my $origcrsid=$env{'request.course.id'};
+ my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
+ if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
+# Do the dumping
+ unless ($outhash{'home_'.$env{'form.authorspace'}}) {
+ $r->print(&endContentScreen());
+ return '';
+ }
+ my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
+ $r->print('
'.&mt('Copying Files').'
');
+ my $title=$env{'form.authorfolder'};
+ $title=&clean($title);
+ my %replacehash=();
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.namefor\_(.+)/) {
+ $replacehash{$1}=$env{$key};
+ }
+ }
+ my $crs='/uploaded/'.$env{'request.course.id'}.'/';
+ $crs=~s/\_/\//g;
+ foreach my $item (keys(%replacehash)) {
+ my $newfilename=$title.'/'.$replacehash{$item};
+ $newfilename=~s/\.(\w+)$//;
+ my $ext=$1;
+ $newfilename=&clean($newfilename);
+ $newfilename.='.'.$ext;
+ my @dirs=split(/\//,$newfilename);
+ my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
+ my $makepath=$path;
+ my $fail=0;
+ for (my $i=0;$i<$#dirs;$i++) {
+ $makepath.='/'.$dirs[$i];
+ unless (-e $makepath) {
+ unless(mkdir($makepath,0777)) { $fail=1; }
+ }
+ }
+ $r->print(' '.$item.' => '.$newfilename.': ');
+ if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
+ if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
+ print $fh &Apache::lonclonecourse::rewritefile(
+ &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
+ (%replacehash,$crs => '')
+ );
+ } else {
+ print $fh
+ &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
+ }
+ $fh->close();
+ } else {
+ $fail=1;
+ }
+ if ($fail) {
+ $r->print(''.&mt('fail').'');
+ } else {
+ $r->print(''.&mt('ok').'');
+ }
+ }
+ } else {
+ $r->print(&mt('Searching ...').' ');
+ $r->rflush();
+# Input form
+ $r->print('');
+ }
+ $r->print(&endContentScreen());
+}
+
+sub group_import {
+ my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
+ my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
+ %removeparam,$importuploaded,$fixuperrors);
+ $allmaps = {};
+ 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 = '';
+ $env{'form.output'}=$newmapstr;
+ my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
+ 'output',$1.$2);
+ if ($result != m|^/uploaded/|) {
+ $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
+ $fatal = 2;
+ }
+ if ($fatal) {
+ return ($errtext,$fatal);
+ }
+ }
+ if ($url) {
+ if (($caller eq 'londocs') &&
+ ($folder =~ /^default/)) {
+ unless ($donechk) {
+ my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
+ my $cid = $coursedom.'_'.$coursenum;
+ $allmaps =
+ &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
+ $chome,$cid);
+ $donechk = 1;
+ }
+ if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
+ &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
+ \%addedmaps,\%hierarchy,\%titles,$allmaps);
+ $importuploaded = 1;
+ } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
+ next if ($allmaps->{$url});
+ }
+ }
+ 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 = &LONCAPA::map::qtunescape($url);
+ $name = &LONCAPA::map::qtunescape($name);
+ $LONCAPA::map::resources[$residx] =
+ join(':', ($name, $url, $ext, 'normal', 'res'));
+ }
+ }
+ if ($importuploaded) {
+ my %import_errors;
+ my %updated = (
+ removefrommap => \%removefrommap,
+ removeparam => \%removeparam,
+ );
+ &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
+ if (keys(%import_errors) > 0) {
+ $fixuperrors =
+ '
'."\n".
+ &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
+ '
'."\n".
+ &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
+ '
'."\n");
+ foreach my $key (sort(keys(%paste_errors))) {
+ $r->print('
'.$key.'
'."\n");
}
-# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ $r->print('
'."\n");
+ }
+ }
+
+ $r->print($upload_output);
+
+ if (&handle_edit_cmd()) {
+ my $contentchg;
+ if ($env{'form.cmd'} =~ /^(del|cut)_/) {
+ $contentchg = 1;
}
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
+ return $errtext if ($fatal);
+ }
# Group import/search
- if ($ENV{'form.importdetail'}) {
- foreach (split(/\&/,$ENV{'form.importdetail'})) {
- if (defined($_)) {
- my ($name,$url)=split(/\=/,$_);
- $name=&Apache::lonnet::unescape($name);
- $url=&Apache::lonnet::unescape($url);
- if ($url) {
- my $idx=$#Apache::lonratedt::resources+1;
- $Apache::lonratedt::order
- [$#Apache::lonratedt::order+1]=$idx;
- my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
- $url=~s/\:/\:/g;
- $name=~s/\:/\:/g;
- $Apache::lonratedt::resources[$idx]=
- $name.':'.$url.':'.$ext.':normal:res';
- }
- }
- }
-# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ if ($env{'form.importdetail'}) {
+ my @imports;
+ foreach my $item (split(/\&/,$env{'form.importdetail'})) {
+ if (defined($item)) {
+ my ($name,$url,$residx)=
+ map {&unescape($_)} split(/\=/,$item);
+ if ($url=~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
+ my ($suffix,$errortxt,$locknotfreed) =
+ &newmap_suffix($1,$2,$coursedom,$coursenum);
+ if ($locknotfreed) {
+ $r->print($locknotfreed);
+ }
+ if ($suffix) {
+ $url =~ s/_new\./_$suffix./;
+ } else {
+ return $errortxt;
+ }
+ }
+ push(@imports, [$name, $url, $residx]);
+ }
+ }
+ ($errtext,$fatal,my $fixuperrors) =
+ &group_import($coursenum, $coursedom, $folder,$container,
+ 'londocs',@imports);
+ return $errtext if ($fatal);
+ if ($fixuperrors) {
+ $r->print($fixuperrors);
}
+ }
# Loading a complete map
- if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
- foreach
-(&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
- my $idx=$#Apache::lonratedt::resources;
- $idx++;
- $Apache::lonratedt::resources[$idx]=$_;
- $Apache::lonratedt::order
- [$#Apache::lonratedt::order+1]=$idx;
- }
+ if ($env{'form.loadmap'}) {
+ if ($env{'form.importmap'}=~/\w/) {
+ foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
+ my ($title,$url,$ext,$type)=split(/\:/,$res);
+ my $idx=&LONCAPA::map::getresidx($url);
+ $LONCAPA::map::resources[$idx]=$res;
+ $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
+ }
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.'.$container,1);
+ return $errtext if ($fatal);
+ } else {
+ $r->print('
'.&mt('No map selected.').'
');
-# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
- }
- }
+ }
+ }
+ &log_differences($plain);
+ }
# ---------------------------------------------------------------- End commands
# ---------------------------------------------------------------- Print screen
- my $idx=0;
- $r->print('
':'').
+ '');
+ if ($randompick>=0) {
+ $r->print('
'
+ .&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.')
+ .'
'
+ .&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.')
+ .'
+ENDPARMS
+ }
+ $line.=&Apache::loncommon::end_data_table_row();
return $line;
}
-# ---------------------------------------------------------------- tie the hash
+sub newmap_suffix {
+ my ($area,$container,$coursedom,$coursenum) = @_;
+ my ($prefix,$idtype,$errtext,$locknotfreed);
+ $prefix = 'docs';
+ if ($area eq 'supplemental') {
+ $prefix = 'supp';
+ }
+ $prefix .= $container;
+ $idtype = 'concat';
+ my ($suffix,$freedlock,$error) =
+ &Apache::lonnet::get_timebased_id($prefix,'num','uploadedmaps',
+ $coursedom,$coursenum);
+ if (!$suffix) {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
+ if ($error) {
+ $errtext .= ' '.$error;
+ }
+ }
+ if ($freedlock ne 'ok') {
+ $locknotfreed = '
'.&mt('There was a problem removing a lockfile. This will prevent creation of additional folders or composite pages in this course. Please contact the domain coordinator for your LON-CAPA domain.').'
';
+ }
+ return ($suffix,$errtext,$locknotfreed);
+}
+
+=pod
+
+=item tiehash()
+
+tie the hash
+
+=cut
sub tiehash {
+ my ($mode)=@_;
$hashtied=0;
- if ($ENV{'request.course.fn'}) {
- if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
- &GDBM_READER(),0640)) {
+ if ($env{'request.course.fn'}) {
+ if ($mode eq 'write') {
+ if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
+ &GDBM_WRCREAT(),0640)) {
+ $hashtied=2;
+ }
+ } else {
+ if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
+ &GDBM_READER(),0640)) {
$hashtied=1;
- }
- }
+ }
+ }
+ }
}
sub untiehash {
if ($hashtied) { untie %hash; }
$hashtied=0;
+ return OK;
}
-# --------------------------------------------------------------- check on this
+
+
sub checkonthis {
my ($r,$url,$level,$title)=@_;
+ $url=&unescape($url);
$alreadyseen{$url}=1;
$r->rflush();
if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
- $r->print(' ');
+ $r->print("\n ");
+ if ($level==0) {
+ $r->print(" ");
+ }
for (my $i=0;$i<=$level*5;$i++) {
$r->print(' ');
}
@@ -317,8 +2675,8 @@ sub checkonthis {
if ($url=~/^\/res\//) {
my $result=&Apache::lonnet::repcopy(
&Apache::lonnet::filelocation('',$url));
- if ($result==OK) {
- $r->print('ok');
+ if ($result eq 'ok') {
+ $r->print(''.&mt('ok').'');
$r->rflush();
&Apache::lonnet::countacc($url);
$url=~/\.(\w+)$/;
@@ -328,619 +2686,2337 @@ sub checkonthis {
for (my $i=0;$i<=$level*5;$i++) {
$r->print(' ');
}
- $r->print('- Rendering: ');
- my $oldpath=$ENV{'request.filename'};
- $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
- &Apache::lonxml::xmlparse($r,'web',
- &Apache::lonnet::getfile(
- &Apache::lonnet::filelocation('',$url)));
- $ENV{'request.filename'}=$oldpath;
- if (($Apache::lonxml::errorcount) ||
- ($Apache::lonxml::warningcount)) {
- if ($Apache::lonxml::errorcount) {
- $r->print(''.
- $Apache::lonxml::errorcount.' error(s) ');
+ $r->print('- '.&mt('Rendering:').' ');
+ my ($errorcount,$warningcount)=split(/:/,
+ &Apache::lonnet::ssi_body($url,
+ ('grade_target'=>'web',
+ 'return_only_error_and_warning_counts' => 1)));
+ if (($errorcount) ||
+ ($warningcount)) {
+ if ($errorcount) {
+ $r->print(''.
+ &mt('[quant,_1,error]',$errorcount).'');
}
- if ($Apache::lonxml::warningcount) {
- $r->print(''.
- $Apache::lonxml::warningcount.' warning(s)');
+ if ($warningcount) {
+ $r->print(''.
+ &mt('[quant,_1,warning]',$warningcount).'');
}
} else {
- $r->print('ok');
+ $r->print(''.&mt('ok').'');
}
$r->rflush();
}
my $dependencies=
&Apache::lonnet::metadata($url,'dependencies');
- foreach (split(/\,/,$dependencies)) {
- if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
- &checkonthis($r,$_,$level+1);
+ foreach my $dep (split(/\,/,$dependencies)) {
+ if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
+ &checkonthis($r,$dep,$level+1);
}
}
- } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
- $r->print('connection down');
- } elsif ($result==HTTP_NOT_FOUND) {
- $r->print('not found');
+ } elsif ($result eq 'unavailable') {
+ $r->print(''.&mt('connection down').'');
+ } elsif ($result eq 'not_found') {
+ unless ($url=~/\$/) {
+ $r->print(''.&mt('not found').'');
+ } else {
+ $r->print(''.&mt('unable to verify variable URL').'');
+ }
} else {
- $r->print('access denied');
+ $r->print(''.&mt('access denied').'');
}
- }
+ }
+ }
+}
+
+
+
+=pod
+
+=item list_symbs()
+
+List Content Identifiers
+
+=cut
+
+sub list_symbs {
+ my ($r) = @_;
+
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
+ $r->print(&startContentScreen('tools'));
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (!defined($navmap)) {
+ $r->print('
'.&mt('Retrieval of List Failed').'
'.
+ '
'.
+ &mt('Unable to retrieve information about course contents').
+ '
');
+ &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+ } else {
+ $r->print('
');
+ $hashtied=0;
+ undef %alreadyseen;
+ %alreadyseen=();
+ &tiehash();
+
+ foreach my $key (keys(%hash)) {
+ if ($hash{$key}=~/\.(page|sequence)$/) {
+ if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
+ $r->print(''.
+ &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
+ &unescape($hash{$key}).' '.
+ &mt('Note that grading records for problems included in this sequence or folder will overlap.').'');
+ }
+ }
+ if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
+ &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
+ }
}
+ &untiehash();
+ $r->print('
'.&mt('Done').'
');
+ $r->print(&endContentScreen());
+}
+
+
+sub devalidateversioncache {
+ my $src=shift;
+ &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
+ &Apache::lonnet::clutter($src));
+}
+
+sub checkversions {
+ my ($r) = @_;
+ 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='';
+ my $weeksel='';
+ my $daysel='';
+ my $allsel='';
+ my %changes=();
+ my $starttime=0;
+ my $haschanged=0;
+ my %setversions=&Apache::lonnet::dump('resourceversions',
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+
+ $hashtied=0;
+ &tiehash();
+ my %newsetversions=();
+ if ($env{'form.setmostrecent'}) {
+ $haschanged=1;
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
+ $newsetversions{$1}='mostrecent';
+ &devalidateversioncache($1);
+ }
+ }
+ } elsif ($env{'form.setcurrent'}) {
+ $haschanged=1;
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
+ my $getvers=&Apache::lonnet::getversion($1);
+ if ($getvers>0) {
+ $newsetversions{$1}=$getvers;
+ &devalidateversioncache($1);
+ }
+ }
+ }
+ } elsif ($env{'form.setversions'}) {
+ $haschanged=1;
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.set_version_(.+)$/) {
+ my $src=$1;
+ if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
+ $newsetversions{$src}=$env{$key};
+ &devalidateversioncache($src);
+ }
+ }
+ }
+ }
+ if ($haschanged) {
+ if (&Apache::lonnet::put('resourceversions',\%newsetversions,
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
+ } else {
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
+ }
+ &mark_hash_old();
+ }
+ &changewarning($r,'');
+ if ($env{'form.timerange'} eq 'all') {
+# show all documents
+ $header=&mt('All Documents in '.$crstype);
+ $allsel=' selected="selected"';
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
+ my $src=$1;
+ $changes{$src}=1;
+ }
+ }
+ } else {
+# show documents which changed
+ %changes=&Apache::lonnet::dump
+ ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+ my $firstkey=(keys(%changes))[0];
+ unless ($firstkey=~/^error\:/) {
+ unless ($env{'form.timerange'}) {
+ $env{'form.timerange'}=604800;
+ }
+ my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
+ .&mt('seconds');
+ if ($env{'form.timerange'}==-1) {
+ $seltext='since start of course';
+ $startsel=' selected="selected"';
+ $env{'form.timerange'}=time;
+ }
+ $starttime=time-$env{'form.timerange'};
+ if ($env{'form.timerange'}==2592000) {
+ $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
+ $monthsel=' selected="selected"';
+ } elsif ($env{'form.timerange'}==604800) {
+ $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
+ $weeksel=' selected="selected"';
+ } elsif ($env{'form.timerange'}==86400) {
+ $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
+ $daysel=' selected="selected"';
+ }
+ $header=&mt('Content changed').' '.$seltext;
+ } else {
+ $header=&mt('No content modifications yet.');
+ }
+ }
+ %setversions=&Apache::lonnet::dump('resourceversions',
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+ my %lt=&Apache::lonlocal::texthash
+ ('st' => 'Version changes since start of '.$crstype,
+ 'lm' => 'Version changes since last Month',
+ 'lw' => 'Version changes since last Week',
+ 'sy' => 'Version changes since Yesterday',
+ 'al' => 'All Resources (possibly large output)',
+ 'cd' => 'Change display',
+ 'sd' => 'Display',
+ 'fi' => 'File',
+ 'md' => 'Modification Date',
+ 'mr' => 'Most recently published Version',
+ 've' => 'Version used in '.$crstype,
+ 'vu' => 'Set Version to be used in '.$crstype,
+'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',
+ 'save' => 'Save changes',
+ 'vers' => 'Version choice(s) for specific resources',
+ 'act' => 'Actions');
+ $r->print(<$header
+'
+ );
+
+ &untiehash();
+ $r->print(&endContentScreen());
+}
+
+sub mark_hash_old {
+ my $retie_hash=0;
+ if ($hashtied) {
+ $retie_hash=1;
+ &untiehash();
+ }
+ &tiehash('write');
+ $hash{'old'}=1;
+ &untiehash();
+ if ($retie_hash) { &tiehash(); }
+}
+
+sub is_hash_old {
+ my $untie_hash=0;
+ if (!$hashtied) {
+ $untie_hash=1;
+ &tiehash();
+ }
+ my $return=$hash{'old'};
+ if ($untie_hash) { &untiehash(); }
+ return $return;
+}
+
+sub changewarning {
+ my ($r,$postexec,$message,$url)=@_;
+ if (!&is_hash_old()) { return; }
+ my $pathvar='folderpath';
+ my $path=&escape($env{'form.folderpath'});
+ if (!defined($url)) {
+ $url='/adm/coursedocs?'.$pathvar.'='.$path;
+ }
+ my $course_type = &Apache::loncommon::course_type();
+ if (!defined($message)) {
+ $message='Changes will become active for your current session after [_1], or the next time you log in.';
+ }
+ $r->print("\n\n".
+''."\n".
+''."\n\n");
+}
+
+
+sub init_breadcrumbs {
+ my ($form,$text)=@_;
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
+ text=>&Apache::loncommon::course_type().' Editor',
+ faq=>273,
+ bug=>'Instructor Interface',
+ help => 'Docs_Adding_Course_Doc'});
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
+ text=>$text,
+ faq=>273,
+ bug=>'Instructor Interface'});
+}
+
+# subroutine to list form elements
+sub create_list_elements {
+ my @formarr = @_;
+ my $list = '';
+ foreach my $button (@formarr){
+ foreach my $picture (keys(%{$button})) {
+ $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
+ }
+ }
+ 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 ($mode) = @_;
+ my $output = '
';
+}
+
+sub supplemental_base {
+ return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
}
-# ================================================================ Main Handler
sub handler {
my $r = shift;
- $r->content_type('text/html');
+ &Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
+# get course data
+ my $crstype = &Apache::loncommon::course_type();
+ my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+
+# graphics settings
+ $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
+
+#
# --------------------------------------------- Initialize help topics for this
- foreach ('Adding_Course_Doc','Main_Course_Documents',
- 'Adding_External_Resource','Navigate_Content',
- 'Adding_Folders','Docs_Overview', 'Load_Map',
- 'Supplemental', 'Score_Upload_Form',
- 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive') {
- $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
- }
+ foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
+ 'Adding_External_Resource','Navigate_Content',
+ 'Adding_Folders','Docs_Overview', 'Load_Map',
+ 'Supplemental','Score_Upload_Form','Adding_Pages',
+ 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
+ 'Uploading_From_Harddrive',
+ 'Check_Resource_Versions','Verify_Content') {
+ $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
+ }
# Composite help files
$help{'Syllabus'} = &Apache::loncommon::help_open_topic(
'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
$help{'Simple Page'} = &Apache::loncommon::help_open_topic(
'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
+ $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
+ 'Option_Response_Simple');
$help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
- $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
+ $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
+ $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
$help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
-
- if ($ENV{'form.verify'}) {
-
- my $loaderror=&Apache::lonnet::overloaderror($r);
- if ($loaderror) { return $loaderror; }
- $r->print('Verify Content'.
- &Apache::loncommon::bodytag('Verify Course Documents'));
- $hashtied=0;
- undef %alreadyseen;
- %alreadyseen=();
- &tiehash();
- foreach (keys %hash) {
- if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
- &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
+
+ 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'});
+ }
+
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
+ 'inhibitmenu']);
+ if ($allowed && $env{'form.chooseserver'}) {
+ &choose_dump_server($r);
+ return OK;
+ } elsif ($allowed && $env{'form.verify'}) {
+ &init_breadcrumbs('verify','Verify Content');
+ &verifycontent($r);
+ } elsif ($allowed && $env{'form.listsymbs'}) {
+ &init_breadcrumbs('listsymbs','List Content IDs');
+ &list_symbs($r);
+ } elsif ($allowed && $env{'form.docslog'}) {
+ &init_breadcrumbs('docslog','Show Log');
+ my $folder = $env{'form.folder'};
+ if ($folder eq '') {
+ $folder='default';
+ }
+ &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
+ } elsif ($allowed && $env{'form.versions'}) {
+ &init_breadcrumbs('versions','Check/Set Resource Versions');
+ &checkversions($r);
+ } elsif ($allowed && $env{'form.dumpcourse'}) {
+ &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
+ &dumpcourse($r);
+ } elsif ($allowed && $env{'form.exportcourse'}) {
+ &init_breadcrumbs('exportcourse','IMS Export');
+ &Apache::imsexport::exportcourse($r);
+ } else {
+#
+# Done catching special calls
+# The whole rest is for course and supplemental documents and utilities menu
+# Get the parameters that may be needed
+#
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['folderpath',
+ 'forcesupplement','forcestandard',
+ 'tools','symb','command','supppath']);
+
+# 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\//);
+
+# Decide whether this should display supplemental or main content or utilities
+# supplementalflag=1: show supplemental documents
+# supplementalflag=0: show standard documents
+# toolsflag=1: show utilities
+
+
+ my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
+ if (($env{'form.folderpath'}=~/^default/) || ($env{'form.folderpath'} eq "")) {
+ $supplementalflag=0;
+ }
+ if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
+ if ($env{'form.forcestandard'}) { $supplementalflag=0; }
+ unless ($allowed) { $supplementalflag=1; }
+ unless ($standard) { $supplementalflag=1; }
+ my $toolsflag=0;
+ if ($env{'form.tools'}) { $toolsflag=1; }
+
+ my $script='';
+ my $showdoc=0;
+ my $addentries = {};
+ my $container;
+ my $containertag;
+ my $pathitem;
+
+# Do we directly jump somewhere?
+
+ if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
+ if ($env{'form.symb'} ne '') {
+ $env{'form.folderpath'}=
+ &Apache::loncommon::symb_to_docspath($env{'form.symb'});
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
+ $env{'form.command'}.'_'.$env{'form.symb'}});
+ } elsif ($env{'form.supppath'} ne '') {
+ $env{'form.folderpath'}=$env{'form.supppath'};
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
+ $env{'form.command'}.'_'.$env{'form.supppath'}});
}
+ } elsif ($env{'form.command'} eq 'editdocs') {
+ $env{'form.folderpath'} = 'default&'.
+ &Apache::lonhtmlcommon::entity_encode('Main Course Content').
+ ':::::';
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
+ } elsif ($env{'form.command'} eq 'editsupp') {
+ $env{'form.folderpath'} = 'supplemental&'.
+ &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
+ } elsif ($env{'form.command'} eq 'contents') {
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
+ } elsif ($env{'form.command'} eq 'home') {
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
}
- &untiehash();
- $r->print('
Done.
');
- } elsif ($ENV{'form.versions'}) {
- $r->print('Check Versions'.
- &Apache::loncommon::bodytag('Check Course Document Versions'));
- $hashtied=0;
- &tiehash();
- my %changes=&Apache::lonnet::dump
- ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
- my $firstkey=(keys %changes)[0];
- unless ($firstkey=~/^error\:/) {
- unless ($ENV{'form.timerange'}) {
- $ENV{'form.timerange'}=604800;
- }
- my $seltext='during the last '.$ENV{'form.timerange'}.' seconds';
- my $startsel='';
- my $monthsel='';
- my $weeksel='';
- my $daysel='';
- if ($ENV{'form.timerange'}==-1) {
- $seltext='since start of course';
- $startsel='selected';
- $ENV{'form.timerange'}=time;
- }
- my $starttime=time-$ENV{'form.timerange'};
- if ($ENV{'form.timerange'}==2592000) {
- $seltext='during the last month ('.localtime($starttime).')';
- $monthsel='selected';
- } elsif ($ENV{'form.timerange'}==604800) {
- $seltext='during the last week ('.localtime($starttime).')';
- $weeksel='selected';
- } elsif ($ENV{'form.timerange'}==86400) {
- $seltext='since yesterday ('.localtime($starttime).')';
- $daysel='selected';
+
+
+# Where do we store these for when we come back?
+ my $stored_folderpath='docs_folderpath';
+ if ($supplementalflag) {
+ $stored_folderpath='docs_sup_folderpath';
+ }
+
+# No folderpath, and in edit mode, see if we have something stored
+ if ((!$env{'form.folderpath'}) && $allowed) {
+ &Apache::loncommon::restore_course_settings($stored_folderpath,
+ {'folderpath' => 'scalar'});
+ unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
+ undef($env{'form.folderpath'});
+ }
+ }
+
+# 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'} = &supplemental_base();
+ }
+ }
+# 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_base()
+ .'&'.
+ $env{'form.folderpath'};
+ }
+# If after all of this, we still don't have any paths, make them
+ unless ($env{'form.folderpath'}) {
+ if ($supplementalflag) {
+ $env{'form.folderpath'}=&supplemental_base();
+ } else {
+ $env{'form.folderpath'}='default'.&escape(&mt('Main '.$crstype.' Documents')).
+ ':::::';
}
-
- $r->print(<
-
-
-
-
Content changed $seltext
-
-
-
File
Modification Date
-
Version
Differences
-ENDHEADERS
- foreach (keys %changes) {
- if ($changes{$_}>$starttime) {
- my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
- my $currentversion=&Apache::lonnet::getversion($_);
- my $linkurl=&Apache::lonnet::clutter($_);
- $r->print(
- '