--- loncom/interface/londocs.pm 2024/12/27 02:32:55 1.714 +++ loncom/interface/londocs.pm 2024/12/28 12:19:21 1.715 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.714 2024/12/27 02:32:55 raeburn Exp $ +# $Id: londocs.pm,v 1.715 2024/12/28 12:19:21 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -579,7 +579,8 @@ $contents{webreferences}.' $title=~s/[\/\s]+/\_/gs; $title=&clean($title); my $formname = 'dumpdoc'; - my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash); + my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash). + '
'."\n"; my %uploadedfiles; &tiehash(); foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { @@ -643,8 +644,8 @@ sub authorspace_selector { } $preamble .= '
'. '
'.&mt('Folder in Authoring Space').''. - ''."\n". - '
'."\n"; + ''."\n". + ''."\n"; return $preamble; } @@ -694,9 +695,70 @@ sub recurse_html { sub copycrsauthored { my ($r,$coursenum,$coursedom,$coursehome,$readonly) = @_; - my ($starthash,$js); + my ($starthash,$js,$title,$formname); + my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'}); + $title=$origcrsdata{'description'}; + $title=~s/[\/\s]+/\_/gs; + $title=&clean($title); + my ($home,$other,%outhash)=&authorhosts(); unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) { - $js = <<"ENDJS"; + my %js_lt; + $formname = 'copycrsauthored'; + if ($home) { + %js_lt = + &Apache::lonlocal::texthash( + yomu => 'You must select an Authoring Space', + whco => 'When Copyright set to "custom", URL of a published rights file is needed.', + ); + &js_escape(\%js_lt); + } + if ($home > 1) { + $js = <<"ENDJS"; + + +ENDJS + } elsif ($home) { + $js = <<"ENDJS"; + + +ENDJS + } + $js .= <<"ENDJS"; ENDJS + + $js .= "\n".&Apache::lonhtmlcommon::scripttag(&Apache::loncommon::browser_and_searcher_javascript())."\n"; $starthash = { - add_entries => {'onload' => "hide_searching();"}, + add_entries => {'onload' => "hide_searching(); init_copycrs_form();"}, }; } $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n". &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n"); $r->print(&startContentScreen('tools')); - my ($home,$other,%outhash)=&authorhosts(); unless ($home) { $r->print('

'.&mt('No author or co-author roles on this server.').'

'); $r->print(&endContentScreen()); return ''; } + my $docroot = $r->dir_config('lonDocRoot'); my $is_course_home; my @ids=&Apache::lonnet::current_machine_ids(); if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) { $is_course_home = 1; } - my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'}); my $exclude = &Apache::lonnet::priv_exclude(); my $srcurl = "/priv/$coursedom/$coursenum"; - my $srctop = $r->dir_config('lonDocRoot').$srcurl; + my $srctop = $docroot.$srcurl; + my $resurl = "/res/$coursedom/$coursenum"; + my $res_exclude = &Apache::lonnet::res_exclude(); if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) { $r->print('

'.&mt('Copying Files and/or Sub-directories').'

'); if ($readonly) { @@ -748,7 +824,8 @@ ENDJS } my ($ca,$cd)=split(/\:/,$env{'form.authorspace'}); my $desturl = "/priv/$cd/$ca"; - my $desttop = $r->dir_config('lonDocRoot').$desturl; + my $destresurl = "/res/$cd/$ca"; + my $desttop = $docroot.$desturl; my $subdir = &clean($env{'form.authorfolder'}); $subdir = &cleandir($subdir); if ($subdir eq '') { @@ -806,8 +883,6 @@ ENDJS } if (keys(%tocopy)) { my (%resdirs,%resfiles); - my $resurl = "/res/$coursedom/$coursenum"; - my $res_exclude = &Apache::lonnet::res_exclude(); &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles); my ($notopdir,%newdir,%newfile,%checkdeps); $r->print('

'.&mt('Copy to: [_1]', @@ -851,6 +926,39 @@ ENDJS } if (-e $desttop.'/'.$subdir) { my $num = 0; + my ($copyright,$customdistfile); + if ($env{'form.copyright'} eq 'default' || $env{'form.copyright'} eq 'domain' || $env{'form.copyright'} eq 'public') { + $copyright = $env{'form.copyright'}; + } elsif ($env{'form.copyright'} eq 'custom') { + if ($env{'form.customrights'} =~ m{^/res/$match_domain/$match_username/.+\.rights$}) { + my ($rightsdom,$rightsuname) = ($1,$2); + my $rightshome = &Apache::lonnet::homeserver($rightsdom,$rightsuname); + if (($rightshome eq 'no_host') || ($rightshome eq '')) { + $copyright = 'default'; + } elsif (grep(/^\Q$rightshome\E$/,@ids)) { + if (-e $docroot.$env{'form.customrights'}) { + $copyright = 'custom'; + $customdistfile = $env{'form.customrights'}; + } else { + $copyright = 'default'; + } + } else { + my $rightsfile = &Apache::lonnet::filelocation('',$env{'form.customrights'}); + unless (&Apache::lonnet::getfile($rightsfile) eq '-1') { + $customdistfile = $env{'form.customrights'}; + } + } + } + } + my $sourceavail; + if ($env{'form.sourceavail'} =~ /^(open|closed)$/) { + $sourceavail = $env{'form.sourceavail'}; + } + my $respublish; + if ($env{'form.respublish'}) { + $respublish = 1; + } + my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes')); foreach my $file (keys(%files_to_copy)) { my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname); if ($file =~ m{/}) { @@ -911,18 +1019,25 @@ ENDJS } if ($gotmeta) { if (open(my $fh,'<',$dest.'.meta')) { - my ($output,$now); + my ($output,$now,setsourceavail); $now = time; + if (($file =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($file =~ /$LONCAPA::assess_re/)) { + $setsourceavail = 1; + } while (my $line=<$fh>) { chomp($line); if ($line eq "$coursenum:$coursedom") { $output .= "$ca:$cd\n"; } elsif ($line eq 'custom') { - $output .= "default\n"; + $output .= "$copyright\n"; } elsif ($line =~ m{^\d+$}) { $output .= "$now\n"; } elsif ($line eq "/res/$coursedom/$coursenum/default.rights") { - $output .= "\n"; + $output .= "$customdistfile\n"; + } elsif ($line =~ m{^(open|closed)$}) { + if ($setsourceavail) { + $output .= "$sourceavail\n"; + } } elsif ($line eq "$coursedom") { $output .= "$cd\n"; } elsif ($line =~ m{^\d+$}) { @@ -1095,6 +1210,18 @@ ENDJS } } } + if ($respublish) { + my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file; + if ($path eq '') { + if ((ref($resfiles{'/'}) eq 'HASH') && + (exists($resfiles{'/'}{$fname}))) { + my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1); + } + } elsif ((ref($resfiles{$path}) eq 'HASH') && + (exists($resfiles{$path}{$fname}))) { + my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1); + } + } } } } @@ -1138,7 +1265,6 @@ ENDJS return ''; } } else { - my $formname = 'copycrsauthored'; my $chkname = 'copytouser'; my $context = 'crsauthored'; my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps); @@ -1172,9 +1298,19 @@ ENDJS } my ($info,$display,$onsubmit,$togglebuttons,$disabled); my (%resdirs,%resfiles); - my $resurl = "/res/$coursedom/$coursenum"; - my $resexclude = &Apache::lonnet::res_exclude(); - &Apache::lonnet::recursedirs($is_course_home,1,undef,$resexclude,0,0,$resurl,'',\%resdirs,\%resfiles); + &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles); + my $numpub = 0; + if (keys(%resfiles)) { + foreach my $dir (keys(%resfiles)) { + if (ref($resfiles{$dir}) eq 'HASH') { + foreach my $file (keys(%{$resfiles{$dir}})) { + if (exists($files{$dir}{$file})) { + $numpub ++; + } + } + } + } + } if ($readonly) { $disabled = ' disabled="disabled"'; } @@ -1186,11 +1322,10 @@ ENDJS '  '; } - my $title=$origcrsdata{'description'}; - $title=~s/[\/\s]+/\_/gs; - $title=&clean($title); - my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash); - my $display = '

