--- loncom/interface/londocs.pm 2014/10/24 00:20:09 1.587 +++ loncom/interface/londocs.pm 2015/06/09 21:22:56 1.594 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.587 2014/10/24 00:20:09 raeburn Exp $ +# $Id: londocs.pm,v 1.594 2015/06/09 21:22:56 damieng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -977,7 +977,7 @@ sub docs_change_log { sub update_paste_buffer { my ($coursenum,$coursedom,$folder) = @_; - my (@possibles,%removals,%cuts); + my (@possibles,%removals,%cuts,$output); if ($env{'form.multiremove'}) { $env{'form.multiremove'} =~ s/,$//; map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'}); @@ -1045,10 +1045,12 @@ sub update_paste_buffer { next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url})); my ($suffix,$errortxt,$locknotfreed) = &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste'); - push(@newpaste,$suffix); - if ($locknotfreed) { - return $locknotfreed; - last; + if ($suffix ne '') { + push(@newpaste,$suffix); + } else { + if ($locknotfreed) { + return $locknotfreed; + } } if (&is_supplemental_title($title)) { &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title}); @@ -1082,13 +1084,17 @@ sub update_paste_buffer { } } } + if ($locknotfreed) { + $output = $locknotfreed; + last; + } } if (@newpaste) { $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste)); } &Apache::lonnet::appenv(\%addtoenv); delete($env{'form.markcopy'}); - return; + return $output; } sub recurse_uploaded_maps { @@ -1191,10 +1197,14 @@ sub print_paste_buffer { $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL')); $icon .= '/navmap.folder.closed.gif'; } + my $title = $env{'docs.markedcopy_title_'.$suffix}; + if ($title eq '') { + ($title) = ($url =~ m{/([^/]+)$}); + } $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'. ': '. &Apache::loncommon::parse_supplemental_title( - &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix})); + &LONCAPA::map::qtescape($title)); } $pasteitems .= '<div class="LC_left_float">'; my ($options,$onclick); @@ -1343,29 +1353,34 @@ sub supp_pasteable { } sub paste_popup_js { - my %lt = &Apache::lonlocal::texthash( + my %html_js_lt = &Apache::lonlocal::texthash( show => 'Show Options', hide => 'Hide Options', + ); + my %js_lt = &Apache::lonlocal::texthash( none => 'No items selected from clipboard.', ); + &html_escape(\%html_js_lt); + &js_escape(\%html_js_lt); + &js_escape(\%js_lt); return <<"END"; function showPasteOptions(suffix) { document.getElementById('pasteoptions_'+suffix).style.display='block'; - document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$lt{'hide'}</a>'; + document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>'; return; } function hidePasteOptions(suffix) { document.getElementById('pasteoptions_'+suffix).style.display='none'; - document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$lt{'show'}</a>'; + document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>'; return; } function showOptions(caller,suffix) { if (document.getElementById('pasteoptionstext_'+suffix)) { if (caller.checked) { - document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$lt{'show'}</a>'; + document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>'; } else { document.getElementById('pasteoptionstext_'+suffix).innerHTML =''; } @@ -1394,7 +1409,7 @@ function validateClipboard() { if (numchk > 0) { return true; } else { - alert("$lt{'none'}"); + alert("$js_lt{'none'}"); return false; } } @@ -2603,26 +2618,44 @@ sub update_parameter { } return $haschanges; } else { - return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/); + my $haschanges = 0; + return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/); my $which = $env{'form.changeparms'}; my $idx = $env{'form.setparms'}; + my $oldvalue = 0; + my $newvalue = 0; + my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0]; + if ($which eq 'randompick') { + if ($current =~ /^(\d+)$/) { + $oldvalue = $1; + } + } elsif ($current =~ /^yes$/i) { + $oldvalue = 1; + } if ($env{'form.'.$which.'_'.$idx}) { - my $value = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx} - : 'yes'; - &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value, - $parameter_type{$which}); - &remember_parms($idx,$which,'set',$value); - } else { - &LONCAPA::map::delparameter($idx,'parameter_'.$which); - - &remember_parms($idx,$which,'del'); + $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx} + : 1; } - return 1; + if ($oldvalue ne $newvalue) { + $haschanges = 1; + if ($newvalue) { + my $storeval = 'yes'; + if ($which eq 'randompick') { + $storeval = $newvalue; + } + &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval, + $parameter_type{$which}); + &remember_parms($idx,$which,'set',$storeval); + } else { + &LONCAPA::map::delparameter($idx,'parameter_'.$which); + &remember_parms($idx,$which,'del'); + } + } + return $haschanges; } } - sub handle_edit_cmd { my ($coursenum,$coursedom) =@_; if ($env{'form.cmd'} eq '') { @@ -2714,7 +2747,7 @@ sub editor { &snapshotbefore(); if (&update_parameter()) { - ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container); + ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1); return $errtext if ($fatal); } @@ -2778,7 +2811,7 @@ sub editor { # Rename, cut, copy or remove a single resource if (&handle_edit_cmd()) { my $contentchg; - if ($env{'form.cmd'} =~ m{^(del|cut)_}) { + if ($env{'form.cmd'} =~ m{^(remove|cut)_}) { $contentchg = 1; } ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg); @@ -3859,9 +3892,19 @@ sub new_timebased_suffix { '<div class="LC_error">'. &mt('There was a problem removing a lockfile.').' '; if ($type eq 'paste') { - &mt('This will prevent use of the paste buffer until th next log-in.'); + if ($freedlock eq 'nolock') { + $locknotfreed = + '<div class="LC_error">'. + &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '. + + &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.'); + } else { + $locknotfreed .= + &mt('This will prevent addition of items to the clipboard until your next log-in.'); + } } elsif ($type eq 'map') { - &mt('This will prevent creation of additional folders or composite pages in this course.'); + $locknotfreed .= + &mt('This will prevent creation of additional folders or composite pages in this course.'); } elsif ($type eq 'smppg') { $locknotfreed .= &mt('This will prevent creation of additional simple pages in this course.'); @@ -5756,7 +5799,7 @@ END sub editing_js { my ($udom,$uname,$supplementalflag) = @_; - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', p_mnp => 'Name of New Page', @@ -5794,7 +5837,7 @@ sub editing_js { noch => 'No changes to settings specified.', noac => 'No actions selected.', ); - + &js_escape(\%js_lt); my $crstype = &Apache::loncommon::course_type(); my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"'); my $main_container_page; @@ -5816,6 +5859,7 @@ sub editing_js { if (&Apache::lonnet::is_on_map($res)) { $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='. &HTML::Entities::encode($caller,'<>&"'); + $backtourl = &Apache::loncommon::escape_single($backtourl); } else { $backtourl = '/adm/navmaps'; } @@ -5838,7 +5882,7 @@ sub editing_js { return <<ENDNEWSCRIPT; function makenewfolder(targetform,folderseq) { - var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}'); + var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}'); if (foldername) { targetform.importdetail.value=escape(foldername)+"="+folderseq; targetform.submit(); @@ -5846,7 +5890,7 @@ function makenewfolder(targetform,folder } function makenewpage(targetform,folderseq) { - var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}'); + var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}'); if (pagename) { targetform.importdetail.value=escape(pagename)+"="+folderseq; targetform.submit(); @@ -5854,7 +5898,7 @@ function makenewpage(targetform,folderse } function makeexamupload() { - var title=prompt('$lt{"p_mxu"}'); + var title=prompt('$js_lt{"p_mxu"}'); if (title) { this.document.forms.newexamupload.importdetail.value= escape(title)+'=/res/lib/templates/examupload.problem'; @@ -5863,7 +5907,7 @@ function makeexamupload() { } function makesmppage() { - var title=prompt('$lt{"p_msp"}'); + var title=prompt('$js_lt{"p_msp"}'); if (title) { this.document.forms.newsmppg.importdetail.value= escape(title)+'=/adm/$udom/$uname/new/smppg'; @@ -5872,7 +5916,7 @@ function makesmppage() { } function makewebpage(type) { - var title=prompt('$lt{"p_mwp"}'); + var title=prompt('$js_lt{"p_mwp"}'); var formname; if (type == 'supp') { formname = this.document.forms.supwebpage; @@ -5887,7 +5931,7 @@ function makewebpage(type) { } function makesmpproblem() { - var title=prompt('$lt{"p_msb"}'); + var title=prompt('$js_lt{"p_msb"}'); if (title) { this.document.forms.newsmpproblem.importdetail.value= escape(title)+'=/res/lib/templates/simpleproblem.problem'; @@ -5896,7 +5940,7 @@ function makesmpproblem() { } function makedropbox() { - var title=prompt('$lt{"p_mdb"}'); + var title=prompt('$js_lt{"p_mdb"}'); if (title) { this.document.forms.newdropbox.importdetail.value= escape(title)+'=/res/lib/templates/DropBox.problem'; @@ -5905,7 +5949,7 @@ function makedropbox() { } function makebulboard() { - var title=prompt('$lt{"p_mbb"}'); + var title=prompt('$js_lt{"p_mbb"}'); if (title) { this.document.forms.newbul.importdetail.value= escape(title)+'=/adm/$udom/$uname/new/bulletinboard'; @@ -5914,20 +5958,20 @@ function makebulboard() { } function makeabout() { - var user=prompt("$lt{'p_mab'}"); + var user=prompt("$js_lt{'p_mab'}"); if (user) { var comp=new Array(); comp=user.split(':'); if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) { if ((comp[0]) && (comp[1])) { this.document.forms.newaboutsomeone.importdetail.value= - '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme'; + '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme'; this.document.forms.newaboutsomeone.submit(); } else { - alert("$lt{'p_mab_alrt1'}"); + alert("$js_lt{'p_mab_alrt1'}"); } } else { - alert("$lt{'p_mab_alrt2'}"); + alert("$js_lt{'p_mab_alrt2'}"); } } } @@ -5965,11 +6009,11 @@ function toggleMap(caller) { function makeims(imsform) { if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) { - alert("$lt{'imsfile'}"); + alert("$js_lt{'imsfile'}"); return; } if (imsform.source.selectedIndex == 0) { - alert("$lt{'imscms'}"); + alert("$js_lt{'imscms'}"); return; } newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes"); @@ -5977,7 +6021,7 @@ function makeims(imsform) { } function changename(folderpath,index,oldtitle) { -var title=prompt('$lt{"p_chn"}',oldtitle); +var title=prompt('$js_lt{"p_chn"}',oldtitle); if (title) { this.document.forms.renameform.markcopy.value=''; this.document.forms.renameform.title.value=title; @@ -6001,7 +6045,7 @@ function updatePick(targetform,index,cal picknumtext = document.getElementById('randompicknum_'+index); } if (pickitem.checked) { - var picknum=prompt('$lt{"rpck"}',picknumitem.value); + var picknum=prompt('$js_lt{"rpck"}',picknumitem.value); if (picknum == '' || picknum == null) { if (caller == 'check') { pickitem.checked=false; @@ -6189,14 +6233,14 @@ function checkForSubmit(targetform,param targetform.markcopy.value=idx+':'+param; targetform.copyfolder.value=folder+'.'+container; if (param == 'remove') { - if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) { + if (skip_confirm || confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) { targetform.markcopy.value=''; targetform.copyfolder.value=''; targetform.submit(); } } if (param == 'cut') { - if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) { + if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) { targetform.submit(); return; } @@ -6375,7 +6419,7 @@ function togglePick(caller,value) { } document.getElementById('multi'+caller).style.display=disp; if (value == 1) { - document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>'; + document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; } else { document.getElementById('more'+caller).innerHTML = ''; } @@ -6401,10 +6445,10 @@ function togglePick(caller,value) { function toggleCheckUncheck(caller,more) { if (more == 1) { - document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$lt{'less'}</a>'; + document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>'; document.getElementById('allfields'+caller).style.display='block'; } else { - document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>'; + document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; document.getElementById('allfields'+caller).style.display='none'; } resize_scrollbox('contentscroll','1','1'); @@ -6560,12 +6604,12 @@ function checkSubmits() { if (numchanges > 0) { if ((cutwarnings > 0) || (remwarnings > 0)) { if (remwarnings > 0) { - if (!confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr3a"} '+remwarnings+' $lt{"p_rmr3b"}')) { + if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) { return false; } } if (cutwarnings > 0) { - if (!confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr3a"} '+cutwarnings+' $lt{"p_ctr3b"}')) { + if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) { return false; } } @@ -6581,12 +6625,12 @@ function checkSubmits() { } } if ((dosettings == 1) && (doactions == 1)) { - alert("$lt{'noor'}"); + alert("$js_lt{'noor'}"); } else { if (dosettings == 1) { - alert("$lt{'noch'}"); + alert("$js_lt{'noch'}"); } else { - alert("$lt{'noac'}"); + alert("$js_lt{'noac'}"); } } return false; @@ -6701,13 +6745,19 @@ ENDINJECT sub dump_switchserver_js { my @hosts = @_; - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( dump => '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"; <script type="text/javascript"> @@ -6748,7 +6798,7 @@ ENDSWJS function dump_needs_switchserver(url) { if (url!='' && url!= null) { - if (confirm("$lt{'dump'}\\n$lt{'swit'}")) { + if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) { go(url); } } @@ -6759,13 +6809,13 @@ function choose_switchserver_window() { newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes') newWindow.document.open(); newWindow.document.writeln('$startpage'); - newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+ - '<p>$lt{'yone'}<\\/p>\\n'+ - '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+ + newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+ + '<p>$html_js_lt{'yone'}<\\/p>\\n'+ + '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+ '<form name="setserver" method="post" action="" \\/>\\n'+ '$hostpicker\\n'+ '<br \\/><br \\/>\\n'+ - '<input type="button" name="makeswitch" value="$lt{'swit'}" '+ + '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+ 'onclick="write_switchserver();" \\/>\\n'+ '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n'); newWindow.document.writeln('$endpage');