--- loncom/interface/londocs.pm 2003/08/05 12:47:21 1.71
+++ loncom/interface/londocs.pm 2004/04/06 23:05:29 1.113
@@ -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.113 2004/04/06 23:05:29 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,8 +35,10 @@ use Apache::loncommon;
use Apache::lonratedt;
use Apache::lonratsrv;
use Apache::lonxml;
+use Apache::loncreatecourse;
use HTML::Entities;
use GDBM_File;
+use Apache::lonlocal;
my $iconpath;
@@ -66,10 +68,194 @@ sub mapread {
sub storemap {
my ($coursenum,$coursedom,$map)=@_;
- $hadchanges=1;
- return
+ my ($outtext,$errtext)=
&Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
$map,1);
+ if ($errtext) { return ($errtext,2); }
+
+ $hadchanges=1;
+ return ($errtext,0);
+}
+
+# ----------------------------------------- Return hash with valid author names
+
+sub authorhosts {
+ my %outhash=();
+ my $home=0;
+ my $other=0;
+ foreach (keys %ENV) {
+ if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
+ my $role=$1;
+ my $realm=$2;
+ my ($start,$end)=split(/\./,$ENV{$_});
+ if (($start) && ($start>time)) { next; }
+ if (($end) && (time>$end)) { next; }
+ my $ca; my $cd;
+ if ($1 eq 'au') {
+ $ca=$ENV{'user.name'};
+ $cd=$ENV{'user.domain'};
+ } else {
+ ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
+ }
+ 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; } }
+ if ($allowed) {
+ $home++;
+ $outhash{'home_'.$ca.'@'.$cd}=1;
+ } else {
+ $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
+ $other++;
+ }
+ }
+ }
+ return ($home,$other,%outhash);
+}
+# ------------------------------------------------------ Generate "dump" button
+
+sub dumpbutton {
+ my ($home,$other,%outhash)=&authorhosts();
+ if ($home+$other==0) { return ''; }
+ my $output='
';
+ if ($home) {
+ return '
'.
+ '';
+ } else {
+ return'
'.
+ &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 editor {
@@ -94,7 +280,7 @@ sub editor {
# 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);
@@ -114,7 +300,12 @@ 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'}) {
@@ -154,44 +345,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('
'.$errtext.'
');
+ return;
+ }
}
}
# ---------------------------------------------------------------- End commands
@@ -201,8 +397,8 @@ sub editor {
foreach (@Apache::lonratedt::order) {
my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
unless ($name) { $name=(split(/\//,$url))[-1]; }
- unless ($name) { $name='NO RESOURCE'; $url='/adm/notfound.html'; }
- $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_));
+ unless ($name) { next; }
+ $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
$idx++;
}
$r->print('');
@@ -212,52 +408,57 @@ sub editor {
# --------------------------------------------------------------- An entry line
sub entryline {
- my ($index,$title,$url,$folder,$allowed,$residx)=@_;
+ my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
$title=~s/\&colon\;/\:/g;
$title=&HTML::Entities::encode(&HTML::Entities::decode(
- &Apache::lonnet::unescape($title)),'\"\<\>\&\'');
+ &Apache::lonnet::unescape($title)),'"<>&\'');
my $renametitle=$title;
my $foldertitle=$title;
- if ($title=~
- /^(\d+)\_\_\_\&\;\&\;\&\;\_\_\_(\w+)\_\_\_\&\;\&\;\&\;\_\_\_(\w+)\_\_\_\&\;\&\;\&\;\_\_\_(.*)$/
- ) {
- $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
- $renametitle=$4;
- $title=''.localtime($1).' '.
- &Apache::loncommon::plainname($2,$3).': '.
- $foldertitle;
- }
+ if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) {
+ $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
+ $renametitle=$4;
+ $title=''.&Apache::lonlocal::locallocaltime($1).' '.
+ &Apache::loncommon::plainname($2,$3).': '.
+ $foldertitle;
+ }
$renametitle=~s/\"\;/\\\"/g;
my $line='
'.''.
+ &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;
+ &Apache::lonnet::logthis('Found: '.$1.' '.$ENV{$_});
+ 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('