--- loncom/interface/londocs.pm 2003/09/28 00:14:25 1.84
+++ loncom/interface/londocs.pm 2025/01/07 21:01:37 1.722
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.84 2003/09/28 00:14:25 www Exp $
+# $Id: londocs.pm,v 1.722 2025/01/07 21:01:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,15 +30,32 @@ 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 Apache::lonhomework();
+use Apache::lonpublisher();
+use Apache::loncourserespicker();
use HTML::Entities;
+use HTML::TokeParser;
+use HTML::LCParser;
use GDBM_File;
+use File::MMagic;
+use File::Copy;
use Apache::lonlocal;
+use Cwd;
+use UUID::Tiny ':std';
+use LONCAPA qw(:DEFAULT :match);
my $iconpath;
@@ -48,449 +65,6189 @@ 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)=@_;
- $hadchanges=1;
- return
- &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
+ my ($coursenum,$coursedom,$map,$contentchg)=@_;
+ my $report;
+ if (($contentchg) && ($map =~ /^default/)) {
+ $report = 1;
+ }
+ my ($outtext,$errtext)=
+ &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
+ $map,1,$report);
+ if ($errtext) { return ($errtext,2); }
+
+ if ($map =~ /^default/) {
+ $hadchanges=1;
+ } elsif ($contentchg) {
+ $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)\.(.+)$/) {
+ my @ids=&Apache::lonnet::current_machine_ids();
+ 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)$/);
}
- if (&Apache::lonnet::homeserver($ca,$cd) eq
- $Apache::lonnet::perlvar{'lonHostID'}) {
+ my $allowed=0;
+ my $myhome=&Apache::lonnet::homeserver($ca,$cd);
+ 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}=
- &Apache::lonnet::homeserver($ca,$cd);
+ $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 ' '.
- ' ';
+
+sub clean {
+ my ($title)=@_;
+ $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
+ 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' '.
- &mt('Dump Course DOCS to Construction Space: available on other servers');
+ return $folderpath;
}
}
-# -------------------------------------------------------- Actually dump course
+sub validate_supppath {
+ my ($coursenum,$coursedom) = @_;
+ my $backto;
+ if ($env{'form.supppath'} ne '') {
+ my @items = split(/\&/,$env{'form.supppath'});
+ my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
+ for (my $i=0; $i<@items; $i++) {
+ my $odd = $i%2;
+ if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
+ $badpath = 1;
+ last;
+ } elsif ($odd) {
+ my $suffix;
+ my $idx = $i-1;
+ if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
+ $backto .= '&'.$1;
+ } elsif ($items[$idx] eq 'supplemental') {
+ $backto .= '&'.$items[$i];
+ } else {
+ $backto .= '&'.$items[$i];
+ my $is_hidden;
+ unless ($got_supp) {
+ my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
+ if (ref($supplemental) eq 'HASH') {
+ if (ref($supplemental->{'hidden'}) eq 'HASH') {
+ %supphidden = %{$supplemental->{'hidden'}};
+ }
+ if (ref($supplemental->{'ids'}) eq 'HASH') {
+ %suppids = %{$supplemental->{'ids'}};
+ }
+ }
+ $got_supp = 1;
+ }
+ if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
+ my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
+ if ($supphidden{$mapid}) {
+ $is_hidden = 1;
+ }
+ }
+ $suffix = '::'.$is_hidden.':::';
+ }
+ $supppath .= '&'.$items[$i].$suffix;
+ } else {
+ $supppath .= '&'.$items[$i];
+ $backto .= '&'.$items[$i];
+ }
+ }
+ if ($badpath) {
+ delete($env{'form.supppath'});
+ } else {
+ $supppath =~ s/^\&//;
+ $backto =~ s/^\&//;
+ $env{'form.supppath'} = $supppath;
+ }
+ }
+ return $backto;
+}
sub dumpcourse {
- my $r=shift;
- $r->print('Dump DOCS '.
- &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
- ' '.&Apache::loncommon::end_data_table_row());
+ }
+ }
+ $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,$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.';
+ }
+ my $windowname = 'loncapaclient';
+ if ($env{'request.lti.login'}) {
+ $windowname .= 'lti';
+ }
+ $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 => ''});
+ }
}
- &untiehash();
+ 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;
- &Apache::lonlocal::clearreroutetrans();
+# 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'};
+ my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
+
+# get docroot
+ my $londocroot = $r->dir_config('lonDocRoot');
+
+# 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','Adding_External_Tool',
+ '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',
+ 'Standard_Problem','Course_Resources',
+ 'Search_LON-CAPA_Resource','Import_Stored_Links') {
+ $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');
@@ -696,482 +6890,4003 @@ sub handler {
'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
$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'}) {
- &verifycontent($r);
- } elsif ($ENV{'form.versions'}) {
- &checkversions($r);
- } elsif ($ENV{'form.dumpcourse'}) {
+ my ($allowed,$canedit,$canview,$noendpage,$disabled);
+# does this user have privileges to modify content.
+ if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+# URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
+ unless ($r->uri eq '/adm/supplemental') {
+ $allowed = 1;
+ }
+ $canedit = 1;
+ $canview = 1;
+ } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
+# URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
+ unless ($r->uri eq '/adm/supplemental') {
+ $allowed = 1;
+ }
+ $canview = 1;
+ }
+ unless ($canedit) {
+ $disabled = ' disabled="disabled"';
+ }
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
+ if ($env{'form.inhibitmenu'}) {
+ unless ($env{'form.inhibitmenu'} eq 'yes') {
+ delete($env{'form.inhibitmenu'});
+ }
+ }
+
+ if ($allowed && $env{'form.verify'}) {
+ &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
+ if (!$canedit) {
+ &verifycontent($r);
+ } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
+ text=>'Results',
+ faq=>273,
+ bug=>'Instructor Interface'});
+ &verifycontent($r,$env{'form.checkstale'});
+ } else {
+ &contentverifyform($r);
+ }
+ } elsif ($allowed && $env{'form.listsymbs'}) {
+ &init_breadcrumbs('listsymbs','List Content IDs');
+ &list_symbs($r);
+ } elsif ($allowed && $env{'form.shorturls'}) {
+ &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
+ &short_urls($r,$canedit);
+ } 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,$canedit);
+ } elsif ($allowed && $env{'form.versions'}) {
+ &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
+ &checkversions($r,$canedit);
+ } elsif ($canedit && $env{'form.dumpcourse'}) {
+ &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
&dumpcourse($r);
+ } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
+ &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
+ my $readonly;
+ if (!$canedit) {
+ $readonly = 1;
+ }
+ ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
+ } elsif ($canedit && $env{'form.exportcourse'}) {
+ &init_breadcrumbs('exportcourse','IMS Export');
+ &Apache::imsexport::exportcourse($r);
} else {
-# is this a standard course?
+ if ($canedit && $env{'form.authorrole'}) {
+ $noendpage = 1;
+ my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
+ if ($redirect) {
+ if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
+ my $container = 'sequence';
+ my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
+ $is_random_order,$container) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
+ my (@folders)=split('&',$env{'form.folderpath'});
+ $env{'form.foldername'}=&unescape(pop(@folders));
+ my $folder=pop(@folders);
+ my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
+ $folder.'.'.$container);
+ my $warning;
+ if ($fatal) {
+ if ($container eq 'page') {
+ $warning = &mt('An error occurred retrieving the contents of the current page.');
+ } else {
+ $warning = &mt('An error occurred retrieving the contents of the current folder.');
+ }
+ } else {
+ my $url = $redirect;
+ my $srcfile = $londocroot.$url;
+ $url =~ s{^/priv/}{/res/};
+ my $targetfile = $londocroot.$url;
+ my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
+ my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
+ $env{'form.folder'} = $folder;
+ &snapshotbefore();
+ my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
+ my $ext = 'false';
+ my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
+ $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
+ ':'.$ext.':normal:res';
+ push(@LONCAPA::map::order,$newidx);
+ &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
+ 'string_yesno');
+ &remember_parms($newidx,'hiddenresource','set','yes');
+ ($errtext,$fatal) =
+ &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
+ &log_differences($plain);
+ &mark_hash_old();
+ $r->internal_redirect($redirect);
+ return OK;
+ }
+ } else {
+ $r->internal_redirect($redirect);
+ }
+ }
+ }
+#
+# 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','title',
+ 'forcesupplement','forcestandard',
+ 'tools','symb','command','supppath']);
+
+ foreach my $item ('forcesupplement','forcestandard','tools') {
+ next if ($env{'form.'.$item} eq '');
+ unless ($env{'form.'.$item} eq '1') {
+ delete($env{'form.'.$item});
+ }
+ }
+
+ if ($env{'form.command'}) {
+ unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
+ delete($env{'form.command'});
+ }
+ }
+
+ if ($env{'form.symb'}) {
+ my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
+ unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
+ delete($env{'form.symb'});
+ }
+ }
+
+# 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 (($supplementalflag) ||
+ ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
+ unless ($allowed) { $supplementalflag=1; }
+ unless ($standard) { $supplementalflag=1; }
+ }
+ my $toolsflag=0;
+ if ($env{'form.tools'}) { $toolsflag=1; }
+
+ if ($env{'form.folderpath'} ne '') {
+ &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
+ }
+
+ my $backto_supppath;
+ if ($env{'form.supppath'} ne '') {
+ if ($supplementalflag && $allowed) {
+ $backto_supppath = &validate_supppath($coursenum,$coursedom);
+ }
+ }
- 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'},
- ['folder','foldername']);
- if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
- $showdoc=$1;
- }
- 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');
- }
- } else { # got called in sequence from course
- $allowed=0;
- $script=''.&Apache::lonmenu::registerurl(1,undef).''."\n"
+ .''."\n";
+
+ # Breadcrumbs
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+
+ if ($showdoc) {
+ my $args;
+ if ($supplementalflag) {
+ my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
+ my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
+ $args = {'bread_crumbs' => $brcrum,
+ 'bread_crumbs_nomenu' => 1};
+ } else {
+ $args = {'force_register' => $showdoc};
+ }
+ $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
+ } 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=>$breadtext});
+ $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
+ .&Apache::loncommon::help_open_menu('','',273,'RAT')
+ .&Apache::lonhtmlcommon::breadcrumbs(
+ $breadtitle)
+ );
+ } elsif ($r->uri eq '/adm/supplemental') {
+ unless ($env{'request.role.adv'}) {
+ unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
+ $r->internal_redirect('/adm/navmaps');
+ return OK;
+ }
+ }
+ my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
+ my $args = {'bread_crumbs' => $brcrum};
+ unless (($env{'form.folderpath'} eq '') ||
+ ($env{'form.folder'} eq 'supplemental')) {
+ $args->{'bread_crumbs_nomenu'} = 1;
+ }
+ $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
+ $args));
+ } 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=>$breadtext});
+ $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
+ {'add_entries' => $addentries}
+ )
+ .&Apache::loncommon::help_open_menu('','',273,'RAT')
+ .&Apache::lonhtmlcommon::breadcrumbs(
+ $breadtitle,
+ $helpitem)
+ );
+ }
- my $now=time;
+ my %allfiles = ();
+ my %codebase = ();
+ my ($upload_result,$upload_output,$uploadphase);
+ if ($canedit) {
+ undef($suppchanges);
+ 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);
+ undef($navmap);
+ if ($hadchanges) {
+ &mark_hash_old();
+ }
+ if ($suppchanges) {
+ &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
+ undef($suppchanges);
+ }
+ $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());
+ }
+ }
-# print screen
- $r->print(<
-
-The LearningOnline Network with CAPA
-
-ENDDOCUMENT
- if ($allowed) {
- $r->print(<
+ if ($allowed && $toolsflag) {
+ $r->print(&startContentScreen('tools'));
+ $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
+ $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 Repository',
+ 'impo' => 'Import from Repository',
+ 'lnks' => 'Import from Stored Links',
+ 'impm' => 'Import from Assembled Map',
+ 'imcr' => 'Import from Course Resources',
+ '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)',
+ 'stpr' => 'Standard Problem',
+ 'news' => 'New sub-directory',
+ 'crpr' => 'Create Problem',
+ 'swit' => 'Switch Server',
+ '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',
+ 'addp' => 'Add Placeholder to course?',
+ 'uste' => 'Use Template?',
+ 'fnam' => 'File Name:',
+ 'loca' => 'Location:',
+ 'dire' => 'Directory:',
+ 'cate' => 'Category:',
+ 'tmpl' => 'Template:',
+ 'empd' => 'No resources found',
+ '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',
+ 'yes' => 'Yes',
+ 'no' => 'No',
+ '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 ($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 $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=(<$lt{'parse'}?
+
+ -->
+
+ $lt{'parse'}
+
+CHBO
+ my $imsfolder = $env{'form.folder'};
+ if ($imsfolder eq '') {
+ $imsfolder = 'default';
+ }
+ my $imspform=(<