--- loncom/interface/londocs.pm 2003/01/23 19:00:06 1.46
+++ loncom/interface/londocs.pm 2004/05/06 17:55:03 1.123
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.46 2003/01/23 19:00:06 www Exp $
+# $Id: londocs.pm,v 1.123 2004/05/06 17:55:03 www 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;
@@ -47,6 +49,10 @@ 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
@@ -62,17 +68,224 @@ 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 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)=
@@ -85,12 +298,53 @@ 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');
+ }
+
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
+ if ($ENV{'form.newpos'}) {
+# change order
+
+ my $newpos=$ENV{'form.newpos'}-1;
+ $r->print('Sorting '.$idx.' -> '.$newpos);
+ ($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);
@@ -110,7 +364,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'}) {
@@ -150,31 +409,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;
- $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'}))) {
+ 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
@@ -183,8 +461,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('');
@@ -194,62 +472,131 @@ 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)),'\"\<\>\&\'');
+ &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;
- }
+ 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.=(<
END
}
# Figure out what kind of a resource this is
my ($extension)=($url=~/\.(\w+)$/);
my $uploaded=($url=~/^\/*uploaded\//);
- my $icon='unknown';
- if (-e "/home/httpd/html/adm/lonIcons/$extension.gif") {
- $icon=$extension;
- }
+ my $icon=&Apache::loncommon::icon($url);
my $isfolder=0;
+ my $folderarg;
if ($uploaded) {
if ($extension eq 'sequence') {
- $icon='folder_closed';
- $url=~/\/(\w+)\.sequence/;
- $url='/adm/coursedocs?folder='.$1;
+ $icon=$iconpath.'/folder_closed.gif';
+ $url=~/$coursenum\/([\/\w]+)\.sequence$/;
+ $url='/adm/coursedocs?';
+ $folderarg=$1;
$isfolder=1;
- } else {
- $url=&Apache::lonnet::tokenwrapper($url);
- }
+ }
}
$url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
- if ($isfolder) { $url.='&foldername='.$foldertitle; }
- $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('