--- loncom/interface/londocs.pm 2002/11/18 15:21:31 1.37
+++ loncom/interface/londocs.pm 2004/06/10 22:23:35 1.129
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.37 2002/11/18 15:21:31 www Exp $
+# $Id: londocs.pm,v 1.129 2004/06/10 22:23:35 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,7 +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;
@@ -44,6 +47,12 @@ my %hash;
my $hashtied;
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
@@ -59,16 +68,224 @@ sub mapread {
sub storemap {
my ($coursenum,$coursedom,$map)=@_;
- 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 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)=
@@ -81,15 +298,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;
@@ -106,32 +388,46 @@ 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];
}
$#Apache::lonratedt::order--;
} elsif ($cmd eq 'up') {
+ if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
my $i=$Apache::lonratedt::order[$idx-1];
$Apache::lonratedt::order[$idx-1]=
$Apache::lonratedt::order[$idx];
$Apache::lonratedt::order[$idx]=$i;
+ }
} elsif ($cmd eq 'down') {
+ if (defined($Apache::lonratedt::order[$idx+1])) {
my $i=$Apache::lonratedt::order[$idx+1];
$Apache::lonratedt::order[$idx+1]=
$Apache::lonratedt::order[$idx];
$Apache::lonratedt::order[$idx]=$i;
+ }
} elsif ($cmd eq 'rename') {
my ($rtitle,@rrest)=split(/\:/,
$Apache::lonratedt::resources[
$Apache::lonratedt::order[$idx]]);
- my $comment=$ENV{'form.title'};
+ my $comment=
+ &HTML::Entities::decode($ENV{'form.title'});
$comment=~s/\\<\;/g;
$comment=~s/\>/\>\;/g;
$comment=~s/\:/\:/g;
@@ -141,30 +437,50 @@ 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;
- $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'}))) {
+ my $idx=$#Apache::lonratedt::resources;
+ $idx++;
+ $Apache::lonratedt::resources[$idx]=$_;
+ $Apache::lonratedt::order
+ [$#Apache::lonratedt::order+1]=$idx;
+ }
+
+# Store the changed version
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.sequence');
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
+ }
}
# ---------------------------------------------------------------- End commands
# ---------------------------------------------------------------- Print screen
@@ -173,8 +489,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('');
@@ -184,58 +500,143 @@ sub editor {
# --------------------------------------------------------------- An entry line
sub entryline {
- my ($index,$title,$url,$folder,$allowed)=@_;
+ my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
+ $title=~s/\&colon\;/\:/g;
+ $title=&HTML::Entities::encode(&HTML::Entities::decode(
+ &Apache::lonnet::unescape($title)),'"<>&\'');
+ my $renametitle=$title;
+ my $foldertitle=$title;
+ my $orderidx=$Apache::lonratedt::order[$index];
+ 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='
';
# Edit commands
+ my $folderpath;
+ if ($ENV{'form.folderpath'}) {
+ $folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
+ # $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
+ }
if ($allowed) {
- $line.=(<
');
+ 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('