'.
+ &mt('Dump Course DOCS to Construction Space: available on other servers');
+ }
+}
+
+# -------------------------------------------------------- Actually dump course
+
+sub dumpcourse {
+ my $r=shift;
+ $r->print('Dump DOCS'.
+ &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
+ '');
+ }
+}
+
+
+# Imports the given (name, url) resources into the course
+# coursenum, coursedom, and folder must precede the list
+sub group_import {
+ my $coursenum = shift;
+ my $coursedom = shift;
+ my $folder = shift;
+ while (@_) {
+ my $name = shift;
+ my $url = shift;
+ 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] =
+ join ':', ($name, $url, $ext, 'normal', 'res');
+ }
+ }
+ return &storemap($coursenum, $coursedom, $folder.'.sequence');
+}
+
+sub breadcrumbs {
+ my ($where)=@_;
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ my (@folders)=split('&',$ENV{'form.folderpath'});
+ my $folderpath;
+ while (@folders) {
+ my $folder=shift(@folders);
+ my $foldername=shift(@folders);
+ if ($folderpath) {$folderpath.='&';}
+ $folderpath.=$folder.'&'.$foldername;
+ my $url='/adm/coursedocs?folderpath='.
+ &Apache::lonnet::escape($folderpath);
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ {'href'=>$url,
+ 'title'=>&Apache::lonnet::unescape($foldername),
+ 'text'=>''.
+ &Apache::lonnet::unescape($foldername).''
+ });
+
+
+ }
+ return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,0);
}
sub editor {
my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
- if ($ENV{'form.foldername'}) {
- $r->print('
Folder: '.$ENV{'form.foldername'}.'
');
- }
+
+ $r->print(&breadcrumbs($folder));
my $errtext='';
my $fatal=0;
($errtext,$fatal)=
@@ -89,15 +300,80 @@ sub editor {
$r->print('
'.$errtext.'
');
} else {
# ------------------------------------------------------------ Process commands
+
# ---------------- if they are for this folder and user allowed to make changes
if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
+# set parameters and change order
+ if (defined($ENV{'form.setparms'})) {
+ my $idx=$ENV{'form.setparms'};
+# set parameters
+ if ($ENV{'form.randpick_'.$idx}) {
+ &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
+ } else {
+ &Apache::lonratedt::delparameter($idx,'parameter_randompick');
+ }
+ if ($ENV{'form.hidprs_'.$idx}) {
+ &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
+ } else {
+ &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
+ }
+ if ($ENV{'form.encprs_'.$idx}) {
+ &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
+ } else {
+ &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
+ }
+
+ if ($ENV{'form.newpos'}) {
+# change order
+
+ my $newpos=$ENV{'form.newpos'}-1;
+ my $currentpos=$ENV{'form.currentpos'}-1;
+ my $i;
+ my @neworder=();
+ if ($newpos>$currentpos) {
+# moving stuff up
+ for ($i=0;$i<$currentpos;$i++) {
+ $neworder[$i]=$Apache::lonratedt::order[$i];
+ }
+ for ($i=$currentpos;$i<$newpos;$i++) {
+ $neworder[$i]=$Apache::lonratedt::order[$i+1];
+ }
+ $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
+ for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
+ $neworder[$i]=$Apache::lonratedt::order[$i];
+ }
+ } else {
+# moving stuff down
+ for ($i=0;$i<$newpos;$i++) {
+ $neworder[$i]=$Apache::lonratedt::order[$i];
+ }
+ $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
+ for ($i=$newpos+1;$i<$currentpos+1;$i++) {
+ $neworder[$i]=$Apache::lonratedt::order[$i-1];
+ }
+ for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
+ $neworder[$i]=$Apache::lonratedt::order[$i];
+ }
+ }
+ @Apache::lonratedt::order=@neworder;
+ }
+# store the changed version
+
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
+
+ }
+
# upload a file, if present
if (($ENV{'form.uploaddoc.filename'}) &&
($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
- if ($folder=~/^$1/) {
+ if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
# this is for a course, not a user, so set coursedoc flag
# probably the only place in the system where this should be "1"
- my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
+ my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
my $ext='false';
if ($url=~/^http\:\/\//) { $ext='true'; }
$url=~s/\:/\:/g;
@@ -114,12 +390,21 @@ sub editor {
$comment.':'.$url.':'.$ext.':normal:res';
$Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
$newidx;
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
}
}
if ($ENV{'form.cmd'}) {
my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
if ($cmd eq 'del') {
+ my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
+ if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
+ &Apache::lonnet::removeuploadedurl($url);
+ }
for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
$Apache::lonratedt::order[$i]=
$Apache::lonratedt::order[$i+1];
@@ -154,44 +439,49 @@ sub editor {
}
# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.sequence');
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
}
# 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';
- }
- }
- }
+ my @imports;
+ foreach (split(/\&/,$ENV{'form.importdetail'})) {
+ if (defined($_)) {
+ my ($name,$url)=split(/\=/,$_);
+ $name=&Apache::lonnet::unescape($name);
+ $url=&Apache::lonnet::unescape($url);
+ push @imports, $name, $url;
+ }
+ }
# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
+ @imports);
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
}
# Loading a complete map
if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
- foreach
-(&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
+ 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;
- }
+ [$#Apache::lonratedt::order+1]=$idx;
+ }
# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.sequence');
+ if ($fatal) {
+ $r->print('
'.''.
+ &mt('Return to DOCS').'');
+}
+
+# -------------------------------------------------------------- Check Versions
+
+sub checkversions {
+ my $r=shift;
+ $r->print('Check Versions'.
+ &Apache::loncommon::bodytag('Check Course Document Versions'));
+ 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 (keys %hash) {
+ if ($_=~/^ids\_(\/res\/.+)$/) {
+ $newsetversions{$1}='mostrecent';
+ }
+ }
+ } elsif ($ENV{'form.setcurrent'}) {
+ $haschanged=1;
+ foreach (keys %hash) {
+ if ($_=~/^ids\_(\/res\/.+)$/) {
+ my $getvers=&Apache::lonnet::getversion($1);
+ if ($getvers>0) {
+ $newsetversions{$1}=$getvers;
+ }
+ }
+ }
+ } elsif ($ENV{'form.setversions'}) {
+ $haschanged=1;
+ foreach (keys %ENV) {
+ if ($_=~/^form\.set_version_(.+)$/) {
+ my $src=$1;
+ if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
+ $newsetversions{$src}=$ENV{$_};
+ }
+ }
+ }
+ }
+ 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('
'.&mt('Your Version Settings have been Stored').'
');
+ } else {
+ $r->print('
'.&mt('An Error Occured while Attempting to Store your Version Settings').'
');
+ }
+ &changewarning($r,'');
+ }
+ if ($ENV{'form.timerange'} eq 'all') {
+# show all documents
+ $header=&mt('All Documents in Course');
+ $allsel=1;
+ foreach (keys %hash) {
+ if ($_=~/^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';
+ $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';
+ } elsif ($ENV{'form.timerange'}==604800) {
+ $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
+ $weeksel='selected';
+ } elsif ($ENV{'form.timerange'}==86400) {
+ $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
+ $daysel='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 Course',
+ 'lm' => 'Version changes since last Month',
+ 'lw' => 'Version changes since last Week',
+ 'sy' => 'Version changes since Yesterday',
+ 'al' => 'All Resources (possibly large output)',
+ 'sd' => 'Display',
+ 'fi' => 'File',
+ 'md' => 'Modification Date',
+ 'mr' => 'Most recently published Version',
+ 've' => 'Version used in Course',
+ 'vu' => 'Set Version to be used in Course',
+'sv' => 'Set Versions to be used in Course 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');
+ $r->print(<
+
+
+
+
+
+
$header
+
+
+ENDHEADERS
+ foreach (sort keys %changes) {
+ if ($changes{$_}>$starttime) {
+ my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
+ my $currentversion=&Apache::lonnet::getversion($_);
+ if ($currentversion<0) {
+ $currentversion=&mt('Could not be determined.');
+ }
+ my $linkurl=&Apache::lonnet::clutter($_);
+ $r->print(
+ '
');
+ my $lastold=1;
+ for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
+ my $url=$root.'.'.$prevvers.'.'.$extension;
+ if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
+ $starttime) {
+ $lastold=$prevvers;
+ }
+ }
+ #
+ # Code to figure out how many version entries should go in
+ # each of the four columns
+ my $entries_per_col = 0;
+ my $num_entries = ($currentversion-$lastold);
+ if ($num_entries % 4 == 0) {
+ $entries_per_col = $num_entries/4;
+ } else {
+ $entries_per_col = $num_entries/4 + 1;
+ }
+ my $entries_count = 0;
+ $r->print('