--- loncom/interface/londocs.pm 2006/11/02 21:06:06 1.245 +++ 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.245 2006/11/02 21:06:06 albertel Exp $ +# $Id: londocs.pm,v 1.722 2025/01/07 21:01:37 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,17 +33,29 @@ use Apache::Constants qw(:common :http); use Apache::imsexport; use Apache::lonnet; use Apache::loncommon; +use Apache::lonhtmlcommon; use LONCAPA::map(); use Apache::lonratedt(); -use Apache::lonratsrv; use Apache::lonxml; 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 LONCAPA; +use UUID::Tiny ':std'; +use LONCAPA qw(:DEFAULT :match); my $iconpath; @@ -53,16 +65,11 @@ my $hashtied; my %alreadyseen=(); my $hadchanges; +my $suppchanges; -# Available help topics my %help=(); -# Mapread read maps into LONCAPA::map:: 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)=@_; @@ -72,1221 +79,5112 @@ sub mapread { } sub storemap { - my ($coursenum,$coursedom,$map)=@_; + my ($coursenum,$coursedom,$map,$contentchg)=@_; + my $report; + if (($contentchg) && ($map =~ /^default/)) { + $report = 1; + } my ($outtext,$errtext)= &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'. - $map,1); + $map,1,$report); if ($errtext) { return ($errtext,2); } - - $hadchanges=1; + + 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'}; } 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(); - my $type = &Apache::loncommon::course_type(); - if ($home+$other==0) { return ''; } - my $output='
'.$error.'
'); + } + if ($hadchanges) { + unless (&is_hash_old()) { + &mark_hash_old(); + } + } + + &changewarning($r,''); + } + } + +# Supplemental documents start here + my $folder=$env{'form.folder'}; - unless ($folder=~/^supplemental/) { + unless ($supplementalflag) { $folder='supplemental'; } - if ($folder =~ /^supplemental$/ && - $env{'form.folderpath'} =~ /^default\&/) { - $env{'form.folderpath'}='supplemental&'. - &escape(&mt('Supplemental '.$type.' Documents')); + if (($folder eq 'supplemental') && + (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) { + $env{'form.folderpath'} = &supplemental_base(); + } elsif ($allowed) { + $env{'form.folderpath'} = $savefolderpath; } - &editor($r,$coursenum,$coursedom,$folder,$allowed); + $pathitem = ''; if ($allowed) { - my $folderseq= - '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time. - '.sequence'; - - $r->print(<'.$error.'
'); + } + if ($suppchanges) { + &Apache::lonnet::update_supp_caches($coursedom,$coursenum); + undef($suppchanges); + } + } + } elsif ($supplementalflag) { + my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, + $supplementalflag,'',$iconpath,$pathitem,'',$canedit, + $hostname); + if ($error) { + $r->print(''.$error.'
'); + } } + + if ($needs_end) { + $r->print(&endContentScreen()); + } + if ($allowed) { - $r->print(''. -&mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."
'. +&mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."
'.&mt('Not extracted.').'
'.
+ $error.'
'.$warning.'
'."\n"; + } + return $output; +} + +sub decompression_phase_two { + my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)= + &decompression_info(); + my $output; + if ($env{'form.archivedelete'}) { + $output = &remove_archive($docudom,$docuname,$container); + } + $output .= + &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname, + $destination,$dir_root,$hiddenelem); + return $output; +} + +sub remove_archive { + my ($docudom,$docuname,$container) = @_; + my $map = $env{'form.folder'}.'.'.$container; + my ($output,$delwarning,$delresult,$url); + my ($errtext,$fatal) = &mapread($docuname,$docudom,$map); + if ($fatal) { + if ($container eq 'page') { + $delwarning = &mt('An error occurred retrieving the contents of the current page.'); + } else { + $delwarning = &mt('An error occurred retrieving the contents of the current folder.'); + } + $delwarning .= ' '.&mt('As a result the archive file has not been removed.'); + } else { + my $currcmd = $env{'form.cmd'}; + my $position = $env{'form.position'}; + my $archiveidx = $position; + if ($position > 0) { + if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) { + $archiveidx = $position-1; + } + $env{'form.cmd'} = 'remove_'.$archiveidx; + my ($title,$url,@rrest) = + split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]); + if ($url eq $env{'form.archiveurl'}) { + if (&handle_edit_cmd($docuname,$docudom)) { + ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1); + if ($suppchanges) { + &Apache::lonnet::update_supp_caches($docudom,$docuname); + undef($suppchanges); + } + if ($fatal) { + if ($container eq 'page') { + $delwarning = &mt('An error occurred updating the contents of the current page.'); + } else { + $delwarning = &mt('An error occurred updating the contents of the current folder.'); + } + } else { + $delresult = &mt('Archive file removed.'); + } + } + } else { + $delwarning .= &mt('Archive file had unexpected item number in folder.'). + ' '.&mt('As a result the archive file has not been removed.'); + } + } + $env{'form.cmd'} = $currcmd; + } + if ($delwarning) { + $output = ''. + $delwarning. + '
'; + } + if ($delresult) { + $output .= ''. + $delresult. + '
'; + } + return $output; +} + +sub generate_admin_menu { + my ($crstype,$canedit,$coursenum,$coursedom) = @_; + my $lc_crstype = lc($crstype); + my ($home,$other,%outhash)=&authorhosts(); + my %lt= ( # do not translate here + 'vc' => 'Verify Content', + 'cv' => 'Check/Set Resource Versions', + 'ls' => 'List Resource Identifiers', + 'ct' => 'Display/Set Shortened URLs for Deep-linking', + 'ca' => "Enter $crstype Authoring Space", + 'imse' => 'Export contents to IMS Archive', + 'dcd' => 'Copy uploaded content to Authoring Space', + 'cpc' => 'Copy from Course Authoring to User Authoring', + ); + my ($candump,$dumpurl,$exportcrsurl); + if ($home + $other > 0) { + $candump = 'F'; + if ($home) { + $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')"; + $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')"; + } else { + my @hosts; + foreach my $aurole (keys(%outhash)) { + unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) { + push(@hosts,$outhash{$aurole}); + } + } + if (@hosts == 1) { + my $switchto = '/adm/switchserver?otherserver='.$hosts[0]. + '&role='. + &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='. + &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&'); + $dumpurl = "javascript:dump_needs_switchserver('$switchto')"; + $exportcrsurl = $dumpurl; + } else { + $dumpurl = "javascript:choose_switchserver_window()"; + $exportcrsurl = $dumpurl; + } + } + } + my @menu= + ({ categorytitle=>'Administration', + items =>[ + { linktext => $lt{'vc'}, + url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')", + permission => 'F', + help => 'Docs_Verify_Content', + icon => 'verify.png', + linktitle => 'Verify contents can be retrieved/rendered', + }, + { linktext => $lt{'cv'}, + url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')", + permission => 'F', + help => 'Docs_Check_Resource_Versions', + icon => 'resversion.png', + linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions", + }, + { linktext => $lt{'ls'}, + url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')", + permission => 'F', + #help => '', + icon => 'symbs.png', + linktitle => "List the unique identifier used for each resource instance in your $lc_crstype" + }, + { linktext => $lt{'ct'}, + url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')", + permission => 'F', + help => 'Docs_Short_URLs', + icon => 'shorturls.png', + linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking" + }, + ] + }); + if ($canedit) { + my ($crsauname,$crsaudom,$crshome); + if (($coursenum ne '') && ($coursedom ne '')) { + my $crsauthorurl = "/priv/$coursedom/$coursenum/"; + ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl); + if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) { + my @ids=&Apache::lonnet::current_machine_ids(); + my $linkurl; + if (grep(/^\Q$crshome\E$/,@ids)) { + $linkurl = $crsauthorurl; + } else { + my $jscall = &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1); + if ($jscall) { + $linkurl = 'javascript:'.$jscall; + } + } + if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY') && ($linkurl)) { + push(@{$menu[0]->{items}}, + { linktext => $lt{'ca'}, + url => $linkurl, + permission => 'F', + help => 'Docs_Course_Authorspace', + icon => 'impcrsau.png', + linktitle => $lt{'ca'}, + }); + } + } + } + push(@menu, + { categorytitle=>'Export', + items =>[ + { linktext => $lt{'imse'}, + url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')", + permission => 'F', + help => 'Docs_Export_Course_Docs', + icon => 'imsexport.png', + linktitle => $lt{'imse'}, + }, + { linktext => $lt{'dcd'}, + url => $dumpurl, + permission => $candump, + help => 'Docs_Dump_Course_Docs', + icon => 'dump.png', + linktitle => $lt{'dcd'}, + }, + ] + }); + if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) { + if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) { + push(@{$menu[1]->{items}}, + { linktext => $lt{'cpc'}, + url => $exportcrsurl, + permission => 'F', + help => 'Docs_Export_Course_Author', + icon => 'res.png', + linktitle => $lt{'cpc'}, + }); + } + } + } + return '$html_js_lt{'yone'}<\\/p>\\n'+ + '