--- loncom/interface/londocs.pm 2020/07/19 14:25:35 1.484.2.85.2.3 +++ loncom/interface/londocs.pm 2017/04/25 22:18:59 1.624 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.85.2.3 2020/07/19 14:25:35 raeburn Exp $ +# $Id: londocs.pm,v 1.624 2017/04/25 22:18:59 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,11 +43,13 @@ use Apache::lonnavdisplay(); use Apache::lonextresedit(); use Apache::lontemplate(); use Apache::lonsimplepage(); -use Apache::loncourserespicker(); +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); @@ -233,7 +235,7 @@ ENDJS } else { &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles, 'dumpdocs',$cdom,$cnum); - } + } my @todump = &Apache::loncommon::get_env_multiple('form.archive'); my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages, %newcontent,%has_simpleprobs); @@ -244,7 +246,7 @@ ENDJS if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) { $tocopy{$1} = $name; $display{$item} = $1; - $lookup{$1} = $item; + $lookup{$1} = $item; } elsif ($res eq 'lib/templates/simpleproblem.problem') { $simpleproblems{$item} = { symb => $resources{$item}, @@ -344,7 +346,7 @@ $contents{content}.' </div>'; } if ($contents{webreferences}) { - $content .= ' + $content .= ' <div class="LC_Box"> <h4 class="LC_hcell">'.&mt('Web References').'</h4>'. $contents{webreferences}.' @@ -354,10 +356,10 @@ $contents{webreferences}.' </body> </html> '; - $newcontent{'/'.$simplepages{$item}{res}} = $content; + $newcontent{'/'.$simplepages{$item}{res}} = $content; } } - foreach my $item (keys(%tocopy)) { + foreach my $item (keys(%tocopy)) { unless ($item=~/\.(sequence|page)$/) { my $currurlpath = $prefix.$item; my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath); @@ -388,39 +390,39 @@ $contents{webreferences}.' if ($simpleproblems{$num}) { $newfilename=$title.'/'.$simpleproblems{$num}{'name'}; } else { - $newfilename=$title.'/'.$replacehash{$item}; + $newfilename=$title.'/'.$replacehash{$item}; } - $newfilename=~s/\.(\w+)$//; - my $ext=$1; - $newfilename=&clean($newfilename); - $newfilename.='.'.$ext; - my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); + $newfilename=~s/\.(\w+)$//; + my $ext=$1; + $newfilename=&clean($newfilename); + $newfilename.='.'.$ext; + my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); if ($newrelpath ne $replacehash{$item}) { $replacehash{$item} = $newrelpath; } - my @dirs=split(/\//,$newfilename); - my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca"; - my $makepath=$path; - my $fail; + my @dirs=split(/\//,$newfilename); + my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca"; + my $makepath=$path; + my $fail; my $origin; - for (my $i=0;$i<$#dirs;$i++) { - $makepath.='/'.$dirs[$i]; - unless (-e $makepath) { - unless(mkdir($makepath,0755)) { + for (my $i=0;$i<$#dirs;$i++) { + $makepath.='/'.$dirs[$i]; + unless (-e $makepath) { + unless(mkdir($makepath,0755)) { $fail = &mt('Directory creation failed.'); } - } - } + } + } if ($i == 0) { - $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: '; + $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: '; } else { $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '. '<span class="LC_fontsize_small" style="font-weight: bold;">'. &mt('(dependency)').'</span>: '; } if (-e $path.'/'.$newfilename) { - $fail = &mt('Destination already exists -- not overwriting.'); - } else { + $fail = &mt('Destination already exists -- not overwriting.'); + } else { if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) { if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) || ($item =~ /^simpleproblem_/)) { @@ -442,18 +444,18 @@ $contents{webreferences}.' while (my $token = $parser->get_token) { if ($token->[0] eq 'S') { if (($token->[1] eq 'resource') && - ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && + ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && ($changes{$token->[2]->{'id'}})) { my $id = $token->[2]->{'id'}; $updatedcontent .= '<'.$token->[1]; foreach my $attrib (@{$token->[3]}) { - next unless ($attrib =~ /^(src|type|title|id)$/); + next unless ($attrib =~ /^(src|type|title|id)$/); if ($attrib eq 'src') { - my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); + my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); if ($file) { $updatedcontent .= ' '.$attrib.'="'.$file.'"'; } else { - $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; + $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; } } else { $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; @@ -468,36 +470,36 @@ $contents{webreferences}.' } } print $fh $updatedcontent; - } else { - print $fh &Apache::lonclonecourse::rewritefile( + } else { + print $fh &Apache::lonclonecourse::rewritefile( &Apache::lonclonecourse::readfile($env{'request.course.id'},$item), - (%replacehash,$crs => '') - ); + (%replacehash,$crs => '') + ); } } else { - print $fh + print $fh &Apache::lonclonecourse::readfile($env{'request.course.id'},$item); - } + } } else { - $fail = &mt('Source does not exist.'); + $fail = &mt('Source does not exist.'); } } $fh->close(); - } else { - $fail = &mt('Could not write to destination.'); + } else { + $fail = &mt('Could not write to destination.'); } - } + } my $text; - if ($fail) { + if ($fail) { $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>'; - } else { + } else { $text = '<span class="LC_success">'.&mt('ok').'</span>'; } if ($i == 0) { $result .= $text; } else { $depresult .= $text.'</li>'; - } + } } $r->print($result); if ($depresult) { @@ -514,63 +516,63 @@ $contents{webreferences}.' $r->rflush(); my ($preamble,$formname); $formname = 'dumpdoc'; - unless ($home==1) { - $preamble = '<div class="LC_left_float">'. - '<fieldset><legend>'. + unless ($home==1) { + $preamble = '<div class="LC_left_float">'. + '<fieldset><legend>'. &mt('Select the Authoring Space'). '</legend><select name="authorspace">'; - } + } my @orderspaces = (); - foreach my $key (sort(keys(%outhash))) { + foreach my $key (sort(keys(%outhash))) { if ($key=~/^home_(.+)$/) { if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) { unshift(@orderspaces,$1); } else { push(@orderspaces,$1); } - } + } } if ($home>1) { $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>'; } foreach my $user (@orderspaces) { - if ($home==1) { - $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />'; - } else { - $preamble .= '<option value="'.$user.'">'.$user.' - '. - &Apache::loncommon::plainname(split(/\:/,$user)).'</option>'; - } - } - unless ($home==1) { - $preamble .= '</select></fieldset></div>'."\n"; - } - my $title=$origcrsdata{'description'}; - $title=~s/[\/\s]+/\_/gs; - $title=&clean($title); - $preamble .= '<div class="LC_left_float">'. + if ($home==1) { + $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />'; + } else { + $preamble .= '<option value="'.$user.'">'.$user.' - '. + &Apache::loncommon::plainname(split(/\:/,$user)).'</option>'; + } + } + unless ($home==1) { + $preamble .= '</select></fieldset></div>'."\n"; + } + my $title=$origcrsdata{'description'}; + $title=~s/[\/\s]+/\_/gs; + $title=&clean($title); + $preamble .= '<div class="LC_left_float">'. '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'. '<input type="text" size="50" name="authorfolder" value="'. $title.'" />'. '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n"; my %uploadedfiles; - &tiehash(); - foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { - my ($ext)=($file=~/\.(\w+)$/); + &tiehash(); + foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { + my ($ext)=($file=~/\.(\w+)$/); # FIXME Check supplemental here - my $title=$hash{'title_'.$hash{ - 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}}; - if (!$title) { - $title=$file; - } else { - $title=~s|/|_|g; - } - $title=~s/\.(\w+)$//; - $title=&clean($title); - $title.='.'.$ext; -# $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>" + my $title=$hash{'title_'.$hash{ + 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}}; + if (!$title) { + $title=$file; + } else { + $title=~s|/|_|g; + } + $title=~s/\.(\w+)$//; + $title=&clean($title); + $title.='.'.$ext; +# $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>" $uploadedfiles{$file} = $title; - } - &untiehash(); + } + &untiehash(); $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef, undef,undef,$preamble,$home,\%uploadedfiles)); } @@ -601,16 +603,16 @@ sub recurse_html { } else { $relfile = $dependency; $depurl = $currurlpath; - $depurl =~ s{[^/]+$}{}; + $depurl =~ s{[^/]+$}{}; $depurl .= $dependency; - ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); + ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); } next if ($relfile eq ''); my $newname = $replacehash->{$container}; $newname =~ s{[^/]+$}{}; $replacehash->{$newcontainer} = $newname.$relfile; $deps->{$item}{$newcontainer} = 1; - my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$}); + my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$}); my $depfile = &Apache::lonnet::filelocation('',$depurl); my $type = $mm->checktype_filename($depfile); if ($type eq 'text/html') { @@ -652,7 +654,7 @@ sub group_import { } } if ($url) { - if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) { + if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) { $url = $1; my $marker = $2; my $info = $3; @@ -675,9 +677,11 @@ sub group_import { if (ref($ltitoolsref) eq 'HASH') { my @deleted; if (ref($ltitoolsref->{$toolid}) eq 'HASH') { + if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) { + $url =~ s/exttool$/exttools/; + } $toolhash{'id'} = $toolid; - if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') || - ($toolhash{'target'} eq 'window')) { + if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) { if ($toolhash{'target'} eq 'window') { foreach my $item ('width','height') { $toolhash{$item} =~ s/^\s+//; @@ -695,7 +699,7 @@ sub group_import { } elsif ($residx) { $toolhash{'target'} = $toolsettings{'target'}; if ($toolhash{'target'} eq 'window') { - foreach my $item ('width','height') { + foreach my $item ('width','height') { $toolhash{$item} = $toolsettings{$item}; } } @@ -715,15 +719,6 @@ sub group_import { } } } - } elsif ($toolhash{'target'} eq 'tab') { - foreach my $item ('width','height') { - delete($toolhash{$item}); - if ($residx) { - if ($toolsettings{$item}) { - push(@deleted,$item); - } - } - } } if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') { foreach my $item ('label','title','linktext','explanation') { @@ -753,7 +748,7 @@ sub group_import { if ($putres eq 'ok') { if (@deleted) { &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum); - } + } } } } @@ -769,8 +764,8 @@ sub group_import { $donechk = 1; } if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) { - &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap, - \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps); + &contained_map_check($url,$folder,\%removefrommap,\%removeparam, + \%addedmaps,\%hierarchy,\%titles,$allmaps); $importuploaded = 1; } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) { next if ($allmaps->{$url}); @@ -810,7 +805,7 @@ $initialtext </html> END $env{'form.output'}=$newhtml; - my $result = + my $result = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output', "$filepath/$residx/$fname.html"); @@ -835,7 +830,7 @@ END removefrommap => \%removefrommap, removeparam => \%removeparam, ); - my ($result,$msgsarray,$lockerror) = + my ($result,$msgsarray,$lockerror) = &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated); if (keys(%import_errors) > 0) { $fixuperrors = @@ -936,12 +931,12 @@ sub log_docs { sub docs_change_log { my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_; my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/); - my $navmap; + my $navmap; my $js = '<script type="text/javascript">'."\n". '// <![CDATA['."\n". &Apache::loncommon::display_filter_js('docslog')."\n". &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag, - $coursedom,$coursenum,'',$canedit,'',\$navmap)."\n". + $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n". &history_tab_js()."\n". &Apache::lonratedt::editscript('simple')."\n". '// ]]>'."\n". @@ -1166,19 +1161,13 @@ sub update_paste_buffer { # Construct identifiers for current contents of user's paste buffer if (@currpaste) { foreach my $suffix (@currpaste) { - my $cid = $env{'docs.markedcopy_crs_'.$suffix}; - my $url = $env{'docs.markedcopy_url_'.$suffix}; - my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; - if (($cid =~ /^$match_domain(?:_)$match_courseid$/) && - ($url ne '')) { - if ($url eq '/res/lib/templates/simpleproblem.problem') { - $pasteurls{$cid.'_'.$mapidx} = 1; - } elsif ($url =~ m{^/res/$match_domain/$match_username/}) { - $pasteurls{$url} = 1; - } else { - $pasteurls{$cid.'_'.$url} = 1; - } - } + my $cid = $env{'docs.markedcopy_crs_'.$suffix}; + my $url = $env{'docs.markedcopy_url_'.$suffix}; + my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; + if (($cid =~ /^$match_domain(?:_)$match_courseid$/) && + ($url ne '')) { + $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1; + } } } @@ -1187,7 +1176,7 @@ sub update_paste_buffer { my @pathitems = split(/\&/,$env{'form.folderpath'}); my @folderconf = split(/\:/,$pathitems[-1]); - my $ispage = $folderconf[5]; + my $ispage = $folderconf[4]; foreach my $item (@possibles) { my ($orderidx,$cmd) = split(/:/,$item); @@ -1200,13 +1189,7 @@ sub update_paste_buffer { $env{'form.folderpath'},\%curr_groups); next if ($denied{'copy'}); $url=~s{http(:|:)//https(:|:)//}{https$2//}; - if ($url eq '/res/lib/templates/simpleproblem.problem') { - next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx})); - } elsif ($url =~ m{^/res/$match_domain/$match_username/}) { - next if (exists($pasteurls{$url})); - } else { - next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url})); - } + next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx})); my ($suffix,$errortxt,$locknotfreed) = &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste'); if ($suffix ne '') { @@ -1233,8 +1216,8 @@ sub update_paste_buffer { $subdir = $prefix; } my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps); - &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap, - \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps); + &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps, + \%hierarchy,\%titles,\%allmaps); if (ref($hierarchy{$url}) eq 'HASH') { my ($nested,$nestednames); &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames); @@ -1303,7 +1286,7 @@ sub print_paste_buffer { next if ($suffix =~ /\D/); my $cid = $env{'docs.markedcopy_crs_'.$suffix}; my $url = $env{'docs.markedcopy_url_'.$suffix}; - my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; + my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; if (($cid =~ /^$match_domain\_$match_courseid$/) && ($url ne '')) { $clipboardcount ++; @@ -1312,7 +1295,7 @@ sub print_paste_buffer { my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1]; if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) { $is_external = 1; - } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) { + } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) { $is_exttool = 1; } if ($folder =~ /^supplemental/) { @@ -1346,34 +1329,26 @@ sub print_paste_buffer { $is_uploaded_map = 1; } } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) || - ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) { + ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) { if ($cid ne $env{'request.course.id'}) { my ($srcdom,$srcnum) = split(/_/,$cid); if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) { - if (($is_exttool) && ($srcdom ne $coursedom)) { - $canpaste = 0; - $nopaste = &mt('Paste from another domain unavailable.'); - } else { - $othercrs = '<br />'.&mt('(from another course)'); - } + $othercrs = '<br />'.&mt('(from another course)'); } else { $canpaste = 0; $nopaste = &mt('Paste from another course unavailable.'); - } + } } } if ($canpaste) { push(@pasteable,$suffix); - } + } } my $buffer; - if ($is_external) { + if (($is_external) || ($is_exttool)) { $buffer = &mt('External Resource').': '. &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('. &LONCAPA::map::qtescape($url).')'; - } elsif ($is_exttool) { - $buffer = &mt('External Tool').': '. - &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}); } else { my $icon = &Apache::loncommon::icon($extension); if ($extension eq 'sequence' && @@ -1426,7 +1401,7 @@ sub print_paste_buffer { my $value = &mt('Paste to current folder'); if ($container eq 'page') { $value = &mt('Paste to current page'); - } + } $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2); } $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2); @@ -1531,7 +1506,7 @@ sub supp_pasteable { ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) || ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) || ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) || - ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) { + ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) { return 1; } return; @@ -1603,7 +1578,7 @@ function checkClipboard() { if (document.pasteform.pasting.length > 1) { for (var i=0; i<document.pasteform.pasting.length; i++) { document.pasteform.pasting[i].checked = true; - } + } } return; } @@ -1653,13 +1628,13 @@ sub do_paste_from_buffer { return(); } - my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate, + my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate, %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult); foreach my $suffix (@topaste) { my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix}); my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); - my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); + my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); # Supplemental content may only include certain types of content # Early out if pasted content is not supported in Supplemental area if ($folder =~ /^supplemental/) { @@ -1681,24 +1656,6 @@ sub do_paste_from_buffer { } $srcdom{$suffix} = $srcd; $srcnum{$suffix} = $srcn; - } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) { - my ($srcd,$srcn) = split(/_/,$cid); -# When paste buffer was populated using an active role in a different course -# check for mdc privilege in the course from which the resource was pasted - if (($srcd ne $coursedom) || ($srcn ne $coursenum)) { - unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) { - $notincrs{$suffix} = 1; - next; - } - } -# When buffer was populated using an active role in a different course -# disallow pasting of External Tool if course is in a different domain. - if ($srcd ne $coursedom) { - $notindom{$suffix} = 1; - next; - } - $srcdom{$suffix} = $srcd; - $srcnum{$suffix} = $srcn; } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) || ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) { my ($srcd,$srcn) = split(/_/,$cid); @@ -1713,7 +1670,7 @@ sub do_paste_from_buffer { $srcdom{$suffix} = $srcd; $srcnum{$suffix} = $srcn; } - $srcmapidx{$suffix} = $mapidx; + $srcmapidx{$suffix} = $mapidx; push(@dopaste,$suffix); if ($url=~/\.(page|sequence)$/) { $is_map{$suffix} = 1; @@ -1723,7 +1680,7 @@ sub do_paste_from_buffer { my $oldprefix = $1; # When pasting content from Main Content to Supplemental Content and vice versa # URLs will contain different paths (which depend on whether pasted item is -# a folder/page or a document). +# a folder/page or a document). if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) { $prefixchg{$suffix} = 'docstosupp'; } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) { @@ -1763,7 +1720,6 @@ sub do_paste_from_buffer { %msgs = &Apache::lonlocal::texthash ( notinsupp => 'Paste failed: content type is not supported within Supplemental Content', notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.', - notindom => 'Paste failed: Item is an external tool from a course in a different donain.', duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.', ); @@ -1792,7 +1748,14 @@ sub do_paste_from_buffer { # Retrieve information about all course maps in main content area my $allmaps = {}; - my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk); + if ($folder =~ /^default/) { + $allmaps = + &Apache::loncommon::allmaps_incourse($coursedom,$coursenum, + $env{"course.$env{'request.course.id'}.home"}, + $env{'request.course.id'}); + } + + my (@toclear,%mapurls,%lockerrs,%msgerrs,%results); # Loop over the items to paste foreach my $suffix (@dopaste) { @@ -1805,21 +1768,13 @@ sub do_paste_from_buffer { } my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix}); my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}); - my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); + my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); my $oldurl = $url; if ($is_map{$suffix}) { # If pasting a map, check if map contains other maps my (%hierarchy,%titles); - if (($folder =~ /^default/) && (!$donechk)) { - $allmaps = - &Apache::loncommon::allmaps_incourse($coursedom,$coursenum, - $env{"course.$env{'request.course.id'}.home"}, - $env{'request.course.id'}); - $donechk = 1; - } - &contained_map_check($url,$folder,$coursenum,$coursedom, - \%removefrommap,\%removeparam,\%addedmaps, - \%hierarchy,\%titles,$allmaps); + &contained_map_check($url,$folder,\%removefrommap,\%removeparam, + \%addedmaps,\%hierarchy,\%titles,$allmaps); if ($url=~ m{^/uploaded/}) { my $newurl; unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') { @@ -1858,7 +1813,7 @@ sub do_paste_from_buffer { $coursenum,$srcdom{$suffix},$srcnum{$suffix}, $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies, \%zombies,\%params,\%mapmoves,\%mapchanges, - \%tomove,\%newsubdir,\%newurls,\%resdatacopy); + \%tomove,\%newsubdir,\%newurls,\%resdatacopy); } } elsif ($url=~m {^/res/}) { # published map can only exist once, so remove from paste buffer when done @@ -1872,9 +1827,9 @@ sub do_paste_from_buffer { } } } - if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) { + if ($url=~ m{/(bulletinboard|smppg)$}) { my $prefix = $1; - my $fromothercrs; + my $fromothercrs; #need to copy the db contents to a new one, unless this is a move. my %info = ( src => $url, @@ -1900,8 +1855,6 @@ sub do_paste_from_buffer { $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext; } elsif ($prefix eq 'bulletinboard') { $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext; - } elsif ($prefix eq 'ext.tool') { - $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext; } $results{$suffix} = $result; $msgerrs{$suffix} = $msg; @@ -1909,7 +1862,7 @@ sub do_paste_from_buffer { next; } if ($lockerr{$prefix}) { - $lockerrs{$suffix} = $lockerr{$prefix}; + $lockerrs{$suffix} = $lockerr{$prefix}; } } } @@ -1948,7 +1901,7 @@ sub do_paste_from_buffer { if ($newdocsdir eq '') { $newdocsdir = 'default'; } - if (($prefixchg{$suffix}) || + if (($prefixchg{$suffix}) || ($srcdom{$suffix} ne $coursedom) || ($srcnum{$suffix} ne $coursenum) || ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) { @@ -1985,8 +1938,8 @@ sub do_paste_from_buffer { } } -# Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update -# resourcedata for simpleproblems copied from another course +# Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update +# resourcedata for simpleproblems copied from another course unless ($allresult eq 'fail') { my %updated = ( rewrites => \%rewrites, @@ -2161,12 +2114,9 @@ sub dbcopy { my ($url,$result,$errtext); if (ref($dbref) eq 'HASH') { $url = $dbref->{'src'}; - if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) { + if ($url =~ m{/(smppg|bulletinboard)$}) { my $prefix = $1; - if ($prefix eq 'ext.tool') { - $prefix = 'exttool'; - } - if (($dbref->{'cdom'} =~ /^$match_domain$/) && + if (($dbref->{'cdom'} =~ /^$match_domain$/) && ($dbref->{'cnum'} =~ /^$match_courseid$/)) { my $db_name; my $marker = (split(m{/},$url))[4]; @@ -2176,8 +2126,6 @@ sub dbcopy { &Apache::lonsimplepage::get_db_name($url,$marker, $dbref->{'cdom'}, $dbref->{'cnum'}); - } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) { - $db_name = 'exttool_'.$marker; } else { $db_name = 'bulletinpage_'.$marker; } @@ -2188,8 +2136,6 @@ sub dbcopy { if (!$suffix) { if ($prefix eq 'smppg') { $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url); - } elsif ($prefix eq 'exttool') { - $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url); } else { $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url); } @@ -2210,7 +2156,7 @@ sub dbcopy { my $content = &Apache::lonnet::getfile($photo); unless ($content eq '-1') { $env{'form.'.$suffix.'.photourl'} = $content; - $newphoto = + $newphoto = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname"); delete($env{'form.'.$suffix.'.photourl'}); } @@ -2223,7 +2169,7 @@ sub dbcopy { $result=&Apache::lonnet::put($db_name,\%contents, $coursedom,$coursenum); if ($result eq 'ok') { - $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x; + $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x; } } if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) { @@ -2233,9 +2179,6 @@ sub dbcopy { if ($prefix eq 'smppg') { $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional simple pages in this course.'); - } elsif ($prefix eq 'exttool') { - $lockerrorsref->{$prefix} .= - ' '.&mt('This will prevent addition of more external tools to this course.'); } else { $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.'); } @@ -2282,9 +2225,7 @@ sub copy_templated_files { my @simpleprobqtypes = qw(radio option string essay numerical); my $qtype=$srcparms{$srcprefix.'questiontype'}; if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) { - my %newdata = ( - $newprefix.'questiontype' => $qtype, - ); + my %newdata; foreach my $type (@simpleprobqtypes) { if ($type eq $qtype) { $newdata{"$weightprefix.$type.weight"}=1; @@ -2367,8 +2308,8 @@ sub uniqueness_check { } sub contained_map_check { - my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps, - $hierarchy,$titles,$allmaps) = @_; + my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles, + $allmaps) = @_; my $content = &Apache::lonnet::getfile($url); unless ($content eq '-1') { my $parser = HTML::TokeParser->new(\$content); @@ -2397,8 +2338,7 @@ sub contained_map_check { $addedmaps->{$ressrc} = [$url]; } } - &contained_map_check($ressrc,$folder,$coursenum,$coursedom, - $removefrommap,$removeparam, + &contained_map_check($ressrc,$folder,$removefrommap,$removeparam, $addedmaps,$hierarchy,$titles,$allmaps); } } elsif ($token->[1] eq 'param') { @@ -2450,7 +2390,7 @@ sub url_paste_fixups { } next if ($token->[2]->{'type'} eq 'external'); if ($token->[2]->{'type'} eq 'zombie') { - next if ($skip); + next if ($skip); $zombies->{$oldurl}{$id} = $ressrc; $changed = 1; } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) { @@ -2731,7 +2671,9 @@ sub apply_fixups { } } if (ref($resdatacopy{$key}) eq 'HASH') { - my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer); + if ($newsubdir{$key}) { + + } foreach my $idx (keys(%{$resdatacopy{$key}})) { if (ref($resdatacopy{$key}{$idx}) eq 'HASH') { my $srcurl = $resdatacopy{$key}{$idx}{'src'}; @@ -2741,18 +2683,15 @@ sub apply_fixups { ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) { my $srcdom = $resdatacopy{$key}{$idx}{'cdom'}; my $srcnum = $resdatacopy{$key}{$idx}{'cnum'}; - unless ($gotnewmapname) { - ($newmapname) = ($key =~ m{/([^/]+)$}); - ($srcfolder,$srccontainer) = split(/\./,$newmapname); - if ($newsubdir{$key}) { - $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; - } - $gotnewmapname = 1; - } + my ($newmapname) = ($key =~ m{/([^/]+)$}); + my ($srcfolder,$srccontainer) = split(/\./,$newmapname); my $srcmapinfo = $srcfolder.':'.$idx; if ($srccontainer eq 'page') { $srcmapinfo .= ':1'; } + if ($newsubdir{$key}) { + $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; + } ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom, $cnum,$template,$idx,$newmapname); } @@ -2775,8 +2714,7 @@ sub apply_fixups { } } } - my $total = scalar(@LONCAPA::map::order) - 1; - for (my $i=$total; $i>=0; $i--) { + for (my $i=0; $i<@LONCAPA::map::order; $i++) { my $idx = $LONCAPA::map::order[$i]; if (defined($LONCAPA::map::resources[$idx])) { my $changed; @@ -2786,7 +2724,7 @@ sub apply_fixups { splice(@LONCAPA::map::order,$i,1); if (ref($currparam{$idx}) eq 'ARRAY') { foreach my $name (@{$currparam{$idx}}) { - &LONCAPA::map::delparameter($idx,$name); + &LONCAPA::map::delparameter($idx,'parameter_'.$name); } } next; @@ -2828,7 +2766,7 @@ sub apply_fixups { foreach my $idx (keys(%remparam)) { if (ref($remparam{$idx}) eq 'ARRAY') { foreach my $name (@{$remparam{$idx}}) { - &LONCAPA::map::delparameter($idx,$name); + &LONCAPA::map::delparameter($idx,'parameter_'.$name); } } } @@ -2936,7 +2874,7 @@ sub update_parameter { 'randomorder' => {}, ); foreach my $which (keys(%allchecked)) { - $env{'form.all'.$which} =~ s/,$//; + $env{'form.all'.$which} =~ s/,$//; if ($which eq 'randompick') { foreach my $item (split(/,/,$env{'form.all'.$which})) { my ($res,$value) = split(/:/,$item); @@ -2963,7 +2901,7 @@ sub update_parameter { foreach my $which (keys(%allchecked)) { if (($which eq 'randompick' || $which eq 'randomorder')) { next if (!$is_map); - } + } my $oldvalue = 0; my $newvalue = 0; if ($allchecked{$which}{$res}) { @@ -3015,8 +2953,8 @@ sub update_parameter { $oldvalue = 1; } if ($env{'form.'.$which.'_'.$idx}) { - $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx} - : 1; + $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx} + : 1; } if ($oldvalue ne $newvalue) { $haschanges = 1; @@ -3025,17 +2963,16 @@ sub update_parameter { if ($which eq 'randompick') { $storeval = $newvalue; } - &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval, - $parameter_type{$which}); - &remember_parms($idx,$which,'set',$storeval); + &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'); + &LONCAPA::map::delparameter($idx,'parameter_'.$which); + &remember_parms($idx,$which,'del'); } } return $haschanges; } - return; } sub handle_edit_cmd { @@ -3120,10 +3057,10 @@ sub editor { undef(@LONCAPA::map::zombies); } $folder = 'default'; - $container = 'sequence'; + $container = 'sequence'; } else { ($errtext,$fatal) = &mapread($coursenum,$coursedom, - $folder.'.'.$container); + $folder.'.'.$container); return $errtext if ($fatal); } @@ -3299,7 +3236,7 @@ sub editor { } else { return $errortxt; } - } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) { + } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) { my ($suffix,$errortxt,$locknotfreed) = &new_timebased_suffix($coursedom,$coursenum,'exttool'); if ($locknotfreed) { @@ -3467,11 +3404,11 @@ sub editor { if (@allidx > 0) { my $path; if ($env{'form.folderpath'}) { - $path = + $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); } if (@allidx > 1) { - $to_show .= + $to_show .= &Apache::loncommon::continue_data_table_row(). '<td colspan="2"> </td>'. '<td>'. @@ -3503,7 +3440,7 @@ sub editor { } my $noresmsg; if ($allowed && $hiddentop && !$supplementalflag) { - $noresmsg = &mt('Main Content Hidden'); + $noresmsg = &mt('Main Content Hidden'); } else { $noresmsg = &mt('Currently empty'); } @@ -3548,7 +3485,7 @@ sub multiple_check_form { return unless (ref($listsref) eq 'HASH'); my $disabled; unless ($canedit) { - $disabled = 'disabled="disabled"'; + $disabled = 'disabled="disabled"'; } my $output = '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'. @@ -3586,7 +3523,7 @@ sub multiple_check_form { '</label></span></td>'."\n". '<td class="LC_docs_entry_parameter">'. '<span class="LC_nobreak LC_docs_copy">'. - '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy'). + '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy'). '</label></span></td>'. '</tr></table>'."\n"; } @@ -3628,6 +3565,8 @@ sub process_file_upload { my $quotatype = 'unofficial'; if ($crstype eq 'Community') { $quotatype = 'community'; + } elsif ($crstype eq 'Placement') { + $quotatype = 'placement'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) { $quotatype = 'official'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) { @@ -3821,7 +3760,7 @@ sub entryline { $renametitle=~s/"/%22/g; $renametitle=~s/ /%20/g; $oldtitle = $renametitle; - $renametitle=~s/\'\;/\\\'/g; + $renametitle=~s/\'/\\\'/g; my $line=&Apache::loncommon::start_data_table_row(); my ($form_start,$form_end,$form_common,$form_param); # Edit commands @@ -3901,7 +3840,7 @@ END 'sv' => 'Save', 'ul' => 'URL', 'ti' => 'Title', - 'er' => 'Editing rights unavailable for your current role.', + 'er' => 'Editing rights unavailable for your current role.', ); my %denied = &action_restrictions($coursenum,$coursedom,$url, $env{'form.folderpath'}, @@ -3915,7 +3854,7 @@ END |/aboutme$ |/navmaps$ |/bulletinboard$ - |/ext\.tool$ + |/exttools?$ |\.html$)}x) || $isexternal) { $skip_confirm = 1; @@ -4050,19 +3989,11 @@ END my ($editlink,$extresform,$anchor,$hiddenres,$nomodal); my $orig_url = $url; $orig_url=~s{http(:|:)//https(:|:)//}{https$2//}; - if ($container eq 'page') { - $url=~s{^http(|s)(:|:)//}{/ext/}; - } else { - $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}; - } + $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}; if (!$supplementalflag && $residx && $symb) { if ((!$isfolder) && (!$ispage)) { (undef,undef,$url)=&Apache::lonnet::decode_symb($symb); - if (($url =~ m{^ext/}) && ($container eq 'page')) { - $url=&Apache::lonnet::clutter_with_no_wrapper($url); - } else { - $url=&Apache::lonnet::clutter($url); - } + $url=&Apache::lonnet::clutter($url); if ($url=~/^\/*uploaded\//) { $url=~/\.(\w+)$/; my $embstyle=&Apache::loncommon::fileembstyle($1); @@ -4073,32 +4004,33 @@ END } elsif ($url!~/\.(sequence|page)$/) { $url='/adm/coursedocs/showdoc'.$url; } - } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) { + } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) { my $wrapped = $1; my $exturl = $2; - if (($wrapped eq '') && ($container ne 'page')) { + if ($wrapped eq '') { $url='/adm/wrapper'.$url; } if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) { $nomodal = 1; } - } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) { - $url='/adm/wrapper'.$url; + } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { + $url='/adm/wrapper'.$url; } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") { if (($ENV{'SERVER_PORT'} == 443) && ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { - unless (&Apache::lonnet::uses_sts()) { - $url .= '?usehttp=1'; - } + $url .= '?usehttp=1'; $nomodal = 1; } - } + } if (&Apache::lonnet::symbverify($symb,$url)) { my $shownsymb = $symb; if ($isexternal) { - $url =~ s/\#[^#]+$//; - if ($container eq 'page') { - $url = &Apache::lonnet::clutter($url); + if ($url =~ /^([^#]+)#([^#]+)$/) { + $url = $1; + $anchor = $2; + if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) { + $shownsymb = $1.&escape('#').$anchor; + } } } unless ($env{'request.role.adv'}) { @@ -4111,7 +4043,7 @@ END } } if ($url ne '') { - $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb); + $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&'); } } elsif (!$env{'request.role.adv'}) { my $checkencrypt; @@ -4124,7 +4056,7 @@ END } if (ref($$navmapref)) { if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') { - $checkencrypt = 1; + $checkencrypt = 1; } } } @@ -4132,7 +4064,7 @@ END my $shownsymb = &Apache::lonenc::encrypted($symb); my $shownurl = &Apache::lonenc::encrypted($url); if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) { - $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb); + $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&'); if ($env{'request.enc'} ne '') { delete($env{'request.enc'}); } @@ -4152,11 +4084,8 @@ END $url = $1; $anchor = $2; if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) { - unless (&Apache::lonnet::uses_sts()) { - if ($hostname ne '') { - $url = 'http://'.$hostname.$url; - } - $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; } $nomodal = 1; } @@ -4164,12 +4093,10 @@ END } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { if (($ENV{'SERVER_PORT'} == 443) && ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { - unless (&Apache::lonnet::uses_sts()) { - if ($hostname ne '') { - $url = 'http://'.$hostname.$url; - } - $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; $nomodal = 1; } } @@ -4202,7 +4129,7 @@ END my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1); unless (@resources) { $hiddenmap = 1; - unless ($env{'request.role.adv'}) { + unless ($env{'request.role.adv'}) { $url = ''; $hiddenfolder = 1; } @@ -4218,10 +4145,10 @@ END } } } - + # Append randompick number, hidden, and encrypted with ":" to foldername, # so it gets transferred between levels - $folderpath.=$containerarg.'&'.$foldername. + $folderpath.=$containerarg.'&'.$foldername. ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage; unless ($url eq '') { $url.='folderpath='.&escape($folderpath); @@ -4257,11 +4184,11 @@ $form_common."\n". $form_param."\n". $form_common."\n". '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'. -$form_end; +$form_end; } } elsif ($supplementalflag && !$allowed) { my $isexttool; - if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) { + if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { $url='/adm/wrapper'.$url; $isexttool = 1; } @@ -4286,7 +4213,7 @@ $form_end; &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem, undef,undef,undef,undef,undef,undef, undef,$disabled); - } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) { + } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { ($editlink,$extresform) = &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem, undef,undef,undef,'tool',$coursedom, @@ -4334,13 +4261,13 @@ $form_end; $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&'); } } - if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) { $link = 'http://'.$hostname.$url; } else { $link = $url; } - $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor); + $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. + (($anchor ne '')?$anchor:'')); if ($nomodal) { $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'. '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>'; @@ -4362,7 +4289,7 @@ $form_end; $line.=&Apache::loncommon::modal_link($link,$title,600,500); } } elsif (($hiddenfolder) || ($hiddenres)) { - $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>'; + $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>'; } else { $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>'; } @@ -4501,8 +4428,6 @@ sub new_timebased_suffix { $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.'); } elsif ($type eq 'smppg') { $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.'); - } elsif ($type eq 'exttool') { - $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.'); } else { $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.'); } @@ -4511,7 +4436,7 @@ sub new_timebased_suffix { } } if ($freedlock ne 'ok') { - $locknotfreed = + $locknotfreed = '<div class="LC_error">'. &mt('There was a problem removing a lockfile.').' '; if ($type eq 'paste') { @@ -4519,9 +4444,9 @@ sub new_timebased_suffix { $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 { + } else { $locknotfreed .= &mt('This will prevent addition of items to the clipboard until your next log-in.'); } @@ -4531,9 +4456,6 @@ sub new_timebased_suffix { } elsif ($type eq 'smppg') { $locknotfreed .= &mt('This will prevent creation of additional simple pages in this course.'); - } elsif ($type eq 'exttool') { - $locknotfreed .= - &mt('This will prevent creation of additional external tools in this course.'); } else { $locknotfreed .= &mt('This will prevent creation of additional discussion boards in this course.'); @@ -4584,7 +4506,7 @@ sub untiehash { sub checkonthis { - my ($r,$url,$level,$title,$checkstale)=@_; + my ($r,$url,$level,$title)=@_; $url=&unescape($url); $alreadyseen{$url}=1; $r->rflush(); @@ -4599,22 +4521,10 @@ sub checkonthis { $r->print('<a href="'.$url.'" target="cat">'. ($title?$title:$url).'</a> '); if ($url=~/^\/res\//) { - my $updated; - if (($checkstale) && ($url !~ m{^/res/lib/templates/}) && - ($url !~ /\.\d+\.\w+$/)) { - $updated = &Apache::lonnet::remove_stale_resfile($url); - } my $result=&Apache::lonnet::repcopy( &Apache::lonnet::filelocation('',$url)); if ($result eq 'ok') { $r->print('<span class="LC_success">'.&mt('ok').'</span>'); - if ($updated) { - $r->print('<br />'); - for (my $i=0;$i<=$level*5;$i++) { - $r->print(' '); - } - $r->print('- '.&mt('Outdated copy removed')); - } $r->rflush(); &Apache::lonnet::countacc($url); $url=~/\.(\w+)$/; @@ -4648,7 +4558,7 @@ sub checkonthis { &Apache::lonnet::metadata($url,'dependencies'); foreach my $dep (split(/\,/,$dependencies)) { if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) { - &checkonthis($r,$dep,$level+1,'',$checkstale); + &checkonthis($r,$dep,$level+1); } } } elsif ($result eq 'unavailable') { @@ -4662,9 +4572,6 @@ sub checkonthis { } else { $r->print('<span class="LC_error">'.&mt('access denied').'</span>'); } - if (($updated) && ($result ne 'ok')) { - $r->print('<br />'.&mt('Outdated copy removed')); - } } } } @@ -4717,71 +4624,9 @@ sub list_symbs { $r->print(&endContentScreen()); } -sub short_urls { - my ($r,$canedit) = @_; - my $crstype = &Apache::loncommon::course_type(); - my $formname = 'shortenurl'; - $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs')); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs')); - $r->print(&startContentScreen('tools')); - my ($navmap,$errormsg) = - &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls'); - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my (%maps,%resources,%titles); - if (!ref($navmap)) { - $r->print($errormsg. - &endContentScreen()); - return ''; - } else { - $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n"); - $r->rflush(); - my $readonly; - if ($canedit) { - my ($numnew,$errors) = &Apache::loncommon::make_short_symbs($cdom,$cnum,$navmap); - if ($numnew) { - $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>'); - } - if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) { - $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>'); - foreach my $error (@{$errors}) { - $r->print('<li>'.$error.'</li>'); - } - $r->print('</ul><br />'); - } - } else { - $readonly = 1; - } - my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum); - $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef, - undef,undef,undef,undef,undef,\%currtiny,$readonly)); - } - $r->print(&endContentScreen()); -} - -sub contentverifyform { - my ($r) = @_; - my $crstype = &Apache::loncommon::course_type(); - $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content')); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content')); - $r->print(&startContentScreen('tools')); - $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); - $r->print('<form method="post" action="/adm/coursedocs"><p>'. - &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?'). - ' <span class="LC_nobreak">'. - '<label><input type="radio" name="checkstale" value="0" checked="checked" />'. - &mt('No').'</label>'.(' 'x2). - '<label><input type="radio" name="checkstale" value="1" />'. - &mt('Yes').'</label></span></p><p>'. - '<input type="submit" value="'.&mt('Verify content').' "/>'. - '<input type="hidden" value="1" name="tools" />'. - '<input type="hidden" value="1" name="verify" /></p></form>'); - $r->print(&endContentScreen()); - return; -} sub verifycontent { - my ($r,$checkstale) = @_; + my ($r) = @_; my $crstype = &Apache::loncommon::course_type(); $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content')); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content')); @@ -4802,7 +4647,7 @@ sub verifycontent { } } if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) { - &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale); + &checkonthis($r,$hash{$key},0,$hash{'title_'.$1}); } } &untiehash(); @@ -4874,8 +4719,8 @@ sub checkversions { } if ($haschanged) { if (&Apache::lonnet::put('resourceversions',\%newsetversions, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { $r->print(&Apache::loncommon::confirmwrapper( &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved')))); } else { @@ -5007,7 +4852,7 @@ ENDHEADERS return; } $r->print( - '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'. + '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'. &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). '<th>'.&mt('Resources').'</th>'. @@ -5050,9 +4895,9 @@ ENDHEADERS $setversions{$linkurl}, 'set_version_'.$linkurl, {'select_form_order' => ['',1..$currentversion,'mostrecent'], - '' => '', - 'mostrecent' => &mt('most recent'), - map {$_,$_} (1..$currentversion)},'',$readonly)); + '' => '', + 'mostrecent' => &mt('most recent'), + map {$_,$_} (1..$currentversion)},'',$readonly)); my $lastold=1; for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) { my $url=$root.'.'.$prevvers.'.'.$extension; @@ -5189,6 +5034,7 @@ sub startContentScreen { if (($mode eq 'navmaps') || ($mode eq 'supplemental')) { $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n"; $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n"; + $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n"; $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>'; } else { $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n"; @@ -5226,18 +5072,21 @@ sub handler { my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'}; my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'}; +# get docroot + my $londocroot = $r->dir_config('lonDocRoot'); + # graphics settings $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/'); # # --------------------------------------------- Initialize help topics for this foreach my $topic ('Adding_Course_Doc','Main_Course_Documents', - 'Adding_External_Resource','Adding_External_Tool', - 'Navigate_Content','Adding_Folders','Docs_Overview', - 'Load_Map','Supplemental','Score_Upload_Form', - 'Adding_Pages','Importing_LON-CAPA_Resource', - 'Importing_IMS_Course','Uploading_From_Harddrive', - 'Course_Roster','Web_Page','Dropbox','Simple_Problem') { + 'Adding_External_Resource','Navigate_Content', + 'Adding_Folders','Docs_Overview', 'Load_Map', + 'Supplemental','Score_Upload_Form','Adding_Pages', + 'Importing_LON-CAPA_Resource','Importing_IMS_Course', + 'Uploading_From_Harddrive','Course_Roster','Web_Page', + 'Dropbox','Simple_Problem') { $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic); } # Composite help files @@ -5252,7 +5101,7 @@ sub handler { $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files'); $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching'); - my ($allowed,$canedit,$canview,$disabled); + my ($allowed,$canedit,$canview,$noendpage,$disabled); # URI is /adm/supplemental when viewing supplemental docs in non-edit mode. unless ($r->uri eq '/adm/supplemental') { # does this user have privileges to modify content. @@ -5269,31 +5118,12 @@ sub handler { $disabled = ' disabled="disabled"'; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']); - if ($env{'form.inhibitmenu'}) { - unless ($env{'form.inhibitmenu'} eq 'yes') { - delete($env{'form.inhibitmenu'}); - } - } - if ($allowed && $env{'form.verify'}) { &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content'); - if (!$canedit) { - &verifycontent($r); - } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) { - &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}", - text=>'Results', - faq=>273, - bug=>'Instructor Interface'}); - &verifycontent($r,$env{'form.checkstale'}); - } else { - &contentverifyform($r); - } + &verifycontent($r); } elsif ($allowed && $env{'form.listsymbs'}) { &init_breadcrumbs('listsymbs','List Content IDs'); &list_symbs($r); - } elsif ($allowed && $env{'form.shorturls'}) { - &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs'); - &short_urls($r,$canedit); } elsif ($allowed && $env{'form.docslog'}) { &init_breadcrumbs('docslog','Show Log'); my $folder = $env{'form.folder'}; @@ -5307,10 +5137,59 @@ sub handler { } elsif ($canedit && $env{'form.dumpcourse'}) { &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space'); &dumpcourse($r); - } elsif ($allowed && $env{'form.exportcourse'}) { + } elsif ($canedit && $env{'form.exportcourse'}) { &init_breadcrumbs('exportcourse','IMS Export'); &Apache::imsexport::exportcourse($r); } else { + if ($canedit && $env{'form.authorrole'}) { + $noendpage = 1; + my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum); + if ($redirect) { + if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) { + my $container = 'sequence'; + my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain, + $is_random_order,$container) = + &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1); + my (@folders)=split('&',$env{'form.folderpath'}); + $env{'form.foldername'}=&unescape(pop(@folders)); + my $folder=pop(@folders); + my ($errtext,$fatal) = &mapread($coursenum,$coursedom, + $folder.'.'.$container); + my $warning; + if ($fatal) { + if ($container eq 'page') { + $warning = &mt('An error occurred retrieving the contents of the current page.'); + } else { + $warning = &mt('An error occurred retrieving the contents of the current folder.'); + } + } else { + my $url = $redirect; + my $srcfile = $londocroot.$url; + $url =~ s{^/priv/}{/res/}; + my $targetfile = $londocroot.$url; + my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes')); + my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1); + $env{'form.folder'} = $folder; + &snapshotbefore(); + my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'}); + my $ext = 'false'; + my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url)); + $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url). + ':'.$ext.':normal:res'; + push(@LONCAPA::map::order,$newidx); + &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes', + 'string_yesno'); + &remember_parms($newidx,'hiddenresource','set','yes'); + ($errtext,$fatal) = + &storemap($coursenum, $coursedom, $folder.'.'.$container,1); + &log_differences($plain); + &mark_hash_old(); + $r->internal_redirect($redirect); + return OK; + } + } + } + } # # Done catching special calls # The whole rest is for course and supplemental documents and utilities menu @@ -5321,26 +5200,6 @@ sub handler { 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); - foreach my $item ('forcesupplement','forcestandard','tools') { - next if ($env{'form.'.$item} eq ''); - unless ($env{'form.'.$item} eq '1') { - delete($env{'form.'.$item}); - } - } - - if ($env{'form.command'}) { - unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) { - delete($env{'form.command'}); - } - } - - if ($env{'form.symb'}) { - my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'}); - unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { - delete($env{'form.symb'}); - } - } - # standard=1: this is a "new-style" course with an uploaded map as top level # standard=2: this is a "old-style" course, and there is nothing we can do @@ -5363,38 +5222,6 @@ sub handler { my $toolsflag=0; if ($env{'form.tools'}) { $toolsflag=1; } - if ($env{'form.folderpath'} ne '') { - my @items = split(/\&/,$env{'form.folderpath'}); - my $badpath; - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) { - $badpath = 1; - } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) { - $badpath = 1; - } - last if ($badpath); - } - if ($badpath) { - delete($env{'form.folderpath'}); - } - } - - if ($env{'form.supppath'} ne '') { - my @items = split(/\&/,$env{'form.supppath'}); - my $badpath; - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { - $badpath = 1; - } - last if ($badpath); - } - if ($badpath) { - delete($env{'form.supppath'}); - } - } - my $script=''; my $showdoc=0; my $addentries = {}; @@ -5444,7 +5271,7 @@ sub handler { if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) { if ($supplementalflag) { - undef($env{'form.folderpath'}) if ($1 eq 'default'); + undef($env{'form.folderpath'}) if ($1 eq 'default'); } else { undef($env{'form.folderpath'}) if ($1 eq 'supplemental'); } @@ -5465,8 +5292,8 @@ sub handler { .'&'. $env{'form.folderpath'}; } -# If allowed and user's role is not advanced check folderpath is not hidden - if (($allowed) && (!$env{'request.role.adv'}) && +# If allowed and user's role is not advanced check folderpath is not hidden + if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '') && (!$supplementalflag)) { my $folderurl; my @pathitems = split(/\&/,$env{'form.folderpath'}); @@ -5475,7 +5302,7 @@ sub handler { undef($env{'form.folderpath'}); } else { $folderurl = "uploaded/$coursedom/$coursenum/$folder"; - if ((split(/\:/,$pathitems[-1]))[5]) { + if ((split(/\:/,$pathitems[-1]))[4]) { $folderurl .= '.page'; } else { $folderurl .= '.sequence'; @@ -5582,8 +5409,8 @@ sub handler { %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom); my $posslti = keys(%ltitools); my $hostname = $r->hostname(); - $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, - $canedit,$hostname,\$navmap). + $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, + $londocroot,$canedit,$hostname,\$navmap). &history_tab_js(). &inject_data_js(). &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid). @@ -5604,7 +5431,8 @@ sub handler { .$script."\n" .'// ]]>'."\n" .'</script>'."\n" - .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n"; + .'<script type="text/javascript" + src="/res/adm/includes/file_upload.js"></script>'."\n"; # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -5666,7 +5494,6 @@ sub handler { undef($hadchanges); $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom, \%allfiles,\%codebase,$context,$crstype); - undef($navmap); if ($hadchanges) { &mark_hash_old(); } @@ -5723,8 +5550,9 @@ sub handler { 'impo' => 'Import', 'lnks' => 'Import from Stored Links', 'impm' => 'Import from Assembled Map', + 'imcr' => 'Import from Course Resources', 'extr' => 'External Resource', - 'extt' => 'External Tool', + 'extt' => 'External Tool', 'selm' => 'Select Map', 'load' => 'Load Map', 'newf' => 'New Folder', @@ -5733,7 +5561,10 @@ sub handler { 'navc' => 'Table of Contents', 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', - 'webp' => 'Blank Web Page (editable)', + 'webp' => 'Blank Web Page (editable)', + 'stpr' => 'Standard Problem', + 'news' => 'New sub-directory', + 'crpr' => 'Create Problem', 'drbx' => 'Drop Box', 'scuf' => 'External Scores (handgrade, upload, clicker)', 'bull' => 'Discussion Board', @@ -5747,20 +5578,32 @@ sub handler { 'se' => 'Select', 'file' => 'File', 'title' => 'Title', + 'addp' => 'Add Placeholder to course?', + 'uste' => 'Use Template?', + 'fnam' => 'File Name:', + 'loca' => 'Location:', + 'dire' => 'Directory:', + 'cate' => 'Category:', + 'tmpl' => 'Template:', 'comment' => 'Comment', 'parse' => 'Upload embedded images/multimedia files if HTML file', 'bb5' => 'Blackboard 5', 'bb6' => 'Blackboard 6', 'angel5' => 'ANGEL 5.5', 'webctce4' => 'WebCT 4 Campus Edition', + 'yes' => 'Yes', + 'no' => 'No', 'er' => 'Editing rights unavailable for your current role.', ); # ----------------------------------------------------------------------------- + # Calculate free quota space for a user or course. A javascript function checks # file size to determine if upload should be allowed. my $quotatype = 'unofficial'; if ($crstype eq 'Community') { $quotatype = 'community'; + } elsif ($crstype eq 'Placement') { + $quotatype = 'placement'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) { $quotatype = 'official'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) { @@ -5791,8 +5634,8 @@ sub handler { my $fileupload=(<<FIUP); $quotainfo $lt{'file'}:<br /> - <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled /> - <input type="hidden" id="LC_free_space" value="$free_space" /> + <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled /> + <input type="hidden" id="free_space" value="$free_space" /> FIUP my $checkbox=(<<CHBO); @@ -5839,7 +5682,7 @@ IMSFORM <fieldset id="uploaddocform" style="display: none;"> <legend>$lt{'upfi'}</legend> <input type="hidden" name="active" value="aa" /> - $fileupload + $fileupload <br /> $lt{'title'}:<br /> <input type="text" size="60" name="comment" $disabled /> @@ -5857,7 +5700,7 @@ FUFORM my $mapimportjs; if ($canedit) { - $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; + $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; } else { $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');"; } @@ -5878,10 +5721,33 @@ FUFORM </form> SEDFFORM + my $importcrsresform; + my ($numdirs,$pickfile) = + &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile', + "resize_scrollbox('contentscroll','1','0');", + undef,'res'); + if ($pickfile) { + $importcrsresform=(<<CRSFORM); + <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');"> + $lt{'imcr'}</a>$help{'Course_Resources'} + <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();"> + <fieldset id="importcrsresform" style="display: none;"> + <legend>$lt{'imcr'}</legend> + <input type="hidden" name="active" value="bb" /> + $pickfile + <p> + $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled /> + </p> + <input type="hidden" name="importdetail" value="" /> + <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /> + </fieldset> + </form> +CRSFORM + } my $fromstoredjs; if ($canedit) { - $fromstoredjs = 'open_StoredLinks_Import()'; + $fromstoredjs = 'open_StoredLinks_Import()'; } else { $fromstoredjs = "alert('".&js_escape($lt{'er'})."')"; } @@ -5890,8 +5756,11 @@ SEDFFORM { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" }, { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" }, { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>' }, - { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform } - ); + { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }, + ); + if ($pickfile) { + push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform}); + } $importpubform = &create_form_ul(&create_list_elements(@importpubforma)); my $extresourcesform = &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem, @@ -5943,9 +5812,8 @@ HIDDENFORM } # - - my $savefolderpath; my $hostname = $r->hostname(); + my $savefolderpath; if ($allowed) { my $folder=$env{'form.folder'}; @@ -6082,7 +5950,224 @@ NROSTFORM $help{'Web_Page'} </form> NWEBFORM - + + my @ids=&Apache::lonnet::current_machine_ids(); + my %select_menus; + my $numauthor = 0; + my $numcrsdirs = 0; + my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}"; + if ($env{'user.author'}) { + $numauthor ++; + $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au'); + if (grep(/^\Q$env{'user.home'}\E$/,@ids)) { + my $is_home = 1; + my %subdirs; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $select_menus{'author'}->{'default'} = '/'; + $select_menus{'author'}->{'select2'}->{'/'} = '/'; + my @ordered = ('/'); + foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $select_menus{'author'}->{'select2'}->{$relpath} = $relpath; + push(@ordered,$relpath); + } + $select_menus{'author'}->{'order'} = \@ordered; + } else { + $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required'); + $select_menus{'author'}->{'default'} = 'switch'; + $select_menus{'author'}->{'order'} = ['switch']; + } + } + my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles', + ['active'],['ca','aa']); + my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'}; + my %by_roletype; + if (keys(%roleshash)) { + foreach my $entry (keys(%roleshash)) { + my ($auname,$audom,$roletype) = split(/:/,$entry); + my $key = $entry; + $key =~ s/:/___/g; + $by_roletype{$roletype}{$auname.'___'.$audom} = 1; + $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)"; + my $rolehome = &Apache::lonnet::homeserver($auname,$audom); + if (grep(/^\Q$rolehome\E$/,@ids)) { + my $is_home = 1; + my (%subdirs,@ordered); + my $toppath="/priv/$audom/$auname"; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $select_menus{$key}->{'default'} = '/'; + $select_menus{$key}->{'select2'}->{'/'} = '/'; + my @ordered = ('/'); + foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $select_menus{$key}->{'select2'}->{$relpath} = $relpath; + push(@ordered,$relpath); + } + $select_menus{$key}->{'order'} = \@ordered; + } else { + $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required'); + $select_menus{$key}->{'default'} = 'switch'; + $select_menus{$key}->{'order'} = ['switch']; + } + $numauthor ++; + } + } + my ($pickdir,$showtitle);; + if ($numauthor) { + my @order; + my $defrole; + if ($env{'user.author'}) { + push(@order,'author'); + $defrole = 'author'; + } + if (keys(%by_roletype)) { + foreach my $possrole ('ca','aa') { + if (ref($by_roletype{$possrole}) eq 'HASH') { + foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) { + unless ($defrole) { + $defrole = $author; + } + push(@order,$author.'___'.$possrole); + } + } + } + } + $select_menus{'course'}->{'text'} = &mt('Course Resource'); + if (grep(/^\Q$crshome\E$/,@ids)) { + my $is_home = 1; + my %subdirs; + my $toppath="/priv/$coursedom/$coursenum"; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $numcrsdirs = keys(%subdirs); + $select_menus{'course'}->{'default'} = '/'; + $select_menus{'course'}->{'select2'}->{'/'} = '/'; + my @ordered = ('/'); + foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $select_menus{'course'}->{'select2'}->{$relpath} = $relpath; + push(@ordered,$relpath); + } + $select_menus{'course'}->{'order'} = \@ordered; + } else { + $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required'); + $select_menus{'course'}->{'default'} = 'switch'; + $select_menus{'course'}->{'order'} = ['switch']; + } + push(@order,'course'); + $pickdir = $lt{'loca'}. + &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'}, + $defrole,'authorrole','authorpath', + \%select_menus,\@order,'toggleCrsResTitle();', + '','priv').'<br />'; + $showtitle = 'none'; + } else { + my $is_home; + $showtitle = 'inline'; + if (grep(/^\Q$crshome\E$/,@ids)) { + $is_home = 1; + $pickdir .= '<input type="hidden" name="authorrole" value="course" />'; + my $toppath="/priv/$coursedom/$coursenum'}"; + my %subdirs; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $numcrsdirs = keys(%subdirs); + if ($numcrsdirs) { + $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n". + '<option value="/">/</option>'."\n"; + foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n"; + } + $pickdir .= '</select>'; + } else { + $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n"; + } + } + } + + my %seltemplate_menus; + my @files = &Apache::lonhomework::get_template_list('problem'); + my @noexamplelink = ('blank.problem','blank.library','script.library'); + my $currentcategory = ''; + my @ordered = (''); + my %templatehelp; + my $defcategory = ''; + my @catorder = ($defcategory); + $seltemplate_menus{$defcategory}->{'order'} = ['']; + $seltemplate_menus{$defcategory}->{'text'} = ''; + foreach my $file (@files) { + if (ref($file) eq 'ARRAY') { + my ($path,$title,$category,$help) = @{$file}; + next if ($title !~ /\S/); + if (&js_escape($category) ne $currentcategory) { + $currentcategory = &js_escape($category); + push(@catorder,&js_escape($currentcategory)); + $seltemplate_menus{$currentcategory}->{'text'} = $category; + $seltemplate_menus{$currentcategory}->{'default'} = ''; + $seltemplate_menus{$currentcategory}->{'select2'}->{''} = ''; + push(@{$seltemplate_menus{$currentcategory}->{'order'}},''); + } + if ($path) { + $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title; + push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path)); + if ($help) { + $templatehelp{$path} = $help; + } + } + } + } + + my $templates = $lt{'cate'}.' '. + &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ', + $defcategory,'tempcategory','template', + \%seltemplate_menus,\@catorder, + "resize_scrollbox('contentscroll','1','0');", + "toggleExampleText();",'template').'<br />'; + my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'. + '<span id="newresexample">'.&mt('Example').'<span></a>'; + my $crsresform=(<<RESFORM); + <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');"> + $lt{'stpr'}</a>$help{'Course_Resource'} + <form action="/adm/coursedocs" method="post" name="courseresform"> + <fieldset id="crsresform" style="display:none;"> + <legend>$lt{'stpr'}</legend> + <input type="hidden" name="active" value="ee" /> + <p> + $pickdir + <span class="LC_nobreak">$lt{'news'}? + <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label> + + <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label> + </span><span id="newsubdir"></span> + <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" /> + </p> + $lt{'fnam'} + <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled /> + <p> + <div id="newresource" style="display:$showtitle"> + $lt{'addp'} + <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled /> + $lt{'no'}</label> + <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled /> + $lt{'yes'}</label> + <span id="newrestitle"></span> + <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled /> + </div> + </p> + <p> + $lt{'uste'} + <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled /> + $lt{'no'}</label> + <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled /> + $lt{'yes'}</label> + <div id="newrestemplate" style="display:none"> + $templates + $templatepreview + </div> + </p> + <span class="LC_nobreak"> + <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" /> + <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled /> + </span> + </fieldset> + </form> + +RESFORM my $specialdocumentsform; my @specialdocumentsforma; @@ -6152,7 +6237,7 @@ NGFFORM ); if (keys(%ltitools)) { push(@importdoc, - {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform}, + {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform}, ); } unless ($container eq 'page') { @@ -6169,7 +6254,7 @@ NGFFORM {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform}, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform}, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}, - + {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform}, ); $gradingform = &create_form_ul(&create_list_elements(@gradingforma)); @@ -6203,9 +6288,7 @@ unless ($container eq 'page') { $r->print('<p><span class="LC_error">'.$error.'</span></p>'); } if ($hadchanges) { - unless (&is_hash_old()) { - &mark_hash_old(); - } + &mark_hash_old(); } &changewarning($r,''); @@ -6266,7 +6349,9 @@ SNFFORM my $supextform = &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, $help{'Adding_External_Resource'}, - undef,undef,$disabled); + undef,undef,undef,undef,undef,undef, + $disabled); + my $supexttoolform = &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, $help{'Adding_External_Tool'}, @@ -6329,11 +6414,11 @@ my @supimportdoc = ( =>$supextform}); if (keys(%ltitools)) { push(@supimportdoc, - {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />' + {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />' =>$supexttoolform}); } - push(@supimportdoc, - {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />' + push(@supimportdoc, + {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />' =>$supupdocform}, ); @@ -6361,12 +6446,12 @@ my %suporderhash = ( } &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); undef($suppchanges); - } - } + } + } } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem,'',$hostname); + $supplementalflag,'',$iconpath,$pathitem,'','',$hostname); if ($error) { $r->print('<p><span class="LC_error">'.$error.'</span></p>'); } @@ -6393,14 +6478,15 @@ my %suporderhash = ( &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>'); } } - $r->print(&Apache::loncommon::end_page()); + unless ($noendpage) { + $r->print(&Apache::loncommon::end_page()); + } return OK; } sub embedded_form_elems { my ($phase,$primaryurl,$newidx) = @_; my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); - $newidx =~s /\D+//g; return <<STATE; <input type="hidden" name="folderpath" value="$folderpath" /> <input type="hidden" name="cmd" value="upload_embedded" /> @@ -6421,11 +6507,7 @@ sub embedded_destination { } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) { $destination .= $2.'/'; } - my $newidx = $env{'form.newidx'}; - $newidx =~s /\D+//g; - if ($newidx) { - $destination .= $newidx; - } + $destination .= $env{'form.newidx'}; my $dir_root = '/userfiles'; return ($destination,$dir_root); } @@ -6451,9 +6533,6 @@ sub decompression_info { } unshift(@hiddens,$pathitem); foreach my $item (@hiddens) { - if ($item eq 'newidx') { - next if ($env{'form.'.$item} =~ /\D/); - } if ($env{'form.'.$item}) { $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'. &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n"; @@ -6566,7 +6645,6 @@ sub generate_admin_menu { 'vc' => 'Verify Content', 'cv' => 'Check/Set Resource Versions', 'ls' => 'List Resource Identifiers', - 'ct' => 'Display/Set Shortened URLs for Deep-linking', 'imse' => 'Export contents to IMS Archive', 'dcd' => "Copy $crstype Content to Authoring Space", ); @@ -6617,13 +6695,6 @@ sub generate_admin_menu { 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) { @@ -6755,7 +6826,7 @@ END sub editing_js { my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, - $canedit,$hostname,$navmapref) = @_; + $londocroot,$canedit,$hostname,$navmapref) = @_; my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', @@ -6767,6 +6838,7 @@ sub editing_js { p_mdb => 'Title for the Drop Box', p_mbb => 'Title for the Discussion Board', p_mwp => 'Title for Web Page', + p_mnr => 'Title for the Resource', p_mab => "Enter user:domain for User's Personal Information Page", p_mab2 => 'Personal Information Page of ', p_mab_alrt1 => 'Not a valid user:domain', @@ -6795,9 +6867,11 @@ sub editing_js { noor => 'No actions selected or changes to settings specified.', noch => 'No changes to settings specified.', noac => 'No actions selected.', + nofi => 'No file selected', + tinc => 'Title in course', + sunm => 'Sub-directory name', edri => 'Editing rights unavailable for your current role.', ); - &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'},'<>&"'); @@ -6827,37 +6901,25 @@ sub editing_js { } else { $url = $res; } - $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"'); - if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) { - $backtourl .= '?navmap=1'; - } else { - $backtourl .= '?symb='. - &HTML::Entities::encode($caller,'<>&"'); - } + $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='. + &HTML::Entities::encode($caller,'<>&"'); if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { if (($ENV{'SERVER_PORT'} == 443) && ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { - unless (&Apache::lonnet::uses_sts()) { - if ($hostname ne '') { - $backtourl = 'http://'.$hostname.$backtourl; - } - $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; } } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { - unless (&Apache::lonnet::uses_sts()) { - if ($hostname ne '') { - $backtourl = 'http://'.$hostname.$backtourl; - } - $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; - } + $backtourl = 'http://'.$hostname.$backtourl; } } if ($anchor ne '') { $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); } - $backtourl = &Apache::loncommon::escape_single($backtourl); + $backtourl = &Apache::loncommon::escape_single($backtourl); } else { $backtourl = '/adm/navmaps'; } @@ -6883,7 +6945,7 @@ sub editing_js { $fieldsets .= ",'supptool'"; } } - + my $jsmakefunctions; if ($canedit) { $jsmakefunctions = <<ENDNEWSCRIPT; @@ -6930,7 +6992,7 @@ function makewebpage(type) { formname = this.document.forms.newwebpage; } if (title) { - var webpage = formname.importdetail.value; + var webpage = formname.importdetail.value; formname.importdetail.value = escape(title)+'='+webpage; formname.submit(); } @@ -7080,14 +7142,14 @@ function toggleUpload(caller) { document.getElementById('upload'+blocks[i]+'form').style.display=disp; if ((caller == 'tool') || (caller == 'supptool')) { if (disp == 'block') { - if (document.getElementById('LC_exttoolid')) { - var toolselector = document.getElementById('LC_exttoolid'); + if (document.getElementById('LC_exttoolid')) { + var toolselector = document.getElementById('LC_exttoolid'); var suppflag = 0; if (caller == 'supptool') { suppflag = 1; } currForm = document.getElementById('new'+caller); - updateExttool(toolselector,currForm,suppflag); + updateExttool(toolselector,currForm,suppflag); } } } @@ -7111,6 +7173,186 @@ function toggleMap(caller) { 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<document.courseresform.newsubdir.length; j++) { + if (document.courseresform.newsubdir[j].value == 0) { + document.courseresform.newsubdir[j].checked = true; + } + break; + } + if (document.getElementById('newsubdirname')) { + document.getElementById('newsubdirname').type = "hidden"; + document.getElementById('newsubdirname').value = ""; + } + if (document.getElementById('newsubdir')) { + document.getElementById('newsubdir').innerHTML = ""; + } + } + document.getElementById('crsresform').style.display=disp; + resize_scrollbox('contentscroll','1','0'); + } + return; +} + +function toggleNewsubdir(form) { + if (form.newsubdir.length) { + for (var j=0; j<form.newsubdir.length; j++) { + if (form.newsubdir[j].checked) { + if (document.getElementById('newsubdirname')) { + if (form.newsubdir[j].value == '1') { + document.getElementById('newsubdirname').type = "text"; + if (document.getElementById('newsubdir')) { + document.getElementById('newsubdir').innerHTML = '<br />$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<form.newresourceadd.length; i++) { + if (form.newresourceadd[i].checked) { + if (document.getElementById('newresourcetitle')) { + if (form.newresourceadd[i].value == '1') { + document.getElementById('newresourcetitle').type = 'text'; + if (document.getElementById('newrestitle')) { + document.getElementById('newrestitle').innerHTML = "<br />$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<form.newresusetemp.length; i++) { + if (form.newresusetemp[i].checked) { + if (document.getElementById('newrestemplate')) { + if (form.newresusetemp[i].value == '1') { + document.getElementById('newrestemplate').style.display = 'inline'; + toggleExampleText(); + } else { + form.tempcategory.selectedIndex = 0; + select1template_changed(); + document.getElementById('newrestemplate').style.display = 'none'; + } + } + } + } + } +} + +function toggleExampleText() { + if (document.getElementById('newresexample')) { + var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value; + if (url == '') { + document.getElementById('newresexample').style.fontWeight = 'normal'; + } else { + document.getElementById('newresexample').style.fontWeight = 'bold'; + } + } +} + +function getExample(width,height,scrolling,transparency) { + var url; + if (document.courseresform.newresusetemp.length) { + for (var i=0; i<document.courseresform.newresusetemp.length; i++) { + if (document.courseresform.newresusetemp[i].checked) { + if (document.courseresform.newresusetemp[i].value == '1') { + var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value; + if (url == '') { + alert('Pick a category and template'); + } else { + url = url.replace("$londocroot",""); + url += '?inhibitmenu=yes'; + } + } + break; + } + } + } + if (url != '') { + openMyModal(url,width,height,scrolling,transparency,''); + } +} + +function toggleImportCrsres(caller,dircount) { + var disp = 'none'; + if (document.getElementById('importcrsresform')) { + if (caller == 'res') { + var numdirs = parseInt(dircount); + var curr = document.getElementById('importcrsresform').style.display; + if (curr == 'none') { + disp='block'; + if (numdirs > 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'}"); @@ -7417,11 +7659,11 @@ for (i = 0; i < currentLis.length; i++) function hideAll(current, nav, data) { unselectInactive(nav); -if (current) { +if (current) { if (current.className == 'right'){ - current.className = 'right active' + current.className = 'right active' } else { - current.className = 'active'; + current.className = 'active'; } } currentData = document.getElementById(data); @@ -7459,13 +7701,15 @@ function showPage(current, pageId, nav, unselectInactive(nav); if ((currstate == 'active') || (currstate == 'right active')) { if (currstate == 'active') { - current.className = ''; + current.className = ''; } else { current.className = 'right'; } - activeTab = ''; + activeTab = ''; toggleUpload(); toggleMap(); + toggleCrsRes(); + toggleImportCrsres(); resize_scrollbox('contentscroll','1','0'); return; } else { @@ -7476,6 +7720,8 @@ function showPage(current, pageId, nav, activeTab = pageId; toggleUpload(); toggleMap(); + toggleCrsRes(); + toggleImportCrsres(); if (nav == 'mainnav') { var storedpath = "$docs_folderpath"; var storedpage = "$main_container_page"; @@ -7839,6 +8085,33 @@ function setBoxes(value) { return; } +function validImportCrsRes() { + var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value; + var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value; + if ((fname == '') || (fname == null)) { + alert("$js_lt{'nofi'}"); + return false; + } + var url = '/res/$coursedom/$coursenum/'; + if (path && path != '/') { + url += path+'/'; + } + if (fname != '') { + url += fname; + } + var title = document.crsresimportform.crsrestitle.value; + document.crsresimportform.importdetail.value=escape(title)+'='+escape(url); + return true; +} + +function validateNewRes(caller) { + if (caller == 'single') { + var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; + var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value; + var resname = document.courseresform.newresourcename.value; + } +} + ENDSCRIPT } @@ -7969,6 +8242,262 @@ sub makesimpleeditform { 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; +<accessrule effect="deny" realm="" type="course" role="" /> +<accessrule effect="allow" realm="$cid" type="course" role="" /> +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"; + +<abstract></abstract> +<author>$author</author> +<authorspace>$coursenum:$coursedom</authorspace> +<copyright>private</copyright> +<creationdate>$now</creationdate> +<customdistributionfile></customdistributionfile> +<dependencies></dependencies> +<domain>$coursedom</domain> +<highestgradelevel>0</highestgradelevel> +<keywords></keywords> +<language>notset </language> +<lastrevisiondate>$now</lastrevisiondate> +<lowestgradelevel>0</lowestgradelevel> +<mime>rights</mime> +<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser> +<notes></notes> +<obsolete></obsolete> +<obsoletereplacement></obsoletereplacement> +<owner>$coursenum:$coursedom</owner> +<rule>deny:::course,allow:$cid::course</rule> +<sourceavail></sourceavail> +<standards></standards> +<subject></subject> +<title></title> +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 <<END; + +<abstract></abstract> +<author>$author</author> +<authorspace>$coursenum:$coursedom</authorspace> +<copyright>custom</copyright> +<creationdate>$now</creationdate> +<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile> +<dependencies></dependencies> +<domain>$coursedom</domain> +<highestgradelevel>0</highestgradelevel> +<keywords></keywords> +<language>notset </language> +<lastrevisiondate>$now</lastrevisiondate> +<lowestgradelevel>0</lowestgradelevel> +<mime>problem</mime> +<modifyinguser>$coursenum:$coursedom</modifyinguser> +<notes></notes> +<obsolete></obsolete> +<obsoletereplacement></obsoletereplacement> +<owner>$coursenum:$coursedom</owner> +<sourceavail></sourceavail> +<standards></standards> +<subject></subject> +<title>$title</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__ @@ -8068,9 +8597,7 @@ check on this Verify Content -=item devalidateversioncache() - -=item checkversions() +=item devalidateversioncache() & checkversions() Check Versions