--- loncom/interface/londocs.pm 2013/12/31 15:20:31 1.484.2.48
+++ loncom/interface/londocs.pm 2019/08/17 12:45:34 1.484.2.84
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.484.2.48 2013/12/31 15:20:31 raeburn Exp $
+# $Id: londocs.pm,v 1.484.2.84 2019/08/17 12:45:34 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,6 +46,7 @@ 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);
@@ -138,7 +139,43 @@ sub clean {
return $title;
}
-
+sub default_folderpath {
+ my ($coursenum,$coursedom,$navmapref) = @_;
+ return unless ($coursenum && $coursedom && ref($navmapref));
+# Check if entire course is hidden and/or encrypted
+ my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
+ my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
+ unless (ref($$navmapref)) {
+ $$navmapref = Apache::lonnavmaps::navmap->new();
+ }
+ if (ref($$navmapref)) {
+ if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
+ my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
+ my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
+ unless (@resources) {
+ $hiddenmap = 1;
+ unless ($env{'request.role.adv'}) {
+ $hiddentop = 1;
+ if ($env{'form.folder'}) {
+ undef($env{'form.folder'});
+ }
+ }
+ }
+ }
+ if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
+ $encryptmap = 1;
+ }
+ }
+ unless ($hiddentop) {
+ $folderpath='default&'.&escape(&mt('Main Content')).
+ '::'.$hiddenmap.':'.$encryptmap.'::';
+ }
+ if (wantarray) {
+ return ($folderpath,$hiddentop);
+ } else {
+ return $folderpath;
+ }
+}
sub dumpcourse {
my ($r) = @_;
@@ -301,14 +338,14 @@ ENDJS
if ($contents{content}) {
$content .= '
-
Content
'.
+'.&mt('Content').'
'.
$contents{content}.'
';
}
if ($contents{webreferences}) {
$content .= '
-
Web References
'.
+'.&mt('Web References').'
'.
$contents{webreferences}.'
';
}
@@ -651,7 +688,7 @@ sub group_import {
} else {
$fname =~ s/\W/_/g;
}
- if (length($fname > 15)) {
+ if (length($fname) > 15) {
$fname = substr($fname,0,14);
}
my $initialtext = &mt('Replace with your own content.');
@@ -790,12 +827,14 @@ sub log_docs {
}
sub docs_change_log {
- my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
+ my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
+ my $navmap;
my $js = ''."\n";
+ .''."\n"
+ .''."\n";
# Breadcrumbs
&Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -4731,34 +5365,52 @@ sub handler {
$r->print(&Apache::loncommon::start_page("$crstype documents",undef,
{'force_register' => $showdoc,}));
} elsif ($toolsflag) {
+ my ($breadtext,$breadtitle);
+ $breadtext = "$crstype Editor";
+ if ($canedit) {
+ $breadtitle = 'Editing '.$crstype.' Contents';
+ } else {
+ $breadtext .= ' (View-only mode)';
+ $breadtitle = 'Viewing '.$crstype.' Contents';
+ }
&Apache::lonhtmlcommon::add_breadcrumb({
- href=>"/adm/coursedocs",text=>"$crstype Contents"});
+ href=>"/adm/coursedocs",text=>$breadtext});
$r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
.&Apache::loncommon::help_open_menu('','',273,'RAT')
.&Apache::lonhtmlcommon::breadcrumbs(
- 'Editing Course Contents')
+ $breadtitle)
);
} 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 {
+ my ($breadtext,$breadtitle,$helpitem);
+ $breadtext = "$crstype Editor";
+ if ($canedit) {
+ $breadtitle = 'Editing '.$crstype.' Contents';
+ $helpitem = 'Docs_Adding_Course_Doc';
+ } else {
+ $breadtext .= ' (View-only mode)';
+ $breadtitle = 'Viewing '.$crstype.' Contents';
+ $helpitem = 'Docs_Viewing_Course_Doc';
+ }
&Apache::lonhtmlcommon::add_breadcrumb({
- href=>"/adm/coursedocs",text=>"$crstype Contents"});
+ href=>"/adm/coursedocs",text=>$breadtext});
$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')
+ $breadtitle,
+ $helpitem)
);
}
my %allfiles = ();
my %codebase = ();
my ($upload_result,$upload_output,$uploadphase);
- if ($allowed) {
+ if ($canedit) {
if (($env{'form.uploaddoc.filename'}) &&
($env{'form.cmd'}=~/^upload_(\w+)/)) {
my $context = $1;
@@ -4766,6 +5418,7 @@ sub handler {
undef($hadchanges);
$uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
\%allfiles,\%codebase,$context,$crstype);
+ undef($navmap);
if ($hadchanges) {
&mark_hash_old();
}
@@ -4810,7 +5463,7 @@ sub handler {
if ($allowed && $toolsflag) {
$r->print(&startContentScreen('tools'));
- $r->print(&generate_admin_menu($crstype));
+ $r->print(&generate_admin_menu($crstype,$canedit));
$r->print(&endContentScreen());
} elsif ((!$showdoc) && (!$uploadphase)) {
# -----------------------------------------------------------------------------
@@ -4846,11 +5499,50 @@ sub handler {
'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',
+ 'er' => 'Editing rights unavailable for your current role.',
+ );
# -----------------------------------------------------------------------------
+ # 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 ($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 $usage = $current_disk_usage/1024; # in MB
+ my $quota = $disk_quota;
+ my $percent;
+ if ($disk_quota == 0) {
+ $percent = 100.0;
+ } else {
+ $percent = 100*($usage/$disk_quota);
+ }
+ $usage = sprintf("%.2f",$usage);
+ $quota = sprintf("%.2f",$quota);
+ $percent = sprintf("%.0f",$percent);
+ my $quotainfo = ''.&mt('Currently using [_1] of the [_2] available.',
+ $percent.'%',$quota.' MB').'
';
+
my $fileupload=(<
-
+
+
FIUP
my $checkbox=(<
-->
CHBO
my $imsfolder = $env{'form.folder'};
@@ -4875,17 +5567,17 @@ CHBO
$lt{'cms'}:
-
-
+
IMSFORM
@@ -4900,7 +5592,7 @@ IMSFORM
$fileupload
$lt{'title'}:
-
+
$pathitem
@@ -4908,11 +5600,17 @@ IMSFORM
$checkbox
-
+
FUFORM
+ my $mapimportjs;
+ if ($canedit) {
+ $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
+ } else {
+ $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
+ }
my $importpubform=(<