--- loncom/interface/londocs.pm 2023/12/28 19:29:38 1.707 +++ loncom/interface/londocs.pm 2024/01/10 20:07:37 1.709 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.707 2023/12/28 19:29:38 raeburn Exp $ +# $Id: londocs.pm,v 1.709 2024/01/10 20:07:37 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -102,6 +102,7 @@ sub authorhosts { my %outhash=(); my $home=0; my $other=0; + my @ids=&Apache::lonnet::current_machine_ids(); foreach my $key (keys(%env)) { if ($key=~/^user\.role\.(au|ca)\.(.+)$/) { my $role=$1; @@ -118,7 +119,6 @@ sub authorhosts { } 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; @@ -263,8 +263,8 @@ ENDJS add_entries => {'onload' => "hide_searching();"}, }; } - $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n". - &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n"); + $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n". + &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n"); $r->print(&startContentScreen('tools')); my ($home,$other,%outhash)=&authorhosts(); unless ($home) { @@ -5965,7 +5965,7 @@ sub handler { &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions'); &checkversions($r,$canedit); } elsif ($canedit && $env{'form.dumpcourse'}) { - &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space'); + &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space'); &dumpcourse($r); } elsif ($canedit && $env{'form.exportcourse'}) { &init_breadcrumbs('exportcourse','IMS Export'); @@ -6503,7 +6503,7 @@ sub handler { if ($allowed && $toolsflag) { $r->print(&startContentScreen('tools')); - $r->print(&generate_admin_menu($crstype,$canedit)); + $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom)); $r->print(&endContentScreen()); } elsif ((!$showdoc) && (!$uploadphase)) { # ----------------------------------------------------------------------------- @@ -7597,7 +7597,7 @@ sub remove_archive { } sub generate_admin_menu { - my ($crstype,$canedit) = @_; + my ($crstype,$canedit,$coursenum,$coursedom) = @_; my $lc_crstype = lc($crstype); my ($home,$other,%outhash)=&authorhosts(); my %lt= ( # do not translate here @@ -7605,6 +7605,7 @@ sub generate_admin_menu { '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 $crstype Content to Authoring Space", ); @@ -7665,6 +7666,31 @@ sub generate_admin_menu { ] }); 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 { + $linkurl = + &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1); + } + if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) { + 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 =>[ @@ -9381,7 +9407,7 @@ sub dump_switchserver_js { ); my %html_js_lt = &Apache::lonlocal::texthash( swit => 'Switch server?', - duco => 'Copying Content to Authoring Space', + duco => 'Copying uploaded content to Authoring Space', yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.', chos => 'Choose server', ); @@ -9522,55 +9548,8 @@ sub makenewproblem { if ($redirect) { my $rightsfile = 'default.rights'; my $sourcerights = "$path/$rightsfile"; + &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom); my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile"; - my $now = time; - if (!-e $sourcerights) { - my $cid = $coursedom.'_'.$coursenum; - if (open(my $fh,">$sourcerights")) { - print $fh < - -END - close($fh); - } - } - if (!-e "$sourcerights.meta") { - if (open(my $fh,">$sourcerights.meta")) { - my $author=$env{'environment.firstname'}.' '. - $env{'environment.middlename'}.' '. - $env{'environment.lastname'}.' '. - $env{'environment.generation'}; - $author =~ s/\s+$//; - print $fh <<"END"; - - -$author -$coursenum:$coursedom -private -$now - - -$coursedom -0 - -notset -$now -0 -rights -$env{'user.name'}:$env{'user.domain'} - - - -$coursenum:$coursedom -deny:::course,allow:$cid::course - - - -Course Authoring Rights -END - close($fh); - } - } if ((-e $sourcerights) && (-e "$sourcerights.meta")) { if (!-e "$docroot/res/$coursedom") { mkdir("$docroot/res/$coursedom",0755);