--- loncom/interface/londocs.pm 2004/04/24 23:03:49 1.119
+++ loncom/interface/londocs.pm 2016/06/06 17:40:48 1.604
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.119 2004/04/24 23:03:49 www Exp $
+# $Id: londocs.pm,v 1.604 2016/06/06 17:40:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,15 +30,26 @@ package Apache::londocs;
use strict;
use Apache::Constants qw(:common :http);
+use Apache::imsexport;
use Apache::lonnet;
use Apache::loncommon;
-use Apache::lonratedt;
-use Apache::lonratsrv;
+use Apache::lonhtmlcommon;
+use LONCAPA::map();
+use Apache::lonratedt();
use Apache::lonxml;
-use Apache::loncreatecourse;
+use Apache::lonclonecourse;
+use Apache::lonnavmaps;
+use Apache::lonnavdisplay();
+use Apache::lonextresedit();
+use Apache::lontemplate();
+use Apache::lonsimplepage();
use HTML::Entities;
+use HTML::TokeParser;
use GDBM_File;
+use File::MMagic;
use Apache::lonlocal;
+use Cwd;
+use LONCAPA qw(:DEFAULT :match);
my $iconpath;
@@ -48,507 +59,4211 @@ my $hashtied;
my %alreadyseen=();
my $hadchanges;
+my $suppchanges;
-# 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
-# sets @resources - array with the resources with correct idx
-#
sub mapread {
my ($coursenum,$coursedom,$map)=@_;
return
- &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map);
+ &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
+ $map);
}
sub storemap {
- my ($coursenum,$coursedom,$map)=@_;
+ my ($coursenum,$coursedom,$map,$contentchg)=@_;
+ my $report;
+ if (($contentchg) && ($map =~ /^default/)) {
+ $report = 1;
+ }
my ($outtext,$errtext)=
- &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
+ &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
+ $map,1,$report);
if ($errtext) { return ($errtext,2); }
-
- $hadchanges=1;
+
+ if ($map =~ /^default/) {
+ $hadchanges=1;
+ } else {
+ $suppchanges=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)\.(.+)$/) {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
my $role=$1;
my $realm=$2;
- my ($start,$end)=split(/\./,$ENV{$_});
+ my ($start,$end)=split(/\./,$env{$key});
if (($start) && ($start>time)) { next; }
if (($end) && (time>$end)) { next; }
- my $ca; my $cd;
+ my ($ca,$cd);
if ($1 eq 'au') {
- $ca=$ENV{'user.name'};
- $cd=$ENV{'user.domain'};
+ $ca=$env{'user.name'};
+ $cd=$env{'user.domain'};
} else {
- ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
+ ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
}
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; } }
+ foreach my $id (@ids) {
+ if ($id eq $myhome) {
+ $allowed=1;
+ last;
+ }
+ }
if ($allowed) {
$home++;
- $outhash{'home_'.$ca.'@'.$cd}=1;
+ $outhash{'home_'.$ca.':'.$cd}=1;
} else {
- $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
+ $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');
- }
+
+sub clean {
+ my ($title)=@_;
+ $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
+ return $title;
}
-# -------------------------------------------------------- Actually dump course
+
sub dumpcourse {
- my $r=shift;
- $r->print('Dump DOCS '.
- &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
- ' ';
+ if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
+ $line.=''.$title.' ';
+ } elsif ($url) {
+ $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
+ $title,600,500);
+ } else {
+ $line.=$title.' '.$reinit.' ';
+ }
+ $line.="$extresform ";
+ $rand_pick_text = ' ' if ($rand_pick_text eq '');
+ $rand_order_text = ' ' if ($rand_order_text eq '');
+ if (($allowed) && ($folder!~/^supplemental/)) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'hd' => 'Hidden',
+ 'ec' => 'URL hidden');
+ my ($enctext,$hidtext);
+ if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
+ $enctext = ' checked="checked"';
+ if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
+ push(@{$filtersref->{'encrypturl'}},$orderidx);
+ }
+ }
+ if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
+ $hidtext = ' checked="checked"';
+ if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
+ push(@{$filtersref->{'hiddenresource'}},$orderidx);
+ }
+ }
+ my $formhidden = 'edit_hiddenresource_'.$orderidx;
+ my $formurlhidden = 'edit_encrypturl_'.$orderidx;
+ $line.=(<
+
+ $form_param
+ $form_common
+ $lt{'hd'}
+ $form_end
+
+
+ $form_param
+ $form_common
+ $lt{'ec'}
+ $form_end
+
+ $rand_pick_text
+ $rand_order_text
+ENDPARMS
+ }
+ $line.=&Apache::loncommon::end_data_table_row();
return $line;
}
-# ---------------------------------------------------------------- tie the hash
+sub action_restrictions {
+ my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
+ my %denied = (
+ cut => 0,
+ copy => 0,
+ remove => 0,
+ );
+ if ($url=~ m{^/res/.+\.(page|sequence)$}) {
+ # no copy for published maps
+ $denied{'copy'} = 1;
+ } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
+ unless ($1 eq 'simpleproblem') {
+ $denied{'copy'} = 1;
+ }
+ $denied{'cut'} = 1;
+ } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
+ if ($folderpath =~ /^default&[^\&]+$/) {
+ if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
+ $denied{'remove'} = 1;
+ }
+ $denied{'cut'} = 1;
+ $denied{'copy'} = 1;
+ }
+ } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
+ my $group = $1;
+ if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
+ if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
+ $denied{'remove'} = 1;
+ }
+ }
+ $denied{'cut'} = 1;
+ $denied{'copy'} = 1;
+ } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
+ my $group = $1;
+ if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
+ if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
+ my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
+ if (keys(%groupsettings) > 0) {
+ $denied{'remove'} = 1;
+ }
+ $denied{'cut'} = 1;
+ $denied{'copy'} = 1;
+ }
+ }
+ } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
+ my $group = $1;
+ if ($url =~ /group_boards_\Q$group\E/) {
+ if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
+ my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
+ if (keys(%groupsettings) > 0) {
+ if (ref($groupsettings{'functions'}) eq 'HASH') {
+ if ($groupsettings{'functions'}{'discussion'} eq 'on') {
+ $denied{'remove'} = 1;
+ }
+ }
+ }
+ $denied{'cut'} = 1;
+ $denied{'copy'} = 1;
+ }
+ }
+ }
+ return %denied;
+}
+
+sub new_timebased_suffix {
+ my ($dom,$num,$type,$area,$container) = @_;
+ my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
+ if ($type eq 'paste') {
+ $prefix = $type;
+ $namespace = 'courseeditor';
+ $idtype = 'addcode';
+ } elsif ($type eq 'map') {
+ $prefix = 'docs';
+ if ($area eq 'supplemental') {
+ $prefix = 'supp';
+ }
+ $prefix .= $container;
+ $namespace = 'uploadedmaps';
+ } else {
+ $prefix = $type;
+ $namespace = 'templated';
+ }
+ my ($suffix,$freedlock,$error) =
+ &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
+ if (!$suffix) {
+ if ($type eq 'paste') {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
+ } elsif ($type eq 'map') {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
+ } elsif ($type eq 'smppg') {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
+ } else {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
+ }
+ if ($error) {
+ $errtext .= ' '.$error;
+ }
+ }
+ if ($freedlock ne 'ok') {
+ $locknotfreed =
+ ''.
+ &mt('There was a problem removing a lockfile.').' ';
+ if ($type eq 'paste') {
+ if ($freedlock eq 'nolock') {
+ $locknotfreed =
+ '
'.
+ &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
+
+ &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
+ } else {
+ $locknotfreed .=
+ &mt('This will prevent addition of items to the clipboard until your next log-in.');
+ }
+ } elsif ($type eq 'map') {
+ $locknotfreed .=
+ &mt('This will prevent creation of additional folders or composite pages in this course.');
+ } elsif ($type eq 'smppg') {
+ $locknotfreed .=
+ &mt('This will prevent creation of additional simple pages in this course.');
+ } else {
+ $locknotfreed .=
+ &mt('This will prevent creation of additional discussion boards in this course.');
+ }
+ unless ($type eq 'paste') {
+ $locknotfreed .=
+ ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
+ '
',' ');
+ }
+ $locknotfreed .= '
';
+ }
+ return ($suffix,$errtext,$locknotfreed);
+}
+
+=pod
+
+=item tiehash()
+
+tie the hash
+
+=cut
sub tiehash {
+ my ($mode)=@_;
$hashtied=0;
- if ($ENV{'request.course.fn'}) {
- if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
- &GDBM_READER(),0640)) {
+ if ($env{'request.course.fn'}) {
+ if ($mode eq 'write') {
+ if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
+ &GDBM_WRCREAT(),0640)) {
+ $hashtied=2;
+ }
+ } else {
+ if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
+ &GDBM_READER(),0640)) {
$hashtied=1;
- }
- }
+ }
+ }
+ }
}
sub untiehash {
if ($hashtied) { untie %hash; }
$hashtied=0;
+ return OK;
}
-# --------------------------------------------------------------- check on this
+
+
sub checkonthis {
my ($r,$url,$level,$title)=@_;
+ $url=&unescape($url);
$alreadyseen{$url}=1;
$r->rflush();
if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
$r->print("\n
");
+ if ($level==0) {
+ $r->print("
");
+ }
for (my $i=0;$i<=$level*5;$i++) {
$r->print(' ');
}
@@ -557,8 +4272,8 @@ sub checkonthis {
if ($url=~/^\/res\//) {
my $result=&Apache::lonnet::repcopy(
&Apache::lonnet::filelocation('',$url));
- if ($result==OK) {
- $r->print('
'.&mt('ok').' ');
+ if ($result eq 'ok') {
+ $r->print('
'.&mt('ok').' ');
$r->rflush();
&Apache::lonnet::countacc($url);
$url=~/\.(\w+)$/;
@@ -568,84 +4283,141 @@ sub checkonthis {
for (my $i=0;$i<=$level*5;$i++) {
$r->print(' ');
}
- $r->print('- '.&mt('Rendering').': ');
- my $oldpath=$ENV{'request.filename'};
- $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
- &Apache::lonxml::xmlparse($r,'web',
- &Apache::lonnet::getfile(
- &Apache::lonnet::filelocation('',$url)));
- undef($Apache::lonhomework::parsing_a_problem);
- $ENV{'request.filename'}=$oldpath;
- if (($Apache::lonxml::errorcount) ||
- ($Apache::lonxml::warningcount)) {
- if ($Apache::lonxml::errorcount) {
- $r->print('
'.
- $Apache::lonxml::errorcount.' '.
- &mt('error(s)').' ');
+ $r->print('- '.&mt('Rendering:').' ');
+ my ($errorcount,$warningcount)=split(/:/,
+ &Apache::lonnet::ssi_body($url,
+ ('grade_target'=>'web',
+ 'return_only_error_and_warning_counts' => 1)));
+ if (($errorcount) ||
+ ($warningcount)) {
+ if ($errorcount) {
+ $r->print('
'.
+ &mt('[quant,_1,error]',$errorcount).' ');
}
- if ($Apache::lonxml::warningcount) {
- $r->print('
'.
- $Apache::lonxml::warningcount.' '.
- &mt('warning(s)').' ');
+ if ($warningcount) {
+ $r->print('
'.
+ &mt('[quant,_1,warning]',$warningcount).' ');
}
} else {
- $r->print('
'.&mt('ok').' ');
+ $r->print('
'.&mt('ok').' ');
}
$r->rflush();
}
my $dependencies=
&Apache::lonnet::metadata($url,'dependencies');
- foreach (split(/\,/,$dependencies)) {
- if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
- &checkonthis($r,$_,$level+1);
+ foreach my $dep (split(/\,/,$dependencies)) {
+ if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
+ &checkonthis($r,$dep,$level+1);
}
}
- } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
- $r->print('
'.&mt('connection down').' ');
- } elsif ($result==HTTP_NOT_FOUND) {
+ } elsif ($result eq 'unavailable') {
+ $r->print('
'.&mt('connection down').' ');
+ } elsif ($result eq 'not_found') {
unless ($url=~/\$/) {
- $r->print('
'.&mt('not found').' ');
+ $r->print('
'.&mt('not found').' ');
} else {
- $r->print('
'.&mt('unable to verify variable URL').' ');
+ $r->print('
'.&mt('unable to verify variable URL').' ');
}
} else {
- $r->print('
'.&mt('access denied').' ');
+ $r->print('
'.&mt('access denied').' ');
}
- }
- }
+ }
+ }
}
-#
-# -------------------------------------------------------------- Verify Content
-#
-sub verifycontent {
- my $r=shift;
- my $loaderror=&Apache::lonnet::overloaderror($r);
- if ($loaderror) { return $loaderror; }
- $r->print('
Verify Content '.
- &Apache::loncommon::bodytag('Verify Course Documents'));
+=pod
+
+=item list_symbs()
+
+List Content Identifiers
+
+=cut
+
+sub list_symbs {
+ my ($r) = @_;
+
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
+ $r->print(&startContentScreen('tools'));
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (!defined($navmap)) {
+ $r->print('
'.&mt('Retrieval of List Failed').' '.
+ '
'.
+ &mt('Unable to retrieve information about course contents').
+ '
');
+ &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+ } else {
+ $r->print('
'.&mt("$crstype Content Identifiers").' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('Title').' '.&mt('Identifier').' '.
+ &Apache::loncommon::end_data_table_header_row()."\n");
+ my $count;
+ foreach my $res ($navmap->retrieveResources()) {
+ $r->print(&Apache::loncommon::start_data_table_row().
+ '
'.$res->compTitle().' '.
+ '
'.$res->symb().' '.
+ &Apache::loncommon::end_data_table_row());
+ $count ++;
+ }
+ if (!$count) {
+ $r->print(&Apache::loncommon::start_data_table_row().
+ '
'.&mt("$crstype is empty").' '.
+ &Apache::loncommon::end_data_table_row());
+ }
+ $r->print(&Apache::loncommon::end_data_table());
+ }
+ $r->print(&endContentScreen());
+}
+
+
+sub verifycontent {
+ my ($r) = @_;
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
+ $r->print(&startContentScreen('tools'));
+ $r->print('
'.&mt($crstype.' content verification').' ');
$hashtied=0;
undef %alreadyseen;
%alreadyseen=();
&tiehash();
- foreach (keys %hash) {
- if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
- &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
+
+ foreach my $key (keys(%hash)) {
+ if ($hash{$key}=~/\.(page|sequence)$/) {
+ if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
+ $r->print('
'.
+ &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
+ &unescape($hash{$key}).' '.
+ &mt('Note that grading records for problems included in this sequence or folder will overlap.').'
');
+ }
+ }
+ if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
+ &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
}
}
&untiehash();
- $r->print('
'.&mt('Done').'. '.'
'.
- &mt('Return to DOCS').' ');
+ $r->print('
'.&mt('Done').'
');
+ $r->print(&endContentScreen());
}
-# -------------------------------------------------------------- Check Versions
+
+sub devalidateversioncache {
+ my $src=shift;
+ &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
+ &Apache::lonnet::clutter($src));
+}
sub checkversions {
- my $r=shift;
- $r->print('
Check Versions '.
- &Apache::loncommon::bodytag('Check Course Document Versions'));
+ my ($r) = @_;
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
+ $r->print(&startContentScreen('tools'));
+
my $header='';
my $startsel='';
my $monthsel='';
@@ -656,56 +4428,62 @@ sub checkversions {
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'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
$hashtied=0;
&tiehash();
my %newsetversions=();
- if ($ENV{'form.setmostrecent'}) {
+ if ($env{'form.setmostrecent'}) {
$haschanged=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
$newsetversions{$1}='mostrecent';
+ &devalidateversioncache($1);
}
}
- } elsif ($ENV{'form.setcurrent'}) {
+ } elsif ($env{'form.setcurrent'}) {
$haschanged=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
my $getvers=&Apache::lonnet::getversion($1);
if ($getvers>0) {
$newsetversions{$1}=$getvers;
+ &devalidateversioncache($1);
}
}
}
- } elsif ($ENV{'form.setversions'}) {
+ } elsif ($env{'form.setversions'}) {
$haschanged=1;
- foreach (keys %ENV) {
- if ($_=~/^form\.set_version_(.+)$/) {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.set_version_(.+)$/) {
my $src=$1;
- if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
- $newsetversions{$src}=$ENV{$_};
+ if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
+ $newsetversions{$src}=$env{$key};
+ &devalidateversioncache($src);
}
}
}
}
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').' ');
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
} else {
- $r->print('
'.&mt('An Error Occured while Attempting to Store your Version Settings').' ');
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
}
- &changewarning($r,'');
+ &mark_hash_old();
}
- if ($ENV{'form.timerange'} eq 'all') {
+ &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\/.+)$/) {
+ $header=&mt('All content in '.$crstype);
+ $allsel=' selected="selected"';
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
my $src=$1;
$changes{$src}=1;
}
@@ -713,30 +4491,30 @@ sub checkversions {
} 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];
+ ('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;
+ unless ($env{'form.timerange'}) {
+ $env{'form.timerange'}=604800;
}
- my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
+ my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
.&mt('seconds');
- if ($ENV{'form.timerange'}==-1) {
+ if ($env{'form.timerange'}==-1) {
$seltext='since start of course';
- $startsel='selected';
- $ENV{'form.timerange'}=time;
+ $startsel=' selected="selected"';
+ $env{'form.timerange'}=time;
}
- $starttime=time-$ENV{'form.timerange'};
- if ($ENV{'form.timerange'}==2592000) {
+ $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) {
+ $monthsel=' selected="selected"';
+ } elsif ($env{'form.timerange'}==604800) {
$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
- $weeksel='selected';
- } elsif ($ENV{'form.timerange'}==86400) {
+ $weeksel=' selected="selected"';
+ } elsif ($env{'form.timerange'}==86400) {
$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
- $daysel='selected';
+ $daysel=' selected="selected"';
}
$header=&mt('Content changed').' '.$seltext;
} else {
@@ -744,686 +4522,2880 @@ sub checkversions {
}
}
%setversions=&Apache::lonnet::dump('resourceversions',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $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',
+ ('st' => 'Version changes since start of '.$crstype,
'lm' => 'Version changes since last Month',
'lw' => 'Version changes since last Week',
'sy' => 'Version changes since Yesterday',
'al' => 'All Resources (possibly large output)',
+ 'cd' => 'Change display',
'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',
+ 've' => 'Version used in '.$crstype,
+ 'vu' => 'Set Version to be used in '.$crstype,
+'sv' => 'Set Versions to be used in '.$crstype.' 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');
+ 'di' => 'Differences',
+ 'save' => 'Save changes',
+ 'vers' => 'Version choice(s) for specific resources',
+ 'act' => 'Actions');
$r->print(<
$header
-
-
+
+
+$lt{'cd'}
-$lt{'al'}
-$lt{'st'}
-$lt{'lm'}
-$lt{'lw'}
-$lt{'sy'}
+$lt{'al'}
+$lt{'st'}
+$lt{'lm'}
+$lt{'lw'}
+$lt{'sy'}
-$header
-
-
+
+
+
+
+$lt{'act'}
+$lt{'sm'}:
+$lt{'sc'}:
+
+
+
+
+$lt{'vers'}
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(
- ''.
- &Apache::lonnet::gettitle($linkurl).
- ' '.
- ' '.
- ''.
- ''.$linkurl.
- ' '.
- ' '.
- ''.
- &Apache::lonlocal::locallocaltime(
- &Apache::lonnet::metadata($root.'.'.$extension,
- 'lastrevisiondate')
- ).
- ' '.
- 'Most Recent: '.
- ''.$currentversion.' '.
- ' '.
- 'In Course: '.
- '');
-# Used in course
- my $usedversion=$hash{'version_'.$linkurl};
- if (($usedversion) && ($usedversion ne 'mostrecent')) {
- $r->print($usedversion);
- } else {
- $r->print($currentversion);
- }
- $r->print(' '.
- 'Use: ');
-# Set version
- $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
- 'set_version_'.$linkurl,
- ('' => '',
- 'mostrecent' => 'most recent',
- map {$_,$_} (1..$currentversion))));
- $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('');
- my $cols_output = 1;
+ #number of columns for version history
+ my %changedbytime;
+ foreach my $key (keys(%changes)) {
+ #excludes not versionable problems from resource version history:
+ next if ($key =~ /^\/res\/lib\/templates/);
+ my $chg;
+ if ($env{'form.timerange'} eq 'all') {
+ my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
+ $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
+ } else {
+ $chg = $changes{$key};
+ next if ($chg < $starttime);
+ }
+ push(@{$changedbytime{$chg}},$key);
+ }
+ if (keys(%changedbytime) == 0) {
+ &untiehash();
+ $r->print(&mt('No content changes in imported content in specified time frame').
+ &endContentScreen());
+ return;
+ }
+ $r->print(
+ ' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ' '.&mt('Resources').' '.
+ "$lt{'mr'} ".
+ "$lt{'ve'} ".
+ "$lt{'vu'} ".
+ ''.&mt('History').' '.
+ &Apache::loncommon::end_data_table_header_row()
+ );
+ foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
+ foreach my $key (sort(@{$changedbytime{$chg}})) {
+ my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
+ my $currentversion=&Apache::lonnet::getversion($key);
+ if ($currentversion<0) {
+ $currentversion=''.&mt('Could not be determined.').' ';
+ }
+ my $linkurl=&Apache::lonnet::clutter($key);
+ $r->print(
+ &Apache::loncommon::start_data_table_row().
+ ''.&Apache::lonnet::gettitle($linkurl).' '.
+ ''.$linkurl.' '.
+ ''.$currentversion.' ('.
+ &Apache::lonlocal::locallocaltime($chg).') '.
+ ''
+ );
+ # Used in course
+ my $usedversion=$hash{'version_'.$linkurl};
+ if (($usedversion) && ($usedversion ne 'mostrecent')) {
+ if ($usedversion != $currentversion) {
+ $r->print(''.$usedversion.' ');
+ } else {
+ $r->print($usedversion);
+ }
+ } else {
+ $r->print($currentversion);
+ }
+ $r->print(' ');
+ # Set version
+ $r->print(&Apache::loncommon::select_form(
+ $setversions{$linkurl},
+ 'set_version_'.$linkurl,
+ {'select_form_order' => ['',1..$currentversion,'mostrecent'],
+ '' => '',
+ 'mostrecent' => &mt('most recent'),
+ map {$_,$_} (1..$currentversion)}));
+ my $lastold=1;
+ for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
+ my $url=$root.'.'.$prevvers.'.'.$extension;
+ if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
+ $lastold=$prevvers;
+ }
+ }
+ $r->print(' ');
+ # List all available versions
+ $r->print('');
for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
- my $url=$root.'.'.$prevvers.'.'.$extension;
- $r->print(''.&mt('Version').' '.$prevvers.' ('.
- &Apache::lonlocal::locallocaltime(
- &Apache::lonnet::metadata($url,
- 'lastrevisiondate')
- ).
- ')');
- if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
- $r->print(' '.&mt('Diffs').' ');
- }
- $r->print(' ');
- if (++$entries_count % $entries_per_col == 0) {
- $r->print(' ');
- if ($cols_output != 4) {
- $r->print('');
- $cols_output++;
- }
+ my $url=$root.'.'.$prevvers.'.'.$extension;
+ $r->print(
+ ''
+ .''
+ .&mt('Version [_1]',$prevvers).' '
+ .' ('.&Apache::lonlocal::locallocaltime(
+ &Apache::lonnet::metadata($url,'lastrevisiondate'))
+ .')');
+ if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
+ $r->print(
+ ' &').
+ '" target="diffs">'.&mt('Diffs').' ');
}
- }
- while($cols_output++ < 4) {
- $r->print(' ')
+ $r->print(' ');
}
- $r->print(' '."\n");
- }
+ $r->print(''.&Apache::loncommon::end_data_table_row());
+ }
}
- $r->print('
');
- $r->print(''.&mt('Done').'. ');
+ $r->print(
+ &Apache::loncommon::end_data_table().
+ ' '.
+ ''
+ );
&untiehash();
+ $r->print(&endContentScreen());
+ return;
+}
+
+sub mark_hash_old {
+ my $retie_hash=0;
+ if ($hashtied) {
+ $retie_hash=1;
+ &untiehash();
+ }
+ &tiehash('write');
+ $hash{'old'}=1;
+ &untiehash();
+ if ($retie_hash) { &tiehash(); }
+}
+
+sub is_hash_old {
+ my $untie_hash=0;
+ if (!$hashtied) {
+ $untie_hash=1;
+ &tiehash();
+ }
+ my $return=$hash{'old'};
+ if ($untie_hash) { &untiehash(); }
+ return $return;
}
sub changewarning {
- my ($r,$postexec)=@_;
- $r->print(
-''.
-''.
-''.
-&mt('Changes will become active for your current session after').
-' '.&mt(', or the next time you log in.').
-$help{'Caching'}.' ');
+ my ($r,$postexec,$message,$url)=@_;
+ if (!&is_hash_old()) { return; }
+ my $pathvar='folderpath';
+ my $path=&escape($env{'form.folderpath'});
+ if (!defined($url)) {
+ $url='/adm/coursedocs?'.$pathvar.'='.$path;
+ }
+ my $course_type = &Apache::loncommon::course_type();
+ if (!defined($message)) {
+ $message='Changes will become active for your current session after [_1], or the next time you log in.';
+ }
+ $r->print("\n\n".
+''."\n".
+''.
+''.
+&mt($message,' ').
+$help{'Caching'}.'
'."\n\n");
+}
+
+
+sub init_breadcrumbs {
+ my ($form,$text,$help)=@_;
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
+ text=>&Apache::loncommon::course_type().' Editor',
+ faq=>273,
+ bug=>'Instructor Interface',
+ help => $help});
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
+ text=>$text,
+ faq=>273,
+ bug=>'Instructor Interface'});
+}
+
+# subroutine to list form elements
+sub create_list_elements {
+ my @formarr = @_;
+ my $list = '';
+ foreach my $button (@formarr){
+ foreach my $picture (keys(%{$button})) {
+ $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
+ }
+ }
+ return $list;
+}
+
+# subroutine to create ul from list elements
+sub create_form_ul {
+ my $list = shift;
+ my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
+ return $ul;
+}
+
+#
+# Start tabs
+#
+
+sub startContentScreen {
+ my ($mode) = @_;
+ my $output = '';
+ if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
+ $output .= ' '.&mt('Content Overview').' '."\n";
+ $output .= ' '.&mt('Content Search').' '."\n";
+ $output .= ' '.&mt('Content Index').' '."\n";
+ $output .= ''.&mt('Supplemental Content').' ';
+ } else {
+ $output .= ' '.&mt('Main Content Editor').' '."\n";
+ $output .= ''.&mt('Supplemental Content Editor').' '."\n";
+ $output .= ' '.&mt('Content Utilities').' '."\n";
+ '> '.&mt('Content Utilities').' ';
+ }
+ $output .= "\n".' '."\n";
+ $output .= ''.
+ '
'.
+ '
';
+ return $output;
+}
+
+#
+# End tabs
+#
+
+sub endContentScreen {
+ return '
';
+}
+
+sub supplemental_base {
+ return 'supplemental&'.&escape(&mt('Supplemental Content'));
}
-# ================================================================ Main Handler
sub handler {
my $r = shift;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
+# get course data
+ my $crstype = &Apache::loncommon::course_type();
+ my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+
+# graphics settings
+ $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
+
+#
# --------------------------------------------- Initialize help topics for this
- foreach ('Adding_Course_Doc','Main_Course_Documents',
- 'Adding_External_Resource','Navigate_Content',
- 'Adding_Folders','Docs_Overview', 'Load_Map',
- 'Supplemental', 'Score_Upload_Form',
- 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive') {
- $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
- }
+ foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
+ 'Adding_External_Resource','Navigate_Content',
+ 'Adding_Folders','Docs_Overview', 'Load_Map',
+ 'Supplemental','Score_Upload_Form','Adding_Pages',
+ 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
+ 'Uploading_From_Harddrive','Course_Roster','Web_Page',
+ 'Dropbox','Simple_Problem') {
+ $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
+ }
# Composite help files
$help{'Syllabus'} = &Apache::loncommon::help_open_topic(
'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
$help{'Simple Page'} = &Apache::loncommon::help_open_topic(
'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
- $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
- 'Option_Response_Simple');
$help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
- $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
+ $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
+ $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
$help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
- if ($ENV{'form.verify'}) {
+ my $allowed;
+# URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
+ unless ($r->uri eq '/adm/supplemental') {
+ # does this user have privileges to modify content.
+ $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+ }
+
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
+ if ($allowed && $env{'form.verify'}) {
+ &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
&verifycontent($r);
- } elsif ($ENV{'form.versions'}) {
+ } elsif ($allowed && $env{'form.listsymbs'}) {
+ &init_breadcrumbs('listsymbs','List Content IDs');
+ &list_symbs($r);
+ } elsif ($allowed && $env{'form.docslog'}) {
+ &init_breadcrumbs('docslog','Show Log');
+ my $folder = $env{'form.folder'};
+ if ($folder eq '') {
+ $folder='default';
+ }
+ &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
+ } elsif ($allowed && $env{'form.versions'}) {
+ &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
&checkversions($r);
- } elsif ($ENV{'form.dumpcourse'}) {
+ } elsif ($allowed && $env{'form.dumpcourse'}) {
+ &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
&dumpcourse($r);
+ } elsif ($allowed && $env{'form.exportcourse'}) {
+ &init_breadcrumbs('exportcourse','IMS Export');
+ &Apache::imsexport::exportcourse($r);
} else {
-# is this a standard course?
+#
+# Done catching special calls
+# The whole rest is for course and supplemental documents and utilities menu
+# Get the parameters that may be needed
+#
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['folderpath',
+ 'forcesupplement','forcestandard',
+ 'tools','symb','command','supppath']);
+
+# standard=1: this is a "new-style" course with an uploaded map as top level
+# standard=2: this is a "old-style" course, and there is nothing we can do
+
+ my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
+
+# Decide whether this should display supplemental or main content or utilities
+# supplementalflag=1: show supplemental documents
+# supplementalflag=0: show standard documents
+# toolsflag=1: show utilities
+
+ my $unesc_folderpath = &unescape($env{'form.folderpath'});
+ my $supplementalflag=($unesc_folderpath=~/^supplemental/);
+ if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
+ $supplementalflag=0;
+ }
+ if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
+ if ($env{'form.forcestandard'}) { $supplementalflag=0; }
+ unless ($allowed) { $supplementalflag=1; }
+ unless ($standard) { $supplementalflag=1; }
+ my $toolsflag=0;
+ if ($env{'form.tools'}) { $toolsflag=1; }
- my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
- my $forcestandard;
- my $forcesupplement;
my $script='';
- my $allowed;
- my $events='';
my $showdoc=0;
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['folderpath']);
- if ($ENV{'form.folderpath'}) {
- my (@folderpath)=split('&',$ENV{'form.folderpath'});
- $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
- $ENV{'form.folder'}=pop(@folderpath);
- }
- if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
- $showdoc=$1;
+ my $addentries = {};
+ my $container;
+ my $containertag;
+ my $pathitem;
+ my %ltitools;
+
+# Do we directly jump somewhere?
+
+ if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
+ if ($env{'form.symb'} ne '') {
+ $env{'form.folderpath'}=
+ &Apache::loncommon::symb_to_docspath($env{'form.symb'});
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
+ $env{'form.command'}.'_'.$env{'form.symb'}});
+ } elsif ($env{'form.supppath'} ne '') {
+ $env{'form.folderpath'}=$env{'form.supppath'};
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
+ $env{'form.command'}.'_'.$env{'form.supppath'}});
+ }
+ } elsif ($env{'form.command'} eq 'editdocs') {
+ $env{'form.folderpath'} = 'default&'.
+ &escape(&mt('Main Content').':::::');
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
+ } elsif ($env{'form.command'} eq 'editsupp') {
+ $env{'form.folderpath'} = 'supplemental&'.
+ &escape('Supplemental Content');
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
+ } elsif ($env{'form.command'} eq 'contents') {
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
+ } elsif ($env{'form.command'} eq 'home') {
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
+ }
+
+
+# Where do we store these for when we come back?
+ my $stored_folderpath='docs_folderpath';
+ if ($supplementalflag) {
+ $stored_folderpath='docs_sup_folderpath';
+ }
+
+# No folderpath, and in edit mode, see if we have something stored
+ if ((!$env{'form.folderpath'}) && $allowed) {
+ &Apache::loncommon::restore_course_settings($stored_folderpath,
+ {'folderpath' => 'scalar'});
+ unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
+ undef($env{'form.folderpath'});
+ }
+ }
+
+# If we are not allowed to make changes, all we can see are supplemental docs
+ if (!$allowed) {
+ unless ($env{'form.folderpath'} =~ /^supplemental/) {
+ $env{'form.folderpath'} = &supplemental_base();
+ }
+ }
+# Make the zeroth entry in supplemental docs page paths, so we can get to top level
+ if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
+ $env{'form.folderpath'} = &supplemental_base()
+ .'&'.
+ $env{'form.folderpath'};
}
- unless ($showdoc) { # got called from remote
- $forcestandard=($ENV{'form.folder'}=~/^default_/);
- $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
-
-# does this user have privileges to post, etc?
- $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
- if ($allowed) {
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
- $script=&Apache::lonratedt::editscript('simple');
+# If after all of this, we still don't have any paths, make them
+ unless ($env{'form.folderpath'}) {
+ if ($supplementalflag) {
+ $env{'form.folderpath'}=&supplemental_base();
+ } else {
+ $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
+ ':::::');
}
- } else { # got called in sequence from course
- $allowed=0;
- $script=''.&Apache::lonmenu::registerurl(1,undef).''."\n"
+ .''."\n";
- my $now=time;
+ # Breadcrumbs
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
-# print screen
- $r->print(<
-
-The LearningOnline Network with CAPA
-
-ENDDOCUMENT
- if ($allowed) {
- $r->print(<
+ if ($showdoc) {
+ $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
+ {'force_register' => $showdoc,}));
+ } elsif ($toolsflag) {
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ href=>"/adm/coursedocs",text=>"$crstype Contents"});
+ $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
+ .&Apache::loncommon::help_open_menu('','',273,'RAT')
+ .&Apache::lonhtmlcommon::breadcrumbs(
+ 'Editing Course Contents')
+ );
+ } elsif ($r->uri eq '/adm/supplemental') {
+ my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
+ $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
+ {'bread_crumbs' => $brcrum,}));
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ href=>"/adm/coursedocs",text=>"$crstype Contents"});
+ $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
+ {'add_entries' => $addentries}
+ )
+ .&Apache::loncommon::help_open_menu('','',273,'RAT')
+ .&Apache::lonhtmlcommon::breadcrumbs(
+ 'Editing '.$crstype.' Contents',
+ 'Docs_Adding_Course_Doc')
+ );
+ }
+
+ my %allfiles = ();
+ my %codebase = ();
+ my ($upload_result,$upload_output,$uploadphase);
+ if ($allowed) {
+ if (($env{'form.uploaddoc.filename'}) &&
+ ($env{'form.cmd'}=~/^upload_(\w+)/)) {
+ my $context = $1;
+ # Process file upload - phase one - upload and parse primary file.
+ undef($hadchanges);
+ $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
+ \%allfiles,\%codebase,$context,$crstype);
+ if ($hadchanges) {
+ &mark_hash_old();
+ }
+ $r->print($upload_output);
+ } elsif ($env{'form.phase'} eq 'upload_embedded') {
+ # Process file upload - phase two - upload embedded objects
+ $uploadphase = 'check_embedded';
+ my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
+ my $state = &embedded_form_elems($uploadphase,$primaryurl,
+ $env{'form.newidx'});
+ my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my ($destination,$dir_root) = &embedded_destination();
+ my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
+ my $actionurl = '/adm/coursedocs';
+ my ($result,$flag) =
+ &Apache::loncommon::upload_embedded('coursedoc',$destination,
+ $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
+ $actionurl);
+ $r->print($result.&return_to_editor());
+ } elsif ($env{'form.phase'} eq 'check_embedded') {
+ # Process file upload - phase three - modify references in HTML file
+ $uploadphase = 'modified_orightml';
+ my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my ($destination,$dir_root) = &embedded_destination();
+ my $result =
+ &Apache::loncommon::modify_html_refs('coursedoc',$destination,
+ $docuname,$docudom,undef,
+ $dir_root);
+ $r->print($result.&return_to_editor());
+ } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
+ $uploadphase = 'decompress_phase_one';
+ $r->print(&decompression_phase_one().
+ &return_to_editor());
+ } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
+ $uploadphase = 'decompress_phase_two';
+ $r->print(&decompression_phase_two().
+ &return_to_editor());
+ }
+ }
+
+ if ($allowed && $toolsflag) {
+ $r->print(&startContentScreen('tools'));
+ $r->print(&generate_admin_menu($crstype));
+ $r->print(&endContentScreen());
+ } elsif ((!$showdoc) && (!$uploadphase)) {
+# -----------------------------------------------------------------------------
+ my %lt=&Apache::lonlocal::texthash(
+ 'copm' => 'All documents out of a published map into this folder',
+ 'upfi' => 'Upload File',
+ 'upld' => 'Upload Content',
+ 'srch' => 'Search',
+ 'impo' => 'Import',
+ 'lnks' => 'Import from Stored Links',
+ 'impm' => 'Import from Assembled Map',
+ 'extr' => 'External Resource',
+ 'extt' => 'External Tool',
+ 'selm' => 'Select Map',
+ 'load' => 'Load Map',
+ 'newf' => 'New Folder',
+ 'newp' => 'New Composite Page',
+ 'syll' => 'Syllabus',
+ 'navc' => 'Table of Contents',
+ 'sipa' => 'Simple Course Page',
+ 'sipr' => 'Simple Problem',
+ 'webp' => 'Blank Web Page (editable)',
+ 'drbx' => 'Drop Box',
+ 'scuf' => 'External Scores (handgrade, upload, clicker)',
+ 'bull' => 'Discussion Board',
+ 'mypi' => 'My Personal Information Page',
+ 'grpo' => 'Group Portfolio',
+ 'rost' => 'Course Roster',
+ 'abou' => 'Personal Information Page for a User',
+ 'imsf' => 'IMS Upload',
+ 'imsl' => 'Upload IMS package',
+ 'cms' => 'Origin of IMS package',
+ 'se' => 'Select',
+ 'file' => 'File',
+ 'title' => 'Title',
+ 'comment' => 'Comment',
+ 'parse' => 'Upload embedded images/multimedia files if HTML file',
+ 'bb5' => 'Blackboard 5',
+ 'bb6' => 'Blackboard 6',
+ 'angel5' => 'ANGEL 5.5',
+ 'webctce4' => 'WebCT 4 Campus Edition',
+ );
+# -----------------------------------------------------------------------------
+
+ # Calculate free quota space for a user or course. A javascript function checks
+ # file size to determine if upload should be allowed.
+ my $quotatype = 'unofficial';
+ if ($crstype eq 'Community') {
+ $quotatype = 'community';
+ } elsif ($crstype eq 'Placement') {
+ $quotatype = 'placement';
+ } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
+ $quotatype = 'official';
+ } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
+ $quotatype = 'textbook';
+ }
+ my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
+ 'course',$quotatype); # expressed in MB
+ my $current_disk_usage = 0;
+ foreach my $subdir ('docs','supplemental') {
+ $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
+ "userfiles/$subdir",1); # expressed in kB
+ }
+ my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
+
+ my $fileupload=(<
+
+
+FIUP
+
+ my $checkbox=(<$lt{'parse'}?
+
+ -->
+
+ $lt{'parse'}
+
+CHBO
+ my $imsfolder = $env{'form.folder'};
+ if ($imsfolder eq '') {
+ $imsfolder = 'default';
+ }
+ my $imspform=(<