--- loncom/interface/londocs.pm 2004/02/19 21:51:11 1.107
+++ loncom/interface/londocs.pm 2017/08/13 20:52:58 1.634
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.107 2004/02/19 21:51:11 albertel Exp $
+# $Id: londocs.pm,v 1.634 2017/08/13 20:52:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,15 +30,29 @@ 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 HTML::Entities;
+use HTML::TokeParser;
use GDBM_File;
+use File::MMagic;
+use File::Copy;
use Apache::lonlocal;
+use Cwd;
+use LONCAPA qw(:DEFAULT :match);
my $iconpath;
@@ -48,463 +62,4541 @@ 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)=@_;
+ my ($coursenum,$coursedom,$map,$contentchg)=@_;
+ my $report;
+ if (($contentchg) && ($map =~ /^default/)) {
+ $report = 1;
+ }
my ($outtext,$errtext)=
- &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
+ &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
+ $map,1,$report);
if ($errtext) { return ($errtext,2); }
-
- $hadchanges=1;
+
+ if ($map =~ /^default/) {
+ $hadchanges=1;
+ } else {
+ $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)\.(.+)$/) {
+ 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)$/);
}
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();
- 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 dumpcourse {
- my $r=shift;
- $r->print('Dump DOCS '.
- &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
- ' ');
- }
-# ----------------------------------------------------- Supplemental documents
- if (!$forcestandard) {
- $r->print(
- ''.&mt('Supplemental Course Documents').
- ($allowed?' '.$help{'Supplemental'}:'').' ');
- my $folder=$ENV{'form.folder'};
- unless ($folder=~/supplemental/) { $folder='supplemental'; }
- &editor($r,$coursenum,$coursedom,$folder,$allowed);
- if ($allowed) {
- my $folderseq=
- '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
- '.sequence';
-
- $r->print(<
-$lt{'upls'}
-$lt{'spec'}
-
-
-
-
- $lt{'comment'}:
-
-
-
-
-
-
-
- $help{'Uploading_From_Harddrive'}
-
-
-
-
-
-
-
-
-
- $help{'Adding_Folders'}
-
-
-
-
-
-
-
- $help{'Adding_External_Resource'}
-
-
-
-
-
-
-
-
-$help{'Syllabus'}
-
-
-
-
-
-
-
-
-$help{'My Personal Info'}
-
-
-
-
-ENDSUPFORM
- }
+ } else {
+ $jsmakefunctions = <print(' ');
+ return <print('');
- } else {
-# -------------------------------------------------------- This is showdoc mode
- $r->print("".&mt('Uploaded Document').' '.
-&mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."
".
- &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'
');
- }
- }
- $r->print('');
- return OK;
+ resize_scrollbox('contentscroll','1','1');
+ return;
+}
+
+function toggleMap(caller) {
+ var disp = 'none';
+ if (document.getElementById('importmapform')) {
+ if (caller == 'map') {
+ var curr = document.getElementById('importmapform').style.display;
+ if (curr == 'none') {
+ disp='block';
+ }
+ }
+ document.getElementById('importmapform').style.display=disp;
+ resize_scrollbox('contentscroll','1','1');
+ }
+ return;
+}
+
+function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
+ var disp = 'none';
+ if (document.getElementById('crsresform')) {
+ if (caller == 'res') {
+ var curr = document.getElementById('crsresform').style.display;
+ if (curr == 'none') {
+ disp='block';
+ numauthor = parseInt(numauthorrole);
+ if (numauthor > 0) {
+ document.courseresform.authorrole.selectedIndex = 0;
+ select1priv_changed();
+ document.courseresform.authorpath.selectedIndex = 0;
+ document.courseresform.newresourceadd.selectedIndex = 0;
+ toggleNewInCourse(document.courseresform);
+ if (document.getElementById('newresource')) {
+ document.getElementById('newresource').style.display = 'none';
+ }
+ } else {
+ if (numcrsdirs) {
+ document.courseresform.authorpath.selectedIndex = 0;
+ }
+ }
+ if (document.courseresform.newresusetemp.length) {
+ document.courseresform.newresusetemp[0].checked = true;
+ toggleWithTemplate(document.courseresform);
+ }
+ document.courseresform.newresourcename.value = '';
+ }
+ }
+ if (document.courseresform.newsubdir.length) {
+ for (var j=0; j $js_lt{'sunm'}';
+ }
+ } else {
+ document.getElementById('newsubdirname').type = "hidden";
+ document.getElementById('newsubdirname').value = "";
+ document.getElementById('newsubdir').innerHTML = "";
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+function toggleCrsResTitle() {
+ if (document.getElementById('newresource')) {
+ if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
+ document.getElementById('newresource').style.display = 'inline';
+ document.courseresform.newresourceadd[0].checked = true;
+ toggleNewInCourse(document.courseresform);
+ } else {
+ document.getElementById('newresource').style.display = 'none';
+ }
+ }
+}
+
+function toggleNewInCourse(form) {
+ if (form.newresourceadd.length) {
+ for (var i=0; i $js_lt{'tinc'}";
+ }
+ } else {
+ document.getElementById('newresourcetitle').type = 'hidden';
+ document.getElementById('newresourcetitle').value = '';
+ if (document.getElementById('newrestitle')) {
+ document.getElementById('newrestitle').innerHTML = '';
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+function toggleWithTemplate(form) {
+ if (form.newresusetemp.length) {
+ for (var i=0; i 1) {
+ select1res_changed();
+ }
+ }
+ }
+ document.getElementById('importcrsresform').style.display=disp;
+ resize_scrollbox('contentscroll','1','0');
+ }
+ return;
+}
+
+function makeims(imsform) {
+ if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
+ alert("$js_lt{'imsfile'}");
+ return;
+ }
+ if (imsform.source.selectedIndex == 0) {
+ alert("$js_lt{'imscms'}");
+ return;
+ }
+ newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
+ imsform.submit();
+}
+
+function updatePick(targetform,index,caller) {
+ var pickitem;
+ var picknumitem;
+ var picknumtext;
+ if (index == 'all') {
+ pickitem = document.getElementById('randompickall');
+ picknumitem = document.getElementById('rpicknumall');
+ picknumtext = document.getElementById('rpicktextall');
+ } else {
+ pickitem = document.getElementById('randompick_'+index);
+ picknumitem = document.getElementById('rpicknum_'+index);
+ picknumtext = document.getElementById('randompicknum_'+index);
+ }
+ if (pickitem.checked) {
+ var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
+ if (picknum == '' || picknum == null) {
+ if (caller == 'check') {
+ pickitem.checked=false;
+ if (index == 'all') {
+ picknumtext.innerHTML = '';
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ checkForSubmit(targetform,'randompick','settings');
+ }
+ }
+ } else {
+ picknum.toString();
+ var regexdigit=/^\\d+\$/;
+ if (regexdigit.test(picknum)) {
+ picknumitem.value = picknum;
+ if (index == 'all') {
+ picknumtext.innerHTML = ' '+picknum+' ';
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ picknumtext.innerHTML = ' '+picknum+' ';
+ checkForSubmit(targetform,'randompick','settings');
+ }
+ } else {
+ if (caller == 'check') {
+ if (index == 'all') {
+ picknumtext.innerHTML = '';
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ pickitem.checked=false;
+ checkForSubmit(targetform,'randompick','settings');
+ }
+ }
+ return;
+ }
+ }
+ } else {
+ picknumitem.value = '';
+ picknumtext.innerHTML = '';
+ if (index == 'all') {
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ checkForSubmit(targetform,'randompick','settings');
+ }
+ }
+}
+
+function propagateState(form,param) {
+ if (document.getElementById(param+'all')) {
+ var setcheck = 0;
+ var rpick = 0;
+ if (param == 'rpicknum') {
+ if (document.getElementById('randompickall')) {
+ if (document.getElementById('randompickall').checked) {
+ if (document.getElementById('rpicknumall')) {
+ rpick = document.getElementById('rpicknumall').value;
+ }
+ }
+ }
+ } else {
+ if (document.getElementById(param+'all').checked) {
+ setcheck = 1;
+ }
+ }
+ var allidxlist;
+ if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
+ if (document.getElementById('all'+param+'idx')) {
+ allidxlist = document.getElementById('all'+param+'idx').value;
+ }
+ var actions = new Array ('remove','cut','copy');
+ for (var i=0; i 1) {
+ for (var i=0; i 0) {
+ document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': '+rpick+' ';
+ } else {
+ document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
+ }
+ }
+ }
+ } else {
+ if (setcheck == 1) {
+ document.getElementById(param+'_'+allidxs[i]).checked = true;
+ } else {
+ document.getElementById(param+'_'+allidxs[i]).checked = false;
+ if (param == 'randompick') {
+ document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
+ }
+ }
+ }
+ }
+ }
+ if (setcheck == 1) {
+ if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
+ var actions = new Array('copy','cut','remove');
+ for (var i=0; i 1) {
+ for (var j=0; j 2 ){
+ currentNav = document.getElementById(tabnav[1].id);
+ currentLis = currentNav.getElementsByTagName('LI');
+ for(i = 0; i< currentLis.length; i++){
+ if(currentLis[i].className == 'active') {
+ funcString = currentLis[i].onclick.toString();
+ tab = funcString.split('"');
+ if(tab.length < 2) {
+ tab = funcString.split("'");
+ }
+ currentData = document.getElementById(tab[1]);
+ currentData.style.display = 'block';
+ }
+ }
+ }
+}
+
+function showPage(current, pageId, nav, data) {
+ currstate = current.className;
+ hideAll(current, nav, data);
+ openTabs(pageId);
+ unselectInactive(nav);
+ if ((currstate == 'active') || (currstate == 'right active')) {
+ if (currstate == 'active') {
+ current.className = '';
+ } else {
+ current.className = 'right';
+ }
+ activeTab = '';
+ toggleUpload();
+ toggleMap();
+ toggleCrsRes();
+ toggleImportCrsres();
+ resize_scrollbox('contentscroll','1','0');
+ return;
+ } else {
+ current.className = 'active';
+ }
+ currentData = document.getElementById(pageId);
+ currentData.style.display = 'block';
+ activeTab = pageId;
+ toggleUpload();
+ toggleMap();
+ toggleCrsRes();
+ toggleImportCrsres();
+ if (nav == 'mainnav') {
+ var storedpath = "$docs_folderpath";
+ var storedpage = "$main_container_page";
+ var reg = new RegExp("^supplemental");
+ if (pageId == 'mainCourseDocuments') {
+ if (storedpage == 1) {
+ document.simpleedit.folderpath.value = '';
+ document.uploaddocument.folderpath.value = '';
+ } else {
+ if (reg.test(storedpath)) {
+ document.simpleedit.folderpath.value = '$toplevelmain';
+ document.uploaddocument.folderpath.value = '$toplevelmain';
+ document.newext.folderpath.value = '$toplevelmain';
+ } else {
+ document.simpleedit.folderpath.value = storedpath;
+ document.uploaddocument.folderpath.value = storedpath;
+ document.newext.folderpath.value = storedpath;
+ }
+ }
+ } else {
+ if (reg.test(storedpath)) {
+ document.simpleedit.folderpath.value = storedpath;
+ document.supuploaddocument.folderpath.value = storedpath;
+ document.supnewext.folderpath.value = storedpath;
+ } else {
+ document.simpleedit.folderpath.value = '$toplevelsupp';
+ document.supuploaddocument.folderpath.value = '$toplevelsupp';
+ document.supnewext.folderpath.value = '$toplevelsupp';
+ }
+ }
+ }
+ resize_scrollbox('contentscroll','1','0');
+ return false;
+}
+
+function toContents(jumpto) {
+ var newurl = '$backtourl';
+ if ((newurl == '/adm/navmaps') && (jumpto != '')) {
+ newurl = newurl+'?postdata='+jumpto;
+ }
+ location.href=newurl;
+}
+
+function togglePick(caller,value) {
+ var disp = 'none';
+ if (document.getElementById('multi'+caller)) {
+ var curr = document.getElementById('multi'+caller).style.display;
+ if (value == 1) {
+ disp='block';
+ }
+ if (curr == disp) {
+ return;
+ }
+ document.getElementById('multi'+caller).style.display=disp;
+ if (value == 1) {
+ document.getElementById('more'+caller).innerHTML = ' $js_lt{'more'} ';
+ } else {
+ document.getElementById('more'+caller).innerHTML = '';
+ }
+ if (caller == 'actions') {
+ setClass(value);
+ setBoxes(value);
+ }
+ }
+ var showButton = multiSettings();
+ if (showButton != 1) {
+ showButton = multiActions();
+ }
+ if (document.getElementById('multisave')) {
+ if (showButton == 1) {
+ document.getElementById('multisave').style.display='block';
+ } else {
+ document.getElementById('multisave').style.display='none';
+ }
+ }
+ resize_scrollbox('contentscroll','1','1');
+ return;
+}
+
+function toggleCheckUncheck(caller,more) {
+ if (more == 1) {
+ document.getElementById('more'+caller).innerHTML = ' $js_lt{'less'} ';
+ document.getElementById('allfields'+caller).style.display='block';
+ } else {
+ document.getElementById('more'+caller).innerHTML = ' $js_lt{'more'} ';
+ document.getElementById('allfields'+caller).style.display='none';
+ }
+ resize_scrollbox('contentscroll','1','1');
+}
+
+function multiSettings() {
+ var inuse = 0;
+ var settingsform = document.togglemultsettings;
+ if (settingsform.showmultpick.length > 1) {
+ for (var i=0; i 1) {
+ for (var i=0; i 0) {
+ form.multichange.value = numchanges;
+ }
+ }
+ var dosettings = multiSettings();
+ var haschanges = 0;
+ if (dosettings == 1) {
+ form.allencrypturl.value = '';
+ form.allhiddenresource.value = '';
+ form.changeparms.value = 'all';
+ var patt=new RegExp(",\$");
+ var allidxlist = document.cumulativesettings.allidx.value;
+ if ((allidxlist != '') && (allidxlist != null)) {
+ var allidxs = allidxlist.split(',');
+ if (allidxs.length > 1) {
+ for (var i=0; i 0) {
+ if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
+ if (remwarnings > 0) {
+ if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
+ return false;
+ }
+ }
+ if (removalinfo > 0) {
+ if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
+ return false;
+ }
+ }
+ if (cutwarnings > 0) {
+ if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
+ return false;
+ }
+ }
+ }
+ form.submit();
+ return true;
+ }
+ }
+ if (dosettings == 1) {
+ if (haschanges == 1) {
+ form.submit();
+ return true;
+ }
+ }
+ if ((dosettings == 1) && (doactions == 1)) {
+ alert("$js_lt{'noor'}");
+ } else {
+ if (dosettings == 1) {
+ alert("$js_lt{'noch'}");
+ } else {
+ alert("$js_lt{'noac'}");
+ }
+ }
+ return false;
+}
+
+function setClass(value) {
+ var cutclass = 'LC_docs_cut';
+ var copyclass = 'LC_docs_copy';
+ var removeclass = 'LC_docs_remove';
+ var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
+ var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
+ var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
+ var links = document.getElementsByTagName('a');
+ for (var i=0; i 'Copying content to Authoring Space requires switching server.',
+ swit => 'Switch server?',
+ );
+ my %html_js_lt = &Apache::lonlocal::texthash(
+ swit => 'Switch server?',
+ duco => 'Copying 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',
+ );
+ &js_escape(\%js_lt);
+ &html_escape(\%html_js_lt);
+ &js_escape(\%html_js_lt);
+ my $role = $env{'request.role'};
+ my $js = <<"ENDSWJS";
+
+
+ENDSWJS
+
+ my $startpage = &Apache::loncommon::start_page('Choose server',$js,
+ {'only_body' => 1,
+ 'js_ready' => 1,});
+ my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
+
+ my $hostpicker;
+ my $count = 0;
+ foreach my $host (sort(@hosts)) {
+ my $checked;
+ if ($count == 0) {
+ $checked = ' checked="checked"';
+ }
+ $hostpicker .= ' '.$host.' ';
+ $count++;
+ }
+
+ return <<"ENDSWITCHJS";
+
+function dump_needs_switchserver(url) {
+ if (url!='' && url!= null) {
+ if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
+ go(url);
+ }
+ }
+ return;
+}
+
+function choose_switchserver_window() {
+ newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
+ newWindow.document.open();
+ newWindow.document.writeln('$startpage');
+ newWindow.document.write('$html_js_lt{'duco'}<\\/h3>\\n'+
+ ' $html_js_lt{'yone'}<\\/p>\\n'+
+ '
$html_js_lt{'chos'}<\\/legend>\\n'+
+ ' \\n'+
+ '$hostpicker\\n'+
+ ' \\n'+
+ ' \\n'+
+ '<\\/form><\\/fieldset><\\/div> \\n');
+ newWindow.document.writeln('$endpage');
+ newWindow.document.close();
+ newWindow.focus();
+}
+
+ENDSWITCHJS
+}
+
+sub makedocslogform {
+ my ($formelems,$docslog) = @_;
+ return <<"LOGSFORM";
+
+
+ $formelems
+
+LOGSFORM
+}
+
+sub makesimpleeditform {
+ my ($formelems) = @_;
+ return <<"SIMPFORM";
+
+
+ $formelems
+
+SIMPFORM
+}
+
+sub makenewproblem {
+ my ($r,$coursedom,$coursenum) = @_;
+# Creating a new problem
+ my ($redirect,$error);
+ if ($env{'form.authorrole'}) {
+ my ($newsubdir,$filename);
+ if ($env{'form.newsubdir'}) {
+ if ($env{'form.newsubdirname'} ne '') {
+ $newsubdir = $env{'form.newsubdirname'};
+ }
+ }
+ if ($env{'form.newresourcename'}) {
+ $filename = $env{'form.newresourcename'};
+ $filename =~ s/\.(\d+)(\.\w+)$/$2/;
+ $filename =~ s/`//g;
+ $filename =~ s{/\.\./}{_}g;
+ $filename =~ s/\.+/./g;
+ $filename =~ s{/+}{_}g;
+ if ($filename ne '') {
+ my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
+ if (($ext) && ($ext ne '.problem')) {
+ $filename = $name.'.problem';
+ } elsif ($ext eq '') {
+ $filename .= '.problem';
+ }
+ my $docroot = $r->dir_config('lonDocRoot');
+ my @ids=&Apache::lonnet::current_machine_ids();
+ if ($env{'form.authorrole'} eq 'author') {
+ if ($env{'user.author'}) {
+ if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
+ my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
+ my $path = $docroot.$url;
+ my $subdir = $env{'form.authorpath'};
+ $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
+ }
+ }
+ } elsif ($env{'form.authorrole'} eq 'course') {
+ my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
+ if ($chome && grep(/^\Q$chome\E$/,@ids)) {
+ my $url = "/priv/$coursedom/$coursenum";
+ my $path=$docroot.$url;
+ my $subdir = $env{'form.authorpath'};
+ $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
+ if ($redirect) {
+ my $rightsfile = 'default.rights';
+ my $sourcerights = "$path/$rightsfile";
+ 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
+
+
+
+
+END
+ close($fh);
+ }
+ if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
+ if (!-e "$docroot/res/$coursedom") {
+ mkdir("$docroot/res/$coursedom",0755);
+ }
+ if (!-e "$docroot/res/$coursedom/$coursenum") {
+ mkdir("$docroot/res/$coursedom/$coursenum",0755);
+ }
+ if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
+ my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
+ my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
+ }
+ }
+ }
+ if ($env{'form.newresourceadd'}) {
+ my $template = $env{'form.template'};
+ my $source = $docroot.$redirect;
+ my $target = $redirect;
+ $target =~ s{^/priv/}{/res/};
+ $target = $docroot.$target;
+ if (!-e $source) {
+ my $copyfrom;
+ if ($template) {
+ my %templates;
+ my @files = &Apache::lonhomework::get_template_list('problem');
+ foreach my $poss (@files) {
+ if (ref($poss) eq 'ARRAY') {
+ if ($template eq $poss->[0]) {
+ $templates{$template} = 1;
+ last;
+ }
+ }
+ }
+ if ($templates{$template}) {
+ $copyfrom = $template;
+ }
+ }
+ unless ($copyfrom) {
+ $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
+ }
+ &File::Copy::copy($copyfrom,$source);
+ }
+ if (!-e "$source.meta") {
+ my $cid = $coursedom.'_'.$coursenum;
+ my $now = time;
+ if (open(my $fh,">$source.meta")) {
+ my $author=$env{'environment.firstname'}.' '.
+ $env{'environment.middlename'}.' '.
+ $env{'environment.lastname'}.' '.
+ $env{'environment.generation'};
+ $author =~ s/\s+$//;
+ my $title = $env{'form.newresourcetitle'};
+ $title =~ s/^\s+|\s+$//g;
+ print $fh <
+$author
+$coursenum:$coursedom
+custom
+$now
+/res/$coursedom/$coursenum/default.rights
+
+$coursedom
+0
+
+notset
+$now
+0
+problem
+$coursenum:$coursedom
+
+
+
+$coursenum:$coursedom
+
+
+
+$title
+END
+ close($fh);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
+ my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
+ if (grep(/^\Q$rolehome\E$/,@ids)) {
+ my $now = time;
+ if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
+ my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
+ if (($start <= $now) && (($end == 0) || ($end >= $now))) {
+ my $url = "/priv/$audom/$auname";
+ my $path = $r->dir_config('lonDocRoot').$url;
+ my $subdir = $env{'form.authorpath'};
+ $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return ($redirect,$error);
+}
+
+sub finishnewprob {
+ my ($url,$path,$subdir,$newsubdir,$filename) = @_;
+ unless (-d $path) {
+ unless (mkdir($path,02770)) {
+ return;
+ }
+ }
+ my $redirect;
+ if ($subdir ne '/') {
+ $subdir = &cleandir($subdir);
+ if (($subdir ne '') && (-d "$path/$subdir")) {
+ $path .= "/$subdir";
+ $url .= "/$subdir";
+ }
+ }
+ my $dest;
+ if ($newsubdir ne '') {
+ $newsubdir = &cleandir($newsubdir);
+ }
+ if ($newsubdir ne '') {
+ if (-d "$path/$newsubdir") {
+ $dest = "$path/$newsubdir/$filename";
+ } else {
+ my $dirok;
+ unless (-e "$path/$newsubdir") {
+ if (mkdir("$path/$newsubdir",02770)) {
+ if (chmod(02770,"$path/$newsubdir")) {
+ $dirok = 1;
+ }
+ }
+ }
+ if ($dirok) {
+ $dest = "$path/$newsubdir/$filename";
+ }
+ }
+ if (($dest ne '') && (!-e $dest)) {
+ $redirect = "$url/$newsubdir/$filename";
+ }
+ } else {
+ $dest = "$path/$filename";
+ if (($dest ne '') && (!-e $dest)) {
+ $redirect = "$url/$filename";
+ }
+ }
+ return $redirect;
+}
+
+sub cleandir {
+ my ($dir) = @_;
+ $dir =~ s/^\s+//;
+ $dir =~ s/\s+$//;
+ $dir =~ s/\.+//g;
+ $dir =~ s/[\#\?&%\":]//g;
+ return $dir;
+}
+
1;
__END__
+
+
+=head1 NAME
+
+Apache::londocs.pm
+
+=head1 SYNOPSIS
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=item %help=()
+
+Available help topics
+
+=item mapread()
+
+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
+
+=item authorhosts()
+
+Return hash with valid author names
+
+=item clean()
+
+=item dumpcourse()
+
+ Actually dump course
+
+=item group_import()
+
+ Imports the given (name, url) resources into the course
+ coursenum, coursedom, and folder must precede the list
+
+=item breadcrumbs()
+
+=item log_docs()
+
+=item docs_change_log()
+
+=item update_paste_buffer()
+
+=item print_paste_buffer()
+
+=item do_paste_from_buffer()
+
+=item do_buffer_empty()
+
+=item clear_from_buffer()
+
+=item get_newmap_url()
+
+=item dbcopy()
+
+=item uniqueness_check()
+
+=item contained_map_check()
+
+=item url_paste_fixups()
+
+=item apply_fixups()
+
+=item copy_dependencies()
+
+=item update_parameter()
+
+=item handle_edit_cmd()
+
+=item editor()
+
+=item process_file_upload()
+
+=item process_secondary_uploads()
+
+=item is_supplemental_title()
+
+=item entryline()
+
+=item tiehash()
+
+=item untiehash()
+
+=item checkonthis()
+
+check on this
+
+=item verifycontent()
+
+Verify Content
+
+=item devalidateversioncache() & checkversions()
+
+Check Versions
+
+=item mark_hash_old()
+
+=item is_hash_old()
+
+=item changewarning()
+
+=item init_breadcrumbs()
+
+Breadcrumbs for special functions
+
+=item create_list_elements()
+
+=item create_form_ul()
+
+=item startContentScreen()
+
+=item endContentScreen()
+
+=item supplemental_base()
+
+=item embedded_form_elems()
+
+=item embedded_destination()
+
+=item return_to_editor()
+
+=item decompression_info()
+
+=item decompression_phase_one()
+
+=item decompression_phase_two()
+
+=item remove_archive()
+
+=item generate_admin_menu()
+
+=item generate_edit_table()
+
+=item editing_js()
+
+=item history_tab_js()
+
+=item inject_data_js()
+
+=item dump_switchserver_js()
+
+=item resize_scrollbox_js()
+
+=item makedocslogform()
+
+=item makesimpleeditform()
+
+=back
+
+=cut