'."\n". + my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash). + &courseresource_options($formname,$numpub). + '
'."\n"; + my $display = ''."\n". $preamble."\n". '
'."\n". '
'."\n". @@ -1326,6 +1461,51 @@ sub recurse_crsauthored { return $count; } +sub courseresource_options { + my ($formname,$numpub) = @_; + my %lt = &Apache::lonlocal::texthash( + 'default' => 'System wide - can be used for any courses system wide', + 'domain' => 'Domain only - use limited to courses in the domain', + 'custom' => 'Customized right of use ...', + 'public' => 'Public - no authentication or authorization required for use', + 'closed' => 'Closed - XML source is closed to everyone', + 'open' => 'Open - XML source is open to people who want to use it', + 'sel' => 'Select', + ); + my $output; + if ($numpub) { + $output .= '
'. + '
'.&mt('Published Resources').''. + &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.', + $numpub).'
'. + &mt('Publish copied files in selected Authoring Space?').': '."\n". + ''."\n". + ''."\n". + '
'."\n"; + } + $output .= '
'. + '
'.&mt('Distribution to set in metadata').''. + &mt('Copyright').': '. + '
'."\n". + &mt('Source').' :'. + '
'."\n". + '
'."\n"; + return $output; +} + sub group_import { my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_; my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,