--- loncom/interface/londocs.pm 2023/09/02 21:48:40 1.484.2.93.2.13 +++ loncom/interface/londocs.pm 2018/01/12 01:54:56 1.650 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.93.2.13 2023/09/02 21:48:40 raeburn Exp $ +# $Id: londocs.pm,v 1.650 2018/01/12 01:54:56 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,11 +43,14 @@ use Apache::lonnavdisplay(); use Apache::lonextresedit(); use Apache::lontemplate(); use Apache::lonsimplepage(); -use Apache::loncourserespicker(); +use Apache::lonhomework(); +use Apache::lonpublisher(); +use Apache::lonparmset(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; use File::MMagic; +use File::Copy; use Apache::lonlocal; use Cwd; use UUID::Tiny ':std'; @@ -87,7 +90,7 @@ sub storemap { if ($map =~ /^default/) { $hadchanges=1; - } elsif ($contentchg) { + } else { $suppchanges=1; } return ($errtext,0); @@ -179,64 +182,6 @@ sub default_folderpath { } } -sub validate_supppath { - my ($coursenum,$coursedom) = @_; - my $backto; - if ($env{'form.supppath'} ne '') { - my @items = split(/\&/,$env{'form.supppath'}); - my ($badpath,$got_supp,$supppath,%supphidden,%suppids); - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { - $badpath = 1; - last; - } elsif ($odd) { - my $suffix; - my $idx = $i-1; - if ($items[$i] =~ /^([^:]*)::(|1):::$/) { - $backto .= '&'.$1; - } elsif ($items[$idx] eq 'supplemental') { - $backto .= '&'.$items[$i]; - } else { - $backto .= '&'.$items[$i]; - my $is_hidden; - unless ($got_supp) { - my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); - if (ref($supplemental) eq 'HASH') { - if (ref($supplemental->{'hidden'}) eq 'HASH') { - %supphidden = %{$supplemental->{'hidden'}}; - } - if (ref($supplemental->{'ids'}) eq 'HASH') { - %suppids = %{$supplemental->{'ids'}}; - } - } - $got_supp = 1; - } - if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') { - my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0]; - if ($supphidden{$mapid}) { - $is_hidden = 1; - } - } - $suffix = '::'.$is_hidden.':::'; - } - $supppath .= '&'.$items[$i].$suffix; - } else { - $supppath .= '&'.$items[$i]; - $backto .= '&'.$items[$i]; - } - } - if ($badpath) { - delete($env{'form.supppath'}); - } else { - $supppath =~ s/^\&//; - $backto =~ s/^\&//; - $env{'form.supppath'} = $supppath; - } - } - return $backto; -} - sub dumpcourse { my ($r) = @_; my $crstype = &Apache::loncommon::course_type(); @@ -292,7 +237,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); @@ -303,7 +248,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}, @@ -403,7 +348,7 @@ $contents{content}.' </div>'; } if ($contents{webreferences}) { - $content .= ' + $content .= ' <div class="LC_Box"> <h4 class="LC_hcell">'.&mt('Web References').'</h4>'. $contents{webreferences}.' @@ -413,10 +358,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); @@ -447,39 +392,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_/)) { @@ -501,18 +446,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}.'"'; @@ -527,36 +472,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) { @@ -573,63 +518,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)); } @@ -660,7 +605,7 @@ sub recurse_html { } else { $relfile = $dependency; $depurl = $currurlpath; - $depurl =~ s{[^/]+$}{}; + $depurl =~ s{[^/]+$}{}; $depurl .= $dependency; ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); } @@ -669,7 +614,7 @@ sub recurse_html { $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') { @@ -715,7 +660,7 @@ sub group_import { $url = $1; my $marker = $2; my $info = $3; - my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings); + my ($toolid,%toolhash,%toolsettings); my @extras = ('linktext','explanation','crslabel','crstitle','crsappend'); my @toolinfo = split(/:/,$info); if ($residx) { @@ -724,12 +669,6 @@ sub group_import { } else { $toolid = shift(@toolinfo); } - if ($toolid =~ /^c/) { - $tooltype = 'crs'; - $toolprefix = 'c'; - } else { - $tooltype = 'dom'; - } $toolid =~ s/\D//g; ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}, $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'}, @@ -743,130 +682,127 @@ sub group_import { $toolhash{'gradable'} =~ s/\D+//g; } if (ref($ltitoolsref) eq 'HASH') { - if (ref($ltitoolsref->{$tooltype}) eq 'HASH') { - if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') { - my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}}; - my @deleted; - $toolhash{'id'} = $toolprefix.$toolid; - if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') || - ($toolhash{'target'} eq 'window')) { - if ($toolhash{'target'} eq 'window') { - foreach my $item ('width','height') { - $toolhash{$item} =~ s/^\s+//; - $toolhash{$item} =~ s/\s+$//; - if ($toolhash{$item} =~ /\D/) { - delete($toolhash{$item}); - if ($residx) { - if ($toolsettings{$item}) { - push(@deleted,$item); - } + if (ref($ltitoolsref->{$toolid}) eq 'HASH') { + my @deleted; + $toolhash{'id'} = $toolid; + if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') || + ($toolhash{'target'} eq 'window')) { + if ($toolhash{'target'} eq 'window') { + foreach my $item ('width','height') { + $toolhash{$item} =~ s/^\s+//; + $toolhash{$item} =~ s/\s+$//; + if ($toolhash{$item} =~ /\D/) { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); } } } } - } elsif ($residx) { - $toolhash{'target'} = $toolsettings{'target'}; - if ($toolhash{'target'} eq 'window') { - foreach my $item ('width','height') { - $toolhash{$item} = $toolsettings{$item}; - } - } - } elsif (ref($tools{'display'}) eq 'HASH') { - $toolhash{'target'} = $tools{'display'}{'target'}; - if ($toolhash{'target'} eq 'window') { - $toolhash{'width'} = $tools{'display'}{'width'}; - $toolhash{'height'} = $tools{'display'}{'height'}; + } + } elsif ($residx) { + $toolhash{'target'} = $toolsettings{'target'}; + if ($toolhash{'target'} eq 'window') { + foreach my $item ('width','height') { + $toolhash{$item} = $toolsettings{$item}; } } - if ($toolhash{'target'} eq 'iframe') { - foreach my $item ('width','height','linktext','explanation') { - delete($toolhash{$item}); - if ($residx) { - if ($toolsettings{$item}) { - push(@deleted,$item); - } + } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') { + $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'}; + if ($toolhash{'target'} eq 'window') { + $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'}; + $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'}; + } + } + if ($toolhash{'target'} eq 'iframe') { + foreach my $item ('width','height','linktext','explanation') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); } } - } elsif ($toolhash{'target'} eq 'tab') { - foreach my $item ('width','height') { - delete($toolhash{$item}); - if ($residx) { - if ($toolsettings{$item}) { - push(@deleted,$item); - } + } + } elsif ($toolhash{'target'} eq 'tab') { + foreach my $item ('width','height') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); } } } - if (ref($tools{'crsconf'}) eq 'HASH') { - foreach my $item ('label','title','linktext','explanation') { - my $crsitem; - if (($item eq 'label') || ($item eq 'title')) { - $crsitem = 'crs'.$item; - } else { - $crsitem = $item; - } - if ($tools{'crsconf'}{$item}) { - $toolhash{$crsitem} =~ s/^\s+//; - $toolhash{$crsitem} =~ s/\s+$//; - if ($toolhash{$crsitem} eq '') { - delete($toolhash{$crsitem}); - } - } else { + } + if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') { + foreach my $item ('label','title','linktext','explanation') { + my $crsitem; + if (($item eq 'label') || ($item eq 'title')) { + $crsitem = 'crs'.$item; + } else { + $crsitem = $item; + } + if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) { + $toolhash{$crsitem} =~ s/^\s+//; + $toolhash{$crsitem} =~ s/\s+$//; + if ($toolhash{$crsitem} eq '') { delete($toolhash{$crsitem}); } - if (($residx) && (exists($toolsettings{$crsitem}))) { - unless (exists($toolhash{$crsitem})) { - push(@deleted,$crsitem); - } - } + } else { + delete($toolhash{$crsitem}); } - } - if ($toolhash{'passback'}) { - my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4); - $toolhash{'gradesecret'} = $gradesecret; - $toolhash{'gradesecretdate'} = time; - } - if ($toolhash{'roster'}) { - my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4); - $toolhash{'rostersecret'} = $rostersecret; - $toolhash{'rostersecretdate'} = time; - } - my $changegradable; - if (($residx) && ($folder =~ /^default/)) { - if ($toolsettings{'gradable'}) { - unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) { - push(@deleted,'gradable'); - $changegradable = 1; + if (($residx) && (exists($toolsettings{$crsitem}))) { + unless (exists($toolhash{$crsitem})) { + push(@deleted,$crsitem); } - } elsif ($toolhash{'gradable'}) { - $changegradable = 1; } - if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) { + } + } + if ($toolhash{'passback'}) { + my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4); + $toolhash{'gradesecret'} = $gradesecret; + $toolhash{'gradesecretdate'} = time; + } + if ($toolhash{'roster'}) { + my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4); + $toolhash{'rostersecret'} = $rostersecret; + $toolhash{'rostersecretdate'} = time; + } + my $changegradable; + if (($residx) && ($folder =~ /^default/)) { + if ($toolsettings{'gradable'}) { + unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) { + push(@deleted,'gradable'); $changegradable = 1; - if ($toolsettings{'gradable'}) { - $toolhash{'gradable'} = 1; - } } + } elsif ($toolhash{'gradable'}) { + $changegradable = 1; } - my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum); - if ($putres eq 'ok') { - if (@deleted) { - &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum); + if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) { + $changegradable = 1; + if ($toolsettings{'gradable'}) { + $toolhash{'gradable'} = 1; } - if (($changegradable) && ($folder =~ /^default/)) { - my $val; - if ($toolhash{'gradable'}) { - $val = 'yes'; - } else { - $val = 'no'; - } - &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val, - 'string_yesno'); - &remember_parms($residx,'gradable','set',$val); + } + } + my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum); + if ($putres eq 'ok') { + if (@deleted) { + &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum); + } + if (($changegradable) && ($folder =~ /^default/)) { + my $val; + if ($toolhash{'gradable'}) { + $val = 'yes'; + } else { + $val = 'no'; } - } else { - return (&mt('Failed to save update to external tool.'),1); + &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val, + 'string_yesno'); + &remember_parms($residx,'gradable','set',$val); } + } else { + return (&mt('Failed to save update to external tool.'),1); } } } @@ -883,7 +819,7 @@ sub group_import { } 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); + \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps); $importuploaded = 1; } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) { next if ($allmaps->{$url}); @@ -896,27 +832,26 @@ sub group_import { } my $ext = 'false'; if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } + $name = &LONCAPA::map::qtunescape($name); + if ($name eq '') { + $name = &LONCAPA::map::qtunescape(&mt('Web Page')); + } if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) { my $filepath = $1; - my $fname; - if ($name eq '') { - $name = &mt('Web Page'); + my $fname = $name; + if ($fname =~ /^\W+$/) { $fname = 'web'; } else { - $fname = $name; - $fname=&Apache::lonnet::clean_filename($fname); - if ($fname eq '') { - $fname = 'web'; - } elsif (length($fname) > 15) { - $fname = substr($fname,0,14); - } + $fname =~ s/\W/_/g; + } + if (length($fname) > 15) { + $fname = substr($fname,0,14); } - my $title = &Apache::loncommon::cleanup_html($name); my $initialtext = &mt('Replace with your own content.'); my $newhtml = <<END; <html> <head> -<title>$title</title> +<title>$name</title> </head> <body bgcolor="#ffffff"> $initialtext @@ -938,7 +873,6 @@ END return (&mt('Failed to save new web page.'),1); } } - $name = &LONCAPA::map::qtunescape($name); $url = &LONCAPA::map::qtunescape($url); $LONCAPA::map::resources[$residx] = join(':', ($name, $url, $ext, 'normal', 'res')); @@ -950,7 +884,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 = @@ -979,6 +913,7 @@ END &storemap($coursenum, $coursedom, $folder.'.'.$container,1); unless ($fatal) { if ($folder =~ /^supplemental/) { + &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); my ($errtext,$fatal) = &mapread($coursenum,$coursedom, $folder.'.'.$container); } @@ -1050,7 +985,7 @@ 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". @@ -1083,7 +1018,7 @@ sub docs_change_log { if ($supplementalflag) { $tid = 2; } - my ($breadcrumbtrail) = + my ($breadcrumbtrail) = &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1); $r->print($breadcrumbtrail. &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto, @@ -1212,13 +1147,7 @@ sub docs_change_log { } $r->print('</ul>'); if ($docslog{$id}{'logentry'}{'parameter_res'}) { - my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3); - if ($title eq '') { - ($title) = ($url =~ m{/([^/]+)$}); - } elsif ($is_supp) { - $title = &Apache::loncommon::parse_supplemental_title($title); - } - $r->print(&LONCAPA::map::qtescape($title).':<ul>'); + $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>'); foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') { if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) { # FIXME: internationalization seems wrong here @@ -1287,19 +1216,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; + } } } @@ -1308,7 +1231,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); @@ -1321,13 +1244,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 '') { @@ -1424,7 +1341,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 ++; @@ -1524,7 +1441,7 @@ sub print_paste_buffer { } $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>'; if ($nopaste) { - $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>'; + $pasteitems .= $nopaste; } else { if ($othercrs) { $pasteitems .= $othercrs; @@ -1547,7 +1464,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); @@ -1724,7 +1641,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; } @@ -1780,7 +1697,7 @@ sub do_paste_from_buffer { 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/) { @@ -1823,7 +1740,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; @@ -1832,7 +1749,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/)) { @@ -1872,7 +1789,7 @@ 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 domain.', + 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.', ); @@ -1901,7 +1818,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) { @@ -1914,18 +1838,11 @@ 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); @@ -1967,7 +1884,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 @@ -1991,7 +1908,7 @@ sub do_paste_from_buffer { cnum => $coursenum, ); if ($prefix eq 'ext.tool') { - if ($prefixchg{$suffix} eq 'docstosupp') { + if ($prefixchg{$suffix} eq 'docstosupp') { $info{'delgradable'} = 1; } } @@ -2003,7 +1920,7 @@ sub do_paste_from_buffer { } } unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) { - my (%lockerr,$msg); + my (%lockerr,$msg); my ($newurl,$result,$errtext) = &dbcopy(\%info,$coursedom,$coursenum,\%lockerr); if ($result eq 'ok') { @@ -2023,7 +1940,7 @@ sub do_paste_from_buffer { next; } if ($lockerr{$prefix}) { - $lockerrs{$suffix} = $lockerr{$prefix}; + $lockerrs{$suffix} = $lockerr{$prefix}; } } } @@ -2063,7 +1980,7 @@ sub do_paste_from_buffer { $newdocsdir = 'default'; } if (($prefixchg{$suffix}) || - ($srcdom{$suffix} ne $coursedom) || + ($srcdom{$suffix} ne $coursedom) || ($srcnum{$suffix} ne $coursenum) || ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) { my $newpath = "$newprefix/$newdocsdir/$newidx/$rem"; @@ -2087,7 +2004,7 @@ sub do_paste_from_buffer { $coursedom,$coursenum,$template,$newidx,"$folder.$container"); } } elsif ($url =~ /ext\.tool$/) { - if (($newidx) && ($folder=~/^default/)) { + if (($newidx) && ($folder=~/^default/)) { my $marker = (split(m{/},$url))[4]; my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); my $val = 'no'; @@ -2111,8 +2028,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, @@ -2292,7 +2209,7 @@ sub dbcopy { 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]; @@ -2336,7 +2253,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'}); } @@ -2411,9 +2328,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; @@ -2532,9 +2447,8 @@ sub contained_map_check { $addedmaps->{$ressrc} = [$url]; } } - &contained_map_check($ressrc,$folder,$coursenum,$coursedom, - $removefrommap,$removeparam, - $addedmaps,$hierarchy,$titles,$allmaps); + &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap, + $removeparam,$addedmaps,$hierarchy,$titles,$allmaps); } } elsif ($token->[1] eq 'param') { if ($folder =~ /^supplemental/) { @@ -2585,7 +2499,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)/(.+)$}) { @@ -2643,7 +2557,7 @@ sub url_paste_fixups { my $rem = $3; my ($is_exttool,$exttoolchg); if ($rem =~ m{\d+/ext\.tool$}) { - $is_exttool = 1; + $is_exttool = 1; } if (($srcdom ne $cdom) || ($srcnum ne $cnum)) { $rewrites->{$oldurl}{$id} = $ressrc; @@ -2654,7 +2568,7 @@ sub url_paste_fixups { if ($is_exttool) { $exttoolchg = 1; } - } elsif (($is_exttool) && + } elsif (($rem =~ m{\d+/ext\.tool$}) && ($env{'form.docs.markedcopy_options'} ne 'move')) { $dbcopies->{$oldurl}{$id}{'src'} = $ressrc; $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom; @@ -2830,15 +2744,6 @@ sub apply_fixups { $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; } my $mapcontent = &Apache::lonnet::getfile($key); - if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') && - ($after{'map'} eq 'default') && - ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) { - $mapcontent = '<map>'."\n". - '<resource id="1" src="" type="start" />'."\n". - '<link from="1" to="2" index="1" />'."\n". - '<resource id="2" src="" type="finish" />'."\n". - '</map>'; - } if ($mapcontent eq '-1') { if (ref($errors) eq 'HASH') { $errors->{$key} = 1; @@ -2897,7 +2802,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'}; @@ -2907,18 +2814,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); } @@ -3121,7 +3025,7 @@ sub update_parameter { my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]); $name=&LONCAPA::map::qtescape($name); $url=&LONCAPA::map::qtescape($url); - next unless $url; + next unless ($name && $url); my $is_map; if ($url =~ m{/uploaded/.+\.(page|sequence)$}) { $is_map = 1; @@ -3129,7 +3033,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}) { @@ -3181,8 +3085,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; @@ -3191,24 +3095,23 @@ 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 { my ($coursenum,$coursedom) =@_; my $haschanges = 0; if ($env{'form.cmd'} eq '') { - return $haschanges; + return $haschanges; } my ($cmd,$idx)=split('_',$env{'form.cmd'}); @@ -3246,6 +3149,23 @@ sub handle_edit_cmd { my $renamed_url=&LONCAPA::map::qtescape($url); &Apache::lonnet::devalidate_title_cache($renamed_url); $haschanges = 1; + } elsif ($cmd eq 'setalias') { + my $newvalue = $env{'form.alias'}; + if ($newvalue ne '') { + unless (Apache::lonnet::get_symb_from_alias($newvalue)) { + &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue, + 'string'); + &remember_parms($idx,'mapalias','set',$newvalue); + $haschanges = 1; + } + } + } elsif ($cmd eq 'delalias') { + my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0]; + if ($current ne '') { + &LONCAPA::map::delparameter($idx,'parameter_0_mapalias'); + &remember_parms($idx,'mapalias','del'); + $haschanges = 1; + } } return $haschanges; } @@ -3285,10 +3205,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); } @@ -3371,7 +3291,7 @@ sub editor { # Rename, cut, copy or remove a single resource if (&handle_edit_cmd($coursenum,$coursedom)) { my $contentchg; - if ($env{'form.cmd'} =~ m{^(remove|cut)_}) { + if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) { $contentchg = 1; } ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg); @@ -3557,21 +3477,6 @@ sub editor { $r->print('</div>'); } - if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) { - my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); - if (ref($supplemental) eq 'HASH') { - if ((ref($supplemental->{'hidden'}) eq 'HASH') && - (ref($supplemental->{'ids'}) eq 'HASH')) { - if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') { - my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0]; - if ($supplemental->{'hidden'}->{$mapnum}) { - $ishidden = 1; - } - } - } - } - } - my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups); %filters = ( canremove => [], @@ -3595,17 +3500,11 @@ sub editor { push(@allmapidx,$res); } - if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) { - if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) { - $idx++; - next; - } - } $output .= &entryline($idx,$name,$url,$folder,$allowed,$res, $coursenum,$coursedom,$crstype, $pathitem,$supplementalflag,$container, \%filters,\%curr_groups,$ltitoolsref,$canedit, - $isencrypted,$ishidden,$navmapref,$hostname); + $isencrypted,$navmapref,$hostname); $idx++; $shown++; } @@ -3614,14 +3513,10 @@ sub editor { my $need_save; if ($allowed || ($supplementalflag && $folder eq 'supplemental')) { my $toolslink; - if ($allowed || $canedit) { - my $helpitem = 'Navigation_Screen'; - if (!$allowed) { - $helpitem = 'Supplemental_Navigation'; - } + if ($allowed) { $toolslink = '<table><tr><td>' .&Apache::loncommon::help_open_menu('Navigation Screen', - $helpitem,undef,'RAT') + 'Navigation_Screen',undef,'RAT') .'</td><td class="LC_middle">'.&mt('Tools:').'</td>' .'<td align="left"><ul id="LC_toolbar">' .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" ' @@ -3636,10 +3531,12 @@ sub editor { .&Apache::loncommon::start_data_table(undef,'contentlist') .&Apache::loncommon::start_data_table_header_row() .'<th colspan="2">'.&mt('Move').'</th>' - .'<th colspan="2">'.&mt('Actions').'</th>' - .'<th>'.&mt('Document').'</th>' - .'<th colspan="2">'.&mt('Settings').'</th>' - .&Apache::loncommon::end_data_table_header_row(); + .'<th colspan="3">'.&mt('Actions').'</th>' + .'<th>'.&mt('Document').'</th>'; + if ($folder !~ /^supplemental/) { + $to_show .= '<th colspan="2">'.&mt('Settings').'</th>'; + } + $to_show .= &Apache::loncommon::end_data_table_header_row(); if ($folder !~ /^supplemental/) { $lists{'canhide'} = join(',',@allidx); $lists{'canrandomlyorder'} = join(',',@allmapidx); @@ -3665,8 +3562,7 @@ sub editor { '<td>'. &multiple_check_form('actions',\%lists,$canedit). '</td>'. - '<td> </td>'. - '<td> </td>'. + '<td colspan="3"> </td>'. '<td colspan="2">'. &multiple_check_form('settings',\%lists,$canedit). '</td>'. @@ -3691,7 +3587,7 @@ sub editor { } my $noresmsg; if ($allowed && $hiddentop && !$supplementalflag) { - $noresmsg = &mt('Main Content Hidden'); + $noresmsg = &mt('Main Content Hidden'); } else { $noresmsg = &mt('Currently empty'); } @@ -3736,7 +3632,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.'">'. @@ -3774,7 +3670,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"; } @@ -3816,6 +3712,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'}) { @@ -3905,7 +3803,7 @@ sub process_file_upload { my $uploadphase = 'upload_embedded'; my $primaryurl = &HTML::Entities::encode($url,'<>&"'); my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); - my ($embedded,$num) = + my ($embedded,$num) = &Apache::loncommon::ask_for_embedded_content( '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url}); if ($embedded) { @@ -3986,14 +3884,12 @@ sub is_supplemental_title { sub entryline { my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom, $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups, - $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_; - my ($foldertitle,$renametitle,$oldtitle,$encodedtitle); + $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_; + my ($foldertitle,$renametitle,$oldtitle); if (&is_supplemental_title($title)) { ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title); - $encodedtitle=$title; } else { $title=&HTML::Entities::encode($title,'"<>&\''); - $encodedtitle=$title; $renametitle=$title; $foldertitle=$title; } @@ -4011,11 +3907,11 @@ 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 - my ($esc_path, $path, $symb, $shownsymb); + my ($esc_path, $path, $symb, $curralias); if ($env{'form.folderpath'}) { $esc_path=&escape($env{'form.folderpath'}); $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); @@ -4084,6 +3980,8 @@ END 'ct' => 'Cut', 'rn' => 'Rename', 'cp' => 'Copy', + 'da' => 'Unset alias', + 'sa' => 'Set alias', 'ex' => 'External Resource', 'et' => 'External Tool', 'ed' => 'Edit', @@ -4091,7 +3989,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'}, @@ -4114,6 +4012,9 @@ END ($url!~/$LONCAPA::assess_page_seq_re/)) { $confirm_removal = 1; } + if ($url =~ /$LONCAPA::assess_re/) { + $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0]; + } if ($denied{'copy'}) { $copylink=(<<ENDCOPY) @@ -4215,7 +4116,6 @@ END my $ispage; my $containerarg; my $folderurl; - my $plainurl; if ($uploaded) { if (($extension eq 'sequence') || ($extension eq 'page')) { $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/; @@ -4234,26 +4134,18 @@ END $url='/adm/supplemental?'; } } else { - $plainurl = $url; + &Apache::lonnet::allowuploaded('/adm/coursedoc',$url); } } 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); @@ -4264,30 +4156,51 @@ 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+/ext\.tool$}) { + $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()) || (&Apache::lonnet::waf_allssl($hostname))) { - $url .= '?usehttp=1'; - } + $url .= '?usehttp=1'; $nomodal = 1; } - } - my ($checkencrypt,$shownurl); - if (!$env{'request.role.adv'}) { + } + if (&Apache::lonnet::symbverify($symb,$url)) { + my $shownsymb = $symb; + if ($isexternal) { + if ($url =~ /^([^#]+)#([^#]+)$/) { + $url = $1; + $anchor = $2; + if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) { + $shownsymb = $1.&escape('#').$anchor; + } + } + } + unless ($env{'request.role.adv'}) { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $url = ''; + } + if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) { + $url = ''; + $hiddenres = 1; + } + } + if ($url ne '') { + $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb); + } + } elsif (!$env{'request.role.adv'}) { + my $checkencrypt; if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) || - ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) { + $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) { $checkencrypt = 1; } elsif (ref($navmapref)) { unless (ref($$navmapref)) { @@ -4295,43 +4208,26 @@ END } if (ref($$navmapref)) { if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') { - $checkencrypt = 1; + $checkencrypt = 1; } } } - } - if ($checkencrypt) { - my $currenc = $env{'request.enc'}; - $env{'request.enc'} = 1; - $shownsymb = &Apache::lonenc::encrypted($symb); - $shownurl = &Apache::lonenc::encrypted($url); - if (&Apache::lonnet::symbverify($symb,$url)) { - $url = $shownurl; - } else { - $url = ''; - } - $env{'request.enc'} = $currenc; - } elsif (&Apache::lonnet::symbverify($symb,$url)) { - $shownsymb = $symb; - if ($isexternal) { - $url =~ s/\#[^#]+$//; - if ($container eq 'page') { - $url = &Apache::lonnet::clutter($url); + if ($checkencrypt) { + my $shownsymb = &Apache::lonenc::encrypted($symb); + my $shownurl = &Apache::lonenc::encrypted($url); + if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) { + $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb); + if ($env{'request.enc'} ne '') { + delete($env{'request.enc'}); + } + } else { + $url=''; } + } else { + $url=''; } - $shownurl = $url; - } - unless ($env{'request.role.adv'}) { - if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { - $url = ''; - } - if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) { - $url = ''; - $hiddenres = 1; - } - } - if ($url ne '') { - $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb); + } else { + $url=''; } } } elsif ($supplementalflag) { @@ -4340,11 +4236,8 @@ END $url = $1; $anchor = $2; if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) { - unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { - if ($hostname ne '') { - $url = 'http://'.$hostname.$url; - } - $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; } $nomodal = 1; } @@ -4352,30 +4245,12 @@ 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()) || (&Apache::lonnet::waf_allssl($hostname))) { - if ($hostname ne '') { - $url = 'http://'.$hostname.$url; - } - $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; $nomodal = 1; } - } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) { - my $embstyle=&Apache::loncommon::fileembstyle($extension); - unless ($embstyle eq 'ssi') { - if (($embstyle eq 'img') - || ($embstyle eq 'emb') - || ($embstyle eq 'wrp')) { - $url='/adm/wrapper'.$url; - } elsif ($url !~ /\.(sequence|page)$/) { - $url='/adm/coursedocs/showdoc'.$url; - } - } - } - unless ($allowed && $env{'request.role.adv'}) { - if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { - $hiddenres = 1; - } } } my ($rand_pick_text,$rand_order_text,$hiddenfolder); @@ -4387,9 +4262,6 @@ END if (!$allowed && $supplementalflag) { $folderpath.=$containerarg.'&'.$foldername; $url.='folderpath='.&escape($folderpath); - if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { - $hiddenfolder = 1; - } } else { my $rpicknum = (&LONCAPA::map::getparameter($orderidx, 'parameter_randompick'))[0]; @@ -4409,7 +4281,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; } @@ -4428,7 +4300,7 @@ 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); @@ -4464,7 +4336,7 @@ $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; @@ -4475,7 +4347,7 @@ $form_end; $url .= ($url =~ /\?/) ? '&':'?'; $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"'); if ($title) { - $url .= '&title='.$encodedtitle; + $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"'); } if ((($isexternal) || ($isexttool)) && $orderidx) { $url .= '&idx='.$orderidx; @@ -4486,10 +4358,10 @@ $form_end; } my ($tdalign,$tdwidth); if ($allowed) { - my $fileloc = + my $fileloc = &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url)); if ($isexternal) { - ($editlink,$extresform) = + ($editlink,$extresform) = &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem, undef,undef,undef,undef,undef,undef, undef,$disabled); @@ -4506,11 +4378,11 @@ $form_end; if ($supplementalflag) { $suppanchor = $anchor; } - my $jscall = + my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home, $switchserver, $forceedit, - undef,$symb,$shownsymb, + undef,$symb, &escape($env{'form.folderpath'}), $renametitle,$hostname, '','',1,$suppanchor); @@ -4530,18 +4402,20 @@ $form_end; $reinit = &mt('(re-initialize course to access)'); } $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink; - my ($link,$nolink); - if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { - if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) { - if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { - $nolink = 1; - } - } - if ($nolink) { - $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>'; + if ($orig_url =~ /$LONCAPA::assess_re/) { + $line.= '<br />'; + if ($curralias ne '') { + $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'. + $lt{'da'}.'</a></span>'; } else { - $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>'; + $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'. + $lt{'sa'}.'</a></span>'; } + } + $line.='</td><td>'; + my $link; + if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { + $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>'; } elsif ($url) { if ($anchor ne '') { if ($supplementalflag) { @@ -4555,15 +4429,9 @@ $form_end; } else { $link = $url; } - $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor); - if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) { - if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { - $nolink = 1; - } - } - if ($nolink) { - $line.='<img src="'.$icon.'" alt="" class="LC_icon" />'; - } elsif ($nomodal) { + $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>'; } else { @@ -4575,26 +4443,9 @@ $form_end; } $line.='</span></td><td'.$tdwidth.'>'; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { - if ($nolink) { - $line.=$title; - } else { - $line.='<a href="'.$url.'">'.$title.'</a>'; - } - if (!$allowed && $supplementalflag && $canedit && $isfolder) { - my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png'; - my $editurl = $url; - $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&}; - $line .= ' '.'<a href="'.$editurl.'">'. - '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'. - '</a>'; - } - if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) { - $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> '; - } + $line.='<a href="'.$url.'">'.$title.'</a>'; } elsif ($url) { - if ($nolink) { - $line.=$title; - } elsif ($nomodal) { + 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;" />'. $title.'</a>'; } else { @@ -4605,45 +4456,40 @@ $form_end; } else { $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>'; } - $line.="$extresform</td>"; + if (($allowed) && ($curralias ne '')) { + $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>'; + } else { + $line .= $extresform; + } + $line .= '</td>'; $rand_pick_text = ' ' if ($rand_pick_text eq ''); $rand_order_text = ' ' if ($rand_order_text eq ''); - if ($uploaded && $url && !$isfolder && !$ispage) { - if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) { - &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl); + if (($allowed) && ($folder!~/^supplemental/)) { + my %lt=&Apache::lonlocal::texthash( + 'hd' => 'Hidden', + 'ec' => 'URL hidden'); + my ($enctext,$hidtext); + if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) { + $enctext = ' checked="checked"'; + if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) { + push(@{$filtersref->{'encrypturl'}},$orderidx); + } } - } - if ($allowed) { - my %lt=&Apache::lonlocal::texthash( - 'hd' => 'Hidden', - 'ec' => 'URL hidden'); - my ($enctext,$hidtext,$formhidden,$formurlhidden); if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { $hidtext = ' checked="checked"'; - if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) { + if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) { push(@{$filtersref->{'hiddenresource'}},$orderidx); } } - $formhidden = 'edit_hiddenresource_'.$orderidx; - $line.=(<<ENDPARMS); + my $formhidden = 'edit_hiddenresource_'.$orderidx; + my $formurlhidden = 'edit_encrypturl_'.$orderidx; + $line.=(<<ENDPARMS); <td class="LC_docs_entry_parameter"> <form action="/adm/coursedocs" method="post" name="$formhidden"> $form_param $form_common <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label> $form_end -ENDPARMS - if ($folder =~/^supplemental/) { - $line.= "\n <td>"; - } else { - if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) { - $enctext = ' checked="checked"'; - if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) { - push(@{$filtersref->{'encrypturl'}},$orderidx); - } - } - $formurlhidden = 'edit_encrypturl_'.$orderidx; - $line.=(<<ENDPARMS); <br /> <form action="/adm/coursedocs" method="post" name="$formurlhidden"> $form_param @@ -4654,7 +4500,6 @@ ENDPARMS <td class="LC_docs_entry_parameter">$rand_pick_text<br /> $rand_order_text</td> ENDPARMS - } } $line.=&Apache::loncommon::end_data_table_row(); return $line; @@ -4769,9 +4614,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.'); } @@ -4967,48 +4812,6 @@ 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::get_requested_shorturls($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(); @@ -5023,7 +4826,7 @@ sub contentverifyform { &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="submit" value="'.&mt('Verify content').' "/>'. '<input type="hidden" value="1" name="tools" />'. '<input type="hidden" value="1" name="verify" /></p></form>'); $r->print(&endContentScreen()); @@ -5060,7 +4863,6 @@ sub verifycontent { $r->print(&endContentScreen()); } - sub devalidateversioncache { my $src=shift; &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'. @@ -5124,8 +4926,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 { @@ -5257,7 +5059,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>'. @@ -5300,9 +5102,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; @@ -5380,17 +5182,13 @@ sub changewarning { if (!defined($message)) { $message='Changes will become active for your current session after [_1], or the next time you log in.'; } - my $windowname = 'loncapaclient'; - if ($env{'request.lti.login'}) { - $windowname .= 'lti'; - } $r->print("\n\n". '<script type="text/javascript">'."\n". '// <![CDATA['."\n". 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n". '// ]]>'."\n". '</script>'."\n". -'<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'. +'<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'. '<input type="hidden" name="orgurl" value="'.$url. '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'. &mt($message,' <input type="hidden" name="'. @@ -5443,6 +5241,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"; @@ -5480,6 +5279,9 @@ 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').'/'); @@ -5488,7 +5290,7 @@ sub handler { 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', + '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') { @@ -5506,21 +5308,18 @@ 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); -# does this user have privileges to modify content. - if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { + my ($allowed,$canedit,$canview,$noendpage,$disabled); # URI is /adm/supplemental when viewing supplemental docs in non-edit mode. - unless ($r->uri eq '/adm/supplemental') { + unless ($r->uri eq '/adm/supplemental') { + # does this user have privileges to modify content. + if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { $allowed = 1; - } - $canedit = 1; - $canview = 1; - } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) { -# URI is /adm/supplemental when viewing supplemental docs in non-edit mode. - unless ($r->uri eq '/adm/supplemental') { + $canedit = 1; + $canview = 1; + } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) { $allowed = 1; + $canview = 1; } - $canview = 1; } unless ($canedit) { $disabled = ' disabled="disabled"'; @@ -5548,9 +5347,6 @@ sub handler { } 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'}; @@ -5564,17 +5360,66 @@ 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 # Get the parameters that may be needed # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['folderpath','title', + ['folderpath', 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); @@ -5593,7 +5438,7 @@ sub handler { if ($env{'form.symb'}) { my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'}); - unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { + unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { delete($env{'form.symb'}); } } @@ -5621,13 +5466,34 @@ sub handler { if ($env{'form.tools'}) { $toolsflag=1; } if ($env{'form.folderpath'} ne '') { - &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom); + 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'}); + } } - my $backto_supppath; if ($env{'form.supppath'} ne '') { - if ($supplementalflag && $allowed) { - $backto_supppath = &validate_supppath($coursenum,$coursedom); + 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'}); } } @@ -5638,7 +5504,6 @@ sub handler { my $containertag; my $pathitem; my %ltitools; - my $posslti; my $hiddentop; my $navmap; my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) }; @@ -5650,10 +5515,10 @@ sub handler { &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap); &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}.'_'.$env{'form.symb'}}); - } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) { + } elsif ($env{'form.supppath'} ne '') { $env{'form.folderpath'}=$env{'form.supppath'}; &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => - $env{'form.command'}.'_'.$backto_supppath}); + $env{'form.command'}.'_'.$env{'form.supppath'}}); } } elsif ($env{'form.command'} eq 'editdocs') { $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap); @@ -5681,16 +5546,13 @@ 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'); } } else { undef($env{'form.folderpath'}); } - if ($env{'form.folderpath'} ne '') { - &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom); - } } # If we are not allowed to make changes, all we can see are supplemental docs @@ -5705,89 +5567,36 @@ sub handler { .'&'. $env{'form.folderpath'}; } -# If allowed and user's role is not advanced check folderpath is not hidden - my $hidden_and_empty; - if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) { - my ($folderurl,$foldername,$hiddenfolder); +# 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'}); my $folder = $pathitems[-2]; if ($folder eq '') { 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'; } - if ($supplementalflag) { - ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/); - $foldername = &HTML::Entities::decode(&unescape($foldername)); - my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); - if (ref($supplemental) eq 'HASH') { - my ($suppmap,$suppmapnum); - if ($folder eq 'supplemental') { - $suppmap = 'default'; - $suppmapnum = 0; - } elsif ($folder =~ /^supplemental_(\d+)$/) { - $suppmap = $1; - $suppmapnum = $suppmap; - } - if ($hiddenfolder) { - my $hascontent; - foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) { - if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) { - $hascontent = 1; - } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') { - foreach my $id (@{$supplemental->{'ids'}->{$key}}) { - if ($id =~ /^$suppmapnum\:/) { - $hascontent = 1; - last; - } - } - } - last if ($hascontent); - } - unless ($hascontent) { - if ($foldername ne '') { - $hidden_and_empty = $foldername; - } else { - $hidden_and_empty = $folder; - } - } - } - } - } else { - unless (ref($navmap)) { - $navmap = Apache::lonnavmaps::navmap->new(); - } - ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/); - $foldername = &HTML::Entities::decode(&unescape($foldername)); - if (ref($navmap)) { - if ($hiddenfolder || - (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) { - my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1); - unless (@resources) { - if ($foldername ne '') { - $hidden_and_empty = $foldername; - } else { - $hidden_and_empty = $folder; - } - } - } - } + unless (ref($navmap)) { + $navmap = Apache::lonnavmaps::navmap->new(); } - if ($hidden_and_empty ne '') { - splice(@pathitems,-2); - if (@pathitems) { - $env{'form.folderpath'} = join('&',@pathitems); - } else { - undef($env{'form.folderpath'}); + if (ref($navmap)) { + if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') { + my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1); + unless (@resources) { + undef($env{'form.folderpath'}); + } } } } } + # If after all of this, we still don't have any paths, make them unless ($env{'form.folderpath'}) { if ($supplementalflag) { @@ -5872,34 +5681,17 @@ sub handler { } } my $tabidstr = join("','",@tabids); - my (%domtools,%crstools); - my %tooltypes = &Apache::loncommon::usable_exttools(); - if ($tooltypes{'dom'}) { - %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer'); - } - if ($tooltypes{'crs'}) { - %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer'); - } - %ltitools = ( - dom => \%domtools, - crs => \%crstools, - ); - $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools)); + %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer'); + 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). &Apache::lonextresedit::extedit_javascript(\%ltitools); - my $onload = "javascript:resize_scrollbox('contentscroll','1','1');"; - if ($hidden_and_empty ne '') { - my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'", - $hidden_and_empty); - $onload .= "javascript:alert('".&js_escape($alert)."');"; - } $addentries = { - onload => $onload, + onload => "javascript:resize_scrollbox('contentscroll','1','1');", }; } $script .= &paste_popup_js(); @@ -5914,21 +5706,15 @@ 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(); if ($showdoc) { - my $args; - if ($supplementalflag) { - my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&'); - my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); - $args = {'bread_crumbs' => $brcrum}; - } else { - $args = {'force_register' => $showdoc}; - } - $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args)); + $r->print(&Apache::loncommon::start_page("$crstype documents",undef, + {'force_register' => $showdoc,})); } elsif ($toolsflag) { my ($breadtext,$breadtitle); $breadtext = "$crstype Editor"; @@ -5946,12 +5732,6 @@ sub handler { $breadtitle) ); } elsif ($r->uri eq '/adm/supplemental') { - unless ($env{'request.role.adv'}) { - unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) { - $r->internal_redirect('/adm/navmaps'); - return OK; - } - } my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype); $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef, {'bread_crumbs' => $brcrum,})); @@ -5982,7 +5762,6 @@ sub handler { my %codebase = (); my ($upload_result,$upload_output,$uploadphase); if ($canedit) { - undef($suppchanges); if (($env{'form.uploaddoc.filename'}) && ($env{'form.cmd'}=~/^upload_(\w+)/)) { my $context = $1; @@ -5994,10 +5773,6 @@ sub handler { if ($hadchanges) { &mark_hash_old(); } - if ($suppchanges) { - &Apache::lonnet::update_supp_caches($coursedom,$coursenum); - undef($suppchanges); - } $r->print($upload_output); } elsif ($env{'form.phase'} eq 'upload_embedded') { # Process file upload - phase two - upload embedded objects @@ -6010,7 +5785,7 @@ sub handler { my ($destination,$dir_root) = &embedded_destination(); my $url_root = '/uploaded/'.$docudom.'/'.$docuname; my $actionurl = '/adm/coursedocs'; - my ($result,$flag) = + my ($result,$flag) = &Apache::loncommon::upload_embedded('coursedoc',$destination, $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state, $actionurl); @@ -6021,11 +5796,11 @@ sub handler { my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; my ($destination,$dir_root) = &embedded_destination(); - my $result = + my $result = &Apache::loncommon::modify_html_refs('coursedoc',$destination, $docuname,$docudom,undef, $dir_root); - $r->print($result.&return_to_editor()); + $r->print($result.&return_to_editor()); } elsif ($env{'form.phase'} eq 'decompress_uploaded') { $uploadphase = 'decompress_phase_one'; $r->print(&decompression_phase_one(). @@ -6051,6 +5826,7 @@ 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', 'selm' => 'Select Map', @@ -6062,6 +5838,9 @@ sub handler { 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', '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', @@ -6075,20 +5854,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'}) { @@ -6119,7 +5910,10 @@ sub handler { my $fileupload=(<<FIUP); $quotainfo $lt{'file'}:<br /> + <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled /> + <input type="hidden" id="free_space" value="$free_space" /> FIUP + my $checkbox=(<<CHBO); <!-- <label>$lt{'parse'}? <input type="checkbox" name="parserflag" /> @@ -6139,8 +5933,6 @@ CHBO <fieldset id="uploadimsform" style="display: none;"> <legend>$lt{'imsf'}</legend> $fileupload - <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled /> - <input type="hidden" id="LC_free_space_ims" value="$free_space" /> <br /> <p> $lt{'cms'}: @@ -6166,9 +5958,7 @@ IMSFORM <fieldset id="uploaddocform" style="display: none;"> <legend>$lt{'upfi'}</legend> <input type="hidden" name="active" value="aa" /> - $fileupload - <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled /> - <input type="hidden" id="LC_free_space" value="$free_space" /> + $fileupload <br /> $lt{'title'}:<br /> <input type="text" size="60" name="comment" $disabled /> @@ -6186,7 +5976,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'})."');"; } @@ -6207,10 +5997,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'})."')"; } @@ -6219,8 +6032,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, @@ -6250,6 +6066,11 @@ SEDFFORM <input type="hidden" name="copyfolder" /> $containertag </form> + <form name="aliasform" method="post" action="/adm/coursedocs"> + <input type="hidden" name="alias" /> + <input type="hidden" name="cmd" /> + $containertag + </form> HIDDENFORM $r->print(&makesimpleeditform($pathitem)."\n". @@ -6272,9 +6093,8 @@ HIDDENFORM } # - - my $savefolderpath; my $hostname = $r->hostname(); + my $savefolderpath; if ($allowed) { my $folder=$env{'form.folder'}; @@ -6287,13 +6107,9 @@ HIDDENFORM } my $postexec=''; if ($folder eq 'default') { - my $windowname = 'loncapaclient'; - if ($env{'request.lti.login'}) { - $windowname .= 'lti'; - } $r->print('<script type="text/javascript">'."\n" .'// <![CDATA['."\n" - .'this.window.name="$windowname";'."\n" + .'this.window.name="loncapaclient";'."\n" .'// ]]>'."\n" .'</script>'."\n" ); @@ -6415,7 +6231,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; @@ -6470,26 +6503,20 @@ NSYLFORM $help{'Group Portfolio'} </form> NGFFORM - if ($container eq 'page') { - @specialdocumentsforma=( - {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform}, - ); - } else { - @specialdocumentsforma=( + @specialdocumentsforma=( {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform}, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform}, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform}, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform}, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform}, - ); - } + ); $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma)); my @importdoc = ( {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform} ); - if ($posslti) { + if (keys(%ltitools)) { push(@importdoc, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform}, ); @@ -6508,7 +6535,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)); @@ -6525,11 +6552,11 @@ my %orderhash = ( 'aa' => ['Upload',$fileuploadform], 'bb' => ['Import',$importpubform], 'cc' => ['Grading',$gradingform], - 'ee' => ['Other',$specialdocumentsform], ); unless ($container eq 'page') { $orderhash{'00'} = ['Newfolder',$newfolderform]; $orderhash{'dd'} = ['Collaboration',$communityform]; + $orderhash{'ee'} = ['Other',$specialdocumentsform]; } $hadchanges=0; @@ -6542,10 +6569,10 @@ unless ($container eq 'page') { $r->print('<p><span class="LC_error">'.$error.'</span></p>'); } if ($hadchanges) { - unless (&is_hash_old()) { - &mark_hash_old(); - } - } + unless (&is_hash_old()) { + &mark_hash_old(); + } + } &changewarning($r,''); } @@ -6557,7 +6584,7 @@ unless ($container eq 'page') { unless ($supplementalflag) { $folder='supplemental'; } - if (($folder eq 'supplemental') && + if ($folder =~ /^supplemental$/ && (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) { $env{'form.folderpath'} = &supplemental_base(); } elsif ($allowed) { @@ -6575,10 +6602,8 @@ unless ($container eq 'page') { <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data"> <fieldset id="uploadsuppdocform" style="display: none;"> <legend>$lt{'upfi'}</legend> - <input type="hidden" name="active" value="ee" /> + <input type="hidden" name="active" value="ee" /> $fileupload - <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled /> - <input type="hidden" id="LC_free_space_supp" value="$free_space" /> <br /> <br /> <span class="LC_nobreak"> @@ -6607,7 +6632,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'}, @@ -6673,8 +6700,8 @@ my @supimportdoc = ( {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.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}, ); @@ -6685,22 +6712,29 @@ my %suporderhash = ( 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))] ); if ($supplementalflag) { - $suppchanges = 0; - my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,\%suporderhash,$iconpath,$pathitem, - \%ltitools,$canedit,$hostname); - if ($error) { - $r->print('<p><span class="LC_error">'.$error.'</span></p>'); - } - if ($suppchanges) { - &Apache::lonnet::update_supp_caches($coursedom,$coursenum); - undef($suppchanges); - } + my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, + $supplementalflag,\%suporderhash,$iconpath,$pathitem, + \%ltitools,$canedit,$hostname); + if ($error) { + $r->print('<p><span class="LC_error">'.$error.'</span></p>'); + } else { + if ($suppchanges) { + my %servers = &Apache::lonnet::internet_dom_servers($coursedom); + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $server (keys(%servers)) { + next if (grep(/^\Q$server\E$/,@ids)); + my $hashid=$coursenum.':'.$coursedom; + my $cachekey = &escape('suppcount').':'.&escape($hashid); + &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]); + } + &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); + undef($suppchanges); + } + } } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem,'',$canedit, - $hostname); + $supplementalflag,'',$iconpath,$pathitem,'','',$hostname); if ($error) { $r->print('<p><span class="LC_error">'.$error.'</span></p>'); } @@ -6727,7 +6761,9 @@ 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; } @@ -6805,7 +6841,7 @@ sub decompression_phase_one { $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'}); } else { my $file = $1; - $output = + $output = &Apache::loncommon::process_decompression($docudom,$docuname,$file, $destination,$dir_root, $hiddenelem); @@ -6862,10 +6898,6 @@ sub remove_archive { if ($url eq $env{'form.archiveurl'}) { if (&handle_edit_cmd($docuname,$docudom)) { ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1); - if ($suppchanges) { - &Apache::lonnet::update_supp_caches($docudom,$docuname); - undef($suppchanges); - } if ($fatal) { if ($container eq 'page') { $delwarning = &mt('An error occurred updating the contents of the current page.'); @@ -6904,7 +6936,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", ); @@ -6955,13 +6986,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) { @@ -7093,7 +7117,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', @@ -7105,6 +7129,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', @@ -7123,6 +7148,8 @@ sub editing_js { p_ctr2b => '?', p_ctr3a => 'Cut those', p_ctr3b => 'items?', + setal => 'Enter a (unique) alias', + delal => 'Are you sure you want to eliminate the alias?', rpck => 'Enter number to pick (e.g., 3)', imsfile => 'You must choose an IMS package for import', imscms => 'You must select which Course Management System was the source of the IMS package', @@ -7133,9 +7160,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'},'<>&"'); @@ -7175,27 +7204,20 @@ sub editing_js { 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()) || (&Apache::lonnet::waf_allssl($hostname))) { - 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()) || (&Apache::lonnet::waf_allssl($hostname))) { - 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'; } @@ -7203,12 +7225,7 @@ sub editing_js { } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') { $backtourl = '/adm/menu'; } elsif ($supplementalflag) { - if (($env{'request.role.adv'}) || - (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) { - $backtourl = '/adm/supplemental'; - } else { - $backtourl = '/adm/navmaps'; - } + $backtourl = '/adm/supplemental'; } else { $backtourl = '/adm/navmaps'; } @@ -7226,14 +7243,14 @@ sub editing_js { $fieldsets .= ",'supptool'"; } } - + my $jsmakefunctions; if ($canedit) { $jsmakefunctions = <<ENDNEWSCRIPT; function makenewfolder(targetform,folderseq) { var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}'); if (foldername) { - targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq; + targetform.importdetail.value=escape(foldername)+"="+folderseq; targetform.submit(); } } @@ -7241,7 +7258,7 @@ function makenewfolder(targetform,folder function makenewpage(targetform,folderseq) { var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}'); if (pagename) { - targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq; + targetform.importdetail.value=escape(pagename)+"="+folderseq; targetform.submit(); } } @@ -7250,7 +7267,7 @@ function makeexamupload() { var title=prompt('$js_lt{"p_mxu"}'); if (title) { this.document.forms.newexamupload.importdetail.value= - encodeURIComponent(title)+'=/res/lib/templates/examupload.problem'; + escape(title)+'=/res/lib/templates/examupload.problem'; this.document.forms.newexamupload.submit(); } } @@ -7259,7 +7276,7 @@ function makesmppage() { var title=prompt('$js_lt{"p_msp"}'); if (title) { this.document.forms.newsmppg.importdetail.value= - encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg'; + escape(title)+'=/adm/$udom/$uname/new/smppg'; this.document.forms.newsmppg.submit(); } } @@ -7273,8 +7290,8 @@ function makewebpage(type) { formname = this.document.forms.newwebpage; } if (title) { - var webpage = formname.importdetail.value; - formname.importdetail.value = encodeURIComponent(title)+'='+webpage; + var webpage = formname.importdetail.value; + formname.importdetail.value = escape(title)+'='+webpage; formname.submit(); } } @@ -7283,7 +7300,7 @@ function makesmpproblem() { var title=prompt('$js_lt{"p_msb"}'); if (title) { this.document.forms.newsmpproblem.importdetail.value= - encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem'; + escape(title)+'=/res/lib/templates/simpleproblem.problem'; this.document.forms.newsmpproblem.submit(); } } @@ -7292,7 +7309,7 @@ function makedropbox() { var title=prompt('$js_lt{"p_mdb"}'); if (title) { this.document.forms.newdropbox.importdetail.value= - encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem'; + escape(title)+'=/res/lib/templates/DropBox.problem'; this.document.forms.newdropbox.submit(); } } @@ -7301,7 +7318,7 @@ function makebulboard() { var title=prompt('$js_lt{"p_mbb"}'); if (title) { this.document.forms.newbul.importdetail.value= - encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard'; + escape(title)+'=/adm/$udom/$uname/new/bulletinboard'; this.document.forms.newbul.submit(); } } @@ -7340,6 +7357,24 @@ function changename(folderpath,index,old } } +function setalias(folderpath,index) { + var alias = prompt('$js_lt{"setal"}'); + if ((alias != null) && (alias != '')) { + this.document.forms.aliasform.alias.value=alias; + this.document.forms.aliasform.cmd.value='setalias_'+index; + this.document.forms.aliasform.folderpath.value=folderpath; + this.document.forms.aliasform.submit(); + } +} + +function delalias(folderpath,index) { + if (confirm('$js_lt{"delal"}')) { + this.document.forms.aliasform.cmd.value='delalias_'+index; + this.document.forms.aliasform.folderpath.value=folderpath; + this.document.forms.aliasform.submit(); + } +} + ENDNEWSCRIPT } else { $jsmakefunctions = <<ENDNEWSCRIPT; @@ -7384,6 +7419,14 @@ function changename() { alert("$js_lt{'edri'}"); } +function setalias() { + alert("$js_lt{'edri'}"); +} + +function delalias() { + alert("$js_lt{'edri'}"); +} + function makenew() { alert("$js_lt{'edri'}"); } @@ -7423,14 +7466,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); } } } @@ -7454,6 +7497,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'}"); @@ -7760,11 +7983,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); @@ -7802,13 +8025,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 { @@ -7819,6 +8044,8 @@ function showPage(current, pageId, nav, activeTab = pageId; toggleUpload(); toggleMap(); + toggleCrsRes(); + toggleImportCrsres(); if (nav == 'mainnav') { var storedpath = "$docs_folderpath"; var storedpage = "$main_container_page"; @@ -8182,6 +8409,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 } @@ -8312,6 +8566,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__ @@ -8411,7 +8921,7 @@ check on this Verify Content -=item devalidateversioncache() +=item devalidateversioncache() =item checkversions()