--- loncom/interface/londocs.pm 2003/10/22 19:47:52 1.87
+++ loncom/interface/londocs.pm 2004/04/08 21:10:25 1.117
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.87 2003/10/22 19:47:52 www Exp $
+# $Id: londocs.pm,v 1.117 2004/04/08 21:10:25 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -68,10 +68,13 @@ 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
@@ -94,13 +97,15 @@ sub authorhosts {
} else {
($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
}
- if (&Apache::lonnet::homeserver($ca,$cd) eq
- $Apache::lonnet::perlvar{'lonHostID'}) {
+ 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}=
- &Apache::lonnet::homeserver($ca,$cd);
+ $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
$other++;
}
}
@@ -250,14 +255,37 @@ sub group_import {
join ':', ($name, $url, $ext, 'normal', 'res');
}
}
- &storemap($coursenum, $coursedom, $folder.'.sequence');
+ 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)=
@@ -275,7 +303,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);
@@ -295,7 +323,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'}) {
@@ -335,7 +368,12 @@ 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'}) {
@@ -349,21 +387,30 @@ sub editor {
}
}
# Store the changed version
- group_import($coursenum, $coursedom, $folder, @imports);
+ ($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
@@ -373,8 +420,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('');
@@ -384,75 +431,87 @@ 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=''.&Apache::lonlocal::locallocaltime($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='
');
+ 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('